Exemplo 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;
            }
        }
Exemplo n.º 2
0
        public ComparisonExprNode loadComparisionExpression(string path)
        {
            string opstr = oilcan.getStringValue(path + ".op", "");

            ComparisonExprNode.OPERATOR op = ComparisonExprNode.OPERATOR.EQUAL;
            switch (opstr)
            {
            case "equal":
                op = ComparisonExprNode.OPERATOR.EQUAL;
                break;

            case "notequal":
                op = ComparisonExprNode.OPERATOR.NOTEQUAL;
                break;

            case "lessthan":
                op = ComparisonExprNode.OPERATOR.LESSTHAN;
                break;

            case "gtrthan":
                op = ComparisonExprNode.OPERATOR.GTRTHAN;
                break;

            case "lessequal":
                op = ComparisonExprNode.OPERATOR.LESSEQUAL;
                break;

            case "gtrequal":
                op = ComparisonExprNode.OPERATOR.GTREQUAL;
                break;

            default:
                break;
            }
            ExprNode           lhs   = loadExpression(path + ".lhs");
            ExprNode           rhs   = loadExpression(path + ".rhs");
            ComparisonExprNode enode = new ComparisonExprNode(op, lhs, rhs);

            return(enode);
        }