Search in sources :

Example 1 with ReadBeforeWriteState

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);
}
Also used : DFAEngine(org.jetbrains.plugins.groovy.lang.psi.dataFlow.DFAEngine) ReadBeforeWriteInstance(org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite.ReadBeforeWriteInstance) ReadBeforeWriteState(org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite.ReadBeforeWriteState) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet)

Aggregations

ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 DFAEngine (org.jetbrains.plugins.groovy.lang.psi.dataFlow.DFAEngine)1 ReadBeforeWriteInstance (org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite.ReadBeforeWriteInstance)1 ReadBeforeWriteState (org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite.ReadBeforeWriteState)1