예제 #1
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);
            }
        }
예제 #2
0
 public override void VisitInvoke(ASTInvoke n)
 {
     if (SystemMethodManager.IsSystemMethod(n.Method))
     {
         n.Actuals.Visit(this);
         SystemMethod method = SystemMethodManager.Lookup(n.Method);
         method.Emit(_gen);
         //store the return type so we can invoke methods and stuff on it.
         _lastWalkedType = _typeManager.LookupCilType(method.FuncInfo.ReturnType);
     }
     else
     {
         //push who
         n.Object.Visit(this);
         Type who = _lastWalkedType;
         //push actuals
         n.Actuals.Visit(this);
         //find the method to execute on the given class
         MethodBuilderInfo info = _typeManager.GetMethodBuilderInfo(who.Name, n.Method);
         _gen.Emit(OpCodes.Callvirt, info.Builder);
         //store the return type of the method
         _lastWalkedType = info.Builder.ReturnType;
     }
 }