mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DfaCondition: cosmetic fixes
GitOrigin-RevId: 3f73e3ce19daafa66a8cbb4e3d1d74e668da580d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fc4b62066d
commit
c3e78325e1
+1
-1
@@ -127,7 +127,7 @@ public class ExpressionTypeMemoryState extends DfaMemoryStateImpl {
|
||||
if (!negated) {
|
||||
setExpressionType(value.getExpression(), value.getCastType());
|
||||
}
|
||||
return super.applyCondition(negated ? value.getRelation().createNegated() : value.getRelation());
|
||||
return super.applyCondition(negated ? value.getRelation().negate() : value.getRelation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-12
@@ -248,18 +248,8 @@ public abstract class InstructionVisitor {
|
||||
}
|
||||
|
||||
public DfaInstructionState[] visitConditionalGoto(ConditionalGotoInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
|
||||
DfaCondition cond = memState.pop().eq(runner.getFactory().getConstFactory().getTrue());
|
||||
|
||||
DfaCondition condTrue;
|
||||
DfaCondition condFalse;
|
||||
|
||||
if (instruction.isNegated()) {
|
||||
condFalse = cond;
|
||||
condTrue = cond.createNegated();
|
||||
} else {
|
||||
condTrue = cond;
|
||||
condFalse = cond.createNegated();
|
||||
}
|
||||
DfaCondition condTrue = memState.pop().eq(runner.getFactory().getBoolean(!instruction.isNegated()));
|
||||
DfaCondition condFalse = condTrue.negate();
|
||||
|
||||
if (condTrue == DfaCondition.getTrue()) {
|
||||
markBranchReachable(instruction, true);
|
||||
|
||||
+3
-3
@@ -464,7 +464,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
for (ContractValue contractValue : contract.getConditions()) {
|
||||
DfaCondition condition = contractValue.makeCondition(factory, callState.myCallArguments);
|
||||
DfaMemoryState falseState = state.createCopy();
|
||||
DfaCondition falseCondition = condition.createNegated();
|
||||
DfaCondition falseCondition = condition.negate();
|
||||
if (contract.getReturnValue().isFail() ?
|
||||
falseState.applyCondition(falseCondition) :
|
||||
falseState.applyContractCondition(falseCondition)) {
|
||||
@@ -797,7 +797,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
if (equality.applyCondition(condition)) {
|
||||
states.add(makeBooleanResult(instruction, runner, equality, ThreeState.UNSURE));
|
||||
}
|
||||
if (memState.applyCondition(condition.createNegated())) {
|
||||
if (memState.applyCondition(condition.negate())) {
|
||||
states.add(makeBooleanResult(instruction, runner, memState, ThreeState.fromBoolean(relationType == RelationType.NE)));
|
||||
}
|
||||
return states.toArray(DfaInstructionState.EMPTY_ARRAY);
|
||||
@@ -890,7 +890,7 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
if (trueState.applyCondition(condition)) {
|
||||
states.add(makeBooleanResult(instruction, runner, trueState, unknownTargetType ? ThreeState.UNSURE : ThreeState.YES));
|
||||
}
|
||||
DfaCondition negated = condition.createNegated();
|
||||
DfaCondition negated = condition.negate();
|
||||
if (unknownTargetType ? memState.applyContractCondition(negated) : memState.applyCondition(negated)) {
|
||||
states.add(makeBooleanResult(instruction, runner, memState, ThreeState.NO));
|
||||
useful |= !memState.isNull(dfaLeft);
|
||||
|
||||
+6
-3
@@ -18,10 +18,13 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class DfaCondition {
|
||||
// To prevent inheritors outside of the package
|
||||
DfaCondition() {}
|
||||
|
||||
|
||||
/**
|
||||
* @return a condition which is the opposite to this condition
|
||||
*/
|
||||
@NotNull
|
||||
@Contract(pure = true)
|
||||
public abstract DfaCondition createNegated();
|
||||
public abstract DfaCondition negate();
|
||||
|
||||
/**
|
||||
* @return always true condition; singleton object
|
||||
@@ -77,7 +80,7 @@ public abstract class DfaCondition {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DfaCondition createNegated() {
|
||||
public DfaCondition negate() {
|
||||
if (this == TRUE) return FALSE;
|
||||
if (this == FALSE) return TRUE;
|
||||
return UNKNOWN;
|
||||
|
||||
+9
-17
@@ -27,8 +27,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
public final class DfaRelation extends DfaCondition {
|
||||
@NotNull
|
||||
@Override
|
||||
public DfaRelation createNegated() {
|
||||
return createCanonicalRelation(myLeftOperand, myRelation.getNegated(), myRightOperand);
|
||||
public DfaRelation negate() {
|
||||
return new DfaRelation(myLeftOperand, myRightOperand, myRelation.getNegated());
|
||||
}
|
||||
|
||||
private @NotNull final DfaValue myLeftOperand;
|
||||
@@ -54,16 +54,16 @@ public final class DfaRelation extends DfaCondition {
|
||||
public static DfaRelation createRelation(@NotNull DfaValue dfaLeft, @NotNull RelationType relationType, @NotNull DfaValue dfaRight) {
|
||||
if ((relationType == RelationType.IS || relationType == RelationType.IS_NOT) &&
|
||||
dfaRight instanceof DfaFactMapValue && !(dfaLeft instanceof DfaFactMapValue)) {
|
||||
return createCanonicalRelation(dfaLeft, relationType, dfaRight);
|
||||
return new DfaRelation(dfaLeft, dfaRight, relationType);
|
||||
}
|
||||
if (dfaLeft instanceof DfaVariableValue || dfaLeft instanceof DfaBoxedValue || dfaLeft instanceof DfaBinOpValue
|
||||
|| dfaRight instanceof DfaVariableValue || dfaRight instanceof DfaBoxedValue || dfaRight instanceof DfaBinOpValue) {
|
||||
if (!(dfaLeft instanceof DfaVariableValue || dfaLeft instanceof DfaBoxedValue || dfaLeft instanceof DfaBinOpValue) ||
|
||||
(dfaRight instanceof DfaBinOpValue && !(dfaLeft instanceof DfaBinOpValue))) {
|
||||
RelationType flipped = relationType.getFlipped();
|
||||
return flipped == null ? null : createCanonicalRelation(dfaRight, flipped, dfaLeft);
|
||||
return flipped == null ? null : new DfaRelation(dfaRight, dfaLeft, flipped);
|
||||
}
|
||||
return createCanonicalRelation(dfaLeft, relationType, dfaRight);
|
||||
return new DfaRelation(dfaLeft, dfaRight, relationType);
|
||||
}
|
||||
if (dfaLeft instanceof DfaFactMapValue && dfaRight instanceof DfaConstValue) {
|
||||
return createConstBasedRelation((DfaFactMapValue)dfaLeft, relationType, (DfaConstValue)dfaRight);
|
||||
@@ -72,10 +72,10 @@ public final class DfaRelation extends DfaCondition {
|
||||
return createConstBasedRelation((DfaFactMapValue)dfaRight, relationType, (DfaConstValue)dfaLeft);
|
||||
}
|
||||
if (dfaLeft instanceof DfaInstanceofValue && dfaRight instanceof DfaConstValue) {
|
||||
return createCanonicalRelation(dfaLeft, relationType, dfaRight);
|
||||
return new DfaRelation(dfaLeft, dfaRight, relationType);
|
||||
}
|
||||
if (dfaLeft instanceof DfaConstValue && dfaRight instanceof DfaInstanceofValue) {
|
||||
return createCanonicalRelation(dfaRight, relationType, dfaLeft);
|
||||
return new DfaRelation(dfaRight, dfaLeft, relationType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -83,17 +83,9 @@ public final class DfaRelation extends DfaCondition {
|
||||
@NotNull
|
||||
private static DfaRelation createConstBasedRelation(DfaFactMapValue dfaLeft, RelationType relationType, DfaConstValue dfaRight) {
|
||||
if (dfaRight.getValue() == null && DfaNullability.isNullable(dfaLeft.getFacts())) {
|
||||
return createCanonicalRelation(dfaLeft.getFactory().getFactValue(DfaFactType.NULLABILITY, DfaNullability.NULLABLE), relationType,
|
||||
dfaRight);
|
||||
return new DfaRelation(dfaLeft.getFactory().getFactValue(DfaFactType.NULLABILITY, DfaNullability.NULLABLE), dfaRight, relationType);
|
||||
}
|
||||
return createCanonicalRelation(DfaUnknownValue.getInstance(), relationType, dfaRight);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static DfaRelation createCanonicalRelation(@NotNull final DfaValue dfaLeft,
|
||||
@NotNull RelationType relationType,
|
||||
@NotNull final DfaValue dfaRight) {
|
||||
return new DfaRelation(dfaLeft, dfaRight, relationType);
|
||||
return new DfaRelation(DfaUnknownValue.getInstance(), dfaRight, relationType);
|
||||
}
|
||||
|
||||
public boolean isEquality() {
|
||||
|
||||
+3
-3
@@ -296,7 +296,7 @@ public class ReorderingUtils {
|
||||
ContractValue cond = conditions.get(0);
|
||||
DfaCondition value = cond.fromCall(myFactory, call);
|
||||
if (value instanceof DfaRelation) {
|
||||
if (myConditions.contains(retValue == negated ? value : ((DfaRelation)value).createNegated())) {
|
||||
if (myConditions.contains(retValue == negated ? value : ((DfaRelation)value).negate())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -315,12 +315,12 @@ public class ReorderingUtils {
|
||||
DfaCondition value1 = leftVal.cond(relationType, rightVal);
|
||||
DfaCondition value2 = rightVal.cond(Objects.requireNonNull(relationType.getFlipped()), leftVal);
|
||||
if (value1 instanceof DfaRelation) {
|
||||
if (myConditions.contains(negated ? value1 : ((DfaRelation)value1).createNegated())) {
|
||||
if (myConditions.contains(negated ? value1 : ((DfaRelation)value1).negate())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (value2 instanceof DfaRelation) {
|
||||
if (myConditions.contains(negated ? value2 : ((DfaRelation)value2).createNegated())) {
|
||||
if (myConditions.contains(negated ? value2 : ((DfaRelation)value2).negate())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user