[PATCH] D84599: [clang-index] Use NamedDecl::getDeclName() instead of NamedDecl::printName in USRGenerator::EmitDeclName

Bruno Ricci via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 26 09:49:01 PDT 2020


riccibruno created this revision.
riccibruno added reviewers: akyrtzi, jkorous, sammccall, hokein.
riccibruno added a project: clang.
Herald added subscribers: cfe-commits, arphaman, dexonsmith.

`NamedDecl::printName` is used as a customisation point for `getNameForDiagnostic`. The default implementation is just sending the `DeclarationName` into the output stream, but it can be overloaded to display a more user-friendly name for some entities.

Currently only `DecompositionDecl` and `MSGuidDecl` have an overload (and they were both added after this code was written) but I will be adding overloads to `VarDecl`, `FieldDecl`, `EnumDecl` and `RecordDecl` to better handle unnamed entities.

To preserve the current behaviour (that is except for `DecompositionDecl` and `MSGuidDecl` which I don't think are relevant here?), just send the `DeclarationName` into the output instead of going through `NamedDecl::printName`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84599

Files:
  clang/lib/Index/USRGeneration.cpp


Index: clang/lib/Index/USRGeneration.cpp
===================================================================
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -179,7 +179,7 @@
 
 bool USRGenerator::EmitDeclName(const NamedDecl *D) {
   const unsigned startSize = Buf.size();
-  D->printName(Out);
+  Out << D->getDeclName();
   const unsigned endSize = Buf.size();
   return startSize == endSize;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84599.280732.patch
Type: text/x-patch
Size: 429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200726/b7f55bb1/attachment.bin>


More information about the cfe-commits mailing list