Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 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.");
     }
 }
Esempio n. 3
0
        /// <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);
            }
        }
Esempio n. 4
0
 /// <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);
 }
Esempio n. 5
0
 public override void VisitDeclConstructor(ASTDeclarationCtor n)
 {
     _mgr.AddCtor(_currentType, n);
 }