public AssignExprNode loadAssignmentExpression(string path) { string opstr = oilcan.getStringValue(path + ".op", ""); AssignExprNode.OPERATOR op = AssignExprNode.OPERATOR.EQUAL; switch (opstr) { case "equal": op = AssignExprNode.OPERATOR.EQUAL; break; case "multequal": op = AssignExprNode.OPERATOR.MULTEQUAL; break; case "divequal": op = AssignExprNode.OPERATOR.DIVEQUAL; break; case "modequal": op = AssignExprNode.OPERATOR.MODEQUAL; break; case "addequal": op = AssignExprNode.OPERATOR.ADDEQUAL; break; case "subequal": op = AssignExprNode.OPERATOR.SUBEQUAL; break; case "lshiftequal": op = AssignExprNode.OPERATOR.LSHIFTEQUAL; break; case "rshiftequal": op = AssignExprNode.OPERATOR.RSHIFTEQUAL; break; case "andequal": op = AssignExprNode.OPERATOR.ANDEQUAL; break; case "xorequal": op = AssignExprNode.OPERATOR.XOREQUAL; break; case "orequal": op = AssignExprNode.OPERATOR.OREQUAL; break; default: break; } ExprNode lhs = loadExpression(path + ".lhs"); ExprNode rhs = loadExpression(path + ".rhs"); AssignExprNode enode = new AssignExprNode(op, lhs, rhs); return(enode); }
//- 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; } }