@@ -27,6 +27,15 @@ module StaticInitializationGraph {
2727 * - Create a `Node` instance for each injector type.
2828 */
2929
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+
3039 newtype TNode =
3140 TInitializerNode ( Initializer i ) {
3241 // This is the initializer of a static storage duration variable
@@ -48,29 +57,29 @@ module StaticInitializationGraph {
4857 } or
4958 TFunctionCallNode ( FunctionCall fc ) {
5059 // 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 ) ) )
5261 or
5362 // This is a function call that occurs in a function called during static initialization
5463 exists (
5564 TFunctionNode ( any ( Function f |
5665 f = fc .getEnclosingFunction ( ) and
5766 // Not in an initializer of a local variable, where the desired flow is instead:
5867 // function -> initializer -> fc
59- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = fc )
68+ not exists ( Initializer i | getAnInitializerExpr ( i ) = fc )
6069 ) )
6170 )
6271 } or
6372 TVariableAccessNode ( VariableAccess va ) {
6473 // 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 ) ) )
6675 or
6776 // This is a variable that is accessed in a function called during static initialization
6877 exists (
6978 TFunctionNode ( any ( Function f |
7079 f = va .getEnclosingFunction ( ) and
7180 // Not in an initializer of a local variable, where the desired flow is instead:
7281 // function -> initializer -> va
73- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = va )
82+ not exists ( Initializer i | getAnInitializerExpr ( i ) = va )
7483 ) )
7584 )
7685 }
@@ -149,9 +158,7 @@ module StaticInitializationGraph {
149158 or
150159 // Initializer steps
151160 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 ( )
155162 )
156163 or
157164 // FunctionCall steps
@@ -169,7 +176,7 @@ module StaticInitializationGraph {
169176 f = n2 .getExpr ( ) .getEnclosingFunction ( ) and
170177 // But not in an initializer of a local variable, where the desired flow is instead:
171178 // function -> initializer -> expression
172- not exists ( Initializer i | i . getExpr ( ) . getAChild * ( ) = n2 .getExpr ( ) )
179+ not exists ( Initializer i | getAnInitializerExpr ( i ) = n2 .getExpr ( ) )
173180 or
174181 // `n2` is an initializer of a local scope variable within function `f`
175182 n2 .( InitializerNode ) .getInitializer ( ) .getDeclaration ( ) .( LocalScopeVariable ) .getFunction ( ) = f
0 commit comments