/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.PrefixExpression, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit(PrefixExpression prefixExpression, BlockScope scope) { final int numberOfParens = (prefixExpression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(prefixExpression, numberOfParens); } int operator = prefixExpression.operator == OperatorIds.PLUS ? TerminalTokens.TokenNamePLUS_PLUS : TerminalTokens.TokenNameMINUS_MINUS; this.scribe.printNextToken(operator, this.preferences.insert_space_before_prefix_operator); if (this.preferences.insert_space_after_prefix_operator) { this.scribe.space(); } prefixExpression.lhs.traverse(this, scope); if (numberOfParens > 0) { manageClosingParenthesizedExpression(prefixExpression, numberOfParens); } return false; }
@Override public void endVisit(PrefixExpression x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JUnaryOperator op; switch (x.operator) { case OperatorIds.MINUS: op = JUnaryOperator.DEC; break; case OperatorIds.PLUS: op = JUnaryOperator.INC; break; default: throw new InternalCompilerException("Unexpected prefix operator"); } JExpression lhs = pop(x.lhs); push(new JPrefixOperation(info, op, lhs)); } catch (Throwable e) { throw translateException(x, e); } }
protected void consumeUnaryExpression(int op, boolean post) { // PreIncrementExpression ::= '++' PushPosition UnaryExpression // PreDecrementExpression ::= '--' PushPosition UnaryExpression // ++ and -- operators //optimize the push/pop //this.intStack has the position of the operator when prefix Expression leftHandSide = this.expressionStack[this.expressionPtr]; if (leftHandSide instanceof Reference) { // ++foo()++ is unvalid if (post) { this.expressionStack[this.expressionPtr] = new PostfixExpression( leftHandSide, IntLiteral.One, op, this.endStatementPosition); } else { this.expressionStack[this.expressionPtr] = new PrefixExpression( leftHandSide, IntLiteral.One, op, this.intStack[this.intPtr--]); } } else { //the ++ or the -- is NOT taken into account if code gen proceeds if (!post) { this.intPtr--; } if(!this.statementRecoveryActivated) problemReporter().invalidUnaryExpression(leftHandSide); } }
@Override public boolean visit(PrefixExpression node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
public boolean visit(PrefixExpression prefixExpression, BlockScope scope) { addRealFragment(prefixExpression); return false; }
@Override public boolean visit(PrefixExpression node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetExpression(node); return super.visit(node, scope); }