blob: 34c88fbba5ab41a28739f4326d681a76f5edcd4a [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"
Douglas Gregor3c3c4542009-02-18 23:53:56 +000022#include "clang/Basic/SourceManager.h"
Douglas Gregor3556bc72009-02-13 00:10:09 +000023#include "llvm/Support/Compiler.h"
24#include "llvm/Support/raw_ostream.h"
25using namespace clang;
26
27namespace {
28 class VISIBILITY_HIDDEN CXXNameMangler {
29 ASTContext &Context;
30 llvm::raw_ostream &Out;
31
32 public:
33 CXXNameMangler(ASTContext &C, llvm::raw_ostream &os)
34 : Context(C), Out(os) { }
35
36 bool mangle(const NamedDecl *D);
37 void mangleFunctionEncoding(const FunctionDecl *FD);
38 void mangleName(const NamedDecl *ND);
39 void mangleUnqualifiedName(const NamedDecl *ND);
40 void mangleSourceName(const IdentifierInfo *II);
41 void mangleNestedName(const NamedDecl *ND);
42 void manglePrefix(const DeclContext *DC);
43 void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
44 void mangleCVQualifiers(unsigned Quals);
45 void mangleType(QualType T);
Anders Carlssonc34a6842009-03-07 23:57:03 +000046 void mangleType(const TypedefType *T);
Douglas Gregor3556bc72009-02-13 00:10:09 +000047 void mangleType(const BuiltinType *T);
48 void mangleType(const FunctionType *T);
49 void mangleBareFunctionType(const FunctionType *T, bool MangleReturnType);
50 void mangleType(const TagType *T);
51 void mangleType(const ArrayType *T);
52 void mangleType(const MemberPointerType *T);
53 void mangleType(const TemplateTypeParmType *T);
Anders Carlssonfae45862009-03-07 22:03:21 +000054 void mangleType(const ObjCInterfaceType *T);
Douglas Gregor3556bc72009-02-13 00:10:09 +000055 void mangleExpression(Expr *E);
56 };
57}
58
59
60bool CXXNameMangler::mangle(const NamedDecl *D) {
61 // <mangled-name> ::= _Z <encoding>
62 // ::= <data name>
63 // ::= <special-name>
64
65 // FIXME: Actually use a visitor to decode these?
66 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
67 bool RequiresMangling = false;
Douglas Gregor3c3c4542009-02-18 23:53:56 +000068 // Clang's "overloadable" attribute extension to C/C++ implies
69 // name mangling (always).
Daniel Dunbar455cc332009-02-20 23:09:27 +000070 if (FD->getAttr<OverloadableAttr>())
Douglas Gregor3556bc72009-02-13 00:10:09 +000071 RequiresMangling = true;
Daniel Dunbar455cc332009-02-20 23:09:27 +000072 // No mangled in an "implicit extern C" header.
73 else if (Context.getSourceManager().getFileCharacteristic(FD->getLocation())
74 == SrcMgr::C_ExternCSystem)
75 RequiresMangling = false;
Douglas Gregoraf682022009-02-24 01:23:02 +000076 else if (Context.getLangOptions().CPlusPlus && !FD->isMain()) {
Douglas Gregor3c3c4542009-02-18 23:53:56 +000077 // C++ requires name mangling, unless we're in a C linkage
78 // specification.
Douglas Gregor3556bc72009-02-13 00:10:09 +000079 RequiresMangling = true;
Douglas Gregor3c3c4542009-02-18 23:53:56 +000080
81 for (const DeclContext *DC = FD->getDeclContext();
82 !DC->isTranslationUnit(); DC = DC->getParent()) {
83 if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) {
84 // extern "C" functions don't use name mangling
85 if (Linkage->getLanguage() == LinkageSpecDecl::lang_c)
86 RequiresMangling = false;
87 break;
88 }
89 }
Douglas Gregor3556bc72009-02-13 00:10:09 +000090 }
91
92 if (RequiresMangling) {
93 Out << "_Z";
94 mangleFunctionEncoding(FD);
95 return true;
96 }
97 }
98
99 return false;
100}
101
102void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
103 // <encoding> ::= <function name> <bare-function-type>
104 mangleName(FD);
105 mangleBareFunctionType(FD->getType()->getAsFunctionType(), false);
106}
107
108static bool isStdNamespace(const DeclContext *DC) {
109 if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit())
110 return false;
111
112 const NamespaceDecl *NS = cast<NamespaceDecl>(DC);
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000113 return NS->getOriginalNamespace()->getIdentifier()->isStr("std");
Douglas Gregor3556bc72009-02-13 00:10:09 +0000114}
115
116void CXXNameMangler::mangleName(const NamedDecl *ND) {
117 // <name> ::= <nested-name>
118 // ::= <unscoped-name>
119 // ::= <unscoped-template-name> <template-args>
120 // ::= <local-name> # See Scope Encoding below
121 //
122 // <unscoped-name> ::= <unqualified-name>
123 // ::= St <unqualified-name> # ::std::
124 if (ND->getDeclContext()->isTranslationUnit())
125 mangleUnqualifiedName(ND);
126 else if (isStdNamespace(ND->getDeclContext())) {
127 Out << "St";
128 mangleUnqualifiedName(ND);
129 } else {
130 mangleNestedName(ND);
131 }
132}
133
134void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
135 // <unqualified-name> ::= <operator-name>
136 // ::= <ctor-dtor-name>
137 // ::= <source-name>
138 DeclarationName Name = ND->getDeclName();
139 switch (Name.getNameKind()) {
140 case DeclarationName::Identifier:
141 mangleSourceName(Name.getAsIdentifierInfo());
142 break;
143
144 case DeclarationName::ObjCZeroArgSelector:
145 case DeclarationName::ObjCOneArgSelector:
146 case DeclarationName::ObjCMultiArgSelector:
147 assert(false && "Can't mangle Objective-C selector names here!");
148 break;
149
150 case DeclarationName::CXXConstructorName:
151 // <ctor-dtor-name> ::= C1 # complete object constructor
152 // ::= C2 # base object constructor
153 // ::= C3 # complete object allocating constructor
154 //
155 // FIXME: We don't even have all of these constructors
156 // in the AST yet.
157 Out << "C1";
158 break;
159
160 case DeclarationName::CXXDestructorName:
161 // <ctor-dtor-name> ::= D0 # deleting destructor
162 // ::= D1 # complete object destructor
163 // ::= D2 # base object destructor
164 //
165 // FIXME: We don't even have all of these destructors in the AST
166 // yet.
167 Out << "D0";
168 break;
169
170 case DeclarationName::CXXConversionFunctionName:
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000171 // <operator-name> ::= cv <type> # (cast)
172 Out << "cv";
173 mangleType(Context.getCanonicalType(Name.getCXXNameType()));
Douglas Gregor3556bc72009-02-13 00:10:09 +0000174 break;
175
176 case DeclarationName::CXXOperatorName:
177 mangleOperatorName(Name.getCXXOverloadedOperator(),
178 cast<FunctionDecl>(ND)->getNumParams());
179 break;
180
181 case DeclarationName::CXXUsingDirective:
182 assert(false && "Can't mangle a using directive name!");
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000183 break;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000184 }
185}
186
187void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
188 // <source-name> ::= <positive length number> <identifier>
189 // <number> ::= [n] <non-negative decimal integer>
190 // <identifier> ::= <unqualified source code identifier>
191 Out << II->getLength() << II->getName();
192}
193
194void CXXNameMangler::mangleNestedName(const NamedDecl *ND) {
195 // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E
196 // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
197 // FIXME: no template support
198 Out << 'N';
199 if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND))
200 mangleCVQualifiers(Method->getTypeQualifiers());
201 manglePrefix(ND->getDeclContext());
202 mangleUnqualifiedName(ND);
203 Out << 'E';
204}
205
206void CXXNameMangler::manglePrefix(const DeclContext *DC) {
207 // <prefix> ::= <prefix> <unqualified-name>
208 // ::= <template-prefix> <template-args>
209 // ::= <template-param>
210 // ::= # empty
211 // ::= <substitution>
212 // FIXME: We only handle mangling of namespaces and classes at the moment.
213 if (DC->getParent() != DC)
214 manglePrefix(DC);
215
216 if (const NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(DC))
217 mangleSourceName(Namespace->getIdentifier());
218 else if (const RecordDecl *Record = dyn_cast<RecordDecl>(DC))
219 mangleSourceName(Record->getIdentifier());
220}
221
222void
223CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) {
224 switch (OO) {
225 // <operator-name> ::= nw # new
226 case OO_New: Out << "nw"; break;
227 // ::= na # new[]
228 case OO_Array_New: Out << "na"; break;
229 // ::= dl # delete
230 case OO_Delete: Out << "dl"; break;
231 // ::= da # delete[]
232 case OO_Array_Delete: Out << "da"; break;
233 // ::= ps # + (unary)
234 // ::= pl # +
235 case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break;
236 // ::= ng # - (unary)
237 // ::= mi # -
238 case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break;
239 // ::= ad # & (unary)
240 // ::= an # &
241 case OO_Amp: Out << (Arity == 1? "ad" : "an"); break;
242 // ::= de # * (unary)
243 // ::= ml # *
244 case OO_Star: Out << (Arity == 1? "de" : "ml"); break;
245 // ::= co # ~
246 case OO_Tilde: Out << "co"; break;
247 // ::= dv # /
248 case OO_Slash: Out << "dv"; break;
249 // ::= rm # %
250 case OO_Percent: Out << "rm"; break;
251 // ::= or # |
252 case OO_Pipe: Out << "or"; break;
253 // ::= eo # ^
254 case OO_Caret: Out << "eo"; break;
255 // ::= aS # =
256 case OO_Equal: Out << "aS"; break;
257 // ::= pL # +=
258 case OO_PlusEqual: Out << "pL"; break;
259 // ::= mI # -=
260 case OO_MinusEqual: Out << "mI"; break;
261 // ::= mL # *=
262 case OO_StarEqual: Out << "mL"; break;
263 // ::= dV # /=
264 case OO_SlashEqual: Out << "dV"; break;
265 // ::= rM # %=
266 case OO_PercentEqual: Out << "rM"; break;
267 // ::= aN # &=
268 case OO_AmpEqual: Out << "aN"; break;
269 // ::= oR # |=
270 case OO_PipeEqual: Out << "oR"; break;
271 // ::= eO # ^=
272 case OO_CaretEqual: Out << "eO"; break;
273 // ::= ls # <<
274 case OO_LessLess: Out << "ls"; break;
275 // ::= rs # >>
276 case OO_GreaterGreater: Out << "rs"; break;
277 // ::= lS # <<=
278 case OO_LessLessEqual: Out << "lS"; break;
279 // ::= rS # >>=
280 case OO_GreaterGreaterEqual: Out << "rS"; break;
281 // ::= eq # ==
282 case OO_EqualEqual: Out << "eq"; break;
283 // ::= ne # !=
284 case OO_ExclaimEqual: Out << "ne"; break;
285 // ::= lt # <
286 case OO_Less: Out << "lt"; break;
287 // ::= gt # >
288 case OO_Greater: Out << "gt"; break;
289 // ::= le # <=
290 case OO_LessEqual: Out << "le"; break;
291 // ::= ge # >=
292 case OO_GreaterEqual: Out << "ge"; break;
293 // ::= nt # !
294 case OO_Exclaim: Out << "nt"; break;
295 // ::= aa # &&
296 case OO_AmpAmp: Out << "aa"; break;
297 // ::= oo # ||
298 case OO_PipePipe: Out << "oo"; break;
299 // ::= pp # ++
300 case OO_PlusPlus: Out << "pp"; break;
301 // ::= mm # --
302 case OO_MinusMinus: Out << "mm"; break;
303 // ::= cm # ,
304 case OO_Comma: Out << "cm"; break;
305 // ::= pm # ->*
306 case OO_ArrowStar: Out << "pm"; break;
307 // ::= pt # ->
308 case OO_Arrow: Out << "pt"; break;
309 // ::= cl # ()
310 case OO_Call: Out << "cl"; break;
311 // ::= ix # []
312 case OO_Subscript: Out << "ix"; break;
313 // UNSUPPORTED: ::= qu # ?
314
315 case OO_None:
316 case NUM_OVERLOADED_OPERATORS:
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000317 assert(false && "Not an overloaded operator");
Douglas Gregor3556bc72009-02-13 00:10:09 +0000318 break;
319 }
320}
321
322void CXXNameMangler::mangleCVQualifiers(unsigned Quals) {
323 // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
324 if (Quals & QualType::Restrict)
325 Out << 'r';
326 if (Quals & QualType::Volatile)
327 Out << 'V';
328 if (Quals & QualType::Const)
329 Out << 'K';
330}
331
332void CXXNameMangler::mangleType(QualType T) {
Douglas Gregor3556bc72009-02-13 00:10:09 +0000333 // FIXME: Should we have a TypeNodes.def to make this easier? (YES!)
334
335 // <type> ::= <CV-qualifiers> <type>
336 mangleCVQualifiers(T.getCVRQualifiers());
337
Anders Carlssonc34a6842009-03-07 23:57:03 +0000338 if (const TypedefType *TT = dyn_cast<TypedefType>(T.getTypePtr()))
339 mangleType(TT);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000340 // ::= <builtin-type>
Anders Carlssonc34a6842009-03-07 23:57:03 +0000341 else if (const BuiltinType *BT = dyn_cast<BuiltinType>(T.getTypePtr()))
Douglas Gregor3556bc72009-02-13 00:10:09 +0000342 mangleType(BT);
343 // ::= <function-type>
344 else if (const FunctionType *FT = dyn_cast<FunctionType>(T.getTypePtr()))
345 mangleType(FT);
346 // ::= <class-enum-type>
347 else if (const TagType *TT = dyn_cast<TagType>(T.getTypePtr()))
348 mangleType(TT);
349 // ::= <array-type>
350 else if (const ArrayType *AT = dyn_cast<ArrayType>(T.getTypePtr()))
351 mangleType(AT);
352 // ::= <pointer-to-member-type>
353 else if (const MemberPointerType *MPT
354 = dyn_cast<MemberPointerType>(T.getTypePtr()))
355 mangleType(MPT);
356 // ::= <template-param>
357 else if (const TemplateTypeParmType *TypeParm
358 = dyn_cast<TemplateTypeParmType>(T.getTypePtr()))
359 mangleType(TypeParm);
360 // FIXME: ::= <template-template-param> <template-args>
361 // FIXME: ::= <substitution> # See Compression below
362 // ::= P <type> # pointer-to
363 else if (const PointerType *PT = dyn_cast<PointerType>(T.getTypePtr())) {
364 Out << 'P';
365 mangleType(PT->getPointeeType());
366 }
367 // ::= R <type> # reference-to
368 // ::= O <type> # rvalue reference-to (C++0x)
369 else if (const ReferenceType *RT = dyn_cast<ReferenceType>(T.getTypePtr())) {
370 // FIXME: rvalue references
371 Out << 'R';
372 mangleType(RT->getPointeeType());
373 }
374 // ::= C <type> # complex pair (C 2000)
375 else if (const ComplexType *CT = dyn_cast<ComplexType>(T.getTypePtr())) {
376 Out << 'C';
377 mangleType(CT->getElementType());
378 } else if (const VectorType *VT = dyn_cast<VectorType>(T.getTypePtr())) {
379 // GNU extension: vector types
380 Out << "U8__vector";
381 mangleType(VT->getElementType());
Anders Carlssonfae45862009-03-07 22:03:21 +0000382 } else if (const ObjCInterfaceType *IT =
383 dyn_cast<ObjCInterfaceType>(T.getTypePtr())) {
384 mangleType(IT);
Anders Carlssonc34a6842009-03-07 23:57:03 +0000385 }
Douglas Gregor3556bc72009-02-13 00:10:09 +0000386 // FIXME: ::= G <type> # imaginary (C 2000)
387 // FIXME: ::= U <source-name> <type> # vendor extended type qualifier
388 else
389 assert(false && "Cannot mangle unknown type");
390}
391
Anders Carlssonc34a6842009-03-07 23:57:03 +0000392void CXXNameMangler::mangleType(const TypedefType *T) {
393 QualType DeclTy = T->getDecl()->getUnderlyingType();
394
395 if (const TagType *TT = dyn_cast<TagType>(DeclTy)) {
396 // If the tag type is anonymous, use the name of the typedef.
397 if (!TT->getDecl()->getIdentifier()) {
398 mangleName(T->getDecl());
399 return;
400 }
401 }
402
403 mangleType(DeclTy);
404}
405
Douglas Gregor3556bc72009-02-13 00:10:09 +0000406void CXXNameMangler::mangleType(const BuiltinType *T) {
407 // <builtin-type> ::= v # void
408 // ::= w # wchar_t
409 // ::= b # bool
410 // ::= c # char
411 // ::= a # signed char
412 // ::= h # unsigned char
413 // ::= s # short
414 // ::= t # unsigned short
415 // ::= i # int
416 // ::= j # unsigned int
417 // ::= l # long
418 // ::= m # unsigned long
419 // ::= x # long long, __int64
420 // ::= y # unsigned long long, __int64
421 // ::= n # __int128
422 // UNSUPPORTED: ::= o # unsigned __int128
423 // ::= f # float
424 // ::= d # double
425 // ::= e # long double, __float80
426 // UNSUPPORTED: ::= g # __float128
Douglas Gregor3556bc72009-02-13 00:10:09 +0000427 // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits)
428 // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
429 // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
430 // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits)
431 // UNSUPPORTED: ::= Di # char32_t
432 // UNSUPPORTED: ::= Ds # char16_t
433 // ::= u <source-name> # vendor extended type
434 switch (T->getKind()) {
435 case BuiltinType::Void: Out << 'v'; break;
436 case BuiltinType::Bool: Out << 'b'; break;
437 case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break;
438 case BuiltinType::UChar: Out << 'h'; break;
439 case BuiltinType::UShort: Out << 't'; break;
440 case BuiltinType::UInt: Out << 'j'; break;
441 case BuiltinType::ULong: Out << 'm'; break;
442 case BuiltinType::ULongLong: Out << 'y'; break;
443 case BuiltinType::SChar: Out << 'a'; break;
444 case BuiltinType::WChar: Out << 'w'; break;
445 case BuiltinType::Short: Out << 's'; break;
446 case BuiltinType::Int: Out << 'i'; break;
447 case BuiltinType::Long: Out << 'l'; break;
448 case BuiltinType::LongLong: Out << 'x'; break;
449 case BuiltinType::Float: Out << 'f'; break;
450 case BuiltinType::Double: Out << 'd'; break;
451 case BuiltinType::LongDouble: Out << 'e'; break;
452
453 case BuiltinType::Overload:
454 case BuiltinType::Dependent:
455 assert(false &&
456 "Overloaded and dependent types shouldn't get to name mangling");
457 break;
458 }
459}
460
461void CXXNameMangler::mangleType(const FunctionType *T) {
462 // <function-type> ::= F [Y] <bare-function-type> E
463 Out << 'F';
464 // FIXME: We don't have enough information in the AST to produce the
465 // 'Y' encoding for extern "C" function types.
466 mangleBareFunctionType(T, /*MangleReturnType=*/true);
467 Out << 'E';
468}
469
470void CXXNameMangler::mangleBareFunctionType(const FunctionType *T,
471 bool MangleReturnType) {
472 // <bare-function-type> ::= <signature type>+
473 if (MangleReturnType)
474 mangleType(T->getResultType());
475
Douglas Gregor4fa58902009-02-26 23:50:07 +0000476 const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T);
Douglas Gregor3556bc72009-02-13 00:10:09 +0000477 assert(Proto && "Can't mangle K&R function prototypes");
478
Douglas Gregor4fa58902009-02-26 23:50:07 +0000479 for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
Douglas Gregor3556bc72009-02-13 00:10:09 +0000480 ArgEnd = Proto->arg_type_end();
481 Arg != ArgEnd; ++Arg)
482 mangleType(*Arg);
Douglas Gregor77cfb3c2009-02-13 01:28:03 +0000483
484 // <builtin-type> ::= z # ellipsis
485 if (Proto->isVariadic())
486 Out << 'z';
Douglas Gregor3556bc72009-02-13 00:10:09 +0000487}
488
489void CXXNameMangler::mangleType(const TagType *T) {
490 // <class-enum-type> ::= <name>
491 mangleName(T->getDecl());
492}
493
494void CXXNameMangler::mangleType(const ArrayType *T) {
495 // <array-type> ::= A <positive dimension number> _ <element type>
496 // ::= A [<dimension expression>] _ <element type>
497 Out << 'A';
498 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(T))
499 Out << CAT->getSize();
500 else if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(T))
501 mangleExpression(VAT->getSizeExpr());
502 else if (const DependentSizedArrayType *DSAT
503 = dyn_cast<DependentSizedArrayType>(T))
504 mangleExpression(DSAT->getSizeExpr());
505
506 Out << '_';
507 mangleType(T->getElementType());
508}
509
510void CXXNameMangler::mangleType(const MemberPointerType *T) {
511 // <pointer-to-member-type> ::= M <class type> <member type>
512 Out << 'M';
513 mangleType(QualType(T->getClass(), 0));
514 mangleType(T->getPointeeType());
515}
516
517void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
518 // <template-param> ::= T_ # first template parameter
519 // ::= T <parameter-2 non-negative number> _
520 if (T->getIndex() == 0)
521 Out << "T_";
522 else
523 Out << 'T' << (T->getIndex() - 1) << '_';
524}
525
Anders Carlssonfae45862009-03-07 22:03:21 +0000526void CXXNameMangler::mangleType(const ObjCInterfaceType *T) {
527 mangleSourceName(T->getDecl()->getIdentifier());
528}
529
Douglas Gregor3556bc72009-02-13 00:10:09 +0000530void CXXNameMangler::mangleExpression(Expr *E) {
531 assert(false && "Cannot mangle expressions yet");
532}
533
534namespace clang {
535 /// \brief Mangles the name of the declaration D and emits that name
536 /// to the given output stream.
537 ///
538 /// If the declaration D requires a mangled name, this routine will
539 /// emit that mangled name to \p os and return true. Otherwise, \p
540 /// os will be unchanged and this routine will return false. In this
541 /// case, the caller should just emit the identifier of the declaration
542 /// (\c D->getIdentifier()) as its name.
543 bool mangleName(const NamedDecl *D, ASTContext &Context,
544 llvm::raw_ostream &os) {
545 CXXNameMangler Mangler(Context, os);
Douglas Gregor3c3c4542009-02-18 23:53:56 +0000546 if (!Mangler.mangle(D))
547 return false;
548
549 os.flush();
550 return true;
Douglas Gregor3556bc72009-02-13 00:10:09 +0000551 }
552}
553