blob: 6250f61198682dc43f175bef9f1a66b8f633c220 [file] [log] [blame]
Peter Collingbourne14110472011-01-13 18:57:25 +00001//===--- 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 Lattnerfc8f0e12011-04-15 05:22:18 +000010// This provides C++ name mangling targeting the Microsoft Visual C++ ABI.
Peter Collingbourne14110472011-01-13 18:57:25 +000011//
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"
23
24using namespace clang;
25
26namespace {
27
28/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
29/// Microsoft Visual C++ ABI.
30class MicrosoftCXXNameMangler {
31 MangleContext &Context;
Chris Lattner5f9e2722011-07-23 10:55:15 +000032 raw_ostream &Out;
Peter Collingbourne14110472011-01-13 18:57:25 +000033
34 ASTContext &getASTContext() const { return Context.getASTContext(); }
35
36public:
Chris Lattner5f9e2722011-07-23 10:55:15 +000037 MicrosoftCXXNameMangler(MangleContext &C, raw_ostream &Out_)
Rafael Espindolac4850c22011-02-10 23:59:36 +000038 : Context(C), Out(Out_) { }
Peter Collingbourne14110472011-01-13 18:57:25 +000039
Chris Lattner5f9e2722011-07-23 10:55:15 +000040 void mangle(const NamedDecl *D, StringRef Prefix = "?");
Peter Collingbourne14110472011-01-13 18:57:25 +000041 void mangleName(const NamedDecl *ND);
42 void mangleFunctionEncoding(const FunctionDecl *FD);
43 void mangleVariableEncoding(const VarDecl *VD);
44 void mangleNumber(int64_t Number);
45 void mangleType(QualType T);
46
47private:
48 void mangleUnqualifiedName(const NamedDecl *ND) {
49 mangleUnqualifiedName(ND, ND->getDeclName());
50 }
51 void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name);
52 void mangleSourceName(const IdentifierInfo *II);
53 void manglePostfix(const DeclContext *DC, bool NoFunction=false);
54 void mangleOperatorName(OverloadedOperatorKind OO);
55 void mangleQualifiers(Qualifiers Quals, bool IsMember);
56
57 void mangleObjCMethodName(const ObjCMethodDecl *MD);
58
59 // Declare manglers for every type class.
60#define ABSTRACT_TYPE(CLASS, PARENT)
61#define NON_CANONICAL_TYPE(CLASS, PARENT)
62#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
63#include "clang/AST/TypeNodes.def"
64
65 void mangleType(const TagType*);
66 void mangleType(const FunctionType *T, const FunctionDecl *D,
67 bool IsStructor, bool IsInstMethod);
68 void mangleType(const ArrayType *T, bool IsGlobal);
69 void mangleExtraDimensions(QualType T);
70 void mangleFunctionClass(const FunctionDecl *FD);
71 void mangleCallingConvention(const FunctionType *T, bool IsInstMethod = false);
72 void mangleThrowSpecification(const FunctionProtoType *T);
73
74};
75
76/// MicrosoftMangleContext - Overrides the default MangleContext for the
77/// Microsoft Visual C++ ABI.
78class MicrosoftMangleContext : public MangleContext {
79public:
80 MicrosoftMangleContext(ASTContext &Context,
David Blaikied6471f72011-09-25 23:23:43 +000081 DiagnosticsEngine &Diags) : MangleContext(Context, Diags) { }
Peter Collingbourne14110472011-01-13 18:57:25 +000082 virtual bool shouldMangleDeclName(const NamedDecl *D);
Chris Lattner5f9e2722011-07-23 10:55:15 +000083 virtual void mangleName(const NamedDecl *D, raw_ostream &Out);
Peter Collingbourne14110472011-01-13 18:57:25 +000084 virtual void mangleThunk(const CXXMethodDecl *MD,
85 const ThunkInfo &Thunk,
Chris Lattner5f9e2722011-07-23 10:55:15 +000086 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +000087 virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
88 const ThisAdjustment &ThisAdjustment,
Chris Lattner5f9e2722011-07-23 10:55:15 +000089 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +000090 virtual void mangleCXXVTable(const CXXRecordDecl *RD,
Chris Lattner5f9e2722011-07-23 10:55:15 +000091 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +000092 virtual void mangleCXXVTT(const CXXRecordDecl *RD,
Chris Lattner5f9e2722011-07-23 10:55:15 +000093 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +000094 virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
95 const CXXRecordDecl *Type,
Chris Lattner5f9e2722011-07-23 10:55:15 +000096 raw_ostream &);
97 virtual void mangleCXXRTTI(QualType T, raw_ostream &);
98 virtual void mangleCXXRTTIName(QualType T, raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +000099 virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000100 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +0000101 virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000102 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +0000103 virtual void mangleReferenceTemporary(const clang::VarDecl *,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000104 raw_ostream &);
Peter Collingbourne14110472011-01-13 18:57:25 +0000105};
106
107}
108
109static bool isInCLinkageSpecification(const Decl *D) {
110 D = D->getCanonicalDecl();
111 for (const DeclContext *DC = D->getDeclContext();
112 !DC->isTranslationUnit(); DC = DC->getParent()) {
113 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
114 return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
115 }
116
117 return false;
118}
119
120bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) {
121 // In C, functions with no attributes never need to be mangled. Fastpath them.
David Blaikie4e4d0842012-03-11 07:00:24 +0000122 if (!getASTContext().getLangOpts().CPlusPlus && !D->hasAttrs())
Peter Collingbourne14110472011-01-13 18:57:25 +0000123 return false;
124
125 // Any decl can be declared with __asm("foo") on it, and this takes precedence
126 // over all other naming in the .o file.
127 if (D->hasAttr<AsmLabelAttr>())
128 return true;
129
130 // Clang's "overloadable" attribute extension to C/C++ implies name mangling
131 // (always) as does passing a C++ member function and a function
132 // whose name is not a simple identifier.
133 const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
134 if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) ||
135 !FD->getDeclName().isIdentifier()))
136 return true;
137
138 // Otherwise, no mangling is done outside C++ mode.
David Blaikie4e4d0842012-03-11 07:00:24 +0000139 if (!getASTContext().getLangOpts().CPlusPlus)
Peter Collingbourne14110472011-01-13 18:57:25 +0000140 return false;
141
142 // Variables at global scope with internal linkage are not mangled.
143 if (!FD) {
144 const DeclContext *DC = D->getDeclContext();
145 if (DC->isTranslationUnit() && D->getLinkage() == InternalLinkage)
146 return false;
147 }
148
149 // C functions and "main" are not mangled.
150 if ((FD && FD->isMain()) || isInCLinkageSpecification(D))
151 return false;
152
153 return true;
154}
155
156void MicrosoftCXXNameMangler::mangle(const NamedDecl *D,
Chris Lattner5f9e2722011-07-23 10:55:15 +0000157 StringRef Prefix) {
Peter Collingbourne14110472011-01-13 18:57:25 +0000158 // MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
159 // Therefore it's really important that we don't decorate the
160 // name with leading underscores or leading/trailing at signs. So, emit a
161 // asm marker at the start so we get the name right.
162 Out << '\01'; // LLVM IR Marker for __asm("foo")
163
164 // Any decl can be declared with __asm("foo") on it, and this takes precedence
165 // over all other naming in the .o file.
166 if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
167 // If we have an asm name, then we use it as the mangling.
168 Out << ALA->getLabel();
169 return;
170 }
171
172 // <mangled-name> ::= ? <name> <type-encoding>
173 Out << Prefix;
174 mangleName(D);
175 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
176 mangleFunctionEncoding(FD);
177 else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
178 mangleVariableEncoding(VD);
179 // TODO: Fields? Can MSVC even mangle them?
180}
181
182void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
183 // <type-encoding> ::= <function-class> <function-type>
184
185 // Don't mangle in the type if this isn't a decl we should typically mangle.
186 if (!Context.shouldMangleDeclName(FD))
187 return;
188
189 // We should never ever see a FunctionNoProtoType at this point.
190 // We don't even know how to mangle their types anyway :).
191 const FunctionProtoType *FT = cast<FunctionProtoType>(FD->getType());
192
193 bool InStructor = false, InInstMethod = false;
194 const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
195 if (MD) {
196 if (MD->isInstance())
197 InInstMethod = true;
198 if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD))
199 InStructor = true;
200 }
201
202 // First, the function class.
203 mangleFunctionClass(FD);
204
205 mangleType(FT, FD, InStructor, InInstMethod);
206}
207
208void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) {
209 // <type-encoding> ::= <storage-class> <variable-type>
210 // <storage-class> ::= 0 # private static member
211 // ::= 1 # protected static member
212 // ::= 2 # public static member
213 // ::= 3 # global
214 // ::= 4 # static local
215
216 // The first character in the encoding (after the name) is the storage class.
217 if (VD->isStaticDataMember()) {
218 // If it's a static member, it also encodes the access level.
219 switch (VD->getAccess()) {
220 default:
221 case AS_private: Out << '0'; break;
222 case AS_protected: Out << '1'; break;
223 case AS_public: Out << '2'; break;
224 }
225 }
226 else if (!VD->isStaticLocal())
227 Out << '3';
228 else
229 Out << '4';
230 // Now mangle the type.
231 // <variable-type> ::= <type> <cvr-qualifiers>
232 // ::= <type> A # pointers, references, arrays
233 // Pointers and references are odd. The type of 'int * const foo;' gets
234 // mangled as 'QAHA' instead of 'PAHB', for example.
235 QualType Ty = VD->getType();
236 if (Ty->isPointerType() || Ty->isReferenceType()) {
237 mangleType(Ty);
238 Out << 'A';
239 } else if (Ty->isArrayType()) {
240 // Global arrays are funny, too.
John McCallf4c73712011-01-19 06:33:43 +0000241 mangleType(cast<ArrayType>(Ty.getTypePtr()), true);
Peter Collingbourne14110472011-01-13 18:57:25 +0000242 Out << 'A';
243 } else {
244 mangleType(Ty.getLocalUnqualifiedType());
245 mangleQualifiers(Ty.getLocalQualifiers(), false);
246 }
247}
248
249void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {
250 // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @
251 const DeclContext *DC = ND->getDeclContext();
252
253 // Always start with the unqualified name.
254 mangleUnqualifiedName(ND);
255
256 // If this is an extern variable declared locally, the relevant DeclContext
257 // is that of the containing namespace, or the translation unit.
258 if (isa<FunctionDecl>(DC) && ND->hasLinkage())
259 while (!DC->isNamespace() && !DC->isTranslationUnit())
260 DC = DC->getParent();
261
262 manglePostfix(DC);
263
264 // Terminate the whole name with an '@'.
265 Out << '@';
266}
267
268void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
269 // <number> ::= [?] <decimal digit> # <= 9
270 // ::= [?] <hex digit>+ @ # > 9; A = 0, B = 1, etc...
271 if (Number < 0) {
272 Out << '?';
273 Number = -Number;
274 }
275 if (Number >= 1 && Number <= 10) {
276 Out << Number-1;
277 } else {
278 // We have to build up the encoding in reverse order, so it will come
279 // out right when we write it out.
280 char Encoding[16];
281 char *EndPtr = Encoding+sizeof(Encoding);
282 char *CurPtr = EndPtr;
283 while (Number) {
284 *--CurPtr = 'A' + (Number % 16);
285 Number /= 16;
286 }
287 Out.write(CurPtr, EndPtr-CurPtr);
288 Out << '@';
289 }
290}
291
292void
293MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
294 DeclarationName Name) {
295 // <unqualified-name> ::= <operator-name>
296 // ::= <ctor-dtor-name>
297 // ::= <source-name>
298 switch (Name.getNameKind()) {
299 case DeclarationName::Identifier: {
300 if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
301 mangleSourceName(II);
302 break;
303 }
304
305 // Otherwise, an anonymous entity. We must have a declaration.
306 assert(ND && "mangling empty name without declaration");
307
308 if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
309 if (NS->isAnonymousNamespace()) {
310 Out << "?A";
311 break;
312 }
313 }
314
315 // We must have an anonymous struct.
316 const TagDecl *TD = cast<TagDecl>(ND);
Richard Smith162e1c12011-04-15 14:24:37 +0000317 if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) {
Peter Collingbourne14110472011-01-13 18:57:25 +0000318 assert(TD->getDeclContext() == D->getDeclContext() &&
319 "Typedef should not be in another decl context!");
320 assert(D->getDeclName().getAsIdentifierInfo() &&
321 "Typedef was not named!");
322 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
323 break;
324 }
325
326 // When VC encounters an anonymous type with no tag and no typedef,
327 // it literally emits '<unnamed-tag>'.
328 Out << "<unnamed-tag>";
329 break;
330 }
331
332 case DeclarationName::ObjCZeroArgSelector:
333 case DeclarationName::ObjCOneArgSelector:
334 case DeclarationName::ObjCMultiArgSelector:
David Blaikieb219cfc2011-09-23 05:06:16 +0000335 llvm_unreachable("Can't mangle Objective-C selector names here!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000336
337 case DeclarationName::CXXConstructorName:
Michael J. Spencer50118da2011-12-01 09:55:00 +0000338 Out << "?0";
339 break;
Peter Collingbourne14110472011-01-13 18:57:25 +0000340
341 case DeclarationName::CXXDestructorName:
Michael J. Spencer50118da2011-12-01 09:55:00 +0000342 Out << "?1";
343 break;
Peter Collingbourne14110472011-01-13 18:57:25 +0000344
345 case DeclarationName::CXXConversionFunctionName:
346 // <operator-name> ::= ?B # (cast)
347 // The target type is encoded as the return type.
348 Out << "?B";
349 break;
350
351 case DeclarationName::CXXOperatorName:
352 mangleOperatorName(Name.getCXXOverloadedOperator());
353 break;
354
355 case DeclarationName::CXXLiteralOperatorName:
356 // FIXME: Was this added in VS2010? Does MS even know how to mangle this?
David Blaikieb219cfc2011-09-23 05:06:16 +0000357 llvm_unreachable("Don't know how to mangle literal operators yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000358
359 case DeclarationName::CXXUsingDirective:
David Blaikieb219cfc2011-09-23 05:06:16 +0000360 llvm_unreachable("Can't mangle a using directive name!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000361 }
362}
363
364void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC,
365 bool NoFunction) {
366 // <postfix> ::= <unqualified-name> [<postfix>]
367 // ::= <template-postfix> <template-args> [<postfix>]
368 // ::= <template-param>
369 // ::= <substitution> [<postfix>]
370
371 if (!DC) return;
372
373 while (isa<LinkageSpecDecl>(DC))
374 DC = DC->getParent();
375
376 if (DC->isTranslationUnit())
377 return;
378
379 if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
Rafael Espindolac4850c22011-02-10 23:59:36 +0000380 Context.mangleBlock(BD, Out);
381 Out << '@';
Peter Collingbourne14110472011-01-13 18:57:25 +0000382 return manglePostfix(DC->getParent(), NoFunction);
383 }
384
385 if (NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)))
386 return;
387 else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC))
388 mangleObjCMethodName(Method);
389 else {
390 mangleUnqualifiedName(cast<NamedDecl>(DC));
391 manglePostfix(DC->getParent(), NoFunction);
392 }
393}
394
395void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO) {
396 switch (OO) {
397 // ?0 # constructor
398 // ?1 # destructor
399 // <operator-name> ::= ?2 # new
400 case OO_New: Out << "?2"; break;
401 // <operator-name> ::= ?3 # delete
402 case OO_Delete: Out << "?3"; break;
403 // <operator-name> ::= ?4 # =
404 case OO_Equal: Out << "?4"; break;
405 // <operator-name> ::= ?5 # >>
406 case OO_GreaterGreater: Out << "?5"; break;
407 // <operator-name> ::= ?6 # <<
408 case OO_LessLess: Out << "?6"; break;
409 // <operator-name> ::= ?7 # !
410 case OO_Exclaim: Out << "?7"; break;
411 // <operator-name> ::= ?8 # ==
412 case OO_EqualEqual: Out << "?8"; break;
413 // <operator-name> ::= ?9 # !=
414 case OO_ExclaimEqual: Out << "?9"; break;
415 // <operator-name> ::= ?A # []
416 case OO_Subscript: Out << "?A"; break;
417 // ?B # conversion
418 // <operator-name> ::= ?C # ->
419 case OO_Arrow: Out << "?C"; break;
420 // <operator-name> ::= ?D # *
421 case OO_Star: Out << "?D"; break;
422 // <operator-name> ::= ?E # ++
423 case OO_PlusPlus: Out << "?E"; break;
424 // <operator-name> ::= ?F # --
425 case OO_MinusMinus: Out << "?F"; break;
426 // <operator-name> ::= ?G # -
427 case OO_Minus: Out << "?G"; break;
428 // <operator-name> ::= ?H # +
429 case OO_Plus: Out << "?H"; break;
430 // <operator-name> ::= ?I # &
431 case OO_Amp: Out << "?I"; break;
432 // <operator-name> ::= ?J # ->*
433 case OO_ArrowStar: Out << "?J"; break;
434 // <operator-name> ::= ?K # /
435 case OO_Slash: Out << "?K"; break;
436 // <operator-name> ::= ?L # %
437 case OO_Percent: Out << "?L"; break;
438 // <operator-name> ::= ?M # <
439 case OO_Less: Out << "?M"; break;
440 // <operator-name> ::= ?N # <=
441 case OO_LessEqual: Out << "?N"; break;
442 // <operator-name> ::= ?O # >
443 case OO_Greater: Out << "?O"; break;
444 // <operator-name> ::= ?P # >=
445 case OO_GreaterEqual: Out << "?P"; break;
446 // <operator-name> ::= ?Q # ,
447 case OO_Comma: Out << "?Q"; break;
448 // <operator-name> ::= ?R # ()
449 case OO_Call: Out << "?R"; break;
450 // <operator-name> ::= ?S # ~
451 case OO_Tilde: Out << "?S"; break;
452 // <operator-name> ::= ?T # ^
453 case OO_Caret: Out << "?T"; break;
454 // <operator-name> ::= ?U # |
455 case OO_Pipe: Out << "?U"; break;
456 // <operator-name> ::= ?V # &&
457 case OO_AmpAmp: Out << "?V"; break;
458 // <operator-name> ::= ?W # ||
459 case OO_PipePipe: Out << "?W"; break;
460 // <operator-name> ::= ?X # *=
461 case OO_StarEqual: Out << "?X"; break;
462 // <operator-name> ::= ?Y # +=
463 case OO_PlusEqual: Out << "?Y"; break;
464 // <operator-name> ::= ?Z # -=
465 case OO_MinusEqual: Out << "?Z"; break;
466 // <operator-name> ::= ?_0 # /=
467 case OO_SlashEqual: Out << "?_0"; break;
468 // <operator-name> ::= ?_1 # %=
469 case OO_PercentEqual: Out << "?_1"; break;
470 // <operator-name> ::= ?_2 # >>=
471 case OO_GreaterGreaterEqual: Out << "?_2"; break;
472 // <operator-name> ::= ?_3 # <<=
473 case OO_LessLessEqual: Out << "?_3"; break;
474 // <operator-name> ::= ?_4 # &=
475 case OO_AmpEqual: Out << "?_4"; break;
476 // <operator-name> ::= ?_5 # |=
477 case OO_PipeEqual: Out << "?_5"; break;
478 // <operator-name> ::= ?_6 # ^=
479 case OO_CaretEqual: Out << "?_6"; break;
480 // ?_7 # vftable
481 // ?_8 # vbtable
482 // ?_9 # vcall
483 // ?_A # typeof
484 // ?_B # local static guard
485 // ?_C # string
486 // ?_D # vbase destructor
487 // ?_E # vector deleting destructor
488 // ?_F # default constructor closure
489 // ?_G # scalar deleting destructor
490 // ?_H # vector constructor iterator
491 // ?_I # vector destructor iterator
492 // ?_J # vector vbase constructor iterator
493 // ?_K # virtual displacement map
494 // ?_L # eh vector constructor iterator
495 // ?_M # eh vector destructor iterator
496 // ?_N # eh vector vbase constructor iterator
497 // ?_O # copy constructor closure
498 // ?_P<name> # udt returning <name>
499 // ?_Q # <unknown>
500 // ?_R0 # RTTI Type Descriptor
501 // ?_R1 # RTTI Base Class Descriptor at (a,b,c,d)
502 // ?_R2 # RTTI Base Class Array
503 // ?_R3 # RTTI Class Hierarchy Descriptor
504 // ?_R4 # RTTI Complete Object Locator
505 // ?_S # local vftable
506 // ?_T # local vftable constructor closure
507 // <operator-name> ::= ?_U # new[]
508 case OO_Array_New: Out << "?_U"; break;
509 // <operator-name> ::= ?_V # delete[]
510 case OO_Array_Delete: Out << "?_V"; break;
511
512 case OO_Conditional:
David Blaikieb219cfc2011-09-23 05:06:16 +0000513 llvm_unreachable("Don't know how to mangle ?:");
Peter Collingbourne14110472011-01-13 18:57:25 +0000514
515 case OO_None:
516 case NUM_OVERLOADED_OPERATORS:
David Blaikieb219cfc2011-09-23 05:06:16 +0000517 llvm_unreachable("Not an overloaded operator");
Peter Collingbourne14110472011-01-13 18:57:25 +0000518 }
519}
520
521void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
522 // <source name> ::= <identifier> @
523 Out << II->getName() << '@';
524}
525
526void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
Rafael Espindolaf0be9792011-02-11 02:52:17 +0000527 Context.mangleObjCMethodName(MD, Out);
Peter Collingbourne14110472011-01-13 18:57:25 +0000528}
529
530void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
531 bool IsMember) {
532 // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
533 // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
534 // 'I' means __restrict (32/64-bit).
535 // Note that the MSVC __restrict keyword isn't the same as the C99 restrict
536 // keyword!
537 // <base-cvr-qualifiers> ::= A # near
538 // ::= B # near const
539 // ::= C # near volatile
540 // ::= D # near const volatile
541 // ::= E # far (16-bit)
542 // ::= F # far const (16-bit)
543 // ::= G # far volatile (16-bit)
544 // ::= H # far const volatile (16-bit)
545 // ::= I # huge (16-bit)
546 // ::= J # huge const (16-bit)
547 // ::= K # huge volatile (16-bit)
548 // ::= L # huge const volatile (16-bit)
549 // ::= M <basis> # based
550 // ::= N <basis> # based const
551 // ::= O <basis> # based volatile
552 // ::= P <basis> # based const volatile
553 // ::= Q # near member
554 // ::= R # near const member
555 // ::= S # near volatile member
556 // ::= T # near const volatile member
557 // ::= U # far member (16-bit)
558 // ::= V # far const member (16-bit)
559 // ::= W # far volatile member (16-bit)
560 // ::= X # far const volatile member (16-bit)
561 // ::= Y # huge member (16-bit)
562 // ::= Z # huge const member (16-bit)
563 // ::= 0 # huge volatile member (16-bit)
564 // ::= 1 # huge const volatile member (16-bit)
565 // ::= 2 <basis> # based member
566 // ::= 3 <basis> # based const member
567 // ::= 4 <basis> # based volatile member
568 // ::= 5 <basis> # based const volatile member
569 // ::= 6 # near function (pointers only)
570 // ::= 7 # far function (pointers only)
571 // ::= 8 # near method (pointers only)
572 // ::= 9 # far method (pointers only)
573 // ::= _A <basis> # based function (pointers only)
574 // ::= _B <basis> # based function (far?) (pointers only)
575 // ::= _C <basis> # based method (pointers only)
576 // ::= _D <basis> # based method (far?) (pointers only)
577 // ::= _E # block (Clang)
578 // <basis> ::= 0 # __based(void)
579 // ::= 1 # __based(segment)?
580 // ::= 2 <name> # __based(name)
581 // ::= 3 # ?
582 // ::= 4 # ?
583 // ::= 5 # not really based
584 if (!IsMember) {
585 if (!Quals.hasVolatile()) {
586 if (!Quals.hasConst())
587 Out << 'A';
588 else
589 Out << 'B';
590 } else {
591 if (!Quals.hasConst())
592 Out << 'C';
593 else
594 Out << 'D';
595 }
596 } else {
597 if (!Quals.hasVolatile()) {
598 if (!Quals.hasConst())
599 Out << 'Q';
600 else
601 Out << 'R';
602 } else {
603 if (!Quals.hasConst())
604 Out << 'S';
605 else
606 Out << 'T';
607 }
608 }
609
610 // FIXME: For now, just drop all extension qualifiers on the floor.
611}
612
613void MicrosoftCXXNameMangler::mangleType(QualType T) {
614 // Only operate on the canonical type!
615 T = getASTContext().getCanonicalType(T);
616
617 Qualifiers Quals = T.getLocalQualifiers();
618 if (Quals) {
619 // We have to mangle these now, while we still have enough information.
620 // <pointer-cvr-qualifiers> ::= P # pointer
621 // ::= Q # const pointer
622 // ::= R # volatile pointer
623 // ::= S # const volatile pointer
624 if (T->isAnyPointerType() || T->isMemberPointerType() ||
625 T->isBlockPointerType()) {
626 if (!Quals.hasVolatile())
627 Out << 'Q';
628 else {
629 if (!Quals.hasConst())
630 Out << 'R';
631 else
632 Out << 'S';
633 }
634 } else
635 // Just emit qualifiers like normal.
636 // NB: When we mangle a pointer/reference type, and the pointee
637 // type has no qualifiers, the lack of qualifier gets mangled
638 // in there.
639 mangleQualifiers(Quals, false);
640 } else if (T->isAnyPointerType() || T->isMemberPointerType() ||
641 T->isBlockPointerType()) {
642 Out << 'P';
643 }
644 switch (T->getTypeClass()) {
645#define ABSTRACT_TYPE(CLASS, PARENT)
646#define NON_CANONICAL_TYPE(CLASS, PARENT) \
647case Type::CLASS: \
648llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
649return;
650#define TYPE(CLASS, PARENT) \
651case Type::CLASS: \
652mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \
653break;
654#include "clang/AST/TypeNodes.def"
655 }
656}
657
658void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T) {
659 // <type> ::= <builtin-type>
660 // <builtin-type> ::= X # void
661 // ::= C # signed char
662 // ::= D # char
663 // ::= E # unsigned char
664 // ::= F # short
665 // ::= G # unsigned short (or wchar_t if it's not a builtin)
666 // ::= H # int
667 // ::= I # unsigned int
668 // ::= J # long
669 // ::= K # unsigned long
670 // L # <none>
671 // ::= M # float
672 // ::= N # double
673 // ::= O # long double (__float80 is mangled differently)
Peter Collingbourne14110472011-01-13 18:57:25 +0000674 // ::= _J # long long, __int64
675 // ::= _K # unsigned long long, __int64
676 // ::= _L # __int128
677 // ::= _M # unsigned __int128
678 // ::= _N # bool
679 // _O # <array in parameter>
680 // ::= _T # __float80 (Intel)
681 // ::= _W # wchar_t
682 // ::= _Z # __float80 (Digital Mars)
683 switch (T->getKind()) {
684 case BuiltinType::Void: Out << 'X'; break;
685 case BuiltinType::SChar: Out << 'C'; break;
686 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break;
687 case BuiltinType::UChar: Out << 'E'; break;
688 case BuiltinType::Short: Out << 'F'; break;
689 case BuiltinType::UShort: Out << 'G'; break;
690 case BuiltinType::Int: Out << 'H'; break;
691 case BuiltinType::UInt: Out << 'I'; break;
692 case BuiltinType::Long: Out << 'J'; break;
693 case BuiltinType::ULong: Out << 'K'; break;
694 case BuiltinType::Float: Out << 'M'; break;
695 case BuiltinType::Double: Out << 'N'; break;
696 // TODO: Determine size and mangle accordingly
697 case BuiltinType::LongDouble: Out << 'O'; break;
Peter Collingbourne14110472011-01-13 18:57:25 +0000698 case BuiltinType::LongLong: Out << "_J"; break;
699 case BuiltinType::ULongLong: Out << "_K"; break;
700 case BuiltinType::Int128: Out << "_L"; break;
701 case BuiltinType::UInt128: Out << "_M"; break;
702 case BuiltinType::Bool: Out << "_N"; break;
703 case BuiltinType::WChar_S:
704 case BuiltinType::WChar_U: Out << "_W"; break;
705
John McCalle0a22d02011-10-18 21:02:43 +0000706#define BUILTIN_TYPE(Id, SingletonId)
707#define PLACEHOLDER_TYPE(Id, SingletonId) \
708 case BuiltinType::Id:
709#include "clang/AST/BuiltinTypes.def"
Peter Collingbourne14110472011-01-13 18:57:25 +0000710 case BuiltinType::Dependent:
John McCalle0a22d02011-10-18 21:02:43 +0000711 llvm_unreachable("placeholder types shouldn't get to name mangling");
712
Peter Collingbourne14110472011-01-13 18:57:25 +0000713 case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break;
714 case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break;
715 case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break;
716
717 case BuiltinType::Char16:
718 case BuiltinType::Char32:
Anton Korobeynikovaa4a99b2011-10-14 23:23:15 +0000719 case BuiltinType::Half:
Peter Collingbourne14110472011-01-13 18:57:25 +0000720 case BuiltinType::NullPtr:
John McCalle0a22d02011-10-18 21:02:43 +0000721 assert(0 && "Don't know how to mangle this type yet");
Peter Collingbourne14110472011-01-13 18:57:25 +0000722 }
723}
724
725// <type> ::= <function-type>
726void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T) {
727 // Structors only appear in decls, so at this point we know it's not a
728 // structor type.
729 // I'll probably have mangleType(MemberPointerType) call the mangleType()
730 // method directly.
731 mangleType(T, NULL, false, false);
732}
733void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T) {
734 llvm_unreachable("Can't mangle K&R function prototypes");
735}
736
737void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
738 const FunctionDecl *D,
739 bool IsStructor,
740 bool IsInstMethod) {
741 // <function-type> ::= <this-cvr-qualifiers> <calling-convention>
742 // <return-type> <argument-list> <throw-spec>
743 const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
744
745 // If this is a C++ instance method, mangle the CVR qualifiers for the
746 // this pointer.
747 if (IsInstMethod)
748 mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
749
750 mangleCallingConvention(T, IsInstMethod);
751
752 // <return-type> ::= <type>
753 // ::= @ # structors (they have no declared return type)
754 if (IsStructor)
755 Out << '@';
756 else
757 mangleType(Proto->getResultType());
758
759 // <argument-list> ::= X # void
760 // ::= <type>+ @
761 // ::= <type>* Z # varargs
762 if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
763 Out << 'X';
764 } else {
765 if (D) {
John McCall3a8ac072012-05-01 02:33:44 +0000766 // If we got a decl, use the type-as-written to make sure arrays
767 // get mangled right. Note that we can't rely on the TSI
768 // existing if (for example) the parameter was synthesized.
Peter Collingbourne14110472011-01-13 18:57:25 +0000769 for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
John McCall3a8ac072012-05-01 02:33:44 +0000770 ParmEnd = D->param_end(); Parm != ParmEnd; ++Parm) {
771 if (TypeSourceInfo *typeAsWritten = (*Parm)->getTypeSourceInfo())
772 mangleType(typeAsWritten->getType());
773 else
774 mangleType((*Parm)->getType());
775 }
Peter Collingbourne14110472011-01-13 18:57:25 +0000776 } else {
777 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
778 ArgEnd = Proto->arg_type_end();
779 Arg != ArgEnd; ++Arg)
780 mangleType(*Arg);
781 }
782 // <builtin-type> ::= Z # ellipsis
783 if (Proto->isVariadic())
784 Out << 'Z';
785 else
786 Out << '@';
787 }
788
789 mangleThrowSpecification(Proto);
790}
791
792void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
793 // <function-class> ::= A # private: near
794 // ::= B # private: far
795 // ::= C # private: static near
796 // ::= D # private: static far
797 // ::= E # private: virtual near
798 // ::= F # private: virtual far
799 // ::= G # private: thunk near
800 // ::= H # private: thunk far
801 // ::= I # protected: near
802 // ::= J # protected: far
803 // ::= K # protected: static near
804 // ::= L # protected: static far
805 // ::= M # protected: virtual near
806 // ::= N # protected: virtual far
807 // ::= O # protected: thunk near
808 // ::= P # protected: thunk far
809 // ::= Q # public: near
810 // ::= R # public: far
811 // ::= S # public: static near
812 // ::= T # public: static far
813 // ::= U # public: virtual near
814 // ::= V # public: virtual far
815 // ::= W # public: thunk near
816 // ::= X # public: thunk far
817 // ::= Y # global near
818 // ::= Z # global far
819 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
820 switch (MD->getAccess()) {
821 default:
822 case AS_private:
823 if (MD->isStatic())
824 Out << 'C';
825 else if (MD->isVirtual())
826 Out << 'E';
827 else
828 Out << 'A';
829 break;
830 case AS_protected:
831 if (MD->isStatic())
832 Out << 'K';
833 else if (MD->isVirtual())
834 Out << 'M';
835 else
836 Out << 'I';
837 break;
838 case AS_public:
839 if (MD->isStatic())
840 Out << 'S';
841 else if (MD->isVirtual())
842 Out << 'U';
843 else
844 Out << 'Q';
845 }
846 } else
847 Out << 'Y';
848}
849void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T,
850 bool IsInstMethod) {
851 // <calling-convention> ::= A # __cdecl
852 // ::= B # __export __cdecl
853 // ::= C # __pascal
854 // ::= D # __export __pascal
855 // ::= E # __thiscall
856 // ::= F # __export __thiscall
857 // ::= G # __stdcall
858 // ::= H # __export __stdcall
859 // ::= I # __fastcall
860 // ::= J # __export __fastcall
861 // The 'export' calling conventions are from a bygone era
862 // (*cough*Win16*cough*) when functions were declared for export with
863 // that keyword. (It didn't actually export them, it just made them so
864 // that they could be in a DLL and somebody from another module could call
865 // them.)
866 CallingConv CC = T->getCallConv();
867 if (CC == CC_Default)
868 CC = IsInstMethod ? getASTContext().getDefaultMethodCallConv() : CC_C;
869 switch (CC) {
Anton Korobeynikov414d8962011-04-14 20:06:49 +0000870 default:
David Blaikieb219cfc2011-09-23 05:06:16 +0000871 llvm_unreachable("Unsupported CC for mangling");
Peter Collingbourne14110472011-01-13 18:57:25 +0000872 case CC_Default:
873 case CC_C: Out << 'A'; break;
874 case CC_X86Pascal: Out << 'C'; break;
875 case CC_X86ThisCall: Out << 'E'; break;
876 case CC_X86StdCall: Out << 'G'; break;
877 case CC_X86FastCall: Out << 'I'; break;
878 }
879}
880void MicrosoftCXXNameMangler::mangleThrowSpecification(
881 const FunctionProtoType *FT) {
882 // <throw-spec> ::= Z # throw(...) (default)
883 // ::= @ # throw() or __declspec/__attribute__((nothrow))
884 // ::= <type>+
885 // NOTE: Since the Microsoft compiler ignores throw specifications, they are
886 // all actually mangled as 'Z'. (They're ignored because their associated
887 // functionality isn't implemented, and probably never will be.)
888 Out << 'Z';
889}
890
891void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000892 llvm_unreachable("Don't know how to mangle UnresolvedUsingTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000893}
894
895// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
896// <union-type> ::= T <name>
897// <struct-type> ::= U <name>
898// <class-type> ::= V <name>
899// <enum-type> ::= W <size> <name>
900void MicrosoftCXXNameMangler::mangleType(const EnumType *T) {
901 mangleType(static_cast<const TagType*>(T));
902}
903void MicrosoftCXXNameMangler::mangleType(const RecordType *T) {
904 mangleType(static_cast<const TagType*>(T));
905}
906void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
907 switch (T->getDecl()->getTagKind()) {
908 case TTK_Union:
909 Out << 'T';
910 break;
911 case TTK_Struct:
912 Out << 'U';
913 break;
914 case TTK_Class:
915 Out << 'V';
916 break;
917 case TTK_Enum:
918 Out << 'W';
919 Out << getASTContext().getTypeSizeInChars(
920 cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity();
921 break;
922 }
923 mangleName(T->getDecl());
924}
925
926// <type> ::= <array-type>
927// <array-type> ::= P <cvr-qualifiers> [Y <dimension-count> <dimension>+]
928// <element-type> # as global
929// ::= Q <cvr-qualifiers> [Y <dimension-count> <dimension>+]
930// <element-type> # as param
931// It's supposed to be the other way around, but for some strange reason, it
932// isn't. Today this behavior is retained for the sole purpose of backwards
933// compatibility.
934void MicrosoftCXXNameMangler::mangleType(const ArrayType *T, bool IsGlobal) {
935 // This isn't a recursive mangling, so now we have to do it all in this
936 // one call.
937 if (IsGlobal)
938 Out << 'P';
939 else
940 Out << 'Q';
941 mangleExtraDimensions(T->getElementType());
942}
943void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T) {
944 mangleType(static_cast<const ArrayType *>(T), false);
945}
946void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T) {
947 mangleType(static_cast<const ArrayType *>(T), false);
948}
949void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T) {
950 mangleType(static_cast<const ArrayType *>(T), false);
951}
952void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T) {
953 mangleType(static_cast<const ArrayType *>(T), false);
954}
955void MicrosoftCXXNameMangler::mangleExtraDimensions(QualType ElementTy) {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000956 SmallVector<llvm::APInt, 3> Dimensions;
Peter Collingbourne14110472011-01-13 18:57:25 +0000957 for (;;) {
958 if (ElementTy->isConstantArrayType()) {
959 const ConstantArrayType *CAT =
960 static_cast<const ConstantArrayType *>(ElementTy.getTypePtr());
961 Dimensions.push_back(CAT->getSize());
962 ElementTy = CAT->getElementType();
963 } else if (ElementTy->isVariableArrayType()) {
David Blaikieb219cfc2011-09-23 05:06:16 +0000964 llvm_unreachable("Don't know how to mangle VLAs!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000965 } else if (ElementTy->isDependentSizedArrayType()) {
966 // The dependent expression has to be folded into a constant (TODO).
David Blaikieb219cfc2011-09-23 05:06:16 +0000967 llvm_unreachable("Don't know how to mangle dependent-sized arrays!");
Peter Collingbourne14110472011-01-13 18:57:25 +0000968 } else if (ElementTy->isIncompleteArrayType()) continue;
969 else break;
970 }
971 mangleQualifiers(ElementTy.getQualifiers(), false);
972 // If there are any additional dimensions, mangle them now.
973 if (Dimensions.size() > 0) {
974 Out << 'Y';
975 // <dimension-count> ::= <number> # number of extra dimensions
976 mangleNumber(Dimensions.size());
977 for (unsigned Dim = 0; Dim < Dimensions.size(); ++Dim) {
978 mangleNumber(Dimensions[Dim].getLimitedValue());
979 }
980 }
981 mangleType(ElementTy.getLocalUnqualifiedType());
982}
983
984// <type> ::= <pointer-to-member-type>
985// <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
986// <class name> <type>
987void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T) {
988 QualType PointeeType = T->getPointeeType();
989 if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
990 Out << '8';
991 mangleName(cast<RecordType>(T->getClass())->getDecl());
992 mangleType(FPT, NULL, false, true);
993 } else {
994 mangleQualifiers(PointeeType.getQualifiers(), true);
995 mangleName(cast<RecordType>(T->getClass())->getDecl());
996 mangleType(PointeeType.getLocalUnqualifiedType());
997 }
998}
999
1000void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001001 llvm_unreachable("Don't know how to mangle TemplateTypeParmTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001002}
1003
Douglas Gregorc3069d62011-01-14 02:55:32 +00001004void MicrosoftCXXNameMangler::mangleType(
1005 const SubstTemplateTypeParmPackType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001006 llvm_unreachable(
Douglas Gregorc3069d62011-01-14 02:55:32 +00001007 "Don't know how to mangle SubstTemplateTypeParmPackTypes yet!");
1008}
1009
Peter Collingbourne14110472011-01-13 18:57:25 +00001010// <type> ::= <pointer-type>
1011// <pointer-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
1012void MicrosoftCXXNameMangler::mangleType(const PointerType *T) {
1013 QualType PointeeTy = T->getPointeeType();
1014 if (PointeeTy->isArrayType()) {
1015 // Pointers to arrays are mangled like arrays.
1016 mangleExtraDimensions(T->getPointeeType());
1017 } else if (PointeeTy->isFunctionType()) {
1018 // Function pointers are special.
1019 Out << '6';
1020 mangleType(static_cast<const FunctionType *>(PointeeTy.getTypePtr()),
1021 NULL, false, false);
1022 } else {
1023 if (!PointeeTy.hasQualifiers())
1024 // Lack of qualifiers is mangled as 'A'.
1025 Out << 'A';
1026 mangleType(PointeeTy);
1027 }
1028}
1029void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
1030 // Object pointers never have qualifiers.
1031 Out << 'A';
1032 mangleType(T->getPointeeType());
1033}
1034
1035// <type> ::= <reference-type>
1036// <reference-type> ::= A <cvr-qualifiers> <type>
1037void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T) {
1038 Out << 'A';
1039 QualType PointeeTy = T->getPointeeType();
1040 if (!PointeeTy.hasQualifiers())
1041 // Lack of qualifiers is mangled as 'A'.
1042 Out << 'A';
1043 mangleType(PointeeTy);
1044}
1045
1046void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001047 llvm_unreachable("Don't know how to mangle RValueReferenceTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001048}
1049
1050void MicrosoftCXXNameMangler::mangleType(const ComplexType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001051 llvm_unreachable("Don't know how to mangle ComplexTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001052}
1053
1054void MicrosoftCXXNameMangler::mangleType(const VectorType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001055 llvm_unreachable("Don't know how to mangle VectorTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001056}
1057void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001058 llvm_unreachable("Don't know how to mangle ExtVectorTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001059}
1060void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001061 llvm_unreachable(
1062 "Don't know how to mangle DependentSizedExtVectorTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001063}
1064
1065void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T) {
1066 // ObjC interfaces have structs underlying them.
1067 Out << 'U';
1068 mangleName(T->getDecl());
1069}
1070
1071void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T) {
1072 // We don't allow overloading by different protocol qualification,
1073 // so mangling them isn't necessary.
1074 mangleType(T->getBaseType());
1075}
1076
1077void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T) {
1078 Out << "_E";
1079 mangleType(T->getPointeeType());
1080}
1081
1082void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001083 llvm_unreachable("Don't know how to mangle InjectedClassNameTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001084}
1085
1086void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001087 llvm_unreachable("Don't know how to mangle TemplateSpecializationTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001088}
1089
1090void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001091 llvm_unreachable("Don't know how to mangle DependentNameTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001092}
1093
1094void MicrosoftCXXNameMangler::mangleType(
1095 const DependentTemplateSpecializationType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001096 llvm_unreachable(
Peter Collingbourne14110472011-01-13 18:57:25 +00001097 "Don't know how to mangle DependentTemplateSpecializationTypes yet!");
1098}
1099
1100void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001101 llvm_unreachable("Don't know how to mangle PackExpansionTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001102}
1103
1104void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001105 llvm_unreachable("Don't know how to mangle TypeOfTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001106}
1107
1108void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001109 llvm_unreachable("Don't know how to mangle TypeOfExprTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001110}
1111
1112void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001113 llvm_unreachable("Don't know how to mangle DecltypeTypes yet!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001114}
1115
Sean Huntca63c202011-05-24 22:41:36 +00001116void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001117 llvm_unreachable("Don't know how to mangle UnaryTransformationTypes yet!");
Sean Huntca63c202011-05-24 22:41:36 +00001118}
1119
Richard Smith34b41d92011-02-20 03:19:35 +00001120void MicrosoftCXXNameMangler::mangleType(const AutoType *T) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001121 llvm_unreachable("Don't know how to mangle AutoTypes yet!");
Richard Smith34b41d92011-02-20 03:19:35 +00001122}
1123
Eli Friedmanb001de72011-10-06 23:00:33 +00001124void MicrosoftCXXNameMangler::mangleType(const AtomicType *T) {
1125 llvm_unreachable("Don't know how to mangle AtomicTypes yet!");
1126}
1127
Peter Collingbourne14110472011-01-13 18:57:25 +00001128void MicrosoftMangleContext::mangleName(const NamedDecl *D,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001129 raw_ostream &Out) {
Peter Collingbourne14110472011-01-13 18:57:25 +00001130 assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
1131 "Invalid mangleName() call, argument is not a variable or function!");
1132 assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
1133 "Invalid mangleName() call on 'structor decl!");
1134
1135 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
1136 getASTContext().getSourceManager(),
1137 "Mangling declaration");
1138
Rafael Espindolac4850c22011-02-10 23:59:36 +00001139 MicrosoftCXXNameMangler Mangler(*this, Out);
Peter Collingbourne14110472011-01-13 18:57:25 +00001140 return Mangler.mangle(D);
1141}
1142void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD,
1143 const ThunkInfo &Thunk,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001144 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001145 llvm_unreachable("Can't yet mangle thunks!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001146}
1147void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
1148 CXXDtorType Type,
1149 const ThisAdjustment &,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001150 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001151 llvm_unreachable("Can't yet mangle destructor thunks!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001152}
1153void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001154 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001155 llvm_unreachable("Can't yet mangle virtual tables!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001156}
1157void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001158 raw_ostream &) {
Peter Collingbourne14110472011-01-13 18:57:25 +00001159 llvm_unreachable("The MS C++ ABI does not have virtual table tables!");
1160}
1161void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
1162 int64_t Offset,
1163 const CXXRecordDecl *Type,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001164 raw_ostream &) {
Peter Collingbourne14110472011-01-13 18:57:25 +00001165 llvm_unreachable("The MS C++ ABI does not have constructor vtables!");
1166}
1167void MicrosoftMangleContext::mangleCXXRTTI(QualType T,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001168 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001169 llvm_unreachable("Can't yet mangle RTTI!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001170}
1171void MicrosoftMangleContext::mangleCXXRTTIName(QualType T,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001172 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001173 llvm_unreachable("Can't yet mangle RTTI names!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001174}
1175void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
1176 CXXCtorType Type,
Michael J. Spencer50118da2011-12-01 09:55:00 +00001177 raw_ostream & Out) {
1178 MicrosoftCXXNameMangler mangler(*this, Out);
1179 mangler.mangle(D);
Peter Collingbourne14110472011-01-13 18:57:25 +00001180}
1181void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
1182 CXXDtorType Type,
Michael J. Spencer50118da2011-12-01 09:55:00 +00001183 raw_ostream & Out) {
1184 MicrosoftCXXNameMangler mangler(*this, Out);
1185 mangler.mangle(D);
Peter Collingbourne14110472011-01-13 18:57:25 +00001186}
1187void MicrosoftMangleContext::mangleReferenceTemporary(const clang::VarDecl *,
Chris Lattner5f9e2722011-07-23 10:55:15 +00001188 raw_ostream &) {
David Blaikieb219cfc2011-09-23 05:06:16 +00001189 llvm_unreachable("Can't yet mangle reference temporaries!");
Peter Collingbourne14110472011-01-13 18:57:25 +00001190}
1191
1192MangleContext *clang::createMicrosoftMangleContext(ASTContext &Context,
David Blaikied6471f72011-09-25 23:23:43 +00001193 DiagnosticsEngine &Diags) {
Peter Collingbourne14110472011-01-13 18:57:25 +00001194 return new MicrosoftMangleContext(Context, Diags);
1195}