示例#1
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.");
     }
 }
示例#2
0
        public override void VisitDeclMethod(ASTDeclarationMethod n)
        {
            n.Modifiers.Visit(this);

            MethodBuilderInfo methodInfo = _typeManager.GetMethodBuilderInfo(_currentTypeBuilder.Name, n.Name);

            //store a reference so we can access locals, arguments, and stuff about the current method we're working on.
            _currentMethodBuilder = methodInfo;
            _gen = methodInfo.Builder.GetILGenerator();
            //is this the entry point
            if (n.Name == MainMethodName)
            {
                _assemblyBuilder.SetEntryPoint(methodInfo.Builder);
            }

            n.Body.Visit(this);
            //we need to explicitly put a return statement for voids
            if (_typeManager.LookupCilType(n.ReturnType) == typeof(void))
            {
                _gen.Emit(OpCodes.Ret);
            }
        }