Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1 | //===--- MicrosoftMangle.cpp - Microsoft Visual C++ Name Mangling ---------===// |
| 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 | // |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 10 | // This provides C++ name mangling targeting the Microsoft Visual C++ ABI. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/Mangle.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/CharUnits.h" |
| 17 | #include "clang/AST/Decl.h" |
| 18 | #include "clang/AST/DeclCXX.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | #include "clang/AST/ExprCXX.h" |
| 22 | #include "clang/Basic/ABI.h" |
Douglas Gregor | 02c23eb | 2012-10-23 22:26:28 +0000 | [diff] [blame] | 23 | #include "clang/Basic/DiagnosticOptions.h" |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 24 | |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 25 | #include <map> |
| 26 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 27 | using namespace clang; |
| 28 | |
| 29 | namespace { |
| 30 | |
| 31 | /// MicrosoftCXXNameMangler - Manage the mangling of a single name for the |
| 32 | /// Microsoft Visual C++ ABI. |
| 33 | class MicrosoftCXXNameMangler { |
| 34 | MangleContext &Context; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 35 | raw_ostream &Out; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 36 | |
Timur Iskhodzhanov | d93c5ff | 2012-07-25 08:16:41 +0000 | [diff] [blame] | 37 | // FIXME: audit the performance of BackRefMap as it might do way too many |
| 38 | // copying of strings. |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 39 | typedef std::map<std::string, unsigned> BackRefMap; |
| 40 | BackRefMap NameBackReferences; |
| 41 | bool UseNameBackReferences; |
| 42 | |
| 43 | typedef llvm::DenseMap<void*, unsigned> ArgBackRefMap; |
| 44 | ArgBackRefMap TypeBackReferences; |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 45 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 46 | ASTContext &getASTContext() const { return Context.getASTContext(); } |
| 47 | |
| 48 | public: |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 49 | MicrosoftCXXNameMangler(MangleContext &C, raw_ostream &Out_) |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 50 | : Context(C), Out(Out_), UseNameBackReferences(true) { } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 51 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 52 | raw_ostream &getStream() const { return Out; } |
| 53 | |
| 54 | void mangle(const NamedDecl *D, StringRef Prefix = "\01?"); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 55 | void mangleName(const NamedDecl *ND); |
| 56 | void mangleFunctionEncoding(const FunctionDecl *FD); |
| 57 | void mangleVariableEncoding(const VarDecl *VD); |
| 58 | void mangleNumber(int64_t Number); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 59 | void mangleNumber(const llvm::APSInt &Value); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 60 | void mangleType(QualType T, SourceRange Range, bool MangleQualifiers = true); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 63 | void disableBackReferences() { UseNameBackReferences = false; } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 64 | void mangleUnqualifiedName(const NamedDecl *ND) { |
| 65 | mangleUnqualifiedName(ND, ND->getDeclName()); |
| 66 | } |
| 67 | void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name); |
| 68 | void mangleSourceName(const IdentifierInfo *II); |
| 69 | void manglePostfix(const DeclContext *DC, bool NoFunction=false); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 70 | void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 71 | void mangleQualifiers(Qualifiers Quals, bool IsMember); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 72 | void manglePointerQualifiers(Qualifiers Quals); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 73 | |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 74 | void mangleUnscopedTemplateName(const TemplateDecl *ND); |
| 75 | void mangleTemplateInstantiationName(const TemplateDecl *TD, |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 76 | const SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 77 | void mangleObjCMethodName(const ObjCMethodDecl *MD); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 78 | void mangleLocalName(const FunctionDecl *FD); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 79 | |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 80 | void mangleArgumentType(QualType T, SourceRange Range); |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 81 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 82 | // Declare manglers for every type class. |
| 83 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 84 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 85 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \ |
| 86 | SourceRange Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 87 | #include "clang/AST/TypeNodes.def" |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 88 | #undef ABSTRACT_TYPE |
| 89 | #undef NON_CANONICAL_TYPE |
| 90 | #undef TYPE |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 91 | |
| 92 | void mangleType(const TagType*); |
| 93 | void mangleType(const FunctionType *T, const FunctionDecl *D, |
| 94 | bool IsStructor, bool IsInstMethod); |
| 95 | void mangleType(const ArrayType *T, bool IsGlobal); |
| 96 | void mangleExtraDimensions(QualType T); |
| 97 | void mangleFunctionClass(const FunctionDecl *FD); |
| 98 | void mangleCallingConvention(const FunctionType *T, bool IsInstMethod = false); |
Nico Weber | 0a26d76 | 2012-11-13 22:09:44 +0000 | [diff] [blame] | 99 | void mangleIntegerLiteral(const llvm::APSInt &Number, bool IsBoolean); |
Nico Weber | 2225556 | 2012-10-03 06:46:47 +0000 | [diff] [blame] | 100 | void mangleExpression(const Expr *E); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 101 | void mangleThrowSpecification(const FunctionProtoType *T); |
| 102 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 103 | void mangleTemplateArgs( |
| 104 | const SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 105 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | /// MicrosoftMangleContext - Overrides the default MangleContext for the |
| 109 | /// Microsoft Visual C++ ABI. |
| 110 | class MicrosoftMangleContext : public MangleContext { |
| 111 | public: |
| 112 | MicrosoftMangleContext(ASTContext &Context, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 113 | DiagnosticsEngine &Diags) : MangleContext(Context, Diags) { } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 114 | virtual bool shouldMangleDeclName(const NamedDecl *D); |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 115 | virtual void mangleName(const NamedDecl *D, raw_ostream &Out); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 116 | virtual void mangleThunk(const CXXMethodDecl *MD, |
| 117 | const ThunkInfo &Thunk, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 118 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 119 | virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type, |
| 120 | const ThisAdjustment &ThisAdjustment, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 121 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 122 | virtual void mangleCXXVTable(const CXXRecordDecl *RD, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 123 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 124 | virtual void mangleCXXVTT(const CXXRecordDecl *RD, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 125 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 126 | virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset, |
| 127 | const CXXRecordDecl *Type, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 128 | raw_ostream &); |
| 129 | virtual void mangleCXXRTTI(QualType T, raw_ostream &); |
| 130 | virtual void mangleCXXRTTIName(QualType T, raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 131 | virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 132 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 133 | virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 134 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 135 | virtual void mangleReferenceTemporary(const clang::VarDecl *, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 136 | raw_ostream &); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } |
| 140 | |
| 141 | static bool isInCLinkageSpecification(const Decl *D) { |
| 142 | D = D->getCanonicalDecl(); |
| 143 | for (const DeclContext *DC = D->getDeclContext(); |
| 144 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
| 145 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) |
| 146 | return Linkage->getLanguage() == LinkageSpecDecl::lang_c; |
| 147 | } |
| 148 | |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) { |
| 153 | // In C, functions with no attributes never need to be mangled. Fastpath them. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 154 | if (!getASTContext().getLangOpts().CPlusPlus && !D->hasAttrs()) |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 155 | return false; |
| 156 | |
| 157 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 158 | // over all other naming in the .o file. |
| 159 | if (D->hasAttr<AsmLabelAttr>()) |
| 160 | return true; |
| 161 | |
| 162 | // Clang's "overloadable" attribute extension to C/C++ implies name mangling |
| 163 | // (always) as does passing a C++ member function and a function |
| 164 | // whose name is not a simple identifier. |
| 165 | const FunctionDecl *FD = dyn_cast<FunctionDecl>(D); |
| 166 | if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) || |
| 167 | !FD->getDeclName().isIdentifier())) |
| 168 | return true; |
| 169 | |
| 170 | // Otherwise, no mangling is done outside C++ mode. |
David Blaikie | 4e4d084 | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 171 | if (!getASTContext().getLangOpts().CPlusPlus) |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 172 | return false; |
| 173 | |
| 174 | // Variables at global scope with internal linkage are not mangled. |
| 175 | if (!FD) { |
| 176 | const DeclContext *DC = D->getDeclContext(); |
| 177 | if (DC->isTranslationUnit() && D->getLinkage() == InternalLinkage) |
| 178 | return false; |
| 179 | } |
| 180 | |
| 181 | // C functions and "main" are not mangled. |
| 182 | if ((FD && FD->isMain()) || isInCLinkageSpecification(D)) |
| 183 | return false; |
| 184 | |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 189 | StringRef Prefix) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 190 | // MSVC doesn't mangle C++ names the same way it mangles extern "C" names. |
| 191 | // Therefore it's really important that we don't decorate the |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 192 | // name with leading underscores or leading/trailing at signs. So, by |
| 193 | // default, we emit an asm marker at the start so we get the name right. |
| 194 | // Callers can override this with a custom prefix. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 195 | |
| 196 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 197 | // over all other naming in the .o file. |
| 198 | if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { |
| 199 | // If we have an asm name, then we use it as the mangling. |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 200 | Out << '\01' << ALA->getLabel(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 201 | return; |
| 202 | } |
| 203 | |
| 204 | // <mangled-name> ::= ? <name> <type-encoding> |
| 205 | Out << Prefix; |
| 206 | mangleName(D); |
| 207 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 208 | mangleFunctionEncoding(FD); |
| 209 | else if (const VarDecl *VD = dyn_cast<VarDecl>(D)) |
| 210 | mangleVariableEncoding(VD); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 211 | else { |
| 212 | // TODO: Fields? Can MSVC even mangle them? |
| 213 | // Issue a diagnostic for now. |
| 214 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 215 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 216 | "cannot mangle this declaration yet"); |
| 217 | Diags.Report(D->getLocation(), DiagID) |
| 218 | << D->getSourceRange(); |
| 219 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
| 223 | // <type-encoding> ::= <function-class> <function-type> |
| 224 | |
| 225 | // Don't mangle in the type if this isn't a decl we should typically mangle. |
| 226 | if (!Context.shouldMangleDeclName(FD)) |
| 227 | return; |
| 228 | |
| 229 | // We should never ever see a FunctionNoProtoType at this point. |
| 230 | // We don't even know how to mangle their types anyway :). |
Richard Smith | bd1d18e | 2012-06-04 22:46:59 +0000 | [diff] [blame] | 231 | const FunctionProtoType *FT = FD->getType()->castAs<FunctionProtoType>(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 232 | |
| 233 | bool InStructor = false, InInstMethod = false; |
| 234 | const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD); |
| 235 | if (MD) { |
| 236 | if (MD->isInstance()) |
| 237 | InInstMethod = true; |
| 238 | if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD)) |
| 239 | InStructor = true; |
| 240 | } |
| 241 | |
| 242 | // First, the function class. |
| 243 | mangleFunctionClass(FD); |
| 244 | |
| 245 | mangleType(FT, FD, InStructor, InInstMethod); |
| 246 | } |
| 247 | |
| 248 | void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) { |
| 249 | // <type-encoding> ::= <storage-class> <variable-type> |
| 250 | // <storage-class> ::= 0 # private static member |
| 251 | // ::= 1 # protected static member |
| 252 | // ::= 2 # public static member |
| 253 | // ::= 3 # global |
| 254 | // ::= 4 # static local |
| 255 | |
| 256 | // The first character in the encoding (after the name) is the storage class. |
| 257 | if (VD->isStaticDataMember()) { |
| 258 | // If it's a static member, it also encodes the access level. |
| 259 | switch (VD->getAccess()) { |
| 260 | default: |
| 261 | case AS_private: Out << '0'; break; |
| 262 | case AS_protected: Out << '1'; break; |
| 263 | case AS_public: Out << '2'; break; |
| 264 | } |
| 265 | } |
| 266 | else if (!VD->isStaticLocal()) |
| 267 | Out << '3'; |
| 268 | else |
| 269 | Out << '4'; |
| 270 | // Now mangle the type. |
| 271 | // <variable-type> ::= <type> <cvr-qualifiers> |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 272 | // ::= <type> <pointee-cvr-qualifiers> # pointers, references |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 273 | // Pointers and references are odd. The type of 'int * const foo;' gets |
| 274 | // mangled as 'QAHA' instead of 'PAHB', for example. |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 275 | TypeLoc TL = VD->getTypeSourceInfo()->getTypeLoc(); |
| 276 | QualType Ty = TL.getType(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 277 | if (Ty->isPointerType() || Ty->isReferenceType()) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 278 | mangleType(Ty, TL.getSourceRange()); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 279 | mangleQualifiers(Ty->getPointeeType().getQualifiers(), false); |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 280 | } else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 281 | // Global arrays are funny, too. |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 282 | mangleType(AT, true); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 283 | mangleQualifiers(Ty.getQualifiers(), false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 284 | } else { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 285 | mangleType(Ty.getLocalUnqualifiedType(), TL.getSourceRange()); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 286 | mangleQualifiers(Ty.getLocalQualifiers(), false); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) { |
| 291 | // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @ |
| 292 | const DeclContext *DC = ND->getDeclContext(); |
| 293 | |
| 294 | // Always start with the unqualified name. |
| 295 | mangleUnqualifiedName(ND); |
| 296 | |
| 297 | // If this is an extern variable declared locally, the relevant DeclContext |
| 298 | // is that of the containing namespace, or the translation unit. |
| 299 | if (isa<FunctionDecl>(DC) && ND->hasLinkage()) |
| 300 | while (!DC->isNamespace() && !DC->isTranslationUnit()) |
| 301 | DC = DC->getParent(); |
| 302 | |
| 303 | manglePostfix(DC); |
| 304 | |
| 305 | // Terminate the whole name with an '@'. |
| 306 | Out << '@'; |
| 307 | } |
| 308 | |
| 309 | void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) { |
Nico Weber | c8e78b2 | 2012-11-09 00:05:56 +0000 | [diff] [blame] | 310 | llvm::APSInt APSNumber(/*BitWidth=*/64, /*isUnsigned=*/false); |
| 311 | APSNumber = Number; |
| 312 | mangleNumber(APSNumber); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 313 | } |
| 314 | |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 315 | void MicrosoftCXXNameMangler::mangleNumber(const llvm::APSInt &Value) { |
Nico Weber | c8e78b2 | 2012-11-09 00:05:56 +0000 | [diff] [blame] | 316 | // <number> ::= [?] <decimal digit> # 1 <= Number <= 10 |
| 317 | // ::= [?] <hex digit>+ @ # 0 or > 9; A = 0, B = 1, etc... |
| 318 | // ::= [?] @ # 0 (alternate mangling, not emitted by VC) |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 319 | if (Value.isSigned() && Value.isNegative()) { |
| 320 | Out << '?'; |
| 321 | mangleNumber(llvm::APSInt(Value.abs())); |
| 322 | return; |
| 323 | } |
Charles Davis | c4d7675 | 2012-05-29 07:01:45 +0000 | [diff] [blame] | 324 | llvm::APSInt Temp(Value); |
Nico Weber | c8e78b2 | 2012-11-09 00:05:56 +0000 | [diff] [blame] | 325 | // There's a special shorter mangling for 0, but Microsoft |
| 326 | // chose not to use it. Instead, 0 gets mangled as "A@". Oh well... |
Charles Davis | c4d7675 | 2012-05-29 07:01:45 +0000 | [diff] [blame] | 327 | if (Value.uge(1) && Value.ule(10)) { |
| 328 | --Temp; |
| 329 | Temp.print(Out, false); |
| 330 | } else { |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 331 | // We have to build up the encoding in reverse order, so it will come |
| 332 | // out right when we write it out. |
| 333 | char Encoding[64]; |
| 334 | char *EndPtr = Encoding+sizeof(Encoding); |
| 335 | char *CurPtr = EndPtr; |
Charles Davis | 104e51f | 2012-05-28 03:54:22 +0000 | [diff] [blame] | 336 | llvm::APSInt NibbleMask(Value.getBitWidth(), Value.isUnsigned()); |
Lang Hames | f17523b | 2012-05-27 21:39:49 +0000 | [diff] [blame] | 337 | NibbleMask = 0xf; |
Nico Weber | e95b46b | 2012-11-08 23:38:59 +0000 | [diff] [blame] | 338 | do { |
Charles Davis | c4d7675 | 2012-05-29 07:01:45 +0000 | [diff] [blame] | 339 | *--CurPtr = 'A' + Temp.And(NibbleMask).getLimitedValue(0xf); |
| 340 | Temp = Temp.lshr(4); |
Nico Weber | e95b46b | 2012-11-08 23:38:59 +0000 | [diff] [blame] | 341 | } while (Temp != 0); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 342 | Out.write(CurPtr, EndPtr-CurPtr); |
| 343 | Out << '@'; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | static const TemplateDecl * |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 348 | isTemplate(const NamedDecl *ND, |
| 349 | SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs) { |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 350 | // Check if we have a function template. |
| 351 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){ |
| 352 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 353 | if (FD->getTemplateSpecializationArgsAsWritten()) { |
| 354 | const ASTTemplateArgumentListInfo *ArgList = |
| 355 | FD->getTemplateSpecializationArgsAsWritten(); |
| 356 | TemplateArgs.append(ArgList->getTemplateArgs(), |
| 357 | ArgList->getTemplateArgs() + |
| 358 | ArgList->NumTemplateArgs); |
| 359 | } else { |
| 360 | const TemplateArgumentList *ArgList = |
| 361 | FD->getTemplateSpecializationArgs(); |
| 362 | TemplateArgumentListInfo LI; |
| 363 | for (unsigned i = 0, e = ArgList->size(); i != e; ++i) |
| 364 | TemplateArgs.push_back(TemplateArgumentLoc(ArgList->get(i), |
| 365 | FD->getTypeSourceInfo())); |
| 366 | } |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 367 | return TD; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // Check if we have a class template. |
| 372 | if (const ClassTemplateSpecializationDecl *Spec = |
| 373 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 374 | TypeSourceInfo *TSI = Spec->getTypeAsWritten(); |
| 375 | if (TSI) { |
Matt Beaumont-Gay | 0bbf1c6 | 2012-11-16 01:14:52 +0000 | [diff] [blame] | 376 | TemplateSpecializationTypeLoc TSTL = |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 377 | cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); |
| 378 | TemplateArgumentListInfo LI(TSTL.getLAngleLoc(), TSTL.getRAngleLoc()); |
| 379 | for (unsigned i = 0, e = TSTL.getNumArgs(); i != e; ++i) |
| 380 | TemplateArgs.push_back(TSTL.getArgLoc(i)); |
| 381 | } else { |
| 382 | TemplateArgumentListInfo LI; |
| 383 | const TemplateArgumentList &ArgList = |
| 384 | Spec->getTemplateArgs(); |
| 385 | for (unsigned i = 0, e = ArgList.size(); i != e; ++i) |
| 386 | TemplateArgs.push_back(TemplateArgumentLoc(ArgList[i], |
| 387 | TemplateArgumentLocInfo())); |
| 388 | } |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 389 | return Spec->getSpecializedTemplate(); |
| 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 395 | void |
| 396 | MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, |
| 397 | DeclarationName Name) { |
| 398 | // <unqualified-name> ::= <operator-name> |
| 399 | // ::= <ctor-dtor-name> |
| 400 | // ::= <source-name> |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 401 | // ::= <template-name> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 402 | SmallVector<TemplateArgumentLoc, 2> TemplateArgs; |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 403 | // Check if we have a template. |
| 404 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 405 | // We have a template. |
| 406 | // Here comes the tricky thing: if we need to mangle something like |
| 407 | // void foo(A::X<Y>, B::X<Y>), |
| 408 | // the X<Y> part is aliased. However, if you need to mangle |
| 409 | // void foo(A::X<A::Y>, A::X<B::Y>), |
| 410 | // the A::X<> part is not aliased. |
| 411 | // That said, from the mangler's perspective we have a structure like this: |
| 412 | // namespace[s] -> type[ -> template-parameters] |
| 413 | // but from the Clang perspective we have |
| 414 | // type [ -> template-parameters] |
| 415 | // \-> namespace[s] |
| 416 | // What we do is we create a new mangler, mangle the same type (without |
| 417 | // a namespace suffix) using the extra mangler with back references |
| 418 | // disabled (to avoid infinite recursion) and then use the mangled type |
| 419 | // name as a key to check the mangling of different types for aliasing. |
| 420 | |
| 421 | std::string BackReferenceKey; |
| 422 | BackRefMap::iterator Found; |
| 423 | if (UseNameBackReferences) { |
| 424 | llvm::raw_string_ostream Stream(BackReferenceKey); |
| 425 | MicrosoftCXXNameMangler Extra(Context, Stream); |
| 426 | Extra.disableBackReferences(); |
| 427 | Extra.mangleUnqualifiedName(ND, Name); |
| 428 | Stream.flush(); |
| 429 | |
| 430 | Found = NameBackReferences.find(BackReferenceKey); |
| 431 | } |
| 432 | if (!UseNameBackReferences || Found == NameBackReferences.end()) { |
| 433 | mangleTemplateInstantiationName(TD, TemplateArgs); |
| 434 | if (UseNameBackReferences && NameBackReferences.size() < 10) { |
| 435 | size_t Size = NameBackReferences.size(); |
| 436 | NameBackReferences[BackReferenceKey] = Size; |
| 437 | } |
| 438 | } else { |
| 439 | Out << Found->second; |
| 440 | } |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 441 | return; |
| 442 | } |
| 443 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 444 | switch (Name.getNameKind()) { |
| 445 | case DeclarationName::Identifier: { |
| 446 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 447 | mangleSourceName(II); |
| 448 | break; |
| 449 | } |
| 450 | |
| 451 | // Otherwise, an anonymous entity. We must have a declaration. |
| 452 | assert(ND && "mangling empty name without declaration"); |
| 453 | |
| 454 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
| 455 | if (NS->isAnonymousNamespace()) { |
| 456 | Out << "?A"; |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | // We must have an anonymous struct. |
| 462 | const TagDecl *TD = cast<TagDecl>(ND); |
Richard Smith | 162e1c1 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 463 | if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 464 | assert(TD->getDeclContext() == D->getDeclContext() && |
| 465 | "Typedef should not be in another decl context!"); |
| 466 | assert(D->getDeclName().getAsIdentifierInfo() && |
| 467 | "Typedef was not named!"); |
| 468 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | // When VC encounters an anonymous type with no tag and no typedef, |
| 473 | // it literally emits '<unnamed-tag>'. |
| 474 | Out << "<unnamed-tag>"; |
| 475 | break; |
| 476 | } |
| 477 | |
| 478 | case DeclarationName::ObjCZeroArgSelector: |
| 479 | case DeclarationName::ObjCOneArgSelector: |
| 480 | case DeclarationName::ObjCMultiArgSelector: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 481 | llvm_unreachable("Can't mangle Objective-C selector names here!"); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 482 | |
| 483 | case DeclarationName::CXXConstructorName: |
Michael J. Spencer | 50118da | 2011-12-01 09:55:00 +0000 | [diff] [blame] | 484 | Out << "?0"; |
| 485 | break; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 486 | |
| 487 | case DeclarationName::CXXDestructorName: |
Michael J. Spencer | 50118da | 2011-12-01 09:55:00 +0000 | [diff] [blame] | 488 | Out << "?1"; |
| 489 | break; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 490 | |
| 491 | case DeclarationName::CXXConversionFunctionName: |
| 492 | // <operator-name> ::= ?B # (cast) |
| 493 | // The target type is encoded as the return type. |
| 494 | Out << "?B"; |
| 495 | break; |
| 496 | |
| 497 | case DeclarationName::CXXOperatorName: |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 498 | mangleOperatorName(Name.getCXXOverloadedOperator(), ND->getLocation()); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 499 | break; |
| 500 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 501 | case DeclarationName::CXXLiteralOperatorName: { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 502 | // FIXME: Was this added in VS2010? Does MS even know how to mangle this? |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 503 | DiagnosticsEngine Diags = Context.getDiags(); |
| 504 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 505 | "cannot mangle this literal operator yet"); |
| 506 | Diags.Report(ND->getLocation(), DiagID); |
| 507 | break; |
| 508 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 509 | |
| 510 | case DeclarationName::CXXUsingDirective: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 511 | llvm_unreachable("Can't mangle a using directive name!"); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC, |
| 516 | bool NoFunction) { |
| 517 | // <postfix> ::= <unqualified-name> [<postfix>] |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 518 | // ::= <substitution> [<postfix>] |
| 519 | |
| 520 | if (!DC) return; |
| 521 | |
| 522 | while (isa<LinkageSpecDecl>(DC)) |
| 523 | DC = DC->getParent(); |
| 524 | |
| 525 | if (DC->isTranslationUnit()) |
| 526 | return; |
| 527 | |
| 528 | if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) { |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 529 | Context.mangleBlock(BD, Out); |
| 530 | Out << '@'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 531 | return manglePostfix(DC->getParent(), NoFunction); |
| 532 | } |
| 533 | |
| 534 | if (NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC))) |
| 535 | return; |
| 536 | else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) |
| 537 | mangleObjCMethodName(Method); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 538 | else if (const FunctionDecl *Func = dyn_cast<FunctionDecl>(DC)) |
| 539 | mangleLocalName(Func); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 540 | else { |
| 541 | mangleUnqualifiedName(cast<NamedDecl>(DC)); |
| 542 | manglePostfix(DC->getParent(), NoFunction); |
| 543 | } |
| 544 | } |
| 545 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 546 | void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, |
| 547 | SourceLocation Loc) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 548 | switch (OO) { |
| 549 | // ?0 # constructor |
| 550 | // ?1 # destructor |
| 551 | // <operator-name> ::= ?2 # new |
| 552 | case OO_New: Out << "?2"; break; |
| 553 | // <operator-name> ::= ?3 # delete |
| 554 | case OO_Delete: Out << "?3"; break; |
| 555 | // <operator-name> ::= ?4 # = |
| 556 | case OO_Equal: Out << "?4"; break; |
| 557 | // <operator-name> ::= ?5 # >> |
| 558 | case OO_GreaterGreater: Out << "?5"; break; |
| 559 | // <operator-name> ::= ?6 # << |
| 560 | case OO_LessLess: Out << "?6"; break; |
| 561 | // <operator-name> ::= ?7 # ! |
| 562 | case OO_Exclaim: Out << "?7"; break; |
| 563 | // <operator-name> ::= ?8 # == |
| 564 | case OO_EqualEqual: Out << "?8"; break; |
| 565 | // <operator-name> ::= ?9 # != |
| 566 | case OO_ExclaimEqual: Out << "?9"; break; |
| 567 | // <operator-name> ::= ?A # [] |
| 568 | case OO_Subscript: Out << "?A"; break; |
| 569 | // ?B # conversion |
| 570 | // <operator-name> ::= ?C # -> |
| 571 | case OO_Arrow: Out << "?C"; break; |
| 572 | // <operator-name> ::= ?D # * |
| 573 | case OO_Star: Out << "?D"; break; |
| 574 | // <operator-name> ::= ?E # ++ |
| 575 | case OO_PlusPlus: Out << "?E"; break; |
| 576 | // <operator-name> ::= ?F # -- |
| 577 | case OO_MinusMinus: Out << "?F"; break; |
| 578 | // <operator-name> ::= ?G # - |
| 579 | case OO_Minus: Out << "?G"; break; |
| 580 | // <operator-name> ::= ?H # + |
| 581 | case OO_Plus: Out << "?H"; break; |
| 582 | // <operator-name> ::= ?I # & |
| 583 | case OO_Amp: Out << "?I"; break; |
| 584 | // <operator-name> ::= ?J # ->* |
| 585 | case OO_ArrowStar: Out << "?J"; break; |
| 586 | // <operator-name> ::= ?K # / |
| 587 | case OO_Slash: Out << "?K"; break; |
| 588 | // <operator-name> ::= ?L # % |
| 589 | case OO_Percent: Out << "?L"; break; |
| 590 | // <operator-name> ::= ?M # < |
| 591 | case OO_Less: Out << "?M"; break; |
| 592 | // <operator-name> ::= ?N # <= |
| 593 | case OO_LessEqual: Out << "?N"; break; |
| 594 | // <operator-name> ::= ?O # > |
| 595 | case OO_Greater: Out << "?O"; break; |
| 596 | // <operator-name> ::= ?P # >= |
| 597 | case OO_GreaterEqual: Out << "?P"; break; |
| 598 | // <operator-name> ::= ?Q # , |
| 599 | case OO_Comma: Out << "?Q"; break; |
| 600 | // <operator-name> ::= ?R # () |
| 601 | case OO_Call: Out << "?R"; break; |
| 602 | // <operator-name> ::= ?S # ~ |
| 603 | case OO_Tilde: Out << "?S"; break; |
| 604 | // <operator-name> ::= ?T # ^ |
| 605 | case OO_Caret: Out << "?T"; break; |
| 606 | // <operator-name> ::= ?U # | |
| 607 | case OO_Pipe: Out << "?U"; break; |
| 608 | // <operator-name> ::= ?V # && |
| 609 | case OO_AmpAmp: Out << "?V"; break; |
| 610 | // <operator-name> ::= ?W # || |
| 611 | case OO_PipePipe: Out << "?W"; break; |
| 612 | // <operator-name> ::= ?X # *= |
| 613 | case OO_StarEqual: Out << "?X"; break; |
| 614 | // <operator-name> ::= ?Y # += |
| 615 | case OO_PlusEqual: Out << "?Y"; break; |
| 616 | // <operator-name> ::= ?Z # -= |
| 617 | case OO_MinusEqual: Out << "?Z"; break; |
| 618 | // <operator-name> ::= ?_0 # /= |
| 619 | case OO_SlashEqual: Out << "?_0"; break; |
| 620 | // <operator-name> ::= ?_1 # %= |
| 621 | case OO_PercentEqual: Out << "?_1"; break; |
| 622 | // <operator-name> ::= ?_2 # >>= |
| 623 | case OO_GreaterGreaterEqual: Out << "?_2"; break; |
| 624 | // <operator-name> ::= ?_3 # <<= |
| 625 | case OO_LessLessEqual: Out << "?_3"; break; |
| 626 | // <operator-name> ::= ?_4 # &= |
| 627 | case OO_AmpEqual: Out << "?_4"; break; |
| 628 | // <operator-name> ::= ?_5 # |= |
| 629 | case OO_PipeEqual: Out << "?_5"; break; |
| 630 | // <operator-name> ::= ?_6 # ^= |
| 631 | case OO_CaretEqual: Out << "?_6"; break; |
| 632 | // ?_7 # vftable |
| 633 | // ?_8 # vbtable |
| 634 | // ?_9 # vcall |
| 635 | // ?_A # typeof |
| 636 | // ?_B # local static guard |
| 637 | // ?_C # string |
| 638 | // ?_D # vbase destructor |
| 639 | // ?_E # vector deleting destructor |
| 640 | // ?_F # default constructor closure |
| 641 | // ?_G # scalar deleting destructor |
| 642 | // ?_H # vector constructor iterator |
| 643 | // ?_I # vector destructor iterator |
| 644 | // ?_J # vector vbase constructor iterator |
| 645 | // ?_K # virtual displacement map |
| 646 | // ?_L # eh vector constructor iterator |
| 647 | // ?_M # eh vector destructor iterator |
| 648 | // ?_N # eh vector vbase constructor iterator |
| 649 | // ?_O # copy constructor closure |
| 650 | // ?_P<name> # udt returning <name> |
| 651 | // ?_Q # <unknown> |
| 652 | // ?_R0 # RTTI Type Descriptor |
| 653 | // ?_R1 # RTTI Base Class Descriptor at (a,b,c,d) |
| 654 | // ?_R2 # RTTI Base Class Array |
| 655 | // ?_R3 # RTTI Class Hierarchy Descriptor |
| 656 | // ?_R4 # RTTI Complete Object Locator |
| 657 | // ?_S # local vftable |
| 658 | // ?_T # local vftable constructor closure |
| 659 | // <operator-name> ::= ?_U # new[] |
| 660 | case OO_Array_New: Out << "?_U"; break; |
| 661 | // <operator-name> ::= ?_V # delete[] |
| 662 | case OO_Array_Delete: Out << "?_V"; break; |
| 663 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 664 | case OO_Conditional: { |
| 665 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 666 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 667 | "cannot mangle this conditional operator yet"); |
| 668 | Diags.Report(Loc, DiagID); |
| 669 | break; |
| 670 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 671 | |
| 672 | case OO_None: |
| 673 | case NUM_OVERLOADED_OPERATORS: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 674 | llvm_unreachable("Not an overloaded operator"); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
| 678 | void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |
| 679 | // <source name> ::= <identifier> @ |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 680 | std::string key = II->getNameStart(); |
| 681 | BackRefMap::iterator Found; |
| 682 | if (UseNameBackReferences) |
| 683 | Found = NameBackReferences.find(key); |
| 684 | if (!UseNameBackReferences || Found == NameBackReferences.end()) { |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 685 | Out << II->getName() << '@'; |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 686 | if (UseNameBackReferences && NameBackReferences.size() < 10) { |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 687 | size_t Size = NameBackReferences.size(); |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 688 | NameBackReferences[key] = Size; |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 689 | } |
| 690 | } else { |
| 691 | Out << Found->second; |
| 692 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 695 | void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) { |
| 696 | Context.mangleObjCMethodName(MD, Out); |
| 697 | } |
| 698 | |
| 699 | // Find out how many function decls live above this one and return an integer |
| 700 | // suitable for use as the number in a numbered anonymous scope. |
| 701 | // TODO: Memoize. |
| 702 | static unsigned getLocalNestingLevel(const FunctionDecl *FD) { |
| 703 | const DeclContext *DC = FD->getParent(); |
| 704 | int level = 1; |
| 705 | |
| 706 | while (DC && !DC->isTranslationUnit()) { |
| 707 | if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)) level++; |
| 708 | DC = DC->getParent(); |
| 709 | } |
| 710 | |
| 711 | return 2*level; |
| 712 | } |
| 713 | |
| 714 | void MicrosoftCXXNameMangler::mangleLocalName(const FunctionDecl *FD) { |
| 715 | // <nested-name> ::= <numbered-anonymous-scope> ? <mangled-name> |
| 716 | // <numbered-anonymous-scope> ::= ? <number> |
| 717 | // Even though the name is rendered in reverse order (e.g. |
| 718 | // A::B::C is rendered as C@B@A), VC numbers the scopes from outermost to |
| 719 | // innermost. So a method bar in class C local to function foo gets mangled |
| 720 | // as something like: |
| 721 | // ?bar@C@?1??foo@@YAXXZ@QAEXXZ |
| 722 | // This is more apparent when you have a type nested inside a method of a |
| 723 | // type nested inside a function. A method baz in class D local to method |
| 724 | // bar of class C local to function foo gets mangled as: |
| 725 | // ?baz@D@?3??bar@C@?1??foo@@YAXXZ@QAEXXZ@QAEXXZ |
| 726 | // This scheme is general enough to support GCC-style nested |
| 727 | // functions. You could have a method baz of class C inside a function bar |
| 728 | // inside a function foo, like so: |
| 729 | // ?baz@C@?3??bar@?1??foo@@YAXXZ@YAXXZ@QAEXXZ |
| 730 | int NestLevel = getLocalNestingLevel(FD); |
| 731 | Out << '?'; |
| 732 | mangleNumber(NestLevel); |
| 733 | Out << '?'; |
| 734 | mangle(FD, "?"); |
| 735 | } |
| 736 | |
| 737 | void MicrosoftCXXNameMangler::mangleTemplateInstantiationName( |
| 738 | const TemplateDecl *TD, |
| 739 | const SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs) { |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 740 | // <template-name> ::= <unscoped-template-name> <template-args> |
| 741 | // ::= <substitution> |
| 742 | // Always start with the unqualified name. |
Timur Iskhodzhanov | 4285f84 | 2012-06-26 22:29:50 +0000 | [diff] [blame] | 743 | |
| 744 | // Templates have their own context for back references. |
| 745 | BackRefMap TemplateContext; |
| 746 | NameBackReferences.swap(TemplateContext); |
| 747 | |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 748 | mangleUnscopedTemplateName(TD); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 749 | mangleTemplateArgs(TemplateArgs); |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 750 | |
Timur Iskhodzhanov | 4285f84 | 2012-06-26 22:29:50 +0000 | [diff] [blame] | 751 | NameBackReferences.swap(TemplateContext); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 754 | void |
| 755 | MicrosoftCXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *TD) { |
| 756 | // <unscoped-template-name> ::= ?$ <unqualified-name> |
| 757 | Out << "?$"; |
| 758 | mangleUnqualifiedName(TD); |
| 759 | } |
| 760 | |
| 761 | void |
Nico Weber | 0a26d76 | 2012-11-13 22:09:44 +0000 | [diff] [blame] | 762 | MicrosoftCXXNameMangler::mangleIntegerLiteral(const llvm::APSInt &Value, |
| 763 | bool IsBoolean) { |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 764 | // <integer-literal> ::= $0 <number> |
| 765 | Out << "$0"; |
| 766 | // Make sure booleans are encoded as 0/1. |
Nico Weber | 0a26d76 | 2012-11-13 22:09:44 +0000 | [diff] [blame] | 767 | if (IsBoolean && Value.getBoolValue()) |
| 768 | mangleNumber(1); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 769 | else |
| 770 | mangleNumber(Value); |
| 771 | } |
| 772 | |
| 773 | void |
Nico Weber | 2225556 | 2012-10-03 06:46:47 +0000 | [diff] [blame] | 774 | MicrosoftCXXNameMangler::mangleExpression(const Expr *E) { |
| 775 | // See if this is a constant expression. |
| 776 | llvm::APSInt Value; |
| 777 | if (E->isIntegerConstantExpr(Value, Context.getASTContext())) { |
Nico Weber | 0a26d76 | 2012-11-13 22:09:44 +0000 | [diff] [blame] | 778 | mangleIntegerLiteral(Value, E->getType()->isBooleanType()); |
Nico Weber | 2225556 | 2012-10-03 06:46:47 +0000 | [diff] [blame] | 779 | return; |
| 780 | } |
| 781 | |
| 782 | // As bad as this diagnostic is, it's better than crashing. |
| 783 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 784 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 785 | "cannot yet mangle expression type %0"); |
| 786 | Diags.Report(E->getExprLoc(), DiagID) |
| 787 | << E->getStmtClassName() << E->getSourceRange(); |
| 788 | } |
| 789 | |
| 790 | void |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 791 | MicrosoftCXXNameMangler::mangleTemplateArgs( |
| 792 | const SmallVectorImpl<TemplateArgumentLoc> &TemplateArgs) { |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 793 | // <template-args> ::= {<type> | <integer-literal>}+ @ |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 794 | unsigned NumTemplateArgs = TemplateArgs.size(); |
| 795 | for (unsigned i = 0; i < NumTemplateArgs; ++i) { |
| 796 | const TemplateArgumentLoc &TAL = TemplateArgs[i]; |
| 797 | const TemplateArgument &TA = TAL.getArgument(); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 798 | switch (TA.getKind()) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 799 | case TemplateArgument::Null: |
| 800 | llvm_unreachable("Can't mangle null template arguments!"); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 801 | case TemplateArgument::Type: |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 802 | mangleType(TA.getAsType(), TAL.getSourceRange()); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 803 | break; |
| 804 | case TemplateArgument::Integral: |
Nico Weber | 0a26d76 | 2012-11-13 22:09:44 +0000 | [diff] [blame] | 805 | mangleIntegerLiteral(TA.getAsIntegral(), |
| 806 | TA.getIntegralType()->isBooleanType()); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 807 | break; |
Nico Weber | 2225556 | 2012-10-03 06:46:47 +0000 | [diff] [blame] | 808 | case TemplateArgument::Expression: |
| 809 | mangleExpression(TA.getAsExpr()); |
| 810 | break; |
Nico Weber | 88a374a | 2012-10-03 06:12:27 +0000 | [diff] [blame] | 811 | case TemplateArgument::Template: |
| 812 | case TemplateArgument::TemplateExpansion: |
| 813 | case TemplateArgument::Declaration: |
| 814 | case TemplateArgument::NullPtr: |
| 815 | case TemplateArgument::Pack: { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 816 | // Issue a diagnostic. |
| 817 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 818 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
Nico Weber | c950bc9 | 2012-10-03 06:57:02 +0000 | [diff] [blame] | 819 | "cannot mangle this %select{ERROR|ERROR|pointer/reference|nullptr|" |
| 820 | "integral|template|template pack expansion|ERROR|parameter pack}0 " |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 821 | "template argument yet"); |
| 822 | Diags.Report(TAL.getLocation(), DiagID) |
| 823 | << TA.getKind() |
| 824 | << TAL.getSourceRange(); |
Charles Davis | 9fd2359 | 2012-05-26 23:12:19 +0000 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | } |
| 828 | Out << '@'; |
| 829 | } |
| 830 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 831 | void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals, |
| 832 | bool IsMember) { |
| 833 | // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers> |
| 834 | // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only); |
| 835 | // 'I' means __restrict (32/64-bit). |
| 836 | // Note that the MSVC __restrict keyword isn't the same as the C99 restrict |
| 837 | // keyword! |
| 838 | // <base-cvr-qualifiers> ::= A # near |
| 839 | // ::= B # near const |
| 840 | // ::= C # near volatile |
| 841 | // ::= D # near const volatile |
| 842 | // ::= E # far (16-bit) |
| 843 | // ::= F # far const (16-bit) |
| 844 | // ::= G # far volatile (16-bit) |
| 845 | // ::= H # far const volatile (16-bit) |
| 846 | // ::= I # huge (16-bit) |
| 847 | // ::= J # huge const (16-bit) |
| 848 | // ::= K # huge volatile (16-bit) |
| 849 | // ::= L # huge const volatile (16-bit) |
| 850 | // ::= M <basis> # based |
| 851 | // ::= N <basis> # based const |
| 852 | // ::= O <basis> # based volatile |
| 853 | // ::= P <basis> # based const volatile |
| 854 | // ::= Q # near member |
| 855 | // ::= R # near const member |
| 856 | // ::= S # near volatile member |
| 857 | // ::= T # near const volatile member |
| 858 | // ::= U # far member (16-bit) |
| 859 | // ::= V # far const member (16-bit) |
| 860 | // ::= W # far volatile member (16-bit) |
| 861 | // ::= X # far const volatile member (16-bit) |
| 862 | // ::= Y # huge member (16-bit) |
| 863 | // ::= Z # huge const member (16-bit) |
| 864 | // ::= 0 # huge volatile member (16-bit) |
| 865 | // ::= 1 # huge const volatile member (16-bit) |
| 866 | // ::= 2 <basis> # based member |
| 867 | // ::= 3 <basis> # based const member |
| 868 | // ::= 4 <basis> # based volatile member |
| 869 | // ::= 5 <basis> # based const volatile member |
| 870 | // ::= 6 # near function (pointers only) |
| 871 | // ::= 7 # far function (pointers only) |
| 872 | // ::= 8 # near method (pointers only) |
| 873 | // ::= 9 # far method (pointers only) |
| 874 | // ::= _A <basis> # based function (pointers only) |
| 875 | // ::= _B <basis> # based function (far?) (pointers only) |
| 876 | // ::= _C <basis> # based method (pointers only) |
| 877 | // ::= _D <basis> # based method (far?) (pointers only) |
| 878 | // ::= _E # block (Clang) |
| 879 | // <basis> ::= 0 # __based(void) |
| 880 | // ::= 1 # __based(segment)? |
| 881 | // ::= 2 <name> # __based(name) |
| 882 | // ::= 3 # ? |
| 883 | // ::= 4 # ? |
| 884 | // ::= 5 # not really based |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 885 | bool HasConst = Quals.hasConst(), |
| 886 | HasVolatile = Quals.hasVolatile(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 887 | if (!IsMember) { |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 888 | if (HasConst && HasVolatile) { |
| 889 | Out << 'D'; |
| 890 | } else if (HasVolatile) { |
| 891 | Out << 'C'; |
| 892 | } else if (HasConst) { |
| 893 | Out << 'B'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 894 | } else { |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 895 | Out << 'A'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 896 | } |
| 897 | } else { |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 898 | if (HasConst && HasVolatile) { |
| 899 | Out << 'T'; |
| 900 | } else if (HasVolatile) { |
| 901 | Out << 'S'; |
| 902 | } else if (HasConst) { |
| 903 | Out << 'R'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 904 | } else { |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 905 | Out << 'Q'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
| 909 | // FIXME: For now, just drop all extension qualifiers on the floor. |
| 910 | } |
| 911 | |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 912 | void MicrosoftCXXNameMangler::manglePointerQualifiers(Qualifiers Quals) { |
| 913 | // <pointer-cvr-qualifiers> ::= P # no qualifiers |
| 914 | // ::= Q # const |
| 915 | // ::= R # volatile |
| 916 | // ::= S # const volatile |
| 917 | bool HasConst = Quals.hasConst(), |
| 918 | HasVolatile = Quals.hasVolatile(); |
| 919 | if (HasConst && HasVolatile) { |
| 920 | Out << 'S'; |
| 921 | } else if (HasVolatile) { |
| 922 | Out << 'R'; |
| 923 | } else if (HasConst) { |
| 924 | Out << 'Q'; |
| 925 | } else { |
| 926 | Out << 'P'; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | void MicrosoftCXXNameMangler::mangleArgumentType(QualType T, |
| 931 | SourceRange Range) { |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 932 | void *TypePtr = getASTContext().getCanonicalType(T).getAsOpaquePtr(); |
Timur Iskhodzhanov | f5e0b22 | 2012-07-24 09:37:54 +0000 | [diff] [blame] | 933 | ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr); |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 934 | |
| 935 | if (Found == TypeBackReferences.end()) { |
| 936 | size_t OutSizeBefore = Out.GetNumBytesInBuffer(); |
| 937 | |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 938 | mangleType(T, Range, false); |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 939 | |
| 940 | // See if it's worth creating a back reference. |
| 941 | // Only types longer than 1 character are considered |
| 942 | // and only 10 back references slots are available: |
| 943 | bool LongerThanOneChar = (Out.GetNumBytesInBuffer() - OutSizeBefore > 1); |
| 944 | if (LongerThanOneChar && TypeBackReferences.size() < 10) { |
| 945 | size_t Size = TypeBackReferences.size(); |
| 946 | TypeBackReferences[TypePtr] = Size; |
| 947 | } |
| 948 | } else { |
| 949 | Out << Found->second; |
| 950 | } |
| 951 | } |
| 952 | |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 953 | void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range, |
| 954 | bool MangleQualifiers) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 955 | // Only operate on the canonical type! |
| 956 | T = getASTContext().getCanonicalType(T); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 957 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 958 | Qualifiers Quals = T.getLocalQualifiers(); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 959 | // We have to mangle these now, while we still have enough information. |
| 960 | if (T->isAnyPointerType() || T->isMemberPointerType() || |
| 961 | T->isBlockPointerType()) { |
| 962 | manglePointerQualifiers(Quals); |
| 963 | } else if (Quals && MangleQualifiers) { |
| 964 | mangleQualifiers(Quals, false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 965 | } |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 966 | |
| 967 | SplitQualType split = T.split(); |
| 968 | const Type *ty = split.Ty; |
| 969 | |
| 970 | // If we're mangling a qualified array type, push the qualifiers to |
| 971 | // the element type. |
| 972 | if (split.Quals && isa<ArrayType>(T)) { |
| 973 | ty = Context.getASTContext().getAsArrayType(T); |
| 974 | } |
| 975 | |
| 976 | switch (ty->getTypeClass()) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 977 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 978 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 979 | case Type::CLASS: \ |
| 980 | llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
| 981 | return; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 982 | #define TYPE(CLASS, PARENT) \ |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 983 | case Type::CLASS: \ |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 984 | mangleType(cast<CLASS##Type>(ty), Range); \ |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 985 | break; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 986 | #include "clang/AST/TypeNodes.def" |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 987 | #undef ABSTRACT_TYPE |
| 988 | #undef NON_CANONICAL_TYPE |
| 989 | #undef TYPE |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 993 | void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, |
| 994 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 995 | // <type> ::= <builtin-type> |
| 996 | // <builtin-type> ::= X # void |
| 997 | // ::= C # signed char |
| 998 | // ::= D # char |
| 999 | // ::= E # unsigned char |
| 1000 | // ::= F # short |
| 1001 | // ::= G # unsigned short (or wchar_t if it's not a builtin) |
| 1002 | // ::= H # int |
| 1003 | // ::= I # unsigned int |
| 1004 | // ::= J # long |
| 1005 | // ::= K # unsigned long |
| 1006 | // L # <none> |
| 1007 | // ::= M # float |
| 1008 | // ::= N # double |
| 1009 | // ::= O # long double (__float80 is mangled differently) |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1010 | // ::= _J # long long, __int64 |
| 1011 | // ::= _K # unsigned long long, __int64 |
| 1012 | // ::= _L # __int128 |
| 1013 | // ::= _M # unsigned __int128 |
| 1014 | // ::= _N # bool |
| 1015 | // _O # <array in parameter> |
| 1016 | // ::= _T # __float80 (Intel) |
| 1017 | // ::= _W # wchar_t |
| 1018 | // ::= _Z # __float80 (Digital Mars) |
| 1019 | switch (T->getKind()) { |
| 1020 | case BuiltinType::Void: Out << 'X'; break; |
| 1021 | case BuiltinType::SChar: Out << 'C'; break; |
| 1022 | case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break; |
| 1023 | case BuiltinType::UChar: Out << 'E'; break; |
| 1024 | case BuiltinType::Short: Out << 'F'; break; |
| 1025 | case BuiltinType::UShort: Out << 'G'; break; |
| 1026 | case BuiltinType::Int: Out << 'H'; break; |
| 1027 | case BuiltinType::UInt: Out << 'I'; break; |
| 1028 | case BuiltinType::Long: Out << 'J'; break; |
| 1029 | case BuiltinType::ULong: Out << 'K'; break; |
| 1030 | case BuiltinType::Float: Out << 'M'; break; |
| 1031 | case BuiltinType::Double: Out << 'N'; break; |
| 1032 | // TODO: Determine size and mangle accordingly |
| 1033 | case BuiltinType::LongDouble: Out << 'O'; break; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1034 | case BuiltinType::LongLong: Out << "_J"; break; |
| 1035 | case BuiltinType::ULongLong: Out << "_K"; break; |
| 1036 | case BuiltinType::Int128: Out << "_L"; break; |
| 1037 | case BuiltinType::UInt128: Out << "_M"; break; |
| 1038 | case BuiltinType::Bool: Out << "_N"; break; |
| 1039 | case BuiltinType::WChar_S: |
| 1040 | case BuiltinType::WChar_U: Out << "_W"; break; |
| 1041 | |
John McCall | e0a22d0 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1042 | #define BUILTIN_TYPE(Id, SingletonId) |
| 1043 | #define PLACEHOLDER_TYPE(Id, SingletonId) \ |
| 1044 | case BuiltinType::Id: |
| 1045 | #include "clang/AST/BuiltinTypes.def" |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1046 | case BuiltinType::Dependent: |
John McCall | e0a22d0 | 2011-10-18 21:02:43 +0000 | [diff] [blame] | 1047 | llvm_unreachable("placeholder types shouldn't get to name mangling"); |
| 1048 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1049 | case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break; |
| 1050 | case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break; |
| 1051 | case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break; |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1052 | |
| 1053 | case BuiltinType::NullPtr: Out << "$$T"; break; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1054 | |
| 1055 | case BuiltinType::Char16: |
| 1056 | case BuiltinType::Char32: |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1057 | case BuiltinType::Half: { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1058 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1059 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1060 | "cannot mangle this built-in %0 type yet"); |
| 1061 | Diags.Report(Range.getBegin(), DiagID) |
| 1062 | << T->getName(Context.getASTContext().getPrintingPolicy()) |
| 1063 | << Range; |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1064 | break; |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1065 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | // <type> ::= <function-type> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1070 | void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, |
| 1071 | SourceRange) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1072 | // Structors only appear in decls, so at this point we know it's not a |
| 1073 | // structor type. |
John McCall | 2612e9f | 2012-08-25 01:12:56 +0000 | [diff] [blame] | 1074 | // FIXME: This may not be lambda-friendly. |
| 1075 | Out << "$$A6"; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1076 | mangleType(T, NULL, false, false); |
| 1077 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1078 | void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T, |
| 1079 | SourceRange) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1080 | llvm_unreachable("Can't mangle K&R function prototypes"); |
| 1081 | } |
| 1082 | |
| 1083 | void MicrosoftCXXNameMangler::mangleType(const FunctionType *T, |
| 1084 | const FunctionDecl *D, |
| 1085 | bool IsStructor, |
| 1086 | bool IsInstMethod) { |
| 1087 | // <function-type> ::= <this-cvr-qualifiers> <calling-convention> |
| 1088 | // <return-type> <argument-list> <throw-spec> |
| 1089 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 1090 | |
| 1091 | // If this is a C++ instance method, mangle the CVR qualifiers for the |
| 1092 | // this pointer. |
| 1093 | if (IsInstMethod) |
| 1094 | mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false); |
| 1095 | |
| 1096 | mangleCallingConvention(T, IsInstMethod); |
| 1097 | |
| 1098 | // <return-type> ::= <type> |
| 1099 | // ::= @ # structors (they have no declared return type) |
| 1100 | if (IsStructor) |
| 1101 | Out << '@'; |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1102 | else { |
| 1103 | QualType Result = Proto->getResultType(); |
| 1104 | const Type* RT = Result.getTypePtr(); |
Timur Iskhodzhanov | dc6dabc | 2012-07-26 10:41:15 +0000 | [diff] [blame] | 1105 | if (!RT->isAnyPointerType() && !RT->isReferenceType()) { |
| 1106 | if (Result.hasQualifiers() || !RT->isBuiltinType()) |
| 1107 | Out << '?'; |
| 1108 | if (!RT->isBuiltinType() && !Result.hasQualifiers()) { |
| 1109 | // Lack of qualifiers for user types is mangled as 'A'. |
| 1110 | Out << 'A'; |
| 1111 | } |
| 1112 | } |
| 1113 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1114 | // FIXME: Get the source range for the result type. Or, better yet, |
| 1115 | // implement the unimplemented stuff so we don't need accurate source |
| 1116 | // location info anymore :). |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1117 | mangleType(Result, SourceRange()); |
| 1118 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1119 | |
| 1120 | // <argument-list> ::= X # void |
| 1121 | // ::= <type>+ @ |
| 1122 | // ::= <type>* Z # varargs |
| 1123 | if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) { |
| 1124 | Out << 'X'; |
| 1125 | } else { |
| 1126 | if (D) { |
John McCall | 3a8ac07 | 2012-05-01 02:33:44 +0000 | [diff] [blame] | 1127 | // If we got a decl, use the type-as-written to make sure arrays |
| 1128 | // get mangled right. Note that we can't rely on the TSI |
| 1129 | // existing if (for example) the parameter was synthesized. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1130 | for (FunctionDecl::param_const_iterator Parm = D->param_begin(), |
John McCall | 3a8ac07 | 2012-05-01 02:33:44 +0000 | [diff] [blame] | 1131 | ParmEnd = D->param_end(); Parm != ParmEnd; ++Parm) { |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1132 | TypeSourceInfo *TSI = (*Parm)->getTypeSourceInfo(); |
| 1133 | QualType Type = TSI ? TSI->getType() : (*Parm)->getType(); |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1134 | mangleArgumentType(Type, (*Parm)->getSourceRange()); |
John McCall | 3a8ac07 | 2012-05-01 02:33:44 +0000 | [diff] [blame] | 1135 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1136 | } else { |
Timur Iskhodzhanov | 3f83568 | 2012-06-23 00:54:17 +0000 | [diff] [blame] | 1137 | // Happens for function pointer type arguments for example. |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1138 | for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), |
| 1139 | ArgEnd = Proto->arg_type_end(); |
| 1140 | Arg != ArgEnd; ++Arg) |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1141 | mangleArgumentType(*Arg, SourceRange()); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1142 | } |
| 1143 | // <builtin-type> ::= Z # ellipsis |
| 1144 | if (Proto->isVariadic()) |
| 1145 | Out << 'Z'; |
| 1146 | else |
| 1147 | Out << '@'; |
| 1148 | } |
| 1149 | |
| 1150 | mangleThrowSpecification(Proto); |
| 1151 | } |
| 1152 | |
| 1153 | void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { |
| 1154 | // <function-class> ::= A # private: near |
| 1155 | // ::= B # private: far |
| 1156 | // ::= C # private: static near |
| 1157 | // ::= D # private: static far |
| 1158 | // ::= E # private: virtual near |
| 1159 | // ::= F # private: virtual far |
| 1160 | // ::= G # private: thunk near |
| 1161 | // ::= H # private: thunk far |
| 1162 | // ::= I # protected: near |
| 1163 | // ::= J # protected: far |
| 1164 | // ::= K # protected: static near |
| 1165 | // ::= L # protected: static far |
| 1166 | // ::= M # protected: virtual near |
| 1167 | // ::= N # protected: virtual far |
| 1168 | // ::= O # protected: thunk near |
| 1169 | // ::= P # protected: thunk far |
| 1170 | // ::= Q # public: near |
| 1171 | // ::= R # public: far |
| 1172 | // ::= S # public: static near |
| 1173 | // ::= T # public: static far |
| 1174 | // ::= U # public: virtual near |
| 1175 | // ::= V # public: virtual far |
| 1176 | // ::= W # public: thunk near |
| 1177 | // ::= X # public: thunk far |
| 1178 | // ::= Y # global near |
| 1179 | // ::= Z # global far |
| 1180 | if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) { |
| 1181 | switch (MD->getAccess()) { |
| 1182 | default: |
| 1183 | case AS_private: |
| 1184 | if (MD->isStatic()) |
| 1185 | Out << 'C'; |
| 1186 | else if (MD->isVirtual()) |
| 1187 | Out << 'E'; |
| 1188 | else |
| 1189 | Out << 'A'; |
| 1190 | break; |
| 1191 | case AS_protected: |
| 1192 | if (MD->isStatic()) |
| 1193 | Out << 'K'; |
| 1194 | else if (MD->isVirtual()) |
| 1195 | Out << 'M'; |
| 1196 | else |
| 1197 | Out << 'I'; |
| 1198 | break; |
| 1199 | case AS_public: |
| 1200 | if (MD->isStatic()) |
| 1201 | Out << 'S'; |
| 1202 | else if (MD->isVirtual()) |
| 1203 | Out << 'U'; |
| 1204 | else |
| 1205 | Out << 'Q'; |
| 1206 | } |
| 1207 | } else |
| 1208 | Out << 'Y'; |
| 1209 | } |
| 1210 | void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T, |
| 1211 | bool IsInstMethod) { |
| 1212 | // <calling-convention> ::= A # __cdecl |
| 1213 | // ::= B # __export __cdecl |
| 1214 | // ::= C # __pascal |
| 1215 | // ::= D # __export __pascal |
| 1216 | // ::= E # __thiscall |
| 1217 | // ::= F # __export __thiscall |
| 1218 | // ::= G # __stdcall |
| 1219 | // ::= H # __export __stdcall |
| 1220 | // ::= I # __fastcall |
| 1221 | // ::= J # __export __fastcall |
| 1222 | // The 'export' calling conventions are from a bygone era |
| 1223 | // (*cough*Win16*cough*) when functions were declared for export with |
| 1224 | // that keyword. (It didn't actually export them, it just made them so |
| 1225 | // that they could be in a DLL and somebody from another module could call |
| 1226 | // them.) |
| 1227 | CallingConv CC = T->getCallConv(); |
Timur Iskhodzhanov | 8f88a1d | 2012-07-12 09:50:54 +0000 | [diff] [blame] | 1228 | if (CC == CC_Default) { |
| 1229 | if (IsInstMethod) { |
| 1230 | const FunctionProtoType *FPT = |
John McCall | 2612e9f | 2012-08-25 01:12:56 +0000 | [diff] [blame] | 1231 | T->getCanonicalTypeUnqualified().castAs<FunctionProtoType>(); |
Timur Iskhodzhanov | 8f88a1d | 2012-07-12 09:50:54 +0000 | [diff] [blame] | 1232 | bool isVariadic = FPT->isVariadic(); |
| 1233 | CC = getASTContext().getDefaultCXXMethodCallConv(isVariadic); |
| 1234 | } else { |
| 1235 | CC = CC_C; |
| 1236 | } |
| 1237 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1238 | switch (CC) { |
Anton Korobeynikov | 414d896 | 2011-04-14 20:06:49 +0000 | [diff] [blame] | 1239 | default: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 1240 | llvm_unreachable("Unsupported CC for mangling"); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1241 | case CC_Default: |
| 1242 | case CC_C: Out << 'A'; break; |
| 1243 | case CC_X86Pascal: Out << 'C'; break; |
| 1244 | case CC_X86ThisCall: Out << 'E'; break; |
| 1245 | case CC_X86StdCall: Out << 'G'; break; |
| 1246 | case CC_X86FastCall: Out << 'I'; break; |
| 1247 | } |
| 1248 | } |
| 1249 | void MicrosoftCXXNameMangler::mangleThrowSpecification( |
| 1250 | const FunctionProtoType *FT) { |
| 1251 | // <throw-spec> ::= Z # throw(...) (default) |
| 1252 | // ::= @ # throw() or __declspec/__attribute__((nothrow)) |
| 1253 | // ::= <type>+ |
| 1254 | // NOTE: Since the Microsoft compiler ignores throw specifications, they are |
| 1255 | // all actually mangled as 'Z'. (They're ignored because their associated |
| 1256 | // functionality isn't implemented, and probably never will be.) |
| 1257 | Out << 'Z'; |
| 1258 | } |
| 1259 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1260 | void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T, |
| 1261 | SourceRange Range) { |
| 1262 | // Probably should be mangled as a template instantiation; need to see what |
| 1263 | // VC does first. |
| 1264 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1265 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1266 | "cannot mangle this unresolved dependent type yet"); |
| 1267 | Diags.Report(Range.getBegin(), DiagID) |
| 1268 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | // <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type> |
| 1272 | // <union-type> ::= T <name> |
| 1273 | // <struct-type> ::= U <name> |
| 1274 | // <class-type> ::= V <name> |
| 1275 | // <enum-type> ::= W <size> <name> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1276 | void MicrosoftCXXNameMangler::mangleType(const EnumType *T, SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1277 | mangleType(cast<TagType>(T)); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1278 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1279 | void MicrosoftCXXNameMangler::mangleType(const RecordType *T, SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1280 | mangleType(cast<TagType>(T)); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1281 | } |
| 1282 | void MicrosoftCXXNameMangler::mangleType(const TagType *T) { |
| 1283 | switch (T->getDecl()->getTagKind()) { |
| 1284 | case TTK_Union: |
Joao Matos | 17d35c3 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 1285 | Out << 'T'; |
| 1286 | break; |
| 1287 | case TTK_Struct: |
| 1288 | case TTK_Interface: |
| 1289 | Out << 'U'; |
| 1290 | break; |
| 1291 | case TTK_Class: |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1292 | Out << 'V'; |
| 1293 | break; |
| 1294 | case TTK_Enum: |
| 1295 | Out << 'W'; |
| 1296 | Out << getASTContext().getTypeSizeInChars( |
| 1297 | cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity(); |
| 1298 | break; |
| 1299 | } |
| 1300 | mangleName(T->getDecl()); |
| 1301 | } |
| 1302 | |
| 1303 | // <type> ::= <array-type> |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1304 | // <array-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> |
| 1305 | // [Y <dimension-count> <dimension>+] |
| 1306 | // <element-type> # as global |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1307 | // ::= Q <cvr-qualifiers> [Y <dimension-count> <dimension>+] |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1308 | // <element-type> # as param |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1309 | // It's supposed to be the other way around, but for some strange reason, it |
| 1310 | // isn't. Today this behavior is retained for the sole purpose of backwards |
| 1311 | // compatibility. |
| 1312 | void MicrosoftCXXNameMangler::mangleType(const ArrayType *T, bool IsGlobal) { |
| 1313 | // This isn't a recursive mangling, so now we have to do it all in this |
| 1314 | // one call. |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1315 | if (IsGlobal) { |
| 1316 | manglePointerQualifiers(T->getElementType().getQualifiers()); |
| 1317 | } else { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1318 | Out << 'Q'; |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1319 | } |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1320 | mangleExtraDimensions(T->getElementType()); |
| 1321 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1322 | void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T, |
| 1323 | SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1324 | mangleType(cast<ArrayType>(T), false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1325 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1326 | void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T, |
| 1327 | SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1328 | mangleType(cast<ArrayType>(T), false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1329 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1330 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T, |
| 1331 | SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1332 | mangleType(cast<ArrayType>(T), false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1333 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1334 | void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T, |
| 1335 | SourceRange) { |
John McCall | efe97d6 | 2012-08-27 18:12:29 +0000 | [diff] [blame] | 1336 | mangleType(cast<ArrayType>(T), false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1337 | } |
| 1338 | void MicrosoftCXXNameMangler::mangleExtraDimensions(QualType ElementTy) { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1339 | SmallVector<llvm::APInt, 3> Dimensions; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1340 | for (;;) { |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1341 | if (const ConstantArrayType *CAT = |
| 1342 | getASTContext().getAsConstantArrayType(ElementTy)) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1343 | Dimensions.push_back(CAT->getSize()); |
| 1344 | ElementTy = CAT->getElementType(); |
| 1345 | } else if (ElementTy->isVariableArrayType()) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1346 | const VariableArrayType *VAT = |
| 1347 | getASTContext().getAsVariableArrayType(ElementTy); |
| 1348 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1349 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1350 | "cannot mangle this variable-length array yet"); |
| 1351 | Diags.Report(VAT->getSizeExpr()->getExprLoc(), DiagID) |
| 1352 | << VAT->getBracketsRange(); |
| 1353 | return; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1354 | } else if (ElementTy->isDependentSizedArrayType()) { |
| 1355 | // The dependent expression has to be folded into a constant (TODO). |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1356 | const DependentSizedArrayType *DSAT = |
| 1357 | getASTContext().getAsDependentSizedArrayType(ElementTy); |
| 1358 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1359 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1360 | "cannot mangle this dependent-length array yet"); |
| 1361 | Diags.Report(DSAT->getSizeExpr()->getExprLoc(), DiagID) |
| 1362 | << DSAT->getBracketsRange(); |
| 1363 | return; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1364 | } else if (ElementTy->isIncompleteArrayType()) continue; |
| 1365 | else break; |
| 1366 | } |
| 1367 | mangleQualifiers(ElementTy.getQualifiers(), false); |
| 1368 | // If there are any additional dimensions, mangle them now. |
| 1369 | if (Dimensions.size() > 0) { |
| 1370 | Out << 'Y'; |
| 1371 | // <dimension-count> ::= <number> # number of extra dimensions |
| 1372 | mangleNumber(Dimensions.size()); |
| 1373 | for (unsigned Dim = 0; Dim < Dimensions.size(); ++Dim) { |
| 1374 | mangleNumber(Dimensions[Dim].getLimitedValue()); |
| 1375 | } |
| 1376 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1377 | mangleType(ElementTy.getLocalUnqualifiedType(), SourceRange()); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1378 | } |
| 1379 | |
| 1380 | // <type> ::= <pointer-to-member-type> |
| 1381 | // <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> |
| 1382 | // <class name> <type> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1383 | void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T, |
| 1384 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1385 | QualType PointeeType = T->getPointeeType(); |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1386 | if (const FunctionProtoType *FPT = PointeeType->getAs<FunctionProtoType>()) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1387 | Out << '8'; |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1388 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1389 | mangleType(FPT, NULL, false, true); |
| 1390 | } else { |
| 1391 | mangleQualifiers(PointeeType.getQualifiers(), true); |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1392 | mangleName(T->getClass()->castAs<RecordType>()->getDecl()); |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1393 | mangleType(PointeeType.getLocalUnqualifiedType(), Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1397 | void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T, |
| 1398 | SourceRange Range) { |
| 1399 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1400 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1401 | "cannot mangle this template type parameter type yet"); |
| 1402 | Diags.Report(Range.getBegin(), DiagID) |
| 1403 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1406 | void MicrosoftCXXNameMangler::mangleType( |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1407 | const SubstTemplateTypeParmPackType *T, |
| 1408 | SourceRange Range) { |
| 1409 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1410 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1411 | "cannot mangle this substituted parameter pack yet"); |
| 1412 | Diags.Report(Range.getBegin(), DiagID) |
| 1413 | << Range; |
Douglas Gregor | c3069d6 | 2011-01-14 02:55:32 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1416 | // <type> ::= <pointer-type> |
| 1417 | // <pointer-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> <type> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1418 | void MicrosoftCXXNameMangler::mangleType(const PointerType *T, |
| 1419 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1420 | QualType PointeeTy = T->getPointeeType(); |
| 1421 | if (PointeeTy->isArrayType()) { |
| 1422 | // Pointers to arrays are mangled like arrays. |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1423 | mangleExtraDimensions(PointeeTy); |
| 1424 | } else if (const FunctionType *FT = PointeeTy->getAs<FunctionType>()) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1425 | // Function pointers are special. |
| 1426 | Out << '6'; |
Richard Smith | c0838d2 | 2012-06-08 00:37:04 +0000 | [diff] [blame] | 1427 | mangleType(FT, NULL, false, false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1428 | } else { |
Timur Iskhodzhanov | a04ca5c | 2012-09-03 09:08:10 +0000 | [diff] [blame] | 1429 | mangleQualifiers(PointeeTy.getQualifiers(), false); |
| 1430 | mangleType(PointeeTy, Range, false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1433 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T, |
| 1434 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1435 | // Object pointers never have qualifiers. |
| 1436 | Out << 'A'; |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1437 | mangleType(T->getPointeeType(), Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | // <type> ::= <reference-type> |
| 1441 | // <reference-type> ::= A <cvr-qualifiers> <type> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1442 | void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T, |
| 1443 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1444 | Out << 'A'; |
| 1445 | QualType PointeeTy = T->getPointeeType(); |
| 1446 | if (!PointeeTy.hasQualifiers()) |
| 1447 | // Lack of qualifiers is mangled as 'A'. |
| 1448 | Out << 'A'; |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1449 | mangleType(PointeeTy, Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1452 | // <type> ::= <r-value-reference-type> |
| 1453 | // <r-value-reference-type> ::= $$Q <cvr-qualifiers> <type> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1454 | void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T, |
| 1455 | SourceRange Range) { |
Richard Smith | 06e767d | 2012-06-21 02:52:27 +0000 | [diff] [blame] | 1456 | Out << "$$Q"; |
| 1457 | QualType PointeeTy = T->getPointeeType(); |
| 1458 | if (!PointeeTy.hasQualifiers()) |
| 1459 | // Lack of qualifiers is mangled as 'A'. |
| 1460 | Out << 'A'; |
| 1461 | mangleType(PointeeTy, Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1464 | void MicrosoftCXXNameMangler::mangleType(const ComplexType *T, |
| 1465 | SourceRange Range) { |
| 1466 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1467 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1468 | "cannot mangle this complex number type yet"); |
| 1469 | Diags.Report(Range.getBegin(), DiagID) |
| 1470 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1473 | void MicrosoftCXXNameMangler::mangleType(const VectorType *T, |
| 1474 | SourceRange Range) { |
| 1475 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1476 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1477 | "cannot mangle this vector type yet"); |
| 1478 | Diags.Report(Range.getBegin(), DiagID) |
| 1479 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1480 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1481 | void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T, |
| 1482 | SourceRange Range) { |
| 1483 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1484 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1485 | "cannot mangle this extended vector type yet"); |
| 1486 | Diags.Report(Range.getBegin(), DiagID) |
| 1487 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1488 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1489 | void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T, |
| 1490 | SourceRange Range) { |
| 1491 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1492 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1493 | "cannot mangle this dependent-sized extended vector type yet"); |
| 1494 | Diags.Report(Range.getBegin(), DiagID) |
| 1495 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1498 | void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, |
| 1499 | SourceRange) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1500 | // ObjC interfaces have structs underlying them. |
| 1501 | Out << 'U'; |
| 1502 | mangleName(T->getDecl()); |
| 1503 | } |
| 1504 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1505 | void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, |
| 1506 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1507 | // We don't allow overloading by different protocol qualification, |
| 1508 | // so mangling them isn't necessary. |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1509 | mangleType(T->getBaseType(), Range); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1512 | void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T, |
| 1513 | SourceRange Range) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1514 | Out << "_E"; |
John McCall | 2612e9f | 2012-08-25 01:12:56 +0000 | [diff] [blame] | 1515 | |
| 1516 | QualType pointee = T->getPointeeType(); |
| 1517 | mangleType(pointee->castAs<FunctionProtoType>(), NULL, false, false); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1520 | void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T, |
| 1521 | SourceRange Range) { |
| 1522 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1523 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1524 | "cannot mangle this injected class name type yet"); |
| 1525 | Diags.Report(Range.getBegin(), DiagID) |
| 1526 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1527 | } |
| 1528 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1529 | void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T, |
| 1530 | SourceRange Range) { |
| 1531 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1532 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1533 | "cannot mangle this template specialization type yet"); |
| 1534 | Diags.Report(Range.getBegin(), DiagID) |
| 1535 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1538 | void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T, |
| 1539 | SourceRange Range) { |
| 1540 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1541 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1542 | "cannot mangle this dependent name type yet"); |
| 1543 | Diags.Report(Range.getBegin(), DiagID) |
| 1544 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | void MicrosoftCXXNameMangler::mangleType( |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1548 | const DependentTemplateSpecializationType *T, |
| 1549 | SourceRange Range) { |
| 1550 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1551 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1552 | "cannot mangle this dependent template specialization type yet"); |
| 1553 | Diags.Report(Range.getBegin(), DiagID) |
| 1554 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1557 | void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T, |
| 1558 | SourceRange Range) { |
| 1559 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1560 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1561 | "cannot mangle this pack expansion yet"); |
| 1562 | Diags.Report(Range.getBegin(), DiagID) |
| 1563 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1566 | void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T, |
| 1567 | SourceRange Range) { |
| 1568 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1569 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1570 | "cannot mangle this typeof(type) yet"); |
| 1571 | Diags.Report(Range.getBegin(), DiagID) |
| 1572 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1573 | } |
| 1574 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1575 | void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T, |
| 1576 | SourceRange Range) { |
| 1577 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1578 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1579 | "cannot mangle this typeof(expression) yet"); |
| 1580 | Diags.Report(Range.getBegin(), DiagID) |
| 1581 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1584 | void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T, |
| 1585 | SourceRange Range) { |
| 1586 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1587 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1588 | "cannot mangle this decltype() yet"); |
| 1589 | Diags.Report(Range.getBegin(), DiagID) |
| 1590 | << Range; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1593 | void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T, |
| 1594 | SourceRange Range) { |
| 1595 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1596 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1597 | "cannot mangle this unary transform type yet"); |
| 1598 | Diags.Report(Range.getBegin(), DiagID) |
| 1599 | << Range; |
Sean Hunt | ca63c20 | 2011-05-24 22:41:36 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1602 | void MicrosoftCXXNameMangler::mangleType(const AutoType *T, SourceRange Range) { |
| 1603 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1604 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1605 | "cannot mangle this 'auto' type yet"); |
| 1606 | Diags.Report(Range.getBegin(), DiagID) |
| 1607 | << Range; |
Richard Smith | 34b41d9 | 2011-02-20 03:19:35 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1610 | void MicrosoftCXXNameMangler::mangleType(const AtomicType *T, |
| 1611 | SourceRange Range) { |
| 1612 | DiagnosticsEngine &Diags = Context.getDiags(); |
| 1613 | unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error, |
| 1614 | "cannot mangle this C11 atomic type yet"); |
| 1615 | Diags.Report(Range.getBegin(), DiagID) |
| 1616 | << Range; |
Eli Friedman | b001de7 | 2011-10-06 23:00:33 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1619 | void MicrosoftMangleContext::mangleName(const NamedDecl *D, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1620 | raw_ostream &Out) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1621 | assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) && |
| 1622 | "Invalid mangleName() call, argument is not a variable or function!"); |
| 1623 | assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) && |
| 1624 | "Invalid mangleName() call on 'structor decl!"); |
| 1625 | |
| 1626 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), |
| 1627 | getASTContext().getSourceManager(), |
| 1628 | "Mangling declaration"); |
| 1629 | |
Rafael Espindola | c4850c2 | 2011-02-10 23:59:36 +0000 | [diff] [blame] | 1630 | MicrosoftCXXNameMangler Mangler(*this, Out); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1631 | return Mangler.mangle(D); |
| 1632 | } |
| 1633 | void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD, |
| 1634 | const ThunkInfo &Thunk, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1635 | raw_ostream &) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1636 | unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, |
| 1637 | "cannot mangle thunk for this method yet"); |
| 1638 | getDiags().Report(MD->getLocation(), DiagID); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1639 | } |
| 1640 | void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD, |
| 1641 | CXXDtorType Type, |
| 1642 | const ThisAdjustment &, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1643 | raw_ostream &) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1644 | unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, |
| 1645 | "cannot mangle thunk for this destructor yet"); |
| 1646 | getDiags().Report(DD->getLocation(), DiagID); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1647 | } |
| 1648 | void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD, |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1649 | raw_ostream &Out) { |
Kaelyn Uhrain | 28e862a | 2012-06-13 17:05:13 +0000 | [diff] [blame] | 1650 | // <mangled-name> ::= ? <operator-name> <class-name> <storage-class> |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1651 | // <cvr-qualifiers> [<name>] @ |
| 1652 | // <operator-name> ::= _7 # vftable |
| 1653 | // ::= _8 # vbtable |
| 1654 | // NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class> |
| 1655 | // is always '6' for vftables and '7' for vbtables. (The difference is |
| 1656 | // beyond me.) |
| 1657 | // TODO: vbtables. |
| 1658 | MicrosoftCXXNameMangler Mangler(*this, Out); |
| 1659 | Mangler.getStream() << "\01??_7"; |
| 1660 | Mangler.mangleName(RD); |
| 1661 | Mangler.getStream() << "6B"; |
| 1662 | // TODO: If the class has more than one vtable, mangle in the class it came |
| 1663 | // from. |
| 1664 | Mangler.getStream() << '@'; |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1665 | } |
| 1666 | void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1667 | raw_ostream &) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1668 | llvm_unreachable("The MS C++ ABI does not have virtual table tables!"); |
| 1669 | } |
| 1670 | void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD, |
| 1671 | int64_t Offset, |
| 1672 | const CXXRecordDecl *Type, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1673 | raw_ostream &) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1674 | llvm_unreachable("The MS C++ ABI does not have constructor vtables!"); |
| 1675 | } |
| 1676 | void MicrosoftMangleContext::mangleCXXRTTI(QualType T, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1677 | raw_ostream &) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1678 | // FIXME: Give a location... |
| 1679 | unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, |
| 1680 | "cannot mangle RTTI descriptors for type %0 yet"); |
| 1681 | getDiags().Report(DiagID) |
| 1682 | << T.getBaseTypeIdentifier(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1683 | } |
| 1684 | void MicrosoftMangleContext::mangleCXXRTTIName(QualType T, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1685 | raw_ostream &) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1686 | // FIXME: Give a location... |
| 1687 | unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, |
| 1688 | "cannot mangle the name of type %0 into RTTI descriptors yet"); |
| 1689 | getDiags().Report(DiagID) |
| 1690 | << T.getBaseTypeIdentifier(); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1691 | } |
| 1692 | void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D, |
| 1693 | CXXCtorType Type, |
Michael J. Spencer | 50118da | 2011-12-01 09:55:00 +0000 | [diff] [blame] | 1694 | raw_ostream & Out) { |
| 1695 | MicrosoftCXXNameMangler mangler(*this, Out); |
| 1696 | mangler.mangle(D); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1697 | } |
| 1698 | void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D, |
| 1699 | CXXDtorType Type, |
Michael J. Spencer | 50118da | 2011-12-01 09:55:00 +0000 | [diff] [blame] | 1700 | raw_ostream & Out) { |
| 1701 | MicrosoftCXXNameMangler mangler(*this, Out); |
| 1702 | mangler.mangle(D); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1703 | } |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1704 | void MicrosoftMangleContext::mangleReferenceTemporary(const clang::VarDecl *VD, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1705 | raw_ostream &) { |
Charles Davis | e0deb03 | 2012-06-13 00:18:14 +0000 | [diff] [blame] | 1706 | unsigned DiagID = getDiags().getCustomDiagID(DiagnosticsEngine::Error, |
| 1707 | "cannot mangle this reference temporary yet"); |
| 1708 | getDiags().Report(VD->getLocation(), DiagID); |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | MangleContext *clang::createMicrosoftMangleContext(ASTContext &Context, |
David Blaikie | d6471f7 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 1712 | DiagnosticsEngine &Diags) { |
Peter Collingbourne | 1411047 | 2011-01-13 18:57:25 +0000 | [diff] [blame] | 1713 | return new MicrosoftMangleContext(Context, Diags); |
| 1714 | } |