From 440183c8e4a75beafdab1a7ec75563cf82c47ec2 Mon Sep 17 00:00:00 2001 From: Oleg Shpynov Date: Mon, 5 Apr 2010 17:25:45 +0400 Subject: [PATCH] Generalizing --- .../codeInsight/dataflow/DFAEngine.java | 20 +++++++-------- .../codeInsight/dataflow/DfaInstance.java | 4 +-- .../codeInsight/dataflow/Semilattice.java | 6 ++--- .../dataflow/{ => map}/DFAMap.java | 3 ++- .../dataflow/map/DFAMapEngine.java | 25 +++++++++++++++++++ .../dataflow/map/DfaMapInstance.java | 21 ++++++++++++++++ .../dataflow/map/MapSemilattice.java | 22 ++++++++++++++++ 7 files changed, 84 insertions(+), 17 deletions(-) rename platform/lang-impl/src/com/intellij/codeInsight/dataflow/{ => map}/DFAMap.java (97%) create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMapEngine.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DfaMapInstance.java create mode 100644 platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/MapSemilattice.java diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAEngine.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAEngine.java index 65908b8d7466..6967dbfefaca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAEngine.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAEngine.java @@ -39,18 +39,18 @@ public class DFAEngine { } - public List> performDFA() { - final ArrayList> info = new ArrayList>(myFlow.length); + public List performDFA() { + final ArrayList info = new ArrayList(myFlow.length); return performDFA(info); } - public List> performDFA(final List> info) { + public List performDFA(final List info) { if (LOG.isDebugEnabled()){ LOG.debug("Perfoming DFA\n" + "Instance: " + myDfa + " Semilattice: " + mySemilattice); } // initializing dfa - final DFAMap initial = myDfa.initial(); + final E initial = myDfa.initial(); for (int i = 0; i < myFlow.length; i++) { info.add(i, initial); } @@ -104,12 +104,12 @@ public class DFAEngine { } final int currentNumber = currentInstruction.num(); - final DFAMap oldE = info.get(currentNumber); - final DFAMap joinedE = join(currentInstruction, info); - final DFAMap newE = myDfa.fun(joinedE, currentInstruction); + final E oldE = info.get(currentNumber); + final E joinedE = join(currentInstruction, info); + final E newE = myDfa.fun(joinedE, currentInstruction); if (!mySemilattice.eq(newE, oldE)) { if (LOG.isDebugEnabled()){ - LOG.debug("Number: " + currentNumber + " old: " + oldE.keySet() + " new: " + newE.keySet()); + LOG.debug("Number: " + currentNumber + " old: " + oldE.toString() + " new: " + newE.toString()); } info.set(currentNumber, newE); for (Instruction next : getNext(currentInstruction)) { @@ -148,9 +148,9 @@ public class DFAEngine { return allPred * 2; } - private DFAMap join(final Instruction instruction, final List> info) { + private E join(final Instruction instruction, final List info) { final Iterable prev = myDfa.isForward() ? instruction.allPred() : instruction.allSucc(); - final ArrayList> prevInfos = new ArrayList>(); + final ArrayList prevInfos = new ArrayList(); for (Instruction i : prev) { prevInfos.add(info.get(i.num())); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DfaInstance.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DfaInstance.java index ce618834fe4b..894e54d0af5b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DfaInstance.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DfaInstance.java @@ -21,10 +21,10 @@ public interface DfaInstance { // Please ensure that E has correctly implemented equals method // Invariant: fun must create new instance of DFAMap if modifies it - DFAMap fun(DFAMap e, Instruction instruction); + E fun(E e, Instruction instruction); @NotNull - DFAMap initial(); + E initial(); boolean isForward(); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/Semilattice.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/Semilattice.java index 199ea50bd62d..0b1e89a7eaeb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/Semilattice.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/Semilattice.java @@ -17,9 +17,7 @@ package com.intellij.codeInsight.dataflow; import java.util.ArrayList; public interface Semilattice { - // Invariant: join can return unmodified ins(0) or empty DFAMap - // DfaInstance must create new one before modifying - DFAMap join(ArrayList> ins); + E join(ArrayList ins); - boolean eq(DFAMap e1, DFAMap e2); + boolean eq(E e1, E e2); } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAMap.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMap.java similarity index 97% rename from platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAMap.java rename to platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMap.java index 148a5942c3ec..9f7e1078ded4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/DFAMap.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMap.java @@ -1,5 +1,6 @@ -package com.intellij.codeInsight.dataflow; +package com.intellij.codeInsight.dataflow.map; +import com.intellij.codeInsight.dataflow.SetUtil; import org.jetbrains.annotations.Nullable; import java.util.*; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMapEngine.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMapEngine.java new file mode 100644 index 000000000000..d10c588a9bf2 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DFAMapEngine.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.dataflow.map; + +import com.intellij.codeInsight.controlflow.Instruction; +import com.intellij.codeInsight.dataflow.DFAEngine; + +public class DFAMapEngine extends DFAEngine>{ + public DFAMapEngine(final Instruction[] flow, final DfaMapInstance dfa, final MapSemilattice dfaMapSemilattice) { + super(flow, dfa, dfaMapSemilattice); + } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DfaMapInstance.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DfaMapInstance.java new file mode 100644 index 000000000000..e6bc73381c10 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/DfaMapInstance.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.dataflow.map; + +import com.intellij.codeInsight.dataflow.DfaInstance; + +public interface DfaMapInstance extends DfaInstance> { +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/MapSemilattice.java b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/MapSemilattice.java new file mode 100644 index 000000000000..fb3547b7d698 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInsight/dataflow/map/MapSemilattice.java @@ -0,0 +1,22 @@ +/* + * Copyright 2000-2007 JetBrains s.r.o. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.dataflow.map; + +import com.intellij.codeInsight.dataflow.Semilattice; + +public interface MapSemilattice extends Semilattice>{ + // Invariant: join can return unmodified ins(0) or empty DFAMap + // DfaInstance must create new one before modifying +} \ No newline at end of file