Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Fix printing of concept id type arguments in PrintAST #18370

Draft
wants to merge 1 commit into
base: jketema/template-parameters-7
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions cpp/ql/lib/semmle/code/cpp/PrintAST.qll
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ private newtype TPrintAstNode =
TConceptIdExprArgumentsNode(ConceptIdExpr concept) {
shouldPrintDeclaration(getAnEnclosingDeclaration(concept))
} or
TConceptIdExprTypeArgumentNode(Type type, ConceptIdExpr concept, int childIndex) {
type = concept.getTemplateArgument(childIndex)
} or
TConstructorInitializersNode(Constructor ctor) {
ctor.hasEntryPoint() and
shouldPrintDeclaration(ctor)
Expand Down Expand Up @@ -601,19 +604,6 @@ class ParameterNode extends AstNode {
}
}

/**
* A node representing a `Type`.
*/
class TypeNode extends AstNode {
Type t;

TypeNode() { t = ast }

final override PrintAstNode getChildInternal(int childIndex) { none() }

final override string getChildAccessorPredicateInternal(int childIndex) { none() }
}

/**
* A node representing an `Initializer`.
*/
Expand Down Expand Up @@ -645,8 +635,12 @@ class ConceptIdExprArgumentsNode extends PrintAstNode, TConceptIdExprArgumentsNo

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

override AstNode getChildInternal(int childIndex) {
result.getAst() = concept.getTemplateArgument(childIndex)
override PrintAstNode getChildInternal(int childIndex) {
exists(Locatable arg | arg = concept.getTemplateArgument(childIndex) |
result.(ConceptIdExprTypeArgumentNode).isArgumentNode(arg, concept, childIndex)
or
result.(ExprNode).getAst() = arg
)
}

override string getChildAccessorPredicateInternal(int childIndex) {
Expand All @@ -660,6 +654,32 @@ class ConceptIdExprArgumentsNode extends PrintAstNode, TConceptIdExprArgumentsNo
final ConceptIdExpr getConceptIdExpr() { result = concept }
}

/**
* A node representing a type argument of a `ConceptIdExpr`.
*/
class ConceptIdExprTypeArgumentNode extends PrintAstNode, TConceptIdExprTypeArgumentNode {
Type type;
ConceptIdExpr concept;
int index;

ConceptIdExprTypeArgumentNode() { this = TConceptIdExprTypeArgumentNode(type, concept, index) }

final override string toString() { result = qlClass(type) + type.toString() }

final override Location getLocation() { result = getRepresentativeLocation(type) }

override AstNode getChildInternal(int childIndex) { none() }

override string getChildAccessorPredicateInternal(int childIndex) { none() }

/**
* Holds if `t` is the `i`th template argument of `c`.
*/
predicate isArgumentNode(Type t, ConceptIdExpr c, int i) {
type = t and concept = c and index = i
}
}

/**
* A node representing the parameters of a `Function`.
*/
Expand Down
Loading