Пример #1
0
        private int GetNumObjVars(ClassRec c)
        {
            int numVars = 0;

            while (null != c)
            {
                numVars += c.VarCnt();
                c = c.Parent();
            }
            return numVars;
        }
Пример #2
0
        private int GetInitStmts(ClassRec c, IrStmtList stmts, IrTemp tmp)
        {
            ClassRec saveCurrClass;
            VarRec v;
            int varCnt = 0;

            // Get init STMTs from inherited class
            if (null != c.Parent())
            {
                varCnt = GetInitStmts(c.Parent(), stmts, tmp);
            }

            // Add init STMTs from this class
            for (int i = 0; i < c.VarCnt(); i++)
            {

                v = c.GetClassVarAt(i);

                if (null == v.Init())
                {
                    stmts.add(ObjVarInitStmt(tmp, varCnt + i, v.Idx - 1, cZero));
                }
                else
                {
                    saveCurrClass = currClass;
                    currClass = c;
                    IrExp e = v.Init().accept(this);
                    currClass = saveCurrClass;

                    stmts.add(ObjVarInitStmt(tmp, varCnt + i, v.Idx - 1, e));
                }
            }
            return varCnt + c.VarCnt();
        }
Пример #3
0
 public string UniqueMethodName(ClassRec c, AstId mid)
 {
     MethodRec m;
     while (c != null)
     {
         if ((m = c.GetMethod(mid)) != null)
             return c.Id().s + "_" + mid.s;
         c = c.Parent();
     }
     throw new SymbolException("Method " + mid.s + " not defined");
 }
Пример #4
0
 public MethodRec GetMethod(ClassRec c, AstId mid)
 {
     MethodRec m;
     while (c != null)
     {
         if ((m = c.GetMethod(mid)) != null)
             return m;
         c = c.Parent();
     }
     throw new SymbolException("Method " + mid.s + " not defined");
 }
Пример #5
0
 public VarRec GetVar(ClassRec c, AstId vid)
 {
     VarRec v;
     while (c != null)
     {
         if ((v = c.GetClassVar(vid)) != null)
             return v;
         c = c.Parent();
     }
     throw new SymbolException("Var " + vid.s + " not defined");
 }