blob: 878f13d516d93c3b489382e184e8aef0d8f57a07 [file] [log] [blame]
Douglas Gregor6ec36682009-02-18 23:53:56 +00001//===--- Mangle.cpp - Mangle C++ Names --------------------------*- C++ -*-===//
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Implements C++ name mangling according to the Itanium C++ ABI,
11// which is used in GCC 3.2 and newer (and many compilers that are
12// ABI-compatible with GCC):
13//
14// http://www.codesourcery.com/public/cxx-abi/abi.html
15//
16//===----------------------------------------------------------------------===//
17#include "Mangle.h"
18#include "clang/AST/ASTContext.h"
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclCXX.h"
Anders Carlssona40c5e42009-03-07 22:03:21 +000021#include "clang/AST/DeclObjC.h"
Anders Carlsson7a0ba872009-05-15 16:09:15 +000022#include "clang/AST/DeclTemplate.h"
Douglas Gregor6ec36682009-02-18 23:53:56 +000023#include "clang/Basic/SourceManager.h"
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000024#include "llvm/Support/Compiler.h"
25#include "llvm/Support/raw_ostream.h"
John McCallefe6aee2009-09-05 07:56:18 +000026#include "llvm/Support/ErrorHandling.h"
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000027using namespace clang;
28
29namespace {
30 class VISIBILITY_HIDDEN CXXNameMangler {
31 ASTContext &Context;
32 llvm::raw_ostream &Out;
33
Anders Carlsson27ae5362009-04-17 01:58:57 +000034 const CXXMethodDecl *Structor;
35 unsigned StructorType;
Anders Carlsson3ac86b52009-04-15 05:36:58 +000036 CXXCtorType CtorType;
Mike Stump1eb44332009-09-09 15:08:12 +000037
Anders Carlsson76967372009-09-17 00:43:46 +000038 llvm::DenseMap<uintptr_t, unsigned> Substitutions;
39
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000040 public:
41 CXXNameMangler(ASTContext &C, llvm::raw_ostream &os)
Anders Carlsson27ae5362009-04-17 01:58:57 +000042 : Context(C), Out(os), Structor(0), StructorType(0) { }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000043
44 bool mangle(const NamedDecl *D);
Mike Stump77ca8f62009-09-05 07:20:32 +000045 void mangleCalloffset(int64_t nv, int64_t v);
Mike Stumpdec025b2009-09-07 04:27:52 +000046 void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v);
47 void mangleCovariantThunk(const FunctionDecl *FD,
Mike Stump77ca8f62009-09-05 07:20:32 +000048 int64_t nv_t, int64_t v_t,
Mike Stump9124bcc2009-09-02 00:56:18 +000049 int64_t nv_r, int64_t v_r);
Anders Carlsson41aa8c12009-04-13 18:02:10 +000050 void mangleGuardVariable(const VarDecl *D);
Mike Stump1eb44332009-09-09 15:08:12 +000051
Mike Stumpf1216772009-07-31 18:25:34 +000052 void mangleCXXVtable(QualType Type);
Mike Stump738f8c22009-07-31 23:15:31 +000053 void mangleCXXRtti(QualType Type);
Anders Carlsson3ac86b52009-04-15 05:36:58 +000054 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type);
Anders Carlsson27ae5362009-04-17 01:58:57 +000055 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type);
Anders Carlsson3ac86b52009-04-15 05:36:58 +000056
Anders Carlsson43f17402009-04-02 15:51:53 +000057 private:
Anders Carlsson6862fc72009-09-17 04:16:28 +000058 bool mangleSubstitution(const NamedDecl *ND);
Anders Carlsson76967372009-09-17 00:43:46 +000059 bool mangleSubstitution(QualType T);
Anders Carlssond3a932a2009-09-17 03:53:28 +000060 bool mangleSubstitution(uintptr_t Ptr);
61
62 void addSubstitution(const NamedDecl *ND) {
63 addSubstitution(reinterpret_cast<uintptr_t>(ND));
64 }
Anders Carlsson76967372009-09-17 00:43:46 +000065 void addSubstitution(QualType T);
Anders Carlssond3a932a2009-09-17 03:53:28 +000066 void addSubstitution(uintptr_t Ptr);
Anders Carlsson76967372009-09-17 00:43:46 +000067
Anders Carlsson43f17402009-04-02 15:51:53 +000068 bool mangleFunctionDecl(const FunctionDecl *FD);
Mike Stump1eb44332009-09-09 15:08:12 +000069
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000070 void mangleFunctionEncoding(const FunctionDecl *FD);
71 void mangleName(const NamedDecl *ND);
Anders Carlsson7624f212009-09-18 02:42:01 +000072 void mangleName(const TemplateDecl *TD,
73 const TemplateArgument *TemplateArgs,
74 unsigned NumTemplateArgs);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000075 void mangleUnqualifiedName(const NamedDecl *ND);
Anders Carlsson201ce742009-09-17 03:17:01 +000076 void mangleUnscopedName(const NamedDecl *ND);
Anders Carlsson7624f212009-09-18 02:42:01 +000077 void mangleUnscopedTemplateName(const NamedDecl *ND);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000078 void mangleSourceName(const IdentifierInfo *II);
Anders Carlsson1b42c792009-04-02 16:24:45 +000079 void mangleLocalName(const NamedDecl *ND);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000080 void mangleNestedName(const NamedDecl *ND);
Anders Carlsson7624f212009-09-18 02:42:01 +000081 void mangleNestedName(const TemplateDecl *TD,
82 const TemplateArgument *TemplateArgs,
83 unsigned NumTemplateArgs);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000084 void manglePrefix(const DeclContext *DC);
Anders Carlssonaa73ab12009-09-18 18:47:07 +000085 void mangleTemplatePrefix(const NamedDecl *ND);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +000086 void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
87 void mangleCVQualifiers(unsigned Quals);
88 void mangleType(QualType T);
John McCallefe6aee2009-09-05 07:56:18 +000089
90 // Declare manglers for every type class.
91#define ABSTRACT_TYPE(CLASS, PARENT)
92#define NON_CANONICAL_TYPE(CLASS, PARENT)
93#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
94#include "clang/AST/TypeNodes.def"
95
96 void mangleType(const TagType*);
97 void mangleBareFunctionType(const FunctionType *T,
98 bool MangleReturnType);
Anders Carlssond553f8c2009-09-21 01:21:10 +000099 void mangleExpression(const Expr *E);
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000100 void mangleCXXCtorType(CXXCtorType T);
Anders Carlsson27ae5362009-04-17 01:58:57 +0000101 void mangleCXXDtorType(CXXDtorType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000102
Anders Carlsson7624f212009-09-18 02:42:01 +0000103 void mangleTemplateArgs(const TemplateArgument *TemplateArgs,
104 unsigned NumTemplateArgs);
Anders Carlsson068f3472009-09-17 05:31:47 +0000105 void mangleTemplateArgumentList(const TemplateArgumentList &L);
106 void mangleTemplateArgument(const TemplateArgument &A);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000107 };
108}
109
Anders Carlsson43f17402009-04-02 15:51:53 +0000110static bool isInCLinkageSpecification(const Decl *D) {
Mike Stump1eb44332009-09-09 15:08:12 +0000111 for (const DeclContext *DC = D->getDeclContext();
Anders Carlsson43f17402009-04-02 15:51:53 +0000112 !DC->isTranslationUnit(); DC = DC->getParent()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000113 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
Anders Carlsson43f17402009-04-02 15:51:53 +0000114 return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
115 }
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Anders Carlsson43f17402009-04-02 15:51:53 +0000117 return false;
118}
119
120bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) {
Mike Stump141c5af2009-09-02 00:25:38 +0000121 // Clang's "overloadable" attribute extension to C/C++ implies name mangling
122 // (always).
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000123 if (!FD->hasAttr<OverloadableAttr>()) {
Chris Lattner783601d2009-06-13 23:34:16 +0000124 // C functions are not mangled, and "main" is never mangled.
Douglas Gregor48a83b52009-09-12 00:17:51 +0000125 if (!Context.getLangOptions().CPlusPlus || FD->isMain())
Chris Lattner783601d2009-06-13 23:34:16 +0000126 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000127
128 // No mangling in an "implicit extern C" header.
Chris Lattner783601d2009-06-13 23:34:16 +0000129 if (FD->getLocation().isValid() &&
130 Context.getSourceManager().isInExternCSystemHeader(FD->getLocation()))
131 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000132
Chris Lattner783601d2009-06-13 23:34:16 +0000133 // No name mangling in a C linkage specification.
Anders Carlssonadd28822009-09-22 20:33:31 +0000134 if (!isa<CXXMethodDecl>(FD) && isInCLinkageSpecification(FD))
Chris Lattner783601d2009-06-13 23:34:16 +0000135 return false;
136 }
Anders Carlsson43f17402009-04-02 15:51:53 +0000137
138 // If we get here, mangle the decl name!
139 Out << "_Z";
140 mangleFunctionEncoding(FD);
141 return true;
142}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000143
144bool CXXNameMangler::mangle(const NamedDecl *D) {
Mike Stump141c5af2009-09-02 00:25:38 +0000145 // Any decl can be declared with __asm("foo") on it, and this takes precedence
146 // over all other naming in the .o file.
Argyrios Kyrtzidis40b598e2009-06-30 02:34:44 +0000147 if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
Chris Lattnerca3f25c2009-03-21 08:24:40 +0000148 // If we have an asm name, then we use it as the mangling.
149 Out << '\01'; // LLVM IR Marker for __asm("foo")
150 Out << ALA->getLabel();
151 return true;
152 }
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000154 // <mangled-name> ::= _Z <encoding>
155 // ::= <data name>
156 // ::= <special-name>
157
158 // FIXME: Actually use a visitor to decode these?
Anders Carlsson43f17402009-04-02 15:51:53 +0000159 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
160 return mangleFunctionDecl(FD);
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Anders Carlsson329749c2009-04-02 16:05:20 +0000162 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
163 if (!Context.getLangOptions().CPlusPlus ||
Anders Carlsson9ccb0652009-04-11 01:19:45 +0000164 isInCLinkageSpecification(D) ||
165 D->getDeclContext()->isTranslationUnit())
Anders Carlsson329749c2009-04-02 16:05:20 +0000166 return false;
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Anders Carlsson329749c2009-04-02 16:05:20 +0000168 Out << "_Z";
169 mangleName(VD);
170 return true;
171 }
Mike Stump1eb44332009-09-09 15:08:12 +0000172
Anders Carlsson43f17402009-04-02 15:51:53 +0000173 return false;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000174}
175
Mike Stump1eb44332009-09-09 15:08:12 +0000176void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D,
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000177 CXXCtorType Type) {
Anders Carlsson27ae5362009-04-17 01:58:57 +0000178 assert(!Structor && "Structor already set!");
179 Structor = D;
180 StructorType = Type;
Mike Stump1eb44332009-09-09 15:08:12 +0000181
Anders Carlsson27ae5362009-04-17 01:58:57 +0000182 mangle(D);
183}
184
Mike Stump1eb44332009-09-09 15:08:12 +0000185void CXXNameMangler::mangleCXXDtor(const CXXDestructorDecl *D,
Anders Carlsson27ae5362009-04-17 01:58:57 +0000186 CXXDtorType Type) {
187 assert(!Structor && "Structor already set!");
188 Structor = D;
189 StructorType = Type;
Mike Stump1eb44332009-09-09 15:08:12 +0000190
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000191 mangle(D);
192}
193
Mike Stumpf1216772009-07-31 18:25:34 +0000194void CXXNameMangler::mangleCXXVtable(QualType T) {
195 // <special-name> ::= TV <type> # virtual table
196 Out << "_ZTV";
197 mangleType(T);
198}
199
Mike Stump738f8c22009-07-31 23:15:31 +0000200void CXXNameMangler::mangleCXXRtti(QualType T) {
201 // <special-name> ::= TI <type> # typeinfo structure
202 Out << "_ZTI";
203 mangleType(T);
204}
205
Mike Stump1eb44332009-09-09 15:08:12 +0000206void CXXNameMangler::mangleGuardVariable(const VarDecl *D) {
207 // <special-name> ::= GV <object name> # Guard variable for one-time
Mike Stumpf1216772009-07-31 18:25:34 +0000208 // # initialization
Anders Carlsson41aa8c12009-04-13 18:02:10 +0000209
210 Out << "_ZGV";
211 mangleName(D);
212}
213
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000214void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
215 // <encoding> ::= <function name> <bare-function-type>
216 mangleName(FD);
Mike Stump1eb44332009-09-09 15:08:12 +0000217
Mike Stump141c5af2009-09-02 00:25:38 +0000218 // Whether the mangling of a function type includes the return type depends on
219 // the context and the nature of the function. The rules for deciding whether
220 // the return type is included are:
Mike Stump1eb44332009-09-09 15:08:12 +0000221 //
Douglas Gregor1fd2dd12009-06-29 22:39:32 +0000222 // 1. Template functions (names or types) have return types encoded, with
223 // the exceptions listed below.
Mike Stump1eb44332009-09-09 15:08:12 +0000224 // 2. Function types not appearing as part of a function name mangling,
Douglas Gregor1fd2dd12009-06-29 22:39:32 +0000225 // e.g. parameters, pointer types, etc., have return type encoded, with the
226 // exceptions listed below.
227 // 3. Non-template function names do not have return types encoded.
228 //
Mike Stump141c5af2009-09-02 00:25:38 +0000229 // The exceptions mentioned in (1) and (2) above, for which the return type is
230 // never included, are
Douglas Gregor1fd2dd12009-06-29 22:39:32 +0000231 // 1. Constructors.
232 // 2. Destructors.
233 // 3. Conversion operator functions, e.g. operator int.
234 bool MangleReturnType = false;
Anders Carlsson9234b7f2009-09-17 03:46:43 +0000235 if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) {
236 if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
237 isa<CXXConversionDecl>(FD)))
238 MangleReturnType = true;
239
240 // Mangle the type of the primary template.
241 FD = PrimaryTemplate->getTemplatedDecl();
242 }
243
John McCall183700f2009-09-21 23:43:11 +0000244 mangleBareFunctionType(FD->getType()->getAs<FunctionType>(), MangleReturnType);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000245}
246
247static bool isStdNamespace(const DeclContext *DC) {
248 if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit())
249 return false;
250
251 const NamespaceDecl *NS = cast<NamespaceDecl>(DC);
Douglas Gregor6ec36682009-02-18 23:53:56 +0000252 return NS->getOriginalNamespace()->getIdentifier()->isStr("std");
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000253}
254
Anders Carlsson2744a062009-09-18 19:00:18 +0000255static const NamedDecl *isTemplate(const NamedDecl *ND,
256 const TemplateArgumentList *&TemplateArgs) {
257 // Check if we have a function template.
258 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){
259 if (FD->getPrimaryTemplate()) {
260 TemplateArgs = FD->getTemplateSpecializationArgs();
261 return FD;
262 }
263 }
264
Anders Carlssoneafc6dc2009-09-18 19:44:50 +0000265 // Check if we have a class template.
266 if (const ClassTemplateSpecializationDecl *Spec =
267 dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
268 TemplateArgs = &Spec->getTemplateArgs();
269 return Spec;
270 }
271
Anders Carlsson2744a062009-09-18 19:00:18 +0000272 return 0;
273}
274
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000275void CXXNameMangler::mangleName(const NamedDecl *ND) {
276 // <name> ::= <nested-name>
277 // ::= <unscoped-name>
278 // ::= <unscoped-template-name> <template-args>
Anders Carlsson201ce742009-09-17 03:17:01 +0000279 // ::= <local-name>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000280 //
Anders Carlssond58d6f72009-09-17 16:12:20 +0000281 const DeclContext *DC = ND->getDeclContext();
Anders Carlsson5cc58c62009-09-22 17:23:30 +0000282 while (isa<LinkageSpecDecl>(DC))
Anders Carlssond58d6f72009-09-17 16:12:20 +0000283 DC = DC->getParent();
Anders Carlssond58d6f72009-09-17 16:12:20 +0000284
285 if (DC->isTranslationUnit() || isStdNamespace(DC)) {
Anders Carlsson2744a062009-09-18 19:00:18 +0000286 // Check if we have a template.
287 const TemplateArgumentList *TemplateArgs = 0;
288 if (const NamedDecl *TD = isTemplate(ND, TemplateArgs)) {
289 mangleUnscopedTemplateName(TD);
290 mangleTemplateArgumentList(*TemplateArgs);
291 return;
Anders Carlsson7482e242009-09-18 04:29:09 +0000292 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000293
Anders Carlsson7482e242009-09-18 04:29:09 +0000294 mangleUnscopedName(ND);
295 return;
296 }
297
298 if (isa<FunctionDecl>(DC)) {
299 mangleLocalName(ND);
300 return;
301 }
302
303 mangleNestedName(ND);
304}
Anders Carlsson7624f212009-09-18 02:42:01 +0000305void CXXNameMangler::mangleName(const TemplateDecl *TD,
306 const TemplateArgument *TemplateArgs,
307 unsigned NumTemplateArgs) {
308 const DeclContext *DC = TD->getDeclContext();
309 while (isa<LinkageSpecDecl>(DC)) {
310 assert(cast<LinkageSpecDecl>(DC)->getLanguage() ==
311 LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!");
312 DC = DC->getParent();
313 }
314
315 if (DC->isTranslationUnit() || isStdNamespace(DC)) {
316 mangleUnscopedTemplateName(cast<NamedDecl>(TD->getTemplatedDecl()));
317 mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
318 } else {
319 mangleNestedName(TD, TemplateArgs, NumTemplateArgs);
320 }
321}
322
Anders Carlsson201ce742009-09-17 03:17:01 +0000323void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) {
324 // <unscoped-name> ::= <unqualified-name>
325 // ::= St <unqualified-name> # ::std::
326 if (isStdNamespace(ND->getDeclContext()))
327 Out << "St";
328
329 mangleUnqualifiedName(ND);
330}
331
Anders Carlsson7624f212009-09-18 02:42:01 +0000332void CXXNameMangler::mangleUnscopedTemplateName(const NamedDecl *ND) {
Anders Carlsson201ce742009-09-17 03:17:01 +0000333 // <unscoped-template-name> ::= <unscoped-name>
334 // ::= <substitution>
Anders Carlsson7624f212009-09-18 02:42:01 +0000335 if (mangleSubstitution(ND))
Anders Carlsson03c9d532009-09-17 04:02:31 +0000336 return;
337
Anders Carlsson7624f212009-09-18 02:42:01 +0000338 mangleUnscopedName(ND);
339 addSubstitution(ND);
Anders Carlsson201ce742009-09-17 03:17:01 +0000340}
341
Mike Stump77ca8f62009-09-05 07:20:32 +0000342void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) {
Mike Stump141c5af2009-09-02 00:25:38 +0000343 // <call-offset> ::= h <nv-offset> _
344 // ::= v <v-offset> _
345 // <nv-offset> ::= <offset number> # non-virtual base override
346 // <v-offset> ::= <offset nubmer> _ <virtual offset number>
347 // # virtual base override, with vcall offset
Mike Stump77ca8f62009-09-05 07:20:32 +0000348 if (v == 0) {
Mike Stump9124bcc2009-09-02 00:56:18 +0000349 Out << "h";
Mike Stump141c5af2009-09-02 00:25:38 +0000350 if (nv < 0) {
351 Out << "n";
352 nv = -nv;
353 }
354 Out << nv;
355 } else {
Mike Stump9124bcc2009-09-02 00:56:18 +0000356 Out << "v";
Mike Stump141c5af2009-09-02 00:25:38 +0000357 if (nv < 0) {
358 Out << "n";
359 nv = -nv;
360 }
361 Out << nv;
362 Out << "_";
363 if (v < 0) {
364 Out << "n";
365 v = -v;
366 }
367 Out << v;
368 }
369 Out << "_";
Mike Stump9124bcc2009-09-02 00:56:18 +0000370}
371
Mike Stumpdec025b2009-09-07 04:27:52 +0000372void CXXNameMangler::mangleThunk(const FunctionDecl *FD, int64_t nv,
373 int64_t v) {
Mike Stump9124bcc2009-09-02 00:56:18 +0000374 // <special-name> ::= T <call-offset> <base encoding>
375 // # base is the nominal target function of thunk
Mike Stumpdec025b2009-09-07 04:27:52 +0000376 Out << "_ZT";
Mike Stump77ca8f62009-09-05 07:20:32 +0000377 mangleCalloffset(nv, v);
Mike Stumpdec025b2009-09-07 04:27:52 +0000378 mangleFunctionEncoding(FD);
Mike Stump9124bcc2009-09-02 00:56:18 +0000379}
380
Mike Stumpdec025b2009-09-07 04:27:52 +0000381 void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD,
Mike Stump77ca8f62009-09-05 07:20:32 +0000382 int64_t nv_t, int64_t v_t,
Mike Stump9124bcc2009-09-02 00:56:18 +0000383 int64_t nv_r, int64_t v_r) {
384 // <special-name> ::= Tc <call-offset> <call-offset> <base encoding>
385 // # base is the nominal target function of thunk
386 // # first call-offset is 'this' adjustment
387 // # second call-offset is result adjustment
Mike Stumpdec025b2009-09-07 04:27:52 +0000388 Out << "_ZTc";
Mike Stump77ca8f62009-09-05 07:20:32 +0000389 mangleCalloffset(nv_t, v_t);
390 mangleCalloffset(nv_r, v_r);
Mike Stumpdec025b2009-09-07 04:27:52 +0000391 mangleFunctionEncoding(FD);
Mike Stump141c5af2009-09-02 00:25:38 +0000392}
393
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000394void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
395 // <unqualified-name> ::= <operator-name>
Mike Stump1eb44332009-09-09 15:08:12 +0000396 // ::= <ctor-dtor-name>
397 // ::= <source-name>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000398 DeclarationName Name = ND->getDeclName();
399 switch (Name.getNameKind()) {
400 case DeclarationName::Identifier:
401 mangleSourceName(Name.getAsIdentifierInfo());
402 break;
403
404 case DeclarationName::ObjCZeroArgSelector:
405 case DeclarationName::ObjCOneArgSelector:
406 case DeclarationName::ObjCMultiArgSelector:
407 assert(false && "Can't mangle Objective-C selector names here!");
408 break;
409
410 case DeclarationName::CXXConstructorName:
Anders Carlsson27ae5362009-04-17 01:58:57 +0000411 if (ND == Structor)
Mike Stump141c5af2009-09-02 00:25:38 +0000412 // If the named decl is the C++ constructor we're mangling, use the type
413 // we were given.
Anders Carlsson27ae5362009-04-17 01:58:57 +0000414 mangleCXXCtorType(static_cast<CXXCtorType>(StructorType));
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000415 else
416 // Otherwise, use the complete constructor name. This is relevant if a
417 // class with a constructor is declared within a constructor.
418 mangleCXXCtorType(Ctor_Complete);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000419 break;
420
421 case DeclarationName::CXXDestructorName:
Anders Carlsson27ae5362009-04-17 01:58:57 +0000422 if (ND == Structor)
Mike Stump141c5af2009-09-02 00:25:38 +0000423 // If the named decl is the C++ destructor we're mangling, use the type we
424 // were given.
Anders Carlsson27ae5362009-04-17 01:58:57 +0000425 mangleCXXDtorType(static_cast<CXXDtorType>(StructorType));
426 else
427 // Otherwise, use the complete destructor name. This is relevant if a
428 // class with a destructor is declared within a destructor.
429 mangleCXXDtorType(Dtor_Complete);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000430 break;
431
432 case DeclarationName::CXXConversionFunctionName:
Mike Stump1eb44332009-09-09 15:08:12 +0000433 // <operator-name> ::= cv <type> # (cast)
Douglas Gregor219cc612009-02-13 01:28:03 +0000434 Out << "cv";
435 mangleType(Context.getCanonicalType(Name.getCXXNameType()));
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000436 break;
437
438 case DeclarationName::CXXOperatorName:
439 mangleOperatorName(Name.getCXXOverloadedOperator(),
440 cast<FunctionDecl>(ND)->getNumParams());
441 break;
442
443 case DeclarationName::CXXUsingDirective:
444 assert(false && "Can't mangle a using directive name!");
Douglas Gregor219cc612009-02-13 01:28:03 +0000445 break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000446 }
447}
448
449void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
450 // <source-name> ::= <positive length number> <identifier>
451 // <number> ::= [n] <non-negative decimal integer>
452 // <identifier> ::= <unqualified source code identifier>
453 Out << II->getLength() << II->getName();
454}
455
456void CXXNameMangler::mangleNestedName(const NamedDecl *ND) {
457 // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
458 // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
Anders Carlsson7482e242009-09-18 04:29:09 +0000459 // FIXME: no class template support
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000460 Out << 'N';
461 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND))
462 mangleCVQualifiers(Method->getTypeQualifiers());
Anders Carlsson7482e242009-09-18 04:29:09 +0000463
Anders Carlsson2744a062009-09-18 19:00:18 +0000464 // Check if we have a template.
465 const TemplateArgumentList *TemplateArgs = 0;
466 if (const NamedDecl *TD = isTemplate(ND, TemplateArgs)) {
467 mangleTemplatePrefix(TD);
468 mangleTemplateArgumentList(*TemplateArgs);
Anders Carlsson7482e242009-09-18 04:29:09 +0000469 } else {
470 manglePrefix(ND->getDeclContext());
471 mangleUnqualifiedName(ND);
472 }
473
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000474 Out << 'E';
475}
Anders Carlsson7624f212009-09-18 02:42:01 +0000476void CXXNameMangler::mangleNestedName(const TemplateDecl *TD,
477 const TemplateArgument *TemplateArgs,
478 unsigned NumTemplateArgs) {
479 Out << 'N';
480 manglePrefix(TD->getDeclContext());
481 mangleUnqualifiedName(TD->getTemplatedDecl());
482
483 mangleTemplateArgs(TemplateArgs, NumTemplateArgs);
484 Out << 'E';
485}
486
Anders Carlsson1b42c792009-04-02 16:24:45 +0000487void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
488 // <local-name> := Z <function encoding> E <entity name> [<discriminator>]
489 // := Z <function encoding> E s [<discriminator>]
Mike Stump1eb44332009-09-09 15:08:12 +0000490 // <discriminator> := _ <non-negative number>
Anders Carlsson1b42c792009-04-02 16:24:45 +0000491 Out << 'Z';
492 mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext()));
493 Out << 'E';
494 mangleSourceName(ND->getIdentifier());
495}
496
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000497void CXXNameMangler::manglePrefix(const DeclContext *DC) {
498 // <prefix> ::= <prefix> <unqualified-name>
499 // ::= <template-prefix> <template-args>
500 // ::= <template-param>
501 // ::= # empty
502 // ::= <substitution>
503 // FIXME: We only handle mangling of namespaces and classes at the moment.
Anders Carlsson6862fc72009-09-17 04:16:28 +0000504
Anders Carlssonadd28822009-09-22 20:33:31 +0000505 while (isa<LinkageSpecDecl>(DC))
506 DC = DC->getParent();
507
Anders Carlsson9263e912009-09-18 18:39:58 +0000508 if (DC->isTranslationUnit())
509 return;
510
Anders Carlsson6862fc72009-09-17 04:16:28 +0000511 if (mangleSubstitution(cast<NamedDecl>(DC)))
512 return;
Anders Carlsson7482e242009-09-18 04:29:09 +0000513
Anders Carlsson2ee3fca2009-09-18 20:11:09 +0000514 // Check if we have a template.
515 const TemplateArgumentList *TemplateArgs = 0;
516 if (const NamedDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) {
517 mangleTemplatePrefix(TD);
518 mangleTemplateArgumentList(*TemplateArgs);
519 } else {
520 manglePrefix(DC->getParent());
521 mangleUnqualifiedName(cast<NamedDecl>(DC));
522 }
Anders Carlsson6862fc72009-09-17 04:16:28 +0000523
524 addSubstitution(cast<NamedDecl>(DC));
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000525}
526
Anders Carlssonaa73ab12009-09-18 18:47:07 +0000527void CXXNameMangler::mangleTemplatePrefix(const NamedDecl *ND) {
Anders Carlsson7482e242009-09-18 04:29:09 +0000528 // <template-prefix> ::= <prefix> <template unqualified-name>
529 // ::= <template-param>
530 // ::= <substitution>
531
Anders Carlssonaa73ab12009-09-18 18:47:07 +0000532 // FIXME: <substitution> and <template-param>
533
534 manglePrefix(ND->getDeclContext());
535 mangleUnqualifiedName(ND);
Anders Carlsson7482e242009-09-18 04:29:09 +0000536 // FIXME: Implement!
537}
538
Mike Stump1eb44332009-09-09 15:08:12 +0000539void
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000540CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) {
541 switch (OO) {
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000542 // <operator-name> ::= nw # new
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000543 case OO_New: Out << "nw"; break;
544 // ::= na # new[]
545 case OO_Array_New: Out << "na"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000546 // ::= dl # delete
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000547 case OO_Delete: Out << "dl"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000548 // ::= da # delete[]
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000549 case OO_Array_Delete: Out << "da"; break;
550 // ::= ps # + (unary)
551 // ::= pl # +
552 case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000553 // ::= ng # - (unary)
554 // ::= mi # -
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000555 case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000556 // ::= ad # & (unary)
557 // ::= an # &
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000558 case OO_Amp: Out << (Arity == 1? "ad" : "an"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000559 // ::= de # * (unary)
560 // ::= ml # *
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000561 case OO_Star: Out << (Arity == 1? "de" : "ml"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000562 // ::= co # ~
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000563 case OO_Tilde: Out << "co"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000564 // ::= dv # /
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000565 case OO_Slash: Out << "dv"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000566 // ::= rm # %
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000567 case OO_Percent: Out << "rm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000568 // ::= or # |
569 case OO_Pipe: Out << "or"; break;
570 // ::= eo # ^
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000571 case OO_Caret: Out << "eo"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000572 // ::= aS # =
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000573 case OO_Equal: Out << "aS"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000574 // ::= pL # +=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000575 case OO_PlusEqual: Out << "pL"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000576 // ::= mI # -=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000577 case OO_MinusEqual: Out << "mI"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000578 // ::= mL # *=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000579 case OO_StarEqual: Out << "mL"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000580 // ::= dV # /=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000581 case OO_SlashEqual: Out << "dV"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000582 // ::= rM # %=
583 case OO_PercentEqual: Out << "rM"; break;
584 // ::= aN # &=
585 case OO_AmpEqual: Out << "aN"; break;
586 // ::= oR # |=
587 case OO_PipeEqual: Out << "oR"; break;
588 // ::= eO # ^=
589 case OO_CaretEqual: Out << "eO"; break;
590 // ::= ls # <<
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000591 case OO_LessLess: Out << "ls"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000592 // ::= rs # >>
593 case OO_GreaterGreater: Out << "rs"; break;
594 // ::= lS # <<=
595 case OO_LessLessEqual: Out << "lS"; break;
596 // ::= rS # >>=
597 case OO_GreaterGreaterEqual: Out << "rS"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000598 // ::= eq # ==
599 case OO_EqualEqual: Out << "eq"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000600 // ::= ne # !=
601 case OO_ExclaimEqual: Out << "ne"; break;
602 // ::= lt # <
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000603 case OO_Less: Out << "lt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000604 // ::= gt # >
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000605 case OO_Greater: Out << "gt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000606 // ::= le # <=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000607 case OO_LessEqual: Out << "le"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000608 // ::= ge # >=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000609 case OO_GreaterEqual: Out << "ge"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000610 // ::= nt # !
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000611 case OO_Exclaim: Out << "nt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000612 // ::= aa # &&
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000613 case OO_AmpAmp: Out << "aa"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000614 // ::= oo # ||
615 case OO_PipePipe: Out << "oo"; break;
616 // ::= pp # ++
617 case OO_PlusPlus: Out << "pp"; break;
618 // ::= mm # --
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000619 case OO_MinusMinus: Out << "mm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000620 // ::= cm # ,
621 case OO_Comma: Out << "cm"; break;
622 // ::= pm # ->*
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000623 case OO_ArrowStar: Out << "pm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000624 // ::= pt # ->
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000625 case OO_Arrow: Out << "pt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000626 // ::= cl # ()
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000627 case OO_Call: Out << "cl"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000628 // ::= ix # []
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000629 case OO_Subscript: Out << "ix"; break;
630 // UNSUPPORTED: ::= qu # ?
631
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000632 case OO_None:
633 case OO_Conditional:
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000634 case NUM_OVERLOADED_OPERATORS:
Mike Stump1eb44332009-09-09 15:08:12 +0000635 assert(false && "Not an overloaded operator");
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000636 break;
637 }
638}
639
640void CXXNameMangler::mangleCVQualifiers(unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +0000641 // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000642 if (Quals & QualType::Restrict)
643 Out << 'r';
644 if (Quals & QualType::Volatile)
645 Out << 'V';
646 if (Quals & QualType::Const)
647 Out << 'K';
648}
649
650void CXXNameMangler::mangleType(QualType T) {
Anders Carlsson4843e582009-03-10 17:07:44 +0000651 // Only operate on the canonical type!
652 T = Context.getCanonicalType(T);
653
Anders Carlsson76967372009-09-17 00:43:46 +0000654 bool IsSubstitutable = !isa<BuiltinType>(T);
655 if (IsSubstitutable && mangleSubstitution(T))
656 return;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000657
Anders Carlsson76967372009-09-17 00:43:46 +0000658 if (unsigned CVRQualifiers = T.getCVRQualifiers()) {
659 // <type> ::= <CV-qualifiers> <type>
660 mangleCVQualifiers(CVRQualifiers);
661
662 mangleType(T.getUnqualifiedType());
663 } else {
664 switch (T->getTypeClass()) {
John McCallefe6aee2009-09-05 07:56:18 +0000665#define ABSTRACT_TYPE(CLASS, PARENT)
666#define NON_CANONICAL_TYPE(CLASS, PARENT) \
Anders Carlsson76967372009-09-17 00:43:46 +0000667 case Type::CLASS: \
668 llvm::llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
669 return;
John McCallefe6aee2009-09-05 07:56:18 +0000670#define TYPE(CLASS, PARENT) \
Anders Carlsson76967372009-09-17 00:43:46 +0000671 case Type::CLASS: \
672 mangleType(static_cast<CLASS##Type*>(T.getTypePtr())); \
673 break;
John McCallefe6aee2009-09-05 07:56:18 +0000674#include "clang/AST/TypeNodes.def"
Anders Carlsson76967372009-09-17 00:43:46 +0000675 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000676 }
Anders Carlsson76967372009-09-17 00:43:46 +0000677
678 // Add the substitution.
679 if (IsSubstitutable)
680 addSubstitution(T);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000681}
682
683void CXXNameMangler::mangleType(const BuiltinType *T) {
John McCallefe6aee2009-09-05 07:56:18 +0000684 // <type> ::= <builtin-type>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000685 // <builtin-type> ::= v # void
686 // ::= w # wchar_t
687 // ::= b # bool
688 // ::= c # char
689 // ::= a # signed char
690 // ::= h # unsigned char
691 // ::= s # short
692 // ::= t # unsigned short
693 // ::= i # int
694 // ::= j # unsigned int
695 // ::= l # long
696 // ::= m # unsigned long
697 // ::= x # long long, __int64
698 // ::= y # unsigned long long, __int64
699 // ::= n # __int128
700 // UNSUPPORTED: ::= o # unsigned __int128
701 // ::= f # float
702 // ::= d # double
703 // ::= e # long double, __float80
704 // UNSUPPORTED: ::= g # __float128
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000705 // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits)
706 // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
707 // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
708 // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits)
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000709 // ::= Di # char32_t
710 // ::= Ds # char16_t
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000711 // ::= u <source-name> # vendor extended type
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000712 // From our point of view, std::nullptr_t is a builtin, but as far as mangling
713 // is concerned, it's a type called std::nullptr_t.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000714 switch (T->getKind()) {
715 case BuiltinType::Void: Out << 'v'; break;
716 case BuiltinType::Bool: Out << 'b'; break;
717 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break;
718 case BuiltinType::UChar: Out << 'h'; break;
719 case BuiltinType::UShort: Out << 't'; break;
720 case BuiltinType::UInt: Out << 'j'; break;
721 case BuiltinType::ULong: Out << 'm'; break;
722 case BuiltinType::ULongLong: Out << 'y'; break;
Chris Lattner2df9ced2009-04-30 02:43:43 +0000723 case BuiltinType::UInt128: Out << 'o'; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000724 case BuiltinType::SChar: Out << 'a'; break;
725 case BuiltinType::WChar: Out << 'w'; break;
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000726 case BuiltinType::Char16: Out << "Ds"; break;
727 case BuiltinType::Char32: Out << "Di"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000728 case BuiltinType::Short: Out << 's'; break;
729 case BuiltinType::Int: Out << 'i'; break;
730 case BuiltinType::Long: Out << 'l'; break;
731 case BuiltinType::LongLong: Out << 'x'; break;
Chris Lattner2df9ced2009-04-30 02:43:43 +0000732 case BuiltinType::Int128: Out << 'n'; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000733 case BuiltinType::Float: Out << 'f'; break;
734 case BuiltinType::Double: Out << 'd'; break;
735 case BuiltinType::LongDouble: Out << 'e'; break;
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000736 case BuiltinType::NullPtr: Out << "St9nullptr_t"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000737
738 case BuiltinType::Overload:
739 case BuiltinType::Dependent:
Mike Stump1eb44332009-09-09 15:08:12 +0000740 assert(false &&
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000741 "Overloaded and dependent types shouldn't get to name mangling");
742 break;
Anders Carlssone89d1592009-06-26 18:41:36 +0000743 case BuiltinType::UndeducedAuto:
744 assert(0 && "Should not see undeduced auto here");
745 break;
Steve Naroff9533a7f2009-07-22 17:14:51 +0000746 case BuiltinType::ObjCId: Out << "11objc_object"; break;
747 case BuiltinType::ObjCClass: Out << "10objc_class"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000748 }
749}
750
John McCallefe6aee2009-09-05 07:56:18 +0000751// <type> ::= <function-type>
752// <function-type> ::= F [Y] <bare-function-type> E
753void CXXNameMangler::mangleType(const FunctionProtoType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000754 Out << 'F';
Mike Stumpf5408fe2009-05-16 07:57:57 +0000755 // FIXME: We don't have enough information in the AST to produce the 'Y'
756 // encoding for extern "C" function types.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000757 mangleBareFunctionType(T, /*MangleReturnType=*/true);
758 Out << 'E';
759}
John McCallefe6aee2009-09-05 07:56:18 +0000760void CXXNameMangler::mangleType(const FunctionNoProtoType *T) {
761 llvm::llvm_unreachable("Can't mangle K&R function prototypes");
762}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000763void CXXNameMangler::mangleBareFunctionType(const FunctionType *T,
764 bool MangleReturnType) {
John McCallefe6aee2009-09-05 07:56:18 +0000765 // We should never be mangling something without a prototype.
766 const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
767
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000768 // <bare-function-type> ::= <signature type>+
769 if (MangleReturnType)
John McCallefe6aee2009-09-05 07:56:18 +0000770 mangleType(Proto->getResultType());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000771
Anders Carlssonc6c91bc2009-04-01 00:15:23 +0000772 if (Proto->getNumArgs() == 0) {
773 Out << 'v';
774 return;
775 }
Mike Stump1eb44332009-09-09 15:08:12 +0000776
Douglas Gregor72564e72009-02-26 23:50:07 +0000777 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +0000778 ArgEnd = Proto->arg_type_end();
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000779 Arg != ArgEnd; ++Arg)
780 mangleType(*Arg);
Douglas Gregor219cc612009-02-13 01:28:03 +0000781
782 // <builtin-type> ::= z # ellipsis
783 if (Proto->isVariadic())
784 Out << 'z';
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000785}
786
John McCallefe6aee2009-09-05 07:56:18 +0000787// <type> ::= <class-enum-type>
Mike Stump1eb44332009-09-09 15:08:12 +0000788// <class-enum-type> ::= <name>
John McCallefe6aee2009-09-05 07:56:18 +0000789void CXXNameMangler::mangleType(const EnumType *T) {
790 mangleType(static_cast<const TagType*>(T));
791}
792void CXXNameMangler::mangleType(const RecordType *T) {
793 mangleType(static_cast<const TagType*>(T));
794}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000795void CXXNameMangler::mangleType(const TagType *T) {
Anders Carlsson4843e582009-03-10 17:07:44 +0000796 if (!T->getDecl()->getIdentifier())
797 mangleName(T->getDecl()->getTypedefForAnonDecl());
798 else
799 mangleName(T->getDecl());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000800}
801
John McCallefe6aee2009-09-05 07:56:18 +0000802// <type> ::= <array-type>
803// <array-type> ::= A <positive dimension number> _ <element type>
804// ::= A [<dimension expression>] _ <element type>
805void CXXNameMangler::mangleType(const ConstantArrayType *T) {
806 Out << 'A' << T->getSize() << '_';
807 mangleType(T->getElementType());
808}
809void CXXNameMangler::mangleType(const VariableArrayType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000810 Out << 'A';
John McCallefe6aee2009-09-05 07:56:18 +0000811 mangleExpression(T->getSizeExpr());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000812 Out << '_';
813 mangleType(T->getElementType());
814}
John McCallefe6aee2009-09-05 07:56:18 +0000815void CXXNameMangler::mangleType(const DependentSizedArrayType *T) {
816 Out << 'A';
817 mangleExpression(T->getSizeExpr());
818 Out << '_';
819 mangleType(T->getElementType());
820}
821void CXXNameMangler::mangleType(const IncompleteArrayType *T) {
822 Out << 'A' << '_';
823 mangleType(T->getElementType());
824}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000825
John McCallefe6aee2009-09-05 07:56:18 +0000826// <type> ::= <pointer-to-member-type>
827// <pointer-to-member-type> ::= M <class type> <member type>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000828void CXXNameMangler::mangleType(const MemberPointerType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000829 Out << 'M';
830 mangleType(QualType(T->getClass(), 0));
Anders Carlsson0e650012009-05-17 17:41:20 +0000831 QualType PointeeType = T->getPointeeType();
832 if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
833 mangleCVQualifiers(FPT->getTypeQuals());
834 mangleType(FPT);
Mike Stump1eb44332009-09-09 15:08:12 +0000835 } else
Anders Carlsson0e650012009-05-17 17:41:20 +0000836 mangleType(PointeeType);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000837}
838
John McCallefe6aee2009-09-05 07:56:18 +0000839// <type> ::= <template-param>
840// <template-param> ::= T_ # first template parameter
841// ::= T <parameter-2 non-negative number> _
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000842void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000843 if (T->getIndex() == 0)
844 Out << "T_";
845 else
846 Out << 'T' << (T->getIndex() - 1) << '_';
847}
848
John McCallefe6aee2009-09-05 07:56:18 +0000849// FIXME: <type> ::= <template-template-param> <template-args>
John McCallefe6aee2009-09-05 07:56:18 +0000850
851// <type> ::= P <type> # pointer-to
852void CXXNameMangler::mangleType(const PointerType *T) {
853 Out << 'P';
854 mangleType(T->getPointeeType());
855}
856void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
857 Out << 'P';
858 mangleType(T->getPointeeType());
859}
860
861// <type> ::= R <type> # reference-to
862void CXXNameMangler::mangleType(const LValueReferenceType *T) {
863 Out << 'R';
864 mangleType(T->getPointeeType());
865}
866
867// <type> ::= O <type> # rvalue reference-to (C++0x)
868void CXXNameMangler::mangleType(const RValueReferenceType *T) {
869 Out << 'O';
870 mangleType(T->getPointeeType());
871}
872
873// <type> ::= C <type> # complex pair (C 2000)
874void CXXNameMangler::mangleType(const ComplexType *T) {
875 Out << 'C';
876 mangleType(T->getElementType());
877}
878
879// GNU extension: vector types
880void CXXNameMangler::mangleType(const VectorType *T) {
881 Out << "U8__vector";
882 mangleType(T->getElementType());
883}
884void CXXNameMangler::mangleType(const ExtVectorType *T) {
885 mangleType(static_cast<const VectorType*>(T));
886}
887void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
888 Out << "U8__vector";
889 mangleType(T->getElementType());
890}
891
Anders Carlssona40c5e42009-03-07 22:03:21 +0000892void CXXNameMangler::mangleType(const ObjCInterfaceType *T) {
893 mangleSourceName(T->getDecl()->getIdentifier());
894}
895
John McCallefe6aee2009-09-05 07:56:18 +0000896void CXXNameMangler::mangleType(const BlockPointerType *T) {
897 assert(false && "can't mangle block pointer types yet");
898}
899
900void CXXNameMangler::mangleType(const FixedWidthIntType *T) {
901 assert(false && "can't mangle arbitary-precision integer type yet");
902}
903
904void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
Anders Carlsson7624f212009-09-18 02:42:01 +0000905 TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
906 assert(TD && "FIXME: Support dependent template names!");
907
908 mangleName(TD, T->getArgs(), T->getNumArgs());
John McCallefe6aee2009-09-05 07:56:18 +0000909}
910
911void CXXNameMangler::mangleType(const TypenameType *T) {
912 assert(false && "can't mangle dependent typenames yet");
913}
914
915// FIXME: For now, just drop all extension qualifiers on the floor.
916void CXXNameMangler::mangleType(const ExtQualType *T) {
917 mangleType(QualType(T->getBaseType(), 0));
918}
919
Anders Carlssond553f8c2009-09-21 01:21:10 +0000920void CXXNameMangler::mangleExpression(const Expr *E) {
921 // <expression> ::= <unary operator-name> <expression>
922 // ::= <binary operator-name> <expression> <expression>
923 // ::= <trinary operator-name> <expression> <expression> <expression>
924 // ::= cl <expression>* E # call
925 // ::= cv <type> expression # conversion with one argument
926 // ::= cv <type> _ <expression>* E # conversion with a different number of arguments
927 // ::= st <type> # sizeof (a type)
928 // ::= at <type> # alignof (a type)
929 // ::= <template-param>
930 // ::= <function-param>
931 // ::= sr <type> <unqualified-name> # dependent name
932 // ::= sr <type> <unqualified-name> <template-args> # dependent template-id
933 // ::= sZ <template-param> # size of a parameter pack
934 // ::= <expr-primary>
935 switch (E->getStmtClass()) {
936 default: assert(false && "Unhandled expression kind!");
937 case Expr::DeclRefExprClass: {
938 const Decl *D = cast<DeclRefExpr>(E)->getDecl();
939
940 switch (D->getKind()) {
941 default: assert(false && "Unhandled decl kind!");
942 case Decl::NonTypeTemplateParm: {
943 const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D);
944
945 if (PD->getIndex() == 0)
946 Out << "T_";
947 else
948 Out << 'T' << (PD->getIndex() - 1) << '_';
949 break;
950 }
951
952 }
953 }
954 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000955}
956
John McCallefe6aee2009-09-05 07:56:18 +0000957// FIXME: <type> ::= G <type> # imaginary (C 2000)
958// FIXME: <type> ::= U <source-name> <type> # vendor extended type qualifier
959
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000960void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) {
961 // <ctor-dtor-name> ::= C1 # complete object constructor
962 // ::= C2 # base object constructor
963 // ::= C3 # complete object allocating constructor
964 //
965 switch (T) {
966 case Ctor_Complete:
967 Out << "C1";
968 break;
969 case Ctor_Base:
970 Out << "C2";
971 break;
972 case Ctor_CompleteAllocating:
973 Out << "C3";
974 break;
975 }
976}
977
Anders Carlsson27ae5362009-04-17 01:58:57 +0000978void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
979 // <ctor-dtor-name> ::= D0 # deleting destructor
980 // ::= D1 # complete object destructor
981 // ::= D2 # base object destructor
982 //
983 switch (T) {
984 case Dtor_Deleting:
985 Out << "D0";
986 break;
987 case Dtor_Complete:
988 Out << "D1";
989 break;
990 case Dtor_Base:
991 Out << "D2";
992 break;
993 }
994}
995
Anders Carlsson068f3472009-09-17 05:31:47 +0000996void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) {
Anders Carlsson7a0ba872009-05-15 16:09:15 +0000997 // <template-args> ::= I <template-arg>+ E
998 Out << "I";
Mike Stump1eb44332009-09-09 15:08:12 +0000999
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001000 for (unsigned i = 0, e = L.size(); i != e; ++i) {
1001 const TemplateArgument &A = L[i];
Mike Stump1eb44332009-09-09 15:08:12 +00001002
Anders Carlsson068f3472009-09-17 05:31:47 +00001003 mangleTemplateArgument(A);
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001006 Out << "E";
1007}
1008
Anders Carlsson7624f212009-09-18 02:42:01 +00001009void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs,
1010 unsigned NumTemplateArgs) {
1011 // <template-args> ::= I <template-arg>+ E
1012 Out << "I";
1013
1014 for (unsigned i = 0; i != NumTemplateArgs; ++i) {
1015 mangleTemplateArgument(TemplateArgs[i]);
1016 }
1017
1018 Out << "E";
1019}
1020
Anders Carlsson068f3472009-09-17 05:31:47 +00001021void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
Mike Stump1eb44332009-09-09 15:08:12 +00001022 // <template-arg> ::= <type> # type or template
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001023 // ::= X <expression> E # expression
1024 // ::= <expr-primary> # simple expressions
1025 // ::= I <template-arg>* E # argument pack
1026 // ::= sp <expression> # pack expansion of (C++0x)
1027 switch (A.getKind()) {
1028 default:
1029 assert(0 && "Unknown template argument kind!");
1030 case TemplateArgument::Type:
1031 mangleType(A.getAsType());
1032 break;
Anders Carlssond553f8c2009-09-21 01:21:10 +00001033 case TemplateArgument::Expression:
1034 Out << 'X';
1035 mangleExpression(A.getAsExpr());
1036 Out << 'E';
1037 break;
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001038 case TemplateArgument::Integral:
1039 // <expr-primary> ::= L <type> <value number> E # integer literal
1040
1041 Out << 'L';
Mike Stump1eb44332009-09-09 15:08:12 +00001042
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001043 mangleType(A.getIntegralType());
Mike Stump1eb44332009-09-09 15:08:12 +00001044
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001045 const llvm::APSInt *Integral = A.getAsIntegral();
1046 if (A.getIntegralType()->isBooleanType()) {
1047 // Boolean values are encoded as 0/1.
1048 Out << (Integral->getBoolValue() ? '1' : '0');
1049 } else {
1050 if (Integral->isNegative())
1051 Out << 'n';
1052 Integral->abs().print(Out, false);
1053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001055 Out << 'E';
1056 break;
1057 }
1058}
1059
Anders Carlsson76967372009-09-17 00:43:46 +00001060// <substitution> ::= S <seq-id> _
1061// ::= S_
Anders Carlsson6862fc72009-09-17 04:16:28 +00001062
1063bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {
1064 return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
1065}
1066
Anders Carlsson76967372009-09-17 00:43:46 +00001067bool CXXNameMangler::mangleSubstitution(QualType T) {
1068 uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
1069
Anders Carlssond3a932a2009-09-17 03:53:28 +00001070 return mangleSubstitution(TypePtr);
1071}
1072
1073bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) {
Anders Carlsson76967372009-09-17 00:43:46 +00001074 llvm::DenseMap<uintptr_t, unsigned>::iterator I =
Anders Carlssond3a932a2009-09-17 03:53:28 +00001075 Substitutions.find(Ptr);
Anders Carlsson76967372009-09-17 00:43:46 +00001076 if (I == Substitutions.end())
1077 return false;
1078
1079 unsigned SeqID = I->second;
1080 if (SeqID == 0)
1081 Out << "S_";
1082 else {
1083 SeqID--;
1084
1085 // <seq-id> is encoded in base-36, using digits and upper case letters.
1086 char Buffer[10];
1087 char *BufferPtr = Buffer + 9;
1088
1089 *BufferPtr = 0;
1090 if (SeqID == 0) *--BufferPtr = '0';
1091
1092 while (SeqID) {
1093 assert(BufferPtr > Buffer && "Buffer overflow!");
1094
1095 unsigned char c = static_cast<unsigned char>(SeqID) % 36;
1096
1097 *--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10);
1098 SeqID /= 36;
1099 }
1100
1101 Out << 'S' << BufferPtr << '_';
1102 }
1103
1104 return true;
1105}
1106
1107void CXXNameMangler::addSubstitution(QualType T) {
1108 uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
Anders Carlssond3a932a2009-09-17 03:53:28 +00001109 addSubstitution(TypePtr);
1110}
1111
1112void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
Anders Carlsson76967372009-09-17 00:43:46 +00001113 unsigned SeqID = Substitutions.size();
1114
Anders Carlssond3a932a2009-09-17 03:53:28 +00001115 assert(!Substitutions.count(Ptr) && "Substitution already exists!");
1116 Substitutions[Ptr] = SeqID;
Anders Carlsson76967372009-09-17 00:43:46 +00001117}
1118
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001119namespace clang {
Mike Stump141c5af2009-09-02 00:25:38 +00001120 /// \brief Mangles the name of the declaration D and emits that name to the
1121 /// given output stream.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001122 ///
Mike Stump141c5af2009-09-02 00:25:38 +00001123 /// If the declaration D requires a mangled name, this routine will emit that
1124 /// mangled name to \p os and return true. Otherwise, \p os will be unchanged
1125 /// and this routine will return false. In this case, the caller should just
1126 /// emit the identifier of the declaration (\c D->getIdentifier()) as its
1127 /// name.
Mike Stump1eb44332009-09-09 15:08:12 +00001128 bool mangleName(const NamedDecl *D, ASTContext &Context,
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001129 llvm::raw_ostream &os) {
Anders Carlsson578aa642009-05-03 16:51:04 +00001130 assert(!isa<CXXConstructorDecl>(D) &&
1131 "Use mangleCXXCtor for constructor decls!");
1132 assert(!isa<CXXDestructorDecl>(D) &&
1133 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001134
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001135 CXXNameMangler Mangler(Context, os);
Douglas Gregor6ec36682009-02-18 23:53:56 +00001136 if (!Mangler.mangle(D))
1137 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001138
Douglas Gregor6ec36682009-02-18 23:53:56 +00001139 os.flush();
1140 return true;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001141 }
Mike Stump1eb44332009-09-09 15:08:12 +00001142
Mike Stump141c5af2009-09-02 00:25:38 +00001143 /// \brief Mangles the a thunk with the offset n for the declaration D and
1144 /// emits that name to the given output stream.
Mike Stumpdec025b2009-09-07 04:27:52 +00001145 void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v,
Mike Stump883f1272009-09-02 00:28:47 +00001146 ASTContext &Context, llvm::raw_ostream &os) {
Mike Stump141c5af2009-09-02 00:25:38 +00001147 // FIXME: Hum, we might have to thunk these, fix.
Mike Stumpdec025b2009-09-07 04:27:52 +00001148 assert(!isa<CXXDestructorDecl>(FD) &&
Mike Stump141c5af2009-09-02 00:25:38 +00001149 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001150
Mike Stump141c5af2009-09-02 00:25:38 +00001151 CXXNameMangler Mangler(Context, os);
Mike Stumpdec025b2009-09-07 04:27:52 +00001152 Mangler.mangleThunk(FD, nv, v);
Mike Stump141c5af2009-09-02 00:25:38 +00001153 os.flush();
1154 }
Mike Stump1eb44332009-09-09 15:08:12 +00001155
Mike Stump9124bcc2009-09-02 00:56:18 +00001156 /// \brief Mangles the a covariant thunk for the declaration D and emits that
1157 /// name to the given output stream.
Mike Stumpdec025b2009-09-07 04:27:52 +00001158 void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
Mike Stump77ca8f62009-09-05 07:20:32 +00001159 int64_t nv_r, int64_t v_r, ASTContext &Context,
Mike Stump9124bcc2009-09-02 00:56:18 +00001160 llvm::raw_ostream &os) {
1161 // FIXME: Hum, we might have to thunk these, fix.
Mike Stumpdec025b2009-09-07 04:27:52 +00001162 assert(!isa<CXXDestructorDecl>(FD) &&
Mike Stump9124bcc2009-09-02 00:56:18 +00001163 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001164
Mike Stump9124bcc2009-09-02 00:56:18 +00001165 CXXNameMangler Mangler(Context, os);
Mike Stumpdec025b2009-09-07 04:27:52 +00001166 Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r);
Mike Stump9124bcc2009-09-02 00:56:18 +00001167 os.flush();
1168 }
Mike Stump1eb44332009-09-09 15:08:12 +00001169
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001170 /// mangleGuardVariable - Returns the mangled name for a guard variable
1171 /// for the passed in VarDecl.
Anders Carlsson41aa8c12009-04-13 18:02:10 +00001172 void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
1173 llvm::raw_ostream &os) {
1174 CXXNameMangler Mangler(Context, os);
1175 Mangler.mangleGuardVariable(D);
1176
1177 os.flush();
1178 }
Mike Stump1eb44332009-09-09 15:08:12 +00001179
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001180 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
1181 ASTContext &Context, llvm::raw_ostream &os) {
1182 CXXNameMangler Mangler(Context, os);
1183 Mangler.mangleCXXCtor(D, Type);
Mike Stump1eb44332009-09-09 15:08:12 +00001184
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001185 os.flush();
1186 }
Mike Stump1eb44332009-09-09 15:08:12 +00001187
Anders Carlsson27ae5362009-04-17 01:58:57 +00001188 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
1189 ASTContext &Context, llvm::raw_ostream &os) {
1190 CXXNameMangler Mangler(Context, os);
1191 Mangler.mangleCXXDtor(D, Type);
Mike Stump1eb44332009-09-09 15:08:12 +00001192
Anders Carlsson27ae5362009-04-17 01:58:57 +00001193 os.flush();
1194 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001195
Mike Stumpf1216772009-07-31 18:25:34 +00001196 void mangleCXXVtable(QualType Type, ASTContext &Context,
1197 llvm::raw_ostream &os) {
1198 CXXNameMangler Mangler(Context, os);
1199 Mangler.mangleCXXVtable(Type);
1200
1201 os.flush();
1202 }
Mike Stump738f8c22009-07-31 23:15:31 +00001203
1204 void mangleCXXRtti(QualType Type, ASTContext &Context,
1205 llvm::raw_ostream &os) {
1206 CXXNameMangler Mangler(Context, os);
1207 Mangler.mangleCXXRtti(Type);
1208
1209 os.flush();
1210 }
Mike Stumpf1216772009-07-31 18:25:34 +00001211}