Esempio n. 1
0
        public override void GenCode(StringBuilder sb)
        {
            MethodDec methodD = declarationRef as MethodDec;

            if (methodD != null)
            {
                // get argurments and load on stack
                // !!!! THIS WON'T WORK IF THE ARGS ARE MORE THAN A SIMPLE LITERAL OR VARIABLE !!!!
                foreach (Expression arg in args)
                {
                    arg.GenCode(sb);
                }

                // emit method call
                methodD.GenCallCode(sb);

                // emit variable types
                string argList = "";
                foreach (Expression arg in args)
                {
                    argList = argList + arg.ObtainType().GetILName() + ',';
                }

                argList = argList.TrimEnd(',');// remove last ','
                cg.emit(sb, argList + ")\n");
            }
        }
Esempio n. 2
0
        public override void TypeCheck()
        {
            // check the type of the arguments
            foreach (Expression argument in args)
            {
                argument.TypeCheck();
            }

            // check the type of the arguments matches what the method expects
            MethodDec decl = declarationRef as MethodDec;

            if (decl != null)
            {
                if (!decl.checkArgTypes(args))
                {
                    // args do match what is expected
                    System.Console.WriteLine("Invalid arguments for method", name);
                    throw new Exception("TypeCheck error");
                }
            }

            // return the type of the method
            type = declarationRef.ObtainType();
        }