public void invalidOperator(CompoundAssignment assign, TypeBinding leftType, TypeBinding rightType) { String leftName = new String(leftType.readableName()); String rightName = new String(rightType.readableName()); String leftShortName = new String(leftType.shortReadableName()); String rightShortName = new String(rightType.shortReadableName()); if (leftShortName.equals(rightShortName)){ leftShortName = leftName; rightShortName = rightName; } this.handle( IProblem.InvalidOperator, new String[] { assign.operatorToString(), leftName + ", " + rightName}, //$NON-NLS-1$ new String[] { assign.operatorToString(), leftShortName + ", " + rightShortName}, //$NON-NLS-1$ assign.sourceStart, assign.sourceEnd); }
public void operatorOnlyValidOnNumericType(CompoundAssignment assignment, TypeBinding leftType, TypeBinding rightType) { String leftName = new String(leftType.readableName()); String rightName = new String(rightType.readableName()); String leftShortName = new String(leftType.shortReadableName()); String rightShortName = new String(rightType.shortReadableName()); if (leftShortName.equals(rightShortName)){ leftShortName = leftName; rightShortName = rightName; } this.handle( IProblem.TypeMismatch, new String[] {leftName, rightName }, new String[] {leftShortName, rightShortName }, assignment.sourceStart, assignment.sourceEnd); }
protected void consumeAssignment() { // Assignment ::= LeftHandSide AssignmentOperator AssignmentExpression //optimize the push/pop int op = this.intStack[this.intPtr--] ; //<--the encoded operator this.expressionPtr -- ; this.expressionLengthPtr -- ; Expression expression = this.expressionStack[this.expressionPtr+1]; this.expressionStack[this.expressionPtr] = (op != EQUAL ) ? new CompoundAssignment( this.expressionStack[this.expressionPtr] , expression, op, expression.sourceEnd): new Assignment( this.expressionStack[this.expressionPtr] , expression, expression.sourceEnd); if (this.pendingRecoveredType != null) { // Used only in statements recovery. // This is not a real assignment but a placeholder for an existing anonymous type. // The assignment must be replace by the anonymous type. if (this.pendingRecoveredType.allocation != null && this.scanner.startPosition - 1 <= this.pendingRecoveredType.declarationSourceEnd) { this.expressionStack[this.expressionPtr] = this.pendingRecoveredType.allocation; this.pendingRecoveredType = null; return; } this.pendingRecoveredType = null; } }
@Override public boolean visit(CompoundAssignment node, BlockScope scope) { fixPositions(setGeneratedBy(node, source)); return super.visit(node, scope); }
public boolean visit( CompoundAssignment compoundAssignment, BlockScope scope) { addRealFragment(compoundAssignment); return false; }
/** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.CompoundAssignment, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ public boolean visit( CompoundAssignment compoundAssignment, BlockScope scope) { final int numberOfParens = (compoundAssignment.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; if (numberOfParens > 0) { manageOpeningParenthesizedExpression(compoundAssignment, numberOfParens); } compoundAssignment.lhs.traverse(this, scope); /* * Print the operator */ int operator; switch(compoundAssignment.operator) { case OperatorIds.PLUS : operator = TerminalTokens.TokenNamePLUS_EQUAL; break; case OperatorIds.MINUS : operator = TerminalTokens.TokenNameMINUS_EQUAL; break; case OperatorIds.MULTIPLY : operator = TerminalTokens.TokenNameMULTIPLY_EQUAL; break; case OperatorIds.DIVIDE : operator = TerminalTokens.TokenNameDIVIDE_EQUAL; break; case OperatorIds.AND : operator = TerminalTokens.TokenNameAND_EQUAL; break; case OperatorIds.OR : operator = TerminalTokens.TokenNameOR_EQUAL; break; case OperatorIds.XOR : operator = TerminalTokens.TokenNameXOR_EQUAL; break; case OperatorIds.REMAINDER : operator = TerminalTokens.TokenNameREMAINDER_EQUAL; break; case OperatorIds.LEFT_SHIFT : operator = TerminalTokens.TokenNameLEFT_SHIFT_EQUAL; break; case OperatorIds.RIGHT_SHIFT : operator = TerminalTokens.TokenNameRIGHT_SHIFT_EQUAL; break; default: // OperatorIds.UNSIGNED_RIGHT_SHIFT : operator = TerminalTokens.TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL; } this.scribe.printNextToken(operator, this.preferences.insert_space_before_assignment_operator); if (this.preferences.insert_space_after_assignment_operator) { this.scribe.space(); } Alignment assignmentAlignment = this.scribe.createAlignment( Alignment.COMPOUND_ASSIGNMENT, this.preferences.alignment_for_assignment, Alignment.R_OUTERMOST, 1, this.scribe.scanner.currentPosition); this.scribe.enterAlignment(assignmentAlignment); boolean ok = false; do { try { this.scribe.alignFragment(assignmentAlignment, 0); compoundAssignment.expression.traverse(this, scope); ok = true; } catch(AlignmentException e){ this.scribe.redoAlignment(e); } } while (!ok); this.scribe.exitAlignment(assignmentAlignment, true); if (numberOfParens > 0) { manageClosingParenthesizedExpression(compoundAssignment, numberOfParens); } return false; }
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { boolean isStatic; FieldBinding codegenBinding = this.binding.original(); if (codegenBinding.canBeSeenBy(this.actualReceiverType, this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } else { this.receiver.generateCode(currentScope, codeStream, !(isStatic = codegenBinding.isStatic())); if (isStatic) { codeStream.aconst_null(); } // the actual stack is: receiver codeStream.dup(); // the actual stack is: receiver receiver codeStream.generateEmulatedReadAccessForField(codegenBinding); // the actual stack is: receiver value // receiver value // value receiver value dup_x1 or dup2_x1 if value required // value value receiver value dup_x1 or dup2_x1 // value value receiver pop or pop2 // value value receiver field generateEmulationForField // value value field receiver swap // value field receiver value field receiver dup2_x1 or dup2_x2 // value field receiver value pop2 // value field receiver newvalue generate constant + op // value store int typeID; switch (typeID = codegenBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : if (valueRequired) { codeStream.dup2_x1(); } codeStream.dup2_x1(); codeStream.pop2(); break; default : if (valueRequired) { codeStream.dup_x1(); } codeStream.dup_x1(); codeStream.pop(); break; } codeStream.generateEmulationForField(codegenBinding); codeStream.swap(); switch (typeID) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2_x2(); break; default : codeStream.dup2_x1(); break; } codeStream.pop2(); codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, codegenBinding.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(codegenBinding); } }
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { switch (this.bits & RestrictiveFlagMASK) { case Binding.FIELD : // assigning to a field FieldBinding codegenField = ((FieldBinding) this.binding).original(); if (codegenField.canBeSeenBy(getReceiverType(currentScope), this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } else { if (codegenField.isStatic()) { codeStream.aconst_null(); } else { if ((this.bits & DepthMASK) != 0) { // internal error, per construction we should have found it // not yet supported currentScope.problemReporter().needImplementation(this); } else { generateReceiver(codeStream); } } codeStream.generateEmulatedReadAccessForField(codegenField); if (valueRequired) { switch (codegenField.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default: codeStream.dup(); break; } } codeStream.generateEmulationForField(codegenField); switch (codegenField.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup_x2(); codeStream.pop(); if (codegenField.isStatic()) { codeStream.aconst_null(); } else { generateReceiver(codeStream); } codeStream.dup_x2(); codeStream.pop(); break; default: codeStream.dup_x1(); codeStream.pop(); if (codegenField.isStatic()) { codeStream.aconst_null(); } else { generateReceiver(codeStream); } codeStream.dup_x1(); codeStream.pop(); break; } codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, codegenField.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(codegenField); } return; case Binding.LOCAL : // assigning to a local variable super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); } }
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); codeStream.generateEmulatedReadAccessForField(lastFieldBinding); if (valueRequired) { switch (lastFieldBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default : codeStream.dup(); break; } } codeStream.generateEmulationForField(lastFieldBinding); if ((TypeBinding.equalsEquals(lastFieldBinding.type, TypeBinding.LONG)) || (TypeBinding.equalsEquals(lastFieldBinding.type, TypeBinding.DOUBLE))) { codeStream.dup_x2(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x2(); codeStream.pop(); } else { codeStream.dup_x1(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x1(); codeStream.pop(); } codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, lastFieldBinding.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(lastFieldBinding); }
public void generatePostIncrement(BlockScope currentScope, CodeStream codeStream, CompoundAssignment postIncrement, boolean valueRequired) { FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generatePostIncrement(currentScope, codeStream, postIncrement, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); codeStream.generateEmulatedReadAccessForField(lastFieldBinding); if (valueRequired) { switch (lastFieldBinding.type.id) { case TypeIds.T_long : case TypeIds.T_double : codeStream.dup2(); break; default : codeStream.dup(); break; } } codeStream.generateEmulationForField(lastFieldBinding); if ((lastFieldBinding.type == TypeBinding.LONG) || (lastFieldBinding.type == TypeBinding.DOUBLE)) { codeStream.dup_x2(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x2(); codeStream.pop(); } else { codeStream.dup_x1(); codeStream.pop(); if (lastFieldBinding.isStatic()) { codeStream.aconst_null(); } else { generateReadSequence(currentScope, codeStream); } codeStream.dup_x1(); codeStream.pop(); } codeStream.generateConstant(postIncrement.expression.constant, this.implicitConversion); codeStream.sendOperator(postIncrement.operator, lastFieldBinding.type.id); codeStream.generateImplicitConversion(postIncrement.preAssignImplicitConversion); codeStream.generateEmulatedWriteAccessForField(lastFieldBinding); }
@Override public void endVisit(CompoundAssignment x, BlockScope scope) { JBinaryOperator op; switch (x.operator) { case OperatorIds.PLUS: if (javaLangString == typeMap.get(x.resolvedType)) { op = JBinaryOperator.ASG_CONCAT; } else { op = JBinaryOperator.ASG_ADD; } break; case OperatorIds.MINUS: op = JBinaryOperator.ASG_SUB; break; case OperatorIds.MULTIPLY: op = JBinaryOperator.ASG_MUL; break; case OperatorIds.DIVIDE: op = JBinaryOperator.ASG_DIV; break; case OperatorIds.AND: op = JBinaryOperator.ASG_BIT_AND; break; case OperatorIds.OR: op = JBinaryOperator.ASG_BIT_OR; break; case OperatorIds.XOR: op = JBinaryOperator.ASG_BIT_XOR; break; case OperatorIds.REMAINDER: op = JBinaryOperator.ASG_MOD; break; case OperatorIds.LEFT_SHIFT: op = JBinaryOperator.ASG_SHL; break; case OperatorIds.RIGHT_SHIFT: op = JBinaryOperator.ASG_SHR; break; case OperatorIds.UNSIGNED_RIGHT_SHIFT: op = JBinaryOperator.ASG_SHRU; break; default: throw translateException(x, new InternalCompilerException( "Unexpected operator for CompoundAssignment")); } pushBinaryOp(x, op); }
@Override public boolean visit(CompoundAssignment node, BlockScope scope) { setGeneratedBy(node, source); applyOffsetExpression(node); return super.visit(node, scope); }