This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Mention when CXXThis is implicit in exposed AST.
ClosedPublic

Authored by sammccall on Nov 20 2020, 6:48 AM.

Details

Summary

Seeing an implicit this in the AST is pretty confusing I think.
While here, also mention when this is const.

Diff Detail

Event Timeline

sammccall created this revision.Nov 20 2020, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2020, 6:48 AM
sammccall requested review of this revision.Nov 20 2020, 6:48 AM

This looks like an improvement to me as well, thanks!

clang-tools-extra/clangd/DumpAST.cpp
237

should we ensure we always return within the branch (as we do within the rest of the branches to make sure we don't accumulate details by mistake)? e.g:

if(CXXThisExpr) {
  details = {}
  if (const) details += "const";
  if (implicit) details += "implicit";
  return join(",", details);
}
clang-tools-extra/clangd/unittests/DumpASTTests.cpp
79–81

is this change intentional ?

sammccall added inline comments.Nov 20 2020, 4:51 PM
clang-tools-extra/clangd/DumpAST.cpp
237

Actually I was trying to *avoid* returning "" in several places.
I think of these functions as a collection of special cases where we have something to say - if we don't find anything, we fall off the end.
(getDetail for DeducedType is the other example)

Can change it if you think it's important though.

clang-tools-extra/clangd/unittests/DumpASTTests.cpp
79–81

Yeah, the problem is that I wanted the root in the new test to be a member function, so I needed to switch from findDecl("root") to findUnqualifiedDecl("root"). But that fails if there are two decls with that name, as there were here: the primary template root<T> and the specialization root<unsigned>. Thus the change to wrap the whole thing in a root namespace. Maybe there's a neater way to solve this, I'm not sure it matters much.

kadircet accepted this revision.Nov 21 2020, 1:47 AM
kadircet added inline comments.
clang-tools-extra/clangd/DumpAST.cpp
237

Actually I was trying to *avoid* returning "" in several places.

I agree that this is bad, but it feels acceptable when the code doesn't read that way directly :P

I think of these functions as a collection of special cases where we have something to say - if we don't find anything, we fall off the end.

I was afraid of entering other branches, before falling off the end (not applicable here, but assume one day we have a children of CXXThisExpr, this code will prefer the children when thisexpr is neither const nor implicit, which might be surprising).

Can change it if you think it's important though.

As mentioned not an immediate threat, but might become surprising in the future and require some digging. So would be nice if you can.

clang-tools-extra/clangd/unittests/DumpASTTests.cpp
79–81

ah makes sense. sorry i missed the change from finddecl to unqualifieddecl within the test body.

This revision is now accepted and ready to land.Nov 21 2020, 1:47 AM
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.