[PATCH] D59745: [NFC] Move writeFuncOrVarName out of class CodegenNameGenerator so that it can be reused more easily.

Puyan Lotfi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 23 23:05:31 PDT 2019


plotfi created this revision.
plotfi added reviewers: compnerd, akyrtzi.
Herald added subscribers: cfe-commits, jdoerfert, arphaman.
Herald added a project: clang.

I simply want a helper function to use for printing out mangled Decl names. I think this could be a pretty simple straightforward patch to do so, in an NFC manner.


Repository:
  rC Clang

https://reviews.llvm.org/D59745

Files:
  clang/include/clang/Index/CodegenNameGenerator.h
  clang/lib/Index/CodegenNameGenerator.cpp


Index: clang/lib/Index/CodegenNameGenerator.cpp
===================================================================
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -24,6 +24,29 @@
 using namespace clang;
 using namespace clang::index;
 
+namespace clang {
+namespace index {
+bool writeFuncOrVarName(MangleContext *MC, const NamedDecl *D,
+                        raw_ostream &OS) {
+  if (MC->shouldMangleDeclName(D)) {
+    if (const auto *CtorD = dyn_cast<CXXConstructorDecl>(D))
+      MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
+    else if (const auto *DtorD = dyn_cast<CXXDestructorDecl>(D))
+      MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
+    else
+      MC->mangleName(D, OS);
+    return false;
+  } else {
+    IdentifierInfo *II = D->getIdentifier();
+    if (!II)
+      return true;
+    OS << II->getName();
+    return false;
+  }
+}
+} // namespace index
+} // namespace clang
+
 struct CodegenNameGenerator::Implementation {
   std::unique_ptr<MangleContext> MC;
   llvm::DataLayout DL;
@@ -147,21 +170,7 @@
 
 private:
   bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
-    if (MC->shouldMangleDeclName(D)) {
-      if (const auto *CtorD = dyn_cast<CXXConstructorDecl>(D))
-        MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
-      else if (const auto *DtorD = dyn_cast<CXXDestructorDecl>(D))
-        MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
-      else
-        MC->mangleName(D, OS);
-      return false;
-    } else {
-      IdentifierInfo *II = D->getIdentifier();
-      if (!II)
-        return true;
-      OS << II->getName();
-      return false;
-    }
+    return clang::index::writeFuncOrVarName(MC.get(), D, OS);
   }
 
   void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
Index: clang/include/clang/Index/CodegenNameGenerator.h
===================================================================
--- clang/include/clang/Index/CodegenNameGenerator.h
+++ clang/include/clang/Index/CodegenNameGenerator.h
@@ -13,7 +13,10 @@
 #ifndef LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 #define LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Mangle.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/Support/raw_ostream.h"
 #include <memory>
 #include <string>
 #include <vector>
@@ -24,6 +27,8 @@
 
 namespace index {
 
+bool writeFuncOrVarName(MangleContext *MC, const NamedDecl *D, raw_ostream &OS);
+
 class CodegenNameGenerator {
 public:
   explicit CodegenNameGenerator(ASTContext &Ctx);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59745.192024.patch
Type: text/x-patch
Size: 2555 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190324/07cecb14/attachment.bin>


More information about the cfe-commits mailing list