Exemplo n.º 1
0
        // *** partial implementation, will be fixed in proj2 ****
        // Call ---
        // Exp obj;
        // Id cid, mid;
        // ExpList args;
        public IrExp visit(AstCall n)
        {
            string label;

            // An Important Detail: The TypeVisitor program has its own copy of
            // currClass and currMethod. These two variables need to be set to the
            // current environment before typechecking can work. Do the following:

            tv.setClass(currClass);
            tv.setMethod(currMethod);

            // 1. Perform typechecking on the obj component of the Call/CallStmt
            // node, which should return an ObjType representing the obj's class.

            AstObjType t = (AstObjType)n.obj.accept(tv);

            // 2. Look up the MethodRec with the class info.
            ClassRec classRec = symTable.GetClass(t.cid);
            MethodRec methodRec = symTable.GetMethod(classRec, n.mid);

            IrExp accessLink = n.obj.accept(this);
            IrExpList el = new IrExpList(accessLink);
            el.addAll(n.args.accept(this));

            if (maxArgCnt <= n.args.Count())
                maxArgCnt = n.args.Count() + 1;

            if (methodRec.Id().s.CompareTo("main") == 0)
                label = "main";
            else
                label = symTable.UniqueMethodName(classRec, methodRec.Id());

            return new IrCall(new IrName(label), el);
        }