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