plotfi updated this revision to Diff 205729.
plotfi added a comment.

full context


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63584/new/

https://reviews.llvm.org/D63584

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp

Index: clang/lib/AST/Mangle.cpp
===================================================================
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -283,10 +284,16 @@
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
-    : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+class ASTNameGenerator::Implementation {
+  std::unique_ptr<MangleContext> MC;
+  llvm::DataLayout DL;
 
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
+public:
+  explicit Implementation(ASTContext &Ctx)
+      : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream &OS) {
     // First apply frontend mangling.
     SmallString<128> FrontendBuf;
     llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
@@ -312,7 +319,7 @@
     return false;
   }
 
-std::string ASTNameGenerator::getName(const Decl *D) {
+  std::string getName(const Decl *D) {
     std::string Name;
     {
       llvm::raw_string_ostream OS(Name);
@@ -333,8 +340,7 @@
     return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
   }
 
-std::vector<std::string>
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
+  std::vector<std::string> getAllManglings(const ObjCContainerDecl *OCD) {
     StringRef ClassName;
     if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(OCD))
       ClassName = OID->getObjCRuntimeNameAsString();
@@ -357,7 +363,7 @@
     };
   }
 
-std::vector<std::string> ASTNameGenerator::getAllManglings(const Decl *D) {
+  std::vector<std::string> getAllManglings(const Decl *D) {
     if (const auto *OCD = dyn_cast<ObjCContainerDecl>(D))
       return getAllManglings(OCD);
 
@@ -407,7 +413,8 @@
     return Manglings;
   }
 
-bool ASTNameGenerator::writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
+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);
@@ -425,14 +432,12 @@
     }
   }
 
-void ASTNameGenerator::writeObjCClassName(const ObjCInterfaceDecl *D,
-                                          raw_ostream &OS) {
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
     OS << getClassSymbolPrefix(ObjCClass, D->getASTContext());
     OS << D->getObjCRuntimeNameAsString();
   }
 
-std::string ASTNameGenerator::getMangledStructor(const NamedDecl *ND,
-                                                 unsigned StructorType) {
+  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) {
     std::string FrontendBuf;
     llvm::raw_string_ostream FOS(FrontendBuf);
 
@@ -449,8 +454,7 @@
     return BOS.str();
   }
 
-std::string ASTNameGenerator::getMangledThunk(const CXXMethodDecl *MD,
-                                              const ThunkInfo &T) {
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T) {
     std::string FrontendBuf;
     llvm::raw_string_ostream FOS(FrontendBuf);
 
@@ -463,3 +467,21 @@
 
     return BOS.str();
   }
+};
+
+ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
+    : Impl(new Implementation(Ctx)) {}
+
+ASTNameGenerator::~ASTNameGenerator() {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
+  return Impl->writeName(D, OS);
+}
+
+std::string ASTNameGenerator::getName(const Decl *D) {
+  return Impl->getName(D);
+}
+
+std::vector<std::string> ASTNameGenerator::getAllManglings(const Decl *D) {
+  return Impl->getAllManglings(D);
+}
Index: clang/include/clang/AST/Mangle.h
===================================================================
--- clang/include/clang/AST/Mangle.h
+++ clang/include/clang/AST/Mangle.h
@@ -17,7 +17,6 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/ABI.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Casting.h"
 
 namespace llvm {
@@ -246,21 +245,16 @@
 };
 
 class ASTNameGenerator {
-  std::unique_ptr<MangleContext> MC;
-  llvm::DataLayout DL;
-
 public:
   explicit ASTNameGenerator(ASTContext &Ctx);
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream &OS);
   std::string getName(const Decl *D);
   std::vector<std::string> getAllManglings(const Decl *D);
 
 private:
-  std::vector<std::string> getAllManglings(const ObjCContainerDecl *OCD);
-  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS);
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS);
-  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
-  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T);
+  class Implementation;
+  std::unique_ptr<Implementation> Impl;
 };
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to