Skip to content

Commit afe62f0

Browse files
committed
C++: Improve PrintAST for concept ids
1 parent 6159e41 commit afe62f0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

cpp/ql/lib/semmle/code/cpp/PrintAST.qll

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ private Declaration getAnEnclosingDeclaration(Locatable ast) {
8888
or
8989
result = ast.(Initializer).getDeclaration()
9090
or
91+
exists(ConceptIdExpr concept | ast = concept.getATemplateArgument() |
92+
result = concept.getEnclosingFunction()
93+
)
94+
or
9195
result = ast
9296
}
9397

@@ -107,6 +111,9 @@ private newtype TPrintAstNode =
107111
TRequiresExprParametersNode(RequiresExpr req) {
108112
shouldPrintDeclaration(getAnEnclosingDeclaration(req))
109113
} or
114+
TConceptIdExprArgumentsNode(ConceptIdExpr concept) {
115+
shouldPrintDeclaration(getAnEnclosingDeclaration(concept))
116+
} or
110117
TConstructorInitializersNode(Constructor ctor) {
111118
ctor.hasEntryPoint() and
112119
shouldPrintDeclaration(ctor)
@@ -357,6 +364,26 @@ class StringLiteralNode extends ExprNode {
357364
override string getValue() { result = "\"" + escapeString(expr.getValue()) + "\"" }
358365
}
359366

367+
/**
368+
* A node representing a `ConceptIdExpr`.
369+
*/
370+
class ConceptIdExprNode extends ExprNode {
371+
override ConceptIdExpr expr;
372+
373+
override PrintAstNode getChildInternal(int childIndex) {
374+
result = super.getChildInternal(childIndex)
375+
or
376+
childIndex = -1 and
377+
result.(ConceptIdExprArgumentsNode).getConceptIdExpr() = expr
378+
}
379+
380+
override string getChildAccessorPredicateInternal(int childIndex) {
381+
result = super.getChildAccessorPredicateInternal(childIndex)
382+
or
383+
childIndex = -1 and result = "<args>"
384+
}
385+
}
386+
360387
/**
361388
* A node representing a `Conversion`.
362389
*/
@@ -574,6 +601,19 @@ class ParameterNode extends AstNode {
574601
}
575602
}
576603

604+
/**
605+
* A node representing a `Type`.
606+
*/
607+
class TypeNode extends AstNode {
608+
Type t;
609+
610+
TypeNode() { t = ast }
611+
612+
final override PrintAstNode getChildInternal(int childIndex) { none() }
613+
614+
final override string getChildAccessorPredicateInternal(int childIndex) { none() }
615+
}
616+
577617
/**
578618
* A node representing an `Initializer`.
579619
*/
@@ -593,6 +633,33 @@ class InitializerNode extends AstNode {
593633
}
594634
}
595635

636+
/**
637+
* A node representing the arguments of a `ConceptIdExpr`.
638+
*/
639+
class ConceptIdExprArgumentsNode extends PrintAstNode, TConceptIdExprArgumentsNode {
640+
ConceptIdExpr concept;
641+
642+
ConceptIdExprArgumentsNode() { this = TConceptIdExprArgumentsNode(concept) }
643+
644+
final override string toString() { result = "" }
645+
646+
final override Location getLocation() { result = getRepresentativeLocation(concept) }
647+
648+
override AstNode getChildInternal(int childIndex) {
649+
result.getAst() = concept.getTemplateArgument(childIndex)
650+
}
651+
652+
override string getChildAccessorPredicateInternal(int childIndex) {
653+
exists(this.getChildInternal(childIndex)) and
654+
result = "getTemplateArgument(" + childIndex.toString() + ")"
655+
}
656+
657+
/**
658+
* Gets the `ConceptIdExpr` for which this node represents the parameters.
659+
*/
660+
final ConceptIdExpr getConceptIdExpr() { result = concept }
661+
}
662+
596663
/**
597664
* A node representing the parameters of a `Function`.
598665
*/

0 commit comments

Comments
 (0)