Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1 | //===--- Mangle.cpp - Mangle C++ Names --------------------------*- C++ -*-===// |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // 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 Carlsson | a40c5e4 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclObjC.h" |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclTemplate.h" |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 23 | #include "clang/AST/ExprCXX.h" |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 24 | #include "clang/Basic/SourceManager.h" |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 26 | #include "llvm/Support/Compiler.h" |
| 27 | #include "llvm/Support/raw_ostream.h" |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 28 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | |
| 31 | namespace { |
| 32 | class VISIBILITY_HIDDEN CXXNameMangler { |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 33 | MangleContext &Context; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 34 | llvm::raw_ostream &Out; |
| 35 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 36 | const CXXMethodDecl *Structor; |
| 37 | unsigned StructorType; |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 38 | CXXCtorType CtorType; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 40 | llvm::DenseMap<uintptr_t, unsigned> Substitutions; |
| 41 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 42 | public: |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 43 | CXXNameMangler(MangleContext &C, llvm::raw_ostream &os) |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 44 | : Context(C), Out(os), Structor(0), StructorType(0) { } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 45 | |
| 46 | bool mangle(const NamedDecl *D); |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 47 | void mangleCalloffset(int64_t nv, int64_t v); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 48 | void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v); |
| 49 | void mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 50 | int64_t nv_t, int64_t v_t, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 51 | int64_t nv_r, int64_t v_r); |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 52 | void mangleGuardVariable(const VarDecl *D); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 53 | |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 54 | void mangleCXXVtable(const CXXRecordDecl *RD); |
Mike Stump | 88e9171 | 2009-10-28 01:51:46 +0000 | [diff] [blame] | 55 | void mangleCXXVTT(const CXXRecordDecl *RD); |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 56 | void mangleCXXRtti(const CXXRecordDecl *RD); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 57 | void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type); |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 58 | void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 59 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 60 | private: |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 61 | bool mangleSubstitution(const NamedDecl *ND); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 62 | bool mangleSubstitution(QualType T); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 63 | bool mangleSubstitution(uintptr_t Ptr); |
| 64 | |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 65 | bool mangleStandardSubstitution(const NamedDecl *ND); |
| 66 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 67 | void addSubstitution(const NamedDecl *ND) { |
| 68 | addSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 69 | } |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 70 | void addSubstitution(QualType T); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 71 | void addSubstitution(uintptr_t Ptr); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 72 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 73 | bool mangleFunctionDecl(const FunctionDecl *FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 74 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 75 | void mangleFunctionEncoding(const FunctionDecl *FD); |
| 76 | void mangleName(const NamedDecl *ND); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 77 | void mangleName(const TemplateDecl *TD, |
| 78 | const TemplateArgument *TemplateArgs, |
| 79 | unsigned NumTemplateArgs); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 80 | void mangleUnqualifiedName(const NamedDecl *ND); |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 81 | void mangleUnscopedName(const NamedDecl *ND); |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 82 | void mangleUnscopedTemplateName(const TemplateDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 83 | void mangleSourceName(const IdentifierInfo *II); |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 84 | void mangleLocalName(const NamedDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 85 | void mangleNestedName(const NamedDecl *ND); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 86 | void mangleNestedName(const TemplateDecl *TD, |
| 87 | const TemplateArgument *TemplateArgs, |
| 88 | unsigned NumTemplateArgs); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 89 | void manglePrefix(const DeclContext *DC); |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 90 | void mangleTemplatePrefix(const TemplateDecl *ND); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 91 | void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 92 | void mangleQualifiers(Qualifiers Quals); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 93 | void mangleType(QualType T); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 94 | |
| 95 | // Declare manglers for every type class. |
| 96 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 97 | #define NON_CANONICAL_TYPE(CLASS, PARENT) |
| 98 | #define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T); |
| 99 | #include "clang/AST/TypeNodes.def" |
| 100 | |
| 101 | void mangleType(const TagType*); |
| 102 | void mangleBareFunctionType(const FunctionType *T, |
| 103 | bool MangleReturnType); |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 104 | void mangleExpression(const Expr *E); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 105 | void mangleCXXCtorType(CXXCtorType T); |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 106 | void mangleCXXDtorType(CXXDtorType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 108 | void mangleTemplateArgs(const TemplateArgument *TemplateArgs, |
| 109 | unsigned NumTemplateArgs); |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 110 | void mangleTemplateArgumentList(const TemplateArgumentList &L); |
| 111 | void mangleTemplateArgument(const TemplateArgument &A); |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 112 | |
| 113 | void mangleTemplateParameter(unsigned Index); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 114 | }; |
| 115 | } |
| 116 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 117 | static bool isInCLinkageSpecification(const Decl *D) { |
Douglas Gregor | 457e281 | 2009-10-28 16:31:34 +0000 | [diff] [blame^] | 118 | D = D->getCanonicalDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | for (const DeclContext *DC = D->getDeclContext(); |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 120 | !DC->isTranslationUnit(); DC = DC->getParent()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC)) |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 122 | return Linkage->getLanguage() == LinkageSpecDecl::lang_c; |
| 123 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 125 | return false; |
| 126 | } |
| 127 | |
| 128 | bool CXXNameMangler::mangleFunctionDecl(const FunctionDecl *FD) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 129 | // Clang's "overloadable" attribute extension to C/C++ implies name mangling |
| 130 | // (always). |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 131 | if (!FD->hasAttr<OverloadableAttr>()) { |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 132 | // C functions are not mangled, and "main" is never mangled. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 133 | if (!Context.getASTContext().getLangOptions().CPlusPlus || FD->isMain()) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 134 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | |
| 136 | // No mangling in an "implicit extern C" header. |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 137 | if (FD->getLocation().isValid() && |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 138 | Context.getASTContext().getSourceManager(). |
| 139 | isInExternCSystemHeader(FD->getLocation())) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 140 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 141 | |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 142 | // No name mangling in a C linkage specification. |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 143 | if (!isa<CXXMethodDecl>(FD) && isInCLinkageSpecification(FD)) |
Chris Lattner | 783601d | 2009-06-13 23:34:16 +0000 | [diff] [blame] | 144 | return false; |
| 145 | } |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 146 | |
| 147 | // If we get here, mangle the decl name! |
| 148 | Out << "_Z"; |
| 149 | mangleFunctionEncoding(FD); |
| 150 | return true; |
| 151 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 152 | |
| 153 | bool CXXNameMangler::mangle(const NamedDecl *D) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 154 | // Any decl can be declared with __asm("foo") on it, and this takes precedence |
| 155 | // over all other naming in the .o file. |
Argyrios Kyrtzidis | 40b598e | 2009-06-30 02:34:44 +0000 | [diff] [blame] | 156 | if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) { |
Chris Lattner | ca3f25c | 2009-03-21 08:24:40 +0000 | [diff] [blame] | 157 | // If we have an asm name, then we use it as the mangling. |
| 158 | Out << '\01'; // LLVM IR Marker for __asm("foo") |
| 159 | Out << ALA->getLabel(); |
| 160 | return true; |
| 161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 163 | // <mangled-name> ::= _Z <encoding> |
| 164 | // ::= <data name> |
| 165 | // ::= <special-name> |
| 166 | |
| 167 | // FIXME: Actually use a visitor to decode these? |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 168 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 169 | return mangleFunctionDecl(FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 171 | if (const VarDecl *VD = dyn_cast<VarDecl>(D)) { |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 172 | if (!Context.getASTContext().getLangOptions().CPlusPlus || |
Anders Carlsson | 9ccb065 | 2009-04-11 01:19:45 +0000 | [diff] [blame] | 173 | isInCLinkageSpecification(D) || |
| 174 | D->getDeclContext()->isTranslationUnit()) |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 175 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Anders Carlsson | 329749c | 2009-04-02 16:05:20 +0000 | [diff] [blame] | 177 | Out << "_Z"; |
| 178 | mangleName(VD); |
| 179 | return true; |
| 180 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 181 | |
Anders Carlsson | 43f1740 | 2009-04-02 15:51:53 +0000 | [diff] [blame] | 182 | return false; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D, |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 186 | CXXCtorType Type) { |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 187 | assert(!Structor && "Structor already set!"); |
| 188 | Structor = D; |
| 189 | StructorType = Type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 190 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 191 | mangle(D); |
| 192 | } |
| 193 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | void CXXNameMangler::mangleCXXDtor(const CXXDestructorDecl *D, |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 195 | CXXDtorType Type) { |
| 196 | assert(!Structor && "Structor already set!"); |
| 197 | Structor = D; |
| 198 | StructorType = Type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 199 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 200 | mangle(D); |
| 201 | } |
| 202 | |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 203 | void CXXNameMangler::mangleCXXVtable(const CXXRecordDecl *RD) { |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 204 | // <special-name> ::= TV <type> # virtual table |
| 205 | Out << "_ZTV"; |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 206 | mangleName(RD); |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Mike Stump | 88e9171 | 2009-10-28 01:51:46 +0000 | [diff] [blame] | 209 | void CXXNameMangler::mangleCXXVTT(const CXXRecordDecl *RD) { |
| 210 | // <special-name> ::= TT <type> # VTT structure |
| 211 | Out << "_ZTT"; |
| 212 | mangleName(RD); |
| 213 | } |
| 214 | |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 215 | void CXXNameMangler::mangleCXXRtti(const CXXRecordDecl *RD) { |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 216 | // <special-name> ::= TI <type> # typeinfo structure |
| 217 | Out << "_ZTI"; |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 218 | mangleName(RD); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 221 | void CXXNameMangler::mangleGuardVariable(const VarDecl *D) { |
| 222 | // <special-name> ::= GV <object name> # Guard variable for one-time |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 223 | // # initialization |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 224 | |
| 225 | Out << "_ZGV"; |
| 226 | mangleName(D); |
| 227 | } |
| 228 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 229 | void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
| 230 | // <encoding> ::= <function name> <bare-function-type> |
| 231 | mangleName(FD); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 233 | // Whether the mangling of a function type includes the return type depends on |
| 234 | // the context and the nature of the function. The rules for deciding whether |
| 235 | // the return type is included are: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 236 | // |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 237 | // 1. Template functions (names or types) have return types encoded, with |
| 238 | // the exceptions listed below. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 239 | // 2. Function types not appearing as part of a function name mangling, |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 240 | // e.g. parameters, pointer types, etc., have return type encoded, with the |
| 241 | // exceptions listed below. |
| 242 | // 3. Non-template function names do not have return types encoded. |
| 243 | // |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 244 | // The exceptions mentioned in (1) and (2) above, for which the return type is |
| 245 | // never included, are |
Douglas Gregor | 1fd2dd1 | 2009-06-29 22:39:32 +0000 | [diff] [blame] | 246 | // 1. Constructors. |
| 247 | // 2. Destructors. |
| 248 | // 3. Conversion operator functions, e.g. operator int. |
| 249 | bool MangleReturnType = false; |
Anders Carlsson | 9234b7f | 2009-09-17 03:46:43 +0000 | [diff] [blame] | 250 | if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) { |
| 251 | if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) || |
| 252 | isa<CXXConversionDecl>(FD))) |
| 253 | MangleReturnType = true; |
| 254 | |
| 255 | // Mangle the type of the primary template. |
| 256 | FD = PrimaryTemplate->getTemplatedDecl(); |
| 257 | } |
| 258 | |
John McCall | 54e14c4 | 2009-10-22 22:37:11 +0000 | [diff] [blame] | 259 | // Do the canonicalization out here because parameter types can |
| 260 | // undergo additional canonicalization (e.g. array decay). |
| 261 | FunctionType *FT = cast<FunctionType>(Context.getASTContext() |
| 262 | .getCanonicalType(FD->getType())); |
| 263 | |
| 264 | mangleBareFunctionType(FT, MangleReturnType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static bool isStdNamespace(const DeclContext *DC) { |
| 268 | if (!DC->isNamespace() || !DC->getParent()->isTranslationUnit()) |
| 269 | return false; |
| 270 | |
| 271 | const NamespaceDecl *NS = cast<NamespaceDecl>(DC); |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 272 | const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier(); |
| 273 | return II && II->isStr("std"); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 276 | static const TemplateDecl * |
| 277 | isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 278 | // Check if we have a function template. |
| 279 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){ |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 280 | if (const TemplateDecl *TD = FD->getPrimaryTemplate()) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 281 | TemplateArgs = FD->getTemplateSpecializationArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 282 | return TD; |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 286 | // Check if we have a class template. |
| 287 | if (const ClassTemplateSpecializationDecl *Spec = |
| 288 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 289 | TemplateArgs = &Spec->getTemplateArgs(); |
Anders Carlsson | bb36ba4 | 2009-09-26 03:24:57 +0000 | [diff] [blame] | 290 | return Spec->getSpecializedTemplate(); |
Anders Carlsson | eafc6dc | 2009-09-18 19:44:50 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 296 | void CXXNameMangler::mangleName(const NamedDecl *ND) { |
| 297 | // <name> ::= <nested-name> |
| 298 | // ::= <unscoped-name> |
| 299 | // ::= <unscoped-template-name> <template-args> |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 300 | // ::= <local-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 301 | // |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 302 | const DeclContext *DC = ND->getDeclContext(); |
Anders Carlsson | 5cc58c6 | 2009-09-22 17:23:30 +0000 | [diff] [blame] | 303 | while (isa<LinkageSpecDecl>(DC)) |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 304 | DC = DC->getParent(); |
Anders Carlsson | d58d6f7 | 2009-09-17 16:12:20 +0000 | [diff] [blame] | 305 | |
| 306 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 307 | // Check if we have a template. |
| 308 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 309 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 310 | mangleUnscopedTemplateName(TD); |
| 311 | mangleTemplateArgumentList(*TemplateArgs); |
| 312 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 313 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 314 | |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 315 | mangleUnscopedName(ND); |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | if (isa<FunctionDecl>(DC)) { |
| 320 | mangleLocalName(ND); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | mangleNestedName(ND); |
| 325 | } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 326 | void CXXNameMangler::mangleName(const TemplateDecl *TD, |
| 327 | const TemplateArgument *TemplateArgs, |
| 328 | unsigned NumTemplateArgs) { |
| 329 | const DeclContext *DC = TD->getDeclContext(); |
| 330 | while (isa<LinkageSpecDecl>(DC)) { |
| 331 | assert(cast<LinkageSpecDecl>(DC)->getLanguage() == |
| 332 | LinkageSpecDecl::lang_cxx && "Unexpected linkage decl!"); |
| 333 | DC = DC->getParent(); |
| 334 | } |
| 335 | |
| 336 | if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 337 | mangleUnscopedTemplateName(TD); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 338 | mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
| 339 | } else { |
| 340 | mangleNestedName(TD, TemplateArgs, NumTemplateArgs); |
| 341 | } |
| 342 | } |
| 343 | |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 344 | void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { |
| 345 | // <unscoped-name> ::= <unqualified-name> |
| 346 | // ::= St <unqualified-name> # ::std:: |
| 347 | if (isStdNamespace(ND->getDeclContext())) |
| 348 | Out << "St"; |
| 349 | |
| 350 | mangleUnqualifiedName(ND); |
| 351 | } |
| 352 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 353 | void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 354 | // <unscoped-template-name> ::= <unscoped-name> |
| 355 | // ::= <substitution> |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 356 | if (mangleSubstitution(ND)) |
Anders Carlsson | 03c9d53 | 2009-09-17 04:02:31 +0000 | [diff] [blame] | 357 | return; |
| 358 | |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 359 | mangleUnscopedName(ND->getTemplatedDecl()); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 360 | addSubstitution(ND); |
Anders Carlsson | 201ce74 | 2009-09-17 03:17:01 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 363 | void CXXNameMangler::mangleCalloffset(int64_t nv, int64_t v) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 364 | // <call-offset> ::= h <nv-offset> _ |
| 365 | // ::= v <v-offset> _ |
| 366 | // <nv-offset> ::= <offset number> # non-virtual base override |
| 367 | // <v-offset> ::= <offset nubmer> _ <virtual offset number> |
| 368 | // # virtual base override, with vcall offset |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 369 | if (v == 0) { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 370 | Out << "h"; |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 371 | if (nv < 0) { |
| 372 | Out << "n"; |
| 373 | nv = -nv; |
| 374 | } |
| 375 | Out << nv; |
| 376 | } else { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 377 | Out << "v"; |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 378 | if (nv < 0) { |
| 379 | Out << "n"; |
| 380 | nv = -nv; |
| 381 | } |
| 382 | Out << nv; |
| 383 | Out << "_"; |
| 384 | if (v < 0) { |
| 385 | Out << "n"; |
| 386 | v = -v; |
| 387 | } |
| 388 | Out << v; |
| 389 | } |
| 390 | Out << "_"; |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 393 | void CXXNameMangler::mangleThunk(const FunctionDecl *FD, int64_t nv, |
| 394 | int64_t v) { |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 395 | // <special-name> ::= T <call-offset> <base encoding> |
| 396 | // # base is the nominal target function of thunk |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 397 | Out << "_ZT"; |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 398 | mangleCalloffset(nv, v); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 399 | mangleFunctionEncoding(FD); |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 402 | void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD, |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 403 | int64_t nv_t, int64_t v_t, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 404 | int64_t nv_r, int64_t v_r) { |
| 405 | // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> |
| 406 | // # base is the nominal target function of thunk |
| 407 | // # first call-offset is 'this' adjustment |
| 408 | // # second call-offset is result adjustment |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 409 | Out << "_ZTc"; |
Mike Stump | 77ca8f6 | 2009-09-05 07:20:32 +0000 | [diff] [blame] | 410 | mangleCalloffset(nv_t, v_t); |
| 411 | mangleCalloffset(nv_r, v_r); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 412 | mangleFunctionEncoding(FD); |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 415 | void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) { |
| 416 | // <unqualified-name> ::= <operator-name> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 417 | // ::= <ctor-dtor-name> |
| 418 | // ::= <source-name> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 419 | DeclarationName Name = ND->getDeclName(); |
| 420 | switch (Name.getNameKind()) { |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 421 | case DeclarationName::Identifier: { |
| 422 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 423 | if (NS->isAnonymousNamespace()) { |
| 424 | // This is how gcc mangles these names. It's apparently |
| 425 | // always '1', no matter how many different anonymous |
| 426 | // namespaces appear in a context. |
| 427 | Out << "12_GLOBAL__N_1"; |
| 428 | break; |
| 429 | } |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 433 | mangleSourceName(II); |
| 434 | break; |
| 435 | } |
| 436 | |
| 437 | // We must have an anonymous struct. |
| 438 | const TagDecl *TD = cast<TagDecl>(ND); |
| 439 | if (const TypedefDecl *D = TD->getTypedefForAnonDecl()) { |
| 440 | assert(TD->getDeclContext() == D->getDeclContext() && |
| 441 | "Typedef should not be in another decl context!"); |
| 442 | assert(D->getDeclName().getAsIdentifierInfo() && |
| 443 | "Typedef was not named!"); |
| 444 | mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
| 445 | break; |
| 446 | } |
| 447 | |
| 448 | // Get a unique id for the anonymous struct. |
| 449 | uint64_t AnonStructId = Context.getAnonymousStructId(TD); |
| 450 | |
| 451 | // Mangle it as a source name in the form |
| 452 | // [n] $_<id> |
| 453 | // where n is the length of the string. |
| 454 | llvm::SmallString<8> Str; |
| 455 | Str += "$_"; |
| 456 | Str += llvm::utostr(AnonStructId); |
| 457 | |
| 458 | Out << Str.size(); |
| 459 | Out << Str.str(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 460 | break; |
Anders Carlsson | c4355b6 | 2009-10-07 01:45:02 +0000 | [diff] [blame] | 461 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 462 | |
| 463 | case DeclarationName::ObjCZeroArgSelector: |
| 464 | case DeclarationName::ObjCOneArgSelector: |
| 465 | case DeclarationName::ObjCMultiArgSelector: |
| 466 | assert(false && "Can't mangle Objective-C selector names here!"); |
| 467 | break; |
| 468 | |
| 469 | case DeclarationName::CXXConstructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 470 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 471 | // If the named decl is the C++ constructor we're mangling, use the type |
| 472 | // we were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 473 | mangleCXXCtorType(static_cast<CXXCtorType>(StructorType)); |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 474 | else |
| 475 | // Otherwise, use the complete constructor name. This is relevant if a |
| 476 | // class with a constructor is declared within a constructor. |
| 477 | mangleCXXCtorType(Ctor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 478 | break; |
| 479 | |
| 480 | case DeclarationName::CXXDestructorName: |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 481 | if (ND == Structor) |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 482 | // If the named decl is the C++ destructor we're mangling, use the type we |
| 483 | // were given. |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 484 | mangleCXXDtorType(static_cast<CXXDtorType>(StructorType)); |
| 485 | else |
| 486 | // Otherwise, use the complete destructor name. This is relevant if a |
| 487 | // class with a destructor is declared within a destructor. |
| 488 | mangleCXXDtorType(Dtor_Complete); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 489 | break; |
| 490 | |
| 491 | case DeclarationName::CXXConversionFunctionName: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 492 | // <operator-name> ::= cv <type> # (cast) |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 493 | Out << "cv"; |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 494 | mangleType(Context.getASTContext().getCanonicalType(Name.getCXXNameType())); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 495 | break; |
| 496 | |
| 497 | case DeclarationName::CXXOperatorName: |
| 498 | mangleOperatorName(Name.getCXXOverloadedOperator(), |
| 499 | cast<FunctionDecl>(ND)->getNumParams()); |
| 500 | break; |
| 501 | |
| 502 | case DeclarationName::CXXUsingDirective: |
| 503 | assert(false && "Can't mangle a using directive name!"); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 504 | break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) { |
| 509 | // <source-name> ::= <positive length number> <identifier> |
| 510 | // <number> ::= [n] <non-negative decimal integer> |
| 511 | // <identifier> ::= <unqualified source code identifier> |
| 512 | Out << II->getLength() << II->getName(); |
| 513 | } |
| 514 | |
| 515 | void CXXNameMangler::mangleNestedName(const NamedDecl *ND) { |
| 516 | // <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqualified-name> E |
| 517 | // ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 518 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 519 | Out << 'N'; |
| 520 | if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 521 | mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers())); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 522 | |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 523 | // Check if we have a template. |
| 524 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 525 | if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
Anders Carlsson | 2744a06 | 2009-09-18 19:00:18 +0000 | [diff] [blame] | 526 | mangleTemplatePrefix(TD); |
| 527 | mangleTemplateArgumentList(*TemplateArgs); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 528 | } else { |
| 529 | manglePrefix(ND->getDeclContext()); |
| 530 | mangleUnqualifiedName(ND); |
| 531 | } |
| 532 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 533 | Out << 'E'; |
| 534 | } |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 535 | void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, |
| 536 | const TemplateArgument *TemplateArgs, |
| 537 | unsigned NumTemplateArgs) { |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 538 | // <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
| 539 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 540 | Out << 'N'; |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 541 | |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 542 | mangleTemplatePrefix(TD); |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 543 | mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
Anders Carlsson | e45117b | 2009-09-27 19:53:49 +0000 | [diff] [blame] | 544 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 545 | Out << 'E'; |
| 546 | } |
| 547 | |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 548 | void CXXNameMangler::mangleLocalName(const NamedDecl *ND) { |
| 549 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| 550 | // := Z <function encoding> E s [<discriminator>] |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | // <discriminator> := _ <non-negative number> |
Anders Carlsson | 1b42c79 | 2009-04-02 16:24:45 +0000 | [diff] [blame] | 552 | Out << 'Z'; |
| 553 | mangleFunctionEncoding(cast<FunctionDecl>(ND->getDeclContext())); |
| 554 | Out << 'E'; |
| 555 | mangleSourceName(ND->getIdentifier()); |
| 556 | } |
| 557 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 558 | void CXXNameMangler::manglePrefix(const DeclContext *DC) { |
| 559 | // <prefix> ::= <prefix> <unqualified-name> |
| 560 | // ::= <template-prefix> <template-args> |
| 561 | // ::= <template-param> |
| 562 | // ::= # empty |
| 563 | // ::= <substitution> |
| 564 | // FIXME: We only handle mangling of namespaces and classes at the moment. |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 565 | |
Anders Carlsson | add2882 | 2009-09-22 20:33:31 +0000 | [diff] [blame] | 566 | while (isa<LinkageSpecDecl>(DC)) |
| 567 | DC = DC->getParent(); |
| 568 | |
Anders Carlsson | 9263e91 | 2009-09-18 18:39:58 +0000 | [diff] [blame] | 569 | if (DC->isTranslationUnit()) |
| 570 | return; |
| 571 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 572 | if (mangleSubstitution(cast<NamedDecl>(DC))) |
| 573 | return; |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 574 | |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 575 | // Check if we have a template. |
| 576 | const TemplateArgumentList *TemplateArgs = 0; |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 577 | if (const TemplateDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) { |
Anders Carlsson | 2ee3fca | 2009-09-18 20:11:09 +0000 | [diff] [blame] | 578 | mangleTemplatePrefix(TD); |
| 579 | mangleTemplateArgumentList(*TemplateArgs); |
| 580 | } else { |
| 581 | manglePrefix(DC->getParent()); |
| 582 | mangleUnqualifiedName(cast<NamedDecl>(DC)); |
| 583 | } |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 584 | |
| 585 | addSubstitution(cast<NamedDecl>(DC)); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Anders Carlsson | 0fa6df4 | 2009-09-26 19:45:45 +0000 | [diff] [blame] | 588 | void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND) { |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 589 | // <template-prefix> ::= <prefix> <template unqualified-name> |
| 590 | // ::= <template-param> |
| 591 | // ::= <substitution> |
| 592 | |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 593 | if (mangleSubstitution(ND)) |
| 594 | return; |
| 595 | |
| 596 | // FIXME: <template-param> |
Anders Carlsson | aa73ab1 | 2009-09-18 18:47:07 +0000 | [diff] [blame] | 597 | |
| 598 | manglePrefix(ND->getDeclContext()); |
Anders Carlsson | 1668f20 | 2009-09-26 20:13:56 +0000 | [diff] [blame] | 599 | mangleUnqualifiedName(ND->getTemplatedDecl()); |
Anders Carlsson | aeb8537 | 2009-09-26 22:18:22 +0000 | [diff] [blame] | 600 | |
| 601 | addSubstitution(ND); |
Anders Carlsson | 7482e24 | 2009-09-18 04:29:09 +0000 | [diff] [blame] | 602 | } |
| 603 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 604 | void |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 605 | CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) { |
| 606 | switch (OO) { |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 607 | // <operator-name> ::= nw # new |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 608 | case OO_New: Out << "nw"; break; |
| 609 | // ::= na # new[] |
| 610 | case OO_Array_New: Out << "na"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 611 | // ::= dl # delete |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 612 | case OO_Delete: Out << "dl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 613 | // ::= da # delete[] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 614 | case OO_Array_Delete: Out << "da"; break; |
| 615 | // ::= ps # + (unary) |
| 616 | // ::= pl # + |
| 617 | case OO_Plus: Out << (Arity == 1? "ps" : "pl"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 618 | // ::= ng # - (unary) |
| 619 | // ::= mi # - |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 620 | case OO_Minus: Out << (Arity == 1? "ng" : "mi"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 621 | // ::= ad # & (unary) |
| 622 | // ::= an # & |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 623 | case OO_Amp: Out << (Arity == 1? "ad" : "an"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 624 | // ::= de # * (unary) |
| 625 | // ::= ml # * |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 626 | case OO_Star: Out << (Arity == 1? "de" : "ml"); break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 627 | // ::= co # ~ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 628 | case OO_Tilde: Out << "co"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 629 | // ::= dv # / |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 630 | case OO_Slash: Out << "dv"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 631 | // ::= rm # % |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 632 | case OO_Percent: Out << "rm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 633 | // ::= or # | |
| 634 | case OO_Pipe: Out << "or"; break; |
| 635 | // ::= eo # ^ |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 636 | case OO_Caret: Out << "eo"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 637 | // ::= aS # = |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 638 | case OO_Equal: Out << "aS"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 639 | // ::= pL # += |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 640 | case OO_PlusEqual: Out << "pL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 641 | // ::= mI # -= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 642 | case OO_MinusEqual: Out << "mI"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 643 | // ::= mL # *= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 644 | case OO_StarEqual: Out << "mL"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 645 | // ::= dV # /= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 646 | case OO_SlashEqual: Out << "dV"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 647 | // ::= rM # %= |
| 648 | case OO_PercentEqual: Out << "rM"; break; |
| 649 | // ::= aN # &= |
| 650 | case OO_AmpEqual: Out << "aN"; break; |
| 651 | // ::= oR # |= |
| 652 | case OO_PipeEqual: Out << "oR"; break; |
| 653 | // ::= eO # ^= |
| 654 | case OO_CaretEqual: Out << "eO"; break; |
| 655 | // ::= ls # << |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 656 | case OO_LessLess: Out << "ls"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 657 | // ::= rs # >> |
| 658 | case OO_GreaterGreater: Out << "rs"; break; |
| 659 | // ::= lS # <<= |
| 660 | case OO_LessLessEqual: Out << "lS"; break; |
| 661 | // ::= rS # >>= |
| 662 | case OO_GreaterGreaterEqual: Out << "rS"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 663 | // ::= eq # == |
| 664 | case OO_EqualEqual: Out << "eq"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 665 | // ::= ne # != |
| 666 | case OO_ExclaimEqual: Out << "ne"; break; |
| 667 | // ::= lt # < |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 668 | case OO_Less: Out << "lt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 669 | // ::= gt # > |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 670 | case OO_Greater: Out << "gt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 671 | // ::= le # <= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 672 | case OO_LessEqual: Out << "le"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 673 | // ::= ge # >= |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 674 | case OO_GreaterEqual: Out << "ge"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 675 | // ::= nt # ! |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 676 | case OO_Exclaim: Out << "nt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 677 | // ::= aa # && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 678 | case OO_AmpAmp: Out << "aa"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 679 | // ::= oo # || |
| 680 | case OO_PipePipe: Out << "oo"; break; |
| 681 | // ::= pp # ++ |
| 682 | case OO_PlusPlus: Out << "pp"; break; |
| 683 | // ::= mm # -- |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 684 | case OO_MinusMinus: Out << "mm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 685 | // ::= cm # , |
| 686 | case OO_Comma: Out << "cm"; break; |
| 687 | // ::= pm # ->* |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 688 | case OO_ArrowStar: Out << "pm"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 689 | // ::= pt # -> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 690 | case OO_Arrow: Out << "pt"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 691 | // ::= cl # () |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 692 | case OO_Call: Out << "cl"; break; |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 693 | // ::= ix # [] |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 694 | case OO_Subscript: Out << "ix"; break; |
| 695 | // UNSUPPORTED: ::= qu # ? |
| 696 | |
Sebastian Redl | 3201f6b | 2009-04-16 17:51:27 +0000 | [diff] [blame] | 697 | case OO_None: |
| 698 | case OO_Conditional: |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 699 | case NUM_OVERLOADED_OPERATORS: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 700 | assert(false && "Not an overloaded operator"); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 701 | break; |
| 702 | } |
| 703 | } |
| 704 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 705 | void CXXNameMangler::mangleQualifiers(Qualifiers Quals) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 706 | // <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 707 | if (Quals.hasRestrict()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 708 | Out << 'r'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 709 | if (Quals.hasVolatile()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 710 | Out << 'V'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 711 | if (Quals.hasConst()) |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 712 | Out << 'K'; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 713 | |
| 714 | // FIXME: For now, just drop all extension qualifiers on the floor. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | void CXXNameMangler::mangleType(QualType T) { |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 718 | // Only operate on the canonical type! |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 719 | T = Context.getASTContext().getCanonicalType(T); |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 720 | |
Anders Carlsson | 410f764 | 2009-10-16 02:06:06 +0000 | [diff] [blame] | 721 | bool IsSubstitutable = T.hasQualifiers() || !isa<BuiltinType>(T); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 722 | if (IsSubstitutable && mangleSubstitution(T)) |
| 723 | return; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 724 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 725 | if (Qualifiers Quals = T.getQualifiers()) { |
| 726 | mangleQualifiers(Quals); |
| 727 | // Recurse: even if the qualified type isn't yet substitutable, |
| 728 | // the unqualified type might be. |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 729 | mangleType(T.getUnqualifiedType()); |
| 730 | } else { |
| 731 | switch (T->getTypeClass()) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 732 | #define ABSTRACT_TYPE(CLASS, PARENT) |
| 733 | #define NON_CANONICAL_TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 734 | case Type::CLASS: \ |
| 735 | llvm::llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \ |
| 736 | return; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 737 | #define TYPE(CLASS, PARENT) \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 738 | case Type::CLASS: \ |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 739 | mangleType(static_cast<const CLASS##Type*>(T.getTypePtr())); \ |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 740 | break; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 741 | #include "clang/AST/TypeNodes.def" |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 742 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 743 | } |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 744 | |
| 745 | // Add the substitution. |
| 746 | if (IsSubstitutable) |
| 747 | addSubstitution(T); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | void CXXNameMangler::mangleType(const BuiltinType *T) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 751 | // <type> ::= <builtin-type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 752 | // <builtin-type> ::= v # void |
| 753 | // ::= w # wchar_t |
| 754 | // ::= b # bool |
| 755 | // ::= c # char |
| 756 | // ::= a # signed char |
| 757 | // ::= h # unsigned char |
| 758 | // ::= s # short |
| 759 | // ::= t # unsigned short |
| 760 | // ::= i # int |
| 761 | // ::= j # unsigned int |
| 762 | // ::= l # long |
| 763 | // ::= m # unsigned long |
| 764 | // ::= x # long long, __int64 |
| 765 | // ::= y # unsigned long long, __int64 |
| 766 | // ::= n # __int128 |
| 767 | // UNSUPPORTED: ::= o # unsigned __int128 |
| 768 | // ::= f # float |
| 769 | // ::= d # double |
| 770 | // ::= e # long double, __float80 |
| 771 | // UNSUPPORTED: ::= g # __float128 |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 772 | // UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits) |
| 773 | // UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits) |
| 774 | // UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits) |
| 775 | // UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits) |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 776 | // ::= Di # char32_t |
| 777 | // ::= Ds # char16_t |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 778 | // ::= u <source-name> # vendor extended type |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 779 | // From our point of view, std::nullptr_t is a builtin, but as far as mangling |
| 780 | // is concerned, it's a type called std::nullptr_t. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 781 | switch (T->getKind()) { |
| 782 | case BuiltinType::Void: Out << 'v'; break; |
| 783 | case BuiltinType::Bool: Out << 'b'; break; |
| 784 | case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break; |
| 785 | case BuiltinType::UChar: Out << 'h'; break; |
| 786 | case BuiltinType::UShort: Out << 't'; break; |
| 787 | case BuiltinType::UInt: Out << 'j'; break; |
| 788 | case BuiltinType::ULong: Out << 'm'; break; |
| 789 | case BuiltinType::ULongLong: Out << 'y'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 790 | case BuiltinType::UInt128: Out << 'o'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 791 | case BuiltinType::SChar: Out << 'a'; break; |
| 792 | case BuiltinType::WChar: Out << 'w'; break; |
Alisdair Meredith | f5c209d | 2009-07-14 06:30:34 +0000 | [diff] [blame] | 793 | case BuiltinType::Char16: Out << "Ds"; break; |
| 794 | case BuiltinType::Char32: Out << "Di"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 795 | case BuiltinType::Short: Out << 's'; break; |
| 796 | case BuiltinType::Int: Out << 'i'; break; |
| 797 | case BuiltinType::Long: Out << 'l'; break; |
| 798 | case BuiltinType::LongLong: Out << 'x'; break; |
Chris Lattner | 2df9ced | 2009-04-30 02:43:43 +0000 | [diff] [blame] | 799 | case BuiltinType::Int128: Out << 'n'; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 800 | case BuiltinType::Float: Out << 'f'; break; |
| 801 | case BuiltinType::Double: Out << 'd'; break; |
| 802 | case BuiltinType::LongDouble: Out << 'e'; break; |
Sebastian Redl | 6e8ed16 | 2009-05-10 18:38:11 +0000 | [diff] [blame] | 803 | case BuiltinType::NullPtr: Out << "St9nullptr_t"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 804 | |
| 805 | case BuiltinType::Overload: |
| 806 | case BuiltinType::Dependent: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | assert(false && |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 808 | "Overloaded and dependent types shouldn't get to name mangling"); |
| 809 | break; |
Anders Carlsson | e89d159 | 2009-06-26 18:41:36 +0000 | [diff] [blame] | 810 | case BuiltinType::UndeducedAuto: |
| 811 | assert(0 && "Should not see undeduced auto here"); |
| 812 | break; |
Steve Naroff | 9533a7f | 2009-07-22 17:14:51 +0000 | [diff] [blame] | 813 | case BuiltinType::ObjCId: Out << "11objc_object"; break; |
| 814 | case BuiltinType::ObjCClass: Out << "10objc_class"; break; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 818 | // <type> ::= <function-type> |
| 819 | // <function-type> ::= F [Y] <bare-function-type> E |
| 820 | void CXXNameMangler::mangleType(const FunctionProtoType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 821 | Out << 'F'; |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 822 | // FIXME: We don't have enough information in the AST to produce the 'Y' |
| 823 | // encoding for extern "C" function types. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 824 | mangleBareFunctionType(T, /*MangleReturnType=*/true); |
| 825 | Out << 'E'; |
| 826 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 827 | void CXXNameMangler::mangleType(const FunctionNoProtoType *T) { |
| 828 | llvm::llvm_unreachable("Can't mangle K&R function prototypes"); |
| 829 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 830 | void CXXNameMangler::mangleBareFunctionType(const FunctionType *T, |
| 831 | bool MangleReturnType) { |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 832 | // We should never be mangling something without a prototype. |
| 833 | const FunctionProtoType *Proto = cast<FunctionProtoType>(T); |
| 834 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 835 | // <bare-function-type> ::= <signature type>+ |
| 836 | if (MangleReturnType) |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 837 | mangleType(Proto->getResultType()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 838 | |
Anders Carlsson | c6c91bc | 2009-04-01 00:15:23 +0000 | [diff] [blame] | 839 | if (Proto->getNumArgs() == 0) { |
| 840 | Out << 'v'; |
| 841 | return; |
| 842 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 844 | for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | ArgEnd = Proto->arg_type_end(); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 846 | Arg != ArgEnd; ++Arg) |
| 847 | mangleType(*Arg); |
Douglas Gregor | 219cc61 | 2009-02-13 01:28:03 +0000 | [diff] [blame] | 848 | |
| 849 | // <builtin-type> ::= z # ellipsis |
| 850 | if (Proto->isVariadic()) |
| 851 | Out << 'z'; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 852 | } |
| 853 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 854 | // <type> ::= <class-enum-type> |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | // <class-enum-type> ::= <name> |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 856 | void CXXNameMangler::mangleType(const EnumType *T) { |
| 857 | mangleType(static_cast<const TagType*>(T)); |
| 858 | } |
| 859 | void CXXNameMangler::mangleType(const RecordType *T) { |
| 860 | mangleType(static_cast<const TagType*>(T)); |
| 861 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 862 | void CXXNameMangler::mangleType(const TagType *T) { |
Anders Carlsson | 4843e58 | 2009-03-10 17:07:44 +0000 | [diff] [blame] | 863 | if (!T->getDecl()->getIdentifier()) |
| 864 | mangleName(T->getDecl()->getTypedefForAnonDecl()); |
| 865 | else |
| 866 | mangleName(T->getDecl()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 867 | } |
| 868 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 869 | // <type> ::= <array-type> |
| 870 | // <array-type> ::= A <positive dimension number> _ <element type> |
| 871 | // ::= A [<dimension expression>] _ <element type> |
| 872 | void CXXNameMangler::mangleType(const ConstantArrayType *T) { |
| 873 | Out << 'A' << T->getSize() << '_'; |
| 874 | mangleType(T->getElementType()); |
| 875 | } |
| 876 | void CXXNameMangler::mangleType(const VariableArrayType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 877 | Out << 'A'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 878 | mangleExpression(T->getSizeExpr()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 879 | Out << '_'; |
| 880 | mangleType(T->getElementType()); |
| 881 | } |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 882 | void CXXNameMangler::mangleType(const DependentSizedArrayType *T) { |
| 883 | Out << 'A'; |
| 884 | mangleExpression(T->getSizeExpr()); |
| 885 | Out << '_'; |
| 886 | mangleType(T->getElementType()); |
| 887 | } |
| 888 | void CXXNameMangler::mangleType(const IncompleteArrayType *T) { |
| 889 | Out << 'A' << '_'; |
| 890 | mangleType(T->getElementType()); |
| 891 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 892 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 893 | // <type> ::= <pointer-to-member-type> |
| 894 | // <pointer-to-member-type> ::= M <class type> <member type> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 895 | void CXXNameMangler::mangleType(const MemberPointerType *T) { |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 896 | Out << 'M'; |
| 897 | mangleType(QualType(T->getClass(), 0)); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 898 | QualType PointeeType = T->getPointeeType(); |
| 899 | if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 900 | mangleQualifiers(Qualifiers::fromCVRMask(FPT->getTypeQuals())); |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 901 | mangleType(FPT); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | } else |
Anders Carlsson | 0e65001 | 2009-05-17 17:41:20 +0000 | [diff] [blame] | 903 | mangleType(PointeeType); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 904 | } |
| 905 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 906 | // <type> ::= <template-param> |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 907 | void CXXNameMangler::mangleType(const TemplateTypeParmType *T) { |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 908 | mangleTemplateParameter(T->getIndex()); |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 909 | } |
| 910 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 911 | // FIXME: <type> ::= <template-template-param> <template-args> |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 912 | |
| 913 | // <type> ::= P <type> # pointer-to |
| 914 | void CXXNameMangler::mangleType(const PointerType *T) { |
| 915 | Out << 'P'; |
| 916 | mangleType(T->getPointeeType()); |
| 917 | } |
| 918 | void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) { |
| 919 | Out << 'P'; |
| 920 | mangleType(T->getPointeeType()); |
| 921 | } |
| 922 | |
| 923 | // <type> ::= R <type> # reference-to |
| 924 | void CXXNameMangler::mangleType(const LValueReferenceType *T) { |
| 925 | Out << 'R'; |
| 926 | mangleType(T->getPointeeType()); |
| 927 | } |
| 928 | |
| 929 | // <type> ::= O <type> # rvalue reference-to (C++0x) |
| 930 | void CXXNameMangler::mangleType(const RValueReferenceType *T) { |
| 931 | Out << 'O'; |
| 932 | mangleType(T->getPointeeType()); |
| 933 | } |
| 934 | |
| 935 | // <type> ::= C <type> # complex pair (C 2000) |
| 936 | void CXXNameMangler::mangleType(const ComplexType *T) { |
| 937 | Out << 'C'; |
| 938 | mangleType(T->getElementType()); |
| 939 | } |
| 940 | |
| 941 | // GNU extension: vector types |
| 942 | void CXXNameMangler::mangleType(const VectorType *T) { |
| 943 | Out << "U8__vector"; |
| 944 | mangleType(T->getElementType()); |
| 945 | } |
| 946 | void CXXNameMangler::mangleType(const ExtVectorType *T) { |
| 947 | mangleType(static_cast<const VectorType*>(T)); |
| 948 | } |
| 949 | void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) { |
| 950 | Out << "U8__vector"; |
| 951 | mangleType(T->getElementType()); |
| 952 | } |
| 953 | |
Anders Carlsson | a40c5e4 | 2009-03-07 22:03:21 +0000 | [diff] [blame] | 954 | void CXXNameMangler::mangleType(const ObjCInterfaceType *T) { |
| 955 | mangleSourceName(T->getDecl()->getIdentifier()); |
| 956 | } |
| 957 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 958 | void CXXNameMangler::mangleType(const BlockPointerType *T) { |
| 959 | assert(false && "can't mangle block pointer types yet"); |
| 960 | } |
| 961 | |
| 962 | void CXXNameMangler::mangleType(const FixedWidthIntType *T) { |
| 963 | assert(false && "can't mangle arbitary-precision integer type yet"); |
| 964 | } |
| 965 | |
| 966 | void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 967 | TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl(); |
| 968 | assert(TD && "FIXME: Support dependent template names!"); |
| 969 | |
| 970 | mangleName(TD, T->getArgs(), T->getNumArgs()); |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | void CXXNameMangler::mangleType(const TypenameType *T) { |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 974 | // Typename types are always nested |
| 975 | Out << 'N'; |
| 976 | |
| 977 | const Type *QTy = T->getQualifier()->getAsType(); |
| 978 | if (const TemplateSpecializationType *TST = |
| 979 | dyn_cast<TemplateSpecializationType>(QTy)) { |
Anders Carlsson | 8859917 | 2009-09-27 01:06:07 +0000 | [diff] [blame] | 980 | if (!mangleSubstitution(QualType(TST, 0))) { |
| 981 | TemplateDecl *TD = TST->getTemplateName().getAsTemplateDecl(); |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 982 | |
Anders Carlsson | 8859917 | 2009-09-27 01:06:07 +0000 | [diff] [blame] | 983 | mangleTemplatePrefix(TD); |
| 984 | mangleTemplateArgs(TST->getArgs(), TST->getNumArgs()); |
| 985 | addSubstitution(QualType(TST, 0)); |
| 986 | } |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 987 | } else if (const TemplateTypeParmType *TTPT = |
| 988 | dyn_cast<TemplateTypeParmType>(QTy)) { |
| 989 | // We use the QualType mangle type variant here because it handles |
| 990 | // substitutions. |
| 991 | mangleType(QualType(TTPT, 0)); |
Anders Carlsson | ae35248 | 2009-09-26 02:26:02 +0000 | [diff] [blame] | 992 | } else |
| 993 | assert(false && "Unhandled type!"); |
| 994 | |
| 995 | mangleSourceName(T->getIdentifier()); |
| 996 | |
| 997 | Out << 'E'; |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1000 | void CXXNameMangler::mangleExpression(const Expr *E) { |
| 1001 | // <expression> ::= <unary operator-name> <expression> |
| 1002 | // ::= <binary operator-name> <expression> <expression> |
| 1003 | // ::= <trinary operator-name> <expression> <expression> <expression> |
| 1004 | // ::= cl <expression>* E # call |
| 1005 | // ::= cv <type> expression # conversion with one argument |
| 1006 | // ::= cv <type> _ <expression>* E # conversion with a different number of arguments |
| 1007 | // ::= st <type> # sizeof (a type) |
| 1008 | // ::= at <type> # alignof (a type) |
| 1009 | // ::= <template-param> |
| 1010 | // ::= <function-param> |
| 1011 | // ::= sr <type> <unqualified-name> # dependent name |
| 1012 | // ::= sr <type> <unqualified-name> <template-args> # dependent template-id |
| 1013 | // ::= sZ <template-param> # size of a parameter pack |
| 1014 | // ::= <expr-primary> |
| 1015 | switch (E->getStmtClass()) { |
| 1016 | default: assert(false && "Unhandled expression kind!"); |
| 1017 | case Expr::DeclRefExprClass: { |
| 1018 | const Decl *D = cast<DeclRefExpr>(E)->getDecl(); |
| 1019 | |
| 1020 | switch (D->getKind()) { |
| 1021 | default: assert(false && "Unhandled decl kind!"); |
| 1022 | case Decl::NonTypeTemplateParm: { |
| 1023 | const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D); |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 1024 | mangleTemplateParameter(PD->getIndex()); |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1025 | break; |
| 1026 | } |
| 1027 | |
| 1028 | } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 1029 | |
| 1030 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1031 | } |
Anders Carlsson | 50755b0 | 2009-09-27 20:11:34 +0000 | [diff] [blame] | 1032 | |
| 1033 | case Expr::UnresolvedDeclRefExprClass: { |
| 1034 | const UnresolvedDeclRefExpr *DRE = cast<UnresolvedDeclRefExpr>(E); |
| 1035 | const Type *QTy = DRE->getQualifier()->getAsType(); |
| 1036 | assert(QTy && "Qualifier was not type!"); |
| 1037 | |
| 1038 | // ::= sr <type> <unqualified-name> # dependent name |
| 1039 | Out << "sr"; |
| 1040 | mangleType(QualType(QTy, 0)); |
| 1041 | |
| 1042 | assert(DRE->getDeclName().getNameKind() == DeclarationName::Identifier && |
| 1043 | "Unhandled decl name kind!"); |
| 1044 | mangleSourceName(DRE->getDeclName().getAsIdentifierInfo()); |
| 1045 | |
| 1046 | break; |
| 1047 | } |
| 1048 | |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1049 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
John McCall | efe6aee | 2009-09-05 07:56:18 +0000 | [diff] [blame] | 1052 | // FIXME: <type> ::= G <type> # imaginary (C 2000) |
| 1053 | // FIXME: <type> ::= U <source-name> <type> # vendor extended type qualifier |
| 1054 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1055 | void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) { |
| 1056 | // <ctor-dtor-name> ::= C1 # complete object constructor |
| 1057 | // ::= C2 # base object constructor |
| 1058 | // ::= C3 # complete object allocating constructor |
| 1059 | // |
| 1060 | switch (T) { |
| 1061 | case Ctor_Complete: |
| 1062 | Out << "C1"; |
| 1063 | break; |
| 1064 | case Ctor_Base: |
| 1065 | Out << "C2"; |
| 1066 | break; |
| 1067 | case Ctor_CompleteAllocating: |
| 1068 | Out << "C3"; |
| 1069 | break; |
| 1070 | } |
| 1071 | } |
| 1072 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1073 | void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) { |
| 1074 | // <ctor-dtor-name> ::= D0 # deleting destructor |
| 1075 | // ::= D1 # complete object destructor |
| 1076 | // ::= D2 # base object destructor |
| 1077 | // |
| 1078 | switch (T) { |
| 1079 | case Dtor_Deleting: |
| 1080 | Out << "D0"; |
| 1081 | break; |
| 1082 | case Dtor_Complete: |
| 1083 | Out << "D1"; |
| 1084 | break; |
| 1085 | case Dtor_Base: |
| 1086 | Out << "D2"; |
| 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1091 | void CXXNameMangler::mangleTemplateArgumentList(const TemplateArgumentList &L) { |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1092 | // <template-args> ::= I <template-arg>+ E |
| 1093 | Out << "I"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1095 | for (unsigned i = 0, e = L.size(); i != e; ++i) { |
| 1096 | const TemplateArgument &A = L[i]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1097 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1098 | mangleTemplateArgument(A); |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1099 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1101 | Out << "E"; |
| 1102 | } |
| 1103 | |
Anders Carlsson | 7624f21 | 2009-09-18 02:42:01 +0000 | [diff] [blame] | 1104 | void CXXNameMangler::mangleTemplateArgs(const TemplateArgument *TemplateArgs, |
| 1105 | unsigned NumTemplateArgs) { |
| 1106 | // <template-args> ::= I <template-arg>+ E |
| 1107 | Out << "I"; |
| 1108 | |
| 1109 | for (unsigned i = 0; i != NumTemplateArgs; ++i) { |
| 1110 | mangleTemplateArgument(TemplateArgs[i]); |
| 1111 | } |
| 1112 | |
| 1113 | Out << "E"; |
| 1114 | } |
| 1115 | |
Anders Carlsson | 068f347 | 2009-09-17 05:31:47 +0000 | [diff] [blame] | 1116 | void CXXNameMangler::mangleTemplateArgument(const TemplateArgument &A) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | // <template-arg> ::= <type> # type or template |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1118 | // ::= X <expression> E # expression |
| 1119 | // ::= <expr-primary> # simple expressions |
| 1120 | // ::= I <template-arg>* E # argument pack |
| 1121 | // ::= sp <expression> # pack expansion of (C++0x) |
| 1122 | switch (A.getKind()) { |
| 1123 | default: |
| 1124 | assert(0 && "Unknown template argument kind!"); |
| 1125 | case TemplateArgument::Type: |
| 1126 | mangleType(A.getAsType()); |
| 1127 | break; |
Anders Carlsson | d553f8c | 2009-09-21 01:21:10 +0000 | [diff] [blame] | 1128 | case TemplateArgument::Expression: |
| 1129 | Out << 'X'; |
| 1130 | mangleExpression(A.getAsExpr()); |
| 1131 | Out << 'E'; |
| 1132 | break; |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1133 | case TemplateArgument::Integral: |
| 1134 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 1135 | |
| 1136 | Out << 'L'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1137 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1138 | mangleType(A.getIntegralType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1139 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1140 | const llvm::APSInt *Integral = A.getAsIntegral(); |
| 1141 | if (A.getIntegralType()->isBooleanType()) { |
| 1142 | // Boolean values are encoded as 0/1. |
| 1143 | Out << (Integral->getBoolValue() ? '1' : '0'); |
| 1144 | } else { |
| 1145 | if (Integral->isNegative()) |
| 1146 | Out << 'n'; |
| 1147 | Integral->abs().print(Out, false); |
| 1148 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1149 | |
Anders Carlsson | 7a0ba87 | 2009-05-15 16:09:15 +0000 | [diff] [blame] | 1150 | Out << 'E'; |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | |
Anders Carlsson | 0ccdf8d | 2009-09-27 00:38:53 +0000 | [diff] [blame] | 1155 | void CXXNameMangler::mangleTemplateParameter(unsigned Index) { |
| 1156 | // <template-param> ::= T_ # first template parameter |
| 1157 | // ::= T <parameter-2 non-negative number> _ |
| 1158 | if (Index == 0) |
| 1159 | Out << "T_"; |
| 1160 | else |
| 1161 | Out << 'T' << (Index - 1) << '_'; |
| 1162 | } |
| 1163 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1164 | // <substitution> ::= S <seq-id> _ |
| 1165 | // ::= S_ |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 1166 | bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) { |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1167 | // Try one of the standard substitutions first. |
| 1168 | if (mangleStandardSubstitution(ND)) |
| 1169 | return true; |
| 1170 | |
Anders Carlsson | 6862fc7 | 2009-09-17 04:16:28 +0000 | [diff] [blame] | 1171 | return mangleSubstitution(reinterpret_cast<uintptr_t>(ND)); |
| 1172 | } |
| 1173 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1174 | bool CXXNameMangler::mangleSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1175 | if (!T.getCVRQualifiers()) { |
| 1176 | if (const RecordType *RT = T->getAs<RecordType>()) |
| 1177 | return mangleSubstitution(RT->getDecl()); |
| 1178 | } |
| 1179 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1180 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
| 1181 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1182 | return mangleSubstitution(TypePtr); |
| 1183 | } |
| 1184 | |
| 1185 | bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) { |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1186 | llvm::DenseMap<uintptr_t, unsigned>::iterator I = |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1187 | Substitutions.find(Ptr); |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1188 | if (I == Substitutions.end()) |
| 1189 | return false; |
| 1190 | |
| 1191 | unsigned SeqID = I->second; |
| 1192 | if (SeqID == 0) |
| 1193 | Out << "S_"; |
| 1194 | else { |
| 1195 | SeqID--; |
| 1196 | |
| 1197 | // <seq-id> is encoded in base-36, using digits and upper case letters. |
| 1198 | char Buffer[10]; |
| 1199 | char *BufferPtr = Buffer + 9; |
| 1200 | |
| 1201 | *BufferPtr = 0; |
| 1202 | if (SeqID == 0) *--BufferPtr = '0'; |
| 1203 | |
| 1204 | while (SeqID) { |
| 1205 | assert(BufferPtr > Buffer && "Buffer overflow!"); |
| 1206 | |
| 1207 | unsigned char c = static_cast<unsigned char>(SeqID) % 36; |
| 1208 | |
| 1209 | *--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10); |
| 1210 | SeqID /= 36; |
| 1211 | } |
| 1212 | |
| 1213 | Out << 'S' << BufferPtr << '_'; |
| 1214 | } |
| 1215 | |
| 1216 | return true; |
| 1217 | } |
| 1218 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1219 | static bool isCharType(QualType T) { |
| 1220 | if (T.isNull()) |
| 1221 | return false; |
| 1222 | |
| 1223 | return T->isSpecificBuiltinType(BuiltinType::Char_S) || |
| 1224 | T->isSpecificBuiltinType(BuiltinType::Char_U); |
| 1225 | } |
| 1226 | |
| 1227 | /// isCharSpecialization - Returns whether a given type is a template |
| 1228 | /// specialization of a given name with a single argument of type char. |
| 1229 | static bool isCharSpecialization(QualType T, const char *Name) { |
| 1230 | if (T.isNull()) |
| 1231 | return false; |
| 1232 | |
| 1233 | const RecordType *RT = T->getAs<RecordType>(); |
| 1234 | if (!RT) |
| 1235 | return false; |
| 1236 | |
| 1237 | const ClassTemplateSpecializationDecl *SD = |
| 1238 | dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl()); |
| 1239 | if (!SD) |
| 1240 | return false; |
| 1241 | |
| 1242 | if (!isStdNamespace(SD->getDeclContext())) |
| 1243 | return false; |
| 1244 | |
| 1245 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 1246 | if (TemplateArgs.size() != 1) |
| 1247 | return false; |
| 1248 | |
| 1249 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 1250 | return false; |
| 1251 | |
Daniel Dunbar | 01eb9b9 | 2009-10-18 21:17:35 +0000 | [diff] [blame] | 1252 | return SD->getIdentifier()->getName() == Name; |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1255 | bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) { |
| 1256 | // <substitution> ::= St # ::std:: |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1257 | if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) { |
John McCall | 9aeed32 | 2009-10-01 00:25:31 +0000 | [diff] [blame] | 1258 | if (isStdNamespace(NS)) { |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1259 | Out << "St"; |
| 1260 | return true; |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) { |
| 1265 | if (!isStdNamespace(TD->getDeclContext())) |
| 1266 | return false; |
| 1267 | |
| 1268 | // <substitution> ::= Sa # ::std::allocator |
| 1269 | if (TD->getIdentifier()->isStr("allocator")) { |
| 1270 | Out << "Sa"; |
| 1271 | return true; |
| 1272 | } |
Anders Carlsson | 189d59c | 2009-09-26 23:14:39 +0000 | [diff] [blame] | 1273 | |
| 1274 | // <<substitution> ::= Sb # ::std::basic_string |
| 1275 | if (TD->getIdentifier()->isStr("basic_string")) { |
| 1276 | Out << "Sb"; |
| 1277 | return true; |
| 1278 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1279 | } |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1280 | |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1281 | if (const ClassTemplateSpecializationDecl *SD = |
| 1282 | dyn_cast<ClassTemplateSpecializationDecl>(ND)) { |
| 1283 | // <substitution> ::= Ss # ::std::basic_string<char, |
| 1284 | // ::std::char_traits<char>, |
| 1285 | // ::std::allocator<char> > |
| 1286 | if (SD->getIdentifier()->isStr("basic_string")) { |
| 1287 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 1288 | |
| 1289 | if (TemplateArgs.size() != 3) |
| 1290 | return false; |
| 1291 | |
| 1292 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 1293 | return false; |
| 1294 | |
| 1295 | if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits")) |
| 1296 | return false; |
| 1297 | |
| 1298 | if (!isCharSpecialization(TemplateArgs[2].getAsType(), "allocator")) |
| 1299 | return false; |
| 1300 | |
| 1301 | Out << "Ss"; |
| 1302 | return true; |
| 1303 | } |
Anders Carlsson | 8f8fd8e | 2009-10-08 17:20:26 +0000 | [diff] [blame] | 1304 | |
| 1305 | // <substitution> ::= So # ::std::basic_ostream<char, |
| 1306 | // ::std::char_traits<char> > |
| 1307 | if (SD->getIdentifier()->isStr("basic_ostream")) { |
| 1308 | const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs(); |
| 1309 | |
| 1310 | if (TemplateArgs.size() != 2) |
| 1311 | return false; |
| 1312 | |
| 1313 | if (!isCharType(TemplateArgs[0].getAsType())) |
| 1314 | return false; |
| 1315 | |
| 1316 | if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits")) |
| 1317 | return false; |
| 1318 | |
| 1319 | Out << "So"; |
| 1320 | return true; |
| 1321 | } |
Anders Carlsson | f514b54 | 2009-09-27 00:12:57 +0000 | [diff] [blame] | 1322 | } |
Anders Carlsson | 8c03155 | 2009-09-26 23:10:05 +0000 | [diff] [blame] | 1323 | return false; |
Anders Carlsson | e7c8cb6 | 2009-09-26 20:53:44 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1326 | void CXXNameMangler::addSubstitution(QualType T) { |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1327 | if (!T.getCVRQualifiers()) { |
| 1328 | if (const RecordType *RT = T->getAs<RecordType>()) { |
| 1329 | addSubstitution(RT->getDecl()); |
| 1330 | return; |
| 1331 | } |
| 1332 | } |
| 1333 | |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1334 | uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr()); |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1335 | addSubstitution(TypePtr); |
| 1336 | } |
| 1337 | |
| 1338 | void CXXNameMangler::addSubstitution(uintptr_t Ptr) { |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1339 | unsigned SeqID = Substitutions.size(); |
| 1340 | |
Anders Carlsson | d3a932a | 2009-09-17 03:53:28 +0000 | [diff] [blame] | 1341 | assert(!Substitutions.count(Ptr) && "Substitution already exists!"); |
| 1342 | Substitutions[Ptr] = SeqID; |
Anders Carlsson | 7696737 | 2009-09-17 00:43:46 +0000 | [diff] [blame] | 1343 | } |
| 1344 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1345 | namespace clang { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1346 | /// \brief Mangles the name of the declaration D and emits that name to the |
| 1347 | /// given output stream. |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1348 | /// |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1349 | /// If the declaration D requires a mangled name, this routine will emit that |
| 1350 | /// mangled name to \p os and return true. Otherwise, \p os will be unchanged |
| 1351 | /// and this routine will return false. In this case, the caller should just |
| 1352 | /// emit the identifier of the declaration (\c D->getIdentifier()) as its |
| 1353 | /// name. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1354 | bool mangleName(MangleContext &Context, const NamedDecl *D, |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1355 | llvm::raw_ostream &os) { |
Anders Carlsson | 578aa64 | 2009-05-03 16:51:04 +0000 | [diff] [blame] | 1356 | assert(!isa<CXXConstructorDecl>(D) && |
| 1357 | "Use mangleCXXCtor for constructor decls!"); |
| 1358 | assert(!isa<CXXDestructorDecl>(D) && |
| 1359 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1360 | |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1361 | PrettyStackTraceDecl CrashInfo(const_cast<NamedDecl *>(D), SourceLocation(), |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1362 | Context.getASTContext().getSourceManager(), |
Anders Carlsson | d99edc4 | 2009-09-26 03:55:37 +0000 | [diff] [blame] | 1363 | "Mangling declaration"); |
| 1364 | |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1365 | CXXNameMangler Mangler(Context, os); |
Douglas Gregor | 457e281 | 2009-10-28 16:31:34 +0000 | [diff] [blame^] | 1366 | if (!Mangler.mangle(D)) |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1367 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1368 | |
Douglas Gregor | 6ec3668 | 2009-02-18 23:53:56 +0000 | [diff] [blame] | 1369 | os.flush(); |
| 1370 | return true; |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1371 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1373 | /// \brief Mangles the a thunk with the offset n for the declaration D and |
| 1374 | /// emits that name to the given output stream. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1375 | void mangleThunk(MangleContext &Context, const FunctionDecl *FD, |
| 1376 | int64_t nv, int64_t v, llvm::raw_ostream &os) { |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1377 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1378 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1379 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1380 | |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1381 | CXXNameMangler Mangler(Context, os); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1382 | Mangler.mangleThunk(FD, nv, v); |
Mike Stump | 141c5af | 2009-09-02 00:25:38 +0000 | [diff] [blame] | 1383 | os.flush(); |
| 1384 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1386 | /// \brief Mangles the a covariant thunk for the declaration D and emits that |
| 1387 | /// name to the given output stream. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1388 | void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD, |
| 1389 | int64_t nv_t, int64_t v_t, |
| 1390 | int64_t nv_r, int64_t v_r, |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1391 | llvm::raw_ostream &os) { |
| 1392 | // FIXME: Hum, we might have to thunk these, fix. |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1393 | assert(!isa<CXXDestructorDecl>(FD) && |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1394 | "Use mangleCXXDtor for destructor decls!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1395 | |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1396 | CXXNameMangler Mangler(Context, os); |
Mike Stump | dec025b | 2009-09-07 04:27:52 +0000 | [diff] [blame] | 1397 | Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r); |
Mike Stump | 9124bcc | 2009-09-02 00:56:18 +0000 | [diff] [blame] | 1398 | os.flush(); |
| 1399 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1400 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1401 | /// mangleGuardVariable - Returns the mangled name for a guard variable |
| 1402 | /// for the passed in VarDecl. |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1403 | void mangleGuardVariable(MangleContext &Context, const VarDecl *D, |
Anders Carlsson | 41aa8c1 | 2009-04-13 18:02:10 +0000 | [diff] [blame] | 1404 | llvm::raw_ostream &os) { |
| 1405 | CXXNameMangler Mangler(Context, os); |
| 1406 | Mangler.mangleGuardVariable(D); |
| 1407 | |
| 1408 | os.flush(); |
| 1409 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1411 | void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D, |
| 1412 | CXXCtorType Type, llvm::raw_ostream &os) { |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1413 | CXXNameMangler Mangler(Context, os); |
| 1414 | Mangler.mangleCXXCtor(D, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | |
Anders Carlsson | 3ac86b5 | 2009-04-15 05:36:58 +0000 | [diff] [blame] | 1416 | os.flush(); |
| 1417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1418 | |
Anders Carlsson | b540491 | 2009-10-07 01:06:45 +0000 | [diff] [blame] | 1419 | void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D, |
| 1420 | CXXDtorType Type, llvm::raw_ostream &os) { |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1421 | CXXNameMangler Mangler(Context, os); |
| 1422 | Mangler.mangleCXXDtor(D, Type); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1423 | |
Anders Carlsson | 27ae536 | 2009-04-17 01:58:57 +0000 | [diff] [blame] | 1424 | os.flush(); |
| 1425 | } |
Douglas Gregor | 5f2bfd4 | 2009-02-13 00:10:09 +0000 | [diff] [blame] | 1426 | |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 1427 | void mangleCXXVtable(MangleContext &Context, const CXXRecordDecl *RD, |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 1428 | llvm::raw_ostream &os) { |
| 1429 | CXXNameMangler Mangler(Context, os); |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 1430 | Mangler.mangleCXXVtable(RD); |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 1431 | |
| 1432 | os.flush(); |
| 1433 | } |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1434 | |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 1435 | void mangleCXXRtti(MangleContext &Context, const CXXRecordDecl *RD, |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1436 | llvm::raw_ostream &os) { |
| 1437 | CXXNameMangler Mangler(Context, os); |
Anders Carlsson | fc3bf4d | 2009-10-11 21:24:51 +0000 | [diff] [blame] | 1438 | Mangler.mangleCXXRtti(RD); |
Mike Stump | 738f8c2 | 2009-07-31 23:15:31 +0000 | [diff] [blame] | 1439 | |
| 1440 | os.flush(); |
| 1441 | } |
Mike Stump | f121677 | 2009-07-31 18:25:34 +0000 | [diff] [blame] | 1442 | } |