blob: 3d3efc62f95bb25e509315b93dee00344328cfde [file] [log] [blame]
Douglas Gregor3c3c4542009-02-18 23:53:56 +00001//===--- Mangle.cpp - Mangle C++ Names --------------------------*- C++ -*-===//
Douglas Gregor3556bc72009-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 Carlssonfae45862009-03-07 22:03:21 +000021#include "clang/AST/DeclObjC.h"
Anders Carlssonb1008e42009-05-15 16:09:15 +000022#include "clang/AST/DeclTemplate.h"
Douglas Gregor3c3c4542009-02-18 23:53:56 +000023#include "clang/Basic/SourceManager.h"
Douglas Gregor3556bc72009-02-13 00:10:09 +000024#include "llvm/Support/Compiler.h"
25#include "llvm/Support/raw_ostream.h"
26using namespace clang;
27
28namespace {
29 class VISIBILITY_HIDDEN CXXNameMangler {
30 ASTContext &Context;
31 llvm::raw_ostream &Out;
32
Anders Carlsson4811c302009-04-17 01:58:57 +000033 const CXXMethodDecl *Structor;
34 unsigned StructorType;
Anders Carlsson6b6adf22009-04-15 05:36:58 +000035 CXXCtorType CtorType;
36
Douglas Gregor3556bc72009-02-13 00:10:09 +000037 public:
38 CXXNameMangler(ASTContext &C, llvm::raw_ostream &os)
Anders Carlsson4811c302009-04-17 01:58:57 +000039 : Context(C), Out(os), Structor(0), StructorType(0) { }
Douglas Gregor3556bc72009-02-13 00:10:09 +000040
41 bool mangle(const NamedDecl *D);
Mike Stump58256412009-09-05 07:20:32 +000042 void mangleCalloffset(int64_t nv, int64_t v);
43 void mangleThunk(const NamedDecl *ND, int64_t nv, int64_t v);
44 void mangleCovariantThunk(const NamedDecl *ND,
45 int64_t nv_t, int64_t v_t,
Mike Stump28db39b2009-09-02 00:56:18 +000046 int64_t nv_r, int64_t v_r);
Anders Carlsson53f73bc2009-04-13 18:02:10 +000047 void mangleGuardVariable(const VarDecl *D);
Anders Carlsson4811c302009-04-17 01:58:57 +000048
Mike Stump7e8c9932009-07-31 18:25:34 +000049 void mangleCXXVtable(QualType Type);
Mike Stump00df7d32009-07-31 23:15:31 +000050 void mangleCXXRtti(QualType Type);
Anders Carlsson6b6adf22009-04-15 05:36:58 +000051 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type);
Anders Carlsson4811c302009-04-17 01:58:57 +000052 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type);
Anders Carlsson6b6adf22009-04-15 05:36:58 +000053
Anders Carlsson70cc0d22009-04-02 15:51:53 +000054 private:
55 bool mangleFunctionDecl(const FunctionDecl *FD);
56
Douglas Gregor3556bc72009-02-13 00:10:09 +000057 void mangleFunctionEncoding(const FunctionDecl *FD);
58 void mangleName(const NamedDecl *ND);
59 void mangleUnqualifiedName(const NamedDecl *ND);
60 void mangleSourceName(const IdentifierInfo *II);
Anders Carlssonfd8c56b2009-04-02 16:24:45 +000061 void mangleLocalName(const NamedDecl *ND);
Douglas Gregor3556bc72009-02-13 00:10:09 +000062 void mangleNestedName(const NamedDecl *ND);
63 void manglePrefix(const DeclContext *DC);
64 void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
65 void mangleCVQualifiers(unsigned Quals);
66 void mangleType(QualType T);
67 void mangleType(const BuiltinType *T);
68 void mangleType(const FunctionType *T);
69 void mangleBareFunctionType(const FunctionType *T, bool MangleReturnType);
70 void mangleType(const TagType *T);
71 void mangleType(const ArrayType *T);
72 void mangleType(const MemberPointerType *T);
73 void mangleType(const TemplateTypeParmType *T);
Anders Carlssonfae45862009-03-07 22:03:21 +000074 void mangleType(const ObjCInterfaceType *T);
Douglas Gregor3556bc72009-02-13 00:10:09 +000075 void mangleExpression(Expr *E);
Anders Carlsson6b6adf22009-04-15 05:36:58 +000076 void mangleCXXCtorType(CXXCtorType T);
Anders Carlsson4811c302009-04-17 01:58:57 +000077 void mangleCXXDtorType(CXXDtorType T);
Anders Carlssonb1008e42009-05-15 16:09:15 +000078
79 void mangleTemplateArgumentList(const TemplateArgumentList &L);
80 void mangleTemplateArgument(const TemplateArgument &A);
Douglas Gregor3556bc72009-02-13 00:10:09 +000081 };
82}
83
Anders Carlsson70cc0d22009-04-02 15:51:53 +000084static bool isInCLinkageSpecification(const Decl *D) {
85 for (const DeclContext *DC = D->getDeclContext();
86 !DC->isTranslationUnit(); DC = DC->getParent()) {
87 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
88 return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
89 }
90
91 return false;
92}
93
94bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) {
Mike Stumpb29542f2009-09-02 00:25:38 +000095 // Clang's "overloadable" attribute extension to C/C++ implies name mangling
96 // (always).
Argiris Kirtzidisfe5f9732009-06-30 02:34:44 +000097 if (!FD->hasAttr<OverloadableAttr>()) {
Chris Lattner0c032a42009-06-13 23:34:16 +000098 // C functions are not mangled, and "main" is never mangled.
John McCallcb6dd8a2009-08-15 02:09:25 +000099 if (!Context.getLangOptions().CPlusPlus || FD->isMain(Context))
Chris Lattner0c032a42009-06-13 23:34:16 +0000100 return false;
101
102 // No mangling in an "implicit extern C" header.
103 if (FD->getLocation().isValid() &&
104 Context.getSourceManager().isInExternCSystemHeader(FD->getLocation()))
105 return false;
106
107 // No name mangling in a C linkage specification.
108 if (isInCLinkageSpecification(FD))
109 return false;
110 }
Anders Carlsson70cc0d22009-04-02 15:51:53 +0000111
112 // If we get here, mangle the decl name!
113 Out << "_Z";
114 mangleFunctionEncoding(FD);
115 return true;
116}
Douglas Gregor3556bc72009-02-13 00:10:09 +0000117
118bool CXXNameMangler::mangle(const NamedDecl *D) {
Mike Stumpb29542f2009-09-02 00:25:38 +0000119 // Any decl can be declared with __asm("foo") on it, and this takes precedence
120 // over all other naming in the .o file.
Argiris Kirtzidisfe5f9732009-06-30 02:34:44 +0000121 if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
Chris Lattner8af0e262009-03-21 08:24:40 +0000122 // If we have an asm name, then we use it as the mangling.
123 Out << '\01'; // LLVM IR Marker for __asm("foo")
124 Out << ALA->getLabel();
125 return true;
126 }
127
Douglas Gregor3556bc72009-02-13 00:10:09 +0000128 // <mangled-name> ::= _Z <encoding>
129 // ::= <data name>
130 // ::= <special-name>
131
132 // FIXME: Actually use a visitor to decode these?
Anders Carlsson70cc0d22009-04-02 15:51:53 +0000133 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
134 return mangleFunctionDecl(FD);
Chris Lattner5cbf5882009-03-21 06:19:20 +0000135
Anders Carlssonaf6bb352009-04-02 16:05:20 +0000136 if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
137 if (!Context.getLangOptions().CPlusPlus ||
Anders Carlssonc3e84ae2009-04-11 01:19:45 +0000138 isInCLinkageSpecification(D) ||
139 D->getDeclContext()->isTranslationUnit())
Anders Carlssonaf6bb352009-04-02 16:05:20 +0000140 return false;
141
142 Out << "_Z";
143 mangleName(VD);
144 return true;
145 }
146
Anders Carlsson70cc0d22009-04-02 15:51:53 +0000147 return false;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000148}
149
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000150void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D,
151 CXXCtorType Type) {
Anders Carlsson4811c302009-04-17 01:58:57 +0000152 assert(!Structor && "Structor already set!");
153 Structor = D;
154 StructorType = Type;
155
156 mangle(D);
157}
158
159void CXXNameMangler::mangleCXXDtor(const CXXDestructorDecl *D,
160 CXXDtorType Type) {
161 assert(!Structor && "Structor already set!");
162 Structor = D;
163 StructorType = Type;
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000164
165 mangle(D);
166}
167
Mike Stump7e8c9932009-07-31 18:25:34 +0000168void CXXNameMangler::mangleCXXVtable(QualType T) {
169 // <special-name> ::= TV <type> # virtual table
170 Out << "_ZTV";
171 mangleType(T);
172}
173
Mike Stump00df7d32009-07-31 23:15:31 +0000174void CXXNameMangler::mangleCXXRtti(QualType T) {
175 // <special-name> ::= TI <type> # typeinfo structure
176 Out << "_ZTI";
177 mangleType(T);
178}
179
Anders Carlsson53f73bc2009-04-13 18:02:10 +0000180void CXXNameMangler::mangleGuardVariable(const VarDecl *D)
181{
182 // <special-name> ::= GV <object name> # Guard variable for one-time
Mike Stump7e8c9932009-07-31 18:25:34 +0000183 // # initialization
Anders Carlsson53f73bc2009-04-13 18:02:10 +0000184
185 Out << "_ZGV";
186 mangleName(D);
187}
188
Douglas Gregor3556bc72009-02-13 00:10:09 +0000189void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
190 // <encoding> ::= <function name> <bare-function-type>
191 mangleName(FD);
Douglas Gregor69678062009-06-29 22:39:32 +0000192
Mike Stumpb29542f2009-09-02 00:25:38 +0000193 // Whether the mangling of a function type includes the return type depends on
194 // the context and the nature of the function. The rules for deciding whether
195 // the return type is included are:
Douglas Gregor69678062009-06-29 22:39:32 +0000196 //
197 // 1. Template functions (names or types) have return types encoded, with
198 // the exceptions listed below.
199 // 2. Function types not appearing as part of a function name mangling,
200 // e.g. parameters, pointer types, etc., have return type encoded, with the
201 // exceptions listed below.
202 // 3. Non-template function names do not have return types encoded.
203 //
Mike Stumpb29542f2009-09-02 00:25:38 +0000204 // The exceptions mentioned in (1) and (2) above, for which the return type is
205 // never included, are
Douglas Gregor69678062009-06-29 22:39:32 +0000206 // 1. Constructors.
207 // 2. Destructors.
208 // 3. Conversion operator functions, e.g. operator int.
209 bool MangleReturnType = false;
210 if (FD->getPrimaryTemplate() &&
211 !(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
212 isa<CXXConversionDecl>(FD)))
213 MangleReturnType = true;
214 mangleBareFunctionType(FD->getType()->getAsFunctionType(), MangleReturnType);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000215}
216
217static bool isStdNamespace(const DeclContext *DC) {
218 if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit())
219 return false;
220
221 const NamespaceDecl *NS = cast<NamespaceDecl>(DC);
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000222 return NS->getOriginalNamespace()->getIdentifier()->isStr("std");
Douglas Gregor3556bc72009-02-13 00:10:09 +0000223}
224
225void CXXNameMangler::mangleName(const NamedDecl *ND) {
226 // <name> ::= <nested-name>
227 // ::= <unscoped-name>
228 // ::= <unscoped-template-name> <template-args>
229 // ::= <local-name> # See Scope Encoding below
230 //
231 // <unscoped-name> ::= <unqualified-name>
232 // ::= St <unqualified-name> # ::std::
233 if (ND->getDeclContext()->isTranslationUnit())
234 mangleUnqualifiedName(ND);
235 else if (isStdNamespace(ND->getDeclContext())) {
236 Out << "St";
237 mangleUnqualifiedName(ND);
Anders Carlssonfd8c56b2009-04-02 16:24:45 +0000238 } else if (isa<FunctionDecl>(ND->getDeclContext()))
239 mangleLocalName(ND);
240 else
Douglas Gregor3556bc72009-02-13 00:10:09 +0000241 mangleNestedName(ND);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000242}
243
Mike Stump58256412009-09-05 07:20:32 +0000244void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) {
Mike Stumpb29542f2009-09-02 00:25:38 +0000245 // <call-offset> ::= h <nv-offset> _
246 // ::= v <v-offset> _
247 // <nv-offset> ::= <offset number> # non-virtual base override
248 // <v-offset> ::= <offset nubmer> _ <virtual offset number>
249 // # virtual base override, with vcall offset
Mike Stump58256412009-09-05 07:20:32 +0000250 if (v == 0) {
Mike Stump28db39b2009-09-02 00:56:18 +0000251 Out << "h";
Mike Stumpb29542f2009-09-02 00:25:38 +0000252 if (nv < 0) {
253 Out << "n";
254 nv = -nv;
255 }
256 Out << nv;
257 } else {
Mike Stump28db39b2009-09-02 00:56:18 +0000258 Out << "v";
Mike Stumpb29542f2009-09-02 00:25:38 +0000259 if (nv < 0) {
260 Out << "n";
261 nv = -nv;
262 }
263 Out << nv;
264 Out << "_";
265 if (v < 0) {
266 Out << "n";
267 v = -v;
268 }
269 Out << v;
270 }
271 Out << "_";
Mike Stump28db39b2009-09-02 00:56:18 +0000272}
273
Mike Stump58256412009-09-05 07:20:32 +0000274void CXXNameMangler::mangleThunk(const NamedDecl *D, int64_t nv, int64_t v) {
Mike Stump28db39b2009-09-02 00:56:18 +0000275 // <special-name> ::= T <call-offset> <base encoding>
276 // # base is the nominal target function of thunk
277 Out << "_T";
Mike Stump58256412009-09-05 07:20:32 +0000278 mangleCalloffset(nv, v);
Mike Stump28db39b2009-09-02 00:56:18 +0000279 mangleName(D);
280}
281
282 void CXXNameMangler::mangleCovariantThunk(const NamedDecl *D,
Mike Stump58256412009-09-05 07:20:32 +0000283 int64_t nv_t, int64_t v_t,
Mike Stump28db39b2009-09-02 00:56:18 +0000284 int64_t nv_r, int64_t v_r) {
285 // <special-name> ::= Tc <call-offset> <call-offset> <base encoding>
286 // # base is the nominal target function of thunk
287 // # first call-offset is 'this' adjustment
288 // # second call-offset is result adjustment
289 Out << "_Tc";
Mike Stump58256412009-09-05 07:20:32 +0000290 mangleCalloffset(nv_t, v_t);
291 mangleCalloffset(nv_r, v_r);
Mike Stumpb29542f2009-09-02 00:25:38 +0000292 mangleName(D);
293}
294
Douglas Gregor3556bc72009-02-13 00:10:09 +0000295void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
296 // <unqualified-name> ::= <operator-name>
297 // ::= <ctor-dtor-name>
298 // ::= <source-name>
299 DeclarationName Name = ND->getDeclName();
300 switch (Name.getNameKind()) {
301 case DeclarationName::Identifier:
302 mangleSourceName(Name.getAsIdentifierInfo());
303 break;
304
305 case DeclarationName::ObjCZeroArgSelector:
306 case DeclarationName::ObjCOneArgSelector:
307 case DeclarationName::ObjCMultiArgSelector:
308 assert(false && "Can't mangle Objective-C selector names here!");
309 break;
310
311 case DeclarationName::CXXConstructorName:
Anders Carlsson4811c302009-04-17 01:58:57 +0000312 if (ND == Structor)
Mike Stumpb29542f2009-09-02 00:25:38 +0000313 // If the named decl is the C++ constructor we're mangling, use the type
314 // we were given.
Anders Carlsson4811c302009-04-17 01:58:57 +0000315 mangleCXXCtorType(static_cast<CXXCtorType>(StructorType));
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000316 else
317 // Otherwise, use the complete constructor name. This is relevant if a
318 // class with a constructor is declared within a constructor.
319 mangleCXXCtorType(Ctor_Complete);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000320 break;
321
322 case DeclarationName::CXXDestructorName:
Anders Carlsson4811c302009-04-17 01:58:57 +0000323 if (ND == Structor)
Mike Stumpb29542f2009-09-02 00:25:38 +0000324 // If the named decl is the C++ destructor we're mangling, use the type we
325 // were given.
Anders Carlsson4811c302009-04-17 01:58:57 +0000326 mangleCXXDtorType(static_cast<CXXDtorType>(StructorType));
327 else
328 // Otherwise, use the complete destructor name. This is relevant if a
329 // class with a destructor is declared within a destructor.
330 mangleCXXDtorType(Dtor_Complete);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000331 break;
332
333 case DeclarationName::CXXConversionFunctionName:
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000334 // <operator-name> ::= cv <type> # (cast)
335 Out << "cv";
336 mangleType(Context.getCanonicalType(Name.getCXXNameType()));
Douglas Gregor3556bc72009-02-13 00:10:09 +0000337 break;
338
339 case DeclarationName::CXXOperatorName:
340 mangleOperatorName(Name.getCXXOverloadedOperator(),
341 cast<FunctionDecl>(ND)->getNumParams());
342 break;
343
344 case DeclarationName::CXXUsingDirective:
345 assert(false && "Can't mangle a using directive name!");
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000346 break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000347 }
Douglas Gregor69678062009-06-29 22:39:32 +0000348
349 if (const FunctionDecl *Function = dyn_cast<FunctionDecl>(ND)) {
350 if (const TemplateArgumentList *TemplateArgs
351 = Function->getTemplateSpecializationArgs())
352 mangleTemplateArgumentList(*TemplateArgs);
353 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000354}
355
356void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
357 // <source-name> ::= <positive length number> <identifier>
358 // <number> ::= [n] <non-negative decimal integer>
359 // <identifier> ::= <unqualified source code identifier>
360 Out << II->getLength() << II->getName();
361}
362
363void CXXNameMangler::mangleNestedName(const NamedDecl *ND) {
364 // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
365 // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
366 // FIXME: no template support
367 Out << 'N';
368 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND))
369 mangleCVQualifiers(Method->getTypeQualifiers());
370 manglePrefix(ND->getDeclContext());
371 mangleUnqualifiedName(ND);
372 Out << 'E';
373}
374
Anders Carlssonfd8c56b2009-04-02 16:24:45 +0000375void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
376 // <local-name> := Z <function encoding> E <entity name> [<discriminator>]
377 // := Z <function encoding> E s [<discriminator>]
378 // <discriminator> := _ <non-negative number>
379 Out << 'Z';
380 mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext()));
381 Out << 'E';
382 mangleSourceName(ND->getIdentifier());
383}
384
Douglas Gregor3556bc72009-02-13 00:10:09 +0000385void CXXNameMangler::manglePrefix(const DeclContext *DC) {
386 // <prefix> ::= <prefix> <unqualified-name>
387 // ::= <template-prefix> <template-args>
388 // ::= <template-param>
389 // ::= # empty
390 // ::= <substitution>
391 // FIXME: We only handle mangling of namespaces and classes at the moment.
Anders Carlsson8c4c12a2009-04-01 00:42:16 +0000392 if (!DC->getParent()->isTranslationUnit())
393 manglePrefix(DC->getParent());
Douglas Gregor3556bc72009-02-13 00:10:09 +0000394
395 if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(DC))
396 mangleSourceName(Namespace->getIdentifier());
Anders Carlssonb1008e42009-05-15 16:09:15 +0000397 else if (const RecordDecl *Record = dyn_cast<RecordDecl>(DC)) {
398 if (const ClassTemplateSpecializationDecl *D =
399 dyn_cast<ClassTemplateSpecializationDecl>(Record)) {
400 mangleType(QualType(D->getTypeForDecl(), 0));
401 } else
402 mangleSourceName(Record->getIdentifier());
403 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000404}
405
406void
407CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) {
408 switch (OO) {
Sebastian Redlbd261962009-04-16 17:51:27 +0000409 // <operator-name> ::= nw # new
Douglas Gregor3556bc72009-02-13 00:10:09 +0000410 case OO_New: Out << "nw"; break;
411 // ::= na # new[]
412 case OO_Array_New: Out << "na"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000413 // ::= dl # delete
Douglas Gregor3556bc72009-02-13 00:10:09 +0000414 case OO_Delete: Out << "dl"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000415 // ::= da # delete[]
Douglas Gregor3556bc72009-02-13 00:10:09 +0000416 case OO_Array_Delete: Out << "da"; break;
417 // ::= ps # + (unary)
418 // ::= pl # +
419 case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000420 // ::= ng # - (unary)
421 // ::= mi # -
Douglas Gregor3556bc72009-02-13 00:10:09 +0000422 case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000423 // ::= ad # & (unary)
424 // ::= an # &
Douglas Gregor3556bc72009-02-13 00:10:09 +0000425 case OO_Amp: Out << (Arity == 1? "ad" : "an"); break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000426 // ::= de # * (unary)
427 // ::= ml # *
Douglas Gregor3556bc72009-02-13 00:10:09 +0000428 case OO_Star: Out << (Arity == 1? "de" : "ml"); break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000429 // ::= co # ~
Douglas Gregor3556bc72009-02-13 00:10:09 +0000430 case OO_Tilde: Out << "co"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000431 // ::= dv # /
Douglas Gregor3556bc72009-02-13 00:10:09 +0000432 case OO_Slash: Out << "dv"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000433 // ::= rm # %
Douglas Gregor3556bc72009-02-13 00:10:09 +0000434 case OO_Percent: Out << "rm"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000435 // ::= or # |
436 case OO_Pipe: Out << "or"; break;
437 // ::= eo # ^
Douglas Gregor3556bc72009-02-13 00:10:09 +0000438 case OO_Caret: Out << "eo"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000439 // ::= aS # =
Douglas Gregor3556bc72009-02-13 00:10:09 +0000440 case OO_Equal: Out << "aS"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000441 // ::= pL # +=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000442 case OO_PlusEqual: Out << "pL"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000443 // ::= mI # -=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000444 case OO_MinusEqual: Out << "mI"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000445 // ::= mL # *=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000446 case OO_StarEqual: Out << "mL"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000447 // ::= dV # /=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000448 case OO_SlashEqual: Out << "dV"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000449 // ::= rM # %=
450 case OO_PercentEqual: Out << "rM"; break;
451 // ::= aN # &=
452 case OO_AmpEqual: Out << "aN"; break;
453 // ::= oR # |=
454 case OO_PipeEqual: Out << "oR"; break;
455 // ::= eO # ^=
456 case OO_CaretEqual: Out << "eO"; break;
457 // ::= ls # <<
Douglas Gregor3556bc72009-02-13 00:10:09 +0000458 case OO_LessLess: Out << "ls"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000459 // ::= rs # >>
460 case OO_GreaterGreater: Out << "rs"; break;
461 // ::= lS # <<=
462 case OO_LessLessEqual: Out << "lS"; break;
463 // ::= rS # >>=
464 case OO_GreaterGreaterEqual: Out << "rS"; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000465 // ::= eq # ==
466 case OO_EqualEqual: Out << "eq"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000467 // ::= ne # !=
468 case OO_ExclaimEqual: Out << "ne"; break;
469 // ::= lt # <
Douglas Gregor3556bc72009-02-13 00:10:09 +0000470 case OO_Less: Out << "lt"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000471 // ::= gt # >
Douglas Gregor3556bc72009-02-13 00:10:09 +0000472 case OO_Greater: Out << "gt"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000473 // ::= le # <=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000474 case OO_LessEqual: Out << "le"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000475 // ::= ge # >=
Douglas Gregor3556bc72009-02-13 00:10:09 +0000476 case OO_GreaterEqual: Out << "ge"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000477 // ::= nt # !
Douglas Gregor3556bc72009-02-13 00:10:09 +0000478 case OO_Exclaim: Out << "nt"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000479 // ::= aa # &&
Douglas Gregor3556bc72009-02-13 00:10:09 +0000480 case OO_AmpAmp: Out << "aa"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000481 // ::= oo # ||
482 case OO_PipePipe: Out << "oo"; break;
483 // ::= pp # ++
484 case OO_PlusPlus: Out << "pp"; break;
485 // ::= mm # --
Douglas Gregor3556bc72009-02-13 00:10:09 +0000486 case OO_MinusMinus: Out << "mm"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000487 // ::= cm # ,
488 case OO_Comma: Out << "cm"; break;
489 // ::= pm # ->*
Douglas Gregor3556bc72009-02-13 00:10:09 +0000490 case OO_ArrowStar: Out << "pm"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000491 // ::= pt # ->
Douglas Gregor3556bc72009-02-13 00:10:09 +0000492 case OO_Arrow: Out << "pt"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000493 // ::= cl # ()
Douglas Gregor3556bc72009-02-13 00:10:09 +0000494 case OO_Call: Out << "cl"; break;
Sebastian Redlbd261962009-04-16 17:51:27 +0000495 // ::= ix # []
Douglas Gregor3556bc72009-02-13 00:10:09 +0000496 case OO_Subscript: Out << "ix"; break;
497 // UNSUPPORTED: ::= qu # ?
498
Sebastian Redlbd261962009-04-16 17:51:27 +0000499 case OO_None:
500 case OO_Conditional:
Douglas Gregor3556bc72009-02-13 00:10:09 +0000501 case NUM_OVERLOADED_OPERATORS:
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000502 assert(false && "Not an overloaded operator");
Douglas Gregor3556bc72009-02-13 00:10:09 +0000503 break;
504 }
505}
506
507void CXXNameMangler::mangleCVQualifiers(unsigned Quals) {
508 // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
509 if (Quals & QualType::Restrict)
510 Out << 'r';
511 if (Quals & QualType::Volatile)
512 Out << 'V';
513 if (Quals & QualType::Const)
514 Out << 'K';
515}
516
517void CXXNameMangler::mangleType(QualType T) {
Anders Carlssonfdaed4c2009-03-10 17:07:44 +0000518 // Only operate on the canonical type!
519 T = Context.getCanonicalType(T);
520
Douglas Gregor3556bc72009-02-13 00:10:09 +0000521 // FIXME: Should we have a TypeNodes.def to make this easier? (YES!)
522
523 // <type> ::= <CV-qualifiers> <type>
524 mangleCVQualifiers(T.getCVRQualifiers());
525
526 // ::= <builtin-type>
Anders Carlssonfdaed4c2009-03-10 17:07:44 +0000527 if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
Douglas Gregor3556bc72009-02-13 00:10:09 +0000528 mangleType(BT);
529 // ::= <function-type>
530 else if (const FunctionType *FT = dyn_cast<FunctionType>(T.getTypePtr()))
531 mangleType(FT);
532 // ::= <class-enum-type>
533 else if (const TagType *TT = dyn_cast<TagType>(T.getTypePtr()))
534 mangleType(TT);
535 // ::= <array-type>
536 else if (const ArrayType *AT = dyn_cast<ArrayType>(T.getTypePtr()))
537 mangleType(AT);
538 // ::= <pointer-to-member-type>
539 else if (const MemberPointerType *MPT
540 = dyn_cast<MemberPointerType>(T.getTypePtr()))
541 mangleType(MPT);
542 // ::= <template-param>
543 else if (const TemplateTypeParmType *TypeParm
544 = dyn_cast<TemplateTypeParmType>(T.getTypePtr()))
545 mangleType(TypeParm);
546 // FIXME: ::= <template-template-param> <template-args>
547 // FIXME: ::= <substitution> # See Compression below
548 // ::= P <type> # pointer-to
549 else if (const PointerType *PT = dyn_cast<PointerType>(T.getTypePtr())) {
550 Out << 'P';
551 mangleType(PT->getPointeeType());
552 }
Steve Naroff329ec222009-07-10 23:34:53 +0000553 else if (const ObjCObjectPointerType *PT =
554 dyn_cast<ObjCObjectPointerType>(T.getTypePtr())) {
555 Out << 'P';
556 mangleType(PT->getPointeeType());
557 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000558 // ::= R <type> # reference-to
Sebastian Redlce6fff02009-03-16 23:22:08 +0000559 else if (const LValueReferenceType *RT =
560 dyn_cast<LValueReferenceType>(T.getTypePtr())) {
Douglas Gregor3556bc72009-02-13 00:10:09 +0000561 Out << 'R';
562 mangleType(RT->getPointeeType());
563 }
Sebastian Redlce6fff02009-03-16 23:22:08 +0000564 // ::= O <type> # rvalue reference-to (C++0x)
565 else if (const RValueReferenceType *RT =
566 dyn_cast<RValueReferenceType>(T.getTypePtr())) {
567 Out << 'O';
568 mangleType(RT->getPointeeType());
569 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000570 // ::= C <type> # complex pair (C 2000)
571 else if (const ComplexType *CT = dyn_cast<ComplexType>(T.getTypePtr())) {
572 Out << 'C';
573 mangleType(CT->getElementType());
574 } else if (const VectorType *VT = dyn_cast<VectorType>(T.getTypePtr())) {
575 // GNU extension: vector types
576 Out << "U8__vector";
577 mangleType(VT->getElementType());
Anders Carlssonfae45862009-03-07 22:03:21 +0000578 } else if (const ObjCInterfaceType *IT =
579 dyn_cast<ObjCInterfaceType>(T.getTypePtr())) {
580 mangleType(IT);
John McCallfbec6a92009-09-05 06:31:47 +0000581 } else if (const ElaboratedType *ET =
582 dyn_cast<ElaboratedType>(T.getTypePtr())) {
583 mangleType(ET->getUnderlyingType());
Anders Carlssonfdaed4c2009-03-10 17:07:44 +0000584 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000585 // FIXME: ::= G <type> # imaginary (C 2000)
586 // FIXME: ::= U <source-name> <type> # vendor extended type qualifier
587 else
588 assert(false && "Cannot mangle unknown type");
589}
590
591void CXXNameMangler::mangleType(const BuiltinType *T) {
592 // <builtin-type> ::= v # void
593 // ::= w # wchar_t
594 // ::= b # bool
595 // ::= c # char
596 // ::= a # signed char
597 // ::= h # unsigned char
598 // ::= s # short
599 // ::= t # unsigned short
600 // ::= i # int
601 // ::= j # unsigned int
602 // ::= l # long
603 // ::= m # unsigned long
604 // ::= x # long long, __int64
605 // ::= y # unsigned long long, __int64
606 // ::= n # __int128
607 // UNSUPPORTED: ::= o # unsigned __int128
608 // ::= f # float
609 // ::= d # double
610 // ::= e # long double, __float80
611 // UNSUPPORTED: ::= g # __float128
Douglas Gregor3556bc72009-02-13 00:10:09 +0000612 // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits)
613 // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
614 // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
615 // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits)
Alisdair Meredith2bcacb62009-07-14 06:30:34 +0000616 // ::= Di # char32_t
617 // ::= Ds # char16_t
Douglas Gregor3556bc72009-02-13 00:10:09 +0000618 // ::= u <source-name> # vendor extended type
Sebastian Redl5d0ead72009-05-10 18:38:11 +0000619 // From our point of view, std::nullptr_t is a builtin, but as far as mangling
620 // is concerned, it's a type called std::nullptr_t.
Douglas Gregor3556bc72009-02-13 00:10:09 +0000621 switch (T->getKind()) {
622 case BuiltinType::Void: Out << 'v'; break;
623 case BuiltinType::Bool: Out << 'b'; break;
624 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break;
625 case BuiltinType::UChar: Out << 'h'; break;
626 case BuiltinType::UShort: Out << 't'; break;
627 case BuiltinType::UInt: Out << 'j'; break;
628 case BuiltinType::ULong: Out << 'm'; break;
629 case BuiltinType::ULongLong: Out << 'y'; break;
Chris Lattner6cc7e412009-04-30 02:43:43 +0000630 case BuiltinType::UInt128: Out << 'o'; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000631 case BuiltinType::SChar: Out << 'a'; break;
632 case BuiltinType::WChar: Out << 'w'; break;
Alisdair Meredith2bcacb62009-07-14 06:30:34 +0000633 case BuiltinType::Char16: Out << "Ds"; break;
634 case BuiltinType::Char32: Out << "Di"; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000635 case BuiltinType::Short: Out << 's'; break;
636 case BuiltinType::Int: Out << 'i'; break;
637 case BuiltinType::Long: Out << 'l'; break;
638 case BuiltinType::LongLong: Out << 'x'; break;
Chris Lattner6cc7e412009-04-30 02:43:43 +0000639 case BuiltinType::Int128: Out << 'n'; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000640 case BuiltinType::Float: Out << 'f'; break;
641 case BuiltinType::Double: Out << 'd'; break;
642 case BuiltinType::LongDouble: Out << 'e'; break;
Sebastian Redl5d0ead72009-05-10 18:38:11 +0000643 case BuiltinType::NullPtr: Out << "St9nullptr_t"; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000644
645 case BuiltinType::Overload:
646 case BuiltinType::Dependent:
647 assert(false &&
648 "Overloaded and dependent types shouldn't get to name mangling");
649 break;
Anders Carlsson4a8498c2009-06-26 18:41:36 +0000650 case BuiltinType::UndeducedAuto:
651 assert(0 && "Should not see undeduced auto here");
652 break;
Steve Naroff0b60cf82009-07-22 17:14:51 +0000653 case BuiltinType::ObjCId: Out << "11objc_object"; break;
654 case BuiltinType::ObjCClass: Out << "10objc_class"; break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000655 }
656}
657
658void CXXNameMangler::mangleType(const FunctionType *T) {
659 // <function-type> ::= F [Y] <bare-function-type> E
660 Out << 'F';
Mike Stumpba2cb0e2009-05-16 07:57:57 +0000661 // FIXME: We don't have enough information in the AST to produce the 'Y'
662 // encoding for extern "C" function types.
Douglas Gregor3556bc72009-02-13 00:10:09 +0000663 mangleBareFunctionType(T, /*MangleReturnType=*/true);
664 Out << 'E';
665}
666
667void CXXNameMangler::mangleBareFunctionType(const FunctionType *T,
668 bool MangleReturnType) {
669 // <bare-function-type> ::= <signature type>+
670 if (MangleReturnType)
671 mangleType(T->getResultType());
672
Douglas Gregor4fa58902009-02-26 23:50:07 +0000673 const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000674 assert(Proto && "Can't mangle K&R function prototypes");
675
Anders Carlsson51e65522009-04-01 00:15:23 +0000676 if (Proto->getNumArgs() == 0) {
677 Out << 'v';
678 return;
679 }
680
Douglas Gregor4fa58902009-02-26 23:50:07 +0000681 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
Douglas Gregor3556bc72009-02-13 00:10:09 +0000682 ArgEnd = Proto->arg_type_end();
683 Arg != ArgEnd; ++Arg)
684 mangleType(*Arg);
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000685
686 // <builtin-type> ::= z # ellipsis
687 if (Proto->isVariadic())
688 Out << 'z';
Douglas Gregor3556bc72009-02-13 00:10:09 +0000689}
690
691void CXXNameMangler::mangleType(const TagType *T) {
692 // <class-enum-type> ::= <name>
Anders Carlssonfdaed4c2009-03-10 17:07:44 +0000693
694 if (!T->getDecl()->getIdentifier())
695 mangleName(T->getDecl()->getTypedefForAnonDecl());
696 else
697 mangleName(T->getDecl());
Anders Carlssonb1008e42009-05-15 16:09:15 +0000698
Mike Stumpb29542f2009-09-02 00:25:38 +0000699 // If this is a class template specialization, mangle the template arguments.
Anders Carlssonb1008e42009-05-15 16:09:15 +0000700 if (ClassTemplateSpecializationDecl *Spec
701 = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
702 mangleTemplateArgumentList(Spec->getTemplateArgs());
Douglas Gregor3556bc72009-02-13 00:10:09 +0000703}
704
705void CXXNameMangler::mangleType(const ArrayType *T) {
706 // <array-type> ::= A <positive dimension number> _ <element type>
707 // ::= A [<dimension expression>] _ <element type>
708 Out << 'A';
709 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T))
710 Out << CAT->getSize();
711 else if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(T))
712 mangleExpression(VAT->getSizeExpr());
713 else if (const DependentSizedArrayType *DSAT
714 = dyn_cast<DependentSizedArrayType>(T))
715 mangleExpression(DSAT->getSizeExpr());
716
717 Out << '_';
718 mangleType(T->getElementType());
719}
720
721void CXXNameMangler::mangleType(const MemberPointerType *T) {
722 // <pointer-to-member-type> ::= M <class type> <member type>
723 Out << 'M';
724 mangleType(QualType(T->getClass(), 0));
Anders Carlsson0b17ef42009-05-17 17:41:20 +0000725 QualType PointeeType = T->getPointeeType();
726 if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
727 mangleCVQualifiers(FPT->getTypeQuals());
728 mangleType(FPT);
729 } else
730 mangleType(PointeeType);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000731}
732
733void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
734 // <template-param> ::= T_ # first template parameter
735 // ::= T <parameter-2 non-negative number> _
736 if (T->getIndex() == 0)
737 Out << "T_";
738 else
739 Out << 'T' << (T->getIndex() - 1) << '_';
740}
741
Anders Carlssonfae45862009-03-07 22:03:21 +0000742void CXXNameMangler::mangleType(const ObjCInterfaceType *T) {
743 mangleSourceName(T->getDecl()->getIdentifier());
744}
745
Douglas Gregor3556bc72009-02-13 00:10:09 +0000746void CXXNameMangler::mangleExpression(Expr *E) {
747 assert(false && "Cannot mangle expressions yet");
748}
749
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000750void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) {
751 // <ctor-dtor-name> ::= C1 # complete object constructor
752 // ::= C2 # base object constructor
753 // ::= C3 # complete object allocating constructor
754 //
755 switch (T) {
756 case Ctor_Complete:
757 Out << "C1";
758 break;
759 case Ctor_Base:
760 Out << "C2";
761 break;
762 case Ctor_CompleteAllocating:
763 Out << "C3";
764 break;
765 }
766}
767
Anders Carlsson4811c302009-04-17 01:58:57 +0000768void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
769 // <ctor-dtor-name> ::= D0 # deleting destructor
770 // ::= D1 # complete object destructor
771 // ::= D2 # base object destructor
772 //
773 switch (T) {
774 case Dtor_Deleting:
775 Out << "D0";
776 break;
777 case Dtor_Complete:
778 Out << "D1";
779 break;
780 case Dtor_Base:
781 Out << "D2";
782 break;
783 }
784}
785
Anders Carlssonb1008e42009-05-15 16:09:15 +0000786void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) {
787 // <template-args> ::= I <template-arg>+ E
788 Out << "I";
789
790 for (unsigned i = 0, e = L.size(); i != e; ++i) {
791 const TemplateArgument &A = L[i];
792
793 mangleTemplateArgument(A);
794 }
795
796 Out << "E";
797}
798
799void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) {
800 // <template-arg> ::= <type> # type or template
801 // ::= X <expression> E # expression
802 // ::= <expr-primary> # simple expressions
803 // ::= I <template-arg>* E # argument pack
804 // ::= sp <expression> # pack expansion of (C++0x)
805 switch (A.getKind()) {
806 default:
807 assert(0 && "Unknown template argument kind!");
808 case TemplateArgument::Type:
809 mangleType(A.getAsType());
810 break;
811 case TemplateArgument::Integral:
812 // <expr-primary> ::= L <type> <value number> E # integer literal
813
814 Out << 'L';
815
816 mangleType(A.getIntegralType());
817
818 const llvm::APSInt *Integral = A.getAsIntegral();
819 if (A.getIntegralType()->isBooleanType()) {
820 // Boolean values are encoded as 0/1.
821 Out << (Integral->getBoolValue() ? '1' : '0');
822 } else {
823 if (Integral->isNegative())
824 Out << 'n';
825 Integral->abs().print(Out, false);
826 }
827
828 Out << 'E';
829 break;
830 }
831}
832
Douglas Gregor3556bc72009-02-13 00:10:09 +0000833namespace clang {
Mike Stumpb29542f2009-09-02 00:25:38 +0000834 /// \brief Mangles the name of the declaration D and emits that name to the
835 /// given output stream.
Douglas Gregor3556bc72009-02-13 00:10:09 +0000836 ///
Mike Stumpb29542f2009-09-02 00:25:38 +0000837 /// If the declaration D requires a mangled name, this routine will emit that
838 /// mangled name to \p os and return true. Otherwise, \p os will be unchanged
839 /// and this routine will return false. In this case, the caller should just
840 /// emit the identifier of the declaration (\c D->getIdentifier()) as its
841 /// name.
Douglas Gregor3556bc72009-02-13 00:10:09 +0000842 bool mangleName(const NamedDecl *D, ASTContext &Context,
843 llvm::raw_ostream &os) {
Anders Carlsson7bb19882009-05-03 16:51:04 +0000844 assert(!isa<CXXConstructorDecl>(D) &&
845 "Use mangleCXXCtor for constructor decls!");
846 assert(!isa<CXXDestructorDecl>(D) &&
847 "Use mangleCXXDtor for destructor decls!");
848
Douglas Gregor3556bc72009-02-13 00:10:09 +0000849 CXXNameMangler Mangler(Context, os);
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000850 if (!Mangler.mangle(D))
851 return false;
852
853 os.flush();
854 return true;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000855 }
Anders Carlsson53f73bc2009-04-13 18:02:10 +0000856
Mike Stumpb29542f2009-09-02 00:25:38 +0000857 /// \brief Mangles the a thunk with the offset n for the declaration D and
858 /// emits that name to the given output stream.
Mike Stump58256412009-09-05 07:20:32 +0000859 void mangleThunk(const NamedDecl *D, int64_t nv, int64_t v,
Mike Stumpeeba4ad2009-09-02 00:28:47 +0000860 ASTContext &Context, llvm::raw_ostream &os) {
Mike Stumpb29542f2009-09-02 00:25:38 +0000861 // FIXME: Hum, we might have to thunk these, fix.
862 assert(!isa<CXXConstructorDecl>(D) &&
863 "Use mangleCXXCtor for constructor decls!");
864 assert(!isa<CXXDestructorDecl>(D) &&
865 "Use mangleCXXDtor for destructor decls!");
866
867 CXXNameMangler Mangler(Context, os);
Mike Stump58256412009-09-05 07:20:32 +0000868 Mangler.mangleThunk(D, nv, v);
Mike Stumpb29542f2009-09-02 00:25:38 +0000869 os.flush();
870 }
871
Mike Stump28db39b2009-09-02 00:56:18 +0000872 /// \brief Mangles the a covariant thunk for the declaration D and emits that
873 /// name to the given output stream.
Mike Stump58256412009-09-05 07:20:32 +0000874 void mangleCovariantThunk(const NamedDecl *D, int64_t nv_t, int64_t v_t,
875 int64_t nv_r, int64_t v_r, ASTContext &Context,
Mike Stump28db39b2009-09-02 00:56:18 +0000876 llvm::raw_ostream &os) {
877 // FIXME: Hum, we might have to thunk these, fix.
878 assert(!isa<CXXConstructorDecl>(D) &&
879 "Use mangleCXXCtor for constructor decls!");
880 assert(!isa<CXXDestructorDecl>(D) &&
881 "Use mangleCXXDtor for destructor decls!");
882
883 CXXNameMangler Mangler(Context, os);
Mike Stump58256412009-09-05 07:20:32 +0000884 Mangler.mangleCovariantThunk(D, nv_t, v_t, nv_r, v_r);
Mike Stump28db39b2009-09-02 00:56:18 +0000885 os.flush();
886 }
887
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000888 /// mangleGuardVariable - Returns the mangled name for a guard variable
889 /// for the passed in VarDecl.
Anders Carlsson53f73bc2009-04-13 18:02:10 +0000890 void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
891 llvm::raw_ostream &os) {
892 CXXNameMangler Mangler(Context, os);
893 Mangler.mangleGuardVariable(D);
894
895 os.flush();
896 }
Anders Carlsson6b6adf22009-04-15 05:36:58 +0000897
898 void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
899 ASTContext &Context, llvm::raw_ostream &os) {
900 CXXNameMangler Mangler(Context, os);
901 Mangler.mangleCXXCtor(D, Type);
902
903 os.flush();
904 }
Anders Carlsson4811c302009-04-17 01:58:57 +0000905
906 void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
907 ASTContext &Context, llvm::raw_ostream &os) {
908 CXXNameMangler Mangler(Context, os);
909 Mangler.mangleCXXDtor(D, Type);
910
911 os.flush();
912 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000913
Mike Stump7e8c9932009-07-31 18:25:34 +0000914 void mangleCXXVtable(QualType Type, ASTContext &Context,
915 llvm::raw_ostream &os) {
916 CXXNameMangler Mangler(Context, os);
917 Mangler.mangleCXXVtable(Type);
918
919 os.flush();
920 }
Mike Stump00df7d32009-07-31 23:15:31 +0000921
922 void mangleCXXRtti(QualType Type, ASTContext &Context,
923 llvm::raw_ostream &os) {
924 CXXNameMangler Mangler(Context, os);
925 Mangler.mangleCXXRtti(Type);
926
927 os.flush();
928 }
Mike Stump7e8c9932009-07-31 18:25:34 +0000929}