ControlFlowAnalyzer: remove special handling for boolean XOR

The only special thing we need to do now is to replace XOR token with NE; this is done in BinopInstruction constructor

GitOrigin-RevId: c783785f812c6c3f950296205d3f8a57eac59976
This commit is contained in:
Tagir Valeev
2019-11-27 17:59:27 +07:00
committed by intellij-monorepo-bot
parent f8fec32e53
commit 774e67ce88
2 changed files with 3 additions and 24 deletions

View File

@@ -201,15 +201,11 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
IElementType op = expression.getOperationTokenType();
PsiType type = expression.getType();
boolean isBoolean = PsiType.BOOLEAN.equals(type);
if (op == JavaTokenType.EQ) {
lExpr.accept(this);
rExpr.accept(this);
generateBoxingUnboxingInstructionFor(rExpr, type);
}
else if (op == JavaTokenType.XOREQ && isBoolean) {
generateXorExpression(expression, new PsiExpression[]{lExpr, rExpr}, type, true);
}
else if (op == JavaTokenType.PLUSEQ && type != null && type.equalsToText(JAVA_LANG_STRING)) {
lExpr.accept(this);
addInstruction(new DupInstruction());
@@ -1341,9 +1337,6 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
else if (op == JavaTokenType.OROR) {
generateShortCircuitAndOr(expression, operands, type, false);
}
else if (op == JavaTokenType.XOR && PsiType.BOOLEAN.equals(type)) {
generateXorExpression(expression, operands, type, false);
}
else if (isBinaryDivision(op) && operands.length == 2 &&
type != null && PsiType.LONG.isAssignableFrom(type)) {
generateDivMod(expression, type, operands[0], operands[1]);
@@ -1455,22 +1448,6 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
}
}
private void generateXorExpression(PsiExpression expression, PsiExpression[] operands, final PsiType exprType, boolean forAssignment) {
PsiExpression operand = operands[0];
operand.accept(this);
if (forAssignment) {
addInstruction(new DupInstruction());
}
generateBoxingUnboxingInstructionFor(operand, exprType);
for (int i = 1; i < operands.length; i++) {
operand = operands[i];
operand.accept(this);
generateBoxingUnboxingInstructionFor(operand, exprType);
PsiExpression psiAnchor = expression.isPhysical() ? expression : null;
addInstruction(new BinopInstruction(JavaTokenType.NE, psiAnchor, exprType, i));
}
}
private void generateShortCircuitAndOr(PsiExpression expression, PsiExpression[] operands, PsiType exprType, boolean and) {
ControlFlow.DeferredOffset endOffset = new ControlFlow.DeferredOffset();
for (int i = 0; i < operands.length; i++) {

View File

@@ -69,7 +69,9 @@ public class BinopInstruction extends BranchingInstruction implements Expression
boolean unrolledLoop) {
super(psiAnchor);
myResultType = resultType;
myOperationSign = ourSignificantOperations.contains(opSign) ? opSign : null;
myOperationSign =
opSign == XOR && PsiType.BOOLEAN.equals(resultType) ? NE : // XOR for boolean is equivalent to NE
ourSignificantOperations.contains(opSign) ? opSign : null;
myLastOperand = lastOperand;
myUnrolledLoop = unrolledLoop;
}