diff options
author | Sam McCall <sam.mccall@gmail.com> | 2021-12-30 01:57:47 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2022-01-26 15:51:17 +0100 |
commit | 33c3ef2fbeec4ede5fc303b09cdca99ae2c0522a (patch) | |
tree | e5b2cf0e8f2eeba9ce6ff650981ff596d1470b9a /clang/lib/Basic/IdentifierTable.cpp | |
parent | a5e324e3e2edcc72d9e402b4d846cae615192ad8 (diff) | |
download | llvm-33c3ef2fbeec4ede5fc303b09cdca99ae2c0522a.zip llvm-33c3ef2fbeec4ede5fc303b09cdca99ae2c0522a.tar.gz llvm-33c3ef2fbeec4ede5fc303b09cdca99ae2c0522a.tar.bz2 |
[CodeCompletion][clangd] Clean __uglified parameter names in completion & hover
Underscore-uglified identifiers are used in standard library implementations to
guard against collisions with macros, and they hurt readability considerably.
(Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`.
When we're describing an interface, the exact names of parameters are not
critical so we can drop these prefixes.
This patch adds a new PrintingPolicy flag that can applies this stripping
when recursively printing pieces of AST.
We set it in code completion/signature help, and in clangd's hover display.
All three features also do a bit of manual poking at names, so fix up those too.
Fixes https://github.com/clangd/clangd/issues/736
Differential Revision: https://reviews.llvm.org/D116387
Diffstat (limited to 'clang/lib/Basic/IdentifierTable.cpp')
-rw-r--r-- | clang/lib/Basic/IdentifierTable.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp index d811aeec..b86cb7a 100644 --- a/clang/lib/Basic/IdentifierTable.cpp +++ b/clang/lib/Basic/IdentifierTable.cpp @@ -309,6 +309,14 @@ IdentifierInfo::isReserved(const LangOptions &LangOpts) const { return ReservedIdentifierStatus::NotReserved; } +StringRef IdentifierInfo::deuglifiedName() const { + StringRef Name = getName(); + if (Name.size() >= 2 && Name.front() == '_' && + (Name[1] == '_' || (Name[1] >= 'A' && Name[1] <= 'Z'))) + return Name.ltrim('_'); + return Name; +} + tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const { // We use a perfect hash function here involving the length of the keyword, // the first and third character. For preprocessor ID's there are no |