@@ -67,11 +67,6 @@ private Function getEnclosingFunction(Locatable ast) {
6767 or
6868 result = ast .( Parameter ) .getFunction ( )
6969 or
70- exists ( DeclStmt stmt |
71- stmt .getADeclarationEntry ( ) = ast and
72- result = stmt .getEnclosingFunction ( )
73- )
74- or
7570 result = ast
7671}
7772
@@ -80,7 +75,14 @@ private Function getEnclosingFunction(Locatable ast) {
8075 * nodes for things like parameter lists and constructor init lists.
8176 */
8277private newtype TPrintASTNode =
83- TASTNode ( Locatable ast ) { shouldPrintFunction ( getEnclosingFunction ( ast ) ) } or
78+ TASTNode ( Locatable ast ) {
79+ shouldPrintFunction ( getEnclosingFunction ( ast ) )
80+ } or
81+ TDeclarationEntryNode ( DeclStmt stmt , DeclarationEntry entry ) {
82+ // We create a unique node for each pair of (stmt, entry), to avoid having one node with
83+ // multiple parents due to extractor bug CPP-413.
84+ stmt .getADeclarationEntry ( ) = entry
85+ } or
8486 TParametersNode ( Function func ) { shouldPrintFunction ( func ) } or
8587 TConstructorInitializersNode ( Constructor ctor ) {
8688 ctor .hasEntryPoint ( ) and
@@ -161,11 +163,9 @@ private string qlClass(ElementBase el) { result = "[" + concat(el.getCanonicalQL
161163/**
162164 * A node representing an AST node.
163165 */
164- abstract class ASTNode extends PrintASTNode , TASTNode {
166+ abstract class BaseASTNode extends PrintASTNode {
165167 Locatable ast ;
166168
167- ASTNode ( ) { this = TASTNode ( ast ) }
168-
169169 override string toString ( ) { result = qlClass ( ast ) + ast .toString ( ) }
170170
171171 final override Location getLocation ( ) { result = getRepresentativeLocation ( ast ) }
@@ -176,6 +176,13 @@ abstract class ASTNode extends PrintASTNode, TASTNode {
176176 final Locatable getAST ( ) { result = ast }
177177}
178178
179+ /**
180+ * A node representing an AST node other than a `DeclarationEntry`.
181+ */
182+ abstract class ASTNode extends BaseASTNode , TASTNode {
183+ ASTNode ( ) { this = TASTNode ( ast ) }
184+ }
185+
179186/**
180187 * A node representing an `Expr`.
181188 */
@@ -250,32 +257,33 @@ class CastNode extends ConversionNode {
250257/**
251258 * A node representing a `DeclarationEntry`.
252259 */
253- class DeclarationEntryNode extends ASTNode {
254- DeclarationEntry entry ;
260+ class DeclarationEntryNode extends BaseASTNode , TDeclarationEntryNode {
261+ override DeclarationEntry ast ;
262+ DeclStmt declStmt ;
255263
256- DeclarationEntryNode ( ) { entry = ast }
264+ DeclarationEntryNode ( ) {
265+ this = TDeclarationEntryNode ( declStmt , ast )
266+ }
257267
258268 override PrintASTNode getChild ( int childIndex ) { none ( ) }
259269
260270 override string getProperty ( string key ) {
261- result = super .getProperty ( key )
271+ result = BaseASTNode . super .getProperty ( key )
262272 or
263273 key = "Type" and
264- result = qlClass ( entry .getType ( ) ) + entry .getType ( ) .toString ( )
274+ result = qlClass ( ast .getType ( ) ) + ast .getType ( ) .toString ( )
265275 }
266276}
267277
268278/**
269279 * A node representing a `VariableDeclarationEntry`.
270280 */
271281class VariableDeclarationEntryNode extends DeclarationEntryNode {
272- VariableDeclarationEntry varEntry ;
273-
274- VariableDeclarationEntryNode ( ) { varEntry = entry }
282+ override VariableDeclarationEntry ast ;
275283
276284 override ASTNode getChild ( int childIndex ) {
277285 childIndex = 0 and
278- result .getAST ( ) = varEntry .getVariable ( ) .getInitializer ( )
286+ result .getAST ( ) = ast .getVariable ( ) .getInitializer ( )
279287 }
280288
281289 override string getChildEdgeLabel ( int childIndex ) { childIndex = 0 and result = "init" }
@@ -289,7 +297,7 @@ class StmtNode extends ASTNode {
289297
290298 StmtNode ( ) { stmt = ast }
291299
292- override ASTNode getChild ( int childIndex ) {
300+ override BaseASTNode getChild ( int childIndex ) {
293301 exists ( Locatable child |
294302 child = stmt .getChild ( childIndex ) and
295303 (
@@ -308,8 +316,11 @@ class DeclStmtNode extends StmtNode {
308316
309317 DeclStmtNode ( ) { declStmt = stmt }
310318
311- override ASTNode getChild ( int childIndex ) {
312- result .getAST ( ) = declStmt .getDeclarationEntry ( childIndex )
319+ override DeclarationEntryNode getChild ( int childIndex ) {
320+ exists ( DeclarationEntry entry |
321+ declStmt .getDeclarationEntry ( childIndex ) = entry and
322+ result = TDeclarationEntryNode ( declStmt , entry )
323+ )
313324 }
314325}
315326
0 commit comments