Douglas Gregor | 3c3c454 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1 | //===--- Mangle.cpp - Mangle C++ Names --------------------------*- C++ -*-===// |
Douglas Gregor | 3556bc7 | 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 | fae4586 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclTemplate.h" |
Douglas Gregor | 3c3c454 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 23 | #include "clang/Basic/SourceManager.h" |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Compiler.h" |
| 25 | #include "llvm/Support/raw_ostream.h" |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 26 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
| 29 | namespace { |
| 30 | class VISIBILITY_HIDDEN CXXNameMangler { |
| 31 | ASTContext &Context; |
| 32 | llvm::raw_ostream &Out; |
| 33 | |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 34 | const CXXMethodDecl *Structor; |
| 35 | unsigned StructorType; |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 36 | CXXCtorType CtorType; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 37 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 38 | public: |
| 39 | CXXNameMangler(ASTContext &C, llvm::raw_ostream &os) |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 40 | : Context(C), Out(os), Structor(0), StructorType(0) { } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 41 | |
| 42 | bool mangle(const NamedDecl *D); |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 43 | void mangleCalloffset(int64_t nv, int64_t v); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 44 | void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v); |
| 45 | void mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 46 | int64_t nv_t, int64_t v_t, |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 47 | int64_t nv_r, int64_t v_r); |
Anders Carlsson | 53f73bc | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 48 | void mangleGuardVariable(const VarDecl *D); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 49 | |
Mike Stump | 7e8c993 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 50 | void mangleCXXVtable(QualType Type); |
Mike Stump | 00df7d3 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 51 | void mangleCXXRtti(QualType Type); |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 52 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type); |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 53 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type); |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 54 | |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 55 | private: |
| 56 | bool mangleFunctionDecl(const FunctionDecl *FD); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 57 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 58 | void mangleFunctionEncoding(const FunctionDecl *FD); |
| 59 | void mangleName(const NamedDecl *ND); |
| 60 | void mangleUnqualifiedName(const NamedDecl *ND); |
| 61 | void mangleSourceName(const IdentifierInfo *II); |
Anders Carlsson | fd8c56b | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 62 | void mangleLocalName(const NamedDecl *ND); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 63 | void mangleNestedName(const NamedDecl *ND); |
| 64 | void manglePrefix(const DeclContext *DC); |
| 65 | void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); |
| 66 | void mangleCVQualifiers(unsigned Quals); |
| 67 | void mangleType(QualType T); |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 68 | |
| 69 | // Declare manglers for every type class. |
| 70 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 71 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
| 72 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); |
| 73 | #include "clang/AST/TypeNodes.def" |
| 74 | |
| 75 | void mangleType(const TagType*); |
| 76 | void mangleBareFunctionType(const FunctionType *T, |
| 77 | bool MangleReturnType); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 78 | void mangleExpression(Expr *E); |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 79 | void mangleCXXCtorType(CXXCtorType T); |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 80 | void mangleCXXDtorType(CXXDtorType T); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 81 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 82 | void mangleTemplateArgumentList(const TemplateArgumentList &L); |
| 83 | void mangleTemplateArgument(const TemplateArgument &A); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 84 | }; |
| 85 | } |
| 86 | |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 87 | static bool isInCLinkageSpecification(const Decl *D) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 88 | for (const DeclContext *DC = D->getDeclContext(); |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 89 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 90 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 91 | return Linkage->getLanguage() == LinkageSpecDecl::lang_c; |
| 92 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 93 | |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 94 | return false; |
| 95 | } |
| 96 | |
| 97 | bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) { |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 98 | // Clang's "overloadable" attribute extension to C/C++ implies name mangling |
| 99 | // (always). |
Argiris Kirtzidis | fe5f973 | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 100 | if (!FD->hasAttr<OverloadableAttr>()) { |
Chris Lattner | 0c032a4 | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 101 | // C functions are not mangled, and "main" is never mangled. |
John McCall | cb6dd8a | 2009-08-15 02:09:25 +0000 | [diff] [blame] | 102 | if (!Context.getLangOptions().CPlusPlus || FD->isMain(Context)) |
Chris Lattner | 0c032a4 | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 103 | return false; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 104 | |
| 105 | // No mangling in an "implicit extern C" header. |
Chris Lattner | 0c032a4 | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 106 | if (FD->getLocation().isValid() && |
| 107 | Context.getSourceManager().isInExternCSystemHeader(FD->getLocation())) |
| 108 | return false; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 109 | |
Chris Lattner | 0c032a4 | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 110 | // No name mangling in a C linkage specification. |
| 111 | if (isInCLinkageSpecification(FD)) |
| 112 | return false; |
| 113 | } |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 114 | |
| 115 | // If we get here, mangle the decl name! |
| 116 | Out << "_Z"; |
| 117 | mangleFunctionEncoding(FD); |
| 118 | return true; |
| 119 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 120 | |
| 121 | bool CXXNameMangler::mangle(const NamedDecl *D) { |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 122 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 123 | // over all other naming in the .o file. |
Argiris Kirtzidis | fe5f973 | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 124 | if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { |
Chris Lattner | 8af0e26 | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 125 | // If we have an asm name, then we use it as the mangling. |
| 126 | Out << '\01'; // LLVM IR Marker for __asm("foo") |
| 127 | Out << ALA->getLabel(); |
| 128 | return true; |
| 129 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 130 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 131 | // <mangled-name> ::= _Z <encoding> |
| 132 | // ::= <data name> |
| 133 | // ::= <special-name> |
| 134 | |
| 135 | // FIXME: Actually use a visitor to decode these? |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 136 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 137 | return mangleFunctionDecl(FD); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 138 | |
Anders Carlsson | af6bb35 | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 139 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 140 | if (!Context.getLangOptions().CPlusPlus || |
Anders Carlsson | c3e84ae | 2009-04-11 01:19:45 +0000 | [diff] [blame] | 141 | isInCLinkageSpecification(D) || |
| 142 | D->getDeclContext()->isTranslationUnit()) |
Anders Carlsson | af6bb35 | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 143 | return false; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 144 | |
Anders Carlsson | af6bb35 | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 145 | Out << "_Z"; |
| 146 | mangleName(VD); |
| 147 | return true; |
| 148 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 149 | |
Anders Carlsson | 70cc0d2 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 150 | return false; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 153 | void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D, |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 154 | CXXCtorType Type) { |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 155 | assert(!Structor && "Structor already set!"); |
| 156 | Structor = D; |
| 157 | StructorType = Type; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 158 | |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 159 | mangle(D); |
| 160 | } |
| 161 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 162 | void CXXNameMangler::mangleCXXDtor(const CXXDestructorDecl *D, |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 163 | CXXDtorType Type) { |
| 164 | assert(!Structor && "Structor already set!"); |
| 165 | Structor = D; |
| 166 | StructorType = Type; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 167 | |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 168 | mangle(D); |
| 169 | } |
| 170 | |
Mike Stump | 7e8c993 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 171 | void CXXNameMangler::mangleCXXVtable(QualType T) { |
| 172 | // <special-name> ::= TV <type> # virtual table |
| 173 | Out << "_ZTV"; |
| 174 | mangleType(T); |
| 175 | } |
| 176 | |
Mike Stump | 00df7d3 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 177 | void CXXNameMangler::mangleCXXRtti(QualType T) { |
| 178 | // <special-name> ::= TI <type> # typeinfo structure |
| 179 | Out << "_ZTI"; |
| 180 | mangleType(T); |
| 181 | } |
| 182 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 183 | void CXXNameMangler::mangleGuardVariable(const VarDecl *D) { |
| 184 | // <special-name> ::= GV <object name> # Guard variable for one-time |
Mike Stump | 7e8c993 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 185 | // # initialization |
Anders Carlsson | 53f73bc | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 186 | |
| 187 | Out << "_ZGV"; |
| 188 | mangleName(D); |
| 189 | } |
| 190 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 191 | void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
| 192 | // <encoding> ::= <function name> <bare-function-type> |
| 193 | mangleName(FD); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 194 | |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 195 | // Whether the mangling of a function type includes the return type depends on |
| 196 | // the context and the nature of the function. The rules for deciding whether |
| 197 | // the return type is included are: |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 198 | // |
Douglas Gregor | 6967806 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 199 | // 1. Template functions (names or types) have return types encoded, with |
| 200 | // the exceptions listed below. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 201 | // 2. Function types not appearing as part of a function name mangling, |
Douglas Gregor | 6967806 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 202 | // e.g. parameters, pointer types, etc., have return type encoded, with the |
| 203 | // exceptions listed below. |
| 204 | // 3. Non-template function names do not have return types encoded. |
| 205 | // |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 206 | // The exceptions mentioned in (1) and (2) above, for which the return type is |
| 207 | // never included, are |
Douglas Gregor | 6967806 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 208 | // 1. Constructors. |
| 209 | // 2. Destructors. |
| 210 | // 3. Conversion operator functions, e.g. operator int. |
| 211 | bool MangleReturnType = false; |
| 212 | if (FD->getPrimaryTemplate() && |
| 213 | !(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || |
| 214 | isa<CXXConversionDecl>(FD))) |
| 215 | MangleReturnType = true; |
| 216 | mangleBareFunctionType(FD->getType()->getAsFunctionType(), MangleReturnType); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | static bool isStdNamespace(const DeclContext *DC) { |
| 220 | if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit()) |
| 221 | return false; |
| 222 | |
| 223 | const NamespaceDecl *NS = cast<NamespaceDecl>(DC); |
Douglas Gregor | 3c3c454 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 224 | return NS->getOriginalNamespace()->getIdentifier()->isStr("std"); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void CXXNameMangler::mangleName(const NamedDecl *ND) { |
| 228 | // <name> ::= <nested-name> |
| 229 | // ::= <unscoped-name> |
| 230 | // ::= <unscoped-template-name> <template-args> |
| 231 | // ::= <local-name> # See Scope Encoding below |
| 232 | // |
| 233 | // <unscoped-name> ::= <unqualified-name> |
| 234 | // ::= St <unqualified-name> # ::std:: |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 235 | if (ND->getDeclContext()->isTranslationUnit()) |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 236 | mangleUnqualifiedName(ND); |
| 237 | else if (isStdNamespace(ND->getDeclContext())) { |
| 238 | Out << "St"; |
| 239 | mangleUnqualifiedName(ND); |
Anders Carlsson | fd8c56b | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 240 | } else if (isa<FunctionDecl>(ND->getDeclContext())) |
| 241 | mangleLocalName(ND); |
| 242 | else |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 243 | mangleNestedName(ND); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 246 | void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) { |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 247 | // <call-offset> ::= h <nv-offset> _ |
| 248 | // ::= v <v-offset> _ |
| 249 | // <nv-offset> ::= <offset number> # non-virtual base override |
| 250 | // <v-offset> ::= <offset nubmer> _ <virtual offset number> |
| 251 | // # virtual base override, with vcall offset |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 252 | if (v == 0) { |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 253 | Out << "h"; |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 254 | if (nv < 0) { |
| 255 | Out << "n"; |
| 256 | nv = -nv; |
| 257 | } |
| 258 | Out << nv; |
| 259 | } else { |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 260 | Out << "v"; |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 261 | if (nv < 0) { |
| 262 | Out << "n"; |
| 263 | nv = -nv; |
| 264 | } |
| 265 | Out << nv; |
| 266 | Out << "_"; |
| 267 | if (v < 0) { |
| 268 | Out << "n"; |
| 269 | v = -v; |
| 270 | } |
| 271 | Out << v; |
| 272 | } |
| 273 | Out << "_"; |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 276 | void CXXNameMangler::mangleThunk(const FunctionDecl *FD, int64_t nv, |
| 277 | int64_t v) { |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 278 | // <special-name> ::= T <call-offset> <base encoding> |
| 279 | // # base is the nominal target function of thunk |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 280 | Out << "_ZT"; |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 281 | mangleCalloffset(nv, v); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 282 | mangleFunctionEncoding(FD); |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 285 | void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 286 | int64_t nv_t, int64_t v_t, |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 287 | int64_t nv_r, int64_t v_r) { |
| 288 | // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> |
| 289 | // # base is the nominal target function of thunk |
| 290 | // # first call-offset is 'this' adjustment |
| 291 | // # second call-offset is result adjustment |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 292 | Out << "_ZTc"; |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 293 | mangleCalloffset(nv_t, v_t); |
| 294 | mangleCalloffset(nv_r, v_r); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 295 | mangleFunctionEncoding(FD); |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 298 | void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) { |
| 299 | // <unqualified-name> ::= <operator-name> |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 300 | // ::= <ctor-dtor-name> |
| 301 | // ::= <source-name> |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 302 | DeclarationName Name = ND->getDeclName(); |
| 303 | switch (Name.getNameKind()) { |
| 304 | case DeclarationName::Identifier: |
| 305 | mangleSourceName(Name.getAsIdentifierInfo()); |
| 306 | break; |
| 307 | |
| 308 | case DeclarationName::ObjCZeroArgSelector: |
| 309 | case DeclarationName::ObjCOneArgSelector: |
| 310 | case DeclarationName::ObjCMultiArgSelector: |
| 311 | assert(false && "Can't mangle Objective-C selector names here!"); |
| 312 | break; |
| 313 | |
| 314 | case DeclarationName::CXXConstructorName: |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 315 | if (ND == Structor) |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 316 | // If the named decl is the C++ constructor we're mangling, use the type |
| 317 | // we were given. |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 318 | mangleCXXCtorType(static_cast<CXXCtorType>(StructorType)); |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 319 | else |
| 320 | // Otherwise, use the complete constructor name. This is relevant if a |
| 321 | // class with a constructor is declared within a constructor. |
| 322 | mangleCXXCtorType(Ctor_Complete); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 323 | break; |
| 324 | |
| 325 | case DeclarationName::CXXDestructorName: |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 326 | if (ND == Structor) |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 327 | // If the named decl is the C++ destructor we're mangling, use the type we |
| 328 | // were given. |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 329 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); |
| 330 | else |
| 331 | // Otherwise, use the complete destructor name. This is relevant if a |
| 332 | // class with a destructor is declared within a destructor. |
| 333 | mangleCXXDtorType(Dtor_Complete); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 334 | break; |
| 335 | |
| 336 | case DeclarationName::CXXConversionFunctionName: |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 337 | // <operator-name> ::= cv <type> # (cast) |
Douglas Gregor | 77cfb3c | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 338 | Out << "cv"; |
| 339 | mangleType(Context.getCanonicalType(Name.getCXXNameType())); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 340 | break; |
| 341 | |
| 342 | case DeclarationName::CXXOperatorName: |
| 343 | mangleOperatorName(Name.getCXXOverloadedOperator(), |
| 344 | cast<FunctionDecl>(ND)->getNumParams()); |
| 345 | break; |
| 346 | |
| 347 | case DeclarationName::CXXUsingDirective: |
| 348 | assert(false && "Can't mangle a using directive name!"); |
Douglas Gregor | 77cfb3c | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 349 | break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 350 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 351 | |
Douglas Gregor | 6967806 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 352 | if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 353 | if (const TemplateArgumentList *TemplateArgs |
Douglas Gregor | 6967806 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 354 | = Function->getTemplateSpecializationArgs()) |
| 355 | mangleTemplateArgumentList(*TemplateArgs); |
| 356 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |
| 360 | // <source-name> ::= <positive length number> <identifier> |
| 361 | // <number> ::= [n] <non-negative decimal integer> |
| 362 | // <identifier> ::= <unqualified source code identifier> |
| 363 | Out << II->getLength() << II->getName(); |
| 364 | } |
| 365 | |
| 366 | void CXXNameMangler::mangleNestedName(const NamedDecl *ND) { |
| 367 | // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E |
| 368 | // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
| 369 | // FIXME: no template support |
| 370 | Out << 'N'; |
| 371 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) |
| 372 | mangleCVQualifiers(Method->getTypeQualifiers()); |
| 373 | manglePrefix(ND->getDeclContext()); |
| 374 | mangleUnqualifiedName(ND); |
| 375 | Out << 'E'; |
| 376 | } |
| 377 | |
Anders Carlsson | fd8c56b | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 378 | void CXXNameMangler::mangleLocalName(const NamedDecl *ND) { |
| 379 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| 380 | // := Z <function encoding> E s [<discriminator>] |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 381 | // <discriminator> := _ <non-negative number> |
Anders Carlsson | fd8c56b | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 382 | Out << 'Z'; |
| 383 | mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext())); |
| 384 | Out << 'E'; |
| 385 | mangleSourceName(ND->getIdentifier()); |
| 386 | } |
| 387 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 388 | void CXXNameMangler::manglePrefix(const DeclContext *DC) { |
| 389 | // <prefix> ::= <prefix> <unqualified-name> |
| 390 | // ::= <template-prefix> <template-args> |
| 391 | // ::= <template-param> |
| 392 | // ::= # empty |
| 393 | // ::= <substitution> |
| 394 | // FIXME: We only handle mangling of namespaces and classes at the moment. |
Anders Carlsson | 8c4c12a | 2009-04-01 00:42:16 +0000 | [diff] [blame] | 395 | if (!DC->getParent()->isTranslationUnit()) |
| 396 | manglePrefix(DC->getParent()); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 397 | |
| 398 | if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(DC)) |
| 399 | mangleSourceName(Namespace->getIdentifier()); |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 400 | else if (const RecordDecl *Record = dyn_cast<RecordDecl>(DC)) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 401 | if (const ClassTemplateSpecializationDecl *D = |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 402 | dyn_cast<ClassTemplateSpecializationDecl>(Record)) { |
| 403 | mangleType(QualType(D->getTypeForDecl(), 0)); |
| 404 | } else |
| 405 | mangleSourceName(Record->getIdentifier()); |
| 406 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 409 | void |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 410 | CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) { |
| 411 | switch (OO) { |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 412 | // <operator-name> ::= nw # new |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 413 | case OO_New: Out << "nw"; break; |
| 414 | // ::= na # new[] |
| 415 | case OO_Array_New: Out << "na"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 416 | // ::= dl # delete |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 417 | case OO_Delete: Out << "dl"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 418 | // ::= da # delete[] |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 419 | case OO_Array_Delete: Out << "da"; break; |
| 420 | // ::= ps # + (unary) |
| 421 | // ::= pl # + |
| 422 | case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 423 | // ::= ng # - (unary) |
| 424 | // ::= mi # - |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 425 | case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 426 | // ::= ad # & (unary) |
| 427 | // ::= an # & |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 428 | case OO_Amp: Out << (Arity == 1? "ad" : "an"); break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 429 | // ::= de # * (unary) |
| 430 | // ::= ml # * |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 431 | case OO_Star: Out << (Arity == 1? "de" : "ml"); break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 432 | // ::= co # ~ |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 433 | case OO_Tilde: Out << "co"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 434 | // ::= dv # / |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 435 | case OO_Slash: Out << "dv"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 436 | // ::= rm # % |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 437 | case OO_Percent: Out << "rm"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 438 | // ::= or # | |
| 439 | case OO_Pipe: Out << "or"; break; |
| 440 | // ::= eo # ^ |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 441 | case OO_Caret: Out << "eo"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 442 | // ::= aS # = |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 443 | case OO_Equal: Out << "aS"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 444 | // ::= pL # += |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 445 | case OO_PlusEqual: Out << "pL"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 446 | // ::= mI # -= |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 447 | case OO_MinusEqual: Out << "mI"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 448 | // ::= mL # *= |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 449 | case OO_StarEqual: Out << "mL"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 450 | // ::= dV # /= |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 451 | case OO_SlashEqual: Out << "dV"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 452 | // ::= rM # %= |
| 453 | case OO_PercentEqual: Out << "rM"; break; |
| 454 | // ::= aN # &= |
| 455 | case OO_AmpEqual: Out << "aN"; break; |
| 456 | // ::= oR # |= |
| 457 | case OO_PipeEqual: Out << "oR"; break; |
| 458 | // ::= eO # ^= |
| 459 | case OO_CaretEqual: Out << "eO"; break; |
| 460 | // ::= ls # << |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 461 | case OO_LessLess: Out << "ls"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 462 | // ::= rs # >> |
| 463 | case OO_GreaterGreater: Out << "rs"; break; |
| 464 | // ::= lS # <<= |
| 465 | case OO_LessLessEqual: Out << "lS"; break; |
| 466 | // ::= rS # >>= |
| 467 | case OO_GreaterGreaterEqual: Out << "rS"; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 468 | // ::= eq # == |
| 469 | case OO_EqualEqual: Out << "eq"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 470 | // ::= ne # != |
| 471 | case OO_ExclaimEqual: Out << "ne"; break; |
| 472 | // ::= lt # < |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 473 | case OO_Less: Out << "lt"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 474 | // ::= gt # > |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 475 | case OO_Greater: Out << "gt"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 476 | // ::= le # <= |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 477 | case OO_LessEqual: Out << "le"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 478 | // ::= ge # >= |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 479 | case OO_GreaterEqual: Out << "ge"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 480 | // ::= nt # ! |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 481 | case OO_Exclaim: Out << "nt"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 482 | // ::= aa # && |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 483 | case OO_AmpAmp: Out << "aa"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 484 | // ::= oo # || |
| 485 | case OO_PipePipe: Out << "oo"; break; |
| 486 | // ::= pp # ++ |
| 487 | case OO_PlusPlus: Out << "pp"; break; |
| 488 | // ::= mm # -- |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 489 | case OO_MinusMinus: Out << "mm"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 490 | // ::= cm # , |
| 491 | case OO_Comma: Out << "cm"; break; |
| 492 | // ::= pm # ->* |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 493 | case OO_ArrowStar: Out << "pm"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 494 | // ::= pt # -> |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 495 | case OO_Arrow: Out << "pt"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 496 | // ::= cl # () |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 497 | case OO_Call: Out << "cl"; break; |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 498 | // ::= ix # [] |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 499 | case OO_Subscript: Out << "ix"; break; |
| 500 | // UNSUPPORTED: ::= qu # ? |
| 501 | |
Sebastian Redl | bd26196 | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 502 | case OO_None: |
| 503 | case OO_Conditional: |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 504 | case NUM_OVERLOADED_OPERATORS: |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 505 | assert(false && "Not an overloaded operator"); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void CXXNameMangler::mangleCVQualifiers(unsigned Quals) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 511 | // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 512 | if (Quals & QualType::Restrict) |
| 513 | Out << 'r'; |
| 514 | if (Quals & QualType::Volatile) |
| 515 | Out << 'V'; |
| 516 | if (Quals & QualType::Const) |
| 517 | Out << 'K'; |
| 518 | } |
| 519 | |
| 520 | void CXXNameMangler::mangleType(QualType T) { |
Anders Carlsson | fdaed4c | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 521 | // Only operate on the canonical type! |
| 522 | T = Context.getCanonicalType(T); |
| 523 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 524 | // <type> ::= <CV-qualifiers> <type> |
| 525 | mangleCVQualifiers(T.getCVRQualifiers()); |
| 526 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 527 | switch (T->getTypeClass()) { |
| 528 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 529 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
| 530 | case Type::CLASS: \ |
| 531 | llvm::llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
| 532 | return; |
| 533 | #define TYPE(CLASS, PARENT) \ |
| 534 | case Type::CLASS: \ |
| 535 | return mangleType(static_cast<CLASS##Type*>(T.getTypePtr())); |
| 536 | #include "clang/AST/TypeNodes.def" |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 537 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void CXXNameMangler::mangleType(const BuiltinType *T) { |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 541 | // <type> ::= <builtin-type> |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 542 | // <builtin-type> ::= v # void |
| 543 | // ::= w # wchar_t |
| 544 | // ::= b # bool |
| 545 | // ::= c # char |
| 546 | // ::= a # signed char |
| 547 | // ::= h # unsigned char |
| 548 | // ::= s # short |
| 549 | // ::= t # unsigned short |
| 550 | // ::= i # int |
| 551 | // ::= j # unsigned int |
| 552 | // ::= l # long |
| 553 | // ::= m # unsigned long |
| 554 | // ::= x # long long, __int64 |
| 555 | // ::= y # unsigned long long, __int64 |
| 556 | // ::= n # __int128 |
| 557 | // UNSUPPORTED: ::= o # unsigned __int128 |
| 558 | // ::= f # float |
| 559 | // ::= d # double |
| 560 | // ::= e # long double, __float80 |
| 561 | // UNSUPPORTED: ::= g # __float128 |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 562 | // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits) |
| 563 | // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits) |
| 564 | // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits) |
| 565 | // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits) |
Alisdair Meredith | 2bcacb6 | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 566 | // ::= Di # char32_t |
| 567 | // ::= Ds # char16_t |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 568 | // ::= u <source-name> # vendor extended type |
Sebastian Redl | 5d0ead7 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 569 | // From our point of view, std::nullptr_t is a builtin, but as far as mangling |
| 570 | // is concerned, it's a type called std::nullptr_t. |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 571 | switch (T->getKind()) { |
| 572 | case BuiltinType::Void: Out << 'v'; break; |
| 573 | case BuiltinType::Bool: Out << 'b'; break; |
| 574 | case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break; |
| 575 | case BuiltinType::UChar: Out << 'h'; break; |
| 576 | case BuiltinType::UShort: Out << 't'; break; |
| 577 | case BuiltinType::UInt: Out << 'j'; break; |
| 578 | case BuiltinType::ULong: Out << 'm'; break; |
| 579 | case BuiltinType::ULongLong: Out << 'y'; break; |
Chris Lattner | 6cc7e41 | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 580 | case BuiltinType::UInt128: Out << 'o'; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 581 | case BuiltinType::SChar: Out << 'a'; break; |
| 582 | case BuiltinType::WChar: Out << 'w'; break; |
Alisdair Meredith | 2bcacb6 | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 583 | case BuiltinType::Char16: Out << "Ds"; break; |
| 584 | case BuiltinType::Char32: Out << "Di"; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 585 | case BuiltinType::Short: Out << 's'; break; |
| 586 | case BuiltinType::Int: Out << 'i'; break; |
| 587 | case BuiltinType::Long: Out << 'l'; break; |
| 588 | case BuiltinType::LongLong: Out << 'x'; break; |
Chris Lattner | 6cc7e41 | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 589 | case BuiltinType::Int128: Out << 'n'; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 590 | case BuiltinType::Float: Out << 'f'; break; |
| 591 | case BuiltinType::Double: Out << 'd'; break; |
| 592 | case BuiltinType::LongDouble: Out << 'e'; break; |
Sebastian Redl | 5d0ead7 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 593 | case BuiltinType::NullPtr: Out << "St9nullptr_t"; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 594 | |
| 595 | case BuiltinType::Overload: |
| 596 | case BuiltinType::Dependent: |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 597 | assert(false && |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 598 | "Overloaded and dependent types shouldn't get to name mangling"); |
| 599 | break; |
Anders Carlsson | 4a8498c | 2009-06-26 18:41:36 +0000 | [diff] [blame] | 600 | case BuiltinType::UndeducedAuto: |
| 601 | assert(0 && "Should not see undeduced auto here"); |
| 602 | break; |
Steve Naroff | 0b60cf8 | 2009-07-22 17:14:51 +0000 | [diff] [blame] | 603 | case BuiltinType::ObjCId: Out << "11objc_object"; break; |
| 604 | case BuiltinType::ObjCClass: Out << "10objc_class"; break; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 608 | // <type> ::= <function-type> |
| 609 | // <function-type> ::= F [Y] <bare-function-type> E |
| 610 | void CXXNameMangler::mangleType(const FunctionProtoType *T) { |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 611 | Out << 'F'; |
Mike Stump | ba2cb0e | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 612 | // FIXME: We don't have enough information in the AST to produce the 'Y' |
| 613 | // encoding for extern "C" function types. |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 614 | mangleBareFunctionType(T, /*MangleReturnType=*/true); |
| 615 | Out << 'E'; |
| 616 | } |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 617 | void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { |
| 618 | llvm::llvm_unreachable("Can't mangle K&R function prototypes"); |
| 619 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 620 | void CXXNameMangler::mangleBareFunctionType(const FunctionType *T, |
| 621 | bool MangleReturnType) { |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 622 | // We should never be mangling something without a prototype. |
| 623 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 624 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 625 | // <bare-function-type> ::= <signature type>+ |
| 626 | if (MangleReturnType) |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 627 | mangleType(Proto->getResultType()); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 628 | |
Anders Carlsson | 51e6552 | 2009-04-01 00:15:23 +0000 | [diff] [blame] | 629 | if (Proto->getNumArgs() == 0) { |
| 630 | Out << 'v'; |
| 631 | return; |
| 632 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 633 | |
Douglas Gregor | 4fa5890 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 634 | for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 635 | ArgEnd = Proto->arg_type_end(); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 636 | Arg != ArgEnd; ++Arg) |
| 637 | mangleType(*Arg); |
Douglas Gregor | 77cfb3c | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 638 | |
| 639 | // <builtin-type> ::= z # ellipsis |
| 640 | if (Proto->isVariadic()) |
| 641 | Out << 'z'; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 642 | } |
| 643 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 644 | // <type> ::= <class-enum-type> |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 645 | // <class-enum-type> ::= <name> |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 646 | void CXXNameMangler::mangleType(const EnumType *T) { |
| 647 | mangleType(static_cast<const TagType*>(T)); |
| 648 | } |
| 649 | void CXXNameMangler::mangleType(const RecordType *T) { |
| 650 | mangleType(static_cast<const TagType*>(T)); |
| 651 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 652 | void CXXNameMangler::mangleType(const TagType *T) { |
Anders Carlsson | fdaed4c | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 653 | if (!T->getDecl()->getIdentifier()) |
| 654 | mangleName(T->getDecl()->getTypedefForAnonDecl()); |
| 655 | else |
| 656 | mangleName(T->getDecl()); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 657 | |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 658 | // If this is a class template specialization, mangle the template arguments. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 659 | if (ClassTemplateSpecializationDecl *Spec |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 660 | = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl())) |
| 661 | mangleTemplateArgumentList(Spec->getTemplateArgs()); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 662 | } |
| 663 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 664 | // <type> ::= <array-type> |
| 665 | // <array-type> ::= A <positive dimension number> _ <element type> |
| 666 | // ::= A [<dimension expression>] _ <element type> |
| 667 | void CXXNameMangler::mangleType(const ConstantArrayType *T) { |
| 668 | Out << 'A' << T->getSize() << '_'; |
| 669 | mangleType(T->getElementType()); |
| 670 | } |
| 671 | void CXXNameMangler::mangleType(const VariableArrayType *T) { |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 672 | Out << 'A'; |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 673 | mangleExpression(T->getSizeExpr()); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 674 | Out << '_'; |
| 675 | mangleType(T->getElementType()); |
| 676 | } |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 677 | void CXXNameMangler::mangleType(const DependentSizedArrayType *T) { |
| 678 | Out << 'A'; |
| 679 | mangleExpression(T->getSizeExpr()); |
| 680 | Out << '_'; |
| 681 | mangleType(T->getElementType()); |
| 682 | } |
| 683 | void CXXNameMangler::mangleType(const IncompleteArrayType *T) { |
| 684 | Out << 'A' << '_'; |
| 685 | mangleType(T->getElementType()); |
| 686 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 687 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 688 | // <type> ::= <pointer-to-member-type> |
| 689 | // <pointer-to-member-type> ::= M <class type> <member type> |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 690 | void CXXNameMangler::mangleType(const MemberPointerType *T) { |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 691 | Out << 'M'; |
| 692 | mangleType(QualType(T->getClass(), 0)); |
Anders Carlsson | 0b17ef4 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 693 | QualType PointeeType = T->getPointeeType(); |
| 694 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) { |
| 695 | mangleCVQualifiers(FPT->getTypeQuals()); |
| 696 | mangleType(FPT); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 697 | } else |
Anders Carlsson | 0b17ef4 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 698 | mangleType(PointeeType); |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 699 | } |
| 700 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 701 | // <type> ::= <template-param> |
| 702 | // <template-param> ::= T_ # first template parameter |
| 703 | // ::= T <parameter-2 non-negative number> _ |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 704 | void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 705 | if (T->getIndex() == 0) |
| 706 | Out << "T_"; |
| 707 | else |
| 708 | Out << 'T' << (T->getIndex() - 1) << '_'; |
| 709 | } |
| 710 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 711 | // FIXME: <type> ::= <template-template-param> <template-args> |
| 712 | // FIXME: <type> ::= <substitution> # See Compression below |
| 713 | |
| 714 | // <type> ::= P <type> # pointer-to |
| 715 | void CXXNameMangler::mangleType(const PointerType *T) { |
| 716 | Out << 'P'; |
| 717 | mangleType(T->getPointeeType()); |
| 718 | } |
| 719 | void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) { |
| 720 | Out << 'P'; |
| 721 | mangleType(T->getPointeeType()); |
| 722 | } |
| 723 | |
| 724 | // <type> ::= R <type> # reference-to |
| 725 | void CXXNameMangler::mangleType(const LValueReferenceType *T) { |
| 726 | Out << 'R'; |
| 727 | mangleType(T->getPointeeType()); |
| 728 | } |
| 729 | |
| 730 | // <type> ::= O <type> # rvalue reference-to (C++0x) |
| 731 | void CXXNameMangler::mangleType(const RValueReferenceType *T) { |
| 732 | Out << 'O'; |
| 733 | mangleType(T->getPointeeType()); |
| 734 | } |
| 735 | |
| 736 | // <type> ::= C <type> # complex pair (C 2000) |
| 737 | void CXXNameMangler::mangleType(const ComplexType *T) { |
| 738 | Out << 'C'; |
| 739 | mangleType(T->getElementType()); |
| 740 | } |
| 741 | |
| 742 | // GNU extension: vector types |
| 743 | void CXXNameMangler::mangleType(const VectorType *T) { |
| 744 | Out << "U8__vector"; |
| 745 | mangleType(T->getElementType()); |
| 746 | } |
| 747 | void CXXNameMangler::mangleType(const ExtVectorType *T) { |
| 748 | mangleType(static_cast<const VectorType*>(T)); |
| 749 | } |
| 750 | void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) { |
| 751 | Out << "U8__vector"; |
| 752 | mangleType(T->getElementType()); |
| 753 | } |
| 754 | |
Anders Carlsson | fae4586 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 755 | void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { |
| 756 | mangleSourceName(T->getDecl()->getIdentifier()); |
| 757 | } |
| 758 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 759 | void CXXNameMangler::mangleType(const BlockPointerType *T) { |
| 760 | assert(false && "can't mangle block pointer types yet"); |
| 761 | } |
| 762 | |
| 763 | void CXXNameMangler::mangleType(const FixedWidthIntType *T) { |
| 764 | assert(false && "can't mangle arbitary-precision integer type yet"); |
| 765 | } |
| 766 | |
| 767 | void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
| 768 | // TSTs are never canonical unless they're dependent. |
| 769 | assert(false && "can't mangle dependent template specializations yet"); |
| 770 | } |
| 771 | |
| 772 | void CXXNameMangler::mangleType(const TypenameType *T) { |
| 773 | assert(false && "can't mangle dependent typenames yet"); |
| 774 | } |
| 775 | |
| 776 | // FIXME: For now, just drop all extension qualifiers on the floor. |
| 777 | void CXXNameMangler::mangleType(const ExtQualType *T) { |
| 778 | mangleType(QualType(T->getBaseType(), 0)); |
| 779 | } |
| 780 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 781 | void CXXNameMangler::mangleExpression(Expr *E) { |
| 782 | assert(false && "Cannot mangle expressions yet"); |
| 783 | } |
| 784 | |
John McCall | b16b547 | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 785 | // FIXME: <type> ::= G <type> # imaginary (C 2000) |
| 786 | // FIXME: <type> ::= U <source-name> <type> # vendor extended type qualifier |
| 787 | |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 788 | void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) { |
| 789 | // <ctor-dtor-name> ::= C1 # complete object constructor |
| 790 | // ::= C2 # base object constructor |
| 791 | // ::= C3 # complete object allocating constructor |
| 792 | // |
| 793 | switch (T) { |
| 794 | case Ctor_Complete: |
| 795 | Out << "C1"; |
| 796 | break; |
| 797 | case Ctor_Base: |
| 798 | Out << "C2"; |
| 799 | break; |
| 800 | case Ctor_CompleteAllocating: |
| 801 | Out << "C3"; |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 806 | void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) { |
| 807 | // <ctor-dtor-name> ::= D0 # deleting destructor |
| 808 | // ::= D1 # complete object destructor |
| 809 | // ::= D2 # base object destructor |
| 810 | // |
| 811 | switch (T) { |
| 812 | case Dtor_Deleting: |
| 813 | Out << "D0"; |
| 814 | break; |
| 815 | case Dtor_Complete: |
| 816 | Out << "D1"; |
| 817 | break; |
| 818 | case Dtor_Base: |
| 819 | Out << "D2"; |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 824 | void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) { |
| 825 | // <template-args> ::= I <template-arg>+ E |
| 826 | Out << "I"; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 827 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 828 | for (unsigned i = 0, e = L.size(); i != e; ++i) { |
| 829 | const TemplateArgument &A = L[i]; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 830 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 831 | mangleTemplateArgument(A); |
| 832 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 833 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 834 | Out << "E"; |
| 835 | } |
| 836 | |
| 837 | void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) { |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 838 | // <template-arg> ::= <type> # type or template |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 839 | // ::= X <expression> E # expression |
| 840 | // ::= <expr-primary> # simple expressions |
| 841 | // ::= I <template-arg>* E # argument pack |
| 842 | // ::= sp <expression> # pack expansion of (C++0x) |
| 843 | switch (A.getKind()) { |
| 844 | default: |
| 845 | assert(0 && "Unknown template argument kind!"); |
| 846 | case TemplateArgument::Type: |
| 847 | mangleType(A.getAsType()); |
| 848 | break; |
| 849 | case TemplateArgument::Integral: |
| 850 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 851 | |
| 852 | Out << 'L'; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 853 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 854 | mangleType(A.getIntegralType()); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 855 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 856 | const llvm::APSInt *Integral = A.getAsIntegral(); |
| 857 | if (A.getIntegralType()->isBooleanType()) { |
| 858 | // Boolean values are encoded as 0/1. |
| 859 | Out << (Integral->getBoolValue() ? '1' : '0'); |
| 860 | } else { |
| 861 | if (Integral->isNegative()) |
| 862 | Out << 'n'; |
| 863 | Integral->abs().print(Out, false); |
| 864 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 865 | |
Anders Carlsson | b1008e4 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 866 | Out << 'E'; |
| 867 | break; |
| 868 | } |
| 869 | } |
| 870 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 871 | namespace clang { |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 872 | /// \brief Mangles the name of the declaration D and emits that name to the |
| 873 | /// given output stream. |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 874 | /// |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 875 | /// If the declaration D requires a mangled name, this routine will emit that |
| 876 | /// mangled name to \p os and return true. Otherwise, \p os will be unchanged |
| 877 | /// and this routine will return false. In this case, the caller should just |
| 878 | /// emit the identifier of the declaration (\c D->getIdentifier()) as its |
| 879 | /// name. |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 880 | bool mangleName(const NamedDecl *D, ASTContext &Context, |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 881 | llvm::raw_ostream &os) { |
Anders Carlsson | 7bb1988 | 2009-05-03 16:51:04 +0000 | [diff] [blame] | 882 | assert(!isa<CXXConstructorDecl>(D) && |
| 883 | "Use mangleCXXCtor for constructor decls!"); |
| 884 | assert(!isa<CXXDestructorDecl>(D) && |
| 885 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 886 | |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 887 | CXXNameMangler Mangler(Context, os); |
Douglas Gregor | 3c3c454 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 888 | if (!Mangler.mangle(D)) |
| 889 | return false; |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 890 | |
Douglas Gregor | 3c3c454 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 891 | os.flush(); |
| 892 | return true; |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 893 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 894 | |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 895 | /// \brief Mangles the a thunk with the offset n for the declaration D and |
| 896 | /// emits that name to the given output stream. |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 897 | void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v, |
Mike Stump | eeba4ad | 2009-09-02 00:28:47 +0000 | [diff] [blame] | 898 | ASTContext &Context, llvm::raw_ostream &os) { |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 899 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 900 | assert(!isa<CXXConstructorDecl>(FD) && |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 901 | "Use mangleCXXCtor for constructor decls!"); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 902 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 903 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 904 | |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 905 | CXXNameMangler Mangler(Context, os); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 906 | Mangler.mangleThunk(FD, nv, v); |
Mike Stump | b29542f | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 907 | os.flush(); |
| 908 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 909 | |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 910 | /// \brief Mangles the a covariant thunk for the declaration D and emits that |
| 911 | /// name to the given output stream. |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 912 | void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t, |
Mike Stump | 5825641 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 913 | int64_t nv_r, int64_t v_r, ASTContext &Context, |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 914 | llvm::raw_ostream &os) { |
| 915 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 916 | assert(!isa<CXXConstructorDecl>(FD) && |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 917 | "Use mangleCXXCtor for constructor decls!"); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 918 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 919 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 920 | |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 921 | CXXNameMangler Mangler(Context, os); |
Mike Stump | bb3126c | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 922 | Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r); |
Mike Stump | 28db39b | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 923 | os.flush(); |
| 924 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 925 | |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 926 | /// mangleGuardVariable - Returns the mangled name for a guard variable |
| 927 | /// for the passed in VarDecl. |
Anders Carlsson | 53f73bc | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 928 | void mangleGuardVariable(const VarDecl *D, ASTContext &Context, |
| 929 | llvm::raw_ostream &os) { |
| 930 | CXXNameMangler Mangler(Context, os); |
| 931 | Mangler.mangleGuardVariable(D); |
| 932 | |
| 933 | os.flush(); |
| 934 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 935 | |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 936 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, |
| 937 | ASTContext &Context, llvm::raw_ostream &os) { |
| 938 | CXXNameMangler Mangler(Context, os); |
| 939 | Mangler.mangleCXXCtor(D, Type); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 940 | |
Anders Carlsson | 6b6adf2 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 941 | os.flush(); |
| 942 | } |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 943 | |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 944 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, |
| 945 | ASTContext &Context, llvm::raw_ostream &os) { |
| 946 | CXXNameMangler Mangler(Context, os); |
| 947 | Mangler.mangleCXXDtor(D, Type); |
Mike Stump | 25cf760 | 2009-09-09 15:08:12 +0000 | [diff] [blame^] | 948 | |
Anders Carlsson | 4811c30 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 949 | os.flush(); |
| 950 | } |
Douglas Gregor | 3556bc7 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 951 | |
Mike Stump | 7e8c993 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 952 | void mangleCXXVtable(QualType Type, ASTContext &Context, |
| 953 | llvm::raw_ostream &os) { |
| 954 | CXXNameMangler Mangler(Context, os); |
| 955 | Mangler.mangleCXXVtable(Type); |
| 956 | |
| 957 | os.flush(); |
| 958 | } |
Mike Stump | 00df7d3 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 959 | |
| 960 | void mangleCXXRtti(QualType Type, ASTContext &Context, |
| 961 | llvm::raw_ostream &os) { |
| 962 | CXXNameMangler Mangler(Context, os); |
| 963 | Mangler.mangleCXXRtti(Type); |
| 964 | |
| 965 | os.flush(); |
| 966 | } |
Mike Stump | 7e8c993 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 967 | } |