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