Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
719 | Am I using the API correctly here? It's a bit weird that ConstDeclVisitor would work differently from RecursiveASTVisitor in that VisitXXX methods for super-classes are not automatically called |
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
719 | right, non-recursive ast visitors are mere helpers for visiting most specific type of an ast node which is interesting to the visitor (i.e. visit method is overridden), and only that. they also don't traverse children of an entitie's entries. which usually hints towards this being the wrong place to handle such constructs. we actually have an outer recursiveastvisitor, that tries to visit each children. but concept references seem to be missing from there.
We should probably figure out how to properly visit type constraints inside the RecursiveASTVisitor (i guess we should actually be visiting TypeConstraints). @usaxena95 who's looking at C++20 features and their interactions with source tooling. In the meanwhile, i think we should have this specialization at the outer layer, in ExplicitReferenceCollector, with something like: bool TraverseTemplateTypeParamDeclConstraints(TemplateTypeParmDecl *TTPD) { if (auto *TC = TTPD->getTypeConstraint()) { reportReference(ReferenceLoc{TC->getNestedNameSpecifierLoc(), TC->getConceptNameLoc(), /*IsDecl=*/false, {TC->getNamedConcept()}}, DynTypedNode::create(*TTPD)); return RecursiveASTVisitor::TraverseTypeConstraint(TC); } return true; } |
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
719 |
This isn't unfortunate, this is where we would handle things internal to the name (e.g. if the name was operator vector<int>()) rather than what the name is used for. The right level to handle this seems to be a missing TraverseConceptReference() which observes the lexical reference to a concept (we don't care here that it's a type constraint specifically). Renaming this to TraverseConceptReference() and making it CRTP-overridable seems like the principled solution at the RAV level. Maybe there's some reason it wasn't done this way to start with though. Failing that, overriding TraverseTypeConstraint() in our RAV subclass seems like it fits the pattern more neatly (there's no VisitTypeConstraint, so we have to override Traverse and call Base::Traverse). We're going to have to handle the other ways concepts can be referenced of course, but changing RAV vs working around its limitations is always a tradeoff of practicality. |
Also filed https://github.com/llvm/llvm-project/issues/60469 for the seemingly missing RecursiveASTVisitor methods
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
1047 | can you also add a comment like // We actually want to handle all ConceptReferences but RAV doesn't traverse it polymorphically. So handle the ones inside TypeConstraints specially here. |
Am I using the API correctly here? It's a bit weird that ConstDeclVisitor would work differently from RecursiveASTVisitor in that VisitXXX methods for super-classes are not automatically called