This is an archive of the discontinued LLVM Phabricator instance.

[AST] Extract Decl::printNestedNameSpecifier helper from Decl::printQualifiedName
ClosedPublic

Authored by ilya-biryukov on Sep 20 2019, 4:19 AM.

Details

Summary

To be used in clangd, e.g. in D66647.
Currently the alternative to this function is doing string manipulation on results of printQualifiedName, which is
hard-to-impossible to get right in presence of template arguments.

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Sep 20 2019, 4:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 20 2019, 4:19 AM
Herald added a subscriber: usaxena95. · View Herald Transcript
ilya-biryukov retitled this revision from [AST] Extrat Decl::printQualifier helper from Decl::printQualifiedName. to [AST] Extract Decl::printQualifier helper from Decl::printQualifiedName..Sep 20 2019, 4:25 AM
ilya-biryukov retitled this revision from [AST] Extract Decl::printQualifier helper from Decl::printQualifiedName. to [AST] Extract Decl::printQualifier helper from Decl::printQualifiedName.
aaron.ballman added a subscriber: aaron.ballman.
aaron.ballman added inline comments.
clang/include/clang/AST/Decl.h
313 ↗(On Diff #220998)

This doesn't return anything, so I think a better way to phrase the comment is "Prints only the nested name specifier, including a trailing :: at the end. e.g., if printQualifiedName(D) prints "A::B::i", this function prints "A::B::".`

317–318 ↗(On Diff #220998)

I'm not keen on "qualifier" here because types have qualifiers. How about printNestedNameSpecifier()?

ilya-biryukov marked 4 inline comments as done.
  • Update comments
  • Rename new function to printNestedNameSpecifier
clang/include/clang/AST/Decl.h
313 ↗(On Diff #220998)

Good point, thanks!

317–318 ↗(On Diff #220998)

Now I understand why we clang uses 'nested name specifier' everywhere!
Renamed per your suggestions.
FWIW, I would rather use NameQualifier and TypeQualifier to disambiguate between the two.
NestedNameSpecifier is a bit too long for my taste. But happy to stick with the conventions in the codebase.

ilya-biryukov retitled this revision from [AST] Extract Decl::printQualifier helper from Decl::printQualifiedName to [AST] Extract Decl::printNestedNameSpecifier helper from Decl::printQualifiedName.Sep 20 2019, 4:59 AM
kadircet accepted this revision.Sep 20 2019, 5:15 AM

LGTM, I know it is trivial, but some more unittests wouldn't hurt anyone :D

Also could you update the summary to mention "doing string manipulations in the presence of template arguments is hard?"

This revision is now accepted and ready to land.Sep 20 2019, 5:15 AM
ilya-biryukov edited the summary of this revision. (Show Details)EditedSep 20 2019, 5:18 AM

LGTM, I know it is trivial, but some more unittests wouldn't hurt anyone :D

Yeah, good point, I'll add a few besides tests for printQualifiedName.

Also could you update the summary to mention "doing string manipulations in the presence of template arguments is hard?"

Done.

aaron.ballman accepted this revision.Sep 20 2019, 5:26 AM

LGTM!

clang/include/clang/AST/Decl.h
317–318 ↗(On Diff #220998)

I think it'd be a pretty large undertaking to hit all of the places where we talk about qualifiers to get to the point where that distinction makes sense. I think we should just stick with nested name specifier, as that's a term of art from the standard for this concept.

ilya-biryukov marked 2 inline comments as done.Sep 20 2019, 5:32 AM
ilya-biryukov added inline comments.
clang/include/clang/AST/Decl.h
317–318 ↗(On Diff #220998)

Fully agree, it's too late to change it at this point.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 25 2019, 6:09 AM