use of org.jetbrains.plugins.groovy.lang.psi.dataFlow.DfaInstance in project intellij-community by JetBrains.
the class ControlFlowUtils method inferWriteAccessMap.
@NotNull
public static List<BitSet> inferWriteAccessMap(final Instruction[] flow, final GrVariable var) {
final Semilattice<BitSet> sem = new Semilattice<BitSet>() {
@NotNull
@Override
public BitSet join(@NotNull List<BitSet> ins) {
BitSet result = new BitSet(flow.length);
for (BitSet set : ins) {
result.or(set);
}
return result;
}
@Override
public boolean eq(@NotNull BitSet e1, @NotNull BitSet e2) {
return e1.equals(e2);
}
};
DfaInstance<BitSet> dfa = new DfaInstance<BitSet>() {
@Override
public void fun(@NotNull BitSet bitSet, @NotNull Instruction instruction) {
if (!(instruction instanceof ReadWriteVariableInstruction))
return;
if (!((ReadWriteVariableInstruction) instruction).isWrite())
return;
final PsiElement element = instruction.getElement();
if (element instanceof GrVariable && element != var)
return;
if (element instanceof GrReferenceExpression) {
final GrReferenceExpression ref = (GrReferenceExpression) element;
if (ref.isQualified() || ref.resolve() != var) {
return;
}
}
if (!((ReadWriteVariableInstruction) instruction).getVariableName().equals(var.getName())) {
return;
}
bitSet.clear();
bitSet.set(instruction.num());
}
@NotNull
@Override
public BitSet initial() {
return new BitSet(flow.length);
}
};
return new DFAEngine<>(flow, dfa, sem).performForceDFA();
}
Aggregations