Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
bf9d0ed9
Commit
bf9d0ed9
authored
6 years ago
by
Daniil Ovchinnikov
Browse files
Options
Download
Email Patches
Plain Diff
[groovy] dfa: move DfaInstance#initial to Semilattice
parent
c561be93
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/control/finalVar/InvalidWriteAccessSearcher.java
+3
-2
...spection/control/finalVar/InvalidWriteAccessSearcher.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/control/finalVar/VariableInitializationChecker.java
+6
-5
...ction/control/finalVar/VariableInitializationChecker.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/dataflow/WritesCounterDFAInstance.java
+1
-21
...ovy/codeInspection/dataflow/WritesCounterDFAInstance.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/dataflow/WritesCounterSemilattice.java
+6
-0
...ovy/codeInspection/dataflow/WritesCounterSemilattice.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/utils/ControlFlowUtils.java
+11
-7
...plugins/groovy/codeInspection/utils/ControlFlowUtils.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAEngine.java
+3
-3
...jetbrains/plugins/groovy/lang/psi/dataFlow/DFAEngine.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DfaInstance.java
+1
-4
...tbrains/plugins/groovy/lang/psi/dataFlow/DfaInstance.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/Semilattice.java
+3
-0
...tbrains/plugins/groovy/lang/psi/dataFlow/Semilattice.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/reachingDefs/ReachingDefinitionsDfaInstance.java
+1
-7
...dataFlow/reachingDefs/ReachingDefinitionsDfaInstance.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/reachingDefs/ReachingDefinitionsSemilattice.java
+8
-15
...dataFlow/reachingDefs/ReachingDefinitionsSemilattice.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteInstance.kt
+2
-4
...vy/lang/psi/dataFlow/readWrite/ReadBeforeWriteInstance.kt
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteSemilattice.kt
+8
-18
...lang/psi/dataFlow/readWrite/ReadBeforeWriteSemilattice.kt
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteState.kt
+2
-20
...roovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteState.kt
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/types/TypeDfaInstance.java
+0
-6
...ugins/groovy/lang/psi/dataFlow/types/TypeDfaInstance.java
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/types/TypesSemilattice.java
+6
-0
...gins/groovy/lang/psi/dataFlow/types/TypesSemilattice.java
with
61 additions
and
112 deletions
+61
-112
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/control/finalVar/InvalidWriteAccessSearcher.java
+
3
-
2
View file @
bf9d0ed9
...
...
@@ -70,15 +70,16 @@ public class InvalidWriteAccessSearcher {
e
.
add
(((
ReadWriteVariableInstruction
)
instruction
).
getDescriptor
());
}
}
}
private
static
class
MySemilattice
implements
Semilattice
<
MyData
>
{
@NotNull
@Override
public
MyData
initial
()
{
return
new
MyData
();
}
}
private
static
class
MySemilattice
implements
Semilattice
<
MyData
>
{
@NotNull
@Override
public
MyData
join
(
@NotNull
List
<?
extends
MyData
>
ins
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/control/finalVar/VariableInitializationChecker.java
+
6
-
5
View file @
bf9d0ed9
...
...
@@ -6,9 +6,9 @@ import com.intellij.util.containers.ContainerUtil;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement
;
import
org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.VariableDescriptorFactory
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DFAEngine
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DfaInstance
;
...
...
@@ -63,16 +63,17 @@ public class VariableInitializationChecker {
}
}
private
final
VariableDescriptor
myVar
;
}
private
static
class
MySemilattice
implements
Semilattice
<
Data
>
{
@NotNull
@Override
public
Data
initial
()
{
return
new
Data
(
false
);
}
private
final
VariableDescriptor
myVar
;
}
private
static
class
MySemilattice
implements
Semilattice
<
Data
>
{
@NotNull
@Override
public
Data
join
(
@NotNull
List
<?
extends
Data
>
ins
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/dataflow/WritesCounterDFAInstance.java
+
1
-
21
View file @
bf9d0ed9
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.groovy.codeInspection.dataflow
;
import
com.intellij.psi.PsiElement
;
...
...
@@ -63,10 +49,4 @@ public class WritesCounterDFAInstance implements DfaInstance<TObjectIntHashMap<G
if
(
currentVal
==
0
||
currentVal
==
1
&&
!(
variable
.
getParent
()
instanceof
GrForInClause
))
currentVal
++;
map
.
put
(
variable
,
currentVal
);
}
@NotNull
@Override
public
TObjectIntHashMap
<
GrVariable
>
initial
()
{
return
new
TObjectIntHashMap
<>();
}
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/dataflow/WritesCounterSemilattice.java
+
6
-
0
View file @
bf9d0ed9
...
...
@@ -23,6 +23,12 @@ public class WritesCounterSemilattice<T> implements Semilattice<TObjectIntHashMa
});
}
@NotNull
@Override
public
TObjectIntHashMap
<
T
>
initial
()
{
return
new
TObjectIntHashMap
<>();
}
@NotNull
@Override
public
TObjectIntHashMap
<
T
>
join
(
@NotNull
List
<?
extends
TObjectIntHashMap
<
T
>>
ins
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/codeInspection/utils/ControlFlowUtils.java
+
11
-
7
View file @
bf9d0ed9
...
...
@@ -47,7 +47,10 @@ import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.AfterCallInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.*
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ControlFlowBuilder
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.IfEndInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.MaybeReturnInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl.ThrowingInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DFAEngine
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DfaInstance
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.Semilattice
;
...
...
@@ -771,6 +774,13 @@ public class ControlFlowUtils {
public
static
List
<
BitSet
>
inferWriteAccessMap
(
final
Instruction
[]
flow
,
final
GrVariable
var
)
{
final
Semilattice
<
BitSet
>
sem
=
new
Semilattice
<
BitSet
>()
{
@NotNull
@Override
public
BitSet
initial
()
{
return
new
BitSet
(
flow
.
length
);
}
@NotNull
@Override
public
BitSet
join
(
@NotNull
List
<?
extends
BitSet
>
ins
)
{
...
...
@@ -803,12 +813,6 @@ public class ControlFlowUtils {
bitSet
.
clear
();
bitSet
.
set
(
instruction
.
num
());
}
@NotNull
@Override
public
BitSet
initial
()
{
return
new
BitSet
(
flow
.
length
);
}
};
return
new
DFAEngine
<>(
flow
,
dfa
,
sem
).
performForceDFA
();
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DFAEngine.java
+
3
-
3
View file @
bf9d0ed9
...
...
@@ -19,12 +19,12 @@ import static org.jetbrains.plugins.groovy.lang.psi.controlFlow.OrderUtil.revers
public
class
DFAEngine
<
E
>
{
private
final
Instruction
[]
myFlow
;
private
final
DfaInstance
<
E
>
myDfa
;
private
final
DfaInstance
<
?
super
E
>
myDfa
;
private
final
Semilattice
<
E
>
mySemilattice
;
private
WorkCounter
myCounter
=
null
;
public
DFAEngine
(
@NotNull
Instruction
[]
flow
,
@NotNull
DfaInstance
<
E
>
dfa
,
@NotNull
Semilattice
<
E
>
semilattice
)
{
public
DFAEngine
(
@NotNull
Instruction
[]
flow
,
@NotNull
DfaInstance
<
?
super
E
>
dfa
,
@NotNull
Semilattice
<
E
>
semilattice
)
{
myFlow
=
flow
;
myDfa
=
dfa
;
mySemilattice
=
semilattice
;
...
...
@@ -67,7 +67,7 @@ public class DFAEngine<E> {
@Nullable
private
List
<
E
>
performDFA
(
boolean
timeout
)
{
final
int
n
=
myFlow
.
length
;
final
List
<
E
>
info
=
new
ArrayList
<>(
Collections
.
nCopies
(
n
,
my
Dfa
.
initial
()));
final
List
<
E
>
info
=
new
ArrayList
<>(
Collections
.
nCopies
(
n
,
my
Semilattice
.
initial
()));
final
CallEnvironment
env
=
new
MyCallEnvironment
(
n
);
final
WorkList
workList
=
new
WorkList
(
n
,
getFlowOrder
());
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/DfaInstance.java
+
1
-
4
View file @
bf9d0ed9
// Copyright 2000-201
8
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-201
9
JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.groovy.lang.psi.dataFlow
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -11,9 +11,6 @@ public interface DfaInstance<E> {
void
fun
(
@NotNull
E
e
,
@NotNull
Instruction
instruction
);
@NotNull
E
initial
();
default
boolean
isForward
()
{
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/Semilattice.java
+
3
-
0
View file @
bf9d0ed9
...
...
@@ -7,6 +7,9 @@ import java.util.List;
public
interface
Semilattice
<
E
>
{
@NotNull
E
initial
();
@NotNull
E
join
(
@NotNull
List
<?
extends
E
>
ins
);
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/reachingDefs/ReachingDefinitionsDfaInstance.java
+
1
-
7
View file @
bf9d0ed9
...
...
@@ -3,9 +3,9 @@ package org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs;
import
gnu.trove.TObjectIntHashMap
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction
;
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
;
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DfaInstance
;
import
java.util.Arrays
;
...
...
@@ -35,10 +35,4 @@ public class ReachingDefinitionsDfaInstance implements DfaInstance<DefinitionMap
}
}
}
@Override
@NotNull
public
DefinitionMap
initial
()
{
return
new
DefinitionMap
();
}
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/reachingDefs/ReachingDefinitionsSemilattice.java
+
8
-
15
View file @
bf9d0ed9
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.groovy.lang.psi.dataFlow.reachingDefs
;
import
org.jetbrains.annotations.NotNull
;
...
...
@@ -24,6 +10,13 @@ import java.util.List;
* @author ven
*/
public
class
ReachingDefinitionsSemilattice
implements
Semilattice
<
DefinitionMap
>
{
@Override
@NotNull
public
DefinitionMap
initial
()
{
return
new
DefinitionMap
();
}
@NotNull
@Override
public
DefinitionMap
join
(
@NotNull
List
<?
extends
DefinitionMap
>
ins
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteInstance.kt
+
2
-
4
View file @
bf9d0ed9
...
...
@@ -2,9 +2,9 @@
package
org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite
import
gnu.trove.TObjectIntHashMap
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.Instruction
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariableInstruction
import
org.jetbrains.plugins.groovy.lang.psi.controlFlow.VariableDescriptor
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.DfaInstance
class
ReadBeforeWriteInstance
(
...
...
@@ -30,7 +30,5 @@ class ReadBeforeWriteInstance(
}
}
override
fun
initial
():
ReadBeforeWriteState
=
ReadBeforeWriteState
.
bottom
override
fun
isReachable
():
Boolean
=
true
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteSemilattice.kt
+
8
-
18
View file @
bf9d0ed9
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite
import
org.jetbrains.plugins.groovy.lang.psi.dataFlow.Semilattice
object
ReadBeforeWriteSemilattice
:
Semilattice
<
ReadBeforeWriteState
>
{
private
val
bottom
:
ReadBeforeWriteState
=
ReadBeforeWriteState
()
override
fun
initial
():
ReadBeforeWriteState
=
bottom
override
fun
join
(
ins
:
MutableList
<
out
ReadBeforeWriteState
>):
ReadBeforeWriteState
{
val
states
=
ins
.
filter
{
it
!==
ReadBeforeWriteState
.
bottom
}
val
states
=
ins
.
filter
{
it
!==
bottom
}
if
(
states
.
isEmpty
())
return
ReadBeforeWriteState
()
val
iterator
=
states
.
iterator
()
val
accumulator
=
iterator
.
next
().
clone
()
// reduce optimized
...
...
@@ -34,7 +24,7 @@ object ReadBeforeWriteSemilattice : Semilattice<ReadBeforeWriteState> {
override
fun
eq
(
e1
:
ReadBeforeWriteState
,
e2
:
ReadBeforeWriteState
):
Boolean
{
if
(
e1
===
e2
)
return
true
if
(
e1
===
ReadBeforeWriteState
.
bottom
||
e2
===
ReadBeforeWriteState
.
bottom
)
return
e1
===
e2
if
(
e1
===
bottom
||
e2
===
bottom
)
return
e1
===
e2
return
e1
.
writes
==
e2
.
writes
&&
e1
.
reads
==
e2
.
reads
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/readWrite/ReadBeforeWriteState.kt
+
2
-
20
View file @
bf9d0ed9
/*
* Copyright 2000-2017 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.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.groovy.lang.psi.dataFlow.readWrite
...
...
@@ -23,11 +9,7 @@ class ReadBeforeWriteState(
val
reads
:
BitSet
=
BitSet
()
)
:
Cloneable
{
companion
object
{
val
bottom
:
ReadBeforeWriteState
=
ReadBeforeWriteState
()
}
public
override
fun
clone
():
ReadBeforeWriteState
=
ReadBeforeWriteState
(
writes
.
clone
()
as
BitSet
,
reads
.
clone
()
as
BitSet
)
override
fun
toString
():
String
=
"(writes=$writes, reads=$reads)"
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/types/TypeDfaInstance.java
+
0
-
6
View file @
bf9d0ed9
...
...
@@ -133,10 +133,4 @@ class TypeDfaInstance implements DfaInstance<TypeDfaState> {
entry
.
setValue
(
entry
.
getValue
().
negate
(
negation
));
}
}
@Override
@NotNull
public
TypeDfaState
initial
()
{
return
new
TypeDfaState
();
}
}
This diff is collapsed.
Click to expand it.
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/dataFlow/types/TypesSemilattice.java
+
6
-
0
View file @
bf9d0ed9
...
...
@@ -25,6 +25,12 @@ public class TypesSemilattice implements Semilattice<TypeDfaState> {
myManager
=
manager
;
}
@Override
@NotNull
public
TypeDfaState
initial
()
{
return
new
TypeDfaState
();
}
@NotNull
@Override
public
TypeDfaState
join
(
@NotNull
List
<?
extends
TypeDfaState
>
ins
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help