protected void expressionPre(Expression x) { append(x.getParenthesis() ? "(" : ""); }
public Expression setParenthesisIfNeeded() { setParenthesis(!( this instanceof VariableRef || this instanceof FunctionCall || this instanceof MemberRef || this instanceof ArrayAccess )); return this; } public boolean getParenthesis() {
public Expression arrayLength() { Expression length = null; for (Expression m : arrayLengths) { m.setParenthesis(true); if (length == null) { length = m.clone(); } else { length = expr(length, Expression.BinaryOperator.Multiply, m.clone()); } } return length.setParenthesis(arrayLengths.size() > 1); }
return null; res.getFirst().setParenthesis(x.getParenthesis()); return (Pair<Expression, TypeRef>) res;
public Expression sizeof(JavaPrim p) { return sizeOfExpression.clone(); } }
@Override public boolean replaceChild(Element child, Element by) { if (child == getOperand()) { setOperand((Expression) by); return true; } return super.replaceChild(child, by); }
op = Expression.getBinaryOperator((t!=null?t.getText():null)); if (op == null) throw new RuntimeException("Failed to parse op " + (t!=null?t.getText():null));
BinaryOperator binOp = assignment.getOperator().getCorrespondingBinaryOp(); Expression value = assignment.getValue(); value.setParenthesisIfNeeded(); if (assignment.getTarget() instanceof UnaryOp) { UnaryOp uop = (UnaryOp) assignment.getTarget(); Expression target = uop.getOperand(); if (binOp != null) { value = expr(methodCall(target.clone(), "get"), binOp, value); Expression index = aa.getIndex(); if (binOp != null) { value = expr(methodCall(target.clone(), "get", index.clone()), binOp, value); String name = mr.getName().toString(); if (binOp != null) { value = expr(methodCall(target.clone(), name), binOp, value);
public static java.lang.Enum<?> getAnyOperator(String s) { java.lang.Enum<?> e = binOps.get(s);//Expression.getBinaryOperator(s); if (e != null) return e; e = unOps.get(s);//Expression.getUnaryOperator(s); if (e != null) return e; return Expression.getAssignmentOperator(s); }
@Override public void visitIf(If ifStat) { super.visitIf(ifStat); Expression cond = ifStat.getCondition(); if (!(cond instanceof BinaryOp)) // TODO use typing rather than this hack to detect implicit boolean conversion in if statements (and not only there) { cond.replaceBy(expr(cond, BinaryOperator.IsDifferent, expr(0))); } }
@Override public void visitMemberRef(MemberRef memberRef) { // TODO restrict to struct/class fields // TODO handle global variables with explicit namespaces... if (!(memberRef.getParentElement() instanceof FunctionCall)) { if (memberRef.getName() != null) { switch (memberRef.getMemberRefStyle()) { case Colons: memberRef.setMemberRefStyle(MemberRefStyle.Dot); break; case Arrow: case Dot: Expression rep = methodCall(memberRef.getTarget(), memberRef.getName().toString()); if (memberRef.getMemberRefStyle() == MemberRefStyle.Arrow) { rep = methodCall(rep, "get"); } memberRef.replaceBy(rep); rep.accept(this); return; } } } super.visitMemberRef(memberRef); }
java.lang.Enum<?> e = Expression.getAnyOperator(op); if (e == null) { if (op.equals("()")) {
op = Expression.getUnaryOperator((t!=null?t.getText():null));
return null; res.getFirst().setParenthesis(x.getParenthesis()); return (Pair<Expression, TypeRef>) res;
public Expression sizeof(JavaPrim p) { return sizeOfExpression.clone(); } }
@Override public boolean replaceChild(Element child, Element by) { return replaceChild(getExpressions(), Expression.class, this, child, by) || super.replaceChild(child, by); } }
if (state.failed) return expr; if ( state.backtracking==0 ) { expr = new BinaryOp(expr, getBinaryOperator((op!=null?op.getText():null)), f); }
BinaryOperator binOp = assignment.getOperator().getCorrespondingBinaryOp(); Expression value = assignment.getValue(); value.setParenthesisIfNeeded(); if (assignment.getTarget() instanceof UnaryOp) { UnaryOp uop = (UnaryOp) assignment.getTarget(); Expression target = uop.getOperand(); if (binOp != null) { value = expr(methodCall(target.clone(), "get"), binOp, value); Expression index = aa.getIndex(); if (binOp != null) { value = expr(methodCall(target.clone(), "get", index.clone()), binOp, value); String name = mr.getName().toString(); if (binOp != null) { value = expr(methodCall(target.clone(), name), binOp, value);
retval.op = getAssignmentOperator((t!=null?t.getText():null));
@Override public void visitIf(If ifStat) { super.visitIf(ifStat); Expression cond = ifStat.getCondition(); if (!(cond instanceof BinaryOp)) // TODO use typing rather than this hack to detect implicit boolean conversion in if statements (and not only there) { cond.replaceBy(expr(cond, BinaryOperator.IsDifferent, expr(0))); } }