Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1 | //===--- ItaniumMangle.cpp - Itanium C++ Name Mangling ----------*- 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 | //===----------------------------------------------------------------------===// |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 17 | #include "clang/AST/Mangle.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 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" |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 24 | #include "clang/Basic/ABI.h" |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 25 | #include "clang/Basic/SourceManager.h" |
Rafael Espindola | 4e274e9 | 2011-02-15 22:23:51 +0000 | [diff] [blame] | 26 | #include "clang/Basic/TargetInfo.h" |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 29 | #include "llvm/Support/ErrorHandling.h" |
Anders Carlsson | f98574b | 2010-02-05 07:31:37 +0000 | [diff] [blame] | 30 | |
| 31 | #define MANGLE_CHECKER 0 |
| 32 | |
| 33 | #if MANGLE_CHECKER |
| 34 | #include <cxxabi.h> |
| 35 | #endif |
| 36 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 37 | using namespace clang; |
Charles Davis | 685b1d9 | 2010-05-26 18:25:27 +0000 | [diff] [blame] | 38 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 39 | namespace { |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 40 | |
John McCall | 82b7d7b | 2010-10-18 21:28:44 +0000 | [diff] [blame] | 41 | static const CXXRecordDecl *GetLocalClassDecl(const NamedDecl *ND) { |
| 42 | const DeclContext *DC = dyn_cast<DeclContext>(ND); |
| 43 | if (!DC) |
| 44 | DC = ND->getDeclContext(); |
| 45 | while (!DC->isNamespace() && !DC->isTranslationUnit()) { |
| 46 | if (isa<FunctionDecl>(DC->getParent())) |
| 47 | return dyn_cast<CXXRecordDecl>(DC); |
| 48 | DC = DC->getParent(); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 49 | } |
| 50 | return 0; |
| 51 | } |
| 52 | |
Anders Carlsson | 7e12003 | 2009-11-24 05:36:32 +0000 | [diff] [blame] | 53 | static const CXXMethodDecl *getStructor(const CXXMethodDecl *MD) { |
| 54 | assert((isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) && |
| 55 | "Passed in decl is not a ctor or dtor!"); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 56 | |
Anders Carlsson | 7e12003 | 2009-11-24 05:36:32 +0000 | [diff] [blame] | 57 | if (const TemplateDecl *TD = MD->getPrimaryTemplate()) { |
| 58 | MD = cast<CXXMethodDecl>(TD->getTemplatedDecl()); |
| 59 | |
| 60 | assert((isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) && |
| 61 | "Templated decl is not a ctor or dtor!"); |
| 62 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 63 | |
Anders Carlsson | 7e12003 | 2009-11-24 05:36:32 +0000 | [diff] [blame] | 64 | return MD; |
| 65 | } |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 66 | |
| 67 | static const unsigned UnknownArity = ~0U; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 68 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 69 | class ItaniumMangleContext : public MangleContext { |
| 70 | llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds; |
| 71 | unsigned Discriminator; |
| 72 | llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier; |
| 73 | |
| 74 | public: |
| 75 | explicit ItaniumMangleContext(ASTContext &Context, |
| 76 | Diagnostic &Diags) |
| 77 | : MangleContext(Context, Diags) { } |
| 78 | |
| 79 | uint64_t getAnonymousStructId(const TagDecl *TD) { |
| 80 | std::pair<llvm::DenseMap<const TagDecl *, |
| 81 | uint64_t>::iterator, bool> Result = |
| 82 | AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size())); |
| 83 | return Result.first->second; |
| 84 | } |
| 85 | |
| 86 | void startNewFunction() { |
| 87 | MangleContext::startNewFunction(); |
| 88 | mangleInitDiscriminator(); |
| 89 | } |
| 90 | |
| 91 | /// @name Mangler Entry Points |
| 92 | /// @{ |
| 93 | |
| 94 | bool shouldMangleDeclName(const NamedDecl *D); |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 95 | void mangleName(const NamedDecl *D, llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 96 | void mangleThunk(const CXXMethodDecl *MD, |
| 97 | const ThunkInfo &Thunk, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 98 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 99 | void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, |
| 100 | const ThisAdjustment &ThisAdjustment, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 101 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 102 | void mangleReferenceTemporary(const VarDecl *D, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 103 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 104 | void mangleCXXVTable(const CXXRecordDecl *RD, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 105 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 106 | void mangleCXXVTT(const CXXRecordDecl *RD, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 107 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 108 | void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, |
| 109 | const CXXRecordDecl *Type, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 110 | llvm::raw_ostream &); |
| 111 | void mangleCXXRTTI(QualType T, llvm::raw_ostream &); |
| 112 | void mangleCXXRTTIName(QualType T, llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 113 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 114 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 115 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 116 | llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 117 | |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 118 | void mangleItaniumGuardVariable(const VarDecl *D, llvm::raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 119 | |
| 120 | void mangleInitDiscriminator() { |
| 121 | Discriminator = 0; |
| 122 | } |
| 123 | |
| 124 | bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { |
| 125 | unsigned &discriminator = Uniquifier[ND]; |
| 126 | if (!discriminator) |
| 127 | discriminator = ++Discriminator; |
| 128 | if (discriminator == 1) |
| 129 | return false; |
| 130 | disc = discriminator-2; |
| 131 | return true; |
| 132 | } |
| 133 | /// @} |
| 134 | }; |
| 135 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 136 | /// CXXNameMangler - Manage the mangling of a single name. |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 137 | class CXXNameMangler { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 138 | ItaniumMangleContext &Context; |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 139 | llvm::raw_ostream &Out; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 140 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 141 | const CXXMethodDecl *Structor; |
| 142 | unsigned StructorType; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 143 | |
Anders Carlsson | 9d85b72 | 2010-06-02 04:29:50 +0000 | [diff] [blame] | 144 | /// SeqID - The next subsitution sequence number. |
| 145 | unsigned SeqID; |
| 146 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 147 | llvm::DenseMap<uintptr_t, unsigned> Substitutions; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 148 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 149 | ASTContext &getASTContext() const { return Context.getASTContext(); } |
| 150 | |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 151 | public: |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 152 | CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_) |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 153 | : Context(C), Out(Out_), Structor(0), StructorType(0), SeqID(0) { } |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 154 | CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_, |
Daniel Dunbar | 77939c9 | 2009-11-21 09:06:31 +0000 | [diff] [blame] | 155 | const CXXConstructorDecl *D, CXXCtorType Type) |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 156 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
Anders Carlsson | 9d85b72 | 2010-06-02 04:29:50 +0000 | [diff] [blame] | 157 | SeqID(0) { } |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 158 | CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_, |
Daniel Dunbar | 77939c9 | 2009-11-21 09:06:31 +0000 | [diff] [blame] | 159 | const CXXDestructorDecl *D, CXXDtorType Type) |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 160 | : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
Anders Carlsson | 9d85b72 | 2010-06-02 04:29:50 +0000 | [diff] [blame] | 161 | SeqID(0) { } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 162 | |
Anders Carlsson | f98574b | 2010-02-05 07:31:37 +0000 | [diff] [blame] | 163 | #if MANGLE_CHECKER |
| 164 | ~CXXNameMangler() { |
| 165 | if (Out.str()[0] == '\01') |
| 166 | return; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 167 | |
Anders Carlsson | f98574b | 2010-02-05 07:31:37 +0000 | [diff] [blame] | 168 | int status = 0; |
| 169 | char *result = abi::__cxa_demangle(Out.str().str().c_str(), 0, 0, &status); |
| 170 | assert(status == 0 && "Could not demangle mangled name!"); |
| 171 | free(result); |
| 172 | } |
| 173 | #endif |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 174 | llvm::raw_ostream &getStream() { return Out; } |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 175 | |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 176 | void mangle(const NamedDecl *D, llvm::StringRef Prefix = "_Z"); |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 177 | void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 178 | void mangleNumber(const llvm::APSInt &I); |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 179 | void mangleNumber(int64_t Number); |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 180 | void mangleFloat(const llvm::APFloat &F); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 181 | void mangleFunctionEncoding(const FunctionDecl *FD); |
| 182 | void mangleName(const NamedDecl *ND); |
| 183 | void mangleType(QualType T); |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 184 | void mangleNameOrStandardSubstitution(const NamedDecl *ND); |
| 185 | |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 186 | private: |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 187 | bool mangleSubstitution(const NamedDecl *ND); |
| 188 | bool mangleSubstitution(QualType T); |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 189 | bool mangleSubstitution(TemplateName Template); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 190 | bool mangleSubstitution(uintptr_t Ptr); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 191 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 192 | bool mangleStandardSubstitution(const NamedDecl *ND); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 193 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 194 | void addSubstitution(const NamedDecl *ND) { |
| 195 | ND = cast<NamedDecl>(ND->getCanonicalDecl()); |
Anders Carlsson | 433d137 | 2009-11-07 04:26:04 +0000 | [diff] [blame] | 196 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 197 | addSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 198 | } |
| 199 | void addSubstitution(QualType T); |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 200 | void addSubstitution(TemplateName Template); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 201 | void addSubstitution(uintptr_t Ptr); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 202 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 203 | void mangleUnresolvedScope(NestedNameSpecifier *Qualifier); |
| 204 | void mangleUnresolvedName(NestedNameSpecifier *Qualifier, |
| 205 | DeclarationName Name, |
| 206 | unsigned KnownArity = UnknownArity); |
| 207 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 208 | void mangleName(const TemplateDecl *TD, |
| 209 | const TemplateArgument *TemplateArgs, |
| 210 | unsigned NumTemplateArgs); |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 211 | void mangleUnqualifiedName(const NamedDecl *ND) { |
| 212 | mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity); |
| 213 | } |
| 214 | void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name, |
| 215 | unsigned KnownArity); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 216 | void mangleUnscopedName(const NamedDecl *ND); |
| 217 | void mangleUnscopedTemplateName(const TemplateDecl *ND); |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 218 | void mangleUnscopedTemplateName(TemplateName); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 219 | void mangleSourceName(const IdentifierInfo *II); |
| 220 | void mangleLocalName(const NamedDecl *ND); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 221 | void mangleNestedName(const NamedDecl *ND, const DeclContext *DC, |
| 222 | bool NoFunction=false); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 223 | void mangleNestedName(const TemplateDecl *TD, |
| 224 | const TemplateArgument *TemplateArgs, |
| 225 | unsigned NumTemplateArgs); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 226 | void manglePrefix(const DeclContext *DC, bool NoFunction=false); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 227 | void mangleTemplatePrefix(const TemplateDecl *ND); |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 228 | void mangleTemplatePrefix(TemplateName Template); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 229 | void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); |
| 230 | void mangleQualifiers(Qualifiers Quals); |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 231 | void mangleRefQualifier(RefQualifierKind RefQualifier); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 232 | |
Anders Carlsson | 7b06f6c | 2009-12-10 03:14:39 +0000 | [diff] [blame] | 233 | void mangleObjCMethodName(const ObjCMethodDecl *MD); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 234 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 235 | // Declare manglers for every type class. |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 236 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 237 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
| 238 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); |
| 239 | #include "clang/AST/TypeNodes.def" |
| 240 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 241 | void mangleType(const TagType*); |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 242 | void mangleType(TemplateName); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 243 | void mangleBareFunctionType(const FunctionType *T, |
| 244 | bool MangleReturnType); |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 245 | void mangleNeonVectorType(const VectorType *T); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 246 | |
| 247 | void mangleIntegerLiteral(QualType T, const llvm::APSInt &Value); |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 248 | void mangleMemberExpr(const Expr *Base, bool IsArrow, |
| 249 | NestedNameSpecifier *Qualifier, |
| 250 | DeclarationName Name, |
| 251 | unsigned KnownArity); |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 252 | void mangleExpression(const Expr *E, unsigned Arity = UnknownArity); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 253 | void mangleCXXCtorType(CXXCtorType T); |
| 254 | void mangleCXXDtorType(CXXDtorType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 255 | |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 256 | void mangleTemplateArgs(const ExplicitTemplateArgumentList &TemplateArgs); |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 257 | void mangleTemplateArgs(TemplateName Template, |
| 258 | const TemplateArgument *TemplateArgs, |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 259 | unsigned NumTemplateArgs); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 260 | void mangleTemplateArgs(const TemplateParameterList &PL, |
| 261 | const TemplateArgument *TemplateArgs, |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 262 | unsigned NumTemplateArgs); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 263 | void mangleTemplateArgs(const TemplateParameterList &PL, |
| 264 | const TemplateArgumentList &AL); |
| 265 | void mangleTemplateArg(const NamedDecl *P, const TemplateArgument &A); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 266 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 267 | void mangleTemplateParameter(unsigned Index); |
| 268 | }; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 269 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 272 | static bool isInCLinkageSpecification(const Decl *D) { |
Douglas Gregor | 457e281 | 2009-10-28 16:31:34 +0000 | [diff] [blame] | 273 | D = D->getCanonicalDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 274 | for (const DeclContext *DC = D->getDeclContext(); |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 275 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 277 | return Linkage->getLanguage() == LinkageSpecDecl::lang_c; |
| 278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 279 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 280 | return false; |
| 281 | } |
| 282 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 283 | bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) { |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 284 | // In C, functions with no attributes never need to be mangled. Fastpath them. |
| 285 | if (!getASTContext().getLangOptions().CPlusPlus && !D->hasAttrs()) |
| 286 | return false; |
| 287 | |
| 288 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 289 | // over all other naming in the .o file. |
| 290 | if (D->hasAttr<AsmLabelAttr>()) |
| 291 | return true; |
| 292 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 293 | // Clang's "overloadable" attribute extension to C/C++ implies name mangling |
Anders Carlsson | a1e1622 | 2009-11-07 07:15:03 +0000 | [diff] [blame] | 294 | // (always) as does passing a C++ member function and a function |
| 295 | // whose name is not a simple identifier. |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 296 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 297 | if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) || |
| 298 | !FD->getDeclName().isIdentifier())) |
| 299 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 301 | // Otherwise, no mangling is done outside C++ mode. |
| 302 | if (!getASTContext().getLangOptions().CPlusPlus) |
| 303 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 305 | // Variables at global scope with non-internal linkage are not mangled |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 306 | if (!FD) { |
| 307 | const DeclContext *DC = D->getDeclContext(); |
| 308 | // Check for extern variable declared locally. |
Fariborz Jahanian | e81c561 | 2010-06-30 18:57:21 +0000 | [diff] [blame] | 309 | if (DC->isFunctionOrMethod() && D->hasLinkage()) |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 310 | while (!DC->isNamespace() && !DC->isTranslationUnit()) |
| 311 | DC = DC->getParent(); |
Douglas Gregor | 0b6bc8b | 2010-02-03 09:33:45 +0000 | [diff] [blame] | 312 | if (DC->isTranslationUnit() && D->getLinkage() != InternalLinkage) |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 313 | return false; |
| 314 | } |
| 315 | |
Eli Friedman | c00cb64 | 2010-07-18 20:49:59 +0000 | [diff] [blame] | 316 | // Class members are always mangled. |
| 317 | if (D->getDeclContext()->isRecord()) |
| 318 | return true; |
| 319 | |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 320 | // C functions and "main" are not mangled. |
| 321 | if ((FD && FD->isMain()) || isInCLinkageSpecification(D)) |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 322 | return false; |
| 323 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 324 | return true; |
| 325 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 326 | |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 327 | void CXXNameMangler::mangle(const NamedDecl *D, llvm::StringRef Prefix) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 328 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 329 | // over all other naming in the .o file. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 330 | if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 331 | // If we have an asm name, then we use it as the mangling. |
Rafael Espindola | 4e274e9 | 2011-02-15 22:23:51 +0000 | [diff] [blame] | 332 | |
| 333 | // Adding the prefix can cause problems when one file has a "foo" and |
| 334 | // another has a "\01foo". That is known to happen on ELF with the |
| 335 | // tricks normally used for producing aliases (PR9177). Fortunately the |
| 336 | // llvm mangler on ELF is a nop, so we can just avoid adding the \01 |
Peter Collingbourne | 6931743 | 2011-04-06 12:29:09 +0000 | [diff] [blame] | 337 | // marker. We also avoid adding the marker if this is an alias for an |
| 338 | // LLVM intrinsic. |
Rafael Espindola | 4e274e9 | 2011-02-15 22:23:51 +0000 | [diff] [blame] | 339 | llvm::StringRef UserLabelPrefix = |
| 340 | getASTContext().Target.getUserLabelPrefix(); |
Peter Collingbourne | 6931743 | 2011-04-06 12:29:09 +0000 | [diff] [blame] | 341 | if (!UserLabelPrefix.empty() && !ALA->getLabel().startswith("llvm.")) |
Rafael Espindola | 4e274e9 | 2011-02-15 22:23:51 +0000 | [diff] [blame] | 342 | Out << '\01'; // LLVM IR Marker for __asm("foo") |
| 343 | |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 344 | Out << ALA->getLabel(); |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 345 | return; |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 346 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 347 | |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 348 | // <mangled-name> ::= _Z <encoding> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 349 | // ::= <data name> |
| 350 | // ::= <special-name> |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 351 | Out << Prefix; |
| 352 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
Daniel Dunbar | f981bf8 | 2009-11-21 09:14:52 +0000 | [diff] [blame] | 353 | mangleFunctionEncoding(FD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 354 | else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 355 | mangleName(VD); |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 356 | else |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 357 | mangleName(cast<FieldDecl>(D)); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
| 361 | // <encoding> ::= <function name> <bare-function-type> |
| 362 | mangleName(FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 363 | |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 364 | // Don't mangle in the type if this isn't a decl we should typically mangle. |
| 365 | if (!Context.shouldMangleDeclName(FD)) |
| 366 | return; |
| 367 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 368 | // Whether the mangling of a function type includes the return type depends on |
| 369 | // the context and the nature of the function. The rules for deciding whether |
| 370 | // the return type is included are: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 371 | // |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 372 | // 1. Template functions (names or types) have return types encoded, with |
| 373 | // the exceptions listed below. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 374 | // 2. Function types not appearing as part of a function name mangling, |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 375 | // e.g. parameters, pointer types, etc., have return type encoded, with the |
| 376 | // exceptions listed below. |
| 377 | // 3. Non-template function names do not have return types encoded. |
| 378 | // |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 379 | // The exceptions mentioned in (1) and (2) above, for which the return type is |
| 380 | // never included, are |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 381 | // 1. Constructors. |
| 382 | // 2. Destructors. |
| 383 | // 3. Conversion operator functions, e.g. operator int. |
| 384 | bool MangleReturnType = false; |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 385 | if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) { |
| 386 | if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || |
| 387 | isa<CXXConversionDecl>(FD))) |
| 388 | MangleReturnType = true; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 389 | |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 390 | // Mangle the type of the primary template. |
| 391 | FD = PrimaryTemplate->getTemplatedDecl(); |
| 392 | } |
| 393 | |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 394 | // Do the canonicalization out here because parameter types can |
| 395 | // undergo additional canonicalization (e.g. array decay). |
John McCall | f4c7371 | 2011-01-19 06:33:43 +0000 | [diff] [blame] | 396 | const FunctionType *FT |
| 397 | = cast<FunctionType>(Context.getASTContext() |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 398 | .getCanonicalType(FD->getType())); |
| 399 | |
| 400 | mangleBareFunctionType(FT, MangleReturnType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 403 | static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) { |
| 404 | while (isa<LinkageSpecDecl>(DC)) { |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 405 | DC = DC->getParent(); |
| 406 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 407 | |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 408 | return DC; |
| 409 | } |
| 410 | |
Anders Carlsson | c820f90 | 2010-06-02 15:58:27 +0000 | [diff] [blame] | 411 | /// isStd - Return whether a given namespace is the 'std' namespace. |
| 412 | static bool isStd(const NamespaceDecl *NS) { |
| 413 | if (!IgnoreLinkageSpecDecls(NS->getParent())->isTranslationUnit()) |
| 414 | return false; |
| 415 | |
| 416 | const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier(); |
| 417 | return II && II->isStr("std"); |
| 418 | } |
| 419 | |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 420 | // isStdNamespace - Return whether a given decl context is a toplevel 'std' |
| 421 | // namespace. |
Daniel Dunbar | 1308af9 | 2009-11-21 09:11:45 +0000 | [diff] [blame] | 422 | static bool isStdNamespace(const DeclContext *DC) { |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 423 | if (!DC->isNamespace()) |
| 424 | return false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 425 | |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 426 | return isStd(cast<NamespaceDecl>(DC)); |
Daniel Dunbar | 1308af9 | 2009-11-21 09:11:45 +0000 | [diff] [blame] | 427 | } |
| 428 | |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 429 | static const TemplateDecl * |
| 430 | isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 431 | // Check if we have a function template. |
| 432 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){ |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 433 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 434 | TemplateArgs = FD->getTemplateSpecializationArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 435 | return TD; |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 439 | // Check if we have a class template. |
| 440 | if (const ClassTemplateSpecializationDecl *Spec = |
| 441 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 442 | TemplateArgs = &Spec->getTemplateArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 443 | return Spec->getSpecializedTemplate(); |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 444 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 445 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 449 | void CXXNameMangler::mangleName(const NamedDecl *ND) { |
| 450 | // <name> ::= <nested-name> |
| 451 | // ::= <unscoped-name> |
| 452 | // ::= <unscoped-template-name> <template-args> |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 453 | // ::= <local-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 454 | // |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 455 | const DeclContext *DC = ND->getDeclContext(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 456 | |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 457 | // If this is an extern variable declared locally, the relevant DeclContext |
| 458 | // is that of the containing namespace, or the translation unit. |
| 459 | if (isa<FunctionDecl>(DC) && ND->hasLinkage()) |
| 460 | while (!DC->isNamespace() && !DC->isTranslationUnit()) |
| 461 | DC = DC->getParent(); |
John McCall | 82b7d7b | 2010-10-18 21:28:44 +0000 | [diff] [blame] | 462 | else if (GetLocalClassDecl(ND)) { |
| 463 | mangleLocalName(ND); |
| 464 | return; |
| 465 | } |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 466 | |
Anders Carlsson | 5cc58c6 | 2009-09-22 17:23:30 +0000 | [diff] [blame] | 467 | while (isa<LinkageSpecDecl>(DC)) |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 468 | DC = DC->getParent(); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 469 | |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 470 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 471 | // Check if we have a template. |
| 472 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 473 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 474 | mangleUnscopedTemplateName(TD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 475 | TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); |
| 476 | mangleTemplateArgs(*TemplateParameters, *TemplateArgs); |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 477 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 478 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 479 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 480 | mangleUnscopedName(ND); |
| 481 | return; |
| 482 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 483 | |
Anders Carlsson | 7b06f6c | 2009-12-10 03:14:39 +0000 | [diff] [blame] | 484 | if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)) { |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 485 | mangleLocalName(ND); |
| 486 | return; |
| 487 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 488 | |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 489 | mangleNestedName(ND, DC); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 490 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 491 | void CXXNameMangler::mangleName(const TemplateDecl *TD, |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 492 | const TemplateArgument *TemplateArgs, |
| 493 | unsigned NumTemplateArgs) { |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 494 | const DeclContext *DC = IgnoreLinkageSpecDecls(TD->getDeclContext()); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 495 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 496 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 497 | mangleUnscopedTemplateName(TD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 498 | TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); |
| 499 | mangleTemplateArgs(*TemplateParameters, TemplateArgs, NumTemplateArgs); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 500 | } else { |
| 501 | mangleNestedName(TD, TemplateArgs, NumTemplateArgs); |
| 502 | } |
| 503 | } |
| 504 | |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 505 | void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { |
| 506 | // <unscoped-name> ::= <unqualified-name> |
| 507 | // ::= St <unqualified-name> # ::std:: |
| 508 | if (isStdNamespace(ND->getDeclContext())) |
| 509 | Out << "St"; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 510 | |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 511 | mangleUnqualifiedName(ND); |
| 512 | } |
| 513 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 514 | void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 515 | // <unscoped-template-name> ::= <unscoped-name> |
| 516 | // ::= <substitution> |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 517 | if (mangleSubstitution(ND)) |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 518 | return; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 519 | |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 520 | // <template-template-param> ::= <template-param> |
| 521 | if (const TemplateTemplateParmDecl *TTP |
| 522 | = dyn_cast<TemplateTemplateParmDecl>(ND)) { |
| 523 | mangleTemplateParameter(TTP->getIndex()); |
| 524 | return; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 525 | } |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 526 | |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 527 | mangleUnscopedName(ND->getTemplatedDecl()); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 528 | addSubstitution(ND); |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 531 | void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) { |
| 532 | // <unscoped-template-name> ::= <unscoped-name> |
| 533 | // ::= <substitution> |
| 534 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
| 535 | return mangleUnscopedTemplateName(TD); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 536 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 537 | if (mangleSubstitution(Template)) |
| 538 | return; |
| 539 | |
| 540 | // FIXME: How to cope with operators here? |
| 541 | DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
| 542 | assert(Dependent && "Not a dependent template name?"); |
| 543 | if (!Dependent->isIdentifier()) { |
| 544 | // FIXME: We can't possibly know the arity of the operator here! |
| 545 | Diagnostic &Diags = Context.getDiags(); |
| 546 | unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, |
| 547 | "cannot mangle dependent operator name"); |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 548 | Diags.Report(DiagID); |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 549 | return; |
| 550 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 551 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 552 | mangleSourceName(Dependent->getIdentifier()); |
| 553 | addSubstitution(Template); |
| 554 | } |
| 555 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 556 | void CXXNameMangler::mangleFloat(const llvm::APFloat &F) { |
| 557 | // TODO: avoid this copy with careful stream management. |
| 558 | llvm::SmallString<20> Buffer; |
| 559 | F.bitcastToAPInt().toString(Buffer, 16, false); |
| 560 | Out.write(Buffer.data(), Buffer.size()); |
| 561 | } |
| 562 | |
| 563 | void CXXNameMangler::mangleNumber(const llvm::APSInt &Value) { |
| 564 | if (Value.isSigned() && Value.isNegative()) { |
| 565 | Out << 'n'; |
| 566 | Value.abs().print(Out, true); |
| 567 | } else |
| 568 | Value.print(Out, Value.isSigned()); |
| 569 | } |
| 570 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 571 | void CXXNameMangler::mangleNumber(int64_t Number) { |
| 572 | // <number> ::= [n] <non-negative decimal integer> |
| 573 | if (Number < 0) { |
| 574 | Out << 'n'; |
| 575 | Number = -Number; |
| 576 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 577 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 578 | Out << Number; |
| 579 | } |
| 580 | |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 581 | void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t Virtual) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 582 | // <call-offset> ::= h <nv-offset> _ |
| 583 | // ::= v <v-offset> _ |
| 584 | // <nv-offset> ::= <offset number> # non-virtual base override |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 585 | // <v-offset> ::= <offset number> _ <virtual offset number> |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 586 | // # virtual base override, with vcall offset |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 587 | if (!Virtual) { |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 588 | Out << 'h'; |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 589 | mangleNumber(NonVirtual); |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 590 | Out << '_'; |
| 591 | return; |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 592 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 593 | |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 594 | Out << 'v'; |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 595 | mangleNumber(NonVirtual); |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 596 | Out << '_'; |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 597 | mangleNumber(Virtual); |
Anders Carlsson | a94822e | 2009-11-26 02:32:05 +0000 | [diff] [blame] | 598 | Out << '_'; |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 599 | } |
| 600 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 601 | void CXXNameMangler::mangleUnresolvedScope(NestedNameSpecifier *Qualifier) { |
| 602 | Qualifier = getASTContext().getCanonicalNestedNameSpecifier(Qualifier); |
| 603 | switch (Qualifier->getKind()) { |
| 604 | case NestedNameSpecifier::Global: |
| 605 | // nothing |
| 606 | break; |
| 607 | case NestedNameSpecifier::Namespace: |
| 608 | mangleName(Qualifier->getAsNamespace()); |
| 609 | break; |
Douglas Gregor | 14aba76 | 2011-02-24 02:36:08 +0000 | [diff] [blame] | 610 | case NestedNameSpecifier::NamespaceAlias: |
| 611 | mangleName(Qualifier->getAsNamespaceAlias()->getNamespace()); |
| 612 | break; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 613 | case NestedNameSpecifier::TypeSpec: |
Rafael Espindola | 9b35b25 | 2010-03-17 04:28:11 +0000 | [diff] [blame] | 614 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 615 | const Type *QTy = Qualifier->getAsType(); |
| 616 | |
| 617 | if (const TemplateSpecializationType *TST = |
| 618 | dyn_cast<TemplateSpecializationType>(QTy)) { |
| 619 | if (!mangleSubstitution(QualType(TST, 0))) { |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 620 | mangleTemplatePrefix(TST->getTemplateName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 621 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 622 | // FIXME: GCC does not appear to mangle the template arguments when |
| 623 | // the template in question is a dependent template name. Should we |
| 624 | // emulate that badness? |
| 625 | mangleTemplateArgs(TST->getTemplateName(), TST->getArgs(), |
Rafael Espindola | 9b35b25 | 2010-03-17 04:28:11 +0000 | [diff] [blame] | 626 | TST->getNumArgs()); |
| 627 | addSubstitution(QualType(TST, 0)); |
| 628 | } |
Douglas Gregor | aa2187d | 2011-02-28 00:04:36 +0000 | [diff] [blame] | 629 | } else if (const DependentTemplateSpecializationType *DTST |
| 630 | = dyn_cast<DependentTemplateSpecializationType>(QTy)) { |
| 631 | TemplateName Template |
| 632 | = getASTContext().getDependentTemplateName(DTST->getQualifier(), |
| 633 | DTST->getIdentifier()); |
| 634 | mangleTemplatePrefix(Template); |
| 635 | |
| 636 | // FIXME: GCC does not appear to mangle the template arguments when |
| 637 | // the template in question is a dependent template name. Should we |
| 638 | // emulate that badness? |
| 639 | mangleTemplateArgs(Template, DTST->getArgs(), DTST->getNumArgs()); |
Rafael Espindola | 9b35b25 | 2010-03-17 04:28:11 +0000 | [diff] [blame] | 640 | } else { |
| 641 | // We use the QualType mangle type variant here because it handles |
| 642 | // substitutions. |
| 643 | mangleType(QualType(QTy, 0)); |
| 644 | } |
| 645 | } |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 646 | break; |
| 647 | case NestedNameSpecifier::Identifier: |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 648 | // Member expressions can have these without prefixes. |
| 649 | if (Qualifier->getPrefix()) |
| 650 | mangleUnresolvedScope(Qualifier->getPrefix()); |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 651 | mangleSourceName(Qualifier->getAsIdentifier()); |
| 652 | break; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /// Mangles a name which was not resolved to a specific entity. |
| 657 | void CXXNameMangler::mangleUnresolvedName(NestedNameSpecifier *Qualifier, |
| 658 | DeclarationName Name, |
| 659 | unsigned KnownArity) { |
| 660 | if (Qualifier) |
| 661 | mangleUnresolvedScope(Qualifier); |
| 662 | // FIXME: ambiguity of unqualified lookup with :: |
| 663 | |
| 664 | mangleUnqualifiedName(0, Name, KnownArity); |
| 665 | } |
| 666 | |
Anders Carlsson | 6f7e2f4 | 2010-06-08 14:49:03 +0000 | [diff] [blame] | 667 | static const FieldDecl *FindFirstNamedDataMember(const RecordDecl *RD) { |
| 668 | assert(RD->isAnonymousStructOrUnion() && |
| 669 | "Expected anonymous struct or union!"); |
| 670 | |
| 671 | for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); |
| 672 | I != E; ++I) { |
| 673 | const FieldDecl *FD = *I; |
| 674 | |
| 675 | if (FD->getIdentifier()) |
| 676 | return FD; |
| 677 | |
| 678 | if (const RecordType *RT = FD->getType()->getAs<RecordType>()) { |
| 679 | if (const FieldDecl *NamedDataMember = |
| 680 | FindFirstNamedDataMember(RT->getDecl())) |
| 681 | return NamedDataMember; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | // We didn't find a named data member. |
| 686 | return 0; |
| 687 | } |
| 688 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 689 | void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, |
| 690 | DeclarationName Name, |
| 691 | unsigned KnownArity) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 692 | // <unqualified-name> ::= <operator-name> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 693 | // ::= <ctor-dtor-name> |
| 694 | // ::= <source-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 695 | switch (Name.getNameKind()) { |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 696 | case DeclarationName::Identifier: { |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 697 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 698 | // We must avoid conflicts between internally- and externally- |
John McCall | 74990f4 | 2011-03-22 06:34:45 +0000 | [diff] [blame] | 699 | // linked variable and function declaration names in the same TU: |
| 700 | // void test() { extern void foo(); } |
| 701 | // static void foo(); |
| 702 | // This naming convention is the same as that followed by GCC, |
| 703 | // though it shouldn't actually matter. |
| 704 | if (ND && ND->getLinkage() == InternalLinkage && |
Sean Hunt | 3145525 | 2010-01-24 03:04:27 +0000 | [diff] [blame] | 705 | ND->getDeclContext()->isFileContext()) |
| 706 | Out << 'L'; |
| 707 | |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 708 | mangleSourceName(II); |
| 709 | break; |
| 710 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 711 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 712 | // Otherwise, an anonymous entity. We must have a declaration. |
| 713 | assert(ND && "mangling empty name without declaration"); |
| 714 | |
| 715 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
| 716 | if (NS->isAnonymousNamespace()) { |
| 717 | // This is how gcc mangles these names. |
| 718 | Out << "12_GLOBAL__N_1"; |
| 719 | break; |
| 720 | } |
| 721 | } |
| 722 | |
Anders Carlsson | 6f7e2f4 | 2010-06-08 14:49:03 +0000 | [diff] [blame] | 723 | if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { |
| 724 | // We must have an anonymous union or struct declaration. |
| 725 | const RecordDecl *RD = |
| 726 | cast<RecordDecl>(VD->getType()->getAs<RecordType>()->getDecl()); |
| 727 | |
| 728 | // Itanium C++ ABI 5.1.2: |
| 729 | // |
| 730 | // For the purposes of mangling, the name of an anonymous union is |
| 731 | // considered to be the name of the first named data member found by a |
| 732 | // pre-order, depth-first, declaration-order walk of the data members of |
| 733 | // the anonymous union. If there is no such data member (i.e., if all of |
| 734 | // the data members in the union are unnamed), then there is no way for |
| 735 | // a program to refer to the anonymous union, and there is therefore no |
| 736 | // need to mangle its name. |
| 737 | const FieldDecl *FD = FindFirstNamedDataMember(RD); |
John McCall | 7121c8f | 2010-08-05 22:02:13 +0000 | [diff] [blame] | 738 | |
| 739 | // It's actually possible for various reasons for us to get here |
| 740 | // with an empty anonymous struct / union. Fortunately, it |
| 741 | // doesn't really matter what name we generate. |
| 742 | if (!FD) break; |
Anders Carlsson | 6f7e2f4 | 2010-06-08 14:49:03 +0000 | [diff] [blame] | 743 | assert(FD->getIdentifier() && "Data member name isn't an identifier!"); |
| 744 | |
| 745 | mangleSourceName(FD->getIdentifier()); |
| 746 | break; |
| 747 | } |
| 748 | |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 749 | // We must have an anonymous struct. |
| 750 | const TagDecl *TD = cast<TagDecl>(ND); |
| 751 | if (const TypedefDecl *D = TD->getTypedefForAnonDecl()) { |
| 752 | assert(TD->getDeclContext() == D->getDeclContext() && |
| 753 | "Typedef should not be in another decl context!"); |
| 754 | assert(D->getDeclName().getAsIdentifierInfo() && |
| 755 | "Typedef was not named!"); |
| 756 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
| 757 | break; |
| 758 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 759 | |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 760 | // Get a unique id for the anonymous struct. |
| 761 | uint64_t AnonStructId = Context.getAnonymousStructId(TD); |
| 762 | |
| 763 | // Mangle it as a source name in the form |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 764 | // [n] $_<id> |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 765 | // where n is the length of the string. |
| 766 | llvm::SmallString<8> Str; |
| 767 | Str += "$_"; |
| 768 | Str += llvm::utostr(AnonStructId); |
| 769 | |
| 770 | Out << Str.size(); |
| 771 | Out << Str.str(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 772 | break; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 773 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 774 | |
| 775 | case DeclarationName::ObjCZeroArgSelector: |
| 776 | case DeclarationName::ObjCOneArgSelector: |
| 777 | case DeclarationName::ObjCMultiArgSelector: |
| 778 | assert(false && "Can't mangle Objective-C selector names here!"); |
| 779 | break; |
| 780 | |
| 781 | case DeclarationName::CXXConstructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 782 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 783 | // If the named decl is the C++ constructor we're mangling, use the type |
| 784 | // we were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 785 | mangleCXXCtorType(static_cast<CXXCtorType>(StructorType)); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 786 | else |
| 787 | // Otherwise, use the complete constructor name. This is relevant if a |
| 788 | // class with a constructor is declared within a constructor. |
| 789 | mangleCXXCtorType(Ctor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case DeclarationName::CXXDestructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 793 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 794 | // If the named decl is the C++ destructor we're mangling, use the type we |
| 795 | // were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 796 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); |
| 797 | else |
| 798 | // Otherwise, use the complete destructor name. This is relevant if a |
| 799 | // class with a destructor is declared within a destructor. |
| 800 | mangleCXXDtorType(Dtor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 801 | break; |
| 802 | |
| 803 | case DeclarationName::CXXConversionFunctionName: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | // <operator-name> ::= cv <type> # (cast) |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 805 | Out << "cv"; |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 806 | mangleType(Context.getASTContext().getCanonicalType(Name.getCXXNameType())); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 807 | break; |
| 808 | |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 809 | case DeclarationName::CXXOperatorName: { |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 810 | unsigned Arity; |
| 811 | if (ND) { |
| 812 | Arity = cast<FunctionDecl>(ND)->getNumParams(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 813 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 814 | // If we have a C++ member function, we need to include the 'this' pointer. |
| 815 | // FIXME: This does not make sense for operators that are static, but their |
| 816 | // names stay the same regardless of the arity (operator new for instance). |
| 817 | if (isa<CXXMethodDecl>(ND)) |
| 818 | Arity++; |
| 819 | } else |
| 820 | Arity = KnownArity; |
| 821 | |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 822 | mangleOperatorName(Name.getCXXOverloadedOperator(), Arity); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 823 | break; |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 824 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 825 | |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 826 | case DeclarationName::CXXLiteralOperatorName: |
Sean Hunt | 5dd6b39 | 2009-12-04 21:11:13 +0000 | [diff] [blame] | 827 | // FIXME: This mangling is not yet official. |
Sean Hunt | 2421f66 | 2009-12-04 21:01:37 +0000 | [diff] [blame] | 828 | Out << "li"; |
Sean Hunt | 3e518bd | 2009-11-29 07:34:05 +0000 | [diff] [blame] | 829 | mangleSourceName(Name.getCXXLiteralIdentifier()); |
| 830 | break; |
| 831 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 832 | case DeclarationName::CXXUsingDirective: |
| 833 | assert(false && "Can't mangle a using directive name!"); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 834 | break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 835 | } |
| 836 | } |
| 837 | |
| 838 | void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |
| 839 | // <source-name> ::= <positive length number> <identifier> |
| 840 | // <number> ::= [n] <non-negative decimal integer> |
| 841 | // <identifier> ::= <unqualified source code identifier> |
| 842 | Out << II->getLength() << II->getName(); |
| 843 | } |
| 844 | |
Eli Friedman | 7facf84 | 2009-12-02 20:32:49 +0000 | [diff] [blame] | 845 | void CXXNameMangler::mangleNestedName(const NamedDecl *ND, |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 846 | const DeclContext *DC, |
| 847 | bool NoFunction) { |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 848 | // <nested-name> |
| 849 | // ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E |
| 850 | // ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> |
| 851 | // <template-args> E |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 852 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 853 | Out << 'N'; |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 854 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 855 | mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers())); |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 856 | mangleRefQualifier(Method->getRefQualifier()); |
| 857 | } |
| 858 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 859 | // Check if we have a template. |
| 860 | const TemplateArgumentList *TemplateArgs = 0; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 861 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 862 | mangleTemplatePrefix(TD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 863 | TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); |
| 864 | mangleTemplateArgs(*TemplateParameters, *TemplateArgs); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 865 | } |
| 866 | else { |
| 867 | manglePrefix(DC, NoFunction); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 868 | mangleUnqualifiedName(ND); |
| 869 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 870 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 871 | Out << 'E'; |
| 872 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 873 | void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 874 | const TemplateArgument *TemplateArgs, |
| 875 | unsigned NumTemplateArgs) { |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 876 | // <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
| 877 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 878 | Out << 'N'; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 879 | |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 880 | mangleTemplatePrefix(TD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 881 | TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); |
| 882 | mangleTemplateArgs(*TemplateParameters, TemplateArgs, NumTemplateArgs); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 883 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 884 | Out << 'E'; |
| 885 | } |
| 886 | |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 887 | void CXXNameMangler::mangleLocalName(const NamedDecl *ND) { |
| 888 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| 889 | // := Z <function encoding> E s [<discriminator>] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 890 | // <discriminator> := _ <non-negative number> |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 891 | const DeclContext *DC = ND->getDeclContext(); |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 892 | Out << 'Z'; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 893 | |
Charles Davis | 685b1d9 | 2010-05-26 18:25:27 +0000 | [diff] [blame] | 894 | if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) { |
| 895 | mangleObjCMethodName(MD); |
John McCall | 82b7d7b | 2010-10-18 21:28:44 +0000 | [diff] [blame] | 896 | } else if (const CXXRecordDecl *RD = GetLocalClassDecl(ND)) { |
| 897 | mangleFunctionEncoding(cast<FunctionDecl>(RD->getDeclContext())); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 898 | Out << 'E'; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 899 | |
John McCall | 82b7d7b | 2010-10-18 21:28:44 +0000 | [diff] [blame] | 900 | // Mangle the name relative to the closest enclosing function. |
| 901 | if (ND == RD) // equality ok because RD derived from ND above |
| 902 | mangleUnqualifiedName(ND); |
| 903 | else |
| 904 | mangleNestedName(ND, DC, true /*NoFunction*/); |
| 905 | |
Fariborz Jahanian | 4819ac4 | 2010-03-04 01:02:03 +0000 | [diff] [blame] | 906 | unsigned disc; |
John McCall | 82b7d7b | 2010-10-18 21:28:44 +0000 | [diff] [blame] | 907 | if (Context.getNextDiscriminator(RD, disc)) { |
Fariborz Jahanian | 4819ac4 | 2010-03-04 01:02:03 +0000 | [diff] [blame] | 908 | if (disc < 10) |
| 909 | Out << '_' << disc; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 910 | else |
Fariborz Jahanian | 4819ac4 | 2010-03-04 01:02:03 +0000 | [diff] [blame] | 911 | Out << "__" << disc << '_'; |
| 912 | } |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 913 | |
| 914 | return; |
| 915 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 916 | else |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 917 | mangleFunctionEncoding(cast<FunctionDecl>(DC)); |
Anders Carlsson | 7b06f6c | 2009-12-10 03:14:39 +0000 | [diff] [blame] | 918 | |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 919 | Out << 'E'; |
Eli Friedman | 6f9f25d | 2009-12-11 20:21:38 +0000 | [diff] [blame] | 920 | mangleUnqualifiedName(ND); |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 923 | void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 924 | // <prefix> ::= <prefix> <unqualified-name> |
| 925 | // ::= <template-prefix> <template-args> |
| 926 | // ::= <template-param> |
| 927 | // ::= # empty |
| 928 | // ::= <substitution> |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 929 | |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 930 | while (isa<LinkageSpecDecl>(DC)) |
| 931 | DC = DC->getParent(); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 932 | |
Anders Carlsson | 9263e91 | 2009-09-18 18:39:58 +0000 | [diff] [blame] | 933 | if (DC->isTranslationUnit()) |
| 934 | return; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 935 | |
Douglas Gregor | 35415f5 | 2010-05-25 17:04:15 +0000 | [diff] [blame] | 936 | if (const BlockDecl *Block = dyn_cast<BlockDecl>(DC)) { |
| 937 | manglePrefix(DC->getParent(), NoFunction); |
| 938 | llvm::SmallString<64> Name; |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 939 | llvm::raw_svector_ostream NameStream(Name); |
| 940 | Context.mangleBlock(Block, NameStream); |
| 941 | NameStream.flush(); |
Douglas Gregor | 35415f5 | 2010-05-25 17:04:15 +0000 | [diff] [blame] | 942 | Out << Name.size() << Name; |
| 943 | return; |
| 944 | } |
| 945 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 946 | if (mangleSubstitution(cast<NamedDecl>(DC))) |
| 947 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 948 | |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 949 | // Check if we have a template. |
| 950 | const TemplateArgumentList *TemplateArgs = 0; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 951 | if (const TemplateDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) { |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 952 | mangleTemplatePrefix(TD); |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 953 | TemplateParameterList *TemplateParameters = TD->getTemplateParameters(); |
| 954 | mangleTemplateArgs(*TemplateParameters, *TemplateArgs); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 955 | } |
Douglas Gregor | 35415f5 | 2010-05-25 17:04:15 +0000 | [diff] [blame] | 956 | else if(NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC))) |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 957 | return; |
Douglas Gregor | 35415f5 | 2010-05-25 17:04:15 +0000 | [diff] [blame] | 958 | else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) |
| 959 | mangleObjCMethodName(Method); |
Fariborz Jahanian | 5705853 | 2010-03-03 19:41:08 +0000 | [diff] [blame] | 960 | else { |
| 961 | manglePrefix(DC->getParent(), NoFunction); |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 962 | mangleUnqualifiedName(cast<NamedDecl>(DC)); |
| 963 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 964 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 965 | addSubstitution(cast<NamedDecl>(DC)); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 968 | void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) { |
| 969 | // <template-prefix> ::= <prefix> <template unqualified-name> |
| 970 | // ::= <template-param> |
| 971 | // ::= <substitution> |
| 972 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
| 973 | return mangleTemplatePrefix(TD); |
| 974 | |
| 975 | if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName()) |
| 976 | mangleUnresolvedScope(Qualified->getQualifier()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 977 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 978 | if (OverloadedTemplateStorage *Overloaded |
| 979 | = Template.getAsOverloadedTemplate()) { |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 980 | mangleUnqualifiedName(0, (*Overloaded->begin())->getDeclName(), |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 981 | UnknownArity); |
| 982 | return; |
| 983 | } |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 985 | DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
| 986 | assert(Dependent && "Unknown template name kind?"); |
| 987 | mangleUnresolvedScope(Dependent->getQualifier()); |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 988 | mangleUnscopedTemplateName(Template); |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 991 | void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND) { |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 992 | // <template-prefix> ::= <prefix> <template unqualified-name> |
| 993 | // ::= <template-param> |
| 994 | // ::= <substitution> |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 995 | // <template-template-param> ::= <template-param> |
| 996 | // <substitution> |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 997 | |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 998 | if (mangleSubstitution(ND)) |
| 999 | return; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 1000 | |
Douglas Gregor | 32fb4e1 | 2010-02-05 20:45:00 +0000 | [diff] [blame] | 1001 | // <template-template-param> ::= <template-param> |
| 1002 | if (const TemplateTemplateParmDecl *TTP |
| 1003 | = dyn_cast<TemplateTemplateParmDecl>(ND)) { |
| 1004 | mangleTemplateParameter(TTP->getIndex()); |
| 1005 | return; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1006 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 1007 | |
Anders Carlsson | aa73ab1 | 2009-09-18 18:47:07 +0000 | [diff] [blame] | 1008 | manglePrefix(ND->getDeclContext()); |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 1009 | mangleUnqualifiedName(ND->getTemplatedDecl()); |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 1010 | addSubstitution(ND); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 1013 | /// Mangles a template name under the production <type>. Required for |
| 1014 | /// template template arguments. |
| 1015 | /// <type> ::= <class-enum-type> |
| 1016 | /// ::= <template-param> |
| 1017 | /// ::= <substitution> |
| 1018 | void CXXNameMangler::mangleType(TemplateName TN) { |
| 1019 | if (mangleSubstitution(TN)) |
| 1020 | return; |
| 1021 | |
| 1022 | TemplateDecl *TD = 0; |
| 1023 | |
| 1024 | switch (TN.getKind()) { |
| 1025 | case TemplateName::QualifiedTemplate: |
| 1026 | TD = TN.getAsQualifiedTemplateName()->getTemplateDecl(); |
| 1027 | goto HaveDecl; |
| 1028 | |
| 1029 | case TemplateName::Template: |
| 1030 | TD = TN.getAsTemplateDecl(); |
| 1031 | goto HaveDecl; |
| 1032 | |
| 1033 | HaveDecl: |
| 1034 | if (isa<TemplateTemplateParmDecl>(TD)) |
| 1035 | mangleTemplateParameter(cast<TemplateTemplateParmDecl>(TD)->getIndex()); |
| 1036 | else |
| 1037 | mangleName(TD); |
| 1038 | break; |
| 1039 | |
| 1040 | case TemplateName::OverloadedTemplate: |
| 1041 | llvm_unreachable("can't mangle an overloaded template name as a <type>"); |
| 1042 | break; |
| 1043 | |
| 1044 | case TemplateName::DependentTemplate: { |
| 1045 | const DependentTemplateName *Dependent = TN.getAsDependentTemplateName(); |
| 1046 | assert(Dependent->isIdentifier()); |
| 1047 | |
| 1048 | // <class-enum-type> ::= <name> |
| 1049 | // <name> ::= <nested-name> |
| 1050 | mangleUnresolvedScope(Dependent->getQualifier()); |
| 1051 | mangleSourceName(Dependent->getIdentifier()); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
Douglas Gregor | 1aee05d | 2011-01-15 06:45:20 +0000 | [diff] [blame] | 1055 | case TemplateName::SubstTemplateTemplateParmPack: { |
| 1056 | SubstTemplateTemplateParmPackStorage *SubstPack |
| 1057 | = TN.getAsSubstTemplateTemplateParmPack(); |
| 1058 | mangleTemplateParameter(SubstPack->getParameterPack()->getIndex()); |
| 1059 | break; |
| 1060 | } |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | addSubstitution(TN); |
| 1064 | } |
| 1065 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | void |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1067 | CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) { |
| 1068 | switch (OO) { |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1069 | // <operator-name> ::= nw # new |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1070 | case OO_New: Out << "nw"; break; |
| 1071 | // ::= na # new[] |
| 1072 | case OO_Array_New: Out << "na"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1073 | // ::= dl # delete |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1074 | case OO_Delete: Out << "dl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1075 | // ::= da # delete[] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1076 | case OO_Array_Delete: Out << "da"; break; |
| 1077 | // ::= ps # + (unary) |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1078 | // ::= pl # + (binary or unknown) |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1079 | case OO_Plus: |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 1080 | Out << (Arity == 1? "ps" : "pl"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1081 | // ::= ng # - (unary) |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1082 | // ::= mi # - (binary or unknown) |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1083 | case OO_Minus: |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 1084 | Out << (Arity == 1? "ng" : "mi"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1085 | // ::= ad # & (unary) |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1086 | // ::= an # & (binary or unknown) |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1087 | case OO_Amp: |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 1088 | Out << (Arity == 1? "ad" : "an"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1089 | // ::= de # * (unary) |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1090 | // ::= ml # * (binary or unknown) |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1091 | case OO_Star: |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1092 | // Use binary when unknown. |
Anders Carlsson | 8257d41 | 2009-12-22 06:36:32 +0000 | [diff] [blame] | 1093 | Out << (Arity == 1? "de" : "ml"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1094 | // ::= co # ~ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1095 | case OO_Tilde: Out << "co"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1096 | // ::= dv # / |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1097 | case OO_Slash: Out << "dv"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1098 | // ::= rm # % |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1099 | case OO_Percent: Out << "rm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1100 | // ::= or # | |
| 1101 | case OO_Pipe: Out << "or"; break; |
| 1102 | // ::= eo # ^ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1103 | case OO_Caret: Out << "eo"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1104 | // ::= aS # = |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1105 | case OO_Equal: Out << "aS"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1106 | // ::= pL # += |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1107 | case OO_PlusEqual: Out << "pL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1108 | // ::= mI # -= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1109 | case OO_MinusEqual: Out << "mI"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1110 | // ::= mL # *= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1111 | case OO_StarEqual: Out << "mL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1112 | // ::= dV # /= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1113 | case OO_SlashEqual: Out << "dV"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1114 | // ::= rM # %= |
| 1115 | case OO_PercentEqual: Out << "rM"; break; |
| 1116 | // ::= aN # &= |
| 1117 | case OO_AmpEqual: Out << "aN"; break; |
| 1118 | // ::= oR # |= |
| 1119 | case OO_PipeEqual: Out << "oR"; break; |
| 1120 | // ::= eO # ^= |
| 1121 | case OO_CaretEqual: Out << "eO"; break; |
| 1122 | // ::= ls # << |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1123 | case OO_LessLess: Out << "ls"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1124 | // ::= rs # >> |
| 1125 | case OO_GreaterGreater: Out << "rs"; break; |
| 1126 | // ::= lS # <<= |
| 1127 | case OO_LessLessEqual: Out << "lS"; break; |
| 1128 | // ::= rS # >>= |
| 1129 | case OO_GreaterGreaterEqual: Out << "rS"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1130 | // ::= eq # == |
| 1131 | case OO_EqualEqual: Out << "eq"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1132 | // ::= ne # != |
| 1133 | case OO_ExclaimEqual: Out << "ne"; break; |
| 1134 | // ::= lt # < |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1135 | case OO_Less: Out << "lt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1136 | // ::= gt # > |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1137 | case OO_Greater: Out << "gt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1138 | // ::= le # <= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1139 | case OO_LessEqual: Out << "le"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1140 | // ::= ge # >= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1141 | case OO_GreaterEqual: Out << "ge"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1142 | // ::= nt # ! |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1143 | case OO_Exclaim: Out << "nt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1144 | // ::= aa # && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1145 | case OO_AmpAmp: Out << "aa"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1146 | // ::= oo # || |
| 1147 | case OO_PipePipe: Out << "oo"; break; |
| 1148 | // ::= pp # ++ |
| 1149 | case OO_PlusPlus: Out << "pp"; break; |
| 1150 | // ::= mm # -- |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1151 | case OO_MinusMinus: Out << "mm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1152 | // ::= cm # , |
| 1153 | case OO_Comma: Out << "cm"; break; |
| 1154 | // ::= pm # ->* |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1155 | case OO_ArrowStar: Out << "pm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1156 | // ::= pt # -> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1157 | case OO_Arrow: Out << "pt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1158 | // ::= cl # () |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1159 | case OO_Call: Out << "cl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1160 | // ::= ix # [] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1161 | case OO_Subscript: Out << "ix"; break; |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1162 | |
| 1163 | // ::= qu # ? |
| 1164 | // The conditional operator can't be overloaded, but we still handle it when |
| 1165 | // mangling expressions. |
| 1166 | case OO_Conditional: Out << "qu"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1167 | |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 1168 | case OO_None: |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1169 | case NUM_OVERLOADED_OPERATORS: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1170 | assert(false && "Not an overloaded operator"); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1171 | break; |
| 1172 | } |
| 1173 | } |
| 1174 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1175 | void CXXNameMangler::mangleQualifiers(Qualifiers Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1177 | if (Quals.hasRestrict()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1178 | Out << 'r'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1179 | if (Quals.hasVolatile()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1180 | Out << 'V'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1181 | if (Quals.hasConst()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1182 | Out << 'K'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1183 | |
Douglas Gregor | 56079f7 | 2010-06-14 23:15:08 +0000 | [diff] [blame] | 1184 | if (Quals.hasAddressSpace()) { |
| 1185 | // Extension: |
| 1186 | // |
| 1187 | // <type> ::= U <address-space-number> |
| 1188 | // |
| 1189 | // where <address-space-number> is a source name consisting of 'AS' |
| 1190 | // followed by the address space <number>. |
| 1191 | llvm::SmallString<64> ASString; |
| 1192 | ASString = "AS" + llvm::utostr_32(Quals.getAddressSpace()); |
| 1193 | Out << 'U' << ASString.size() << ASString; |
| 1194 | } |
| 1195 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1196 | // FIXME: For now, just drop all extension qualifiers on the floor. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 1199 | void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) { |
| 1200 | // <ref-qualifier> ::= R # lvalue reference |
| 1201 | // ::= O # rvalue-reference |
| 1202 | // Proposal to Itanium C++ ABI list on 1/26/11 |
| 1203 | switch (RefQualifier) { |
| 1204 | case RQ_None: |
| 1205 | break; |
| 1206 | |
| 1207 | case RQ_LValue: |
| 1208 | Out << 'R'; |
| 1209 | break; |
| 1210 | |
| 1211 | case RQ_RValue: |
| 1212 | Out << 'O'; |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Anders Carlsson | 7b06f6c | 2009-12-10 03:14:39 +0000 | [diff] [blame] | 1217 | void CXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) { |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 1218 | Context.mangleObjCMethodName(MD, Out); |
Anders Carlsson | 7b06f6c | 2009-12-10 03:14:39 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1221 | void CXXNameMangler::mangleType(QualType nonCanon) { |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 1222 | // Only operate on the canonical type! |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1223 | QualType canon = nonCanon.getCanonicalType(); |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 1224 | |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1225 | SplitQualType split = canon.split(); |
| 1226 | Qualifiers quals = split.second; |
| 1227 | const Type *ty = split.first; |
| 1228 | |
| 1229 | bool isSubstitutable = quals || !isa<BuiltinType>(ty); |
| 1230 | if (isSubstitutable && mangleSubstitution(canon)) |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1231 | return; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1232 | |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1233 | // If we're mangling a qualified array type, push the qualifiers to |
| 1234 | // the element type. |
| 1235 | if (quals && isa<ArrayType>(ty)) { |
| 1236 | ty = Context.getASTContext().getAsArrayType(canon); |
| 1237 | quals = Qualifiers(); |
| 1238 | |
| 1239 | // Note that we don't update canon: we want to add the |
| 1240 | // substitution at the canonical type. |
| 1241 | } |
| 1242 | |
| 1243 | if (quals) { |
| 1244 | mangleQualifiers(quals); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1245 | // Recurse: even if the qualified type isn't yet substitutable, |
| 1246 | // the unqualified type might be. |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1247 | mangleType(QualType(ty, 0)); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1248 | } else { |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1249 | switch (ty->getTypeClass()) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1250 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 1251 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1252 | case Type::CLASS: \ |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1253 | llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1254 | return; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1255 | #define TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1256 | case Type::CLASS: \ |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1257 | mangleType(static_cast<const CLASS##Type*>(ty)); \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1258 | break; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1259 | #include "clang/AST/TypeNodes.def" |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1260 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1261 | } |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1262 | |
| 1263 | // Add the substitution. |
John McCall | b47f748 | 2011-01-26 20:05:40 +0000 | [diff] [blame] | 1264 | if (isSubstitutable) |
| 1265 | addSubstitution(canon); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 1268 | void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) { |
| 1269 | if (!mangleStandardSubstitution(ND)) |
| 1270 | mangleName(ND); |
| 1271 | } |
| 1272 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1273 | void CXXNameMangler::mangleType(const BuiltinType *T) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1274 | // <type> ::= <builtin-type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1275 | // <builtin-type> ::= v # void |
| 1276 | // ::= w # wchar_t |
| 1277 | // ::= b # bool |
| 1278 | // ::= c # char |
| 1279 | // ::= a # signed char |
| 1280 | // ::= h # unsigned char |
| 1281 | // ::= s # short |
| 1282 | // ::= t # unsigned short |
| 1283 | // ::= i # int |
| 1284 | // ::= j # unsigned int |
| 1285 | // ::= l # long |
| 1286 | // ::= m # unsigned long |
| 1287 | // ::= x # long long, __int64 |
| 1288 | // ::= y # unsigned long long, __int64 |
| 1289 | // ::= n # __int128 |
| 1290 | // UNSUPPORTED: ::= o # unsigned __int128 |
| 1291 | // ::= f # float |
| 1292 | // ::= d # double |
| 1293 | // ::= e # long double, __float80 |
| 1294 | // UNSUPPORTED: ::= g # __float128 |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1295 | // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits) |
| 1296 | // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits) |
| 1297 | // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits) |
| 1298 | // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits) |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1299 | // ::= Di # char32_t |
| 1300 | // ::= Ds # char16_t |
Anders Carlsson | e292368 | 2010-11-04 04:31:32 +0000 | [diff] [blame] | 1301 | // ::= Dn # std::nullptr_t (i.e., decltype(nullptr)) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1302 | // ::= u <source-name> # vendor extended type |
| 1303 | switch (T->getKind()) { |
| 1304 | case BuiltinType::Void: Out << 'v'; break; |
| 1305 | case BuiltinType::Bool: Out << 'b'; break; |
| 1306 | case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break; |
| 1307 | case BuiltinType::UChar: Out << 'h'; break; |
| 1308 | case BuiltinType::UShort: Out << 't'; break; |
| 1309 | case BuiltinType::UInt: Out << 'j'; break; |
| 1310 | case BuiltinType::ULong: Out << 'm'; break; |
| 1311 | case BuiltinType::ULongLong: Out << 'y'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 1312 | case BuiltinType::UInt128: Out << 'o'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1313 | case BuiltinType::SChar: Out << 'a'; break; |
Chris Lattner | 3f59c97 | 2010-12-25 23:25:43 +0000 | [diff] [blame] | 1314 | case BuiltinType::WChar_S: |
| 1315 | case BuiltinType::WChar_U: Out << 'w'; break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 1316 | case BuiltinType::Char16: Out << "Ds"; break; |
| 1317 | case BuiltinType::Char32: Out << "Di"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1318 | case BuiltinType::Short: Out << 's'; break; |
| 1319 | case BuiltinType::Int: Out << 'i'; break; |
| 1320 | case BuiltinType::Long: Out << 'l'; break; |
| 1321 | case BuiltinType::LongLong: Out << 'x'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 1322 | case BuiltinType::Int128: Out << 'n'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1323 | case BuiltinType::Float: Out << 'f'; break; |
| 1324 | case BuiltinType::Double: Out << 'd'; break; |
| 1325 | case BuiltinType::LongDouble: Out << 'e'; break; |
Anders Carlsson | e292368 | 2010-11-04 04:31:32 +0000 | [diff] [blame] | 1326 | case BuiltinType::NullPtr: Out << "Dn"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1327 | |
| 1328 | case BuiltinType::Overload: |
| 1329 | case BuiltinType::Dependent: |
John McCall | 1de4d4e | 2011-04-07 08:22:57 +0000 | [diff] [blame] | 1330 | case BuiltinType::UnknownAny: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1331 | assert(false && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1332 | "Overloaded and dependent types shouldn't get to name mangling"); |
| 1333 | break; |
Steve Naroff | 9533a7f | 2009-07-22 17:14:51 +0000 | [diff] [blame] | 1334 | case BuiltinType::ObjCId: Out << "11objc_object"; break; |
| 1335 | case BuiltinType::ObjCClass: Out << "10objc_class"; break; |
Fariborz Jahanian | 13dcd00 | 2009-11-21 19:53:08 +0000 | [diff] [blame] | 1336 | case BuiltinType::ObjCSel: Out << "13objc_selector"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1340 | // <type> ::= <function-type> |
| 1341 | // <function-type> ::= F [Y] <bare-function-type> E |
| 1342 | void CXXNameMangler::mangleType(const FunctionProtoType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1343 | Out << 'F'; |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 1344 | // FIXME: We don't have enough information in the AST to produce the 'Y' |
| 1345 | // encoding for extern "C" function types. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1346 | mangleBareFunctionType(T, /*MangleReturnType=*/true); |
| 1347 | Out << 'E'; |
| 1348 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1349 | void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { |
Jeffrey Yasskin | 9f61aa9 | 2009-12-12 05:05:38 +0000 | [diff] [blame] | 1350 | llvm_unreachable("Can't mangle K&R function prototypes"); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1351 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1352 | void CXXNameMangler::mangleBareFunctionType(const FunctionType *T, |
| 1353 | bool MangleReturnType) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1354 | // We should never be mangling something without a prototype. |
| 1355 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 1356 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1357 | // <bare-function-type> ::= <signature type>+ |
| 1358 | if (MangleReturnType) |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1359 | mangleType(Proto->getResultType()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1360 | |
Anders Carlsson | 9329668 | 2010-06-02 04:40:13 +0000 | [diff] [blame] | 1361 | if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) { |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 1362 | // <builtin-type> ::= v # void |
Anders Carlsson | c6c91bc | 2009-04-01 00:15:23 +0000 | [diff] [blame] | 1363 | Out << 'v'; |
| 1364 | return; |
| 1365 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1366 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1367 | for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | ArgEnd = Proto->arg_type_end(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1369 | Arg != ArgEnd; ++Arg) |
| 1370 | mangleType(*Arg); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 1371 | |
| 1372 | // <builtin-type> ::= z # ellipsis |
| 1373 | if (Proto->isVariadic()) |
| 1374 | Out << 'z'; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1375 | } |
| 1376 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1377 | // <type> ::= <class-enum-type> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | // <class-enum-type> ::= <name> |
John McCall | ed97649 | 2009-12-04 22:46:56 +0000 | [diff] [blame] | 1379 | void CXXNameMangler::mangleType(const UnresolvedUsingType *T) { |
| 1380 | mangleName(T->getDecl()); |
| 1381 | } |
| 1382 | |
| 1383 | // <type> ::= <class-enum-type> |
| 1384 | // <class-enum-type> ::= <name> |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1385 | void CXXNameMangler::mangleType(const EnumType *T) { |
| 1386 | mangleType(static_cast<const TagType*>(T)); |
| 1387 | } |
| 1388 | void CXXNameMangler::mangleType(const RecordType *T) { |
| 1389 | mangleType(static_cast<const TagType*>(T)); |
| 1390 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1391 | void CXXNameMangler::mangleType(const TagType *T) { |
Eli Friedman | ecb7e93 | 2009-12-11 18:00:57 +0000 | [diff] [blame] | 1392 | mangleName(T->getDecl()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1395 | // <type> ::= <array-type> |
| 1396 | // <array-type> ::= A <positive dimension number> _ <element type> |
| 1397 | // ::= A [<dimension expression>] _ <element type> |
| 1398 | void CXXNameMangler::mangleType(const ConstantArrayType *T) { |
| 1399 | Out << 'A' << T->getSize() << '_'; |
| 1400 | mangleType(T->getElementType()); |
| 1401 | } |
| 1402 | void CXXNameMangler::mangleType(const VariableArrayType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1403 | Out << 'A'; |
Fariborz Jahanian | 7281d1f | 2010-11-02 16:54:00 +0000 | [diff] [blame] | 1404 | // decayed vla types (size 0) will just be skipped. |
| 1405 | if (T->getSizeExpr()) |
| 1406 | mangleExpression(T->getSizeExpr()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1407 | Out << '_'; |
| 1408 | mangleType(T->getElementType()); |
| 1409 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1410 | void CXXNameMangler::mangleType(const DependentSizedArrayType *T) { |
| 1411 | Out << 'A'; |
| 1412 | mangleExpression(T->getSizeExpr()); |
| 1413 | Out << '_'; |
| 1414 | mangleType(T->getElementType()); |
| 1415 | } |
| 1416 | void CXXNameMangler::mangleType(const IncompleteArrayType *T) { |
Nick Lewycky | 271b665 | 2010-09-05 03:40:33 +0000 | [diff] [blame] | 1417 | Out << "A_"; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1418 | mangleType(T->getElementType()); |
| 1419 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1420 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1421 | // <type> ::= <pointer-to-member-type> |
| 1422 | // <pointer-to-member-type> ::= M <class type> <member type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1423 | void CXXNameMangler::mangleType(const MemberPointerType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1424 | Out << 'M'; |
| 1425 | mangleType(QualType(T->getClass(), 0)); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 1426 | QualType PointeeType = T->getPointeeType(); |
| 1427 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 1428 | mangleQualifiers(Qualifiers::fromCVRMask(FPT->getTypeQuals())); |
Douglas Gregor | 0a9a6d6 | 2011-01-26 17:36:28 +0000 | [diff] [blame] | 1429 | mangleRefQualifier(FPT->getRefQualifier()); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 1430 | mangleType(FPT); |
Anders Carlsson | 9d85b72 | 2010-06-02 04:29:50 +0000 | [diff] [blame] | 1431 | |
| 1432 | // Itanium C++ ABI 5.1.8: |
| 1433 | // |
| 1434 | // The type of a non-static member function is considered to be different, |
| 1435 | // for the purposes of substitution, from the type of a namespace-scope or |
| 1436 | // static member function whose type appears similar. The types of two |
| 1437 | // non-static member functions are considered to be different, for the |
| 1438 | // purposes of substitution, if the functions are members of different |
| 1439 | // classes. In other words, for the purposes of substitution, the class of |
| 1440 | // which the function is a member is considered part of the type of |
| 1441 | // function. |
| 1442 | |
| 1443 | // We increment the SeqID here to emulate adding an entry to the |
| 1444 | // substitution table. We can't actually add it because we don't want this |
| 1445 | // particular function type to be substituted. |
| 1446 | ++SeqID; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | } else |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 1448 | mangleType(PointeeType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1451 | // <type> ::= <template-param> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1452 | void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 1453 | mangleTemplateParameter(T->getIndex()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1456 | // <type> ::= <template-param> |
| 1457 | void CXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T) { |
| 1458 | mangleTemplateParameter(T->getReplacedParameter()->getIndex()); |
| 1459 | } |
| 1460 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1461 | // <type> ::= P <type> # pointer-to |
| 1462 | void CXXNameMangler::mangleType(const PointerType *T) { |
| 1463 | Out << 'P'; |
| 1464 | mangleType(T->getPointeeType()); |
| 1465 | } |
| 1466 | void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) { |
| 1467 | Out << 'P'; |
| 1468 | mangleType(T->getPointeeType()); |
| 1469 | } |
| 1470 | |
| 1471 | // <type> ::= R <type> # reference-to |
| 1472 | void CXXNameMangler::mangleType(const LValueReferenceType *T) { |
| 1473 | Out << 'R'; |
| 1474 | mangleType(T->getPointeeType()); |
| 1475 | } |
| 1476 | |
| 1477 | // <type> ::= O <type> # rvalue reference-to (C++0x) |
| 1478 | void CXXNameMangler::mangleType(const RValueReferenceType *T) { |
| 1479 | Out << 'O'; |
| 1480 | mangleType(T->getPointeeType()); |
| 1481 | } |
| 1482 | |
| 1483 | // <type> ::= C <type> # complex pair (C 2000) |
| 1484 | void CXXNameMangler::mangleType(const ComplexType *T) { |
| 1485 | Out << 'C'; |
| 1486 | mangleType(T->getElementType()); |
| 1487 | } |
| 1488 | |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1489 | // ARM's ABI for Neon vector types specifies that they should be mangled as |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1490 | // if they are structs (to match ARM's initial implementation). The |
| 1491 | // vector type must be one of the special types predefined by ARM. |
| 1492 | void CXXNameMangler::mangleNeonVectorType(const VectorType *T) { |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1493 | QualType EltType = T->getElementType(); |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1494 | assert(EltType->isBuiltinType() && "Neon vector element not a BuiltinType"); |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1495 | const char *EltName = 0; |
Bob Wilson | 491328c | 2010-11-12 17:24:46 +0000 | [diff] [blame] | 1496 | if (T->getVectorKind() == VectorType::NeonPolyVector) { |
| 1497 | switch (cast<BuiltinType>(EltType)->getKind()) { |
Bob Wilson | 4cfaa5d | 2010-11-12 17:24:49 +0000 | [diff] [blame] | 1498 | case BuiltinType::SChar: EltName = "poly8_t"; break; |
| 1499 | case BuiltinType::Short: EltName = "poly16_t"; break; |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1500 | default: llvm_unreachable("unexpected Neon polynomial vector element type"); |
Bob Wilson | 491328c | 2010-11-12 17:24:46 +0000 | [diff] [blame] | 1501 | } |
| 1502 | } else { |
| 1503 | switch (cast<BuiltinType>(EltType)->getKind()) { |
Bob Wilson | 4cfaa5d | 2010-11-12 17:24:49 +0000 | [diff] [blame] | 1504 | case BuiltinType::SChar: EltName = "int8_t"; break; |
| 1505 | case BuiltinType::UChar: EltName = "uint8_t"; break; |
| 1506 | case BuiltinType::Short: EltName = "int16_t"; break; |
| 1507 | case BuiltinType::UShort: EltName = "uint16_t"; break; |
| 1508 | case BuiltinType::Int: EltName = "int32_t"; break; |
| 1509 | case BuiltinType::UInt: EltName = "uint32_t"; break; |
| 1510 | case BuiltinType::LongLong: EltName = "int64_t"; break; |
| 1511 | case BuiltinType::ULongLong: EltName = "uint64_t"; break; |
| 1512 | case BuiltinType::Float: EltName = "float32_t"; break; |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1513 | default: llvm_unreachable("unexpected Neon vector element type"); |
Bob Wilson | 491328c | 2010-11-12 17:24:46 +0000 | [diff] [blame] | 1514 | } |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1515 | } |
| 1516 | const char *BaseName = 0; |
Bob Wilson | 4cfaa5d | 2010-11-12 17:24:49 +0000 | [diff] [blame] | 1517 | unsigned BitSize = (T->getNumElements() * |
Bob Wilson | 3a72302 | 2010-11-16 00:32:12 +0000 | [diff] [blame] | 1518 | getASTContext().getTypeSize(EltType)); |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1519 | if (BitSize == 64) |
| 1520 | BaseName = "__simd64_"; |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1521 | else { |
| 1522 | assert(BitSize == 128 && "Neon vector type not 64 or 128 bits"); |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1523 | BaseName = "__simd128_"; |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1524 | } |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1525 | Out << strlen(BaseName) + strlen(EltName); |
| 1526 | Out << BaseName << EltName; |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1529 | // GNU extension: vector types |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 1530 | // <type> ::= <vector-type> |
| 1531 | // <vector-type> ::= Dv <positive dimension number> _ |
| 1532 | // <extended element type> |
| 1533 | // ::= Dv [<dimension expression>] _ <element type> |
| 1534 | // <extended element type> ::= <element type> |
| 1535 | // ::= p # AltiVec vector pixel |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1536 | void CXXNameMangler::mangleType(const VectorType *T) { |
Bob Wilson | 491328c | 2010-11-12 17:24:46 +0000 | [diff] [blame] | 1537 | if ((T->getVectorKind() == VectorType::NeonVector || |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1538 | T->getVectorKind() == VectorType::NeonPolyVector)) { |
| 1539 | mangleNeonVectorType(T); |
Bob Wilson | c7df92d | 2010-11-12 17:24:43 +0000 | [diff] [blame] | 1540 | return; |
Bob Wilson | 57147a8 | 2010-11-16 00:32:18 +0000 | [diff] [blame] | 1541 | } |
Nick Lewycky | 0e5f067 | 2010-03-26 07:18:04 +0000 | [diff] [blame] | 1542 | Out << "Dv" << T->getNumElements() << '_'; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1543 | if (T->getVectorKind() == VectorType::AltiVecPixel) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 1544 | Out << 'p'; |
Bob Wilson | e86d78c | 2010-11-10 21:56:12 +0000 | [diff] [blame] | 1545 | else if (T->getVectorKind() == VectorType::AltiVecBool) |
Chris Lattner | 788b0fd | 2010-06-23 06:00:24 +0000 | [diff] [blame] | 1546 | Out << 'b'; |
| 1547 | else |
| 1548 | mangleType(T->getElementType()); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1549 | } |
| 1550 | void CXXNameMangler::mangleType(const ExtVectorType *T) { |
| 1551 | mangleType(static_cast<const VectorType*>(T)); |
| 1552 | } |
| 1553 | void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) { |
Nick Lewycky | 0e5f067 | 2010-03-26 07:18:04 +0000 | [diff] [blame] | 1554 | Out << "Dv"; |
| 1555 | mangleExpression(T->getSizeExpr()); |
| 1556 | Out << '_'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1557 | mangleType(T->getElementType()); |
| 1558 | } |
| 1559 | |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 1560 | void CXXNameMangler::mangleType(const PackExpansionType *T) { |
Douglas Gregor | 4fc4866 | 2011-01-13 16:39:34 +0000 | [diff] [blame] | 1561 | // <type> ::= Dp <type> # pack expansion (C++0x) |
Douglas Gregor | 255c269 | 2011-01-13 17:44:36 +0000 | [diff] [blame] | 1562 | Out << "Dp"; |
Douglas Gregor | 7536dd5 | 2010-12-20 02:24:11 +0000 | [diff] [blame] | 1563 | mangleType(T->getPattern()); |
| 1564 | } |
| 1565 | |
Anders Carlsson | a40c5e4 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 1566 | void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { |
| 1567 | mangleSourceName(T->getDecl()->getIdentifier()); |
| 1568 | } |
| 1569 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1570 | void CXXNameMangler::mangleType(const ObjCObjectType *T) { |
John McCall | c00c1f6 | 2010-05-15 17:06:29 +0000 | [diff] [blame] | 1571 | // We don't allow overloading by different protocol qualification, |
| 1572 | // so mangling them isn't necessary. |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1573 | mangleType(T->getBaseType()); |
| 1574 | } |
| 1575 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1576 | void CXXNameMangler::mangleType(const BlockPointerType *T) { |
Anders Carlsson | f28c687 | 2009-12-23 22:31:44 +0000 | [diff] [blame] | 1577 | Out << "U13block_pointer"; |
| 1578 | mangleType(T->getPointeeType()); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
John McCall | 31f17ec | 2010-04-27 00:57:59 +0000 | [diff] [blame] | 1581 | void CXXNameMangler::mangleType(const InjectedClassNameType *T) { |
| 1582 | // Mangle injected class name types as if the user had written the |
| 1583 | // specialization out fully. It may not actually be possible to see |
| 1584 | // this mangling, though. |
| 1585 | mangleType(T->getInjectedSpecializationType()); |
| 1586 | } |
| 1587 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1588 | void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 1589 | if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) { |
| 1590 | mangleName(TD, T->getArgs(), T->getNumArgs()); |
| 1591 | } else { |
| 1592 | if (mangleSubstitution(QualType(T, 0))) |
| 1593 | return; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1594 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 1595 | mangleTemplatePrefix(T->getTemplateName()); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 1596 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 1597 | // FIXME: GCC does not appear to mangle the template arguments when |
| 1598 | // the template in question is a dependent template name. Should we |
| 1599 | // emulate that badness? |
| 1600 | mangleTemplateArgs(T->getTemplateName(), T->getArgs(), T->getNumArgs()); |
| 1601 | addSubstitution(QualType(T, 0)); |
| 1602 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Douglas Gregor | 4714c12 | 2010-03-31 17:34:00 +0000 | [diff] [blame] | 1605 | void CXXNameMangler::mangleType(const DependentNameType *T) { |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 1606 | // Typename types are always nested |
| 1607 | Out << 'N'; |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 1608 | mangleUnresolvedScope(T->getQualifier()); |
| 1609 | mangleSourceName(T->getIdentifier()); |
| 1610 | Out << 'E'; |
| 1611 | } |
John McCall | 6ab30e0 | 2010-06-09 07:26:17 +0000 | [diff] [blame] | 1612 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 1613 | void CXXNameMangler::mangleType(const DependentTemplateSpecializationType *T) { |
Douglas Gregor | aa2187d | 2011-02-28 00:04:36 +0000 | [diff] [blame] | 1614 | // Dependently-scoped template types are nested if they have a prefix. |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 1615 | Out << 'N'; |
| 1616 | |
| 1617 | // TODO: avoid making this TemplateName. |
| 1618 | TemplateName Prefix = |
| 1619 | getASTContext().getDependentTemplateName(T->getQualifier(), |
| 1620 | T->getIdentifier()); |
| 1621 | mangleTemplatePrefix(Prefix); |
| 1622 | |
| 1623 | // FIXME: GCC does not appear to mangle the template arguments when |
| 1624 | // the template in question is a dependent template name. Should we |
| 1625 | // emulate that badness? |
| 1626 | mangleTemplateArgs(Prefix, T->getArgs(), T->getNumArgs()); |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 1627 | Out << 'E'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 1630 | void CXXNameMangler::mangleType(const TypeOfType *T) { |
| 1631 | // FIXME: this is pretty unsatisfactory, but there isn't an obvious |
| 1632 | // "extension with parameters" mangling. |
| 1633 | Out << "u6typeof"; |
| 1634 | } |
| 1635 | |
| 1636 | void CXXNameMangler::mangleType(const TypeOfExprType *T) { |
| 1637 | // FIXME: this is pretty unsatisfactory, but there isn't an obvious |
| 1638 | // "extension with parameters" mangling. |
| 1639 | Out << "u6typeof"; |
| 1640 | } |
| 1641 | |
| 1642 | void CXXNameMangler::mangleType(const DecltypeType *T) { |
| 1643 | Expr *E = T->getUnderlyingExpr(); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1644 | |
John McCall | ad5e738 | 2010-03-01 23:49:17 +0000 | [diff] [blame] | 1645 | // type ::= Dt <expression> E # decltype of an id-expression |
| 1646 | // # or class member access |
| 1647 | // ::= DT <expression> E # decltype of an expression |
| 1648 | |
| 1649 | // This purports to be an exhaustive list of id-expressions and |
| 1650 | // class member accesses. Note that we do not ignore parentheses; |
| 1651 | // parentheses change the semantics of decltype for these |
| 1652 | // expressions (and cause the mangler to use the other form). |
| 1653 | if (isa<DeclRefExpr>(E) || |
| 1654 | isa<MemberExpr>(E) || |
| 1655 | isa<UnresolvedLookupExpr>(E) || |
| 1656 | isa<DependentScopeDeclRefExpr>(E) || |
| 1657 | isa<CXXDependentScopeMemberExpr>(E) || |
| 1658 | isa<UnresolvedMemberExpr>(E)) |
| 1659 | Out << "Dt"; |
| 1660 | else |
| 1661 | Out << "DT"; |
| 1662 | mangleExpression(E); |
| 1663 | Out << 'E'; |
| 1664 | } |
| 1665 | |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1666 | void CXXNameMangler::mangleType(const AutoType *T) { |
| 1667 | QualType D = T->getDeducedType(); |
Richard Smith | 967ecd3 | 2011-02-21 20:10:02 +0000 | [diff] [blame] | 1668 | // <builtin-type> ::= Da # dependent auto |
| 1669 | if (D.isNull()) |
| 1670 | Out << "Da"; |
| 1671 | else |
| 1672 | mangleType(D); |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1675 | void CXXNameMangler::mangleIntegerLiteral(QualType T, |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1676 | const llvm::APSInt &Value) { |
| 1677 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 1678 | Out << 'L'; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1679 | |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1680 | mangleType(T); |
| 1681 | if (T->isBooleanType()) { |
| 1682 | // Boolean values are encoded as 0/1. |
| 1683 | Out << (Value.getBoolValue() ? '1' : '0'); |
| 1684 | } else { |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1685 | mangleNumber(Value); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1686 | } |
| 1687 | Out << 'E'; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1688 | |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1691 | /// Mangles a member expression. Implicit accesses are not handled, |
| 1692 | /// but that should be okay, because you shouldn't be able to |
| 1693 | /// make an implicit access in a function template declaration. |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1694 | void CXXNameMangler::mangleMemberExpr(const Expr *Base, |
| 1695 | bool IsArrow, |
| 1696 | NestedNameSpecifier *Qualifier, |
| 1697 | DeclarationName Member, |
| 1698 | unsigned Arity) { |
John McCall | e1e342f | 2010-03-01 19:12:25 +0000 | [diff] [blame] | 1699 | // gcc-4.4 uses 'dt' for dot expressions, which is reasonable. |
| 1700 | // OTOH, gcc also mangles the name as an expression. |
| 1701 | Out << (IsArrow ? "pt" : "dt"); |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1702 | mangleExpression(Base); |
| 1703 | mangleUnresolvedName(Qualifier, Member, Arity); |
| 1704 | } |
| 1705 | |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1706 | void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) { |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1707 | // <expression> ::= <unary operator-name> <expression> |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1708 | // ::= <binary operator-name> <expression> <expression> |
| 1709 | // ::= <trinary operator-name> <expression> <expression> <expression> |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 1710 | // ::= cl <expression>* E # call |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1711 | // ::= cv <type> expression # conversion with one argument |
| 1712 | // ::= cv <type> _ <expression>* E # conversion with a different number of arguments |
Eli Friedman | a7e6845 | 2010-08-22 01:00:03 +0000 | [diff] [blame] | 1713 | // ::= st <type> # sizeof (a type) |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1714 | // ::= at <type> # alignof (a type) |
| 1715 | // ::= <template-param> |
| 1716 | // ::= <function-param> |
| 1717 | // ::= sr <type> <unqualified-name> # dependent name |
| 1718 | // ::= sr <type> <unqualified-name> <template-args> # dependent template-id |
| 1719 | // ::= sZ <template-param> # size of a parameter pack |
Douglas Gregor | 4fc4866 | 2011-01-13 16:39:34 +0000 | [diff] [blame] | 1720 | // ::= sZ <function-param> # size of a function parameter pack |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1721 | // ::= <expr-primary> |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1722 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 1723 | // ::= L <type <value float> E # floating literal |
| 1724 | // ::= L <mangled-name> E # external name |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1725 | switch (E->getStmtClass()) { |
John McCall | 6ae1f35 | 2010-04-09 22:26:14 +0000 | [diff] [blame] | 1726 | case Expr::NoStmtClass: |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 1727 | #define ABSTRACT_STMT(Type) |
John McCall | 6ae1f35 | 2010-04-09 22:26:14 +0000 | [diff] [blame] | 1728 | #define EXPR(Type, Base) |
| 1729 | #define STMT(Type, Base) \ |
| 1730 | case Expr::Type##Class: |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 1731 | #include "clang/AST/StmtNodes.inc" |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1732 | // fallthrough |
| 1733 | |
| 1734 | // These all can only appear in local or variable-initialization |
| 1735 | // contexts and so should never appear in a mangling. |
| 1736 | case Expr::AddrLabelExprClass: |
| 1737 | case Expr::BlockDeclRefExprClass: |
| 1738 | case Expr::CXXThisExprClass: |
| 1739 | case Expr::DesignatedInitExprClass: |
| 1740 | case Expr::ImplicitValueInitExprClass: |
| 1741 | case Expr::InitListExprClass: |
| 1742 | case Expr::ParenListExprClass: |
| 1743 | case Expr::CXXScalarValueInitExprClass: |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1744 | llvm_unreachable("unexpected statement kind"); |
| 1745 | break; |
| 1746 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1747 | // FIXME: invent manglings for all these. |
| 1748 | case Expr::BlockExprClass: |
| 1749 | case Expr::CXXPseudoDestructorExprClass: |
| 1750 | case Expr::ChooseExprClass: |
| 1751 | case Expr::CompoundLiteralExprClass: |
| 1752 | case Expr::ExtVectorElementExprClass: |
Peter Collingbourne | f111d93 | 2011-04-15 00:35:48 +0000 | [diff] [blame] | 1753 | case Expr::GenericSelectionExprClass: |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1754 | case Expr::ObjCEncodeExprClass: |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1755 | case Expr::ObjCIsaExprClass: |
| 1756 | case Expr::ObjCIvarRefExprClass: |
| 1757 | case Expr::ObjCMessageExprClass: |
| 1758 | case Expr::ObjCPropertyRefExprClass: |
| 1759 | case Expr::ObjCProtocolExprClass: |
| 1760 | case Expr::ObjCSelectorExprClass: |
| 1761 | case Expr::ObjCStringLiteralClass: |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1762 | case Expr::OffsetOfExprClass: |
| 1763 | case Expr::PredefinedExprClass: |
| 1764 | case Expr::ShuffleVectorExprClass: |
| 1765 | case Expr::StmtExprClass: |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1766 | case Expr::UnaryTypeTraitExprClass: |
Francois Pichet | 6ad6f28 | 2010-12-07 00:08:36 +0000 | [diff] [blame] | 1767 | case Expr::BinaryTypeTraitExprClass: |
Francois Pichet | 9be8840 | 2010-09-08 23:47:05 +0000 | [diff] [blame] | 1768 | case Expr::VAArgExprClass: |
Sebastian Redl | 2e15622 | 2010-09-10 20:55:43 +0000 | [diff] [blame] | 1769 | case Expr::CXXUuidofExprClass: |
Peter Collingbourne | e08ce65 | 2011-02-09 21:07:24 +0000 | [diff] [blame] | 1770 | case Expr::CXXNoexceptExprClass: |
| 1771 | case Expr::CUDAKernelCallExprClass: { |
John McCall | 6ae1f35 | 2010-04-09 22:26:14 +0000 | [diff] [blame] | 1772 | // As bad as this diagnostic is, it's better than crashing. |
| 1773 | Diagnostic &Diags = Context.getDiags(); |
| 1774 | unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, |
| 1775 | "cannot yet mangle expression type %0"); |
Argyrios Kyrtzidis | 33e4e70 | 2010-11-18 20:06:41 +0000 | [diff] [blame] | 1776 | Diags.Report(E->getExprLoc(), DiagID) |
John McCall | 739bf09 | 2010-04-10 09:39:25 +0000 | [diff] [blame] | 1777 | << E->getStmtClassName() << E->getSourceRange(); |
John McCall | 6ae1f35 | 2010-04-09 22:26:14 +0000 | [diff] [blame] | 1778 | break; |
| 1779 | } |
| 1780 | |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 1781 | // Even gcc-4.5 doesn't mangle this. |
| 1782 | case Expr::BinaryConditionalOperatorClass: { |
| 1783 | Diagnostic &Diags = Context.getDiags(); |
| 1784 | unsigned DiagID = |
| 1785 | Diags.getCustomDiagID(Diagnostic::Error, |
| 1786 | "?: operator with omitted middle operand cannot be mangled"); |
| 1787 | Diags.Report(E->getExprLoc(), DiagID) |
| 1788 | << E->getStmtClassName() << E->getSourceRange(); |
| 1789 | break; |
| 1790 | } |
| 1791 | |
| 1792 | // These are used for internal purposes and cannot be meaningfully mangled. |
John McCall | 7cd7d1a | 2010-11-15 23:31:06 +0000 | [diff] [blame] | 1793 | case Expr::OpaqueValueExprClass: |
| 1794 | llvm_unreachable("cannot mangle opaque value; mangling wrong thing?"); |
| 1795 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1796 | case Expr::CXXDefaultArgExprClass: |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1797 | mangleExpression(cast<CXXDefaultArgExpr>(E)->getExpr(), Arity); |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1798 | break; |
| 1799 | |
| 1800 | case Expr::CXXMemberCallExprClass: // fallthrough |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1801 | case Expr::CallExprClass: { |
| 1802 | const CallExpr *CE = cast<CallExpr>(E); |
| 1803 | Out << "cl"; |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1804 | mangleExpression(CE->getCallee(), CE->getNumArgs()); |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1805 | for (unsigned I = 0, N = CE->getNumArgs(); I != N; ++I) |
| 1806 | mangleExpression(CE->getArg(I)); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1807 | Out << 'E'; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1808 | break; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1809 | } |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1810 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1811 | case Expr::CXXNewExprClass: { |
| 1812 | // Proposal from David Vandervoorde, 2010.06.30 |
| 1813 | const CXXNewExpr *New = cast<CXXNewExpr>(E); |
| 1814 | if (New->isGlobalNew()) Out << "gs"; |
| 1815 | Out << (New->isArray() ? "na" : "nw"); |
| 1816 | for (CXXNewExpr::const_arg_iterator I = New->placement_arg_begin(), |
| 1817 | E = New->placement_arg_end(); I != E; ++I) |
| 1818 | mangleExpression(*I); |
| 1819 | Out << '_'; |
| 1820 | mangleType(New->getAllocatedType()); |
| 1821 | if (New->hasInitializer()) { |
| 1822 | Out << "pi"; |
| 1823 | for (CXXNewExpr::const_arg_iterator I = New->constructor_arg_begin(), |
| 1824 | E = New->constructor_arg_end(); I != E; ++I) |
| 1825 | mangleExpression(*I); |
| 1826 | } |
| 1827 | Out << 'E'; |
| 1828 | break; |
| 1829 | } |
| 1830 | |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1831 | case Expr::MemberExprClass: { |
| 1832 | const MemberExpr *ME = cast<MemberExpr>(E); |
| 1833 | mangleMemberExpr(ME->getBase(), ME->isArrow(), |
| 1834 | ME->getQualifier(), ME->getMemberDecl()->getDeclName(), |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1835 | Arity); |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1836 | break; |
| 1837 | } |
| 1838 | |
| 1839 | case Expr::UnresolvedMemberExprClass: { |
| 1840 | const UnresolvedMemberExpr *ME = cast<UnresolvedMemberExpr>(E); |
| 1841 | mangleMemberExpr(ME->getBase(), ME->isArrow(), |
| 1842 | ME->getQualifier(), ME->getMemberName(), |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1843 | Arity); |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 1844 | if (ME->hasExplicitTemplateArgs()) |
| 1845 | mangleTemplateArgs(ME->getExplicitTemplateArgs()); |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1846 | break; |
| 1847 | } |
| 1848 | |
| 1849 | case Expr::CXXDependentScopeMemberExprClass: { |
| 1850 | const CXXDependentScopeMemberExpr *ME |
| 1851 | = cast<CXXDependentScopeMemberExpr>(E); |
| 1852 | mangleMemberExpr(ME->getBase(), ME->isArrow(), |
| 1853 | ME->getQualifier(), ME->getMember(), |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1854 | Arity); |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 1855 | if (ME->hasExplicitTemplateArgs()) |
| 1856 | mangleTemplateArgs(ME->getExplicitTemplateArgs()); |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1857 | break; |
| 1858 | } |
| 1859 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1860 | case Expr::UnresolvedLookupExprClass: { |
John McCall | a3218e7 | 2010-02-04 01:48:38 +0000 | [diff] [blame] | 1861 | // The ABI doesn't cover how to mangle overload sets, so we mangle |
| 1862 | // using something as close as possible to the original lookup |
| 1863 | // expression. |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1864 | const UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(E); |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1865 | mangleUnresolvedName(ULE->getQualifier(), ULE->getName(), Arity); |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 1866 | if (ULE->hasExplicitTemplateArgs()) |
| 1867 | mangleTemplateArgs(ULE->getExplicitTemplateArgs()); |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1868 | break; |
| 1869 | } |
| 1870 | |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1871 | case Expr::CXXUnresolvedConstructExprClass: { |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1872 | const CXXUnresolvedConstructExpr *CE = cast<CXXUnresolvedConstructExpr>(E); |
| 1873 | unsigned N = CE->arg_size(); |
| 1874 | |
| 1875 | Out << "cv"; |
| 1876 | mangleType(CE->getType()); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1877 | if (N != 1) Out << '_'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1878 | for (unsigned I = 0; I != N; ++I) mangleExpression(CE->getArg(I)); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1879 | if (N != 1) Out << 'E'; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1880 | break; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1881 | } |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1882 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1883 | case Expr::CXXTemporaryObjectExprClass: |
| 1884 | case Expr::CXXConstructExprClass: { |
| 1885 | const CXXConstructExpr *CE = cast<CXXConstructExpr>(E); |
| 1886 | unsigned N = CE->getNumArgs(); |
| 1887 | |
| 1888 | Out << "cv"; |
| 1889 | mangleType(CE->getType()); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1890 | if (N != 1) Out << '_'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1891 | for (unsigned I = 0; I != N; ++I) mangleExpression(CE->getArg(I)); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1892 | if (N != 1) Out << 'E'; |
John McCall | 09cc141 | 2010-02-03 00:55:45 +0000 | [diff] [blame] | 1893 | break; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Peter Collingbourne | f4e3cfb | 2011-03-11 19:24:49 +0000 | [diff] [blame] | 1896 | case Expr::UnaryExprOrTypeTraitExprClass: { |
| 1897 | const UnaryExprOrTypeTraitExpr *SAE = cast<UnaryExprOrTypeTraitExpr>(E); |
| 1898 | switch(SAE->getKind()) { |
| 1899 | case UETT_SizeOf: |
| 1900 | Out << 's'; |
| 1901 | break; |
| 1902 | case UETT_AlignOf: |
| 1903 | Out << 'a'; |
| 1904 | break; |
| 1905 | case UETT_VecStep: |
| 1906 | Diagnostic &Diags = Context.getDiags(); |
| 1907 | unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, |
| 1908 | "cannot yet mangle vec_step expression"); |
| 1909 | Diags.Report(DiagID); |
| 1910 | return; |
| 1911 | } |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1912 | if (SAE->isArgumentType()) { |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1913 | Out << 't'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1914 | mangleType(SAE->getArgumentType()); |
| 1915 | } else { |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 1916 | Out << 'z'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 1917 | mangleExpression(SAE->getArgumentExpr()); |
| 1918 | } |
| 1919 | break; |
| 1920 | } |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 1921 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1922 | case Expr::CXXThrowExprClass: { |
| 1923 | const CXXThrowExpr *TE = cast<CXXThrowExpr>(E); |
| 1924 | |
| 1925 | // Proposal from David Vandervoorde, 2010.06.30 |
| 1926 | if (TE->getSubExpr()) { |
| 1927 | Out << "tw"; |
| 1928 | mangleExpression(TE->getSubExpr()); |
| 1929 | } else { |
| 1930 | Out << "tr"; |
| 1931 | } |
| 1932 | break; |
| 1933 | } |
| 1934 | |
| 1935 | case Expr::CXXTypeidExprClass: { |
| 1936 | const CXXTypeidExpr *TIE = cast<CXXTypeidExpr>(E); |
| 1937 | |
| 1938 | // Proposal from David Vandervoorde, 2010.06.30 |
| 1939 | if (TIE->isTypeOperand()) { |
| 1940 | Out << "ti"; |
| 1941 | mangleType(TIE->getTypeOperand()); |
| 1942 | } else { |
| 1943 | Out << "te"; |
| 1944 | mangleExpression(TIE->getExprOperand()); |
| 1945 | } |
| 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | case Expr::CXXDeleteExprClass: { |
| 1950 | const CXXDeleteExpr *DE = cast<CXXDeleteExpr>(E); |
| 1951 | |
| 1952 | // Proposal from David Vandervoorde, 2010.06.30 |
| 1953 | if (DE->isGlobalDelete()) Out << "gs"; |
| 1954 | Out << (DE->isArrayForm() ? "da" : "dl"); |
| 1955 | mangleExpression(DE->getArgument()); |
| 1956 | break; |
| 1957 | } |
| 1958 | |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1959 | case Expr::UnaryOperatorClass: { |
| 1960 | const UnaryOperator *UO = cast<UnaryOperator>(E); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1961 | mangleOperatorName(UnaryOperator::getOverloadedOperator(UO->getOpcode()), |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1962 | /*Arity=*/1); |
| 1963 | mangleExpression(UO->getSubExpr()); |
| 1964 | break; |
| 1965 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1966 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1967 | case Expr::ArraySubscriptExprClass: { |
| 1968 | const ArraySubscriptExpr *AE = cast<ArraySubscriptExpr>(E); |
| 1969 | |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame^] | 1970 | // Array subscript is treated as a syntactically weird form of |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 1971 | // binary operator. |
| 1972 | Out << "ix"; |
| 1973 | mangleExpression(AE->getLHS()); |
| 1974 | mangleExpression(AE->getRHS()); |
| 1975 | break; |
| 1976 | } |
| 1977 | |
| 1978 | case Expr::CompoundAssignOperatorClass: // fallthrough |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1979 | case Expr::BinaryOperatorClass: { |
| 1980 | const BinaryOperator *BO = cast<BinaryOperator>(E); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1981 | mangleOperatorName(BinaryOperator::getOverloadedOperator(BO->getOpcode()), |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1982 | /*Arity=*/2); |
| 1983 | mangleExpression(BO->getLHS()); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 1984 | mangleExpression(BO->getRHS()); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1985 | break; |
John McCall | 2f27bf8 | 2010-02-04 02:56:29 +0000 | [diff] [blame] | 1986 | } |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1987 | |
| 1988 | case Expr::ConditionalOperatorClass: { |
| 1989 | const ConditionalOperator *CO = cast<ConditionalOperator>(E); |
| 1990 | mangleOperatorName(OO_Conditional, /*Arity=*/3); |
| 1991 | mangleExpression(CO->getCond()); |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1992 | mangleExpression(CO->getLHS(), Arity); |
| 1993 | mangleExpression(CO->getRHS(), Arity); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 1994 | break; |
| 1995 | } |
| 1996 | |
Douglas Gregor | 46287c7 | 2010-01-29 16:37:09 +0000 | [diff] [blame] | 1997 | case Expr::ImplicitCastExprClass: { |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 1998 | mangleExpression(cast<ImplicitCastExpr>(E)->getSubExpr(), Arity); |
Douglas Gregor | 46287c7 | 2010-01-29 16:37:09 +0000 | [diff] [blame] | 1999 | break; |
| 2000 | } |
| 2001 | |
| 2002 | case Expr::CStyleCastExprClass: |
| 2003 | case Expr::CXXStaticCastExprClass: |
| 2004 | case Expr::CXXDynamicCastExprClass: |
| 2005 | case Expr::CXXReinterpretCastExprClass: |
| 2006 | case Expr::CXXConstCastExprClass: |
| 2007 | case Expr::CXXFunctionalCastExprClass: { |
| 2008 | const ExplicitCastExpr *ECE = cast<ExplicitCastExpr>(E); |
| 2009 | Out << "cv"; |
| 2010 | mangleType(ECE->getType()); |
| 2011 | mangleExpression(ECE->getSubExpr()); |
| 2012 | break; |
| 2013 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2014 | |
Anders Carlsson | 58040a5 | 2009-12-16 05:48:46 +0000 | [diff] [blame] | 2015 | case Expr::CXXOperatorCallExprClass: { |
| 2016 | const CXXOperatorCallExpr *CE = cast<CXXOperatorCallExpr>(E); |
| 2017 | unsigned NumArgs = CE->getNumArgs(); |
| 2018 | mangleOperatorName(CE->getOperator(), /*Arity=*/NumArgs); |
| 2019 | // Mangle the arguments. |
| 2020 | for (unsigned i = 0; i != NumArgs; ++i) |
| 2021 | mangleExpression(CE->getArg(i)); |
| 2022 | break; |
| 2023 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2024 | |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 2025 | case Expr::ParenExprClass: |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 2026 | mangleExpression(cast<ParenExpr>(E)->getSubExpr(), Arity); |
Anders Carlsson | a769408 | 2009-11-06 02:50:19 +0000 | [diff] [blame] | 2027 | break; |
| 2028 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2029 | case Expr::DeclRefExprClass: { |
Douglas Gregor | 5ed1bc3 | 2010-02-28 21:40:32 +0000 | [diff] [blame] | 2030 | const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl(); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2031 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2032 | switch (D->getKind()) { |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2033 | default: |
Douglas Gregor | 5ed1bc3 | 2010-02-28 21:40:32 +0000 | [diff] [blame] | 2034 | // <expr-primary> ::= L <mangled-name> E # external name |
| 2035 | Out << 'L'; |
| 2036 | mangle(D, "_Z"); |
| 2037 | Out << 'E'; |
| 2038 | break; |
| 2039 | |
John McCall | 3dc7e7b | 2010-07-24 01:17:35 +0000 | [diff] [blame] | 2040 | case Decl::EnumConstant: { |
| 2041 | const EnumConstantDecl *ED = cast<EnumConstantDecl>(D); |
| 2042 | mangleIntegerLiteral(ED->getType(), ED->getInitVal()); |
| 2043 | break; |
| 2044 | } |
| 2045 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2046 | case Decl::NonTypeTemplateParm: { |
| 2047 | const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D); |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 2048 | mangleTemplateParameter(PD->getIndex()); |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2053 | |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 2054 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2055 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2056 | |
Douglas Gregor | c7793c7 | 2011-01-15 01:15:58 +0000 | [diff] [blame] | 2057 | case Expr::SubstNonTypeTemplateParmPackExprClass: |
| 2058 | mangleTemplateParameter( |
| 2059 | cast<SubstNonTypeTemplateParmPackExpr>(E)->getParameterPack()->getIndex()); |
| 2060 | break; |
| 2061 | |
John McCall | 865d447 | 2009-11-19 22:55:06 +0000 | [diff] [blame] | 2062 | case Expr::DependentScopeDeclRefExprClass: { |
| 2063 | const DependentScopeDeclRefExpr *DRE = cast<DependentScopeDeclRefExpr>(E); |
Douglas Gregor | 4b2ccfc | 2010-02-28 22:05:49 +0000 | [diff] [blame] | 2064 | NestedNameSpecifier *NNS = DRE->getQualifier(); |
| 2065 | const Type *QTy = NNS->getAsType(); |
| 2066 | |
| 2067 | // When we're dealing with a nested-name-specifier that has just a |
| 2068 | // dependent identifier in it, mangle that as a typename. FIXME: |
| 2069 | // It isn't clear that we ever actually want to have such a |
| 2070 | // nested-name-specifier; why not just represent it as a typename type? |
| 2071 | if (!QTy && NNS->getAsIdentifier() && NNS->getPrefix()) { |
Douglas Gregor | 4a2023f | 2010-03-31 20:19:30 +0000 | [diff] [blame] | 2072 | QTy = getASTContext().getDependentNameType(ETK_Typename, |
| 2073 | NNS->getPrefix(), |
| 2074 | NNS->getAsIdentifier()) |
Douglas Gregor | 4b2ccfc | 2010-02-28 22:05:49 +0000 | [diff] [blame] | 2075 | .getTypePtr(); |
| 2076 | } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 2077 | assert(QTy && "Qualifier was not type!"); |
| 2078 | |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 2079 | // ::= sr <type> <unqualified-name> # dependent name |
| 2080 | // ::= sr <type> <unqualified-name> <template-args> # dependent template-id |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 2081 | Out << "sr"; |
| 2082 | mangleType(QualType(QTy, 0)); |
John McCall | 5e1e89b | 2010-08-18 19:18:59 +0000 | [diff] [blame] | 2083 | mangleUnqualifiedName(0, DRE->getDeclName(), Arity); |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 2084 | if (DRE->hasExplicitTemplateArgs()) |
| 2085 | mangleTemplateArgs(DRE->getExplicitTemplateArgs()); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2086 | |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 2087 | break; |
| 2088 | } |
| 2089 | |
John McCall | d930760 | 2010-04-09 22:54:09 +0000 | [diff] [blame] | 2090 | case Expr::CXXBindTemporaryExprClass: |
| 2091 | mangleExpression(cast<CXXBindTemporaryExpr>(E)->getSubExpr()); |
| 2092 | break; |
| 2093 | |
John McCall | 4765fa0 | 2010-12-06 08:20:24 +0000 | [diff] [blame] | 2094 | case Expr::ExprWithCleanupsClass: |
| 2095 | mangleExpression(cast<ExprWithCleanups>(E)->getSubExpr(), Arity); |
John McCall | d930760 | 2010-04-09 22:54:09 +0000 | [diff] [blame] | 2096 | break; |
| 2097 | |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 2098 | case Expr::FloatingLiteralClass: { |
| 2099 | const FloatingLiteral *FL = cast<FloatingLiteral>(E); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2100 | Out << 'L'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 2101 | mangleType(FL->getType()); |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2102 | mangleFloat(FL->getValue()); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2103 | Out << 'E'; |
John McCall | 1dd7383 | 2010-02-04 01:42:13 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | } |
| 2106 | |
John McCall | de81063 | 2010-04-09 21:48:08 +0000 | [diff] [blame] | 2107 | case Expr::CharacterLiteralClass: |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2108 | Out << 'L'; |
John McCall | de81063 | 2010-04-09 21:48:08 +0000 | [diff] [blame] | 2109 | mangleType(E->getType()); |
| 2110 | Out << cast<CharacterLiteral>(E)->getValue(); |
| 2111 | Out << 'E'; |
| 2112 | break; |
| 2113 | |
| 2114 | case Expr::CXXBoolLiteralExprClass: |
| 2115 | Out << "Lb"; |
| 2116 | Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ? '1' : '0'); |
| 2117 | Out << 'E'; |
| 2118 | break; |
| 2119 | |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2120 | case Expr::IntegerLiteralClass: { |
| 2121 | llvm::APSInt Value(cast<IntegerLiteral>(E)->getValue()); |
| 2122 | if (E->getType()->isSignedIntegerType()) |
| 2123 | Value.setIsSigned(true); |
| 2124 | mangleIntegerLiteral(E->getType(), Value); |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 2125 | break; |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | case Expr::ImaginaryLiteralClass: { |
| 2129 | const ImaginaryLiteral *IE = cast<ImaginaryLiteral>(E); |
| 2130 | // Mangle as if a complex literal. |
Nick Lewycky | 271b665 | 2010-09-05 03:40:33 +0000 | [diff] [blame] | 2131 | // Proposal from David Vandevoorde, 2010.06.30. |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2132 | Out << 'L'; |
| 2133 | mangleType(E->getType()); |
| 2134 | if (const FloatingLiteral *Imag = |
| 2135 | dyn_cast<FloatingLiteral>(IE->getSubExpr())) { |
| 2136 | // Mangle a floating-point zero of the appropriate type. |
| 2137 | mangleFloat(llvm::APFloat(Imag->getValue().getSemantics())); |
| 2138 | Out << '_'; |
| 2139 | mangleFloat(Imag->getValue()); |
| 2140 | } else { |
Nick Lewycky | 271b665 | 2010-09-05 03:40:33 +0000 | [diff] [blame] | 2141 | Out << "0_"; |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2142 | llvm::APSInt Value(cast<IntegerLiteral>(IE->getSubExpr())->getValue()); |
| 2143 | if (IE->getSubExpr()->getType()->isSignedIntegerType()) |
| 2144 | Value.setIsSigned(true); |
| 2145 | mangleNumber(Value); |
| 2146 | } |
| 2147 | Out << 'E'; |
| 2148 | break; |
| 2149 | } |
| 2150 | |
| 2151 | case Expr::StringLiteralClass: { |
John McCall | 1658c39 | 2010-07-15 21:53:03 +0000 | [diff] [blame] | 2152 | // Revised proposal from David Vandervoorde, 2010.07.15. |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2153 | Out << 'L'; |
John McCall | 1658c39 | 2010-07-15 21:53:03 +0000 | [diff] [blame] | 2154 | assert(isa<ConstantArrayType>(E->getType())); |
| 2155 | mangleType(E->getType()); |
John McCall | 0512e48 | 2010-07-14 04:20:34 +0000 | [diff] [blame] | 2156 | Out << 'E'; |
| 2157 | break; |
| 2158 | } |
| 2159 | |
| 2160 | case Expr::GNUNullExprClass: |
| 2161 | // FIXME: should this really be mangled the same as nullptr? |
| 2162 | // fallthrough |
| 2163 | |
| 2164 | case Expr::CXXNullPtrLiteralExprClass: { |
| 2165 | // Proposal from David Vandervoorde, 2010.06.30, as |
| 2166 | // modified by ABI list discussion. |
| 2167 | Out << "LDnE"; |
| 2168 | break; |
| 2169 | } |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 2170 | |
| 2171 | case Expr::PackExpansionExprClass: |
| 2172 | Out << "sp"; |
| 2173 | mangleExpression(cast<PackExpansionExpr>(E)->getPattern()); |
| 2174 | break; |
Douglas Gregor | 2e774c4 | 2011-01-04 18:56:13 +0000 | [diff] [blame] | 2175 | |
| 2176 | case Expr::SizeOfPackExprClass: { |
Douglas Gregor | 2e774c4 | 2011-01-04 18:56:13 +0000 | [diff] [blame] | 2177 | Out << "sZ"; |
| 2178 | const NamedDecl *Pack = cast<SizeOfPackExpr>(E)->getPack(); |
| 2179 | if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack)) |
| 2180 | mangleTemplateParameter(TTP->getIndex()); |
| 2181 | else if (const NonTypeTemplateParmDecl *NTTP |
| 2182 | = dyn_cast<NonTypeTemplateParmDecl>(Pack)) |
| 2183 | mangleTemplateParameter(NTTP->getIndex()); |
| 2184 | else if (const TemplateTemplateParmDecl *TempTP |
| 2185 | = dyn_cast<TemplateTemplateParmDecl>(Pack)) |
| 2186 | mangleTemplateParameter(TempTP->getIndex()); |
| 2187 | else { |
Douglas Gregor | 4fc4866 | 2011-01-13 16:39:34 +0000 | [diff] [blame] | 2188 | // Note: proposed by Mike Herrick on 11/30/10 |
| 2189 | // <expression> ::= sZ <function-param> # size of function parameter pack |
Douglas Gregor | 2e774c4 | 2011-01-04 18:56:13 +0000 | [diff] [blame] | 2190 | Diagnostic &Diags = Context.getDiags(); |
| 2191 | unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error, |
| 2192 | "cannot mangle sizeof...(function parameter pack)"); |
| 2193 | Diags.Report(DiagID); |
| 2194 | return; |
| 2195 | } |
Douglas Gregor | dfbbcf9 | 2011-03-03 02:20:19 +0000 | [diff] [blame] | 2196 | break; |
Douglas Gregor | 2e774c4 | 2011-01-04 18:56:13 +0000 | [diff] [blame] | 2197 | } |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2198 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 2201 | void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) { |
| 2202 | // <ctor-dtor-name> ::= C1 # complete object constructor |
| 2203 | // ::= C2 # base object constructor |
| 2204 | // ::= C3 # complete object allocating constructor |
| 2205 | // |
| 2206 | switch (T) { |
| 2207 | case Ctor_Complete: |
| 2208 | Out << "C1"; |
| 2209 | break; |
| 2210 | case Ctor_Base: |
| 2211 | Out << "C2"; |
| 2212 | break; |
| 2213 | case Ctor_CompleteAllocating: |
| 2214 | Out << "C3"; |
| 2215 | break; |
| 2216 | } |
| 2217 | } |
| 2218 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 2219 | void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) { |
| 2220 | // <ctor-dtor-name> ::= D0 # deleting destructor |
| 2221 | // ::= D1 # complete object destructor |
| 2222 | // ::= D2 # base object destructor |
| 2223 | // |
| 2224 | switch (T) { |
| 2225 | case Dtor_Deleting: |
| 2226 | Out << "D0"; |
| 2227 | break; |
| 2228 | case Dtor_Complete: |
| 2229 | Out << "D1"; |
| 2230 | break; |
| 2231 | case Dtor_Base: |
| 2232 | Out << "D2"; |
| 2233 | break; |
| 2234 | } |
| 2235 | } |
| 2236 | |
John McCall | 6dbce19 | 2010-08-20 00:17:19 +0000 | [diff] [blame] | 2237 | void CXXNameMangler::mangleTemplateArgs( |
| 2238 | const ExplicitTemplateArgumentList &TemplateArgs) { |
| 2239 | // <template-args> ::= I <template-arg>+ E |
| 2240 | Out << 'I'; |
| 2241 | for (unsigned I = 0, E = TemplateArgs.NumTemplateArgs; I != E; ++I) |
| 2242 | mangleTemplateArg(0, TemplateArgs.getTemplateArgs()[I].getArgument()); |
| 2243 | Out << 'E'; |
| 2244 | } |
| 2245 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 2246 | void CXXNameMangler::mangleTemplateArgs(TemplateName Template, |
| 2247 | const TemplateArgument *TemplateArgs, |
| 2248 | unsigned NumTemplateArgs) { |
| 2249 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
| 2250 | return mangleTemplateArgs(*TD->getTemplateParameters(), TemplateArgs, |
| 2251 | NumTemplateArgs); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2252 | |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 2253 | // <template-args> ::= I <template-arg>+ E |
| 2254 | Out << 'I'; |
| 2255 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 2256 | mangleTemplateArg(0, TemplateArgs[i]); |
| 2257 | Out << 'E'; |
| 2258 | } |
| 2259 | |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2260 | void CXXNameMangler::mangleTemplateArgs(const TemplateParameterList &PL, |
| 2261 | const TemplateArgumentList &AL) { |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2262 | // <template-args> ::= I <template-arg>+ E |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2263 | Out << 'I'; |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2264 | for (unsigned i = 0, e = AL.size(); i != e; ++i) |
| 2265 | mangleTemplateArg(PL.getParam(i), AL[i]); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2266 | Out << 'E'; |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2269 | void CXXNameMangler::mangleTemplateArgs(const TemplateParameterList &PL, |
| 2270 | const TemplateArgument *TemplateArgs, |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 2271 | unsigned NumTemplateArgs) { |
| 2272 | // <template-args> ::= I <template-arg>+ E |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2273 | Out << 'I'; |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2274 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2275 | mangleTemplateArg(PL.getParam(i), TemplateArgs[i]); |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2276 | Out << 'E'; |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 2277 | } |
| 2278 | |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2279 | void CXXNameMangler::mangleTemplateArg(const NamedDecl *P, |
| 2280 | const TemplateArgument &A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2281 | // <template-arg> ::= <type> # type or template |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2282 | // ::= X <expression> E # expression |
| 2283 | // ::= <expr-primary> # simple expressions |
Douglas Gregor | 4fc4866 | 2011-01-13 16:39:34 +0000 | [diff] [blame] | 2284 | // ::= J <template-arg>* E # argument pack |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2285 | // ::= sp <expression> # pack expansion of (C++0x) |
| 2286 | switch (A.getKind()) { |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 2287 | case TemplateArgument::Null: |
| 2288 | llvm_unreachable("Cannot mangle NULL template argument"); |
| 2289 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2290 | case TemplateArgument::Type: |
| 2291 | mangleType(A.getAsType()); |
| 2292 | break; |
Anders Carlsson | 9e85c74 | 2009-12-23 19:30:55 +0000 | [diff] [blame] | 2293 | case TemplateArgument::Template: |
John McCall | b6f532e | 2010-07-14 06:43:17 +0000 | [diff] [blame] | 2294 | // This is mangled as <type>. |
| 2295 | mangleType(A.getAsTemplate()); |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2296 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2297 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 4fc4866 | 2011-01-13 16:39:34 +0000 | [diff] [blame] | 2298 | // <type> ::= Dp <type> # pack expansion (C++0x) |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 2299 | Out << "Dp"; |
| 2300 | mangleType(A.getAsTemplateOrTemplatePattern()); |
| 2301 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 2302 | case TemplateArgument::Expression: |
| 2303 | Out << 'X'; |
| 2304 | mangleExpression(A.getAsExpr()); |
| 2305 | Out << 'E'; |
| 2306 | break; |
Anders Carlsson | e170ba7 | 2009-12-14 01:45:37 +0000 | [diff] [blame] | 2307 | case TemplateArgument::Integral: |
| 2308 | mangleIntegerLiteral(A.getIntegralType(), *A.getAsIntegral()); |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2309 | break; |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2310 | case TemplateArgument::Declaration: { |
Douglas Gregor | 20f0cc7 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 2311 | assert(P && "Missing template parameter for declaration argument"); |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2312 | // <expr-primary> ::= L <mangled-name> E # external name |
| 2313 | |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2314 | // Clang produces AST's where pointer-to-member-function expressions |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2315 | // and pointer-to-function expressions are represented as a declaration not |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2316 | // an expression. We compensate for it here to produce the correct mangling. |
| 2317 | NamedDecl *D = cast<NamedDecl>(A.getAsDecl()); |
| 2318 | const NonTypeTemplateParmDecl *Parameter = cast<NonTypeTemplateParmDecl>(P); |
| 2319 | bool compensateMangling = D->isCXXClassMember() && |
| 2320 | !Parameter->getType()->isReferenceType(); |
| 2321 | if (compensateMangling) { |
| 2322 | Out << 'X'; |
| 2323 | mangleOperatorName(OO_Amp, 1); |
| 2324 | } |
| 2325 | |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2326 | Out << 'L'; |
| 2327 | // References to external entities use the mangled name; if the name would |
| 2328 | // not normally be manged then mangle it as unqualified. |
| 2329 | // |
| 2330 | // FIXME: The ABI specifies that external names here should have _Z, but |
| 2331 | // gcc leaves this off. |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2332 | if (compensateMangling) |
| 2333 | mangle(D, "_Z"); |
| 2334 | else |
| 2335 | mangle(D, "Z"); |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2336 | Out << 'E'; |
Rafael Espindola | d980072 | 2010-03-11 14:07:00 +0000 | [diff] [blame] | 2337 | |
| 2338 | if (compensateMangling) |
| 2339 | Out << 'E'; |
| 2340 | |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2341 | break; |
| 2342 | } |
Douglas Gregor | f90b27a | 2011-01-03 22:36:02 +0000 | [diff] [blame] | 2343 | |
| 2344 | case TemplateArgument::Pack: { |
| 2345 | // Note: proposal by Mike Herrick on 12/20/10 |
| 2346 | Out << 'J'; |
| 2347 | for (TemplateArgument::pack_iterator PA = A.pack_begin(), |
| 2348 | PAEnd = A.pack_end(); |
| 2349 | PA != PAEnd; ++PA) |
| 2350 | mangleTemplateArg(P, *PA); |
| 2351 | Out << 'E'; |
| 2352 | } |
Daniel Dunbar | 7e0c195 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2353 | } |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 2356 | void CXXNameMangler::mangleTemplateParameter(unsigned Index) { |
| 2357 | // <template-param> ::= T_ # first template parameter |
| 2358 | // ::= T <parameter-2 non-negative number> _ |
| 2359 | if (Index == 0) |
| 2360 | Out << "T_"; |
| 2361 | else |
| 2362 | Out << 'T' << (Index - 1) << '_'; |
| 2363 | } |
| 2364 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2365 | // <substitution> ::= S <seq-id> _ |
| 2366 | // ::= S_ |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 2367 | bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) { |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 2368 | // Try one of the standard substitutions first. |
| 2369 | if (mangleStandardSubstitution(ND)) |
| 2370 | return true; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2371 | |
Anders Carlsson | 433d137 | 2009-11-07 04:26:04 +0000 | [diff] [blame] | 2372 | ND = cast<NamedDecl>(ND->getCanonicalDecl()); |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 2373 | return mangleSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 2374 | } |
| 2375 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2376 | bool CXXNameMangler::mangleSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 2377 | if (!T.getCVRQualifiers()) { |
| 2378 | if (const RecordType *RT = T->getAs<RecordType>()) |
| 2379 | return mangleSubstitution(RT->getDecl()); |
| 2380 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2381 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2382 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
| 2383 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 2384 | return mangleSubstitution(TypePtr); |
| 2385 | } |
| 2386 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 2387 | bool CXXNameMangler::mangleSubstitution(TemplateName Template) { |
| 2388 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
| 2389 | return mangleSubstitution(TD); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2390 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 2391 | Template = Context.getASTContext().getCanonicalTemplateName(Template); |
| 2392 | return mangleSubstitution( |
| 2393 | reinterpret_cast<uintptr_t>(Template.getAsVoidPointer())); |
| 2394 | } |
| 2395 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 2396 | bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) { |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2397 | llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2398 | if (I == Substitutions.end()) |
| 2399 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2400 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2401 | unsigned SeqID = I->second; |
| 2402 | if (SeqID == 0) |
| 2403 | Out << "S_"; |
| 2404 | else { |
| 2405 | SeqID--; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2406 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2407 | // <seq-id> is encoded in base-36, using digits and upper case letters. |
| 2408 | char Buffer[10]; |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2409 | char *BufferPtr = llvm::array_endof(Buffer); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2410 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2411 | if (SeqID == 0) *--BufferPtr = '0'; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2412 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2413 | while (SeqID) { |
| 2414 | assert(BufferPtr > Buffer && "Buffer overflow!"); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2415 | |
John McCall | 6ab30e0 | 2010-06-09 07:26:17 +0000 | [diff] [blame] | 2416 | char c = static_cast<char>(SeqID % 36); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2417 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2418 | *--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10); |
| 2419 | SeqID /= 36; |
| 2420 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2421 | |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2422 | Out << 'S' |
| 2423 | << llvm::StringRef(BufferPtr, llvm::array_endof(Buffer)-BufferPtr) |
| 2424 | << '_'; |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2425 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2426 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2427 | return true; |
| 2428 | } |
| 2429 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2430 | static bool isCharType(QualType T) { |
| 2431 | if (T.isNull()) |
| 2432 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2433 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2434 | return T->isSpecificBuiltinType(BuiltinType::Char_S) || |
| 2435 | T->isSpecificBuiltinType(BuiltinType::Char_U); |
| 2436 | } |
| 2437 | |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2438 | /// isCharSpecialization - Returns whether a given type is a template |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2439 | /// specialization of a given name with a single argument of type char. |
| 2440 | static bool isCharSpecialization(QualType T, const char *Name) { |
| 2441 | if (T.isNull()) |
| 2442 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2443 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2444 | const RecordType *RT = T->getAs<RecordType>(); |
| 2445 | if (!RT) |
| 2446 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2447 | |
| 2448 | const ClassTemplateSpecializationDecl *SD = |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2449 | dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()); |
| 2450 | if (!SD) |
| 2451 | return false; |
| 2452 | |
| 2453 | if (!isStdNamespace(SD->getDeclContext())) |
| 2454 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2455 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2456 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 2457 | if (TemplateArgs.size() != 1) |
| 2458 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2459 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2460 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 2461 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2462 | |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 2463 | return SD->getIdentifier()->getName() == Name; |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2464 | } |
| 2465 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2466 | template <std::size_t StrLen> |
Benjamin Kramer | 54353f4 | 2010-11-25 18:29:30 +0000 | [diff] [blame] | 2467 | static bool isStreamCharSpecialization(const ClassTemplateSpecializationDecl*SD, |
| 2468 | const char (&Str)[StrLen]) { |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2469 | if (!SD->getIdentifier()->isStr(Str)) |
| 2470 | return false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2471 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2472 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 2473 | if (TemplateArgs.size() != 2) |
| 2474 | return false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2475 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2476 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 2477 | return false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2478 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2479 | if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits")) |
| 2480 | return false; |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2481 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2482 | return true; |
| 2483 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2484 | |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 2485 | bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) { |
| 2486 | // <substitution> ::= St # ::std:: |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 2487 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
Anders Carlsson | 47846d2 | 2009-12-04 06:23:23 +0000 | [diff] [blame] | 2488 | if (isStd(NS)) { |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 2489 | Out << "St"; |
| 2490 | return true; |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) { |
| 2495 | if (!isStdNamespace(TD->getDeclContext())) |
| 2496 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2497 | |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 2498 | // <substitution> ::= Sa # ::std::allocator |
| 2499 | if (TD->getIdentifier()->isStr("allocator")) { |
| 2500 | Out << "Sa"; |
| 2501 | return true; |
| 2502 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2503 | |
Anders Carlsson | 189d59c | 2009-09-26 23:14:39 +0000 | [diff] [blame] | 2504 | // <<substitution> ::= Sb # ::std::basic_string |
| 2505 | if (TD->getIdentifier()->isStr("basic_string")) { |
| 2506 | Out << "Sb"; |
| 2507 | return true; |
| 2508 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 2509 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2510 | |
| 2511 | if (const ClassTemplateSpecializationDecl *SD = |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2512 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
Eli Friedman | 5370ee2 | 2010-02-23 18:25:09 +0000 | [diff] [blame] | 2513 | if (!isStdNamespace(SD->getDeclContext())) |
| 2514 | return false; |
| 2515 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2516 | // <substitution> ::= Ss # ::std::basic_string<char, |
| 2517 | // ::std::char_traits<char>, |
| 2518 | // ::std::allocator<char> > |
| 2519 | if (SD->getIdentifier()->isStr("basic_string")) { |
| 2520 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2521 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2522 | if (TemplateArgs.size() != 3) |
| 2523 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2524 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2525 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 2526 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2527 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2528 | if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits")) |
| 2529 | return false; |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2530 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2531 | if (!isCharSpecialization(TemplateArgs[2].getAsType(), "allocator")) |
| 2532 | return false; |
| 2533 | |
| 2534 | Out << "Ss"; |
| 2535 | return true; |
| 2536 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2537 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2538 | // <substitution> ::= Si # ::std::basic_istream<char, |
| 2539 | // ::std::char_traits<char> > |
| 2540 | if (isStreamCharSpecialization(SD, "basic_istream")) { |
| 2541 | Out << "Si"; |
| 2542 | return true; |
| 2543 | } |
| 2544 | |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2545 | // <substitution> ::= So # ::std::basic_ostream<char, |
Anders Carlsson | 8f8fd8e | 2009-10-08 17:20:26 +0000 | [diff] [blame] | 2546 | // ::std::char_traits<char> > |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2547 | if (isStreamCharSpecialization(SD, "basic_ostream")) { |
Anders Carlsson | 8f8fd8e | 2009-10-08 17:20:26 +0000 | [diff] [blame] | 2548 | Out << "So"; |
| 2549 | return true; |
| 2550 | } |
Kovarththanan Rajaratnam | 1935754 | 2010-03-13 10:17:05 +0000 | [diff] [blame] | 2551 | |
Anders Carlsson | 91f8860 | 2009-12-07 19:56:42 +0000 | [diff] [blame] | 2552 | // <substitution> ::= Sd # ::std::basic_iostream<char, |
| 2553 | // ::std::char_traits<char> > |
| 2554 | if (isStreamCharSpecialization(SD, "basic_iostream")) { |
| 2555 | Out << "Sd"; |
| 2556 | return true; |
| 2557 | } |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 2558 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 2559 | return false; |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2562 | void CXXNameMangler::addSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 2563 | if (!T.getCVRQualifiers()) { |
| 2564 | if (const RecordType *RT = T->getAs<RecordType>()) { |
| 2565 | addSubstitution(RT->getDecl()); |
| 2566 | return; |
| 2567 | } |
| 2568 | } |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2569 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2570 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 2571 | addSubstitution(TypePtr); |
| 2572 | } |
| 2573 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 2574 | void CXXNameMangler::addSubstitution(TemplateName Template) { |
| 2575 | if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
| 2576 | return addSubstitution(TD); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2577 | |
Douglas Gregor | 1e9268e | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 2578 | Template = Context.getASTContext().getCanonicalTemplateName(Template); |
| 2579 | addSubstitution(reinterpret_cast<uintptr_t>(Template.getAsVoidPointer())); |
| 2580 | } |
| 2581 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 2582 | void CXXNameMangler::addSubstitution(uintptr_t Ptr) { |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 2583 | assert(!Substitutions.count(Ptr) && "Substitution already exists!"); |
Anders Carlsson | 9d85b72 | 2010-06-02 04:29:50 +0000 | [diff] [blame] | 2584 | Substitutions[Ptr] = SeqID++; |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 2585 | } |
| 2586 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2587 | // |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2588 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2589 | /// \brief Mangles the name of the declaration D and emits that name to the |
| 2590 | /// given output stream. |
| 2591 | /// |
| 2592 | /// If the declaration D requires a mangled name, this routine will emit that |
| 2593 | /// mangled name to \p os and return true. Otherwise, \p os will be unchanged |
| 2594 | /// and this routine will return false. In this case, the caller should just |
| 2595 | /// emit the identifier of the declaration (\c D->getIdentifier()) as its |
| 2596 | /// name. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2597 | void ItaniumMangleContext::mangleName(const NamedDecl *D, |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 2598 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c02ab4c | 2009-11-21 09:14:44 +0000 | [diff] [blame] | 2599 | assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) && |
| 2600 | "Invalid mangleName() call, argument is not a variable or function!"); |
| 2601 | assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) && |
| 2602 | "Invalid mangleName() call on 'structor decl!"); |
Daniel Dunbar | 3c9e463 | 2009-11-21 09:05:47 +0000 | [diff] [blame] | 2603 | |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2604 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), |
| 2605 | getASTContext().getSourceManager(), |
| 2606 | "Mangling declaration"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2607 | |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2608 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | 94fd26d | 2009-11-21 09:06:22 +0000 | [diff] [blame] | 2609 | return Mangler.mangle(D); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2610 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2611 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2612 | void ItaniumMangleContext::mangleCXXCtor(const CXXConstructorDecl *D, |
| 2613 | CXXCtorType Type, |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 2614 | llvm::raw_ostream &Out) { |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2615 | CXXNameMangler Mangler(*this, Out, D, Type); |
Daniel Dunbar | 77939c9 | 2009-11-21 09:06:31 +0000 | [diff] [blame] | 2616 | Mangler.mangle(D); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2617 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2618 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2619 | void ItaniumMangleContext::mangleCXXDtor(const CXXDestructorDecl *D, |
| 2620 | CXXDtorType Type, |
Rafael Espindola | 0e376a0 | 2011-02-11 01:41:00 +0000 | [diff] [blame] | 2621 | llvm::raw_ostream &Out) { |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2622 | CXXNameMangler Mangler(*this, Out, D, Type); |
Daniel Dunbar | 77939c9 | 2009-11-21 09:06:31 +0000 | [diff] [blame] | 2623 | Mangler.mangle(D); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2624 | } |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 2625 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2626 | void ItaniumMangleContext::mangleThunk(const CXXMethodDecl *MD, |
| 2627 | const ThunkInfo &Thunk, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2628 | llvm::raw_ostream &Out) { |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2629 | // <special-name> ::= T <call-offset> <base encoding> |
| 2630 | // # base is the nominal target function of thunk |
| 2631 | // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> |
| 2632 | // # base is the nominal target function of thunk |
| 2633 | // # first call-offset is 'this' adjustment |
| 2634 | // # second call-offset is result adjustment |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2635 | |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2636 | assert(!isa<CXXDestructorDecl>(MD) && |
| 2637 | "Use mangleCXXDtor for destructor decls!"); |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2638 | CXXNameMangler Mangler(*this, Out); |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2639 | Mangler.getStream() << "_ZT"; |
| 2640 | if (!Thunk.Return.isEmpty()) |
| 2641 | Mangler.getStream() << 'c'; |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2642 | |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2643 | // Mangle the 'this' pointer adjustment. |
| 2644 | Mangler.mangleCallOffset(Thunk.This.NonVirtual, Thunk.This.VCallOffsetOffset); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2645 | |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2646 | // Mangle the return pointer adjustment if there is one. |
| 2647 | if (!Thunk.Return.isEmpty()) |
| 2648 | Mangler.mangleCallOffset(Thunk.Return.NonVirtual, |
| 2649 | Thunk.Return.VBaseOffsetOffset); |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2650 | |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2651 | Mangler.mangleFunctionEncoding(MD); |
| 2652 | } |
| 2653 | |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2654 | void |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2655 | ItaniumMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD, |
| 2656 | CXXDtorType Type, |
| 2657 | const ThisAdjustment &ThisAdjustment, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2658 | llvm::raw_ostream &Out) { |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2659 | // <special-name> ::= T <call-offset> <base encoding> |
| 2660 | // # base is the nominal target function of thunk |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2661 | CXXNameMangler Mangler(*this, Out, DD, Type); |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2662 | Mangler.getStream() << "_ZT"; |
| 2663 | |
| 2664 | // Mangle the 'this' pointer adjustment. |
Sean Hunt | c302113 | 2010-05-05 15:23:54 +0000 | [diff] [blame] | 2665 | Mangler.mangleCallOffset(ThisAdjustment.NonVirtual, |
Anders Carlsson | 19879c9 | 2010-03-23 17:17:29 +0000 | [diff] [blame] | 2666 | ThisAdjustment.VCallOffsetOffset); |
| 2667 | |
| 2668 | Mangler.mangleFunctionEncoding(DD); |
| 2669 | } |
| 2670 | |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2671 | /// mangleGuardVariable - Returns the mangled name for a guard variable |
| 2672 | /// for the passed in VarDecl. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2673 | void ItaniumMangleContext::mangleItaniumGuardVariable(const VarDecl *D, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2674 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2675 | // <special-name> ::= GV <object name> # Guard variable for one-time |
| 2676 | // # initialization |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2677 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2678 | Mangler.getStream() << "_ZGV"; |
| 2679 | Mangler.mangleName(D); |
| 2680 | } |
| 2681 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2682 | void ItaniumMangleContext::mangleReferenceTemporary(const VarDecl *D, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2683 | llvm::raw_ostream &Out) { |
Anders Carlsson | 715edf2 | 2010-06-26 16:09:40 +0000 | [diff] [blame] | 2684 | // We match the GCC mangling here. |
| 2685 | // <special-name> ::= GR <object name> |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2686 | CXXNameMangler Mangler(*this, Out); |
Anders Carlsson | 715edf2 | 2010-06-26 16:09:40 +0000 | [diff] [blame] | 2687 | Mangler.getStream() << "_ZGR"; |
| 2688 | Mangler.mangleName(D); |
| 2689 | } |
| 2690 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2691 | void ItaniumMangleContext::mangleCXXVTable(const CXXRecordDecl *RD, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2692 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2693 | // <special-name> ::= TV <type> # virtual table |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2694 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2695 | Mangler.getStream() << "_ZTV"; |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 2696 | Mangler.mangleNameOrStandardSubstitution(RD); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2697 | } |
Mike Stump | 82d75b0 | 2009-11-10 01:58:37 +0000 | [diff] [blame] | 2698 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2699 | void ItaniumMangleContext::mangleCXXVTT(const CXXRecordDecl *RD, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2700 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2701 | // <special-name> ::= TT <type> # VTT structure |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2702 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2703 | Mangler.getStream() << "_ZTT"; |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 2704 | Mangler.mangleNameOrStandardSubstitution(RD); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2705 | } |
Mike Stump | ab3f7e9 | 2009-11-10 01:41:59 +0000 | [diff] [blame] | 2706 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2707 | void ItaniumMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD, |
| 2708 | int64_t Offset, |
| 2709 | const CXXRecordDecl *Type, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2710 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2711 | // <special-name> ::= TC <type> <offset number> _ <base type> |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2712 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2713 | Mangler.getStream() << "_ZTC"; |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 2714 | Mangler.mangleNameOrStandardSubstitution(RD); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2715 | Mangler.getStream() << Offset; |
Benjamin Kramer | 35f59b6 | 2010-04-10 16:03:31 +0000 | [diff] [blame] | 2716 | Mangler.getStream() << '_'; |
Douglas Gregor | 1b12a3b | 2010-05-26 05:11:13 +0000 | [diff] [blame] | 2717 | Mangler.mangleNameOrStandardSubstitution(Type); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2718 | } |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 2719 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2720 | void ItaniumMangleContext::mangleCXXRTTI(QualType Ty, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2721 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2722 | // <special-name> ::= TI <type> # typeinfo structure |
Douglas Gregor | 154fe98 | 2009-12-23 22:04:40 +0000 | [diff] [blame] | 2723 | assert(!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers"); |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2724 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2725 | Mangler.getStream() << "_ZTI"; |
| 2726 | Mangler.mangleType(Ty); |
Daniel Dunbar | 1b07711 | 2009-11-21 09:06:10 +0000 | [diff] [blame] | 2727 | } |
Mike Stump | 6779598 | 2009-11-14 00:14:13 +0000 | [diff] [blame] | 2728 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2729 | void ItaniumMangleContext::mangleCXXRTTIName(QualType Ty, |
Rafael Espindola | f0be979 | 2011-02-11 02:52:17 +0000 | [diff] [blame] | 2730 | llvm::raw_ostream &Out) { |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2731 | // <special-name> ::= TS <type> # typeinfo name (null terminated byte string) |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 2732 | CXXNameMangler Mangler(*this, Out); |
Daniel Dunbar | c074771 | 2009-11-21 09:12:13 +0000 | [diff] [blame] | 2733 | Mangler.getStream() << "_ZTS"; |
| 2734 | Mangler.mangleType(Ty); |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 2735 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 2736 | |
| 2737 | MangleContext *clang::createItaniumMangleContext(ASTContext &Context, |
| 2738 | Diagnostic &Diags) { |
| 2739 | return new ItaniumMangleContext(Context, Diags); |
| 2740 | } |