@@ -28,13 +28,7 @@ private predicate shouldPrint(Locatable e) { any(PrintAstConfiguration config).s
28
28
/**
29
29
* An AST node that should be printed.
30
30
*/
31
- private newtype TPrintAstNode =
32
- TLocatable ( Locatable ast ) {
33
- // Only consider resolved nodes (that is not within the hidden conversion AST)
34
- ast = ast .resolve ( )
35
- } or
36
- TConversion ( Expr conv ) { conv .isConversion ( ) } or
37
- TConversionContainer ( Expr e ) { e = e .resolve ( ) and e .hasConversions ( ) }
31
+ private newtype TPrintAstNode = TLocatable ( Locatable ast )
38
32
39
33
/**
40
34
* A node in the output tree.
@@ -49,7 +43,7 @@ class PrintAstNode extends TPrintAstNode {
49
43
* Gets the child node at index `index`. Child indices must be unique,
50
44
* but need not be contiguous.
51
45
*/
52
- abstract predicate hasChild ( PrintAstNode child , int index , string accessor ) ;
46
+ abstract predicate hasChild ( PrintAstNode child , int index , string label ) ;
53
47
54
48
/**
55
49
* Holds if this node should be printed in the output.
@@ -72,6 +66,10 @@ private string prettyPrint(Locatable e) {
72
66
result = "[" + concat ( e .getPrimaryQlClasses ( ) , ", " ) + "] " + e
73
67
}
74
68
69
+ private class Unresolved extends Locatable {
70
+ Unresolved ( ) { this != this .resolve ( ) }
71
+ }
72
+
75
73
/**
76
74
* A graph node representing a real Locatable node.
77
75
*/
@@ -84,61 +82,37 @@ class PrintLocatable extends PrintAstNode, TLocatable {
84
82
85
83
final override predicate shouldBePrinted ( ) { shouldPrint ( ast ) }
86
84
87
- override predicate hasChild ( PrintAstNode child , int index , string accessor ) {
88
- child = TLocatable ( getChildAndAccessor ( ast , index , accessor ) )
85
+ override predicate hasChild ( PrintAstNode child , int index , string label ) {
86
+ exists ( Locatable c , int i , string accessor |
87
+ c = getChildAndAccessor ( ast , i , accessor ) and
88
+ (
89
+ // use even indexes for normal children, leaving odd slots for conversions if any
90
+ child = TLocatable ( c ) and index = 2 * i and label = accessor
91
+ or
92
+ child = TLocatable ( c .getFullyUnresolved ( ) .( Unresolved ) ) and
93
+ index = 2 * i + 1 and
94
+ (
95
+ if c instanceof Expr
96
+ then label = accessor + ".getFullyUncoverted()"
97
+ else label = accessor + ".getFullyUnresolved()"
98
+ )
99
+ )
100
+ )
89
101
}
90
102
91
103
final override Location getLocation ( ) { result = ast .getLocation ( ) }
92
104
}
93
105
94
106
/**
95
- * A graph node representing a conversion.
96
- */
97
- class PrintConversion extends PrintAstNode , TConversion {
98
- Expr conv ;
99
-
100
- PrintConversion ( ) { this = TConversion ( conv ) }
101
-
102
- override string toString ( ) { result = prettyPrint ( conv ) }
103
-
104
- final override predicate shouldBePrinted ( ) { shouldPrint ( conv .resolve ( ) ) }
105
-
106
- override predicate hasChild ( PrintAstNode child , int index , string accessor ) { none ( ) }
107
-
108
- final override Location getLocation ( ) { result = conv .getLocation ( ) }
109
- }
110
-
111
- /**
112
- * A graph node representing a virtual container for conversions.
107
+ * A specialization of graph node for "unresolved" children, that is nodes in
108
+ * the parallel conversion AST.
113
109
*/
114
- class PrintConversionContainer extends PrintAstNode , TConversionContainer {
115
- Expr convertee ;
116
-
117
- PrintConversionContainer ( ) { this = TConversionContainer ( convertee ) }
118
-
119
- override string toString ( ) { result = "" }
120
-
121
- final override predicate shouldBePrinted ( ) { shouldPrint ( convertee ) }
122
-
123
- override predicate hasChild ( PrintAstNode child , int index , string accessor ) {
124
- child = TConversion ( convertee .getConversion ( index ) ) and
125
- accessor = "getConversion(" + index + ")"
126
- }
127
-
128
- final override Location getLocation ( ) { result = convertee .getFullyConverted ( ) .getLocation ( ) }
129
- }
110
+ class PrintUnresolved extends PrintLocatable {
111
+ override Unresolved ast ;
130
112
131
- /** A graph node specialization for expressions to show conversions. */
132
- class PrintExpr extends PrintLocatable {
133
- override Expr ast ;
134
-
135
- override predicate hasChild ( PrintAstNode child , int index , string accessor ) {
136
- super .hasChild ( child , index , accessor )
137
- or
138
- ast .hasConversions ( ) and
139
- index = - 1 and
140
- accessor = "conversions" and
141
- child = TConversionContainer ( ast )
113
+ override predicate hasChild ( PrintAstNode child , int index , string label ) {
114
+ // only print immediate unresolved children from the "parallel" AST
115
+ child = TLocatable ( getImmediateChildAndAccessor ( ast , index , label ) .( Unresolved ) )
142
116
}
143
117
}
144
118
0 commit comments