Пример #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();
        }