@@ -492,10 +492,41 @@ private string toExprString(Node n) {
492
492
result = n .asExpr ( 0 ) .toString ( )
493
493
or
494
494
not exists ( n .asExpr ( ) ) and
495
- result = n .asIndirectExpr ( 0 , 1 ) .toString ( ) + " indirection"
495
+ result = stars ( n ) + n .asIndirectExpr ( 0 , 1 ) .toString ( )
496
496
)
497
497
}
498
498
499
+ private module NodeStars {
500
+ private int getNumberOfIndirections ( Node n ) {
501
+ result = n .( RawIndirectOperand ) .getIndirectionIndex ( )
502
+ or
503
+ result = n .( RawIndirectInstruction ) .getIndirectionIndex ( )
504
+ or
505
+ result = n .( VariableNode ) .getIndirectionIndex ( )
506
+ or
507
+ result = n .( PostUpdateNodeImpl ) .getIndirectionIndex ( )
508
+ or
509
+ result = n .( FinalParameterNode ) .getIndirectionIndex ( )
510
+ }
511
+
512
+ private int maxNumberOfIndirections ( ) { result = max ( getNumberOfIndirections ( _) ) }
513
+
514
+ private string repeatStars ( int n ) {
515
+ n = 0 and result = ""
516
+ or
517
+ n = [ 1 .. maxNumberOfIndirections ( ) ] and
518
+ result = "*" + repeatStars ( n - 1 )
519
+ }
520
+
521
+ /**
522
+ * Gets the number of stars (i.e., `*`s) needed to produce the `toString`
523
+ * output for `n`.
524
+ */
525
+ string stars ( Node n ) { result = repeatStars ( getNumberOfIndirections ( n ) ) }
526
+ }
527
+
528
+ private import NodeStars
529
+
499
530
/**
500
531
* A class that lifts pre-SSA dataflow nodes to regular dataflow nodes.
501
532
*/
@@ -786,10 +817,12 @@ class IndirectParameterNode extends Node instanceof IndirectInstruction {
786
817
override Location getLocationImpl ( ) { result = this .getParameter ( ) .getLocation ( ) }
787
818
788
819
override string toStringImpl ( ) {
789
- result = this .getParameter ( ) .toString ( ) + " indirection"
790
- or
791
- not exists ( this .getParameter ( ) ) and
792
- result = "this indirection"
820
+ exists ( string prefix | prefix = stars ( this ) |
821
+ result = prefix + this .getParameter ( ) .toString ( )
822
+ or
823
+ not exists ( this .getParameter ( ) ) and
824
+ result = prefix + "this"
825
+ )
793
826
}
794
827
}
795
828
@@ -1016,7 +1049,7 @@ private module RawIndirectNodes {
1016
1049
}
1017
1050
1018
1051
override string toStringImpl ( ) {
1019
- result = operandNode ( this .getOperand ( ) ) .toStringImpl ( ) + " indirection"
1052
+ result = stars ( this ) + operandNode ( this .getOperand ( ) ) .toStringImpl ( )
1020
1053
}
1021
1054
}
1022
1055
@@ -1058,7 +1091,7 @@ private module RawIndirectNodes {
1058
1091
}
1059
1092
1060
1093
override string toStringImpl ( ) {
1061
- result = instructionNode ( this .getInstruction ( ) ) .toStringImpl ( ) + " indirection"
1094
+ result = stars ( this ) + instructionNode ( this .getInstruction ( ) ) .toStringImpl ( )
1062
1095
}
1063
1096
}
1064
1097
@@ -1151,9 +1184,7 @@ class FinalParameterNode extends Node, TFinalParameterNode {
1151
1184
result instanceof UnknownDefaultLocation
1152
1185
}
1153
1186
1154
- override string toStringImpl ( ) {
1155
- if indirectionIndex > 1 then result = p .toString ( ) + " indirection" else result = p .toString ( )
1156
- }
1187
+ override string toStringImpl ( ) { result = stars ( this ) + p .toString ( ) }
1157
1188
}
1158
1189
1159
1190
/**
@@ -1787,9 +1818,7 @@ class VariableNode extends Node, TVariableNode {
1787
1818
result instanceof UnknownDefaultLocation
1788
1819
}
1789
1820
1790
- override string toStringImpl ( ) {
1791
- if indirectionIndex = 1 then result = v .toString ( ) else result = v .toString ( ) + " indirection"
1792
- }
1821
+ override string toStringImpl ( ) { result = stars ( this ) + v .toString ( ) }
1793
1822
}
1794
1823
1795
1824
/**
@@ -2249,18 +2278,29 @@ class Content extends TContent {
2249
2278
abstract predicate impliesClearOf ( Content c ) ;
2250
2279
}
2251
2280
2281
+ private module ContentStars {
2282
+ private int maxNumberOfIndirections ( ) { result = max ( any ( Content c ) .getIndirectionIndex ( ) ) }
2283
+
2284
+ private string repeatStars ( int n ) {
2285
+ n = 0 and result = ""
2286
+ or
2287
+ n = [ 1 .. maxNumberOfIndirections ( ) ] and
2288
+ result = "*" + repeatStars ( n - 1 )
2289
+ }
2290
+
2291
+ string contentStars ( Content c ) { result = repeatStars ( c .getIndirectionIndex ( ) - 1 ) }
2292
+ }
2293
+
2294
+ private import ContentStars
2295
+
2252
2296
/** A reference through a non-union instance field. */
2253
2297
class FieldContent extends Content , TFieldContent {
2254
2298
Field f ;
2255
2299
int indirectionIndex ;
2256
2300
2257
2301
FieldContent ( ) { this = TFieldContent ( f , indirectionIndex ) }
2258
2302
2259
- override string toString ( ) {
2260
- indirectionIndex = 1 and result = f .toString ( )
2261
- or
2262
- indirectionIndex > 1 and result = f .toString ( ) + " indirection"
2263
- }
2303
+ override string toString ( ) { result = contentStars ( this ) + f .toString ( ) }
2264
2304
2265
2305
Field getField ( ) { result = f }
2266
2306
@@ -2289,11 +2329,7 @@ class UnionContent extends Content, TUnionContent {
2289
2329
2290
2330
UnionContent ( ) { this = TUnionContent ( u , bytes , indirectionIndex ) }
2291
2331
2292
- override string toString ( ) {
2293
- indirectionIndex = 1 and result = u .toString ( )
2294
- or
2295
- indirectionIndex > 1 and result = u .toString ( ) + " indirection"
2296
- }
2332
+ override string toString ( ) { result = contentStars ( this ) + u .toString ( ) }
2297
2333
2298
2334
/** Gets a field of the underlying union of this `UnionContent`, if any. */
2299
2335
Field getAField ( ) { result = u .getAField ( ) and getFieldSize ( result ) = bytes }
0 commit comments