Esempio n. 1
0
        //- writing expressions -------------------------------------

        public void saveExpression(string path, ExprNode expr)
        {
            if (expr == null)
            {
                return;
            }

            switch (expr.type)
            {
            case OILType.IdentExpr:
                IdentExprNode idexpr = (IdentExprNode)expr;
                oilcan.setStringValue(path + ".type", "ident-expr");
                oilcan.setStringValue(path + ".ref", idexpr.idsym.OILname);
                break;

            case OILType.IntConst:
                IntConstant iconst = (IntConstant)expr;
                oilcan.setStringValue(path + ".type", "int-const");
                oilcan.setIntValue(path + ".val", iconst.value);
                break;

            case OILType.FloatConst:
                FloatConstant fconst = (FloatConstant)expr;
                oilcan.setStringValue(path + ".type", "float-const");
                oilcan.setFloatValue(path + ".val", fconst.value);
                break;

            case OILType.ArithmeticExpr:
                ArithmeticExprNode arithexpr = (ArithmeticExprNode)expr;
                oilcan.setStringValue(path + ".type", "arith-expr");
                saveExpression(path + ".lhs", arithexpr.lhs);
                oilcan.setStringValue(path + ".op", ArithmeticExprNode.opname[(int)arithexpr.op]);
                saveExpression(path + ".rhs", arithexpr.rhs);
                break;

            case OILType.CompareExpr:
                ComparisonExprNode compexpr = (ComparisonExprNode)expr;
                oilcan.setStringValue(path + ".type", "comp-expr");
                saveExpression(path + ".lhs", compexpr.lhs);
                oilcan.setStringValue(path + ".op", ComparisonExprNode.opname[(int)compexpr.op]);
                saveExpression(path + ".rhs", compexpr.rhs);
                break;

            case OILType.AssignExpr:
                AssignExprNode assignexpr = (AssignExprNode)expr;
                oilcan.setStringValue(path + ".type", "assign-expr");
                saveExpression(path + ".lhs", assignexpr.lhs);
                oilcan.setStringValue(path + ".op", AssignExprNode.opname[(int)assignexpr.op]);
                saveExpression(path + ".rhs", assignexpr.rhs);
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        //- reading expressions -------------------------------------

        public ExprNode loadExpression(string path)
        {
            ExprNode enode    = null;
            string   exprtype = oilcan.getStringValue(path + ".type", "");

            switch (exprtype)
            {
            case "ident-expr":
                OILNode idsym = loadSymbolRef(path + ".ref");
                enode = new IdentExprNode(idsym);
                break;

            case "int-const":
                int intval = oilcan.getIntValue(path + ".val", 0);
                enode = new IntConstant(intval);
                break;

            case "float-const":
                double dblval = oilcan.getFloatValue(path + ".val", 0.0);
                enode = new FloatConstant(dblval);
                break;

            case "arith-expr":
                enode = loadArithmeticExpression(path);
                break;

            case "comp-expr":
                enode = loadComparisionExpression(path);
                break;

            case "assign-expr":
                enode = loadAssignmentExpression(path);
                break;

            default:
                break;
            }
            return(enode);
        }