Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1 | //===--- Mangle.cpp - Mangle C++ Names --------------------------*- C++ -*-===// |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implements C++ name mangling according to the Itanium C++ ABI, |
| 11 | // which is used in GCC 3.2 and newer (and many compilers that are |
| 12 | // ABI-compatible with GCC): |
| 13 | // |
| 14 | // http://www.codesourcery.com/public/cxx-abi/abi.html |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | #include "Mangle.h" |
| 18 | #include "clang/AST/ASTContext.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclCXX.h" |
Anders Carlsson | a40c5e4 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclTemplate.h" |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 23 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 24 | #include "clang/Basic/SourceManager.h" |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 25 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Compiler.h" |
| 27 | #include "llvm/Support/raw_ostream.h" |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | |
| 31 | namespace { |
| 32 | class VISIBILITY_HIDDEN CXXNameMangler { |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 33 | MangleContext &Context; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 34 | llvm::raw_ostream &Out; |
| 35 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 36 | const CXXMethodDecl *Structor; |
| 37 | unsigned StructorType; |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 38 | CXXCtorType CtorType; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 40 | llvm::DenseMap<uintptr_t, unsigned> Substitutions; |
| 41 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 42 | public: |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 43 | CXXNameMangler(MangleContext &C, llvm::raw_ostream &os) |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 44 | : Context(C), Out(os), Structor(0), StructorType(0) { } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 45 | |
| 46 | bool mangle(const NamedDecl *D); |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 47 | void mangleCalloffset(int64_t nv, int64_t v); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 48 | void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v); |
| 49 | void mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 50 | int64_t nv_t, int64_t v_t, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 51 | int64_t nv_r, int64_t v_r); |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 52 | void mangleGuardVariable(const VarDecl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 54 | void mangleCXXVtable(QualType Type); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 55 | void mangleCXXRtti(QualType Type); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 56 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type); |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 57 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 58 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 59 | private: |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 60 | bool mangleSubstitution(const NamedDecl *ND); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 61 | bool mangleSubstitution(QualType T); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 62 | bool mangleSubstitution(uintptr_t Ptr); |
| 63 | |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 64 | bool mangleStandardSubstitution(const NamedDecl *ND); |
| 65 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 66 | void addSubstitution(const NamedDecl *ND) { |
| 67 | addSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 68 | } |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 69 | void addSubstitution(QualType T); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 70 | void addSubstitution(uintptr_t Ptr); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 71 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 72 | bool mangleFunctionDecl(const FunctionDecl *FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 73 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 74 | void mangleFunctionEncoding(const FunctionDecl *FD); |
| 75 | void mangleName(const NamedDecl *ND); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 76 | void mangleName(const TemplateDecl *TD, |
| 77 | const TemplateArgument *TemplateArgs, |
| 78 | unsigned NumTemplateArgs); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 79 | void mangleUnqualifiedName(const NamedDecl *ND); |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 80 | void mangleUnscopedName(const NamedDecl *ND); |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 81 | void mangleUnscopedTemplateName(const TemplateDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 82 | void mangleSourceName(const IdentifierInfo *II); |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 83 | void mangleLocalName(const NamedDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 84 | void mangleNestedName(const NamedDecl *ND); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 85 | void mangleNestedName(const TemplateDecl *TD, |
| 86 | const TemplateArgument *TemplateArgs, |
| 87 | unsigned NumTemplateArgs); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 88 | void manglePrefix(const DeclContext *DC); |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 89 | void mangleTemplatePrefix(const TemplateDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 90 | void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 91 | void mangleQualifiers(Qualifiers Quals); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 92 | void mangleType(QualType T); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 93 | |
| 94 | // Declare manglers for every type class. |
| 95 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 96 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
| 97 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); |
| 98 | #include "clang/AST/TypeNodes.def" |
| 99 | |
| 100 | void mangleType(const TagType*); |
| 101 | void mangleBareFunctionType(const FunctionType *T, |
| 102 | bool MangleReturnType); |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 103 | void mangleExpression(const Expr *E); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 104 | void mangleCXXCtorType(CXXCtorType T); |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 105 | void mangleCXXDtorType(CXXDtorType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 107 | void mangleTemplateArgs(const TemplateArgument *TemplateArgs, |
| 108 | unsigned NumTemplateArgs); |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 109 | void mangleTemplateArgumentList(const TemplateArgumentList &L); |
| 110 | void mangleTemplateArgument(const TemplateArgument &A); |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 111 | |
| 112 | void mangleTemplateParameter(unsigned Index); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 113 | }; |
| 114 | } |
| 115 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 116 | static bool isInCLinkageSpecification(const Decl *D) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 117 | for (const DeclContext *DC = D->getDeclContext(); |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 118 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 120 | return Linkage->getLanguage() == LinkageSpecDecl::lang_c; |
| 121 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 122 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 123 | return false; |
| 124 | } |
| 125 | |
| 126 | bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 127 | // Clang's "overloadable" attribute extension to C/C++ implies name mangling |
| 128 | // (always). |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 129 | if (!FD->hasAttr<OverloadableAttr>()) { |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 130 | // C functions are not mangled, and "main" is never mangled. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 131 | if (!Context.getASTContext().getLangOptions().CPlusPlus || FD->isMain()) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 132 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 133 | |
| 134 | // No mangling in an "implicit extern C" header. |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 135 | if (FD->getLocation().isValid() && |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 136 | Context.getASTContext().getSourceManager(). |
| 137 | isInExternCSystemHeader(FD->getLocation())) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 138 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 140 | // No name mangling in a C linkage specification. |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 141 | if (!isa<CXXMethodDecl>(FD) && isInCLinkageSpecification(FD)) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 142 | return false; |
| 143 | } |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 144 | |
| 145 | // If we get here, mangle the decl name! |
| 146 | Out << "_Z"; |
| 147 | mangleFunctionEncoding(FD); |
| 148 | return true; |
| 149 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 150 | |
| 151 | bool CXXNameMangler::mangle(const NamedDecl *D) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 152 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 153 | // over all other naming in the .o file. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 154 | if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 155 | // If we have an asm name, then we use it as the mangling. |
| 156 | Out << '\01'; // LLVM IR Marker for __asm("foo") |
| 157 | Out << ALA->getLabel(); |
| 158 | return true; |
| 159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 161 | // <mangled-name> ::= _Z <encoding> |
| 162 | // ::= <data name> |
| 163 | // ::= <special-name> |
| 164 | |
| 165 | // FIXME: Actually use a visitor to decode these? |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 166 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 167 | return mangleFunctionDecl(FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 169 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 170 | if (!Context.getASTContext().getLangOptions().CPlusPlus || |
Anders Carlsson | 9ccb065 | 2009-04-11 01:19:45 +0000 | [diff] [blame] | 171 | isInCLinkageSpecification(D) || |
| 172 | D->getDeclContext()->isTranslationUnit()) |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 173 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 175 | Out << "_Z"; |
| 176 | mangleName(VD); |
| 177 | return true; |
| 178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 179 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 180 | return false; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D, |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 184 | CXXCtorType Type) { |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 185 | assert(!Structor && "Structor already set!"); |
| 186 | Structor = D; |
| 187 | StructorType = Type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 189 | mangle(D); |
| 190 | } |
| 191 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 192 | void CXXNameMangler::mangleCXXDtor(const CXXDestructorDecl *D, |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 193 | CXXDtorType Type) { |
| 194 | assert(!Structor && "Structor already set!"); |
| 195 | Structor = D; |
| 196 | StructorType = Type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 198 | mangle(D); |
| 199 | } |
| 200 | |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 201 | void CXXNameMangler::mangleCXXVtable(QualType T) { |
| 202 | // <special-name> ::= TV <type> # virtual table |
| 203 | Out << "_ZTV"; |
| 204 | mangleType(T); |
| 205 | } |
| 206 | |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 207 | void CXXNameMangler::mangleCXXRtti(QualType T) { |
| 208 | // <special-name> ::= TI <type> # typeinfo structure |
| 209 | Out << "_ZTI"; |
| 210 | mangleType(T); |
| 211 | } |
| 212 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 213 | void CXXNameMangler::mangleGuardVariable(const VarDecl *D) { |
| 214 | // <special-name> ::= GV <object name> # Guard variable for one-time |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 215 | // # initialization |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 216 | |
| 217 | Out << "_ZGV"; |
| 218 | mangleName(D); |
| 219 | } |
| 220 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 221 | void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
| 222 | // <encoding> ::= <function name> <bare-function-type> |
| 223 | mangleName(FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 225 | // Whether the mangling of a function type includes the return type depends on |
| 226 | // the context and the nature of the function. The rules for deciding whether |
| 227 | // the return type is included are: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 228 | // |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 229 | // 1. Template functions (names or types) have return types encoded, with |
| 230 | // the exceptions listed below. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 231 | // 2. Function types not appearing as part of a function name mangling, |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 232 | // e.g. parameters, pointer types, etc., have return type encoded, with the |
| 233 | // exceptions listed below. |
| 234 | // 3. Non-template function names do not have return types encoded. |
| 235 | // |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 236 | // The exceptions mentioned in (1) and (2) above, for which the return type is |
| 237 | // never included, are |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 238 | // 1. Constructors. |
| 239 | // 2. Destructors. |
| 240 | // 3. Conversion operator functions, e.g. operator int. |
| 241 | bool MangleReturnType = false; |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 242 | if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) { |
| 243 | if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || |
| 244 | isa<CXXConversionDecl>(FD))) |
| 245 | MangleReturnType = true; |
| 246 | |
| 247 | // Mangle the type of the primary template. |
| 248 | FD = PrimaryTemplate->getTemplatedDecl(); |
| 249 | } |
| 250 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 251 | mangleBareFunctionType(FD->getType()->getAs<FunctionType>(), MangleReturnType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static bool isStdNamespace(const DeclContext *DC) { |
| 255 | if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit()) |
| 256 | return false; |
| 257 | |
| 258 | const NamespaceDecl *NS = cast<NamespaceDecl>(DC); |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 259 | const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier(); |
| 260 | return II && II->isStr("std"); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 263 | static const TemplateDecl * |
| 264 | isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 265 | // Check if we have a function template. |
| 266 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){ |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 267 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 268 | TemplateArgs = FD->getTemplateSpecializationArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 269 | return TD; |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 273 | // Check if we have a class template. |
| 274 | if (const ClassTemplateSpecializationDecl *Spec = |
| 275 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 276 | TemplateArgs = &Spec->getTemplateArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 277 | return Spec->getSpecializedTemplate(); |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 283 | void CXXNameMangler::mangleName(const NamedDecl *ND) { |
| 284 | // <name> ::= <nested-name> |
| 285 | // ::= <unscoped-name> |
| 286 | // ::= <unscoped-template-name> <template-args> |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 287 | // ::= <local-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 288 | // |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 289 | const DeclContext *DC = ND->getDeclContext(); |
Anders Carlsson | 5cc58c6 | 2009-09-22 17:23:30 +0000 | [diff] [blame] | 290 | while (isa<LinkageSpecDecl>(DC)) |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 291 | DC = DC->getParent(); |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 292 | |
| 293 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 294 | // Check if we have a template. |
| 295 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 296 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 297 | mangleUnscopedTemplateName(TD); |
| 298 | mangleTemplateArgumentList(*TemplateArgs); |
| 299 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 300 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 301 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 302 | mangleUnscopedName(ND); |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | if (isa<FunctionDecl>(DC)) { |
| 307 | mangleLocalName(ND); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | mangleNestedName(ND); |
| 312 | } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 313 | void CXXNameMangler::mangleName(const TemplateDecl *TD, |
| 314 | const TemplateArgument *TemplateArgs, |
| 315 | unsigned NumTemplateArgs) { |
| 316 | const DeclContext *DC = TD->getDeclContext(); |
| 317 | while (isa<LinkageSpecDecl>(DC)) { |
| 318 | assert(cast<LinkageSpecDecl>(DC)->getLanguage() == |
| 319 | LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!"); |
| 320 | DC = DC->getParent(); |
| 321 | } |
| 322 | |
| 323 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 324 | mangleUnscopedTemplateName(TD); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 325 | mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
| 326 | } else { |
| 327 | mangleNestedName(TD, TemplateArgs, NumTemplateArgs); |
| 328 | } |
| 329 | } |
| 330 | |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 331 | void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { |
| 332 | // <unscoped-name> ::= <unqualified-name> |
| 333 | // ::= St <unqualified-name> # ::std:: |
| 334 | if (isStdNamespace(ND->getDeclContext())) |
| 335 | Out << "St"; |
| 336 | |
| 337 | mangleUnqualifiedName(ND); |
| 338 | } |
| 339 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 340 | void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 341 | // <unscoped-template-name> ::= <unscoped-name> |
| 342 | // ::= <substitution> |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 343 | if (mangleSubstitution(ND)) |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 344 | return; |
| 345 | |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 346 | mangleUnscopedName(ND->getTemplatedDecl()); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 347 | addSubstitution(ND); |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 350 | void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 351 | // <call-offset> ::= h <nv-offset> _ |
| 352 | // ::= v <v-offset> _ |
| 353 | // <nv-offset> ::= <offset number> # non-virtual base override |
| 354 | // <v-offset> ::= <offset nubmer> _ <virtual offset number> |
| 355 | // # virtual base override, with vcall offset |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 356 | if (v == 0) { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 357 | Out << "h"; |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 358 | if (nv < 0) { |
| 359 | Out << "n"; |
| 360 | nv = -nv; |
| 361 | } |
| 362 | Out << nv; |
| 363 | } else { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 364 | Out << "v"; |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 365 | if (nv < 0) { |
| 366 | Out << "n"; |
| 367 | nv = -nv; |
| 368 | } |
| 369 | Out << nv; |
| 370 | Out << "_"; |
| 371 | if (v < 0) { |
| 372 | Out << "n"; |
| 373 | v = -v; |
| 374 | } |
| 375 | Out << v; |
| 376 | } |
| 377 | Out << "_"; |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 378 | } |
| 379 | |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 380 | void CXXNameMangler::mangleThunk(const FunctionDecl *FD, int64_t nv, |
| 381 | int64_t v) { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 382 | // <special-name> ::= T <call-offset> <base encoding> |
| 383 | // # base is the nominal target function of thunk |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 384 | Out << "_ZT"; |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 385 | mangleCalloffset(nv, v); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 386 | mangleFunctionEncoding(FD); |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 387 | } |
| 388 | |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 389 | void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 390 | int64_t nv_t, int64_t v_t, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 391 | int64_t nv_r, int64_t v_r) { |
| 392 | // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> |
| 393 | // # base is the nominal target function of thunk |
| 394 | // # first call-offset is 'this' adjustment |
| 395 | // # second call-offset is result adjustment |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 396 | Out << "_ZTc"; |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 397 | mangleCalloffset(nv_t, v_t); |
| 398 | mangleCalloffset(nv_r, v_r); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 399 | mangleFunctionEncoding(FD); |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 402 | void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) { |
| 403 | // <unqualified-name> ::= <operator-name> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | // ::= <ctor-dtor-name> |
| 405 | // ::= <source-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 406 | DeclarationName Name = ND->getDeclName(); |
| 407 | switch (Name.getNameKind()) { |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 408 | case DeclarationName::Identifier: { |
| 409 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 410 | if (NS->isAnonymousNamespace()) { |
| 411 | // This is how gcc mangles these names. It's apparently |
| 412 | // always '1', no matter how many different anonymous |
| 413 | // namespaces appear in a context. |
| 414 | Out << "12_GLOBAL__N_1"; |
| 415 | break; |
| 416 | } |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 417 | } |
| 418 | |
| 419 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 420 | mangleSourceName(II); |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | // We must have an anonymous struct. |
| 425 | const TagDecl *TD = cast<TagDecl>(ND); |
| 426 | if (const TypedefDecl *D = TD->getTypedefForAnonDecl()) { |
| 427 | assert(TD->getDeclContext() == D->getDeclContext() && |
| 428 | "Typedef should not be in another decl context!"); |
| 429 | assert(D->getDeclName().getAsIdentifierInfo() && |
| 430 | "Typedef was not named!"); |
| 431 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | // Get a unique id for the anonymous struct. |
| 436 | uint64_t AnonStructId = Context.getAnonymousStructId(TD); |
| 437 | |
| 438 | // Mangle it as a source name in the form |
| 439 | // [n] $_<id> |
| 440 | // where n is the length of the string. |
| 441 | llvm::SmallString<8> Str; |
| 442 | Str += "$_"; |
| 443 | Str += llvm::utostr(AnonStructId); |
| 444 | |
| 445 | Out << Str.size(); |
| 446 | Out << Str.str(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 447 | break; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame^] | 448 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 449 | |
| 450 | case DeclarationName::ObjCZeroArgSelector: |
| 451 | case DeclarationName::ObjCOneArgSelector: |
| 452 | case DeclarationName::ObjCMultiArgSelector: |
| 453 | assert(false && "Can't mangle Objective-C selector names here!"); |
| 454 | break; |
| 455 | |
| 456 | case DeclarationName::CXXConstructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 457 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 458 | // If the named decl is the C++ constructor we're mangling, use the type |
| 459 | // we were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 460 | mangleCXXCtorType(static_cast<CXXCtorType>(StructorType)); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 461 | else |
| 462 | // Otherwise, use the complete constructor name. This is relevant if a |
| 463 | // class with a constructor is declared within a constructor. |
| 464 | mangleCXXCtorType(Ctor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 465 | break; |
| 466 | |
| 467 | case DeclarationName::CXXDestructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 468 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 469 | // If the named decl is the C++ destructor we're mangling, use the type we |
| 470 | // were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 471 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); |
| 472 | else |
| 473 | // Otherwise, use the complete destructor name. This is relevant if a |
| 474 | // class with a destructor is declared within a destructor. |
| 475 | mangleCXXDtorType(Dtor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 476 | break; |
| 477 | |
| 478 | case DeclarationName::CXXConversionFunctionName: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | // <operator-name> ::= cv <type> # (cast) |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 480 | Out << "cv"; |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 481 | mangleType(Context.getASTContext().getCanonicalType(Name.getCXXNameType())); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 482 | break; |
| 483 | |
| 484 | case DeclarationName::CXXOperatorName: |
| 485 | mangleOperatorName(Name.getCXXOverloadedOperator(), |
| 486 | cast<FunctionDecl>(ND)->getNumParams()); |
| 487 | break; |
| 488 | |
| 489 | case DeclarationName::CXXUsingDirective: |
| 490 | assert(false && "Can't mangle a using directive name!"); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 491 | break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
| 495 | void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |
| 496 | // <source-name> ::= <positive length number> <identifier> |
| 497 | // <number> ::= [n] <non-negative decimal integer> |
| 498 | // <identifier> ::= <unqualified source code identifier> |
| 499 | Out << II->getLength() << II->getName(); |
| 500 | } |
| 501 | |
| 502 | void CXXNameMangler::mangleNestedName(const NamedDecl *ND) { |
| 503 | // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E |
| 504 | // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 505 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 506 | Out << 'N'; |
| 507 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 508 | mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers())); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 509 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 510 | // Check if we have a template. |
| 511 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 512 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 513 | mangleTemplatePrefix(TD); |
| 514 | mangleTemplateArgumentList(*TemplateArgs); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 515 | } else { |
| 516 | manglePrefix(ND->getDeclContext()); |
| 517 | mangleUnqualifiedName(ND); |
| 518 | } |
| 519 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 520 | Out << 'E'; |
| 521 | } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 522 | void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, |
| 523 | const TemplateArgument *TemplateArgs, |
| 524 | unsigned NumTemplateArgs) { |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 525 | // <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
| 526 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 527 | Out << 'N'; |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 528 | |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 529 | mangleTemplatePrefix(TD); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 530 | mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 531 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 532 | Out << 'E'; |
| 533 | } |
| 534 | |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 535 | void CXXNameMangler::mangleLocalName(const NamedDecl *ND) { |
| 536 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| 537 | // := Z <function encoding> E s [<discriminator>] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | // <discriminator> := _ <non-negative number> |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 539 | Out << 'Z'; |
| 540 | mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext())); |
| 541 | Out << 'E'; |
| 542 | mangleSourceName(ND->getIdentifier()); |
| 543 | } |
| 544 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 545 | void CXXNameMangler::manglePrefix(const DeclContext *DC) { |
| 546 | // <prefix> ::= <prefix> <unqualified-name> |
| 547 | // ::= <template-prefix> <template-args> |
| 548 | // ::= <template-param> |
| 549 | // ::= # empty |
| 550 | // ::= <substitution> |
| 551 | // FIXME: We only handle mangling of namespaces and classes at the moment. |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 552 | |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 553 | while (isa<LinkageSpecDecl>(DC)) |
| 554 | DC = DC->getParent(); |
| 555 | |
Anders Carlsson | 9263e91 | 2009-09-18 18:39:58 +0000 | [diff] [blame] | 556 | if (DC->isTranslationUnit()) |
| 557 | return; |
| 558 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 559 | if (mangleSubstitution(cast<NamedDecl>(DC))) |
| 560 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 561 | |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 562 | // Check if we have a template. |
| 563 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 564 | if (const TemplateDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) { |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 565 | mangleTemplatePrefix(TD); |
| 566 | mangleTemplateArgumentList(*TemplateArgs); |
| 567 | } else { |
| 568 | manglePrefix(DC->getParent()); |
| 569 | mangleUnqualifiedName(cast<NamedDecl>(DC)); |
| 570 | } |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 571 | |
| 572 | addSubstitution(cast<NamedDecl>(DC)); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 575 | void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND) { |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 576 | // <template-prefix> ::= <prefix> <template unqualified-name> |
| 577 | // ::= <template-param> |
| 578 | // ::= <substitution> |
| 579 | |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 580 | if (mangleSubstitution(ND)) |
| 581 | return; |
| 582 | |
| 583 | // FIXME: <template-param> |
Anders Carlsson | aa73ab1 | 2009-09-18 18:47:07 +0000 | [diff] [blame] | 584 | |
| 585 | manglePrefix(ND->getDeclContext()); |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 586 | mangleUnqualifiedName(ND->getTemplatedDecl()); |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 587 | |
| 588 | addSubstitution(ND); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | void |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 592 | CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) { |
| 593 | switch (OO) { |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 594 | // <operator-name> ::= nw # new |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 595 | case OO_New: Out << "nw"; break; |
| 596 | // ::= na # new[] |
| 597 | case OO_Array_New: Out << "na"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 598 | // ::= dl # delete |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 599 | case OO_Delete: Out << "dl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 600 | // ::= da # delete[] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 601 | case OO_Array_Delete: Out << "da"; break; |
| 602 | // ::= ps # + (unary) |
| 603 | // ::= pl # + |
| 604 | case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 605 | // ::= ng # - (unary) |
| 606 | // ::= mi # - |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 607 | case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 608 | // ::= ad # & (unary) |
| 609 | // ::= an # & |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 610 | case OO_Amp: Out << (Arity == 1? "ad" : "an"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 611 | // ::= de # * (unary) |
| 612 | // ::= ml # * |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 613 | case OO_Star: Out << (Arity == 1? "de" : "ml"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 614 | // ::= co # ~ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 615 | case OO_Tilde: Out << "co"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 616 | // ::= dv # / |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 617 | case OO_Slash: Out << "dv"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 618 | // ::= rm # % |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 619 | case OO_Percent: Out << "rm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 620 | // ::= or # | |
| 621 | case OO_Pipe: Out << "or"; break; |
| 622 | // ::= eo # ^ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 623 | case OO_Caret: Out << "eo"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 624 | // ::= aS # = |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 625 | case OO_Equal: Out << "aS"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 626 | // ::= pL # += |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 627 | case OO_PlusEqual: Out << "pL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 628 | // ::= mI # -= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 629 | case OO_MinusEqual: Out << "mI"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 630 | // ::= mL # *= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 631 | case OO_StarEqual: Out << "mL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 632 | // ::= dV # /= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 633 | case OO_SlashEqual: Out << "dV"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 634 | // ::= rM # %= |
| 635 | case OO_PercentEqual: Out << "rM"; break; |
| 636 | // ::= aN # &= |
| 637 | case OO_AmpEqual: Out << "aN"; break; |
| 638 | // ::= oR # |= |
| 639 | case OO_PipeEqual: Out << "oR"; break; |
| 640 | // ::= eO # ^= |
| 641 | case OO_CaretEqual: Out << "eO"; break; |
| 642 | // ::= ls # << |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 643 | case OO_LessLess: Out << "ls"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 644 | // ::= rs # >> |
| 645 | case OO_GreaterGreater: Out << "rs"; break; |
| 646 | // ::= lS # <<= |
| 647 | case OO_LessLessEqual: Out << "lS"; break; |
| 648 | // ::= rS # >>= |
| 649 | case OO_GreaterGreaterEqual: Out << "rS"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 650 | // ::= eq # == |
| 651 | case OO_EqualEqual: Out << "eq"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 652 | // ::= ne # != |
| 653 | case OO_ExclaimEqual: Out << "ne"; break; |
| 654 | // ::= lt # < |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 655 | case OO_Less: Out << "lt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 656 | // ::= gt # > |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 657 | case OO_Greater: Out << "gt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 658 | // ::= le # <= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 659 | case OO_LessEqual: Out << "le"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 660 | // ::= ge # >= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 661 | case OO_GreaterEqual: Out << "ge"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 662 | // ::= nt # ! |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 663 | case OO_Exclaim: Out << "nt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 664 | // ::= aa # && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 665 | case OO_AmpAmp: Out << "aa"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 666 | // ::= oo # || |
| 667 | case OO_PipePipe: Out << "oo"; break; |
| 668 | // ::= pp # ++ |
| 669 | case OO_PlusPlus: Out << "pp"; break; |
| 670 | // ::= mm # -- |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 671 | case OO_MinusMinus: Out << "mm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 672 | // ::= cm # , |
| 673 | case OO_Comma: Out << "cm"; break; |
| 674 | // ::= pm # ->* |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 675 | case OO_ArrowStar: Out << "pm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 676 | // ::= pt # -> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 677 | case OO_Arrow: Out << "pt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 678 | // ::= cl # () |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 679 | case OO_Call: Out << "cl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 680 | // ::= ix # [] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 681 | case OO_Subscript: Out << "ix"; break; |
| 682 | // UNSUPPORTED: ::= qu # ? |
| 683 | |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 684 | case OO_None: |
| 685 | case OO_Conditional: |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 686 | case NUM_OVERLOADED_OPERATORS: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 687 | assert(false && "Not an overloaded operator"); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 688 | break; |
| 689 | } |
| 690 | } |
| 691 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 692 | void CXXNameMangler::mangleQualifiers(Qualifiers Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 694 | if (Quals.hasRestrict()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 695 | Out << 'r'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 696 | if (Quals.hasVolatile()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 697 | Out << 'V'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 698 | if (Quals.hasConst()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 699 | Out << 'K'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 700 | |
| 701 | // FIXME: For now, just drop all extension qualifiers on the floor. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | void CXXNameMangler::mangleType(QualType T) { |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 705 | // Only operate on the canonical type! |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 706 | T = Context.getASTContext().getCanonicalType(T); |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 707 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 708 | bool IsSubstitutable = !isa<BuiltinType>(T); |
| 709 | if (IsSubstitutable && mangleSubstitution(T)) |
| 710 | return; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 711 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 712 | if (Qualifiers Quals = T.getQualifiers()) { |
| 713 | mangleQualifiers(Quals); |
| 714 | // Recurse: even if the qualified type isn't yet substitutable, |
| 715 | // the unqualified type might be. |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 716 | mangleType(T.getUnqualifiedType()); |
| 717 | } else { |
| 718 | switch (T->getTypeClass()) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 719 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 720 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 721 | case Type::CLASS: \ |
| 722 | llvm::llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
| 723 | return; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 724 | #define TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 725 | case Type::CLASS: \ |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 726 | mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 727 | break; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 728 | #include "clang/AST/TypeNodes.def" |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 729 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 730 | } |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 731 | |
| 732 | // Add the substitution. |
| 733 | if (IsSubstitutable) |
| 734 | addSubstitution(T); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | void CXXNameMangler::mangleType(const BuiltinType *T) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 738 | // <type> ::= <builtin-type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 739 | // <builtin-type> ::= v # void |
| 740 | // ::= w # wchar_t |
| 741 | // ::= b # bool |
| 742 | // ::= c # char |
| 743 | // ::= a # signed char |
| 744 | // ::= h # unsigned char |
| 745 | // ::= s # short |
| 746 | // ::= t # unsigned short |
| 747 | // ::= i # int |
| 748 | // ::= j # unsigned int |
| 749 | // ::= l # long |
| 750 | // ::= m # unsigned long |
| 751 | // ::= x # long long, __int64 |
| 752 | // ::= y # unsigned long long, __int64 |
| 753 | // ::= n # __int128 |
| 754 | // UNSUPPORTED: ::= o # unsigned __int128 |
| 755 | // ::= f # float |
| 756 | // ::= d # double |
| 757 | // ::= e # long double, __float80 |
| 758 | // UNSUPPORTED: ::= g # __float128 |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 759 | // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits) |
| 760 | // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits) |
| 761 | // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits) |
| 762 | // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits) |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 763 | // ::= Di # char32_t |
| 764 | // ::= Ds # char16_t |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 765 | // ::= u <source-name> # vendor extended type |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 766 | // From our point of view, std::nullptr_t is a builtin, but as far as mangling |
| 767 | // is concerned, it's a type called std::nullptr_t. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 768 | switch (T->getKind()) { |
| 769 | case BuiltinType::Void: Out << 'v'; break; |
| 770 | case BuiltinType::Bool: Out << 'b'; break; |
| 771 | case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break; |
| 772 | case BuiltinType::UChar: Out << 'h'; break; |
| 773 | case BuiltinType::UShort: Out << 't'; break; |
| 774 | case BuiltinType::UInt: Out << 'j'; break; |
| 775 | case BuiltinType::ULong: Out << 'm'; break; |
| 776 | case BuiltinType::ULongLong: Out << 'y'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 777 | case BuiltinType::UInt128: Out << 'o'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 778 | case BuiltinType::SChar: Out << 'a'; break; |
| 779 | case BuiltinType::WChar: Out << 'w'; break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 780 | case BuiltinType::Char16: Out << "Ds"; break; |
| 781 | case BuiltinType::Char32: Out << "Di"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 782 | case BuiltinType::Short: Out << 's'; break; |
| 783 | case BuiltinType::Int: Out << 'i'; break; |
| 784 | case BuiltinType::Long: Out << 'l'; break; |
| 785 | case BuiltinType::LongLong: Out << 'x'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 786 | case BuiltinType::Int128: Out << 'n'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 787 | case BuiltinType::Float: Out << 'f'; break; |
| 788 | case BuiltinType::Double: Out << 'd'; break; |
| 789 | case BuiltinType::LongDouble: Out << 'e'; break; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 790 | case BuiltinType::NullPtr: Out << "St9nullptr_t"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 791 | |
| 792 | case BuiltinType::Overload: |
| 793 | case BuiltinType::Dependent: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | assert(false && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 795 | "Overloaded and dependent types shouldn't get to name mangling"); |
| 796 | break; |
Anders Carlsson | e89d159 | 2009-06-26 18:41:36 +0000 | [diff] [blame] | 797 | case BuiltinType::UndeducedAuto: |
| 798 | assert(0 && "Should not see undeduced auto here"); |
| 799 | break; |
Steve Naroff | 9533a7f | 2009-07-22 17:14:51 +0000 | [diff] [blame] | 800 | case BuiltinType::ObjCId: Out << "11objc_object"; break; |
| 801 | case BuiltinType::ObjCClass: Out << "10objc_class"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 802 | } |
| 803 | } |
| 804 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 805 | // <type> ::= <function-type> |
| 806 | // <function-type> ::= F [Y] <bare-function-type> E |
| 807 | void CXXNameMangler::mangleType(const FunctionProtoType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 808 | Out << 'F'; |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 809 | // FIXME: We don't have enough information in the AST to produce the 'Y' |
| 810 | // encoding for extern "C" function types. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 811 | mangleBareFunctionType(T, /*MangleReturnType=*/true); |
| 812 | Out << 'E'; |
| 813 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 814 | void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { |
| 815 | llvm::llvm_unreachable("Can't mangle K&R function prototypes"); |
| 816 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 817 | void CXXNameMangler::mangleBareFunctionType(const FunctionType *T, |
| 818 | bool MangleReturnType) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 819 | // We should never be mangling something without a prototype. |
| 820 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 821 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 822 | // <bare-function-type> ::= <signature type>+ |
| 823 | if (MangleReturnType) |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 824 | mangleType(Proto->getResultType()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 825 | |
Anders Carlsson | c6c91bc | 2009-04-01 00:15:23 +0000 | [diff] [blame] | 826 | if (Proto->getNumArgs() == 0) { |
| 827 | Out << 'v'; |
| 828 | return; |
| 829 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 830 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 831 | for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 832 | ArgEnd = Proto->arg_type_end(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 833 | Arg != ArgEnd; ++Arg) |
| 834 | mangleType(*Arg); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 835 | |
| 836 | // <builtin-type> ::= z # ellipsis |
| 837 | if (Proto->isVariadic()) |
| 838 | Out << 'z'; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 839 | } |
| 840 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 841 | // <type> ::= <class-enum-type> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | // <class-enum-type> ::= <name> |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 843 | void CXXNameMangler::mangleType(const EnumType *T) { |
| 844 | mangleType(static_cast<const TagType*>(T)); |
| 845 | } |
| 846 | void CXXNameMangler::mangleType(const RecordType *T) { |
| 847 | mangleType(static_cast<const TagType*>(T)); |
| 848 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 849 | void CXXNameMangler::mangleType(const TagType *T) { |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 850 | if (!T->getDecl()->getIdentifier()) |
| 851 | mangleName(T->getDecl()->getTypedefForAnonDecl()); |
| 852 | else |
| 853 | mangleName(T->getDecl()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 854 | } |
| 855 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 856 | // <type> ::= <array-type> |
| 857 | // <array-type> ::= A <positive dimension number> _ <element type> |
| 858 | // ::= A [<dimension expression>] _ <element type> |
| 859 | void CXXNameMangler::mangleType(const ConstantArrayType *T) { |
| 860 | Out << 'A' << T->getSize() << '_'; |
| 861 | mangleType(T->getElementType()); |
| 862 | } |
| 863 | void CXXNameMangler::mangleType(const VariableArrayType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 864 | Out << 'A'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 865 | mangleExpression(T->getSizeExpr()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 866 | Out << '_'; |
| 867 | mangleType(T->getElementType()); |
| 868 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 869 | void CXXNameMangler::mangleType(const DependentSizedArrayType *T) { |
| 870 | Out << 'A'; |
| 871 | mangleExpression(T->getSizeExpr()); |
| 872 | Out << '_'; |
| 873 | mangleType(T->getElementType()); |
| 874 | } |
| 875 | void CXXNameMangler::mangleType(const IncompleteArrayType *T) { |
| 876 | Out << 'A' << '_'; |
| 877 | mangleType(T->getElementType()); |
| 878 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 879 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 880 | // <type> ::= <pointer-to-member-type> |
| 881 | // <pointer-to-member-type> ::= M <class type> <member type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 882 | void CXXNameMangler::mangleType(const MemberPointerType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 883 | Out << 'M'; |
| 884 | mangleType(QualType(T->getClass(), 0)); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 885 | QualType PointeeType = T->getPointeeType(); |
| 886 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 887 | mangleQualifiers(Qualifiers::fromCVRMask(FPT->getTypeQuals())); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 888 | mangleType(FPT); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 889 | } else |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 890 | mangleType(PointeeType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 891 | } |
| 892 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 893 | // <type> ::= <template-param> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 894 | void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 895 | mangleTemplateParameter(T->getIndex()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 896 | } |
| 897 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 898 | // FIXME: <type> ::= <template-template-param> <template-args> |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 899 | |
| 900 | // <type> ::= P <type> # pointer-to |
| 901 | void CXXNameMangler::mangleType(const PointerType *T) { |
| 902 | Out << 'P'; |
| 903 | mangleType(T->getPointeeType()); |
| 904 | } |
| 905 | void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) { |
| 906 | Out << 'P'; |
| 907 | mangleType(T->getPointeeType()); |
| 908 | } |
| 909 | |
| 910 | // <type> ::= R <type> # reference-to |
| 911 | void CXXNameMangler::mangleType(const LValueReferenceType *T) { |
| 912 | Out << 'R'; |
| 913 | mangleType(T->getPointeeType()); |
| 914 | } |
| 915 | |
| 916 | // <type> ::= O <type> # rvalue reference-to (C++0x) |
| 917 | void CXXNameMangler::mangleType(const RValueReferenceType *T) { |
| 918 | Out << 'O'; |
| 919 | mangleType(T->getPointeeType()); |
| 920 | } |
| 921 | |
| 922 | // <type> ::= C <type> # complex pair (C 2000) |
| 923 | void CXXNameMangler::mangleType(const ComplexType *T) { |
| 924 | Out << 'C'; |
| 925 | mangleType(T->getElementType()); |
| 926 | } |
| 927 | |
| 928 | // GNU extension: vector types |
| 929 | void CXXNameMangler::mangleType(const VectorType *T) { |
| 930 | Out << "U8__vector"; |
| 931 | mangleType(T->getElementType()); |
| 932 | } |
| 933 | void CXXNameMangler::mangleType(const ExtVectorType *T) { |
| 934 | mangleType(static_cast<const VectorType*>(T)); |
| 935 | } |
| 936 | void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) { |
| 937 | Out << "U8__vector"; |
| 938 | mangleType(T->getElementType()); |
| 939 | } |
| 940 | |
Anders Carlsson | a40c5e4 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 941 | void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { |
| 942 | mangleSourceName(T->getDecl()->getIdentifier()); |
| 943 | } |
| 944 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 945 | void CXXNameMangler::mangleType(const BlockPointerType *T) { |
| 946 | assert(false && "can't mangle block pointer types yet"); |
| 947 | } |
| 948 | |
| 949 | void CXXNameMangler::mangleType(const FixedWidthIntType *T) { |
| 950 | assert(false && "can't mangle arbitary-precision integer type yet"); |
| 951 | } |
| 952 | |
| 953 | void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 954 | TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl(); |
| 955 | assert(TD && "FIXME: Support dependent template names!"); |
| 956 | |
| 957 | mangleName(TD, T->getArgs(), T->getNumArgs()); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | void CXXNameMangler::mangleType(const TypenameType *T) { |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 961 | // Typename types are always nested |
| 962 | Out << 'N'; |
| 963 | |
| 964 | const Type *QTy = T->getQualifier()->getAsType(); |
| 965 | if (const TemplateSpecializationType *TST = |
| 966 | dyn_cast<TemplateSpecializationType>(QTy)) { |
Anders Carlsson | 8859917 | 2009-09-27 01:06:07 +0000 | [diff] [blame] | 967 | if (!mangleSubstitution(QualType(TST, 0))) { |
| 968 | TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl(); |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 969 | |
Anders Carlsson | 8859917 | 2009-09-27 01:06:07 +0000 | [diff] [blame] | 970 | mangleTemplatePrefix(TD); |
| 971 | mangleTemplateArgs(TST->getArgs(), TST->getNumArgs()); |
| 972 | addSubstitution(QualType(TST, 0)); |
| 973 | } |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 974 | } else if (const TemplateTypeParmType *TTPT = |
| 975 | dyn_cast<TemplateTypeParmType>(QTy)) { |
| 976 | // We use the QualType mangle type variant here because it handles |
| 977 | // substitutions. |
| 978 | mangleType(QualType(TTPT, 0)); |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 979 | } else |
| 980 | assert(false && "Unhandled type!"); |
| 981 | |
| 982 | mangleSourceName(T->getIdentifier()); |
| 983 | |
| 984 | Out << 'E'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 985 | } |
| 986 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 987 | void CXXNameMangler::mangleExpression(const Expr *E) { |
| 988 | // <expression> ::= <unary operator-name> <expression> |
| 989 | // ::= <binary operator-name> <expression> <expression> |
| 990 | // ::= <trinary operator-name> <expression> <expression> <expression> |
| 991 | // ::= cl <expression>* E # call |
| 992 | // ::= cv <type> expression # conversion with one argument |
| 993 | // ::= cv <type> _ <expression>* E # conversion with a different number of arguments |
| 994 | // ::= st <type> # sizeof (a type) |
| 995 | // ::= at <type> # alignof (a type) |
| 996 | // ::= <template-param> |
| 997 | // ::= <function-param> |
| 998 | // ::= sr <type> <unqualified-name> # dependent name |
| 999 | // ::= sr <type> <unqualified-name> <template-args> # dependent template-id |
| 1000 | // ::= sZ <template-param> # size of a parameter pack |
| 1001 | // ::= <expr-primary> |
| 1002 | switch (E->getStmtClass()) { |
| 1003 | default: assert(false && "Unhandled expression kind!"); |
| 1004 | case Expr::DeclRefExprClass: { |
| 1005 | const Decl *D = cast<DeclRefExpr>(E)->getDecl(); |
| 1006 | |
| 1007 | switch (D->getKind()) { |
| 1008 | default: assert(false && "Unhandled decl kind!"); |
| 1009 | case Decl::NonTypeTemplateParm: { |
| 1010 | const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D); |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 1011 | mangleTemplateParameter(PD->getIndex()); |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | |
| 1015 | } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 1016 | |
| 1017 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1018 | } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 1019 | |
| 1020 | case Expr::UnresolvedDeclRefExprClass: { |
| 1021 | const UnresolvedDeclRefExpr *DRE = cast<UnresolvedDeclRefExpr>(E); |
| 1022 | const Type *QTy = DRE->getQualifier()->getAsType(); |
| 1023 | assert(QTy && "Qualifier was not type!"); |
| 1024 | |
| 1025 | // ::= sr <type> <unqualified-name> # dependent name |
| 1026 | Out << "sr"; |
| 1027 | mangleType(QualType(QTy, 0)); |
| 1028 | |
| 1029 | assert(DRE->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1030 | "Unhandled decl name kind!"); |
| 1031 | mangleSourceName(DRE->getDeclName().getAsIdentifierInfo()); |
| 1032 | |
| 1033 | break; |
| 1034 | } |
| 1035 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1036 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1039 | // FIXME: <type> ::= G <type> # imaginary (C 2000) |
| 1040 | // FIXME: <type> ::= U <source-name> <type> # vendor extended type qualifier |
| 1041 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1042 | void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) { |
| 1043 | // <ctor-dtor-name> ::= C1 # complete object constructor |
| 1044 | // ::= C2 # base object constructor |
| 1045 | // ::= C3 # complete object allocating constructor |
| 1046 | // |
| 1047 | switch (T) { |
| 1048 | case Ctor_Complete: |
| 1049 | Out << "C1"; |
| 1050 | break; |
| 1051 | case Ctor_Base: |
| 1052 | Out << "C2"; |
| 1053 | break; |
| 1054 | case Ctor_CompleteAllocating: |
| 1055 | Out << "C3"; |
| 1056 | break; |
| 1057 | } |
| 1058 | } |
| 1059 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1060 | void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) { |
| 1061 | // <ctor-dtor-name> ::= D0 # deleting destructor |
| 1062 | // ::= D1 # complete object destructor |
| 1063 | // ::= D2 # base object destructor |
| 1064 | // |
| 1065 | switch (T) { |
| 1066 | case Dtor_Deleting: |
| 1067 | Out << "D0"; |
| 1068 | break; |
| 1069 | case Dtor_Complete: |
| 1070 | Out << "D1"; |
| 1071 | break; |
| 1072 | case Dtor_Base: |
| 1073 | Out << "D2"; |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1078 | void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) { |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1079 | // <template-args> ::= I <template-arg>+ E |
| 1080 | Out << "I"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1081 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1082 | for (unsigned i = 0, e = L.size(); i != e; ++i) { |
| 1083 | const TemplateArgument &A = L[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1084 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1085 | mangleTemplateArgument(A); |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1086 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1087 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1088 | Out << "E"; |
| 1089 | } |
| 1090 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 1091 | void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs, |
| 1092 | unsigned NumTemplateArgs) { |
| 1093 | // <template-args> ::= I <template-arg>+ E |
| 1094 | Out << "I"; |
| 1095 | |
| 1096 | for (unsigned i = 0; i != NumTemplateArgs; ++i) { |
| 1097 | mangleTemplateArgument(TemplateArgs[i]); |
| 1098 | } |
| 1099 | |
| 1100 | Out << "E"; |
| 1101 | } |
| 1102 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1103 | void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1104 | // <template-arg> ::= <type> # type or template |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1105 | // ::= X <expression> E # expression |
| 1106 | // ::= <expr-primary> # simple expressions |
| 1107 | // ::= I <template-arg>* E # argument pack |
| 1108 | // ::= sp <expression> # pack expansion of (C++0x) |
| 1109 | switch (A.getKind()) { |
| 1110 | default: |
| 1111 | assert(0 && "Unknown template argument kind!"); |
| 1112 | case TemplateArgument::Type: |
| 1113 | mangleType(A.getAsType()); |
| 1114 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1115 | case TemplateArgument::Expression: |
| 1116 | Out << 'X'; |
| 1117 | mangleExpression(A.getAsExpr()); |
| 1118 | Out << 'E'; |
| 1119 | break; |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1120 | case TemplateArgument::Integral: |
| 1121 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 1122 | |
| 1123 | Out << 'L'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1124 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1125 | mangleType(A.getIntegralType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1127 | const llvm::APSInt *Integral = A.getAsIntegral(); |
| 1128 | if (A.getIntegralType()->isBooleanType()) { |
| 1129 | // Boolean values are encoded as 0/1. |
| 1130 | Out << (Integral->getBoolValue() ? '1' : '0'); |
| 1131 | } else { |
| 1132 | if (Integral->isNegative()) |
| 1133 | Out << 'n'; |
| 1134 | Integral->abs().print(Out, false); |
| 1135 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1137 | Out << 'E'; |
| 1138 | break; |
| 1139 | } |
| 1140 | } |
| 1141 | |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 1142 | void CXXNameMangler::mangleTemplateParameter(unsigned Index) { |
| 1143 | // <template-param> ::= T_ # first template parameter |
| 1144 | // ::= T <parameter-2 non-negative number> _ |
| 1145 | if (Index == 0) |
| 1146 | Out << "T_"; |
| 1147 | else |
| 1148 | Out << 'T' << (Index - 1) << '_'; |
| 1149 | } |
| 1150 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1151 | // <substitution> ::= S <seq-id> _ |
| 1152 | // ::= S_ |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 1153 | bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) { |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1154 | // Try one of the standard substitutions first. |
| 1155 | if (mangleStandardSubstitution(ND)) |
| 1156 | return true; |
| 1157 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 1158 | return mangleSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 1159 | } |
| 1160 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1161 | bool CXXNameMangler::mangleSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1162 | if (!T.getCVRQualifiers()) { |
| 1163 | if (const RecordType *RT = T->getAs<RecordType>()) |
| 1164 | return mangleSubstitution(RT->getDecl()); |
| 1165 | } |
| 1166 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1167 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
| 1168 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1169 | return mangleSubstitution(TypePtr); |
| 1170 | } |
| 1171 | |
| 1172 | bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) { |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1173 | llvm::DenseMap<uintptr_t, unsigned>::iterator I = |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1174 | Substitutions.find(Ptr); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1175 | if (I == Substitutions.end()) |
| 1176 | return false; |
| 1177 | |
| 1178 | unsigned SeqID = I->second; |
| 1179 | if (SeqID == 0) |
| 1180 | Out << "S_"; |
| 1181 | else { |
| 1182 | SeqID--; |
| 1183 | |
| 1184 | // <seq-id> is encoded in base-36, using digits and upper case letters. |
| 1185 | char Buffer[10]; |
| 1186 | char *BufferPtr = Buffer + 9; |
| 1187 | |
| 1188 | *BufferPtr = 0; |
| 1189 | if (SeqID == 0) *--BufferPtr = '0'; |
| 1190 | |
| 1191 | while (SeqID) { |
| 1192 | assert(BufferPtr > Buffer && "Buffer overflow!"); |
| 1193 | |
| 1194 | unsigned char c = static_cast<unsigned char>(SeqID) % 36; |
| 1195 | |
| 1196 | *--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10); |
| 1197 | SeqID /= 36; |
| 1198 | } |
| 1199 | |
| 1200 | Out << 'S' << BufferPtr << '_'; |
| 1201 | } |
| 1202 | |
| 1203 | return true; |
| 1204 | } |
| 1205 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1206 | static bool isCharType(QualType T) { |
| 1207 | if (T.isNull()) |
| 1208 | return false; |
| 1209 | |
| 1210 | return T->isSpecificBuiltinType(BuiltinType::Char_S) || |
| 1211 | T->isSpecificBuiltinType(BuiltinType::Char_U); |
| 1212 | } |
| 1213 | |
| 1214 | /// isCharSpecialization - Returns whether a given type is a template |
| 1215 | /// specialization of a given name with a single argument of type char. |
| 1216 | static bool isCharSpecialization(QualType T, const char *Name) { |
| 1217 | if (T.isNull()) |
| 1218 | return false; |
| 1219 | |
| 1220 | const RecordType *RT = T->getAs<RecordType>(); |
| 1221 | if (!RT) |
| 1222 | return false; |
| 1223 | |
| 1224 | const ClassTemplateSpecializationDecl *SD = |
| 1225 | dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()); |
| 1226 | if (!SD) |
| 1227 | return false; |
| 1228 | |
| 1229 | if (!isStdNamespace(SD->getDeclContext())) |
| 1230 | return false; |
| 1231 | |
| 1232 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 1233 | if (TemplateArgs.size() != 1) |
| 1234 | return false; |
| 1235 | |
| 1236 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 1237 | return false; |
| 1238 | |
| 1239 | if (strcmp(SD->getIdentifier()->getName(), Name) != 0) |
| 1240 | return false; |
| 1241 | |
| 1242 | return true; |
| 1243 | } |
| 1244 | |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1245 | bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) { |
| 1246 | // <substitution> ::= St # ::std:: |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1247 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 1248 | if (isStdNamespace(NS)) { |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1249 | Out << "St"; |
| 1250 | return true; |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) { |
| 1255 | if (!isStdNamespace(TD->getDeclContext())) |
| 1256 | return false; |
| 1257 | |
| 1258 | // <substitution> ::= Sa # ::std::allocator |
| 1259 | if (TD->getIdentifier()->isStr("allocator")) { |
| 1260 | Out << "Sa"; |
| 1261 | return true; |
| 1262 | } |
Anders Carlsson | 189d59c | 2009-09-26 23:14:39 +0000 | [diff] [blame] | 1263 | |
| 1264 | // <<substitution> ::= Sb # ::std::basic_string |
| 1265 | if (TD->getIdentifier()->isStr("basic_string")) { |
| 1266 | Out << "Sb"; |
| 1267 | return true; |
| 1268 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1269 | } |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1270 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1271 | if (const ClassTemplateSpecializationDecl *SD = |
| 1272 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 1273 | // <substitution> ::= Ss # ::std::basic_string<char, |
| 1274 | // ::std::char_traits<char>, |
| 1275 | // ::std::allocator<char> > |
| 1276 | if (SD->getIdentifier()->isStr("basic_string")) { |
| 1277 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 1278 | |
| 1279 | if (TemplateArgs.size() != 3) |
| 1280 | return false; |
| 1281 | |
| 1282 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 1283 | return false; |
| 1284 | |
| 1285 | if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits")) |
| 1286 | return false; |
| 1287 | |
| 1288 | if (!isCharSpecialization(TemplateArgs[2].getAsType(), "allocator")) |
| 1289 | return false; |
| 1290 | |
| 1291 | Out << "Ss"; |
| 1292 | return true; |
| 1293 | } |
| 1294 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1295 | return false; |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1298 | void CXXNameMangler::addSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1299 | if (!T.getCVRQualifiers()) { |
| 1300 | if (const RecordType *RT = T->getAs<RecordType>()) { |
| 1301 | addSubstitution(RT->getDecl()); |
| 1302 | return; |
| 1303 | } |
| 1304 | } |
| 1305 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1306 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1307 | addSubstitution(TypePtr); |
| 1308 | } |
| 1309 | |
| 1310 | void CXXNameMangler::addSubstitution(uintptr_t Ptr) { |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1311 | unsigned SeqID = Substitutions.size(); |
| 1312 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1313 | assert(!Substitutions.count(Ptr) && "Substitution already exists!"); |
| 1314 | Substitutions[Ptr] = SeqID; |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1317 | namespace clang { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1318 | /// \brief Mangles the name of the declaration D and emits that name to the |
| 1319 | /// given output stream. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1320 | /// |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1321 | /// If the declaration D requires a mangled name, this routine will emit that |
| 1322 | /// mangled name to \p os and return true. Otherwise, \p os will be unchanged |
| 1323 | /// and this routine will return false. In this case, the caller should just |
| 1324 | /// emit the identifier of the declaration (\c D->getIdentifier()) as its |
| 1325 | /// name. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1326 | bool mangleName(MangleContext &Context, const NamedDecl *D, |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1327 | llvm::raw_ostream &os) { |
Anders Carlsson | 578aa64 | 2009-05-03 16:51:04 +0000 | [diff] [blame] | 1328 | assert(!isa<CXXConstructorDecl>(D) && |
| 1329 | "Use mangleCXXCtor for constructor decls!"); |
| 1330 | assert(!isa<CXXDestructorDecl>(D) && |
| 1331 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1332 | |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1333 | PrettyStackTraceDecl CrashInfo(const_cast<NamedDecl *>(D), SourceLocation(), |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1334 | Context.getASTContext().getSourceManager(), |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1335 | "Mangling declaration"); |
| 1336 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1337 | CXXNameMangler Mangler(Context, os); |
Anders Carlsson | b217c1b | 2009-10-06 21:58:01 +0000 | [diff] [blame] | 1338 | if (!Mangler.mangle(cast<NamedDecl>(D->getCanonicalDecl()))) |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1339 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1340 | |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1341 | os.flush(); |
| 1342 | return true; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1343 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1344 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1345 | /// \brief Mangles the a thunk with the offset n for the declaration D and |
| 1346 | /// emits that name to the given output stream. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1347 | void mangleThunk(MangleContext &Context, const FunctionDecl *FD, |
| 1348 | int64_t nv, int64_t v, llvm::raw_ostream &os) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1349 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1350 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1351 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1353 | CXXNameMangler Mangler(Context, os); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1354 | Mangler.mangleThunk(FD, nv, v); |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1355 | os.flush(); |
| 1356 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1357 | |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1358 | /// \brief Mangles the a covariant thunk for the declaration D and emits that |
| 1359 | /// name to the given output stream. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1360 | void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD, |
| 1361 | int64_t nv_t, int64_t v_t, |
| 1362 | int64_t nv_r, int64_t v_r, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1363 | llvm::raw_ostream &os) { |
| 1364 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1365 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1366 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1367 | |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1368 | CXXNameMangler Mangler(Context, os); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1369 | Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r); |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1370 | os.flush(); |
| 1371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1373 | /// mangleGuardVariable - Returns the mangled name for a guard variable |
| 1374 | /// for the passed in VarDecl. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1375 | void mangleGuardVariable(MangleContext &Context, const VarDecl *D, |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 1376 | llvm::raw_ostream &os) { |
| 1377 | CXXNameMangler Mangler(Context, os); |
| 1378 | Mangler.mangleGuardVariable(D); |
| 1379 | |
| 1380 | os.flush(); |
| 1381 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1383 | void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D, |
| 1384 | CXXCtorType Type, llvm::raw_ostream &os) { |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1385 | CXXNameMangler Mangler(Context, os); |
| 1386 | Mangler.mangleCXXCtor(D, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1387 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1388 | os.flush(); |
| 1389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1390 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1391 | void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D, |
| 1392 | CXXDtorType Type, llvm::raw_ostream &os) { |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1393 | CXXNameMangler Mangler(Context, os); |
| 1394 | Mangler.mangleCXXDtor(D, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1396 | os.flush(); |
| 1397 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1398 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1399 | void mangleCXXVtable(MangleContext &Context, QualType Type, |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 1400 | llvm::raw_ostream &os) { |
| 1401 | CXXNameMangler Mangler(Context, os); |
| 1402 | Mangler.mangleCXXVtable(Type); |
| 1403 | |
| 1404 | os.flush(); |
| 1405 | } |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1406 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1407 | void mangleCXXRtti(MangleContext &Context, QualType Type, |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1408 | llvm::raw_ostream &os) { |
| 1409 | CXXNameMangler Mangler(Context, os); |
| 1410 | Mangler.mangleCXXRtti(Type); |
| 1411 | |
| 1412 | os.flush(); |
| 1413 | } |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 1414 | } |