public TypeVisitor(DemiTasse.symbol.SymbolTable symtab, ClassRec c, MethodRec m) { symTable = symtab; currClass = c; currMethod = m; hasReturn = false; }
// *********************************************************** // * constructor -- a symbol table is passed in as a parameter // *********************************************************** public TypeVisitor(SymbolTable symtab) { symTable = symtab; currClass = null; currMethod = null; hasReturn = false; }
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; }
// *** 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); }
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); }
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); }
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; }
private MethodRec currMethod; // the current method scope #endregion Fields #region Constructors public SymbolVisitor() { symTable = new symbol.SymbolTable(); currClass = null; currMethod = null; }
// 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; }
public void setMethod(MethodRec m) { currMethod = m; }
/* 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; }