3
3
private import swift
4
4
private import BasicBlocks
5
5
private import ControlFlowGraph
6
- private import internal.ControlFlowGraphImpl
6
+ private import internal.ControlFlowGraphImpl as Impl
7
7
private import internal.ControlFlowElements
8
8
private import internal.Splitting
9
9
10
- /** An entry node for a given scope. */
11
- class EntryNode extends ControlFlowNode , TEntryNode {
12
- private CfgScope scope ;
13
-
14
- EntryNode ( ) { this = TEntryNode ( scope ) }
15
-
16
- final override EntryBasicBlock getBasicBlock ( ) { result = ControlFlowNode .super .getBasicBlock ( ) }
17
-
18
- final override Location getLocation ( ) { result = scope .getLocation ( ) }
19
-
20
- final override string toString ( ) { result = "enter " + scope }
21
- }
22
-
23
- /** An exit node for a given scope, annotated with the type of exit. */
24
- class AnnotatedExitNode extends ControlFlowNode , TAnnotatedExitNode {
25
- private CfgScope scope ;
26
- private boolean normal ;
27
-
28
- AnnotatedExitNode ( ) { this = TAnnotatedExitNode ( scope , normal ) }
29
-
30
- /** Holds if this node represent a normal exit. */
31
- final predicate isNormal ( ) { normal = true }
32
-
33
- final override AnnotatedExitBasicBlock getBasicBlock ( ) {
34
- result = ControlFlowNode .super .getBasicBlock ( )
35
- }
36
-
37
- final override Location getLocation ( ) { result = scope .getLocation ( ) }
38
-
39
- final override string toString ( ) {
40
- exists ( string s |
41
- normal = true and s = "normal"
42
- or
43
- normal = false and s = "abnormal"
44
- |
45
- result = "exit " + scope + " (" + s + ")"
46
- )
47
- }
48
- }
49
-
50
- /** An exit node for a given scope. */
51
- class ExitNode extends ControlFlowNode , TExitNode {
52
- private CfgScope scope ;
53
-
54
- ExitNode ( ) { this = TExitNode ( scope ) }
55
-
56
- final override Location getLocation ( ) { result = scope .getLocation ( ) }
57
-
58
- final override string toString ( ) { result = "exit " + scope }
59
- }
60
-
61
10
/**
62
11
* A node for an AST node.
63
12
*
64
13
* Each AST node maps to zero or more `CfgNode`s: zero when the node is unreachable
65
14
* (dead) code or not important for control flow, and multiple when there are different
66
15
* splits for the AST node.
67
16
*/
68
- class CfgNode extends ControlFlowNode , TElementNode {
69
- private Splits splits ;
70
- ControlFlowElement n ;
71
-
72
- CfgNode ( ) { this = TElementNode ( _, n , splits ) }
73
-
74
- final override ControlFlowElement getNode ( ) { result = n }
17
+ class CfgNode extends ControlFlowNode instanceof Impl:: AstCfgNode {
18
+ final override ControlFlowElement getNode ( ) { result = this .getAstNode ( ) }
75
19
76
- override Location getLocation ( ) { result = n .getLocation ( ) }
77
-
78
- final override string toString ( ) {
79
- exists ( string s | s = n .toString ( ) |
80
- result = "[" + this .getSplitsString ( ) + "] " + s
81
- or
82
- not exists ( this .getSplitsString ( ) ) and result = s
83
- )
84
- }
20
+ /** Gets a split for this control flow node, if any. */
21
+ final Split getASplit ( ) { result = super .getASplit ( ) }
85
22
86
23
/** Gets a comma-separated list of strings for each split in this node, if any. */
87
- final string getSplitsString ( ) {
88
- result = splits .toString ( ) and
89
- result != ""
90
- }
91
-
92
- /** Gets a split for this control flow node, if any. */
93
- final Split getASplit ( ) { result = splits .getASplit ( ) }
24
+ final string getSplitsString ( ) { result = super .getSplitsString ( ) }
94
25
95
26
/** Gets the AST representation of this control flow node, if any. */
96
27
Expr getAst ( ) {
97
- result = n .asAstNode ( )
28
+ result = this . getNode ( ) .asAstNode ( )
98
29
or
99
- result = n .( PropertyGetterElement ) .getRef ( )
30
+ result = this . getNode ( ) .( PropertyGetterElement ) .getRef ( )
100
31
or
101
- result = n .( PropertySetterElement ) .getAssignExpr ( )
32
+ result = this . getNode ( ) .( PropertySetterElement ) .getAssignExpr ( )
102
33
or
103
- result = n .( PropertyObserverElement ) .getAssignExpr ( )
34
+ result = this . getNode ( ) .( PropertyObserverElement ) .getAssignExpr ( )
104
35
or
105
- result = n .( ClosureElement ) .getAst ( )
36
+ result = this . getNode ( ) .( ClosureElement ) .getAst ( )
106
37
or
107
- result = n .( KeyPathElement ) .getAst ( )
38
+ result = this . getNode ( ) .( KeyPathElement ) .getAst ( )
108
39
}
109
40
}
110
41
@@ -130,7 +61,9 @@ class PatternCfgNode extends CfgNode {
130
61
131
62
/** A control-flow node that wraps a property getter. */
132
63
class PropertyGetterCfgNode extends CfgNode {
133
- override PropertyGetterElement n ;
64
+ PropertyGetterElement n ;
65
+
66
+ PropertyGetterCfgNode ( ) { n = this .getAstNode ( ) }
134
67
135
68
Expr getRef ( ) { result = n .getRef ( ) }
136
69
@@ -141,7 +74,9 @@ class PropertyGetterCfgNode extends CfgNode {
141
74
142
75
/** A control-flow node that wraps a property setter. */
143
76
class PropertySetterCfgNode extends CfgNode {
144
- override PropertySetterElement n ;
77
+ PropertySetterElement n ;
78
+
79
+ PropertySetterCfgNode ( ) { n = this .getAstNode ( ) }
145
80
146
81
AssignExpr getAssignExpr ( ) { result = n .getAssignExpr ( ) }
147
82
@@ -153,7 +88,9 @@ class PropertySetterCfgNode extends CfgNode {
153
88
}
154
89
155
90
class PropertyObserverCfgNode extends CfgNode {
156
- override PropertyObserverElement n ;
91
+ PropertyObserverElement n ;
92
+
93
+ PropertyObserverCfgNode ( ) { n = this .getAstNode ( ) }
157
94
158
95
AssignExpr getAssignExpr ( ) { result = n .getAssignExpr ( ) }
159
96
@@ -201,3 +138,9 @@ class KeyPathApplicationExprCfgNode extends ExprCfgNode {
201
138
class KeyPathExprCfgNode extends ExprCfgNode {
202
139
override KeyPathExpr e ;
203
140
}
141
+
142
+ class EntryNode = Impl:: EntryNode ;
143
+
144
+ class ExitNode = Impl:: ExitNode ;
145
+
146
+ class AnnotatedExitNode = Impl:: AnnotatedExitNode ;
0 commit comments