Created
May 22, 2012 03:15
-
-
Save tritao/2766291 to your computer and use it in GitHub Desktop.
libclang Name Mangling API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: include/clang-c/Index.h | |
=================================================================== | |
--- include/clang-c/Index.h (revision 156043) | |
+++ include/clang-c/Index.h (working copy) | |
@@ -4737,10 +4737,32 @@ | |
* @} | |
*/ | |
+/** \defgroup CINDEX_MANGLE Name Mangling API Functions | |
+ * | |
+ * @{ | |
+ */ | |
+ | |
/** | |
+ * \brief Represents the different available ABIs for name mangling. | |
+ */ | |
+typedef enum { | |
+ CXMangleABI_Itanium = 0, | |
+ CXMangleABI_Microsoft = 1, | |
+} CXMangleABI; | |
+ | |
+/** | |
+ * \brief Retrieve the CXString representing the mangled name of the cursor. | |
+ */ | |
+CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor, CXMangleABI); | |
+ | |
+/** | |
* @} | |
*/ | |
+/** | |
+ * @} | |
+ */ | |
+ | |
#ifdef __cplusplus | |
} | |
#endif | |
Index: tools/libclang/CXCursor.cpp | |
=================================================================== | |
--- tools/libclang/CXCursor.cpp (revision 156043) | |
+++ tools/libclang/CXCursor.cpp (working copy) | |
@@ -24,6 +24,7 @@ | |
#include "clang/AST/Expr.h" | |
#include "clang/AST/ExprCXX.h" | |
#include "clang/AST/ExprObjC.h" | |
+#include "clang/AST/Mangle.h" | |
#include "clang-c/Index.h" | |
#include "llvm/Support/ErrorHandling.h" | |
@@ -1253,5 +1254,39 @@ | |
pool.AvailableCursors.push_back(Vec); | |
} | |
+ | |
+CXString clang_Cursor_getMangling(CXCursor C, CXMangleABI ABI) { | |
+ if (clang_isInvalid(C.kind) || | |
+ !clang_isDeclaration(C.kind)) | |
+ return cxstring::createCXString(""); | |
+ | |
+ Decl* D = getCursorDecl(C); | |
+ | |
+ if(!D || !isa<NamedDecl>(D)) | |
+ return cxstring::createCXString(""); | |
+ | |
+ NamedDecl* ND = static_cast<NamedDecl*>(D); | |
+ | |
+ ASTContext& AC = ND->getASTContext(); | |
+ | |
+ llvm::OwningPtr<MangleContext> MC; | |
+ | |
+ switch(ABI) { | |
+ default: | |
+ llvm_unreachable("Unknown mangling ABI"); | |
+ break; | |
+ case CXMangleABI_Itanium: | |
+ MC.reset(createItaniumMangleContext(AC, AC.getDiagnostics())); | |
+ break; | |
+ case CXMangleABI_Microsoft: | |
+ MC.reset(createMicrosoftMangleContext(AC, AC.getDiagnostics())); | |
+ break; | |
+ } | |
+ | |
+ std::string Mangled; | |
+ MC->mangleName(ND, llvm::raw_string_ostream(Mangled)); | |
+ | |
+ return cxstring::createCXString(Mangled); | |
+} | |
} // end: extern "C" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FWIW, I added this (though heavily modified) to upstream clang in r214410.