Example #1
0
 // VarDecl ---
 // Type t;
 // Id var;
 // Exp e;
 public IrStmt visit(AstVarDecl n)
 {
     if (n.e != null)
     {
         IrExp id = n.var.accept(this);
         IrExp e = n.e.accept(this);
         return new IrMove(id, e);
     }
     return null;
 }
Example #2
0
    // ************************************************
    // * DECLARATIONS
    // ************************************************

    public void visit(AstVarDecl n) {
    // need to check class existence if type is ObjType
    // need to check init expr if it exists

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

        if (n.e != null)
        {
            AstType t2 = n.e.accept(this);
            if (!compatible(n.t,t2))
                throw new TypeException("Incompatible types in VarDecl: " + n.t + " <- " + t2);
        }
    }
Example #3
0
        /* throws Exception */
        // VarDecl ---
        // Type t;
        // Id var;
        // Exp e;
        public void visit(AstVarDecl n)
        {
            if (null != (n.t as AstObjType))
                // make sure type is defined
                symTable.GetClass(((AstObjType) n.t).cid);

            if (n.e != null)
            {
                AstType t2 = n.e.accept(this);
                if (!compatible(n.t,t2))
                    throw new TypeException("Incompatible types in VarDecl: " + n.t + " <- " + t2);
            }
        }
Example #4
0
 // VarDecl ---
 // Type t;
 // Id var;
 // Exp e;
 public void visit(AstVarDecl n)
 {
     if (currMethod != null)
     { 	// a local variable
         if (currMethod.GetParam(n.var) != null)
             throw new SymbolException(n.var.s + " already defined as a param");
         currMethod.AddLocal(n.var, n.t);
     }
     else
     {   // a class variable
         currClass.AddClassVar(n.var, n.t, n.e);
     }
 }
Example #5
0
 public void Add(AstVarDecl n)
 {
     base.Add(n);
 }