//- 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; } }
public ArithmeticExprNode loadArithmeticExpression(string path) { string opstr = oilcan.getStringValue(path + ".op", ""); ArithmeticExprNode.OPERATOR op = ArithmeticExprNode.OPERATOR.PLUS; switch (opstr) { case "plus": op = ArithmeticExprNode.OPERATOR.PLUS; break; case "minus": op = ArithmeticExprNode.OPERATOR.MINUS; break; case "inc": op = ArithmeticExprNode.OPERATOR.INC; break; case "dec": op = ArithmeticExprNode.OPERATOR.DEC; break; case "add": op = ArithmeticExprNode.OPERATOR.ADD; break; case "sub": op = ArithmeticExprNode.OPERATOR.SUB; break; case "mult": op = ArithmeticExprNode.OPERATOR.MULT; break; case "div": op = ArithmeticExprNode.OPERATOR.DIV; break; case "mod": op = ArithmeticExprNode.OPERATOR.MOD; break; default: break; } ExprNode lhs = loadExpression(path + ".lhs"); ExprNode rhs = loadExpression(path + ".rhs"); ArithmeticExprNode enode = new ArithmeticExprNode(op, lhs, rhs); return(enode); }