@Override public boolean visit(org.eclipse.edt.compiler.core.ast.WhenClause whenClause) { IfStatement clause = factory.createIfStatement(); Expression prevCond = null; for (Node node : whenClause.getExpr_plus()) { node.accept(this); Expression expr = (Expression) stack.pop(); if (prevCond != null) { BinaryExpression binExp = factory.createBinaryExpression(); binExp.setLHS(prevCond); binExp.setRHS(expr); binExp.setOperator(Operation.OR); expr = binExp; } prevCond = expr; clause.setCondition(expr); } StatementBlock block = factory.createStatementBlock(); for (Node node : (List<Node>) whenClause.getStmts()) { node.accept(this); Statement stmt = (Statement) stack.pop(); if (stmt != null) { block.getStatements().add(stmt); } } clause.setTrueBranch(block); stack.push(clause); setElementInformation(whenClause, clause); setElementInformation(whenClause, block); return false; }
public void genBinaryExpression(Type type, Context ctx, TabbedWriter out, BinaryExpression arg) { out.print(getNativeStringPrefixOperation(arg)); out.print("("); ctx.invoke(genExpression, arg.getLHS(), ctx, out, arg.getOperation().getParameters().get(0)); out.print(getNativeStringOperation(arg)); ctx.invoke(genExpression, arg.getRHS(), ctx, out, arg.getOperation().getParameters().get(1)); out.print(getNativeStringComparisionOperation(arg)); out.print(")"); }
@SuppressWarnings("static-access") protected String getNativeStringPrefixOperation(BinaryExpression expr) { String op = expr.getOperator(); if (op.equals(expr.Op_EQ)) return "egl.eglx.lang.EDecimal.equals"; if (op.equals(expr.Op_NE)) return "egl.eglx.lang.EDecimal.notEquals"; return ""; }
private Expression addWhenCriterion(Expression criterion, Expression condition) { if (condition instanceof BinaryExpression) { BinaryExpression binExp = (BinaryExpression) condition; Expression expr = addWhenCriterion(criterion, binExp.getLHS()); binExp.setLHS(expr); expr = addWhenCriterion(criterion, binExp.getRHS()); binExp.setRHS(expr); return condition; } else { BinaryExpression binExp = factory.createBinaryExpression(); binExp.setLHS(criterion); binExp.setRHS(condition); binExp.setOperator(Operation.EQUALS); return binExp; } }
@SuppressWarnings("static-access") protected String getNativeStringComparisionOperation(BinaryExpression expr) { String op = expr.getOperator(); if (op.equals(expr.Op_PLUS)) return ")"; if (op.equals(expr.Op_MINUS)) return ")"; if (op.equals(expr.Op_MULTIPLY)) return ")"; if (op.equals(expr.Op_DIVIDE)) return ")"; // if (op.equals(expr.Op_EQ)) // return ") == 0"; // if (op.equals(expr.Op_NE)) // return ") != 0"; if (op.equals(expr.Op_LT)) return ") < 0"; if (op.equals(expr.Op_GT)) return ") > 0"; if (op.equals(expr.Op_LE)) return ") <= 0"; if (op.equals(expr.Op_GE)) return ") >= 0"; if (op.equals(expr.Op_MODULO)) return ")"; if (op.equals(expr.Op_POWER)) return ",egl.javascript.BigDecimal.prototype.eglMC)"; return ""; }
@SuppressWarnings("static-access") protected String getNativeStringOperation(BinaryExpression expr) { String op = expr.getOperator(); // these are the defaults for what can be handled by the java string class if (op.equals(expr.Op_PLUS)) return ".add("; if (op.equals(expr.Op_MINUS)) return ".subtract("; if (op.equals(expr.Op_MULTIPLY)) return ".multiply("; if (op.equals(expr.Op_DIVIDE)) return ".divide("; if (op.equals(expr.Op_EQ)) return ","; if (op.equals(expr.Op_NE)) return ","; if (op.equals(expr.Op_LT)) return ".compareTo("; if (op.equals(expr.Op_GT)) return ".compareTo("; if (op.equals(expr.Op_LE)) return ".compareTo("; if (op.equals(expr.Op_GE)) return ".compareTo("; if (op.equals(expr.Op_AND)) return " && "; if (op.equals(expr.Op_OR)) return " || "; if (op.equals(expr.Op_CONCAT)) return " + "; if (op.equals(expr.Op_MODULO)) return ".remainder("; if (op.equals(expr.Op_POWER)) return ".pow("; return ""; }