DfaValueFactory#createCommonValue

This commit is contained in:
Tagir Valeev
2018-04-17 10:53:58 +07:00
parent 128794aa97
commit 836f11c1f2
3 changed files with 19 additions and 6 deletions
@@ -631,19 +631,14 @@ public class CFGBuilder {
public CFGBuilder loopOver(PsiExpression[] expressions, DfaVariableValue targetVariable) {
DfaValueFactory factory = getFactory();
if (expressions.length > ControlFlowAnalyzer.MAX_UNROLL_SIZE) {
DfaValue loopElement = null;
for (PsiExpression expression : expressions) {
pushExpression(expression);
DfaValue expressionValue = factory.createValue(expression);
if (expressionValue == null) {
expressionValue = factory.createTypeValue(expression.getType(), NullnessUtil.getExpressionNullness(expression));
}
loopElement = loopElement == null ? expressionValue : loopElement.union(expressionValue);
pop();
}
ConditionalGotoInstruction condGoto = new ConditionalGotoInstruction(null, false, null);
condGoto.setOffset(myAnalyzer.getInstructionCount());
myBranches.add(() -> pushUnknown().add(condGoto));
DfaValue loopElement = factory.createCommonValue(expressions);
pushForWrite(targetVariable).push(loopElement).assign();
} else {
push(factory.getConstFactory().getSentinel());
@@ -16,10 +16,14 @@
package com.intellij.codeInspection.dataFlow.value;
import org.jetbrains.annotations.NotNull;
public class DfaUnknownValue extends DfaValue {
private static class DfaUnknownValueHolder {
private static final DfaUnknownValue myInstance = new DfaUnknownValue();
}
@NotNull
public static DfaUnknownValue getInstance() {
return DfaUnknownValueHolder.myInstance;
}
@@ -258,6 +258,20 @@ public class DfaValueFactory {
@NotNull
public DfaExpressionFactory getExpressionFactory() { return myExpressionFactory;}
@NotNull
public DfaValue createCommonValue(@NotNull PsiExpression[] expressions) {
DfaValue loopElement = null;
for (PsiExpression expression : expressions) {
DfaValue expressionValue = createValue(expression);
if (expressionValue == null) {
expressionValue = createTypeValue(expression.getType(), NullnessUtil.getExpressionNullness(expression));
}
loopElement = loopElement == null ? expressionValue : loopElement.union(expressionValue);
if (loopElement == DfaUnknownValue.getInstance()) break;
}
return loopElement == null ? DfaUnknownValue.getInstance() : loopElement;
}
private static class ClassInitializationInfo {
final boolean myCanInstantiateItself;
final boolean myCtorsCallMethods;