blob: 5a994d2234b272f9242b1f4dcbca28aaa8a7919f [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.
134 if (isInCLinkageSpecification(FD))
135 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 Carlsson9263e912009-09-18 18:39:58 +0000505 if (DC->isTranslationUnit())
506 return;
507
Anders Carlsson6862fc72009-09-17 04:16:28 +0000508 if (mangleSubstitution(cast<NamedDecl>(DC)))
509 return;
Anders Carlsson7482e242009-09-18 04:29:09 +0000510
Anders Carlsson2ee3fca2009-09-18 20:11:09 +0000511 // Check if we have a template.
512 const TemplateArgumentList *TemplateArgs = 0;
513 if (const NamedDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) {
514 mangleTemplatePrefix(TD);
515 mangleTemplateArgumentList(*TemplateArgs);
516 } else {
517 manglePrefix(DC->getParent());
518 mangleUnqualifiedName(cast<NamedDecl>(DC));
519 }
Anders Carlsson6862fc72009-09-17 04:16:28 +0000520
521 addSubstitution(cast<NamedDecl>(DC));
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000522}
523
Anders Carlssonaa73ab12009-09-18 18:47:07 +0000524void CXXNameMangler::mangleTemplatePrefix(const NamedDecl *ND) {
Anders Carlsson7482e242009-09-18 04:29:09 +0000525 // <template-prefix> ::= <prefix> <template unqualified-name>
526 // ::= <template-param>
527 // ::= <substitution>
528
Anders Carlssonaa73ab12009-09-18 18:47:07 +0000529 // FIXME: <substitution> and <template-param>
530
531 manglePrefix(ND->getDeclContext());
532 mangleUnqualifiedName(ND);
Anders Carlsson7482e242009-09-18 04:29:09 +0000533 // FIXME: Implement!
534}
535
Mike Stump1eb44332009-09-09 15:08:12 +0000536void
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000537CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) {
538 switch (OO) {
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000539 // <operator-name> ::= nw # new
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000540 case OO_New: Out << "nw"; break;
541 // ::= na # new[]
542 case OO_Array_New: Out << "na"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000543 // ::= dl # delete
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000544 case OO_Delete: Out << "dl"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000545 // ::= da # delete[]
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000546 case OO_Array_Delete: Out << "da"; break;
547 // ::= ps # + (unary)
548 // ::= pl # +
549 case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000550 // ::= ng # - (unary)
551 // ::= mi # -
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000552 case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000553 // ::= ad # & (unary)
554 // ::= an # &
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000555 case OO_Amp: Out << (Arity == 1? "ad" : "an"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000556 // ::= de # * (unary)
557 // ::= ml # *
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000558 case OO_Star: Out << (Arity == 1? "de" : "ml"); break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000559 // ::= co # ~
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000560 case OO_Tilde: Out << "co"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000561 // ::= dv # /
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000562 case OO_Slash: Out << "dv"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000563 // ::= rm # %
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000564 case OO_Percent: Out << "rm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000565 // ::= or # |
566 case OO_Pipe: Out << "or"; break;
567 // ::= eo # ^
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000568 case OO_Caret: Out << "eo"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000569 // ::= aS # =
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000570 case OO_Equal: Out << "aS"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000571 // ::= pL # +=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000572 case OO_PlusEqual: Out << "pL"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000573 // ::= mI # -=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000574 case OO_MinusEqual: Out << "mI"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000575 // ::= mL # *=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000576 case OO_StarEqual: Out << "mL"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000577 // ::= dV # /=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000578 case OO_SlashEqual: Out << "dV"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000579 // ::= rM # %=
580 case OO_PercentEqual: Out << "rM"; break;
581 // ::= aN # &=
582 case OO_AmpEqual: Out << "aN"; break;
583 // ::= oR # |=
584 case OO_PipeEqual: Out << "oR"; break;
585 // ::= eO # ^=
586 case OO_CaretEqual: Out << "eO"; break;
587 // ::= ls # <<
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000588 case OO_LessLess: Out << "ls"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000589 // ::= rs # >>
590 case OO_GreaterGreater: Out << "rs"; break;
591 // ::= lS # <<=
592 case OO_LessLessEqual: Out << "lS"; break;
593 // ::= rS # >>=
594 case OO_GreaterGreaterEqual: Out << "rS"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000595 // ::= eq # ==
596 case OO_EqualEqual: Out << "eq"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000597 // ::= ne # !=
598 case OO_ExclaimEqual: Out << "ne"; break;
599 // ::= lt # <
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000600 case OO_Less: Out << "lt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000601 // ::= gt # >
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000602 case OO_Greater: Out << "gt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000603 // ::= le # <=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000604 case OO_LessEqual: Out << "le"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000605 // ::= ge # >=
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000606 case OO_GreaterEqual: Out << "ge"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000607 // ::= nt # !
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000608 case OO_Exclaim: Out << "nt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000609 // ::= aa # &&
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000610 case OO_AmpAmp: Out << "aa"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000611 // ::= oo # ||
612 case OO_PipePipe: Out << "oo"; break;
613 // ::= pp # ++
614 case OO_PlusPlus: Out << "pp"; break;
615 // ::= mm # --
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000616 case OO_MinusMinus: Out << "mm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000617 // ::= cm # ,
618 case OO_Comma: Out << "cm"; break;
619 // ::= pm # ->*
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000620 case OO_ArrowStar: Out << "pm"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000621 // ::= pt # ->
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000622 case OO_Arrow: Out << "pt"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000623 // ::= cl # ()
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000624 case OO_Call: Out << "cl"; break;
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000625 // ::= ix # []
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000626 case OO_Subscript: Out << "ix"; break;
627 // UNSUPPORTED: ::= qu # ?
628
Sebastian Redl3201f6b2009-04-16 17:51:27 +0000629 case OO_None:
630 case OO_Conditional:
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000631 case NUM_OVERLOADED_OPERATORS:
Mike Stump1eb44332009-09-09 15:08:12 +0000632 assert(false && "Not an overloaded operator");
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000633 break;
634 }
635}
636
637void CXXNameMangler::mangleCVQualifiers(unsigned Quals) {
Mike Stump1eb44332009-09-09 15:08:12 +0000638 // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000639 if (Quals & QualType::Restrict)
640 Out << 'r';
641 if (Quals & QualType::Volatile)
642 Out << 'V';
643 if (Quals & QualType::Const)
644 Out << 'K';
645}
646
647void CXXNameMangler::mangleType(QualType T) {
Anders Carlsson4843e582009-03-10 17:07:44 +0000648 // Only operate on the canonical type!
649 T = Context.getCanonicalType(T);
650
Anders Carlsson76967372009-09-17 00:43:46 +0000651 bool IsSubstitutable = !isa<BuiltinType>(T);
652 if (IsSubstitutable && mangleSubstitution(T))
653 return;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000654
Anders Carlsson76967372009-09-17 00:43:46 +0000655 if (unsigned CVRQualifiers = T.getCVRQualifiers()) {
656 // <type> ::= <CV-qualifiers> <type>
657 mangleCVQualifiers(CVRQualifiers);
658
659 mangleType(T.getUnqualifiedType());
660 } else {
661 switch (T->getTypeClass()) {
John McCallefe6aee2009-09-05 07:56:18 +0000662#define ABSTRACT_TYPE(CLASS, PARENT)
663#define NON_CANONICAL_TYPE(CLASS, PARENT) \
Anders Carlsson76967372009-09-17 00:43:46 +0000664 case Type::CLASS: \
665 llvm::llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
666 return;
John McCallefe6aee2009-09-05 07:56:18 +0000667#define TYPE(CLASS, PARENT) \
Anders Carlsson76967372009-09-17 00:43:46 +0000668 case Type::CLASS: \
669 mangleType(static_cast<CLASS##Type*>(T.getTypePtr())); \
670 break;
John McCallefe6aee2009-09-05 07:56:18 +0000671#include "clang/AST/TypeNodes.def"
Anders Carlsson76967372009-09-17 00:43:46 +0000672 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000673 }
Anders Carlsson76967372009-09-17 00:43:46 +0000674
675 // Add the substitution.
676 if (IsSubstitutable)
677 addSubstitution(T);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000678}
679
680void CXXNameMangler::mangleType(const BuiltinType *T) {
John McCallefe6aee2009-09-05 07:56:18 +0000681 // <type> ::= <builtin-type>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000682 // <builtin-type> ::= v # void
683 // ::= w # wchar_t
684 // ::= b # bool
685 // ::= c # char
686 // ::= a # signed char
687 // ::= h # unsigned char
688 // ::= s # short
689 // ::= t # unsigned short
690 // ::= i # int
691 // ::= j # unsigned int
692 // ::= l # long
693 // ::= m # unsigned long
694 // ::= x # long long, __int64
695 // ::= y # unsigned long long, __int64
696 // ::= n # __int128
697 // UNSUPPORTED: ::= o # unsigned __int128
698 // ::= f # float
699 // ::= d # double
700 // ::= e # long double, __float80
701 // UNSUPPORTED: ::= g # __float128
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000702 // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits)
703 // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
704 // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
705 // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits)
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000706 // ::= Di # char32_t
707 // ::= Ds # char16_t
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000708 // ::= u <source-name> # vendor extended type
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000709 // From our point of view, std::nullptr_t is a builtin, but as far as mangling
710 // is concerned, it's a type called std::nullptr_t.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000711 switch (T->getKind()) {
712 case BuiltinType::Void: Out << 'v'; break;
713 case BuiltinType::Bool: Out << 'b'; break;
714 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break;
715 case BuiltinType::UChar: Out << 'h'; break;
716 case BuiltinType::UShort: Out << 't'; break;
717 case BuiltinType::UInt: Out << 'j'; break;
718 case BuiltinType::ULong: Out << 'm'; break;
719 case BuiltinType::ULongLong: Out << 'y'; break;
Chris Lattner2df9ced2009-04-30 02:43:43 +0000720 case BuiltinType::UInt128: Out << 'o'; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000721 case BuiltinType::SChar: Out << 'a'; break;
722 case BuiltinType::WChar: Out << 'w'; break;
Alisdair Meredithf5c209d2009-07-14 06:30:34 +0000723 case BuiltinType::Char16: Out << "Ds"; break;
724 case BuiltinType::Char32: Out << "Di"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000725 case BuiltinType::Short: Out << 's'; break;
726 case BuiltinType::Int: Out << 'i'; break;
727 case BuiltinType::Long: Out << 'l'; break;
728 case BuiltinType::LongLong: Out << 'x'; break;
Chris Lattner2df9ced2009-04-30 02:43:43 +0000729 case BuiltinType::Int128: Out << 'n'; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000730 case BuiltinType::Float: Out << 'f'; break;
731 case BuiltinType::Double: Out << 'd'; break;
732 case BuiltinType::LongDouble: Out << 'e'; break;
Sebastian Redl6e8ed162009-05-10 18:38:11 +0000733 case BuiltinType::NullPtr: Out << "St9nullptr_t"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000734
735 case BuiltinType::Overload:
736 case BuiltinType::Dependent:
Mike Stump1eb44332009-09-09 15:08:12 +0000737 assert(false &&
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000738 "Overloaded and dependent types shouldn't get to name mangling");
739 break;
Anders Carlssone89d1592009-06-26 18:41:36 +0000740 case BuiltinType::UndeducedAuto:
741 assert(0 && "Should not see undeduced auto here");
742 break;
Steve Naroff9533a7f2009-07-22 17:14:51 +0000743 case BuiltinType::ObjCId: Out << "11objc_object"; break;
744 case BuiltinType::ObjCClass: Out << "10objc_class"; break;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000745 }
746}
747
John McCallefe6aee2009-09-05 07:56:18 +0000748// <type> ::= <function-type>
749// <function-type> ::= F [Y] <bare-function-type> E
750void CXXNameMangler::mangleType(const FunctionProtoType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000751 Out << 'F';
Mike Stumpf5408fe2009-05-16 07:57:57 +0000752 // FIXME: We don't have enough information in the AST to produce the 'Y'
753 // encoding for extern "C" function types.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000754 mangleBareFunctionType(T, /*MangleReturnType=*/true);
755 Out << 'E';
756}
John McCallefe6aee2009-09-05 07:56:18 +0000757void CXXNameMangler::mangleType(const FunctionNoProtoType *T) {
758 llvm::llvm_unreachable("Can't mangle K&R function prototypes");
759}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000760void CXXNameMangler::mangleBareFunctionType(const FunctionType *T,
761 bool MangleReturnType) {
John McCallefe6aee2009-09-05 07:56:18 +0000762 // We should never be mangling something without a prototype.
763 const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
764
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000765 // <bare-function-type> ::= <signature type>+
766 if (MangleReturnType)
John McCallefe6aee2009-09-05 07:56:18 +0000767 mangleType(Proto->getResultType());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000768
Anders Carlssonc6c91bc2009-04-01 00:15:23 +0000769 if (Proto->getNumArgs() == 0) {
770 Out << 'v';
771 return;
772 }
Mike Stump1eb44332009-09-09 15:08:12 +0000773
Douglas Gregor72564e72009-02-26 23:50:07 +0000774 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +0000775 ArgEnd = Proto->arg_type_end();
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000776 Arg != ArgEnd; ++Arg)
777 mangleType(*Arg);
Douglas Gregor219cc612009-02-13 01:28:03 +0000778
779 // <builtin-type> ::= z # ellipsis
780 if (Proto->isVariadic())
781 Out << 'z';
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000782}
783
John McCallefe6aee2009-09-05 07:56:18 +0000784// <type> ::= <class-enum-type>
Mike Stump1eb44332009-09-09 15:08:12 +0000785// <class-enum-type> ::= <name>
John McCallefe6aee2009-09-05 07:56:18 +0000786void CXXNameMangler::mangleType(const EnumType *T) {
787 mangleType(static_cast<const TagType*>(T));
788}
789void CXXNameMangler::mangleType(const RecordType *T) {
790 mangleType(static_cast<const TagType*>(T));
791}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000792void CXXNameMangler::mangleType(const TagType *T) {
Anders Carlsson4843e582009-03-10 17:07:44 +0000793 if (!T->getDecl()->getIdentifier())
794 mangleName(T->getDecl()->getTypedefForAnonDecl());
795 else
796 mangleName(T->getDecl());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000797}
798
John McCallefe6aee2009-09-05 07:56:18 +0000799// <type> ::= <array-type>
800// <array-type> ::= A <positive dimension number> _ <element type>
801// ::= A [<dimension expression>] _ <element type>
802void CXXNameMangler::mangleType(const ConstantArrayType *T) {
803 Out << 'A' << T->getSize() << '_';
804 mangleType(T->getElementType());
805}
806void CXXNameMangler::mangleType(const VariableArrayType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000807 Out << 'A';
John McCallefe6aee2009-09-05 07:56:18 +0000808 mangleExpression(T->getSizeExpr());
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000809 Out << '_';
810 mangleType(T->getElementType());
811}
John McCallefe6aee2009-09-05 07:56:18 +0000812void CXXNameMangler::mangleType(const DependentSizedArrayType *T) {
813 Out << 'A';
814 mangleExpression(T->getSizeExpr());
815 Out << '_';
816 mangleType(T->getElementType());
817}
818void CXXNameMangler::mangleType(const IncompleteArrayType *T) {
819 Out << 'A' << '_';
820 mangleType(T->getElementType());
821}
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000822
John McCallefe6aee2009-09-05 07:56:18 +0000823// <type> ::= <pointer-to-member-type>
824// <pointer-to-member-type> ::= M <class type> <member type>
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000825void CXXNameMangler::mangleType(const MemberPointerType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000826 Out << 'M';
827 mangleType(QualType(T->getClass(), 0));
Anders Carlsson0e650012009-05-17 17:41:20 +0000828 QualType PointeeType = T->getPointeeType();
829 if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
830 mangleCVQualifiers(FPT->getTypeQuals());
831 mangleType(FPT);
Mike Stump1eb44332009-09-09 15:08:12 +0000832 } else
Anders Carlsson0e650012009-05-17 17:41:20 +0000833 mangleType(PointeeType);
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000834}
835
John McCallefe6aee2009-09-05 07:56:18 +0000836// <type> ::= <template-param>
837// <template-param> ::= T_ # first template parameter
838// ::= T <parameter-2 non-negative number> _
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000839void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000840 if (T->getIndex() == 0)
841 Out << "T_";
842 else
843 Out << 'T' << (T->getIndex() - 1) << '_';
844}
845
John McCallefe6aee2009-09-05 07:56:18 +0000846// FIXME: <type> ::= <template-template-param> <template-args>
John McCallefe6aee2009-09-05 07:56:18 +0000847
848// <type> ::= P <type> # pointer-to
849void CXXNameMangler::mangleType(const PointerType *T) {
850 Out << 'P';
851 mangleType(T->getPointeeType());
852}
853void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
854 Out << 'P';
855 mangleType(T->getPointeeType());
856}
857
858// <type> ::= R <type> # reference-to
859void CXXNameMangler::mangleType(const LValueReferenceType *T) {
860 Out << 'R';
861 mangleType(T->getPointeeType());
862}
863
864// <type> ::= O <type> # rvalue reference-to (C++0x)
865void CXXNameMangler::mangleType(const RValueReferenceType *T) {
866 Out << 'O';
867 mangleType(T->getPointeeType());
868}
869
870// <type> ::= C <type> # complex pair (C 2000)
871void CXXNameMangler::mangleType(const ComplexType *T) {
872 Out << 'C';
873 mangleType(T->getElementType());
874}
875
876// GNU extension: vector types
877void CXXNameMangler::mangleType(const VectorType *T) {
878 Out << "U8__vector";
879 mangleType(T->getElementType());
880}
881void CXXNameMangler::mangleType(const ExtVectorType *T) {
882 mangleType(static_cast<const VectorType*>(T));
883}
884void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
885 Out << "U8__vector";
886 mangleType(T->getElementType());
887}
888
Anders Carlssona40c5e42009-03-07 22:03:21 +0000889void CXXNameMangler::mangleType(const ObjCInterfaceType *T) {
890 mangleSourceName(T->getDecl()->getIdentifier());
891}
892
John McCallefe6aee2009-09-05 07:56:18 +0000893void CXXNameMangler::mangleType(const BlockPointerType *T) {
894 assert(false && "can't mangle block pointer types yet");
895}
896
897void CXXNameMangler::mangleType(const FixedWidthIntType *T) {
898 assert(false && "can't mangle arbitary-precision integer type yet");
899}
900
901void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
Anders Carlsson7624f212009-09-18 02:42:01 +0000902 TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
903 assert(TD && "FIXME: Support dependent template names!");
904
905 mangleName(TD, T->getArgs(), T->getNumArgs());
John McCallefe6aee2009-09-05 07:56:18 +0000906}
907
908void CXXNameMangler::mangleType(const TypenameType *T) {
909 assert(false && "can't mangle dependent typenames yet");
910}
911
912// FIXME: For now, just drop all extension qualifiers on the floor.
913void CXXNameMangler::mangleType(const ExtQualType *T) {
914 mangleType(QualType(T->getBaseType(), 0));
915}
916
Anders Carlssond553f8c2009-09-21 01:21:10 +0000917void CXXNameMangler::mangleExpression(const Expr *E) {
918 // <expression> ::= <unary operator-name> <expression>
919 // ::= <binary operator-name> <expression> <expression>
920 // ::= <trinary operator-name> <expression> <expression> <expression>
921 // ::= cl <expression>* E # call
922 // ::= cv <type> expression # conversion with one argument
923 // ::= cv <type> _ <expression>* E # conversion with a different number of arguments
924 // ::= st <type> # sizeof (a type)
925 // ::= at <type> # alignof (a type)
926 // ::= <template-param>
927 // ::= <function-param>
928 // ::= sr <type> <unqualified-name> # dependent name
929 // ::= sr <type> <unqualified-name> <template-args> # dependent template-id
930 // ::= sZ <template-param> # size of a parameter pack
931 // ::= <expr-primary>
932 switch (E->getStmtClass()) {
933 default: assert(false && "Unhandled expression kind!");
934 case Expr::DeclRefExprClass: {
935 const Decl *D = cast<DeclRefExpr>(E)->getDecl();
936
937 switch (D->getKind()) {
938 default: assert(false && "Unhandled decl kind!");
939 case Decl::NonTypeTemplateParm: {
940 const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D);
941
942 if (PD->getIndex() == 0)
943 Out << "T_";
944 else
945 Out << 'T' << (PD->getIndex() - 1) << '_';
946 break;
947 }
948
949 }
950 }
951 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +0000952}
953
John McCallefe6aee2009-09-05 07:56:18 +0000954// FIXME: <type> ::= G <type> # imaginary (C 2000)
955// FIXME: <type> ::= U <source-name> <type> # vendor extended type qualifier
956
Anders Carlsson3ac86b52009-04-15 05:36:58 +0000957void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) {
958 // <ctor-dtor-name> ::= C1 # complete object constructor
959 // ::= C2 # base object constructor
960 // ::= C3 # complete object allocating constructor
961 //
962 switch (T) {
963 case Ctor_Complete:
964 Out << "C1";
965 break;
966 case Ctor_Base:
967 Out << "C2";
968 break;
969 case Ctor_CompleteAllocating:
970 Out << "C3";
971 break;
972 }
973}
974
Anders Carlsson27ae5362009-04-17 01:58:57 +0000975void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
976 // <ctor-dtor-name> ::= D0 # deleting destructor
977 // ::= D1 # complete object destructor
978 // ::= D2 # base object destructor
979 //
980 switch (T) {
981 case Dtor_Deleting:
982 Out << "D0";
983 break;
984 case Dtor_Complete:
985 Out << "D1";
986 break;
987 case Dtor_Base:
988 Out << "D2";
989 break;
990 }
991}
992
Anders Carlsson068f3472009-09-17 05:31:47 +0000993void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) {
Anders Carlsson7a0ba872009-05-15 16:09:15 +0000994 // <template-args> ::= I <template-arg>+ E
995 Out << "I";
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Anders Carlsson7a0ba872009-05-15 16:09:15 +0000997 for (unsigned i = 0, e = L.size(); i != e; ++i) {
998 const TemplateArgument &A = L[i];
Mike Stump1eb44332009-09-09 15:08:12 +0000999
Anders Carlsson068f3472009-09-17 05:31:47 +00001000 mangleTemplateArgument(A);
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001001 }
Mike Stump1eb44332009-09-09 15:08:12 +00001002
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001003 Out << "E";
1004}
1005
Anders Carlsson7624f212009-09-18 02:42:01 +00001006void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs,
1007 unsigned NumTemplateArgs) {
1008 // <template-args> ::= I <template-arg>+ E
1009 Out << "I";
1010
1011 for (unsigned i = 0; i != NumTemplateArgs; ++i) {
1012 mangleTemplateArgument(TemplateArgs[i]);
1013 }
1014
1015 Out << "E";
1016}
1017
Anders Carlsson068f3472009-09-17 05:31:47 +00001018void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
Mike Stump1eb44332009-09-09 15:08:12 +00001019 // <template-arg> ::= <type> # type or template
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001020 // ::= X <expression> E # expression
1021 // ::= <expr-primary> # simple expressions
1022 // ::= I <template-arg>* E # argument pack
1023 // ::= sp <expression> # pack expansion of (C++0x)
1024 switch (A.getKind()) {
1025 default:
1026 assert(0 && "Unknown template argument kind!");
1027 case TemplateArgument::Type:
1028 mangleType(A.getAsType());
1029 break;
Anders Carlssond553f8c2009-09-21 01:21:10 +00001030 case TemplateArgument::Expression:
1031 Out << 'X';
1032 mangleExpression(A.getAsExpr());
1033 Out << 'E';
1034 break;
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001035 case TemplateArgument::Integral:
1036 // <expr-primary> ::= L <type> <value number> E # integer literal
1037
1038 Out << 'L';
Mike Stump1eb44332009-09-09 15:08:12 +00001039
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001040 mangleType(A.getIntegralType());
Mike Stump1eb44332009-09-09 15:08:12 +00001041
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001042 const llvm::APSInt *Integral = A.getAsIntegral();
1043 if (A.getIntegralType()->isBooleanType()) {
1044 // Boolean values are encoded as 0/1.
1045 Out << (Integral->getBoolValue() ? '1' : '0');
1046 } else {
1047 if (Integral->isNegative())
1048 Out << 'n';
1049 Integral->abs().print(Out, false);
1050 }
Mike Stump1eb44332009-09-09 15:08:12 +00001051
Anders Carlsson7a0ba872009-05-15 16:09:15 +00001052 Out << 'E';
1053 break;
1054 }
1055}
1056
Anders Carlsson76967372009-09-17 00:43:46 +00001057// <substitution> ::= S <seq-id> _
1058// ::= S_
Anders Carlsson6862fc72009-09-17 04:16:28 +00001059
1060bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {
1061 return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
1062}
1063
Anders Carlsson76967372009-09-17 00:43:46 +00001064bool CXXNameMangler::mangleSubstitution(QualType T) {
1065 uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
1066
Anders Carlssond3a932a2009-09-17 03:53:28 +00001067 return mangleSubstitution(TypePtr);
1068}
1069
1070bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) {
Anders Carlsson76967372009-09-17 00:43:46 +00001071 llvm::DenseMap<uintptr_t, unsigned>::iterator I =
Anders Carlssond3a932a2009-09-17 03:53:28 +00001072 Substitutions.find(Ptr);
Anders Carlsson76967372009-09-17 00:43:46 +00001073 if (I == Substitutions.end())
1074 return false;
1075
1076 unsigned SeqID = I->second;
1077 if (SeqID == 0)
1078 Out << "S_";
1079 else {
1080 SeqID--;
1081
1082 // <seq-id> is encoded in base-36, using digits and upper case letters.
1083 char Buffer[10];
1084 char *BufferPtr = Buffer + 9;
1085
1086 *BufferPtr = 0;
1087 if (SeqID == 0) *--BufferPtr = '0';
1088
1089 while (SeqID) {
1090 assert(BufferPtr > Buffer && "Buffer overflow!");
1091
1092 unsigned char c = static_cast<unsigned char>(SeqID) % 36;
1093
1094 *--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10);
1095 SeqID /= 36;
1096 }
1097
1098 Out << 'S' << BufferPtr << '_';
1099 }
1100
1101 return true;
1102}
1103
1104void CXXNameMangler::addSubstitution(QualType T) {
1105 uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
Anders Carlssond3a932a2009-09-17 03:53:28 +00001106 addSubstitution(TypePtr);
1107}
1108
1109void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
Anders Carlsson76967372009-09-17 00:43:46 +00001110 unsigned SeqID = Substitutions.size();
1111
Anders Carlssond3a932a2009-09-17 03:53:28 +00001112 assert(!Substitutions.count(Ptr) && "Substitution already exists!");
1113 Substitutions[Ptr] = SeqID;
Anders Carlsson76967372009-09-17 00:43:46 +00001114}
1115
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001116namespace clang {
Mike Stump141c5af2009-09-02 00:25:38 +00001117 /// \brief Mangles the name of the declaration D and emits that name to the
1118 /// given output stream.
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001119 ///
Mike Stump141c5af2009-09-02 00:25:38 +00001120 /// If the declaration D requires a mangled name, this routine will emit that
1121 /// mangled name to \p os and return true. Otherwise, \p os will be unchanged
1122 /// and this routine will return false. In this case, the caller should just
1123 /// emit the identifier of the declaration (\c D->getIdentifier()) as its
1124 /// name.
Mike Stump1eb44332009-09-09 15:08:12 +00001125 bool mangleName(const NamedDecl *D, ASTContext &Context,
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001126 llvm::raw_ostream &os) {
Anders Carlsson578aa642009-05-03 16:51:04 +00001127 assert(!isa<CXXConstructorDecl>(D) &&
1128 "Use mangleCXXCtor for constructor decls!");
1129 assert(!isa<CXXDestructorDecl>(D) &&
1130 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001131
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001132 CXXNameMangler Mangler(Context, os);
Douglas Gregor6ec36682009-02-18 23:53:56 +00001133 if (!Mangler.mangle(D))
1134 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001135
Douglas Gregor6ec36682009-02-18 23:53:56 +00001136 os.flush();
1137 return true;
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001138 }
Mike Stump1eb44332009-09-09 15:08:12 +00001139
Mike Stump141c5af2009-09-02 00:25:38 +00001140 /// \brief Mangles the a thunk with the offset n for the declaration D and
1141 /// emits that name to the given output stream.
Mike Stumpdec025b2009-09-07 04:27:52 +00001142 void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v,
Mike Stump883f1272009-09-02 00:28:47 +00001143 ASTContext &Context, llvm::raw_ostream &os) {
Mike Stump141c5af2009-09-02 00:25:38 +00001144 // FIXME: Hum, we might have to thunk these, fix.
Mike Stumpdec025b2009-09-07 04:27:52 +00001145 assert(!isa<CXXDestructorDecl>(FD) &&
Mike Stump141c5af2009-09-02 00:25:38 +00001146 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001147
Mike Stump141c5af2009-09-02 00:25:38 +00001148 CXXNameMangler Mangler(Context, os);
Mike Stumpdec025b2009-09-07 04:27:52 +00001149 Mangler.mangleThunk(FD, nv, v);
Mike Stump141c5af2009-09-02 00:25:38 +00001150 os.flush();
1151 }
Mike Stump1eb44332009-09-09 15:08:12 +00001152
Mike Stump9124bcc2009-09-02 00:56:18 +00001153 /// \brief Mangles the a covariant thunk for the declaration D and emits that
1154 /// name to the given output stream.
Mike Stumpdec025b2009-09-07 04:27:52 +00001155 void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t,
Mike Stump77ca8f62009-09-05 07:20:32 +00001156 int64_t nv_r, int64_t v_r, ASTContext &Context,
Mike Stump9124bcc2009-09-02 00:56:18 +00001157 llvm::raw_ostream &os) {
1158 // FIXME: Hum, we might have to thunk these, fix.
Mike Stumpdec025b2009-09-07 04:27:52 +00001159 assert(!isa<CXXDestructorDecl>(FD) &&
Mike Stump9124bcc2009-09-02 00:56:18 +00001160 "Use mangleCXXDtor for destructor decls!");
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Mike Stump9124bcc2009-09-02 00:56:18 +00001162 CXXNameMangler Mangler(Context, os);
Mike Stumpdec025b2009-09-07 04:27:52 +00001163 Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r);
Mike Stump9124bcc2009-09-02 00:56:18 +00001164 os.flush();
1165 }
Mike Stump1eb44332009-09-09 15:08:12 +00001166
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001167 /// mangleGuardVariable - Returns the mangled name for a guard variable
1168 /// for the passed in VarDecl.
Anders Carlsson41aa8c12009-04-13 18:02:10 +00001169 void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
1170 llvm::raw_ostream &os) {
1171 CXXNameMangler Mangler(Context, os);
1172 Mangler.mangleGuardVariable(D);
1173
1174 os.flush();
1175 }
Mike Stump1eb44332009-09-09 15:08:12 +00001176
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001177 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
1178 ASTContext &Context, llvm::raw_ostream &os) {
1179 CXXNameMangler Mangler(Context, os);
1180 Mangler.mangleCXXCtor(D, Type);
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Anders Carlsson3ac86b52009-04-15 05:36:58 +00001182 os.flush();
1183 }
Mike Stump1eb44332009-09-09 15:08:12 +00001184
Anders Carlsson27ae5362009-04-17 01:58:57 +00001185 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
1186 ASTContext &Context, llvm::raw_ostream &os) {
1187 CXXNameMangler Mangler(Context, os);
1188 Mangler.mangleCXXDtor(D, Type);
Mike Stump1eb44332009-09-09 15:08:12 +00001189
Anders Carlsson27ae5362009-04-17 01:58:57 +00001190 os.flush();
1191 }
Douglas Gregor5f2bfd42009-02-13 00:10:09 +00001192
Mike Stumpf1216772009-07-31 18:25:34 +00001193 void mangleCXXVtable(QualType Type, ASTContext &Context,
1194 llvm::raw_ostream &os) {
1195 CXXNameMangler Mangler(Context, os);
1196 Mangler.mangleCXXVtable(Type);
1197
1198 os.flush();
1199 }
Mike Stump738f8c22009-07-31 23:15:31 +00001200
1201 void mangleCXXRtti(QualType Type, ASTContext &Context,
1202 llvm::raw_ostream &os) {
1203 CXXNameMangler Mangler(Context, os);
1204 Mangler.mangleCXXRtti(Type);
1205
1206 os.flush();
1207 }
Mike Stumpf1216772009-07-31 18:25:34 +00001208}