@@ -268,15 +268,21 @@ class Node extends TIRDataFlowNode {
268268 * Gets the variable corresponding to this node, if any. This can be used for
269269 * modeling flow in and out of global variables.
270270 */
271- Variable asVariable ( ) { result = this . asVariable ( 1 ) }
271+ Variable asVariable ( ) { this = TVariableNode ( result , 1 ) }
272272
273- Variable asVariable ( int indirectionIndex ) {
274- exists ( VariableNode varNode | this = varNode |
275- varNode .getVariable ( ) = result and
276- varNode .getIndirectionIndex ( ) = indirectionIndex
277- )
273+ /**
274+ * Gets the `indirectionIndex`'th indirection of this node's underlying variable, if any.
275+ *
276+ * This can be used for modeling flow in and out of global variables.
277+ */
278+ Variable asIndirectVariable ( int indirectionIndex ) {
279+ indirectionIndex > 1 and
280+ this = TVariableNode ( result , indirectionIndex )
278281 }
279282
283+ /** Gets an indirection of this node's underlying variable, if any. */
284+ Variable asIndirectVariable ( ) { result = this .asIndirectVariable ( _) }
285+
280286 /**
281287 * Gets the expression that is partially defined by this node, if any.
282288 *
@@ -510,11 +516,16 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
510516
511517 override Declaration getFunction ( ) { result = globalUse .getIRFunction ( ) .getFunction ( ) }
512518
513- override DataFlowType getType ( ) { result instanceof VoidType } // TODO
519+ override DataFlowType getType ( ) {
520+ exists ( int indirectionIndex |
521+ indirectionIndex = globalUse .getIndirectionIndex ( ) and
522+ result = getTypeImpl ( globalUse .getUnspecifiedType ( ) , indirectionIndex - 1 )
523+ )
524+ }
514525
515526 final override Location getLocationImpl ( ) { result = globalUse .getLocation ( ) }
516527
517- override string toStringImpl ( ) { result = "FinalGlobalValue" }
528+ override string toStringImpl ( ) { result = globalUse . toString ( ) }
518529}
519530
520531class InitialGlobalValue extends Node , TInitialGlobalValue {
@@ -528,11 +539,16 @@ class InitialGlobalValue extends Node, TInitialGlobalValue {
528539
529540 override Declaration getFunction ( ) { result = globalDef .getIRFunction ( ) .getFunction ( ) }
530541
531- override DataFlowType getType ( ) { result instanceof VoidType } // TODO
542+ override DataFlowType getType ( ) {
543+ exists ( int indirectionIndex |
544+ indirectionIndex = globalDef .getIndirectionIndex ( ) and
545+ result = getTypeImpl ( globalDef .getUnspecifiedType ( ) , indirectionIndex )
546+ )
547+ }
532548
533549 final override Location getLocationImpl ( ) { result = globalDef .getLocation ( ) }
534550
535- override string toStringImpl ( ) { result = "InitialGlobalValue" }
551+ override string toStringImpl ( ) { result = globalDef . toString ( ) }
536552}
537553
538554/**
@@ -1173,7 +1189,9 @@ class VariableNode extends Node, TVariableNode {
11731189 result = v
11741190 }
11751191
1176- override DataFlowType getType ( ) { result = v .getType ( ) }
1192+ override DataFlowType getType ( ) {
1193+ result = getTypeImpl ( v .getUnspecifiedType ( ) , indirectionIndex - 1 )
1194+ }
11771195
11781196 final override Location getLocationImpl ( ) {
11791197 // Certain variables (such as parameters) can have multiple locations.
@@ -1185,7 +1203,9 @@ class VariableNode extends Node, TVariableNode {
11851203 result instanceof UnknownDefaultLocation
11861204 }
11871205
1188- override string toStringImpl ( ) { result = v .toString ( ) }
1206+ override string toStringImpl ( ) {
1207+ if indirectionIndex = 1 then result = v .toString ( ) else result = v .toString ( ) + " indirection"
1208+ }
11891209}
11901210
11911211/**
0 commit comments