Пример #1
0
        // *** partial implementation, will be fixed in proj2 ****
        // MethodDecl ---
        // Type t;
        // Id mid;
        // FormalList fl;
        // VarDeclList vl;
        // StmtList sl;
        public IrFunc visit(AstMethodDecl n)
        {
            string label;
            int varCnt = 0;
            int tmpCnt = 0;
            maxArgCnt = 0;       // note this is a class variable

            // Look up the corresponding MethodRec in the symbol table
            currMethod = currClass.GetMethod(n.mid);

            IrTemp.Reset();

            IrStmtList stmts = n.vl.accept(this);
            if (stmts == null)
                stmts = n.sl.accept(this);
            else
                stmts.add(n.sl.accept(this));

            // Create an unique label for the method by concatenating class name
            //  and method name together, with an underscore ( ) in between.

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

            varCnt = currMethod.LocalCnt();
            tmpCnt = IrTemp.Count;

            currMethod = null;
            return new IrFunc(label, varCnt, tmpCnt, maxArgCnt, stmts);
        }
Пример #2
0
 public void Add(AstMethodDecl n)
 {
     base.Add(n);
 }
Пример #3
0
 // MethodDecl ---
 // Type t;
 // Id mid;
 // FormalList fl;
 // VarDeclList vl;
 // StmtList sl;
 public void visit(AstMethodDecl n)
 {
     currClass.AddMethod(n.mid, n.t);
     currMethod = currClass.GetMethod(n.mid);
     n.fl.accept(this);
     n.vl.accept(this);
     currMethod = null;
 }
Пример #4
0
    public void visit(AstMethodDecl n) {

        // Set currMethod to the method table
        currMethod = currClass.getMethod(n.mid);
        hasReturn = false;
        n.fl.accept(this);
        n.vl.accept(this);
        n.sl.accept(this);

        // if method has a return value verify that method had a return statement
            if (null != (n.t as AstObjType))
                symTable.getClass(((AstObjType) n.t).cid);

            if ((n.t != null) && !hasReturn)
                throw new TypeException("Method " + n.mid.s + " is missing a Return statment");
            currMethod = null;
    }
Пример #5
0
        /* throws Exception */
        // MethodDecl ---
        // Type t;
        // Id mid;
        // FormalList fl;
        // VarDeclList vl;
        // StmtList sl;
        public void visit(AstMethodDecl n)
        {
            currMethod = currClass.GetMethod(n.mid);
            hasReturn = false;
            n.fl.accept(this);
            n.vl.accept(this);
            n.sl.accept(this);

            // make sure return type is defined
            if (null != (n.t as AstObjType))
                symTable.GetClass(((AstObjType) n.t).cid);

            if ((n.t != null) && !hasReturn)
                throw new TypeException("Method " + n.mid.s + " is missing a Return statment");
            currMethod = null;
        }