Skip to content

Commit 1ed4f74

Browse files
committed
C++: Fix printing of concept id type arguments in PrintAST
If a type would be used in multiple places in the AST, rendering of the AST would be broken.
1 parent bf19755 commit 1ed4f74

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

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

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ private newtype TPrintAstNode =
114114
TConceptIdExprArgumentsNode(ConceptIdExpr concept) {
115115
shouldPrintDeclaration(getAnEnclosingDeclaration(concept))
116116
} or
117+
TConceptIdExprTypeArgumentNode(Type type, ConceptIdExpr concept, int childIndex) {
118+
type = concept.getTemplateArgument(childIndex)
119+
} or
117120
TConstructorInitializersNode(Constructor ctor) {
118121
ctor.hasEntryPoint() and
119122
shouldPrintDeclaration(ctor)
@@ -601,19 +604,6 @@ class ParameterNode extends AstNode {
601604
}
602605
}
603606

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-
617607
/**
618608
* A node representing an `Initializer`.
619609
*/
@@ -645,8 +635,12 @@ class ConceptIdExprArgumentsNode extends PrintAstNode, TConceptIdExprArgumentsNo
645635

646636
final override Location getLocation() { result = getRepresentativeLocation(concept) }
647637

648-
override AstNode getChildInternal(int childIndex) {
649-
result.getAst() = concept.getTemplateArgument(childIndex)
638+
override PrintAstNode getChildInternal(int childIndex) {
639+
exists(Locatable arg | arg = concept.getTemplateArgument(childIndex) |
640+
result.(ConceptIdExprTypeArgumentNode).isArgumentNode(arg, concept, childIndex)
641+
or
642+
result.(ExprNode).getAst() = arg
643+
)
650644
}
651645

652646
override string getChildAccessorPredicateInternal(int childIndex) {
@@ -660,6 +654,29 @@ class ConceptIdExprArgumentsNode extends PrintAstNode, TConceptIdExprArgumentsNo
660654
final ConceptIdExpr getConceptIdExpr() { result = concept }
661655
}
662656

657+
class ConceptIdExprTypeArgumentNode extends PrintAstNode, TConceptIdExprTypeArgumentNode {
658+
Type type;
659+
ConceptIdExpr concept;
660+
int index;
661+
662+
ConceptIdExprTypeArgumentNode() { this = TConceptIdExprTypeArgumentNode(type, concept, index) }
663+
664+
final override string toString() { result = qlClass(type) + type.toString() }
665+
666+
final override Location getLocation() { result = getRepresentativeLocation(type) }
667+
668+
override AstNode getChildInternal(int childIndex) { none() }
669+
670+
override string getChildAccessorPredicateInternal(int childIndex) { none() }
671+
672+
/**
673+
* Holds if `t` is the `i`th template argument of `c`.
674+
*/
675+
predicate isArgumentNode(Type t, ConceptIdExpr c, int i) {
676+
type = t and concept = c and index = i
677+
}
678+
}
679+
663680
/**
664681
* A node representing the parameters of a `Function`.
665682
*/

0 commit comments

Comments
 (0)