Example #1
0
 public TypeVisitor(DemiTasse.symbol.SymbolTable symtab, ClassRec c, MethodRec m)
 {
     symTable = symtab;
     currClass = c;
     currMethod = m;
     hasReturn = false;
 }
Example #2
0
 // ***********************************************************
 // * constructor -- a symbol table is passed in as a parameter
 // ***********************************************************
 public TypeVisitor(SymbolTable symtab)
 {
     symTable = symtab;
     currClass = null;
     currMethod = null;
     hasReturn = false;
 }
Example #3
0
 public IrgenVisitor(SymbolTable symTable_, TypeVisitor tv_)
 {
     cOne = new IrConst(1);
     cZero = new IrConst(0);
     cWordSize = new IrName("wSZ");
     symTable = symTable_;
     tv = tv_;
     currClass = null;
     currMethod = null;
 }
Example #4
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);
        }
Example #5
0
        public void AddMethod(AstId mid, DemiTasse.ast.AstType rtype)
        {
            if (_methods.ContainsKey(mid.s))
                throw new SymbolException("Method " + mid.s + " already defined");

            MethodRec m = new MethodRec(mid, rtype);

            _methods.Add(mid.s, m);
        }
Example #6
0
 public VarRec GetVar(ClassRec c, MethodRec m, AstId vid)
 {
     VarRec v;
     if (m != null)
     {
         if ((v = m.GetLocal(vid)) != null)
             return v;
         if ((v = m.GetParam(vid)) != null)
             return v;
     }
     return GetVar(c, vid);
 }
Example #7
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;
    }
Example #8
0
        private MethodRec currMethod; // the current method scope

        #endregion Fields

        #region Constructors

        public SymbolVisitor()
        {
            symTable = new symbol.SymbolTable();
            currClass = null;
            currMethod = null;
        }
Example #9
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;
 }
Example #10
0
 public void setMethod(MethodRec m)
 {
     currMethod = m;
 }
Example #11
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;
        }