@@ -27,6 +27,15 @@ module StaticInitializationGraph {
27
27
* - Create a `Node` instance for each injector type.
28
28
*/
29
29
30
+ /**
31
+ * Gets an Expr directly or indirectly included in an initializer.
32
+ */
33
+ private Expr getAnInitializerExpr ( Initializer i ) {
34
+ result = i .getExpr ( )
35
+ or
36
+ result = getAnInitializerExpr ( i ) .getAChild ( )
37
+ }
38
+
30
39
newtype TNode =
31
40
TInitializerNode ( Initializer i ) {
32
41
// This is the initializer of a static storage duration variable
@@ -48,29 +57,29 @@ module StaticInitializationGraph {
48
57
} or
49
58
TFunctionCallNode ( FunctionCall fc ) {
50
59
// This is a function call that occurs in an initializer called during static initialization
51
- exists ( TInitializerNode ( any ( Initializer i | i . getExpr ( ) . getAChild * ( ) = fc ) ) )
60
+ exists ( TInitializerNode ( any ( Initializer i | getAnInitializerExpr ( i ) = fc ) ) )
52
61
or
53
62
// This is a function call that occurs in a function called during static initialization
54
63
exists (
55
64
TFunctionNode ( any ( Function f |
56
65
f = fc .getEnclosingFunction ( ) and
57
66
// Not in an initializer of a local variable, where the desired flow is instead:
58
67
// function -> initializer -> fc
59
- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = fc )
68
+ not exists ( Initializer i | getAnInitializerExpr ( i ) = fc )
60
69
) )
61
70
)
62
71
} or
63
72
TVariableAccessNode ( VariableAccess va ) {
64
73
// This is a variable that is accessed in an initializer called during static initialization
65
- exists ( TInitializerNode ( any ( Initializer i | i . getExpr ( ) . getAChild * ( ) = va ) ) )
74
+ exists ( TInitializerNode ( any ( Initializer i | getAnInitializerExpr ( i ) = va ) ) )
66
75
or
67
76
// This is a variable that is accessed in a function called during static initialization
68
77
exists (
69
78
TFunctionNode ( any ( Function f |
70
79
f = va .getEnclosingFunction ( ) and
71
80
// Not in an initializer of a local variable, where the desired flow is instead:
72
81
// function -> initializer -> va
73
- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = va )
82
+ not exists ( Initializer i | getAnInitializerExpr ( i ) = va )
74
83
) )
75
84
)
76
85
}
@@ -149,9 +158,7 @@ module StaticInitializationGraph {
149
158
or
150
159
// Initializer steps
151
160
exists ( Initializer i | i = n1 .( InitializerNode ) .getInitializer ( ) |
152
- i .getExpr ( ) .getAChild * ( ) = n2 .( FunctionCallNode ) .getFunctionCall ( )
153
- or
154
- i .getExpr ( ) .getAChild * ( ) = n2 .( VariableAccessNode ) .getVariableAccess ( )
161
+ getAnInitializerExpr ( i ) = n2 .getExpr ( )
155
162
)
156
163
or
157
164
// FunctionCall steps
@@ -169,7 +176,7 @@ module StaticInitializationGraph {
169
176
f = n2 .getExpr ( ) .getEnclosingFunction ( ) and
170
177
// But not in an initializer of a local variable, where the desired flow is instead:
171
178
// function -> initializer -> expression
172
- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = n2 .getExpr ( ) )
179
+ not exists ( Initializer i | getAnInitializerExpr ( i ) = n2 .getExpr ( ) )
173
180
or
174
181
// `n2` is an initializer of a local scope variable within function `f`
175
182
n2 .( InitializerNode ) .getInitializer ( ) .getDeclaration ( ) .( LocalScopeVariable ) .getFunction ( ) = f
0 commit comments