@@ -28,11 +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
- }
31
+ private newtype TPrintAstNode = TLocatable ( Locatable ast )
36
32
37
33
/**
38
34
* A node in the output tree.
@@ -47,7 +43,7 @@ class PrintAstNode extends TPrintAstNode {
47
43
* Gets the child node at index `index`. Child indices must be unique,
48
44
* but need not be contiguous.
49
45
*/
50
- abstract predicate hasChild ( PrintAstNode child , int index , string accessor ) ;
46
+ abstract predicate hasChild ( PrintAstNode child , int index , string label ) ;
51
47
52
48
/**
53
49
* Holds if this node should be printed in the output.
@@ -66,6 +62,14 @@ class PrintAstNode extends TPrintAstNode {
66
62
string getProperty ( string key ) { none ( ) }
67
63
}
68
64
65
+ private string prettyPrint ( Locatable e ) {
66
+ result = "[" + concat ( e .getPrimaryQlClasses ( ) , ", " ) + "] " + e
67
+ }
68
+
69
+ private class Unresolved extends Locatable {
70
+ Unresolved ( ) { this != this .resolve ( ) }
71
+ }
72
+
69
73
/**
70
74
* A graph node representing a real Locatable node.
71
75
*/
@@ -74,13 +78,60 @@ class PrintLocatable extends PrintAstNode, TLocatable {
74
78
75
79
PrintLocatable ( ) { this = TLocatable ( ast ) }
76
80
81
+ override string toString ( ) { result = prettyPrint ( ast ) }
82
+
77
83
final override predicate shouldBePrinted ( ) { shouldPrint ( ast ) }
78
84
79
- override predicate hasChild ( PrintAstNode child , int index , string accessor ) {
80
- 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 + ".getFullyConverted()"
97
+ else label = accessor + ".getFullyUnresolved()"
98
+ )
99
+ )
100
+ )
81
101
}
82
102
83
- override string toString ( ) { result = "[" + concat ( ast .getPrimaryQlClasses ( ) , ", " ) + "] " + ast }
84
-
85
103
final override Location getLocation ( ) { result = ast .getLocation ( ) }
86
104
}
105
+
106
+ /**
107
+ * A specialization of graph node for "unresolved" children, that is nodes in
108
+ * the parallel conversion AST.
109
+ */
110
+ class PrintUnresolved extends PrintLocatable {
111
+ override Unresolved ast ;
112
+
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 ) )
116
+ }
117
+ }
118
+
119
+ /**
120
+ * A specialization of graph node for `VarDecl`, to add typing information.
121
+ */
122
+ class PrintVarDecl extends PrintLocatable {
123
+ override VarDecl ast ;
124
+
125
+ override string getProperty ( string key ) { key = "Type" and result = ast .getType ( ) .toString ( ) }
126
+ }
127
+
128
+ /**
129
+ * A specialization of graph node for `AbstractFunctionDecl`, to add typing information.
130
+ */
131
+ class PrintAbstractFunctionDecl extends PrintLocatable {
132
+ override AbstractFunctionDecl ast ;
133
+
134
+ override string getProperty ( string key ) {
135
+ key = "InterfaceType" and result = ast .getInterfaceType ( ) .toString ( )
136
+ }
137
+ }
0 commit comments