-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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++: Support concept id expressions #18366
base: main
Are you sure you want to change the base?
Conversation
c843bfa
to
0f5b70a
Compare
0a8643e
to
a4e7505
Compare
a4e7505
to
94dabbc
Compare
|
||
private Type getTemplateArgumentType(int index) { | ||
exists(int i | if this.isTypeConstraint() then i = index - 1 else i = index | | ||
concept_template_argument(underlyingElement(this), i, unresolveElement(result)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's a trade-off in the design here: I follow what we do for the arguments in template instantiations, as concept ids are similar to those. Alternatively we could have added them as a kind of child expressions. The latter would have made the modifications to PrintAST somewhat simpler, but would have required custom code on the extractor-side, while in the current situation that shares code with template instantiations.
If a type would be used in multiple places in the AST, rendering of the AST would be broken. Hence, we cannot directly use types as AST nodes.
e32fc08
to
f08d100
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments, mostly just questions to help my understanding
*/ | ||
class ConceptIdExpr extends RequirementExpr, @concept_id { | ||
override string toString() { result = "concept<...>" } | ||
override string toString() { | ||
exists(string name | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this preferable to result = this.getConcept().getName() + "<...>"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're absolutely right, that's much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
/** | ||
* Gets a template argument passed to the concept. | ||
*/ | ||
final Locatable getATemplateArgument() { result = this.getTemplateArgument(_) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observation: It feels like we need a new return type class TemplateArgument
here, but I see that this code follows the examples elsewhere in the library, so don't fix this now.
* then `getTemplateArgumentKind(1)` yields `int`, and there is no result for | ||
* `getTemplateArgumentKind(0)`. | ||
*/ | ||
final Locatable getTemplateArgumentKind(int index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused here. Why is the word Kind
used, and what is a "kind"? I note that this predicate always yields a Type
, so should this be the return type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could the name Type getTemplateValueArgumentType()
be suitable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is consistent with Declaration::getTemplateArgumentKind/1
and FunctionCall::getTemplateArgumentKind/1
.
I could do a follow-up where I change all of them, and deprecate all the getTemplateArgumentKind
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like getNonTypeTemplateArgumentType
is probably most accurate (as "value" is just an internal name).
|
||
override string getChildAccessorPredicateInternal(int childIndex) { | ||
exists(this.getChildInternal(childIndex)) and | ||
result = "getTemplateArgument(" + childIndex.toString() + ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .toString()
needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Also removed in a few other places.
Pull Request checklist
All query authors
.qhelp
. See the documentation in this repository.Internal query authors only
.ql
,.qll
, or.qhelp
files. See the documentation (internal access required).