use of org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite.ReadBeforeWriteState in project intellij-community by JetBrains.
the class ControlFlowBuilderUtil method getReadsWithoutPriorWrites.
public static ReadWriteVariableInstruction[] getReadsWithoutPriorWrites(Instruction[] flow, boolean onlyFirstRead) {
DFAEngine<ReadBeforeWriteState> engine = new DFAEngine<>(flow, new ReadBeforeWriteInstance(buildNamesIndex(flow), onlyFirstRead), ReadBeforeWriteSemilattice.INSTANCE);
List<ReadBeforeWriteState> dfaResult = engine.performDFAWithTimeout();
if (dfaResult == null) {
return ReadWriteVariableInstruction.EMPTY_ARRAY;
}
List<ReadWriteVariableInstruction> result = new ArrayList<>();
BitSet reads = dfaResult.get(dfaResult.size() - 1).getReads();
for (int i = reads.nextSetBit(0); i >= 0; i = reads.nextSetBit(i + 1)) {
if (i == Integer.MAX_VALUE)
break;
result.add((ReadWriteVariableInstruction) flow[i]);
}
return result.toArray(ReadWriteVariableInstruction.EMPTY_ARRAY);
}
Aggregations