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