Skip to content

Commit a8c1b15

Browse files
committed
C#: Use shared SuccessorType.
1 parent d9989ce commit a8c1b15

File tree

20 files changed

+41
-383
lines changed

20 files changed

+41
-383
lines changed

csharp/ql/lib/semmle/code/csharp/Caching.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module Stages {
1010
cached
1111
module ControlFlowStage {
1212
private import semmle.code.csharp.controlflow.internal.Splitting
13-
private import semmle.code.csharp.controlflow.internal.SuccessorType
1413
private import semmle.code.csharp.controlflow.Guards as Guards
1514

1615
cached
@@ -20,8 +19,6 @@ module Stages {
2019
private predicate forceCachingInSameStageRev() {
2120
exists(Split s)
2221
or
23-
exists(SuccessorType st)
24-
or
2522
exists(ControlFlow::Node n)
2623
or
2724
Guards::Internal::isCustomNullCheck(_, _, _, _)

csharp/ql/lib/semmle/code/csharp/commons/Constants.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ private import semmle.code.csharp.commons.StructuralComparison as StructuralComp
66

77
pragma[noinline]
88
private predicate isConstantCondition0(ControlFlow::Node cfn, boolean b) {
9-
exists(
10-
cfn.getASuccessorByType(any(ControlFlow::SuccessorTypes::BooleanSuccessor t | t.getValue() = b))
11-
) and
9+
exists(cfn.getASuccessorByType(any(ControlFlow::BooleanSuccessor t | t.getValue() = b))) and
1210
strictcount(ControlFlow::SuccessorType t | exists(cfn.getASuccessorByType(t))) = 1
1311
}
1412

csharp/ql/lib/semmle/code/csharp/controlflow/BasicBlocks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import csharp
6-
private import ControlFlow::SuccessorTypes
6+
private import ControlFlow
77
private import semmle.code.csharp.controlflow.internal.ControlFlowGraphImpl as CfgImpl
88
private import CfgImpl::BasicBlocks as BasicBlocksImpl
99

csharp/ql/lib/semmle/code/csharp/controlflow/ControlFlowElement.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ private import semmle.code.csharp.ExprOrStmtParent
55
private import semmle.code.csharp.commons.Compilation
66
private import ControlFlow
77
private import ControlFlow::BasicBlocks
8-
private import SuccessorTypes
98
private import semmle.code.csharp.Caching
109
private import internal.ControlFlowGraphImpl as Impl
1110

csharp/ql/lib/semmle/code/csharp/controlflow/ControlFlowGraph.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import csharp
66
module ControlFlow {
77
private import semmle.code.csharp.controlflow.BasicBlocks as BBs
88
import semmle.code.csharp.controlflow.internal.SuccessorType
9-
private import SuccessorTypes
109
private import internal.ControlFlowGraphImpl as Impl
1110
private import internal.Splitting as Splitting
1211

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import csharp
6-
private import ControlFlow::SuccessorTypes
6+
private import ControlFlow
77
private import semmle.code.csharp.commons.Assertions
88
private import semmle.code.csharp.commons.ComparisonTest
99
private import semmle.code.csharp.commons.StructuralComparison as SC

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Completion.qll

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ private import semmle.code.csharp.frameworks.System
2626
private import ControlFlowGraphImpl
2727
private import NonReturning
2828
private import SuccessorType
29-
private import SuccessorTypes
3029

3130
private newtype TCompletion =
3231
TSimpleCompletion() or
@@ -575,7 +574,7 @@ abstract private class NonNestedNormalCompletion extends NormalCompletion { }
575574

576575
/** A simple (normal) completion. */
577576
class SimpleCompletion extends NonNestedNormalCompletion, TSimpleCompletion {
578-
override NormalSuccessor getAMatchingSuccessorType() { any() }
577+
override DirectSuccessor getAMatchingSuccessorType() { any() }
579578

580579
override string toString() { result = "normal" }
581580
}
@@ -759,7 +758,7 @@ class NestedCompletion extends Completion, TNestedCompletion {
759758
*
760759
* The `break` on line 3 completes with a `TBreakCompletion`, therefore
761760
* the `while` loop can complete with a `NestedBreakCompletion`, so we
762-
* get an edge `break --break--> return`. (If we instead used a
761+
* get an edge `break --jump--> return`. (If we instead used a
763762
* `TSimpleCompletion`, we would get a less precise edge
764763
* `break --normal--> return`.)
765764
*/
@@ -782,7 +781,7 @@ class NestedBreakCompletion extends NormalCompletion, NestedCompletion {
782781

783782
override SuccessorType getAMatchingSuccessorType() {
784783
outer instanceof SimpleCompletion and
785-
result instanceof BreakSuccessor
784+
result instanceof JumpSuccessor
786785
or
787786
result = outer.(ConditionalCompletion).getAMatchingSuccessorType()
788787
}
@@ -817,7 +816,7 @@ class BreakCompletion extends Completion {
817816
this = TNestedCompletion(_, TBreakCompletion(), _)
818817
}
819818

820-
override BreakSuccessor getAMatchingSuccessorType() { any() }
819+
override JumpSuccessor getAMatchingSuccessorType() { any() }
821820

822821
override string toString() {
823822
// `NestedCompletion` defines `toString()` for the other case
@@ -836,7 +835,7 @@ class ContinueCompletion extends Completion {
836835
this = TNestedCompletion(_, TContinueCompletion(), _)
837836
}
838837

839-
override ContinueSuccessor getAMatchingSuccessorType() { any() }
838+
override JumpSuccessor getAMatchingSuccessorType() { any() }
840839

841840
override string toString() {
842841
// `NestedCompletion` defines `toString()` for the other case
@@ -859,7 +858,7 @@ class GotoCompletion extends Completion {
859858
/** Gets the label of the `goto` completion. */
860859
string getLabel() { result = label }
861860

862-
override GotoSuccessor getAMatchingSuccessorType() { result.getLabel() = label }
861+
override JumpSuccessor getAMatchingSuccessorType() { any() }
863862

864863
override string toString() {
865864
// `NestedCompletion` defines `toString()` for the other case
@@ -882,7 +881,7 @@ class ThrowCompletion extends Completion {
882881
/** Gets the type of the exception being thrown. */
883882
ExceptionClass getExceptionClass() { result = ec }
884883

885-
override ExceptionSuccessor getAMatchingSuccessorType() { result.getExceptionClass() = ec }
884+
override ExceptionSuccessor getAMatchingSuccessorType() { any() }
886885

887886
override string toString() {
888887
// `NestedCompletion` defines `toString()` for the other case

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,13 @@ private module CfgInput implements CfgShared::InputSig<Location> {
8383

8484
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
8585

86-
predicate successorTypeIsSimple(SuccessorType t) {
87-
t instanceof ST::SuccessorTypes::NormalSuccessor
88-
}
86+
predicate successorTypeIsSimple(SuccessorType t) { t instanceof ST::DirectSuccessor }
8987

90-
predicate successorTypeIsCondition(SuccessorType t) {
91-
t instanceof ST::SuccessorTypes::ConditionalSuccessor
92-
}
88+
predicate successorTypeIsCondition(SuccessorType t) { t instanceof ST::ConditionalSuccessor }
9389

9490
predicate isAbnormalExitType(SuccessorType t) {
95-
t instanceof ST::SuccessorTypes::ExceptionSuccessor or
96-
t instanceof ST::SuccessorTypes::ExitSuccessor
91+
t instanceof ST::ExceptionSuccessor or
92+
t instanceof ST::ExitSuccessor
9793
}
9894

9995
int idOfAstNode(AstNode node) { result = node.getId() }

csharp/ql/lib/semmle/code/csharp/controlflow/internal/PreBasicBlocks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ConditionBlock extends PreBasicBlock {
119119
}
120120

121121
pragma[nomagic]
122-
predicate controls(PreBasicBlock controlled, Cfg::SuccessorTypes::ConditionalSuccessor s) {
122+
predicate controls(PreBasicBlock controlled, Cfg::ConditionalSuccessor s) {
123123
exists(PreBasicBlock succ, ConditionalCompletion c | this.immediatelyControls(succ, c) |
124124
succ.dominates(controlled) and
125125
s = c.getAMatchingSuccessorType()

csharp/ql/lib/semmle/code/csharp/controlflow/internal/Splitting.qll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,18 @@ module FinallySplitting {
470470
* then the `finally` block must end with a `return` as well (provided that
471471
* the `finally` block exits normally).
472472
*/
473-
class FinallySplitType extends Cfg::SuccessorType {
474-
FinallySplitType() { not this instanceof Cfg::SuccessorTypes::ConditionalSuccessor }
473+
class FinallySplitType instanceof Cfg::SuccessorType {
474+
FinallySplitType() { not this instanceof Cfg::ConditionalSuccessor }
475+
476+
string toString() { result = super.toString() }
475477

476478
/** Holds if this split type matches entry into a `finally` block with completion `c`. */
477479
predicate isSplitForEntryCompletion(Completion c) {
478480
if c instanceof NormalCompletion
479481
then
480482
// If the entry into the `finally` block completes with any normal completion,
481483
// it simply means normal execution after the `finally` block
482-
this instanceof Cfg::SuccessorTypes::NormalSuccessor
484+
this instanceof Cfg::DirectSuccessor
483485
else this = c.getAMatchingSuccessorType()
484486
}
485487
}
@@ -533,7 +535,7 @@ module FinallySplitting {
533535
int getNestLevel() { result = nestLevel }
534536

535537
override string toString() {
536-
if type instanceof Cfg::SuccessorTypes::NormalSuccessor
538+
if type instanceof Cfg::DirectSuccessor
537539
then result = ""
538540
else
539541
if nestLevel > 0
@@ -617,14 +619,14 @@ module FinallySplitting {
617619
or
618620
not c instanceof NormalCompletion
619621
or
620-
type instanceof Cfg::SuccessorTypes::NormalSuccessor
622+
type instanceof Cfg::DirectSuccessor
621623
)
622624
else (
623625
// Finally block can exit with completion `c` inherited from try/catch
624626
// block: must match this split
625627
inherited = true and
626628
type = c.getAMatchingSuccessorType() and
627-
not type instanceof Cfg::SuccessorTypes::NormalSuccessor
629+
not type instanceof Cfg::DirectSuccessor
628630
)
629631
)
630632
or
@@ -657,7 +659,7 @@ module FinallySplitting {
657659
exists(FinallySplit outer |
658660
outer.getNestLevel() = super.getNestLevel() - 1 and
659661
outer.(FinallySplitImpl).exit(pred, c, inherited) and
660-
super.getType() instanceof Cfg::SuccessorTypes::NormalSuccessor and
662+
super.getType() instanceof Cfg::DirectSuccessor and
661663
inherited = true
662664
)
663665
}

0 commit comments

Comments
 (0)