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