List of usage examples for org.eclipse.jdt.internal.compiler.ast OR_OR_Expression OR_OR_Expression
public OR_OR_Expression(Expression left, Expression right, int operator)
From source file:lombok.eclipse.handlers.ast.EclipseASTMaker.java
License:Open Source License
@Override public ASTNode visitBinary(final lombok.ast.Binary node, final Void p) { final String operator = node.getOperator(); final int opCode; if (BINARY_OPERATORS.containsKey(operator)) { opCode = BINARY_OPERATORS.get(operator); } else {/*from w w w. ja v a2 s .c o m*/ throw new IllegalStateException(String.format("Unknown binary operator '%s'", operator)); } final BinaryExpression binaryExpression; if ("||".equals(operator)) { binaryExpression = new OR_OR_Expression(build(node.getLeft(), Expression.class), build(node.getRight(), Expression.class), opCode); } else if ("&&".equals(operator)) { binaryExpression = new AND_AND_Expression(build(node.getLeft(), Expression.class), build(node.getRight(), Expression.class), opCode); } else if (Is.oneOf(operator, "==", "!=")) { binaryExpression = new EqualExpression(build(node.getLeft(), Expression.class), build(node.getRight(), Expression.class), opCode); } else { binaryExpression = new BinaryExpression(build(node.getLeft(), Expression.class), build(node.getRight(), Expression.class), opCode); } setGeneratedByAndCopyPos(binaryExpression, source, posHintOf(node)); return binaryExpression; }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected void consumeBinaryExpression(int op) { // MultiplicativeExpression ::= MultiplicativeExpression '*' UnaryExpression // MultiplicativeExpression ::= MultiplicativeExpression '/' UnaryExpression // MultiplicativeExpression ::= MultiplicativeExpression '%' UnaryExpression // AdditiveExpression ::= AdditiveExpression '+' MultiplicativeExpression // AdditiveExpression ::= AdditiveExpression '-' MultiplicativeExpression // ShiftExpression ::= ShiftExpression '<<' AdditiveExpression // ShiftExpression ::= ShiftExpression '>>' AdditiveExpression // ShiftExpression ::= ShiftExpression '>>>' AdditiveExpression // RelationalExpression ::= RelationalExpression '<' ShiftExpression // RelationalExpression ::= RelationalExpression '>' ShiftExpression // RelationalExpression ::= RelationalExpression '<=' ShiftExpression // RelationalExpression ::= RelationalExpression '>=' ShiftExpression // AndExpression ::= AndExpression '&' EqualityExpression // ExclusiveOrExpression ::= ExclusiveOrExpression '^' AndExpression // InclusiveOrExpression ::= InclusiveOrExpression '|' ExclusiveOrExpression // ConditionalAndExpression ::= ConditionalAndExpression '&&' InclusiveOrExpression // ConditionalOrExpression ::= ConditionalOrExpression '||' ConditionalAndExpression //optimize the push/pop this.expressionPtr--; this.expressionLengthPtr--; Expression expr1 = this.expressionStack[this.expressionPtr]; Expression expr2 = this.expressionStack[this.expressionPtr + 1]; switch (op) { case OR_OR://from w w w .ja v a 2s .c om this.expressionStack[this.expressionPtr] = new OR_OR_Expression(expr1, expr2, op); break; case AND_AND: this.expressionStack[this.expressionPtr] = new AND_AND_Expression(expr1, expr2, op); break; case PLUS: // look for "string1" + "string2" if (this.optimizeStringLiterals) { if (expr1 instanceof StringLiteral) { if (((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) { if (expr2 instanceof CharLiteral) { // string+char this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendWith((CharLiteral) expr2); } else if (expr2 instanceof StringLiteral) { //string+string this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendWith((StringLiteral) expr2); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else if (expr1 instanceof CombinedBinaryExpression) { CombinedBinaryExpression cursor; // left branch is comprised of PLUS BEs // cursor is shifted upwards, while needed BEs are added // on demand; past the arityMax-th // consecutive BE, a CBE is inserted that holds a // full-fledged references table if ((cursor = (CombinedBinaryExpression) expr1).arity < cursor.arityMax) { cursor.left = new BinaryExpression(cursor); cursor.arity++; } else { cursor.left = new CombinedBinaryExpression(cursor); cursor.arity = 0; cursor.tuneArityMax(); } cursor.right = expr2; cursor.sourceEnd = expr2.sourceEnd; this.expressionStack[this.expressionPtr] = cursor; // BE_INSTRUMENTATION: neutralized in the released code // cursor.depthTracker = ((BinaryExpression)cursor.left). // depthTracker + 1; } else if (expr1 instanceof BinaryExpression && // single out the a + b case, which is a BE // instead of a CBE (slightly more than a half of // strings concatenation are one-deep binary // expressions) ((expr1.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT) == OperatorIds.PLUS) { this.expressionStack[this.expressionPtr] = new CombinedBinaryExpression(expr1, expr2, PLUS, 1); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else if (expr1 instanceof StringLiteral) { if (expr2 instanceof StringLiteral && ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) { // string + string this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendsWith((StringLiteral) expr2); } else { // single out the a + b case this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else if (expr1 instanceof CombinedBinaryExpression) { CombinedBinaryExpression cursor; // shift cursor; create BE/CBE as needed if ((cursor = (CombinedBinaryExpression) expr1).arity < cursor.arityMax) { cursor.left = new BinaryExpression(cursor); // clear the bits on cursor cursor.bits &= ~ASTNode.ParenthesizedMASK; cursor.arity++; } else { cursor.left = new CombinedBinaryExpression(cursor); // clear the bits on cursor cursor.bits &= ~ASTNode.ParenthesizedMASK; cursor.arity = 0; cursor.tuneArityMax(); } cursor.right = expr2; cursor.sourceEnd = expr2.sourceEnd; // BE_INSTRUMENTATION: neutralized in the released code // cursor.depthTracker = ((BinaryExpression)cursor.left). // depthTracker + 1; this.expressionStack[this.expressionPtr] = cursor; } else if (expr1 instanceof BinaryExpression && ((expr1.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT) == OperatorIds.PLUS) { // single out the a + b case this.expressionStack[this.expressionPtr] = new CombinedBinaryExpression(expr1, expr2, PLUS, 1); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } break; case LESS: case MULTIPLY: this.intPtr--; // star end position or starting position of angle bracket this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); break; default: this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
/** * @param op binary operator/*from w w w.j av a 2 s .c o m*/ */ protected void consumeBinaryExpressionWithName(int op) { pushOnExpressionStack(getUnspecifiedReferenceOptimized()); this.expressionPtr--; this.expressionLengthPtr--; /* if (op == OR_OR) { this.expressionStack[this.expressionPtr] = new OR_OR_Expression( this.expressionStack[this.expressionPtr + 1], this.expressionStack[this.expressionPtr], op); } else { if (op == AND_AND) { this.expressionStack[this.expressionPtr] = new AND_AND_Expression( this.expressionStack[this.expressionPtr + 1], this.expressionStack[this.expressionPtr], op); } else { // look for "string1" + "string2" if ((op == PLUS) && this.optimizeStringLiterals) { Expression expr1, expr2; expr1 = this.expressionStack[this.expressionPtr + 1]; expr2 = this.expressionStack[this.expressionPtr]; if (expr1 instanceof StringLiteral) { if (expr2 instanceof CharLiteral) { // string+char this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1).extendWith((CharLiteral) expr2); } else if (expr2 instanceof StringLiteral) { //string+string this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1).extendWith((StringLiteral) expr2); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else { this.expressionStack[this.expressionPtr] = new BinaryExpression( this.expressionStack[this.expressionPtr + 1], this.expressionStack[this.expressionPtr], op); } } } */ Expression expr1 = this.expressionStack[this.expressionPtr + 1]; Expression expr2 = this.expressionStack[this.expressionPtr]; // Note: we do not attempt to promote BinaryExpression-s to // IndexedBinaryExpression-s here since expr1 always holds a name switch (op) { case OR_OR: this.expressionStack[this.expressionPtr] = new OR_OR_Expression(expr1, expr2, op); break; case AND_AND: this.expressionStack[this.expressionPtr] = new AND_AND_Expression(expr1, expr2, op); break; case PLUS: // look for "string1" + "string2" if (this.optimizeStringLiterals) { if (expr1 instanceof StringLiteral && ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) { if (expr2 instanceof CharLiteral) { // string+char this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendWith((CharLiteral) expr2); } else if (expr2 instanceof StringLiteral) { //string+string this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendWith((StringLiteral) expr2); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, PLUS); } } else if (expr1 instanceof StringLiteral) { if (expr2 instanceof StringLiteral && ((expr1.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) == 0) { // string + string this.expressionStack[this.expressionPtr] = ((StringLiteral) expr1) .extendsWith((StringLiteral) expr2); } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); } } else { this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); } break; case LESS: case MULTIPLY: this.intPtr--; // star end position or starting position of angle bracket this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); break; default: this.expressionStack[this.expressionPtr] = new BinaryExpression(expr1, expr2, op); } }
From source file:org.nabucco.framework.mda.model.java.ast.produce.JavaAstModelProducer.java
License:Open Source License
public BinaryExpression createBinaryExpression(BinaryExpressionType type, Expression left, Expression right, Integer operator) {/*from www .j a va 2 s .co m*/ switch (type) { case AND_AND_EXPRESSION: return new AND_AND_Expression(left, right, operator); case OR_OR_EXPRESSION: return new OR_OR_Expression(left, right, operator); case BINARY_EXPRESSION: return new BinaryExpression(left, right, operator); case EQUAL_EXPRESSION: return new EqualExpression(left, right, operator); } return null; }
From source file:org.nabucco.framework.mda.template.java.extract.statement.JavaAstStatementExtractorVisitor.java
License:Open Source License
@Override public boolean visit(OR_OR_Expression orOrExpression, BlockScope scope) { Expression left = copy(orOrExpression.left, scope); Expression right = copy(orOrExpression.right, scope); OR_OR_Expression orCopy = new OR_OR_Expression(left, right, 0); orCopy.bits = orOrExpression.bits;//w w w .j av a 2s .c o m this.statement = orCopy; return false; }