Skip to content

Commit 86d1078

Browse files
committed
Swift: Use shared SuccessorType.
1 parent fdcad17 commit 86d1078

File tree

6 files changed

+11
-98
lines changed

6 files changed

+11
-98
lines changed

swift/ql/lib/codeql/swift/controlflow/BasicBlocks.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
private import ControlFlowGraph
44
private import internal.ControlFlowGraphImpl as CfgImpl
5-
private import SuccessorTypes
65
private import CfgImpl::BasicBlocks as BasicBlocksImpl
76

87
/**

swift/ql/lib/codeql/swift/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
private import swift
44
private import BasicBlocks
5-
private import SuccessorTypes
65
private import internal.ControlFlowGraphImpl as CfgImpl
76
private import internal.Completion
87
private import internal.Scope
98
private import internal.ControlFlowElements
9+
import codeql.controlflow.SuccessorType
1010

1111
/** An AST node with an associated control-flow graph. */
1212
class CfgScope extends Scope instanceof CfgImpl::CfgScope::Range_ {
@@ -61,72 +61,3 @@ class ControlFlowNode extends CfgImpl::Node {
6161
/** Holds if this node has more than one successor. */
6262
final predicate isBranch() { strictcount(this.getASuccessor()) > 1 }
6363
}
64-
65-
/** The type of a control flow successor. */
66-
class SuccessorType extends CfgImpl::TSuccessorType {
67-
/** Gets a textual representation of successor type. */
68-
string toString() { none() }
69-
}
70-
71-
/** Provides different types of control flow successor types. */
72-
module SuccessorTypes {
73-
/** A normal control flow successor. */
74-
class NormalSuccessor extends SuccessorType, CfgImpl::TSuccessorSuccessor {
75-
final override string toString() { result = "successor" }
76-
}
77-
78-
/** A conditional control flow successor. */
79-
abstract class ConditionalSuccessor extends SuccessorType {
80-
boolean value;
81-
82-
bindingset[value]
83-
ConditionalSuccessor() { any() }
84-
85-
/** Gets the Boolean value of this successor. */
86-
final boolean getValue() { result = value }
87-
88-
override string toString() { result = this.getValue().toString() }
89-
}
90-
91-
/** A Boolean control flow successor. */
92-
class BooleanSuccessor extends ConditionalSuccessor, CfgImpl::TBooleanSuccessor {
93-
BooleanSuccessor() { this = CfgImpl::TBooleanSuccessor(value) }
94-
}
95-
96-
class BreakSuccessor extends SuccessorType, CfgImpl::TBreakSuccessor {
97-
final override string toString() { result = "break" }
98-
}
99-
100-
class ContinueSuccessor extends SuccessorType, CfgImpl::TContinueSuccessor {
101-
final override string toString() { result = "continue" }
102-
}
103-
104-
class ReturnSuccessor extends SuccessorType, CfgImpl::TReturnSuccessor {
105-
final override string toString() { result = "return" }
106-
}
107-
108-
class MatchingSuccessor extends ConditionalSuccessor, CfgImpl::TMatchingSuccessor {
109-
MatchingSuccessor() { this = CfgImpl::TMatchingSuccessor(value) }
110-
111-
/** Holds if this is a match successor. */
112-
predicate isMatch() { value = true }
113-
114-
override string toString() { if this.isMatch() then result = "match" else result = "no-match" }
115-
}
116-
117-
class FallthroughSuccessor extends SuccessorType, CfgImpl::TFallthroughSuccessor {
118-
final override string toString() { result = "fallthrough" }
119-
}
120-
121-
class EmptinessSuccessor extends ConditionalSuccessor, CfgImpl::TEmptinessSuccessor {
122-
EmptinessSuccessor() { this = CfgImpl::TEmptinessSuccessor(value) }
123-
124-
predicate isEmpty() { value = true }
125-
126-
override string toString() { if this.isEmpty() then result = "empty" else result = "non-empty" }
127-
}
128-
129-
class ExceptionSuccessor extends SuccessorType, CfgImpl::TExceptionSuccessor {
130-
override string toString() { result = "exception" }
131-
}
132-
}

swift/ql/lib/codeql/swift/controlflow/internal/Completion.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ private import swift
88
private import codeql.swift.controlflow.ControlFlowGraph
99
private import ControlFlowElements
1010
private import ControlFlowGraphImpl
11-
private import SuccessorTypes
1211

1312
private newtype TCompletion =
1413
TSimpleCompletion() or
@@ -324,7 +323,7 @@ abstract class NormalCompletion extends Completion {
324323

325324
/** A simple (normal) completion. */
326325
class SimpleCompletion extends NormalCompletion, TSimpleCompletion {
327-
override NormalSuccessor getAMatchingSuccessorType() { any() }
326+
override DirectSuccessor getAMatchingSuccessorType() { any() }
328327

329328
override string toString() { result = "simple" }
330329
}
@@ -468,7 +467,7 @@ class FallthroughCompletion extends Completion, TFallthroughCompletion {
468467

469468
FallthroughCompletion() { this = TFallthroughCompletion(dest) }
470469

471-
override FallthroughSuccessor getAMatchingSuccessorType() { any() }
470+
override DirectSuccessor getAMatchingSuccessorType() { any() }
472471

473472
CaseStmt getDestination() { result = dest }
474473

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,18 +1976,6 @@ private module Cached {
19761976
result = n.(FuncDeclElement).getAst() or
19771977
result = n.(KeyPathElement).getAst()
19781978
}
1979-
1980-
cached
1981-
newtype TSuccessorType =
1982-
TSuccessorSuccessor() or
1983-
TBooleanSuccessor(boolean b) { b in [false, true] } or
1984-
TBreakSuccessor() or
1985-
TContinueSuccessor() or
1986-
TReturnSuccessor() or
1987-
TMatchingSuccessor(boolean match) { match in [false, true] } or
1988-
TFallthroughSuccessor() or
1989-
TEmptinessSuccessor(boolean isEmpty) { isEmpty in [false, true] } or
1990-
TExceptionSuccessor()
19911979
}
19921980

19931981
import Cached

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImplSpecific.qll

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,18 @@ module CfgInput implements InputSig<Location> {
5757
* Hold if `c` represents simple (normal) evaluation of a statement or an
5858
* expression.
5959
*/
60-
predicate successorTypeIsSimple(SuccessorType t) {
61-
t instanceof Cfg::SuccessorTypes::NormalSuccessor
62-
}
60+
predicate successorTypeIsSimple(SuccessorType t) { t instanceof Cfg::DirectSuccessor }
6361

6462
/** Holds if `t` is an abnormal exit type out of a CFG scope. */
65-
predicate isAbnormalExitType(SuccessorType t) {
66-
t instanceof Cfg::SuccessorTypes::ExceptionSuccessor
67-
}
63+
predicate isAbnormalExitType(SuccessorType t) { t instanceof Cfg::ExceptionSuccessor }
6864

6965
/** Hold if `t` represents a conditional successor type. */
7066
predicate successorTypeIsCondition(SuccessorType t) {
71-
t instanceof Cfg::SuccessorTypes::BooleanSuccessor or
72-
t instanceof Cfg::SuccessorTypes::BreakSuccessor or
73-
t instanceof Cfg::SuccessorTypes::ContinueSuccessor or
74-
t instanceof Cfg::SuccessorTypes::MatchingSuccessor or
75-
t instanceof Cfg::SuccessorTypes::EmptinessSuccessor
67+
t instanceof Cfg::BooleanSuccessor or
68+
t instanceof Cfg::BreakSuccessor or
69+
t instanceof Cfg::ContinueSuccessor or
70+
t instanceof Cfg::MatchingSuccessor or
71+
t instanceof Cfg::EmptinessSuccessor
7672
}
7773

7874
/** Holds if `first` is first executed when entering `scope`. */

swift/ql/lib/codeql/swift/security/PathInjectionExtensions.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private class DefaultPathInjectionBarrier extends PathInjectionBarrier {
108108
TaintTracking::localTaint(validated, DataFlow::exprNode(normalize.getQualifier())) and
109109
DataFlow::localExprFlow(normalize, starts.getQualifier()) and
110110
DataFlow::localFlow(validated, this) and
111-
exists(ConditionBlock bb, SuccessorTypes::BooleanSuccessor b |
111+
exists(ConditionBlock bb, BooleanSuccessor b |
112112
bb.getANode().getNode().asAstNode().(IfStmt).getACondition() = getImmediateParent*(starts) and
113113
b.getValue() = true
114114
|

0 commit comments

Comments
 (0)