Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks this mostly LG, but I think we need some tests feel free to copy the ones in D66647 as a start point. But I believe coverage for this one is bigger, as this tries to figure-out all references, whereas the define-inline patch only cares about references to non-local decls in contexts that can have a nested name specifier.
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
369 ↗ | (On Diff #220999) | could you add some comments on what it does |
373 ↗ | (On Diff #220999) | what is namedTarget ? |
376 ↗ | (On Diff #220999) | can we simplify this by populating two vectors, Instantiations and Patterns, and then returning the patterns iff instantiations are empty? |
381 ↗ | (On Diff #220999) | why do we discard aliases(specifically underlying decls) ? for example if we have vector<int> I believe decl(template<> std::vector<int>) will be marked with both TemplateInst and Underlying right ? |
391 ↗ | (On Diff #220999) | same here for ignoring underlying decls |
399 ↗ | (On Diff #220999) | these three(usingdirective,using,namespacealias) decls are the only ones that can have a nestednamespecifier. Are we sure these are the only ones that can reference a decl? For example what about a ConstructorDecl with initializers referencing FieldDecls, I believe this function should rather return multiple locations in such cases. |
409 ↗ | (On Diff #220999) | I think getUsingLoc will return the location for using keyword, not the name location. Maybe use getLocation ? |
426 ↗ | (On Diff #220999) | again I believe this list is non-exhaustive, e.g. designatedinitilaizers. and again this also needs to return a vector instead. |
432 ↗ | (On Diff #220999) | I believe it is better to return getFoundDecl then getDecl, the former respects using declarations. |
506 ↗ | (On Diff #220999) | can we move this below ExplicitReferenceCollector to prevent splitting anon namespace? |
548 ↗ | (On Diff #220999) | why not just traversenestednamespecifier and visitNode(L) instead of calling the base::traverse ? |
570 ↗ | (On Diff #220999) | why not just visitNode(L) and traverse(prefix(L)) instead of calling base? |
581 ↗ | (On Diff #220999) | what is nodeReference? |
594 ↗ | (On Diff #220999) | So this endpoint doesn't seem to have downsides above(not visiting all referenced decls) as it performs traversal through an extra ASTVisitor. What is the point of exposing the first method? Maybe we can getaway with not exposing it or strictly mentioning it might not return references in the children nodes? |
clang-tools-extra/clangd/FindTarget.h | ||
103 ↗ | (On Diff #220999) | drop :wa ? |
clang-tools-extra/clangd/FindTarget.h | ||
---|---|---|
115 ↗ | (On Diff #220999) | It might be better to accept a DynTypedNode in here as well, so that this can be used with other node types as well, or provide overrides for them(for example Decl). |
clang-tools-extra/clangd/FindTarget.h | ||
---|---|---|
93 ↗ | (On Diff #220999) | do we have any real use-case for this field? apart from "skipping instance members in define inline"? because that one can also be achieved easily through decl (there is a isCXXInstanceMember). |
Added some tests too. More tests for dependent constructs are still missing, but please take a look at what we have for now.
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
373 ↗ | (On Diff #220999) | Used to be called this before. Fixed, thanks. |
376 ↗ | (On Diff #220999) | Did something very similar. PTAL. |
381 ↗ | (On Diff #220999) | For ^vector<int>, we get vector<int>(TemplateInstantiation) and vector(TemplatePattern). Added a relevant test-case. |
391 ↗ | (On Diff #220999) | As mentioned in the previous comment, we want to discard underlying. Underlying decl was not written in the source code, therefore should not be returned by this function. |
399 ↗ | (On Diff #220999) | This function is non-recursive and ConstructorInitializer is a separate node under ConsturctorDecl. There might be more decls that I missed here, though, hopefully we'll find and add them later. It's a bit hard to get all cases on the first try. |
409 ↗ | (On Diff #220999) | Thanks for spotting this! This was supposed to be a temporary placeholder until I figure out a proper location. Fixed and added a test. |
426 ↗ | (On Diff #220999) | Added a FIXME to add more exhaustive handling. I would try avoiding returning more than one element here. For designated initializers we seem to have multiple designators. Since this function is non-recursive, it should not return those. Instead we would require our clients (i.e. our visitor) to call a separate function for each of the designators. |
432 ↗ | (On Diff #220999) | Good point. Done. Added a test too. |
548 ↗ | (On Diff #220999) | To avoid re-implementing the traversal logic. Base::Traverse does exactly that, we shouldn't re-implement traversal ourselves. |
570 ↗ | (On Diff #220999) | For code reuse. See other comment too |
581 ↗ | (On Diff #220999) | Now renamed to explicitReference. Thanks. |
594 ↗ | (On Diff #220999) | I think we'll need it for D56610 (qualify name under cursor). Also updated a comment to explicitly mention it does not recurse into child nodes, hope its intention is clear now. |
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
376 ↗ | (On Diff #220999) | LG, thanks! |
432 ↗ | (On Diff #220999) | I was actually referring to DeclRefExpr, change seems to be on MemberExpr |
548 ↗ | (On Diff #220999) | I see but that should help get rid of TypeLocsToSkip and some extra traversals. I believe it would be worth getting rid of the additional state management, but up to you. |
370 ↗ | (On Diff #221345) | nit: s/a declaration/declaration(s)/ |
519 ↗ | (On Diff #221345) | unnecessary closing and opening of anon namespace |
577 ↗ | (On Diff #221345) | :wa is still around have:wa references :D |
609 ↗ | (On Diff #221345) | I can see the second check is for getting rid of references coming from macro expansions. But what exactly is the first one for? How can we get an invalid nameloc, could you also add it as a comment? |
clang-tools-extra/clangd/FindTarget.h | ||
96 ↗ | (On Diff #221345) | Is this for testing purposes? maybe move it into findtargettests.cpp or make it a member helper like Print(SourceManager&) so that it can also print locations etc.? |
clang-tools-extra/clangd/unittests/FindTargetTests.cpp | ||
498 ↗ | (On Diff #221345) | this sounds more like LastOffset or PrevOffset |
504 ↗ | (On Diff #221345) | I believe these are already filtered-out by findExplicitReferences ? |
600 ↗ | (On Diff #221345) | Is it OK for this case to be different than X::a above? also shouldn't this be a::b::struct S or None ?(my preference would be towards None) |
638 ↗ | (On Diff #221345) | again qualifiers seems to be inconsistent with the rest of the cases. |
clang-tools-extra/clangd/FindTarget.cpp | ||
---|---|---|
432 ↗ | (On Diff #220999) | Good point. Fixed that one too, thanks! |
548 ↗ | (On Diff #220999) | I like the idea and actually tried to implement it before, but failed. The nested-name-specifier case is simple and we could actually implement it. However, the ElaboratedTypeLoc case is more complicated: we have to call Base::TraverseTypeLoc to make sure we recursively visit children of ElaboratedTypeLoc::getNamedType (e.g. template arguments inside the typeloc). However, Base::TraverseTypeLoc automatically calls VisitTypeLoc and our qualifier is forgotten again. Let me know if there's a way to implement this that I missed, though. |
577 ↗ | (On Diff #221345) | Thanks. This slipped my attention last time :-) |
609 ↗ | (On Diff #221345) | Ah, thanks for spotting this. I don't think we want to filter out macro references, fixed that and added a test The first one is a precaution against various implicit nodes getting into the traversal. Normally this shouldn't happen, unless:
I couldn't come up with examples of that actually happening, but I'm also scared of adding an assertion as I feel this would inevitably fail at some point. Added a comment, let me know if this could be made clearer, though. |
clang-tools-extra/clangd/FindTarget.h | ||
96 ↗ | (On Diff #221345) | Yes, this is for output in the test. Moving to findTargetTests.cpp, we risk ODR violations in the future. What are the downsides of having it? |
clang-tools-extra/clangd/unittests/FindTargetTests.cpp | ||
498 ↗ | (On Diff #221345) | That's the next character in Code we need to process, renamed to NextCodeChar to specifically mention what string we're referring to. |
504 ↗ | (On Diff #221345) | Not anymore (wasn't supposed to in the first place). Added tests too. |
600 ↗ | (On Diff #221345) | Qualifier captures exactly what's written in the source code, so it seems correct: S:: is what written down. Why would the qualifier be None? Maybe the purpose of this field is unclear? |
638 ↗ | (On Diff #221345) | There are no qualifiers written in the source code in any of the two references, therefore both qualifiers are empty. |
- Use DeclRefExpr::getFoundDecl, add a test
- Update a comment
- Remove redundant anon namespace declaration
- Remove :wa
- Do not filter-out macro references
- Document why we drop references with invalid locations, log if that happens
- Rename NextOffset to NextCodeChar
clang-tools-extra/clangd/FindTarget.h | ||
---|---|---|
96 ↗ | (On Diff #221345) | I wasn't happy about it because it actually needs a SourceManager to print completely, and I believe that's also necessary for debugging. But feel free to ignore if you're OK with that. |
clang-tools-extra/clangd/unittests/FindTargetTests.cpp | ||
498 ↗ | (On Diff #221345) | well, this looked more like "beginning of the last token we processed" to me. but now I see your point of view as well. Feel free to use whichever you want. |
600 ↗ | (On Diff #221345) | ah sorry, I missed the fact that this was written as S::type in the code, now it makes sense. just ignore this one. |
638 ↗ | (On Diff #221345) | yeah it totally makes sense now, the problem started with me missing the S:: in the previous example :D, nvm.. |
I believe all comments were addressed. PTAL and let me know if I missed something.
clang-tools-extra/clangd/FindTarget.h | ||
---|---|---|
96 ↗ | (On Diff #221345) | Having some llvm::toString is great, because it's nicely integrated to all of the infrastructure and very easy to use. |
93 ↗ | (On Diff #220999) | Thanks, this is definitely a valid concern. I was overthinking the problem, removed it. |
115 ↗ | (On Diff #220999) | I would avoid doing DynTypedNode - many of the cases don't quite make sense here, e.g. TypeLoc is arguably ok as it has location information, but Type* or QualType are not ok as they lack location information. Decl definitely sounds useful, though. Would allow to visit all top-level decls of a file, which is another use-case we probably want. Added that. |
LGTM, thanks!
clang-tools-extra/clangd/FindTarget.h | ||
---|---|---|
103 ↗ | (On Diff #221556) | nit: s/Decl *S/Decl *D/ |