blob: 960b1fe77a09a35d5d59da82803b4a8f9f24af63 [file] [log] [blame]
Charles Davis74ce8592010-06-09 23:25:41 +00001//===--- MicrosoftCXXABI.cpp - Emit LLVM Code from ASTs for a Module ------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This provides C++ code generation targetting the Microsoft Visual C++ ABI.
11// The class in this file generates structures that follow the Microsoft
12// Visual C++ ABI, which is actually not very well documented at all outside
13// of Microsoft.
14//
15//===----------------------------------------------------------------------===//
16
17#include "CGCXXABI.h"
18#include "CodeGenModule.h"
19#include "Mangle.h"
20#include "clang/AST/ASTContext.h"
21#include "clang/AST/Decl.h"
22#include "clang/AST/DeclCXX.h"
23#include "clang/AST/DeclTemplate.h"
24#include "clang/AST/ExprCXX.h"
25#include "CGVTables.h"
26
27using namespace clang;
28using namespace CodeGen;
29
30namespace {
31
Charles Davis9af2d4a2010-06-11 03:07:32 +000032/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
33/// Microsoft Visual C++ ABI.
34class MicrosoftCXXNameMangler {
35 MangleContext &Context;
36 llvm::raw_svector_ostream Out;
37
38 ASTContext &getASTContext() const { return Context.getASTContext(); }
39
40public:
41 MicrosoftCXXNameMangler(MangleContext &C, llvm::SmallVectorImpl<char> &Res)
42 : Context(C), Out(Res) { }
43
44 llvm::raw_svector_ostream &getStream() { return Out; }
45
46 void mangle(const NamedDecl *D, llvm::StringRef Prefix = "?");
47 void mangleName(const NamedDecl *ND);
Charles Davis89338af2010-06-16 05:33:16 +000048 void mangleFunctionEncoding(const FunctionDecl *FD);
Charles Davis2d7b10c2010-06-14 05:29:01 +000049 void mangleVariableEncoding(const VarDecl *VD);
Charles Davis108f5a22010-06-18 07:51:00 +000050 void mangleNumber(int64_t Number);
Charles Davis7dacc952010-06-12 08:11:16 +000051 void mangleType(QualType T);
Charles Davis9af2d4a2010-06-11 03:07:32 +000052
53private:
54 void mangleUnqualifiedName(const NamedDecl *ND) {
55 mangleUnqualifiedName(ND, ND->getDeclName());
56 }
57 void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name);
58 void mangleSourceName(const IdentifierInfo *II);
59 void manglePostfix(const DeclContext *DC, bool NoFunction=false);
Charles Davis8c02c132010-06-17 06:47:31 +000060 void mangleOperatorName(OverloadedOperatorKind OO);
Charles Davis2d7b10c2010-06-14 05:29:01 +000061 void mangleQualifiers(Qualifiers Quals, bool IsMember);
Charles Davis9af2d4a2010-06-11 03:07:32 +000062
63 void mangleObjCMethodName(const ObjCMethodDecl *MD);
64
Charles Davis7dacc952010-06-12 08:11:16 +000065 // Declare manglers for every type class.
66#define ABSTRACT_TYPE(CLASS, PARENT)
67#define NON_CANONICAL_TYPE(CLASS, PARENT)
68#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
69#include "clang/AST/TypeNodes.def"
70
Charles Davis108f5a22010-06-18 07:51:00 +000071 void mangleType(const TagType*);
Charles Davis77552762010-07-03 02:41:45 +000072 void mangleType(const FunctionType *T, const FunctionDecl *D,
73 bool IsStructor, bool IsInstMethod);
Charles Davis2a4773072010-06-30 08:09:57 +000074 void mangleType(const ArrayType *T, bool IsGlobal);
75 void mangleExtraDimensions(QualType T);
Charles Davis89338af2010-06-16 05:33:16 +000076 void mangleFunctionClass(const FunctionDecl *FD);
77 void mangleCallingConvention(const FunctionType *T);
78 void mangleThrowSpecification(const FunctionProtoType *T);
79
Charles Davis9af2d4a2010-06-11 03:07:32 +000080};
81
Charles Davis74ce8592010-06-09 23:25:41 +000082/// MicrosoftMangleContext - Overrides the default MangleContext for the
83/// Microsoft Visual C++ ABI.
84class MicrosoftMangleContext : public MangleContext {
85public:
86 MicrosoftMangleContext(ASTContext &Context,
87 Diagnostic &Diags) : MangleContext(Context, Diags) { }
Charles Davisb6a5a0d2010-06-11 04:25:47 +000088 virtual bool shouldMangleDeclName(const NamedDecl *D);
Charles Davis74ce8592010-06-09 23:25:41 +000089 virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
90 virtual void mangleThunk(const CXXMethodDecl *MD,
91 const ThunkInfo &Thunk,
92 llvm::SmallVectorImpl<char> &);
93 virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
94 const ThisAdjustment &ThisAdjustment,
95 llvm::SmallVectorImpl<char> &);
96 virtual void mangleGuardVariable(const VarDecl *D,
97 llvm::SmallVectorImpl<char> &);
98 virtual void mangleCXXVTable(const CXXRecordDecl *RD,
99 llvm::SmallVectorImpl<char> &);
100 virtual void mangleCXXVTT(const CXXRecordDecl *RD,
101 llvm::SmallVectorImpl<char> &);
102 virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
103 const CXXRecordDecl *Type,
104 llvm::SmallVectorImpl<char> &);
105 virtual void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &);
106 virtual void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &);
107 virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
108 llvm::SmallVectorImpl<char> &);
109 virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
110 llvm::SmallVectorImpl<char> &);
111};
112
113class MicrosoftCXXABI : public CXXABI {
114 MicrosoftMangleContext MangleCtx;
115public:
116 MicrosoftCXXABI(CodeGenModule &CGM)
117 : MangleCtx(CGM.getContext(), CGM.getDiags()) {}
118
119 MicrosoftMangleContext &getMangleContext() {
120 return MangleCtx;
121 }
122};
123
124}
125
Charles Davisb6a5a0d2010-06-11 04:25:47 +0000126static bool isInCLinkageSpecification(const Decl *D) {
127 D = D->getCanonicalDecl();
128 for (const DeclContext *DC = D->getDeclContext();
129 !DC->isTranslationUnit(); DC = DC->getParent()) {
130 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
131 return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
132 }
Charles Davis7dacc952010-06-12 08:11:16 +0000133
Charles Davisb6a5a0d2010-06-11 04:25:47 +0000134 return false;
135}
136
137bool MicrosoftMangleContext::shouldMangleDeclName(const NamedDecl *D) {
138 // In C, functions with no attributes never need to be mangled. Fastpath them.
139 if (!getASTContext().getLangOptions().CPlusPlus && !D->hasAttrs())
140 return false;
141
142 // Any decl can be declared with __asm("foo") on it, and this takes precedence
143 // over all other naming in the .o file.
144 if (D->hasAttr<AsmLabelAttr>())
145 return true;
146
147 // Clang's "overloadable" attribute extension to C/C++ implies name mangling
148 // (always) as does passing a C++ member function and a function
149 // whose name is not a simple identifier.
150 const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
151 if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) ||
152 !FD->getDeclName().isIdentifier()))
153 return true;
154
155 // Otherwise, no mangling is done outside C++ mode.
156 if (!getASTContext().getLangOptions().CPlusPlus)
157 return false;
158
Charles Davis7dacc952010-06-12 08:11:16 +0000159 // Variables at global scope with internal linkage are not mangled.
160 if (!FD) {
161 const DeclContext *DC = D->getDeclContext();
162 if (DC->isTranslationUnit() && D->getLinkage() == InternalLinkage)
163 return false;
164 }
165
Charles Davisb6a5a0d2010-06-11 04:25:47 +0000166 // C functions and "main" are not mangled.
167 if ((FD && FD->isMain()) || isInCLinkageSpecification(D))
168 return false;
169
170 return true;
171}
172
Charles Davis9af2d4a2010-06-11 03:07:32 +0000173void MicrosoftCXXNameMangler::mangle(const NamedDecl *D,
174 llvm::StringRef Prefix) {
175 // MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
176 // Therefore it's really important that we don't decorate the
177 // name with leading underscores or leading/trailing at signs. So, emit a
178 // asm marker at the start so we get the name right.
179 Out << '\01'; // LLVM IR Marker for __asm("foo")
180
181 // Any decl can be declared with __asm("foo") on it, and this takes precedence
182 // over all other naming in the .o file.
183 if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
184 // If we have an asm name, then we use it as the mangling.
185 Out << ALA->getLabel();
186 return;
187 }
188
Charles Davis89338af2010-06-16 05:33:16 +0000189 // <mangled-name> ::= ? <name> <type-encoding>
Charles Davis9af2d4a2010-06-11 03:07:32 +0000190 Out << Prefix;
191 mangleName(D);
Charles Davis89338af2010-06-16 05:33:16 +0000192 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
193 mangleFunctionEncoding(FD);
194 else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
Charles Davis2d7b10c2010-06-14 05:29:01 +0000195 mangleVariableEncoding(VD);
Charles Davis89338af2010-06-16 05:33:16 +0000196 // TODO: Fields? Can MSVC even mangle them?
197}
198
199void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
200 // <type-encoding> ::= <function-class> <function-type>
201
202 // Don't mangle in the type if this isn't a decl we should typically mangle.
203 if (!Context.shouldMangleDeclName(FD))
204 return;
205
206 // We should never ever see a FunctionNoProtoType at this point.
207 // We don't even know how to mangle their types anyway :).
Charles Davisf4db33c2010-06-26 03:50:05 +0000208 const FunctionProtoType *FT = cast<FunctionProtoType>(FD->getType());
Charles Davis89338af2010-06-16 05:33:16 +0000209
Charles Davisf4db33c2010-06-26 03:50:05 +0000210 bool InStructor = false, InInstMethod = false;
Charles Davis89338af2010-06-16 05:33:16 +0000211 const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
212 if (MD) {
Charles Davisf4db33c2010-06-26 03:50:05 +0000213 if (MD->isInstance())
214 InInstMethod = true;
Charles Davis89338af2010-06-16 05:33:16 +0000215 if (isa<CXXConstructorDecl>(MD) || isa<CXXDestructorDecl>(MD))
216 InStructor = true;
217 }
218
219 // First, the function class.
220 mangleFunctionClass(FD);
221
Charles Davis77552762010-07-03 02:41:45 +0000222 mangleType(FT, FD, InStructor, InInstMethod);
Charles Davis2d7b10c2010-06-14 05:29:01 +0000223}
224
225void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) {
Charles Davis89338af2010-06-16 05:33:16 +0000226 // <type-encoding> ::= <storage-class> <variable-type>
Charles Davis2d7b10c2010-06-14 05:29:01 +0000227 // <storage-class> ::= 0 # private static member
228 // ::= 1 # protected static member
229 // ::= 2 # public static member
230 // ::= 3 # global
231 // ::= 4 # static local
232
233 // The first character in the encoding (after the name) is the storage class.
234 if (VD->isStaticDataMember()) {
235 // If it's a static member, it also encodes the access level.
236 switch (VD->getAccess()) {
237 default:
238 case AS_private: Out << '0'; break;
239 case AS_protected: Out << '1'; break;
240 case AS_public: Out << '2'; break;
241 }
242 }
243 else if (!VD->isStaticLocal())
244 Out << '3';
245 else
246 Out << '4';
247 // Now mangle the type.
248 // <variable-type> ::= <type> <cvr-qualifiers>
Charles Davis2a4773072010-06-30 08:09:57 +0000249 // ::= <type> A # pointers, references, arrays
Charles Davisf4db33c2010-06-26 03:50:05 +0000250 // Pointers and references are odd. The type of 'int * const foo;' gets
251 // mangled as 'QAHA' instead of 'PAHB', for example.
Charles Davis2d7b10c2010-06-14 05:29:01 +0000252 QualType Ty = VD->getType();
Charles Davisf4db33c2010-06-26 03:50:05 +0000253 if (Ty->isPointerType() || Ty->isReferenceType()) {
254 mangleType(Ty);
255 Out << 'A';
Charles Davis2a4773072010-06-30 08:09:57 +0000256 } else if (Ty->isArrayType()) {
257 // Global arrays are funny, too.
258 mangleType(static_cast<ArrayType *>(Ty.getTypePtr()), true);
259 Out << 'A';
Charles Davisf4db33c2010-06-26 03:50:05 +0000260 } else {
261 mangleType(Ty.getLocalUnqualifiedType());
262 mangleQualifiers(Ty.getLocalQualifiers(), false);
263 }
Charles Davis9af2d4a2010-06-11 03:07:32 +0000264}
265
266void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {
267 // <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @
268 const DeclContext *DC = ND->getDeclContext();
269
270 // Always start with the unqualified name.
271 mangleUnqualifiedName(ND);
272
273 // If this is an extern variable declared locally, the relevant DeclContext
274 // is that of the containing namespace, or the translation unit.
275 if (isa<FunctionDecl>(DC) && ND->hasLinkage())
276 while (!DC->isNamespace() && !DC->isTranslationUnit())
277 DC = DC->getParent();
278
279 manglePostfix(DC);
280
281 // Terminate the whole name with an '@'.
282 Out << '@';
283}
284
Charles Davis108f5a22010-06-18 07:51:00 +0000285void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
286 // <number> ::= [?] <decimal digit> # <= 9
287 // ::= [?] <hex digit>+ @ # > 9; A = 0, B = 1, etc...
288 if (Number < 0) {
289 Out << '?';
290 Number = -Number;
291 }
292 if (Number <= 9) {
293 Out << Number;
294 } else {
295 // We have to build up the encoding in reverse order, so it will come
296 // out right when we write it out.
297 char Encoding[16];
298 char *EndPtr = Encoding+sizeof(Encoding);
299 char *CurPtr = EndPtr;
300 while (Number) {
301 *--CurPtr = 'A' + (Number % 16);
302 Number /= 16;
303 }
304 Out.write(CurPtr, EndPtr-CurPtr);
305 Out << '@';
306 }
307}
308
Charles Davis9af2d4a2010-06-11 03:07:32 +0000309void
310MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
311 DeclarationName Name) {
312 // <unqualified-name> ::= <operator-name>
313 // ::= <ctor-dtor-name>
314 // ::= <source-name>
315 switch (Name.getNameKind()) {
316 case DeclarationName::Identifier: {
317 if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
318 mangleSourceName(II);
319 break;
320 }
321
322 // Otherwise, an anonymous entity. We must have a declaration.
323 assert(ND && "mangling empty name without declaration");
324
325 if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
326 if (NS->isAnonymousNamespace()) {
327 Out << "?A";
328 break;
329 }
330 }
331
332 // We must have an anonymous struct.
333 const TagDecl *TD = cast<TagDecl>(ND);
334 if (const TypedefDecl *D = TD->getTypedefForAnonDecl()) {
335 assert(TD->getDeclContext() == D->getDeclContext() &&
336 "Typedef should not be in another decl context!");
337 assert(D->getDeclName().getAsIdentifierInfo() &&
338 "Typedef was not named!");
339 mangleSourceName(D->getDeclName().getAsIdentifierInfo());
340 break;
341 }
342
Charles Davis77552762010-07-03 02:41:45 +0000343 // When VC encounters an anonymous type with no tag and no typedef,
344 // it literally emits '<unnamed-tag>'.
345 Out << "<unnamed-tag>";
Charles Davis9af2d4a2010-06-11 03:07:32 +0000346 break;
347 }
348
349 case DeclarationName::ObjCZeroArgSelector:
350 case DeclarationName::ObjCOneArgSelector:
351 case DeclarationName::ObjCMultiArgSelector:
352 assert(false && "Can't mangle Objective-C selector names here!");
353 break;
354
355 case DeclarationName::CXXConstructorName:
356 assert(false && "Can't mangle constructors yet!");
357 break;
358
359 case DeclarationName::CXXDestructorName:
360 assert(false && "Can't mangle destructors yet!");
361 break;
362
363 case DeclarationName::CXXConversionFunctionName:
364 // <operator-name> ::= ?B # (cast)
365 // The target type is encoded as the return type.
366 Out << "?B";
367 break;
368
369 case DeclarationName::CXXOperatorName:
Charles Davis8c02c132010-06-17 06:47:31 +0000370 mangleOperatorName(Name.getCXXOverloadedOperator());
371 break;
Charles Davis9af2d4a2010-06-11 03:07:32 +0000372
373 case DeclarationName::CXXLiteralOperatorName:
374 // FIXME: Was this added in VS2010? Does MS even know how to mangle this?
375 assert(false && "Don't know how to mangle literal operators yet!");
376 break;
377
378 case DeclarationName::CXXUsingDirective:
379 assert(false && "Can't mangle a using directive name!");
380 break;
381 }
382}
383
384void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC,
385 bool NoFunction) {
386 // <postfix> ::= <unqualified-name> [<postfix>]
387 // ::= <template-postfix> <template-args> [<postfix>]
388 // ::= <template-param>
389 // ::= <substitution> [<postfix>]
390
391 if (!DC) return;
392
393 while (isa<LinkageSpecDecl>(DC))
394 DC = DC->getParent();
395
396 if (DC->isTranslationUnit())
397 return;
398
399 if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
400 llvm::SmallString<64> Name;
Fariborz Jahanian9b5528d2010-06-24 00:08:06 +0000401 Context.mangleBlock(GlobalDecl(), BD, Name);
Charles Davis9af2d4a2010-06-11 03:07:32 +0000402 Out << Name << '@';
403 return manglePostfix(DC->getParent(), NoFunction);
404 }
405
406 if (NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)))
407 return;
408 else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC))
409 mangleObjCMethodName(Method);
410 else {
411 mangleUnqualifiedName(cast<NamedDecl>(DC));
412 manglePostfix(DC->getParent(), NoFunction);
413 }
414}
415
Charles Davis8c02c132010-06-17 06:47:31 +0000416void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO) {
417 switch (OO) {
418 // ?0 # constructor
419 // ?1 # destructor
420 // <operator-name> ::= ?2 # new
421 case OO_New: Out << "?2"; break;
422 // <operator-name> ::= ?3 # delete
423 case OO_Delete: Out << "?3"; break;
424 // <operator-name> ::= ?4 # =
425 case OO_Equal: Out << "?4"; break;
426 // <operator-name> ::= ?5 # >>
427 case OO_GreaterGreater: Out << "?5"; break;
428 // <operator-name> ::= ?6 # <<
429 case OO_LessLess: Out << "?6"; break;
430 // <operator-name> ::= ?7 # !
431 case OO_Exclaim: Out << "?7"; break;
432 // <operator-name> ::= ?8 # ==
433 case OO_EqualEqual: Out << "?8"; break;
434 // <operator-name> ::= ?9 # !=
435 case OO_ExclaimEqual: Out << "?9"; break;
436 // <operator-name> ::= ?A # []
437 case OO_Subscript: Out << "?A"; break;
438 // ?B # conversion
439 // <operator-name> ::= ?C # ->
440 case OO_Arrow: Out << "?C"; break;
441 // <operator-name> ::= ?D # *
442 case OO_Star: Out << "?D"; break;
443 // <operator-name> ::= ?E # ++
444 case OO_PlusPlus: Out << "?E"; break;
445 // <operator-name> ::= ?F # --
446 case OO_MinusMinus: Out << "?F"; break;
447 // <operator-name> ::= ?G # -
448 case OO_Minus: Out << "?G"; break;
449 // <operator-name> ::= ?H # +
450 case OO_Plus: Out << "?H"; break;
451 // <operator-name> ::= ?I # &
452 case OO_Amp: Out << "?I"; break;
453 // <operator-name> ::= ?J # ->*
454 case OO_ArrowStar: Out << "?J"; break;
455 // <operator-name> ::= ?K # /
456 case OO_Slash: Out << "?K"; break;
457 // <operator-name> ::= ?L # %
458 case OO_Percent: Out << "?L"; break;
459 // <operator-name> ::= ?M # <
460 case OO_Less: Out << "?M"; break;
461 // <operator-name> ::= ?N # <=
462 case OO_LessEqual: Out << "?N"; break;
463 // <operator-name> ::= ?O # >
464 case OO_Greater: Out << "?O"; break;
465 // <operator-name> ::= ?P # >=
466 case OO_GreaterEqual: Out << "?P"; break;
467 // <operator-name> ::= ?Q # ,
468 case OO_Comma: Out << "?Q"; break;
469 // <operator-name> ::= ?R # ()
470 case OO_Call: Out << "?R"; break;
471 // <operator-name> ::= ?S # ~
472 case OO_Tilde: Out << "?S"; break;
473 // <operator-name> ::= ?T # ^
474 case OO_Caret: Out << "?T"; break;
475 // <operator-name> ::= ?U # |
476 case OO_Pipe: Out << "?U"; break;
477 // <operator-name> ::= ?V # &&
478 case OO_AmpAmp: Out << "?V"; break;
479 // <operator-name> ::= ?W # ||
480 case OO_PipePipe: Out << "?W"; break;
481 // <operator-name> ::= ?X # *=
482 case OO_StarEqual: Out << "?X"; break;
483 // <operator-name> ::= ?Y # +=
484 case OO_PlusEqual: Out << "?Y"; break;
485 // <operator-name> ::= ?Z # -=
486 case OO_MinusEqual: Out << "?Z"; break;
487 // <operator-name> ::= ?_0 # /=
488 case OO_SlashEqual: Out << "?_0"; break;
489 // <operator-name> ::= ?_1 # %=
490 case OO_PercentEqual: Out << "?_1"; break;
491 // <operator-name> ::= ?_2 # >>=
492 case OO_GreaterGreaterEqual: Out << "?_2"; break;
493 // <operator-name> ::= ?_3 # <<=
494 case OO_LessLessEqual: Out << "?_3"; break;
495 // <operator-name> ::= ?_4 # &=
496 case OO_AmpEqual: Out << "?_4"; break;
497 // <operator-name> ::= ?_5 # |=
498 case OO_PipeEqual: Out << "?_5"; break;
499 // <operator-name> ::= ?_6 # ^=
500 case OO_CaretEqual: Out << "?_6"; break;
501 // ?_7 # vftable
502 // ?_8 # vbtable
503 // ?_9 # vcall
504 // ?_A # typeof
505 // ?_B # local static guard
506 // ?_C # string
507 // ?_D # vbase destructor
508 // ?_E # vector deleting destructor
509 // ?_F # default constructor closure
510 // ?_G # scalar deleting destructor
511 // ?_H # vector constructor iterator
512 // ?_I # vector destructor iterator
513 // ?_J # vector vbase constructor iterator
514 // ?_K # virtual displacement map
515 // ?_L # eh vector constructor iterator
516 // ?_M # eh vector destructor iterator
517 // ?_N # eh vector vbase constructor iterator
518 // ?_O # copy constructor closure
519 // ?_P<name> # udt returning <name>
520 // ?_Q # <unknown>
521 // ?_R0 # RTTI Type Descriptor
522 // ?_R1 # RTTI Base Class Descriptor at (a,b,c,d)
523 // ?_R2 # RTTI Base Class Array
524 // ?_R3 # RTTI Class Hierarchy Descriptor
525 // ?_R4 # RTTI Complete Object Locator
526 // ?_S # local vftable
527 // ?_T # local vftable constructor closure
528 // <operator-name> ::= ?_U # new[]
529 case OO_Array_New: Out << "?_U"; break;
530 // <operator-name> ::= ?_V # delete[]
531 case OO_Array_Delete: Out << "?_V"; break;
532
533 case OO_Conditional:
534 assert(false && "Don't know how to mangle ?:");
535 break;
536
537 case OO_None:
538 case NUM_OVERLOADED_OPERATORS:
539 assert(false && "Not an overloaded operator");
540 break;
541 }
542}
543
Charles Davis9af2d4a2010-06-11 03:07:32 +0000544void MicrosoftCXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
545 // <source name> ::= <identifier> @
546 Out << II->getName() << '@';
547}
548
549void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
550 llvm::SmallString<64> Buffer;
551 MiscNameMangler(Context, Buffer).mangleObjCMethodName(MD);
552 Out << Buffer;
553}
554
Charles Davis2d7b10c2010-06-14 05:29:01 +0000555void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
556 bool IsMember) {
557 // <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
558 // 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
559 // 'I' means __restrict (32/64-bit).
560 // Note that the MSVC __restrict keyword isn't the same as the C99 restrict
561 // keyword!
562 // <base-cvr-qualifiers> ::= A # near
563 // ::= B # near const
564 // ::= C # near volatile
565 // ::= D # near const volatile
566 // ::= E # far (16-bit)
567 // ::= F # far const (16-bit)
568 // ::= G # far volatile (16-bit)
569 // ::= H # far const volatile (16-bit)
570 // ::= I # huge (16-bit)
571 // ::= J # huge const (16-bit)
572 // ::= K # huge volatile (16-bit)
573 // ::= L # huge const volatile (16-bit)
574 // ::= M <basis> # based
575 // ::= N <basis> # based const
576 // ::= O <basis> # based volatile
577 // ::= P <basis> # based const volatile
578 // ::= Q # near member
579 // ::= R # near const member
580 // ::= S # near volatile member
581 // ::= T # near const volatile member
582 // ::= U # far member (16-bit)
583 // ::= V # far const member (16-bit)
584 // ::= W # far volatile member (16-bit)
585 // ::= X # far const volatile member (16-bit)
586 // ::= Y # huge member (16-bit)
587 // ::= Z # huge const member (16-bit)
588 // ::= 0 # huge volatile member (16-bit)
589 // ::= 1 # huge const volatile member (16-bit)
590 // ::= 2 <basis> # based member
591 // ::= 3 <basis> # based const member
592 // ::= 4 <basis> # based volatile member
593 // ::= 5 <basis> # based const volatile member
594 // ::= 6 # near function (pointers only)
595 // ::= 7 # far function (pointers only)
596 // ::= 8 # near method (pointers only)
597 // ::= 9 # far method (pointers only)
598 // ::= _A <basis> # based function (pointers only)
599 // ::= _B <basis> # based function (far?) (pointers only)
600 // ::= _C <basis> # based method (pointers only)
601 // ::= _D <basis> # based method (far?) (pointers only)
602 // <basis> ::= 0 # __based(void)
603 // ::= 1 # __based(segment)?
604 // ::= 2 <name> # __based(name)
605 // ::= 3 # ?
606 // ::= 4 # ?
607 // ::= 5 # not really based
608 if (!IsMember) {
609 if (!Quals.hasVolatile()) {
610 if (!Quals.hasConst())
611 Out << 'A';
612 else
613 Out << 'B';
614 } else {
615 if (!Quals.hasConst())
616 Out << 'C';
617 else
618 Out << 'D';
619 }
620 } else {
621 if (!Quals.hasVolatile()) {
622 if (!Quals.hasConst())
623 Out << 'Q';
624 else
625 Out << 'R';
626 } else {
627 if (!Quals.hasConst())
628 Out << 'S';
629 else
630 Out << 'T';
631 }
632 }
633
634 // FIXME: For now, just drop all extension qualifiers on the floor.
635}
636
Charles Davis7dacc952010-06-12 08:11:16 +0000637void MicrosoftCXXNameMangler::mangleType(QualType T) {
638 // Only operate on the canonical type!
639 T = getASTContext().getCanonicalType(T);
640
Charles Davisf4db33c2010-06-26 03:50:05 +0000641 Qualifiers Quals = T.getLocalQualifiers();
642 if (Quals) {
643 // We have to mangle these now, while we still have enough information.
644 // <pointer-cvr-qualifiers> ::= P # pointer
645 // ::= Q # const pointer
646 // ::= R # volatile pointer
647 // ::= S # const volatile pointer
648 if (T->isPointerType()) {
649 if (!Quals.hasVolatile()) {
650 Out << 'Q';
651 } else {
652 if (!Quals.hasConst())
653 Out << 'R';
654 else
655 Out << 'S';
656 }
657 } else
658 // Just emit qualifiers like normal.
659 // NB: When we mangle a pointer/reference type, and the pointee
660 // type has no qualifiers, the lack of qualifier gets mangled
661 // in there.
662 mangleQualifiers(Quals, false);
663 }
664 else if (T->isPointerType()) {
665 Out << 'P';
666 }
Charles Davis7dacc952010-06-12 08:11:16 +0000667 switch (T->getTypeClass()) {
668#define ABSTRACT_TYPE(CLASS, PARENT)
669#define NON_CANONICAL_TYPE(CLASS, PARENT) \
670case Type::CLASS: \
671llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
672return;
Charles Davis2a4773072010-06-30 08:09:57 +0000673#define TYPE(CLASS, PARENT) \
674case Type::CLASS: \
675mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \
676break;
Charles Davis7dacc952010-06-12 08:11:16 +0000677#include "clang/AST/TypeNodes.def"
Charles Davis7dacc952010-06-12 08:11:16 +0000678 }
679}
680
681void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T) {
682 // <type> ::= <builtin-type>
683 // <builtin-type> ::= X # void
684 // ::= C # signed char
685 // ::= D # char
686 // ::= E # unsigned char
687 // ::= F # short
688 // ::= G # unsigned short (or wchar_t if it's not a builtin)
689 // ::= H # int
690 // ::= I # unsigned int
691 // ::= J # long
692 // ::= K # unsigned long
693 // L # <none>
694 // ::= M # float
695 // ::= N # double
696 // ::= O # long double (__float80 is mangled differently)
697 // ::= _D # __int8 (yup, it's a distinct type in MSVC)
698 // ::= _E # unsigned __int8
699 // ::= _F # __int16
700 // ::= _G # unsigned __int16
701 // ::= _H # __int32
702 // ::= _I # unsigned __int32
703 // ::= _J # long long, __int64
704 // ::= _K # unsigned long long, __int64
705 // ::= _L # __int128
706 // ::= _M # unsigned __int128
707 // ::= _N # bool
708 // _O # <array in parameter>
709 // ::= _T # __float80 (Intel)
710 // ::= _W # wchar_t
711 // ::= _Z # __float80 (Digital Mars)
712 switch (T->getKind()) {
713 case BuiltinType::Void: Out << 'X'; break;
714 case BuiltinType::SChar: Out << 'C'; break;
715 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'D'; break;
716 case BuiltinType::UChar: Out << 'E'; break;
717 case BuiltinType::Short: Out << 'F'; break;
718 case BuiltinType::UShort: Out << 'G'; break;
719 case BuiltinType::Int: Out << 'H'; break;
720 case BuiltinType::UInt: Out << 'I'; break;
721 case BuiltinType::Long: Out << 'J'; break;
722 case BuiltinType::ULong: Out << 'K'; break;
723 case BuiltinType::Float: Out << 'M'; break;
724 case BuiltinType::Double: Out << 'N'; break;
725 // TODO: Determine size and mangle accordingly
726 case BuiltinType::LongDouble: Out << 'O'; break;
727 // TODO: __int8 and friends
728 case BuiltinType::LongLong: Out << "_J"; break;
729 case BuiltinType::ULongLong: Out << "_K"; break;
730 case BuiltinType::Int128: Out << "_L"; break;
731 case BuiltinType::UInt128: Out << "_M"; break;
732 case BuiltinType::Bool: Out << "_N"; break;
733 case BuiltinType::WChar: Out << "_W"; break;
734
735 case BuiltinType::Overload:
736 case BuiltinType::Dependent:
737 assert(false &&
738 "Overloaded and dependent types shouldn't get to name mangling");
739 break;
740 case BuiltinType::UndeducedAuto:
741 assert(0 && "Should not see undeduced auto here");
742 break;
743 case BuiltinType::ObjCId: Out << "PAUobjc_object@@"; break;
744 case BuiltinType::ObjCClass: Out << "PAUobjc_class@@"; break;
745 case BuiltinType::ObjCSel: Out << "PAUobjc_selector@@"; break;
746
747 case BuiltinType::Char16:
748 case BuiltinType::Char32:
749 case BuiltinType::NullPtr:
750 assert(false && "Don't know how to mangle this type");
751 break;
752 }
753}
754
Charles Davis89338af2010-06-16 05:33:16 +0000755// <type> ::= <function-type>
756void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T) {
757 // Structors only appear in decls, so at this point we know it's not a
758 // structor type.
Charles Davis2a4773072010-06-30 08:09:57 +0000759 // I'll probably have mangleType(MemberPointerType) call the mangleType()
760 // method directly.
Charles Davis77552762010-07-03 02:41:45 +0000761 mangleType(T, NULL, false, false);
Charles Davis89338af2010-06-16 05:33:16 +0000762}
763void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T) {
764 llvm_unreachable("Can't mangle K&R function prototypes");
765}
766
767void MicrosoftCXXNameMangler::mangleType(const FunctionType *T,
Charles Davis77552762010-07-03 02:41:45 +0000768 const FunctionDecl *D,
Charles Davisf4db33c2010-06-26 03:50:05 +0000769 bool IsStructor,
770 bool IsInstMethod) {
771 // <function-type> ::= <this-cvr-qualifiers> <calling-convention>
772 // <return-type> <argument-list> <throw-spec>
Charles Davis89338af2010-06-16 05:33:16 +0000773 const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
774
Charles Davisf4db33c2010-06-26 03:50:05 +0000775 // If this is a C++ instance method, mangle the CVR qualifiers for the
776 // this pointer.
777 if (IsInstMethod)
778 mangleQualifiers(Qualifiers::fromCVRMask(Proto->getTypeQuals()), false);
779
780 mangleCallingConvention(T);
781
782 // <return-type> ::= <type>
783 // ::= @ # structors (they have no declared return type)
Charles Davis89338af2010-06-16 05:33:16 +0000784 if (IsStructor)
785 Out << '@';
786 else
787 mangleType(Proto->getResultType());
788
789 // <argument-list> ::= X # void
790 // ::= <type>+ @
791 // ::= <type>* Z # varargs
792 if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
793 Out << 'X';
794 } else {
Charles Davis77552762010-07-03 02:41:45 +0000795 if (D) {
796 // If we got a decl, use the "types-as-written" to make sure arrays
797 // get mangled right.
798 for (FunctionDecl::param_const_iterator Parm = D->param_begin(),
799 ParmEnd = D->param_end();
800 Parm != ParmEnd; ++Parm)
801 mangleType((*Parm)->getTypeSourceInfo()->getType());
802 } else {
803 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
804 ArgEnd = Proto->arg_type_end();
805 Arg != ArgEnd; ++Arg)
806 mangleType(*Arg);
807 }
Charles Davis89338af2010-06-16 05:33:16 +0000808 // <builtin-type> ::= Z # ellipsis
809 if (Proto->isVariadic())
810 Out << 'Z';
811 else
812 Out << '@';
813 }
814
815 mangleThrowSpecification(Proto);
816}
817
818void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
819 // <function-class> ::= A # private: near
820 // ::= B # private: far
821 // ::= C # private: static near
822 // ::= D # private: static far
823 // ::= E # private: virtual near
824 // ::= F # private: virtual far
825 // ::= G # private: thunk near
826 // ::= H # private: thunk far
827 // ::= I # protected: near
828 // ::= J # protected: far
829 // ::= K # protected: static near
830 // ::= L # protected: static far
831 // ::= M # protected: virtual near
832 // ::= N # protected: virtual far
833 // ::= O # protected: thunk near
834 // ::= P # protected: thunk far
835 // ::= Q # public: near
836 // ::= R # public: far
837 // ::= S # public: static near
838 // ::= T # public: static far
839 // ::= U # public: virtual near
840 // ::= V # public: virtual far
841 // ::= W # public: thunk near
842 // ::= X # public: thunk far
843 // ::= Y # global near
844 // ::= Z # global far
845 if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
846 switch (MD->getAccess()) {
847 default:
848 case AS_private:
849 if (MD->isStatic())
850 Out << 'C';
851 else if (MD->isVirtual())
852 Out << 'E';
853 else
854 Out << 'A';
855 break;
856 case AS_protected:
857 if (MD->isStatic())
858 Out << 'K';
859 else if (MD->isVirtual())
860 Out << 'M';
861 else
862 Out << 'I';
863 break;
864 case AS_public:
865 if (MD->isStatic())
866 Out << 'S';
867 else if (MD->isVirtual())
868 Out << 'U';
869 else
870 Out << 'Q';
871 }
872 } else
873 Out << 'Y';
874}
875void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) {
876 // <calling-convention> ::= A # __cdecl
877 // ::= B # __export __cdecl
878 // ::= C # __pascal
879 // ::= D # __export __pascal
880 // ::= E # __thiscall
881 // ::= F # __export __thiscall
882 // ::= G # __stdcall
883 // ::= H # __export __stdcall
884 // ::= I # __fastcall
885 // ::= J # __export __fastcall
886 // The 'export' calling conventions are from a bygone era
887 // (*cough*Win16*cough*) when functions were declared for export with
888 // that keyword. (It didn't actually export them, it just made them so
889 // that they could be in a DLL and somebody from another module could call
890 // them.)
891 switch (T->getCallConv()) {
892 case CC_Default:
893 case CC_C: Out << 'A'; break;
894 case CC_X86ThisCall: Out << 'E'; break;
895 case CC_X86StdCall: Out << 'G'; break;
896 case CC_X86FastCall: Out << 'I'; break;
897 }
898}
899void MicrosoftCXXNameMangler::mangleThrowSpecification(
900 const FunctionProtoType *FT) {
901 // <throw-spec> ::= Z # throw(...) (default)
902 // ::= @ # throw() or __declspec/__attribute__((nothrow))
903 // ::= <type>+
Charles Davisf4db33c2010-06-26 03:50:05 +0000904 // NOTE: Since the Microsoft compiler ignores throw specifications, they are
905 // all actually mangled as 'Z'. (They're ignored because their associated
906 // functionality isn't implemented, and probably never will be.)
907 Out << 'Z';
Charles Davis89338af2010-06-16 05:33:16 +0000908}
909
Charles Davis2a4773072010-06-30 08:09:57 +0000910void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T) {
911 assert(false && "Don't know how to mangle UnresolvedUsingTypes yet!");
912}
913
Charles Davis108f5a22010-06-18 07:51:00 +0000914// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
915// <union-type> ::= T <name>
916// <struct-type> ::= U <name>
917// <class-type> ::= V <name>
918// <enum-type> ::= W <size> <name>
919void MicrosoftCXXNameMangler::mangleType(const EnumType *T) {
920 mangleType(static_cast<const TagType*>(T));
921}
922void MicrosoftCXXNameMangler::mangleType(const RecordType *T) {
923 mangleType(static_cast<const TagType*>(T));
924}
925void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
926 switch (T->getDecl()->getTagKind()) {
927 case TTK_Union:
928 Out << 'T';
929 break;
930 case TTK_Struct:
931 Out << 'U';
932 break;
933 case TTK_Class:
934 Out << 'V';
935 break;
936 case TTK_Enum:
937 Out << 'W';
938 mangleNumber(getASTContext().getTypeSizeInChars(
939 cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity());
940 break;
941 }
942 mangleName(T->getDecl());
943}
944
Charles Davis2a4773072010-06-30 08:09:57 +0000945// <type> ::= <array-type>
946// <array-type> ::= P <cvr-qualifiers> [Y <dimension-count> <dimension>+]
947// <element-type> # as global
948// ::= Q <cvr-qualifiers> [Y <dimension-count> <dimension>+]
949// <element-type> # as param
950// It's supposed to be the other way around, but for some strange reason, it
951// isn't. Today this behavior is retained for the sole purpose of backwards
952// compatibility.
953void MicrosoftCXXNameMangler::mangleType(const ArrayType *T, bool IsGlobal) {
954 // This isn't a recursive mangling, so now we have to do it all in this
955 // one call.
956 if (IsGlobal)
957 Out << 'P';
958 else
959 Out << 'Q';
960 mangleExtraDimensions(T->getElementType());
961}
962void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T) {
963 mangleType(static_cast<const ArrayType *>(T), false);
964}
965void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T) {
966 mangleType(static_cast<const ArrayType *>(T), false);
967}
968void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T) {
969 mangleType(static_cast<const ArrayType *>(T), false);
970}
971void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T) {
972 mangleType(static_cast<const ArrayType *>(T), false);
973}
974void MicrosoftCXXNameMangler::mangleExtraDimensions(QualType ElementTy) {
975 llvm::SmallVector<llvm::APInt, 3> Dimensions;
976 for (;;) {
977 if (ElementTy->isConstantArrayType()) {
978 const ConstantArrayType *CAT =
979 static_cast<const ConstantArrayType *>(ElementTy.getTypePtr());
980 Dimensions.push_back(CAT->getSize()-1);
981 ElementTy = CAT->getElementType();
982 } else if (ElementTy->isVariableArrayType()) {
983 assert(false && "Don't know how to mangle VLAs!");
984 } else if (ElementTy->isDependentSizedArrayType()) {
985 // The dependent expression has to be folded into a constant (TODO).
986 assert(false && "Don't know how to mangle dependent-sized arrays!");
987 } else if (ElementTy->isIncompleteArrayType()) continue;
988 else break;
989 }
990 mangleQualifiers(ElementTy.getQualifiers(), false);
991 // If there are any additional dimensions, mangle them now.
992 if (Dimensions.size() > 0) {
993 Out << 'Y';
994 // <dimension-count> ::= <number> # number of extra dimensions minus 1
995 mangleNumber(Dimensions.size()-1);
996 for (unsigned Dim = 0; Dim < Dimensions.size(); ++Dim) {
997 mangleNumber(Dimensions[Dim].getLimitedValue());
998 }
999 }
1000 mangleType(ElementTy.getLocalUnqualifiedType());
1001}
1002
1003void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T) {
1004 assert(false && "Don't know how to mangle MemberPointerTypes yet!");
1005}
1006
1007void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T) {
1008 assert(false && "Don't know how to mangle TemplateTypeParmTypes yet!");
1009}
1010
Charles Davisf4db33c2010-06-26 03:50:05 +00001011// <type> ::= <pointer-type>
1012// <pointer-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
1013void MicrosoftCXXNameMangler::mangleType(const PointerType *T) {
1014 QualType PointeeTy = T->getPointeeType();
Charles Davis2a4773072010-06-30 08:09:57 +00001015 if (PointeeTy->isArrayType()) {
1016 // Pointers to arrays are mangled like arrays.
1017 mangleExtraDimensions(T->getPointeeType());
Charles Davis0029a2a2010-07-03 05:53:41 +00001018 } else if (PointeeTy->isFunctionType()) {
1019 // Function pointers are special.
1020 Out << '6';
1021 mangleType(static_cast<const FunctionType *>(PointeeTy.getTypePtr()),
1022 NULL, false, false);
Charles Davis2a4773072010-06-30 08:09:57 +00001023 } else {
1024 if (!PointeeTy.hasQualifiers())
1025 // Lack of qualifiers is mangled as 'A'.
1026 Out << 'A';
1027 mangleType(PointeeTy);
1028 }
1029}
1030void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
1031 assert(false && "Don't know how to mangle ObjCObjectPointerTypes yet!");
Charles Davisf4db33c2010-06-26 03:50:05 +00001032}
1033
1034// <type> ::= <reference-type>
1035// <reference-type> ::= A <cvr-qualifiers> <type>
1036void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T) {
1037 Out << 'A';
1038 QualType PointeeTy = T->getPointeeType();
Charles Davis2a4773072010-06-30 08:09:57 +00001039 if (!PointeeTy.hasQualifiers())
Charles Davisf4db33c2010-06-26 03:50:05 +00001040 // Lack of qualifiers is mangled as 'A'.
1041 Out << 'A';
1042 mangleType(PointeeTy);
1043}
1044
Charles Davis2a4773072010-06-30 08:09:57 +00001045void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T) {
1046 assert(false && "Don't know how to mangle RValueReferenceTypes yet!");
1047}
1048
1049void MicrosoftCXXNameMangler::mangleType(const ComplexType *T) {
1050 assert(false && "Don't know how to mangle ComplexTypes yet!");
1051}
1052
1053void MicrosoftCXXNameMangler::mangleType(const VectorType *T) {
1054 assert(false && "Don't know how to mangle VectorTypes yet!");
1055}
1056void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T) {
1057 assert(false && "Don't know how to mangle ExtVectorTypes yet!");
1058}
1059void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
1060 assert(false && "Don't know how to mangle DependentSizedExtVectorTypes yet!");
1061}
1062
1063void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T) {
1064 assert(false && "Don't know how to mangle ObjCInterfaceTypes yet!");
1065}
1066
1067void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T) {
1068 assert(false && "Don't know how to mangle ObjCObjectTypes yet!");
1069}
1070
1071void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T) {
1072 assert(false && "Don't know how to mangle BlockPointerTypes yet!");
1073}
1074
1075void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *T) {
1076 assert(false && "Don't know how to mangle InjectedClassNameTypes yet!");
1077}
1078
1079void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T) {
1080 assert(false && "Don't know how to mangle TemplateSpecializationTypes yet!");
1081}
1082
1083void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T) {
1084 assert(false && "Don't know how to mangle DependentNameTypes yet!");
1085}
1086
1087void MicrosoftCXXNameMangler::mangleType(
1088 const DependentTemplateSpecializationType *T) {
1089 assert(false &&
1090 "Don't know how to mangle DependentTemplateSpecializationTypes yet!");
1091}
1092
1093void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T) {
1094 assert(false && "Don't know how to mangle TypeOfTypes yet!");
1095}
1096
1097void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T) {
1098 assert(false && "Don't know how to mangle TypeOfExprTypes yet!");
1099}
1100
1101void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T) {
1102 assert(false && "Don't know how to mangle DecltypeTypes yet!");
1103}
1104
Charles Davis74ce8592010-06-09 23:25:41 +00001105void MicrosoftMangleContext::mangleName(const NamedDecl *D,
1106 llvm::SmallVectorImpl<char> &Name) {
Charles Davis9af2d4a2010-06-11 03:07:32 +00001107 assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
1108 "Invalid mangleName() call, argument is not a variable or function!");
1109 assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
1110 "Invalid mangleName() call on 'structor decl!");
1111
1112 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
1113 getASTContext().getSourceManager(),
1114 "Mangling declaration");
1115
1116 MicrosoftCXXNameMangler Mangler(*this, Name);
1117 return Mangler.mangle(D);
Charles Davis74ce8592010-06-09 23:25:41 +00001118}
1119void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD,
1120 const ThunkInfo &Thunk,
1121 llvm::SmallVectorImpl<char> &) {
1122 assert(false && "Can't yet mangle thunks!");
1123}
1124void MicrosoftMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
1125 CXXDtorType Type,
1126 const ThisAdjustment &,
1127 llvm::SmallVectorImpl<char> &) {
1128 assert(false && "Can't yet mangle destructor thunks!");
1129}
1130void MicrosoftMangleContext::mangleGuardVariable(const VarDecl *D,
1131 llvm::SmallVectorImpl<char> &) {
1132 assert(false && "Can't yet mangle guard variables!");
1133}
1134void MicrosoftMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
1135 llvm::SmallVectorImpl<char> &) {
1136 assert(false && "Can't yet mangle virtual tables!");
1137}
1138void MicrosoftMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
1139 llvm::SmallVectorImpl<char> &) {
1140 llvm_unreachable("The MS C++ ABI does not have virtual table tables!");
1141}
1142void MicrosoftMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
1143 int64_t Offset,
1144 const CXXRecordDecl *Type,
1145 llvm::SmallVectorImpl<char> &) {
1146 llvm_unreachable("The MS C++ ABI does not have constructor vtables!");
1147}
1148void MicrosoftMangleContext::mangleCXXRTTI(QualType T,
1149 llvm::SmallVectorImpl<char> &) {
1150 assert(false && "Can't yet mangle RTTI!");
1151}
1152void MicrosoftMangleContext::mangleCXXRTTIName(QualType T,
1153 llvm::SmallVectorImpl<char> &) {
1154 assert(false && "Can't yet mangle RTTI names!");
1155}
1156void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
1157 CXXCtorType Type,
1158 llvm::SmallVectorImpl<char> &) {
1159 assert(false && "Can't yet mangle constructors!");
1160}
1161void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
1162 CXXDtorType Type,
1163 llvm::SmallVectorImpl<char> &) {
1164 assert(false && "Can't yet mangle destructors!");
1165}
1166
Charles Davis95a546e2010-06-11 01:06:47 +00001167CXXABI *clang::CodeGen::CreateMicrosoftCXXABI(CodeGenModule &CGM) {
Charles Davis74ce8592010-06-09 23:25:41 +00001168 return new MicrosoftCXXABI(CGM);
1169}
1170