public void AddCtor(string typeName, ASTDeclarationCtor n) { TypeBuilderInfo info = TypeBuilderMap[typeName]; TypeFunction function = n.Type as TypeFunction; ConstructorBuilder builderObj = info.Builder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ArgumentTypes(function)); info.ConstructorBuilder = new ConstructorBuilderInfo(builderObj, BuildFormalMap(n.Descriptor.Formals)); }
public override void VisitDeclConstructor(ASTDeclarationCtor n) { //lookup base class for the current type builder if (_currentTypeBuilder.Builder.BaseType is object) { _currentMethodBuilder = _currentTypeBuilder.ConstructorBuilder; _gen = _currentTypeBuilder.ConstructorBuilder.Builder.GetILGenerator(); //invoke the constructor of object ConstructorInfo baseCtor = typeof(object).GetConstructor(Type.EmptyTypes); _gen.Emit(OpCodes.Ldarg_0); //this. _gen.Emit(OpCodes.Call, baseCtor); //visit the body of the constructor n.Body.Visit(this); _gen.Emit(OpCodes.Ret); } else { throw new NotImplementedException("Inheritance is totally not done yet."); } }
/// <summary> /// Essentially the same as a method declaration, except there is no /// return type to validate. /// </summary> /// <param name="n"></param> public override void VisitDeclConstructor(ASTDeclarationCtor n) { var ctorScope = _scopeMgr.PushScope(string.Format("ctor {0}", n.Name)); var func = new TypeFunction(n.Name) { ReturnType = new TypeVoid(), IsConstructor = true }; var formalDescriptors = CollectFormals(n.Formals, func); func.Scope = ctorScope; _scopeMgr.PopScope(); var methodDesc = _scopeMgr.AddMethod(n.Name, func, _currentClass); n.Descriptor = methodDesc; n.Type = func; foreach (var formal in formalDescriptors) { methodDesc.Formals.Add(formal); } }
/// <summary> /// Pretty much the same thing as visiting a regular method. /// </summary> /// <param name="n"></param> public override void VisitDeclConstructor(ASTDeclarationCtor n) { VisitMethodBody(string.Format("ctor body {0}", n.Name), n.Body, n.Type as TypeFunction); }
public override void VisitDeclConstructor(ASTDeclarationCtor n) { _mgr.AddCtor(_currentType, n); }