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