tomlokhorst / language-cil

Manipulating Common Intermediate Language AST in Haskell
Other
20 stars 8 forks source link

Static Constructors #9

Closed dmcclean closed 13 years ago

dmcclean commented 13 years ago

I need support for defining static constructors. The existing implementation...

-- | A Method definition in CIL.
data MethodDef
  = Constructor [MethAttr] PrimitiveType [Parameter] [MethodDecl]
  | Method [MethAttr] PrimitiveType MethodName [Parameter] [MethodDecl]
  deriving Show

...distinguishes constructor definitions from method definitions. The only difference is the absence of a method name. If we want to stick with this approach, for consistency we should add a third case for StaticConstructor -- although I don't advocate this.

The only difference is names; constructors have the special name ".ctor", static constructors have the special name ".cctor". I would advocate eliminating the Constructor alternative from the MethodDef type, retaining special methods in Build.hs to define constructors and static constructors.

One reason I advocate this change is that there are a number of other constructs implemented (partly or wholly) through special names: property getter/setters. event modification methods, indexers. Adding cases for all of these to MethodDef seems useless, since there is basically no need to case-analyze on these cases: a method is a method is a method.

tomlokhorst commented 13 years ago

I agree with dropping the Constructor constructor from MethodDef.

If it is necessary to see the difference between a constructor and another method, the name ".ctor" can be used to check, since is is specified to be special.