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