2011-01-14 02:57:25 +08:00
|
|
|
//===--- ItaniumMangle.cpp - Itanium C++ Name Mangling ----------*- C++ -*-===//
|
2009-02-13 08:10:09 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements C++ name mangling according to the Itanium C++ ABI,
|
|
|
|
// which is used in GCC 3.2 and newer (and many compilers that are
|
|
|
|
// ABI-compatible with GCC):
|
|
|
|
//
|
|
|
|
// http://www.codesourcery.com/public/cxx-abi/abi.html
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-01-14 02:57:25 +08:00
|
|
|
#include "clang/AST/Mangle.h"
|
2009-02-13 08:10:09 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
2009-03-08 06:03:21 +08:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2009-05-16 00:09:15 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2009-09-28 04:11:34 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2011-06-16 07:02:42 +08:00
|
|
|
#include "clang/AST/ExprObjC.h"
|
2011-05-02 06:35:37 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2011-01-14 02:57:25 +08:00
|
|
|
#include "clang/Basic/ABI.h"
|
2009-02-19 07:53:56 +08:00
|
|
|
#include "clang/Basic/SourceManager.h"
|
2011-02-16 06:23:51 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2009-10-07 09:45:02 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2009-02-13 08:10:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-09-05 15:56:18 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-02-05 15:31:37 +08:00
|
|
|
|
|
|
|
#define MANGLE_CHECKER 0
|
|
|
|
|
|
|
|
#if MANGLE_CHECKER
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
using namespace clang;
|
2010-05-27 02:25:27 +08:00
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
namespace {
|
2010-03-04 03:41:08 +08:00
|
|
|
|
2010-10-19 05:28:44 +08:00
|
|
|
static const CXXRecordDecl *GetLocalClassDecl(const NamedDecl *ND) {
|
|
|
|
const DeclContext *DC = dyn_cast<DeclContext>(ND);
|
|
|
|
if (!DC)
|
|
|
|
DC = ND->getDeclContext();
|
|
|
|
while (!DC->isNamespace() && !DC->isTranslationUnit()) {
|
|
|
|
if (isa<FunctionDecl>(DC->getParent()))
|
|
|
|
return dyn_cast<CXXRecordDecl>(DC);
|
|
|
|
DC = DC->getParent();
|
2010-03-04 03:41:08 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
static const FunctionDecl *getStructor(const FunctionDecl *fn) {
|
|
|
|
if (const FunctionTemplateDecl *ftd = fn->getPrimaryTemplate())
|
|
|
|
return ftd->getTemplatedDecl();
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
return fn;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
static const NamedDecl *getStructor(const NamedDecl *decl) {
|
|
|
|
const FunctionDecl *fn = dyn_cast_or_null<FunctionDecl>(decl);
|
|
|
|
return (fn ? getStructor(fn) : decl);
|
2009-11-24 13:36:32 +08:00
|
|
|
}
|
2010-02-04 09:42:13 +08:00
|
|
|
|
|
|
|
static const unsigned UnknownArity = ~0U;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
class ItaniumMangleContext : public MangleContext {
|
|
|
|
llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds;
|
|
|
|
unsigned Discriminator;
|
|
|
|
llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ItaniumMangleContext(ASTContext &Context,
|
|
|
|
Diagnostic &Diags)
|
|
|
|
: MangleContext(Context, Diags) { }
|
|
|
|
|
|
|
|
uint64_t getAnonymousStructId(const TagDecl *TD) {
|
|
|
|
std::pair<llvm::DenseMap<const TagDecl *,
|
|
|
|
uint64_t>::iterator, bool> Result =
|
|
|
|
AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size()));
|
|
|
|
return Result.first->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void startNewFunction() {
|
|
|
|
MangleContext::startNewFunction();
|
|
|
|
mangleInitDiscriminator();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @name Mangler Entry Points
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
bool shouldMangleDeclName(const NamedDecl *D);
|
2011-02-11 09:41:00 +08:00
|
|
|
void mangleName(const NamedDecl *D, llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleThunk(const CXXMethodDecl *MD,
|
|
|
|
const ThunkInfo &Thunk,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
const ThisAdjustment &ThisAdjustment,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleReferenceTemporary(const VarDecl *D,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXVTable(const CXXRecordDecl *RD,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXVTT(const CXXRecordDecl *RD,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
|
|
|
|
const CXXRecordDecl *Type,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &);
|
|
|
|
void mangleCXXRTTI(QualType T, llvm::raw_ostream &);
|
|
|
|
void mangleCXXRTTIName(QualType T, llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
|
2011-02-11 10:52:17 +08:00
|
|
|
void mangleItaniumGuardVariable(const VarDecl *D, llvm::raw_ostream &);
|
2011-01-14 02:57:25 +08:00
|
|
|
|
|
|
|
void mangleInitDiscriminator() {
|
|
|
|
Discriminator = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) {
|
|
|
|
unsigned &discriminator = Uniquifier[ND];
|
|
|
|
if (!discriminator)
|
|
|
|
discriminator = ++Discriminator;
|
|
|
|
if (discriminator == 1)
|
|
|
|
return false;
|
|
|
|
disc = discriminator-2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/// @}
|
|
|
|
};
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
/// CXXNameMangler - Manage the mangling of a single name.
|
2009-11-21 17:12:13 +08:00
|
|
|
class CXXNameMangler {
|
2011-01-14 02:57:25 +08:00
|
|
|
ItaniumMangleContext &Context;
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &Out;
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
/// The "structor" is the top-level declaration being mangled, if
|
|
|
|
/// that's not a template specialization; otherwise it's the pattern
|
|
|
|
/// for that specialization.
|
|
|
|
const NamedDecl *Structor;
|
2009-11-21 17:06:10 +08:00
|
|
|
unsigned StructorType;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-06-02 12:29:50 +08:00
|
|
|
/// SeqID - The next subsitution sequence number.
|
|
|
|
unsigned SeqID;
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
class FunctionTypeDepthState {
|
|
|
|
unsigned Bits;
|
|
|
|
|
|
|
|
enum { InResultTypeMask = 1 };
|
|
|
|
|
|
|
|
public:
|
|
|
|
FunctionTypeDepthState() : Bits(0) {}
|
|
|
|
|
|
|
|
/// The number of function types we're inside.
|
|
|
|
unsigned getDepth() const {
|
|
|
|
return Bits >> 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// True if we're in the return type of the innermost function type.
|
|
|
|
bool isInResultType() const {
|
|
|
|
return Bits & InResultTypeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionTypeDepthState push() {
|
|
|
|
FunctionTypeDepthState tmp = *this;
|
|
|
|
Bits = (Bits & ~InResultTypeMask) + 2;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void enterResultType() {
|
|
|
|
Bits |= InResultTypeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void leaveResultType() {
|
|
|
|
Bits &= ~InResultTypeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop(FunctionTypeDepthState saved) {
|
|
|
|
assert(getDepth() == saved.getDepth() + 1);
|
|
|
|
Bits = saved.Bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
} FunctionTypeDepth;
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
llvm::DenseMap<uintptr_t, unsigned> Substitutions;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
ASTContext &getASTContext() const { return Context.getASTContext(); }
|
|
|
|
|
2009-11-21 17:12:13 +08:00
|
|
|
public:
|
2011-05-02 06:35:37 +08:00
|
|
|
CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_,
|
|
|
|
const NamedDecl *D = 0)
|
|
|
|
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(0),
|
|
|
|
SeqID(0) {
|
|
|
|
// These can't be mangled without a ctor type or dtor type.
|
|
|
|
assert(!D || (!isa<CXXDestructorDecl>(D) &&
|
|
|
|
!isa<CXXConstructorDecl>(D)));
|
|
|
|
}
|
2011-02-11 09:41:00 +08:00
|
|
|
CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_,
|
2009-11-21 17:06:31 +08:00
|
|
|
const CXXConstructorDecl *D, CXXCtorType Type)
|
2011-02-11 07:59:36 +08:00
|
|
|
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
|
2011-05-02 06:35:37 +08:00
|
|
|
SeqID(0) { }
|
2011-02-11 09:41:00 +08:00
|
|
|
CXXNameMangler(ItaniumMangleContext &C, llvm::raw_ostream &Out_,
|
2009-11-21 17:06:31 +08:00
|
|
|
const CXXDestructorDecl *D, CXXDtorType Type)
|
2011-02-11 07:59:36 +08:00
|
|
|
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
|
2011-05-02 06:35:37 +08:00
|
|
|
SeqID(0) { }
|
2009-04-15 13:36:58 +08:00
|
|
|
|
2010-02-05 15:31:37 +08:00
|
|
|
#if MANGLE_CHECKER
|
|
|
|
~CXXNameMangler() {
|
|
|
|
if (Out.str()[0] == '\01')
|
|
|
|
return;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-02-05 15:31:37 +08:00
|
|
|
int status = 0;
|
|
|
|
char *result = abi::__cxa_demangle(Out.str().str().c_str(), 0, 0, &status);
|
|
|
|
assert(status == 0 && "Could not demangle mangled name!");
|
|
|
|
free(result);
|
|
|
|
}
|
|
|
|
#endif
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &getStream() { return Out; }
|
2009-11-21 17:12:13 +08:00
|
|
|
|
2009-11-21 17:17:15 +08:00
|
|
|
void mangle(const NamedDecl *D, llvm::StringRef Prefix = "_Z");
|
2010-03-24 01:17:29 +08:00
|
|
|
void mangleCallOffset(int64_t NonVirtual, int64_t Virtual);
|
2010-07-14 12:20:34 +08:00
|
|
|
void mangleNumber(const llvm::APSInt &I);
|
2009-11-26 10:32:05 +08:00
|
|
|
void mangleNumber(int64_t Number);
|
2010-07-14 12:20:34 +08:00
|
|
|
void mangleFloat(const llvm::APFloat &F);
|
2009-11-21 17:12:13 +08:00
|
|
|
void mangleFunctionEncoding(const FunctionDecl *FD);
|
|
|
|
void mangleName(const NamedDecl *ND);
|
|
|
|
void mangleType(QualType T);
|
2010-05-26 13:11:13 +08:00
|
|
|
void mangleNameOrStandardSubstitution(const NamedDecl *ND);
|
|
|
|
|
2009-11-21 17:12:13 +08:00
|
|
|
private:
|
2009-11-21 17:06:10 +08:00
|
|
|
bool mangleSubstitution(const NamedDecl *ND);
|
|
|
|
bool mangleSubstitution(QualType T);
|
2010-04-28 13:58:56 +08:00
|
|
|
bool mangleSubstitution(TemplateName Template);
|
2009-11-21 17:06:10 +08:00
|
|
|
bool mangleSubstitution(uintptr_t Ptr);
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2011-07-01 08:04:39 +08:00
|
|
|
void mangleExistingSubstitution(QualType type);
|
|
|
|
void mangleExistingSubstitution(TemplateName name);
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
bool mangleStandardSubstitution(const NamedDecl *ND);
|
2009-11-07 12:26:04 +08:00
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
void addSubstitution(const NamedDecl *ND) {
|
|
|
|
ND = cast<NamedDecl>(ND->getCanonicalDecl());
|
2009-09-05 15:56:18 +08:00
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
addSubstitution(reinterpret_cast<uintptr_t>(ND));
|
|
|
|
}
|
|
|
|
void addSubstitution(QualType T);
|
2010-04-28 13:58:56 +08:00
|
|
|
void addSubstitution(TemplateName Template);
|
2009-11-21 17:06:10 +08:00
|
|
|
void addSubstitution(uintptr_t Ptr);
|
|
|
|
|
2011-04-24 16:23:24 +08:00
|
|
|
void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
bool recursive = false);
|
|
|
|
void mangleUnresolvedName(NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
DeclarationName name,
|
2010-02-04 09:42:13 +08:00
|
|
|
unsigned KnownArity = UnknownArity);
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleName(const TemplateDecl *TD,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
|
|
|
unsigned NumTemplateArgs);
|
2010-02-04 09:42:13 +08:00
|
|
|
void mangleUnqualifiedName(const NamedDecl *ND) {
|
|
|
|
mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity);
|
|
|
|
}
|
|
|
|
void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name,
|
|
|
|
unsigned KnownArity);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleUnscopedName(const NamedDecl *ND);
|
|
|
|
void mangleUnscopedTemplateName(const TemplateDecl *ND);
|
2010-04-28 13:58:56 +08:00
|
|
|
void mangleUnscopedTemplateName(TemplateName);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleSourceName(const IdentifierInfo *II);
|
|
|
|
void mangleLocalName(const NamedDecl *ND);
|
2010-03-04 03:41:08 +08:00
|
|
|
void mangleNestedName(const NamedDecl *ND, const DeclContext *DC,
|
|
|
|
bool NoFunction=false);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleNestedName(const TemplateDecl *TD,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
|
|
|
unsigned NumTemplateArgs);
|
2011-04-24 16:23:24 +08:00
|
|
|
void manglePrefix(NestedNameSpecifier *qualifier);
|
2010-03-04 03:41:08 +08:00
|
|
|
void manglePrefix(const DeclContext *DC, bool NoFunction=false);
|
2011-05-04 09:45:19 +08:00
|
|
|
void manglePrefix(QualType type);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleTemplatePrefix(const TemplateDecl *ND);
|
2010-04-23 11:10:43 +08:00
|
|
|
void mangleTemplatePrefix(TemplateName Template);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity);
|
|
|
|
void mangleQualifiers(Qualifiers Quals);
|
2011-01-27 01:36:28 +08:00
|
|
|
void mangleRefQualifier(RefQualifierKind RefQualifier);
|
2009-11-21 17:06:10 +08:00
|
|
|
|
2009-12-10 11:14:39 +08:00
|
|
|
void mangleObjCMethodName(const ObjCMethodDecl *MD);
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
// Declare manglers for every type class.
|
2009-09-05 15:56:18 +08:00
|
|
|
#define ABSTRACT_TYPE(CLASS, PARENT)
|
|
|
|
#define NON_CANONICAL_TYPE(CLASS, PARENT)
|
|
|
|
#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleType(const TagType*);
|
2010-07-14 14:43:17 +08:00
|
|
|
void mangleType(TemplateName);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleBareFunctionType(const FunctionType *T,
|
|
|
|
bool MangleReturnType);
|
2010-11-16 08:32:18 +08:00
|
|
|
void mangleNeonVectorType(const VectorType *T);
|
2009-12-14 09:45:37 +08:00
|
|
|
|
|
|
|
void mangleIntegerLiteral(QualType T, const llvm::APSInt &Value);
|
2011-04-24 16:23:24 +08:00
|
|
|
void mangleMemberExpr(const Expr *base, bool isArrow,
|
|
|
|
NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
DeclarationName name,
|
|
|
|
unsigned knownArity);
|
2010-08-19 03:18:59 +08:00
|
|
|
void mangleExpression(const Expr *E, unsigned Arity = UnknownArity);
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleCXXCtorType(CXXCtorType T);
|
|
|
|
void mangleCXXDtorType(CXXDtorType T);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-20 08:17:19 +08:00
|
|
|
void mangleTemplateArgs(const ExplicitTemplateArgumentList &TemplateArgs);
|
2010-04-23 11:10:43 +08:00
|
|
|
void mangleTemplateArgs(TemplateName Template,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
2010-05-05 23:23:54 +08:00
|
|
|
unsigned NumTemplateArgs);
|
2010-03-11 22:07:00 +08:00
|
|
|
void mangleTemplateArgs(const TemplateParameterList &PL,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
2009-11-21 17:06:10 +08:00
|
|
|
unsigned NumTemplateArgs);
|
2010-03-11 22:07:00 +08:00
|
|
|
void mangleTemplateArgs(const TemplateParameterList &PL,
|
|
|
|
const TemplateArgumentList &AL);
|
|
|
|
void mangleTemplateArg(const NamedDecl *P, const TemplateArgument &A);
|
2011-05-04 09:45:19 +08:00
|
|
|
void mangleUnresolvedTemplateArgs(const TemplateArgument *args,
|
|
|
|
unsigned numArgs);
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
void mangleTemplateParameter(unsigned Index);
|
2011-05-02 06:35:37 +08:00
|
|
|
|
|
|
|
void mangleFunctionParam(const ParmVarDecl *parm);
|
2009-11-21 17:06:10 +08:00
|
|
|
};
|
2011-01-14 02:57:25 +08:00
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-04-02 23:51:53 +08:00
|
|
|
static bool isInCLinkageSpecification(const Decl *D) {
|
2009-10-29 00:31:34 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2009-09-09 23:08:12 +08:00
|
|
|
for (const DeclContext *DC = D->getDeclContext();
|
2009-04-02 23:51:53 +08:00
|
|
|
!DC->isTranslationUnit(); DC = DC->getParent()) {
|
2009-09-09 23:08:12 +08:00
|
|
|
if (const LinkageSpecDecl *Linkage = dyn_cast<LinkageSpecDecl>(DC))
|
2009-04-02 23:51:53 +08:00
|
|
|
return Linkage->getLanguage() == LinkageSpecDecl::lang_c;
|
2009-03-21 16:24:40 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-04-02 23:51:53 +08:00
|
|
|
return false;
|
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
bool ItaniumMangleContext::shouldMangleDeclName(const NamedDecl *D) {
|
2009-11-21 17:14:52 +08:00
|
|
|
// In C, functions with no attributes never need to be mangled. Fastpath them.
|
|
|
|
if (!getASTContext().getLangOptions().CPlusPlus && !D->hasAttrs())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Any decl can be declared with __asm("foo") on it, and this takes precedence
|
|
|
|
// over all other naming in the .o file.
|
|
|
|
if (D->hasAttr<AsmLabelAttr>())
|
|
|
|
return true;
|
|
|
|
|
2009-09-02 08:25:38 +08:00
|
|
|
// Clang's "overloadable" attribute extension to C/C++ implies name mangling
|
2009-11-07 15:15:03 +08:00
|
|
|
// (always) as does passing a C++ member function and a function
|
|
|
|
// whose name is not a simple identifier.
|
2009-11-21 17:14:52 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (FD && (FD->hasAttr<OverloadableAttr>() || isa<CXXMethodDecl>(FD) ||
|
|
|
|
!FD->getDeclName().isIdentifier()))
|
|
|
|
return true;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-21 17:14:52 +08:00
|
|
|
// Otherwise, no mangling is done outside C++ mode.
|
|
|
|
if (!getASTContext().getLangOptions().CPlusPlus)
|
|
|
|
return false;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-24 11:04:27 +08:00
|
|
|
// Variables at global scope with non-internal linkage are not mangled
|
2009-12-03 04:32:49 +08:00
|
|
|
if (!FD) {
|
|
|
|
const DeclContext *DC = D->getDeclContext();
|
|
|
|
// Check for extern variable declared locally.
|
2010-07-01 02:57:21 +08:00
|
|
|
if (DC->isFunctionOrMethod() && D->hasLinkage())
|
2009-12-03 04:32:49 +08:00
|
|
|
while (!DC->isNamespace() && !DC->isTranslationUnit())
|
|
|
|
DC = DC->getParent();
|
When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.
This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:
- Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
when the declaration is in an anonymous namespace.
- Added Type::getLinkage() to determine the linkage of a type, which
is defined as the minimum linkage of the types (when we're dealing
with a compound type that is not a struct/class/union).
- Extended NamedDecl::getLinkage() to consider the linkage of the
template arguments and template parameters of function template
specializations and class template specializations.
- Taught code generation to rely on NamedDecl::getLinkage() when
determining the linkage of variables and functions, also
considering the linkage of the types of those variables and
functions (C++ only). Map UniqueExternalLinkage to internal
linkage, taking out the explicit checks for
isInAnonymousNamespace().
This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:
LLVM:
Expected Passes : 4006
Expected Failures : 32
Unsupported Tests : 40
Unexpected Failures: 736
Clang:
Expected Passes : 1903
Expected Failures : 14
Unexpected Failures: 75
Overall:
Expected Passes : 5909
Expected Failures : 46
Unsupported Tests : 40
Unexpected Failures: 811
Still to do:
- Improve testing
- Check whether we should allow the presence of types with
InternalLinkage (in addition to UniqueExternalLinkage) given
variables/functions internal linkage in C++, as mentioned in
PR5792.
- Determine how expensive the getLinkage() calls are in practice;
consider caching the result in NamedDecl.
- Assess the feasibility of Chris's idea in comment #1 of PR5792.
llvm-svn: 95216
2010-02-03 17:33:45 +08:00
|
|
|
if (DC->isTranslationUnit() && D->getLinkage() != InternalLinkage)
|
2009-12-03 04:32:49 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-19 04:49:59 +08:00
|
|
|
// Class members are always mangled.
|
|
|
|
if (D->getDeclContext()->isRecord())
|
|
|
|
return true;
|
|
|
|
|
2009-12-03 04:32:49 +08:00
|
|
|
// C functions and "main" are not mangled.
|
|
|
|
if ((FD && FD->isMain()) || isInCLinkageSpecification(D))
|
2009-11-21 17:14:52 +08:00
|
|
|
return false;
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2009-03-21 14:19:20 +08:00
|
|
|
return true;
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 17:17:15 +08:00
|
|
|
void CXXNameMangler::mangle(const NamedDecl *D, llvm::StringRef Prefix) {
|
2009-09-02 08:25:38 +08:00
|
|
|
// Any decl can be declared with __asm("foo") on it, and this takes precedence
|
|
|
|
// over all other naming in the .o file.
|
2009-06-30 10:34:44 +08:00
|
|
|
if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
|
2009-04-02 23:51:53 +08:00
|
|
|
// If we have an asm name, then we use it as the mangling.
|
2011-02-16 06:23:51 +08:00
|
|
|
|
|
|
|
// Adding the prefix can cause problems when one file has a "foo" and
|
|
|
|
// another has a "\01foo". That is known to happen on ELF with the
|
|
|
|
// tricks normally used for producing aliases (PR9177). Fortunately the
|
|
|
|
// llvm mangler on ELF is a nop, so we can just avoid adding the \01
|
2011-04-06 20:29:09 +08:00
|
|
|
// marker. We also avoid adding the marker if this is an alias for an
|
|
|
|
// LLVM intrinsic.
|
2011-02-16 06:23:51 +08:00
|
|
|
llvm::StringRef UserLabelPrefix =
|
|
|
|
getASTContext().Target.getUserLabelPrefix();
|
2011-04-06 20:29:09 +08:00
|
|
|
if (!UserLabelPrefix.empty() && !ALA->getLabel().startswith("llvm."))
|
2011-02-16 06:23:51 +08:00
|
|
|
Out << '\01'; // LLVM IR Marker for __asm("foo")
|
|
|
|
|
2009-04-02 23:51:53 +08:00
|
|
|
Out << ALA->getLabel();
|
2009-11-21 17:14:52 +08:00
|
|
|
return;
|
2009-04-02 23:51:53 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-01-24 11:04:27 +08:00
|
|
|
// <mangled-name> ::= _Z <encoding>
|
2009-04-02 23:51:53 +08:00
|
|
|
// ::= <data name>
|
|
|
|
// ::= <special-name>
|
2009-11-21 17:17:15 +08:00
|
|
|
Out << Prefix;
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
2009-11-21 17:14:52 +08:00
|
|
|
mangleFunctionEncoding(FD);
|
2010-03-11 22:07:00 +08:00
|
|
|
else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
|
|
|
|
mangleName(VD);
|
2009-11-21 17:17:15 +08:00
|
|
|
else
|
2010-03-11 22:07:00 +08:00
|
|
|
mangleName(cast<FieldDecl>(D));
|
2009-04-02 23:51:53 +08:00
|
|
|
}
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
|
|
|
|
// <encoding> ::= <function name> <bare-function-type>
|
|
|
|
mangleName(FD);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-21 17:17:15 +08:00
|
|
|
// Don't mangle in the type if this isn't a decl we should typically mangle.
|
|
|
|
if (!Context.shouldMangleDeclName(FD))
|
|
|
|
return;
|
|
|
|
|
2009-09-02 08:25:38 +08:00
|
|
|
// Whether the mangling of a function type includes the return type depends on
|
|
|
|
// the context and the nature of the function. The rules for deciding whether
|
|
|
|
// the return type is included are:
|
2009-09-09 23:08:12 +08:00
|
|
|
//
|
2009-06-30 06:39:32 +08:00
|
|
|
// 1. Template functions (names or types) have return types encoded, with
|
|
|
|
// the exceptions listed below.
|
2009-09-09 23:08:12 +08:00
|
|
|
// 2. Function types not appearing as part of a function name mangling,
|
2009-06-30 06:39:32 +08:00
|
|
|
// e.g. parameters, pointer types, etc., have return type encoded, with the
|
|
|
|
// exceptions listed below.
|
|
|
|
// 3. Non-template function names do not have return types encoded.
|
|
|
|
//
|
2009-09-02 08:25:38 +08:00
|
|
|
// The exceptions mentioned in (1) and (2) above, for which the return type is
|
|
|
|
// never included, are
|
2009-06-30 06:39:32 +08:00
|
|
|
// 1. Constructors.
|
|
|
|
// 2. Destructors.
|
|
|
|
// 3. Conversion operator functions, e.g. operator int.
|
|
|
|
bool MangleReturnType = false;
|
2009-09-17 11:46:43 +08:00
|
|
|
if (FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate()) {
|
|
|
|
if (!(isa<CXXConstructorDecl>(FD) || isa<CXXDestructorDecl>(FD) ||
|
|
|
|
isa<CXXConversionDecl>(FD)))
|
|
|
|
MangleReturnType = true;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 11:46:43 +08:00
|
|
|
// Mangle the type of the primary template.
|
|
|
|
FD = PrimaryTemplate->getTemplatedDecl();
|
|
|
|
}
|
|
|
|
|
2011-07-12 12:42:08 +08:00
|
|
|
mangleBareFunctionType(FD->getType()->getAs<FunctionType>(),
|
|
|
|
MangleReturnType);
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-12-04 14:23:23 +08:00
|
|
|
static const DeclContext *IgnoreLinkageSpecDecls(const DeclContext *DC) {
|
|
|
|
while (isa<LinkageSpecDecl>(DC)) {
|
|
|
|
DC = DC->getParent();
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-04 14:23:23 +08:00
|
|
|
return DC;
|
|
|
|
}
|
|
|
|
|
2010-06-02 23:58:27 +08:00
|
|
|
/// isStd - Return whether a given namespace is the 'std' namespace.
|
|
|
|
static bool isStd(const NamespaceDecl *NS) {
|
|
|
|
if (!IgnoreLinkageSpecDecls(NS->getParent())->isTranslationUnit())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const IdentifierInfo *II = NS->getOriginalNamespace()->getIdentifier();
|
|
|
|
return II && II->isStr("std");
|
|
|
|
}
|
|
|
|
|
2009-12-04 14:23:23 +08:00
|
|
|
// isStdNamespace - Return whether a given decl context is a toplevel 'std'
|
|
|
|
// namespace.
|
2009-11-21 17:11:45 +08:00
|
|
|
static bool isStdNamespace(const DeclContext *DC) {
|
2009-12-04 14:23:23 +08:00
|
|
|
if (!DC->isNamespace())
|
|
|
|
return false;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-04 14:23:23 +08:00
|
|
|
return isStd(cast<NamespaceDecl>(DC));
|
2009-11-21 17:11:45 +08:00
|
|
|
}
|
|
|
|
|
2009-09-26 11:24:57 +08:00
|
|
|
static const TemplateDecl *
|
|
|
|
isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) {
|
2009-09-19 03:00:18 +08:00
|
|
|
// Check if we have a function template.
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)){
|
2009-09-26 11:24:57 +08:00
|
|
|
if (const TemplateDecl *TD = FD->getPrimaryTemplate()) {
|
2009-09-19 03:00:18 +08:00
|
|
|
TemplateArgs = FD->getTemplateSpecializationArgs();
|
2009-09-26 11:24:57 +08:00
|
|
|
return TD;
|
2009-09-19 03:00:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-19 03:44:50 +08:00
|
|
|
// Check if we have a class template.
|
|
|
|
if (const ClassTemplateSpecializationDecl *Spec =
|
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
|
|
|
|
TemplateArgs = &Spec->getTemplateArgs();
|
2009-09-26 11:24:57 +08:00
|
|
|
return Spec->getSpecializedTemplate();
|
2009-09-19 03:44:50 +08:00
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-19 03:00:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleName(const NamedDecl *ND) {
|
|
|
|
// <name> ::= <nested-name>
|
|
|
|
// ::= <unscoped-name>
|
|
|
|
// ::= <unscoped-template-name> <template-args>
|
2009-09-17 11:17:01 +08:00
|
|
|
// ::= <local-name>
|
2009-02-13 08:10:09 +08:00
|
|
|
//
|
2009-09-18 00:12:20 +08:00
|
|
|
const DeclContext *DC = ND->getDeclContext();
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-03 04:32:49 +08:00
|
|
|
// If this is an extern variable declared locally, the relevant DeclContext
|
|
|
|
// is that of the containing namespace, or the translation unit.
|
|
|
|
if (isa<FunctionDecl>(DC) && ND->hasLinkage())
|
|
|
|
while (!DC->isNamespace() && !DC->isTranslationUnit())
|
|
|
|
DC = DC->getParent();
|
2010-10-19 05:28:44 +08:00
|
|
|
else if (GetLocalClassDecl(ND)) {
|
|
|
|
mangleLocalName(ND);
|
|
|
|
return;
|
|
|
|
}
|
2009-12-03 04:32:49 +08:00
|
|
|
|
2009-09-23 01:23:30 +08:00
|
|
|
while (isa<LinkageSpecDecl>(DC))
|
2009-09-18 00:12:20 +08:00
|
|
|
DC = DC->getParent();
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-18 00:12:20 +08:00
|
|
|
if (DC->isTranslationUnit() || isStdNamespace(DC)) {
|
2009-09-19 03:00:18 +08:00
|
|
|
// Check if we have a template.
|
|
|
|
const TemplateArgumentList *TemplateArgs = 0;
|
2009-09-27 03:45:45 +08:00
|
|
|
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
|
2009-09-19 03:00:18 +08:00
|
|
|
mangleUnscopedTemplateName(TD);
|
2010-03-11 22:07:00 +08:00
|
|
|
TemplateParameterList *TemplateParameters = TD->getTemplateParameters();
|
|
|
|
mangleTemplateArgs(*TemplateParameters, *TemplateArgs);
|
2009-09-19 03:00:18 +08:00
|
|
|
return;
|
2009-09-18 12:29:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
mangleUnscopedName(ND);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-12-10 11:14:39 +08:00
|
|
|
if (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)) {
|
2009-04-03 00:24:45 +08:00
|
|
|
mangleLocalName(ND);
|
2009-09-18 12:29:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-12-03 04:32:49 +08:00
|
|
|
mangleNestedName(ND, DC);
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
void CXXNameMangler::mangleName(const TemplateDecl *TD,
|
2009-09-18 10:42:01 +08:00
|
|
|
const TemplateArgument *TemplateArgs,
|
|
|
|
unsigned NumTemplateArgs) {
|
2009-12-04 14:23:23 +08:00
|
|
|
const DeclContext *DC = IgnoreLinkageSpecDecls(TD->getDeclContext());
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-18 10:42:01 +08:00
|
|
|
if (DC->isTranslationUnit() || isStdNamespace(DC)) {
|
2009-09-27 03:45:45 +08:00
|
|
|
mangleUnscopedTemplateName(TD);
|
2010-03-11 22:07:00 +08:00
|
|
|
TemplateParameterList *TemplateParameters = TD->getTemplateParameters();
|
|
|
|
mangleTemplateArgs(*TemplateParameters, TemplateArgs, NumTemplateArgs);
|
2009-09-18 10:42:01 +08:00
|
|
|
} else {
|
|
|
|
mangleNestedName(TD, TemplateArgs, NumTemplateArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-17 11:17:01 +08:00
|
|
|
void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) {
|
|
|
|
// <unscoped-name> ::= <unqualified-name>
|
|
|
|
// ::= St <unqualified-name> # ::std::
|
|
|
|
if (isStdNamespace(ND->getDeclContext()))
|
|
|
|
Out << "St";
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 11:17:01 +08:00
|
|
|
mangleUnqualifiedName(ND);
|
|
|
|
}
|
|
|
|
|
2009-09-27 03:45:45 +08:00
|
|
|
void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) {
|
2009-09-17 11:17:01 +08:00
|
|
|
// <unscoped-template-name> ::= <unscoped-name>
|
|
|
|
// ::= <substitution>
|
2009-09-18 10:42:01 +08:00
|
|
|
if (mangleSubstitution(ND))
|
2009-09-17 12:02:31 +08:00
|
|
|
return;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-02-06 04:45:00 +08:00
|
|
|
// <template-template-param> ::= <template-param>
|
|
|
|
if (const TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(ND)) {
|
|
|
|
mangleTemplateParameter(TTP->getIndex());
|
|
|
|
return;
|
2010-03-13 18:17:05 +08:00
|
|
|
}
|
2010-02-06 04:45:00 +08:00
|
|
|
|
2009-09-27 04:13:56 +08:00
|
|
|
mangleUnscopedName(ND->getTemplatedDecl());
|
2009-09-18 10:42:01 +08:00
|
|
|
addSubstitution(ND);
|
2009-09-17 11:17:01 +08:00
|
|
|
}
|
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) {
|
|
|
|
// <unscoped-template-name> ::= <unscoped-name>
|
|
|
|
// ::= <substitution>
|
|
|
|
if (TemplateDecl *TD = Template.getAsTemplateDecl())
|
|
|
|
return mangleUnscopedTemplateName(TD);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
if (mangleSubstitution(Template))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// FIXME: How to cope with operators here?
|
|
|
|
DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
|
|
|
|
assert(Dependent && "Not a dependent template name?");
|
|
|
|
if (!Dependent->isIdentifier()) {
|
|
|
|
// FIXME: We can't possibly know the arity of the operator here!
|
|
|
|
Diagnostic &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
|
|
|
|
"cannot mangle dependent operator name");
|
2010-11-19 04:06:41 +08:00
|
|
|
Diags.Report(DiagID);
|
2010-04-28 13:58:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
mangleSourceName(Dependent->getIdentifier());
|
|
|
|
addSubstitution(Template);
|
|
|
|
}
|
|
|
|
|
2011-04-24 11:07:16 +08:00
|
|
|
void CXXNameMangler::mangleFloat(const llvm::APFloat &f) {
|
|
|
|
// ABI:
|
|
|
|
// Floating-point literals are encoded using a fixed-length
|
|
|
|
// lowercase hexadecimal string corresponding to the internal
|
|
|
|
// representation (IEEE on Itanium), high-order bytes first,
|
|
|
|
// without leading zeroes. For example: "Lf bf800000 E" is -1.0f
|
|
|
|
// on Itanium.
|
|
|
|
// APInt::toString uses uppercase hexadecimal, and it's not really
|
|
|
|
// worth embellishing that interface for this use case, so we just
|
|
|
|
// do a second pass to lowercase things.
|
|
|
|
typedef llvm::SmallString<20> buffer_t;
|
|
|
|
buffer_t buffer;
|
|
|
|
f.bitcastToAPInt().toString(buffer, 16, false);
|
|
|
|
|
|
|
|
for (buffer_t::iterator i = buffer.begin(), e = buffer.end(); i != e; ++i)
|
|
|
|
if (isupper(*i)) *i = tolower(*i);
|
|
|
|
|
|
|
|
Out.write(buffer.data(), buffer.size());
|
2010-07-14 12:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleNumber(const llvm::APSInt &Value) {
|
|
|
|
if (Value.isSigned() && Value.isNegative()) {
|
|
|
|
Out << 'n';
|
|
|
|
Value.abs().print(Out, true);
|
|
|
|
} else
|
|
|
|
Value.print(Out, Value.isSigned());
|
|
|
|
}
|
|
|
|
|
2009-11-26 10:32:05 +08:00
|
|
|
void CXXNameMangler::mangleNumber(int64_t Number) {
|
|
|
|
// <number> ::= [n] <non-negative decimal integer>
|
|
|
|
if (Number < 0) {
|
|
|
|
Out << 'n';
|
|
|
|
Number = -Number;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << Number;
|
|
|
|
}
|
|
|
|
|
2010-03-24 01:17:29 +08:00
|
|
|
void CXXNameMangler::mangleCallOffset(int64_t NonVirtual, int64_t Virtual) {
|
2009-09-02 08:25:38 +08:00
|
|
|
// <call-offset> ::= h <nv-offset> _
|
|
|
|
// ::= v <v-offset> _
|
|
|
|
// <nv-offset> ::= <offset number> # non-virtual base override
|
2009-11-26 10:32:05 +08:00
|
|
|
// <v-offset> ::= <offset number> _ <virtual offset number>
|
2009-09-02 08:25:38 +08:00
|
|
|
// # virtual base override, with vcall offset
|
2010-03-24 01:17:29 +08:00
|
|
|
if (!Virtual) {
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << 'h';
|
2010-03-24 01:17:29 +08:00
|
|
|
mangleNumber(NonVirtual);
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << '_';
|
|
|
|
return;
|
2009-09-02 08:25:38 +08:00
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << 'v';
|
2010-03-24 01:17:29 +08:00
|
|
|
mangleNumber(NonVirtual);
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << '_';
|
2010-03-24 01:17:29 +08:00
|
|
|
mangleNumber(Virtual);
|
2009-11-26 10:32:05 +08:00
|
|
|
Out << '_';
|
2009-09-02 08:56:18 +08:00
|
|
|
}
|
|
|
|
|
2011-05-04 09:45:19 +08:00
|
|
|
void CXXNameMangler::manglePrefix(QualType type) {
|
2011-04-24 16:23:24 +08:00
|
|
|
if (const TemplateSpecializationType *TST =
|
|
|
|
type->getAs<TemplateSpecializationType>()) {
|
|
|
|
if (!mangleSubstitution(QualType(TST, 0))) {
|
|
|
|
mangleTemplatePrefix(TST->getTemplateName());
|
|
|
|
|
|
|
|
// FIXME: GCC does not appear to mangle the template arguments when
|
|
|
|
// the template in question is a dependent template name. Should we
|
|
|
|
// emulate that badness?
|
|
|
|
mangleTemplateArgs(TST->getTemplateName(), TST->getArgs(),
|
|
|
|
TST->getNumArgs());
|
|
|
|
addSubstitution(QualType(TST, 0));
|
|
|
|
}
|
|
|
|
} else if (const DependentTemplateSpecializationType *DTST
|
|
|
|
= type->getAs<DependentTemplateSpecializationType>()) {
|
|
|
|
TemplateName Template
|
|
|
|
= getASTContext().getDependentTemplateName(DTST->getQualifier(),
|
|
|
|
DTST->getIdentifier());
|
|
|
|
mangleTemplatePrefix(Template);
|
|
|
|
|
|
|
|
// FIXME: GCC does not appear to mangle the template arguments when
|
|
|
|
// the template in question is a dependent template name. Should we
|
|
|
|
// emulate that badness?
|
|
|
|
mangleTemplateArgs(Template, DTST->getArgs(), DTST->getNumArgs());
|
|
|
|
} else {
|
|
|
|
// We use the QualType mangle type variant here because it handles
|
|
|
|
// substitutions.
|
|
|
|
mangleType(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Mangle everything prior to the base-unresolved-name in an unresolved-name.
|
|
|
|
///
|
|
|
|
/// \param firstQualifierLookup - the entity found by unqualified lookup
|
|
|
|
/// for the first name in the qualifier, if this is for a member expression
|
|
|
|
/// \param recursive - true if this is being called recursively,
|
|
|
|
/// i.e. if there is more prefix "to the right".
|
|
|
|
void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
bool recursive) {
|
|
|
|
|
|
|
|
// x, ::x
|
|
|
|
// <unresolved-name> ::= [gs] <base-unresolved-name>
|
|
|
|
|
|
|
|
// T::x / decltype(p)::x
|
|
|
|
// <unresolved-name> ::= sr <unresolved-type> <base-unresolved-name>
|
|
|
|
|
|
|
|
// T::N::x /decltype(p)::N::x
|
|
|
|
// <unresolved-name> ::= srN <unresolved-type> <unresolved-qualifier-level>+ E
|
|
|
|
// <base-unresolved-name>
|
|
|
|
|
|
|
|
// A::x, N::y, A<T>::z; "gs" means leading "::"
|
|
|
|
// <unresolved-name> ::= [gs] sr <unresolved-qualifier-level>+ E
|
|
|
|
// <base-unresolved-name>
|
|
|
|
|
|
|
|
switch (qualifier->getKind()) {
|
2010-02-04 09:42:13 +08:00
|
|
|
case NestedNameSpecifier::Global:
|
2011-04-24 16:23:24 +08:00
|
|
|
Out << "gs";
|
|
|
|
|
|
|
|
// We want an 'sr' unless this is the entire NNS.
|
|
|
|
if (recursive)
|
|
|
|
Out << "sr";
|
|
|
|
|
|
|
|
// We never want an 'E' here.
|
|
|
|
return;
|
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
case NestedNameSpecifier::Namespace:
|
2011-04-24 16:23:24 +08:00
|
|
|
if (qualifier->getPrefix())
|
|
|
|
mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup,
|
|
|
|
/*recursive*/ true);
|
|
|
|
else
|
|
|
|
Out << "sr";
|
|
|
|
mangleSourceName(qualifier->getAsNamespace()->getIdentifier());
|
2010-02-04 09:42:13 +08:00
|
|
|
break;
|
2011-02-24 10:36:08 +08:00
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
2011-04-24 16:23:24 +08:00
|
|
|
if (qualifier->getPrefix())
|
|
|
|
mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup,
|
|
|
|
/*recursive*/ true);
|
|
|
|
else
|
|
|
|
Out << "sr";
|
|
|
|
mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier());
|
2011-02-24 10:36:08 +08:00
|
|
|
break;
|
2011-04-24 16:23:24 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
case NestedNameSpecifier::TypeSpec:
|
2010-03-17 12:28:11 +08:00
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate: {
|
2011-05-04 09:45:19 +08:00
|
|
|
const Type *type = qualifier->getAsType();
|
2010-03-17 12:28:11 +08:00
|
|
|
|
2011-05-04 09:45:19 +08:00
|
|
|
// We only want to use an unresolved-type encoding if this is one of:
|
|
|
|
// - a decltype
|
|
|
|
// - a template type parameter
|
|
|
|
// - a template template parameter with arguments
|
|
|
|
// In all of these cases, we should have no prefix.
|
|
|
|
if (qualifier->getPrefix()) {
|
|
|
|
mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup,
|
|
|
|
/*recursive*/ true);
|
|
|
|
} else {
|
|
|
|
// Otherwise, all the cases want this.
|
|
|
|
Out << "sr";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only certain other types are valid as prefixes; enumerate them.
|
2011-06-29 00:49:23 +08:00
|
|
|
switch (type->getTypeClass()) {
|
|
|
|
case Type::Builtin:
|
|
|
|
case Type::Complex:
|
|
|
|
case Type::Pointer:
|
|
|
|
case Type::BlockPointer:
|
|
|
|
case Type::LValueReference:
|
|
|
|
case Type::RValueReference:
|
|
|
|
case Type::MemberPointer:
|
|
|
|
case Type::ConstantArray:
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
case Type::VariableArray:
|
|
|
|
case Type::DependentSizedArray:
|
|
|
|
case Type::DependentSizedExtVector:
|
|
|
|
case Type::Vector:
|
|
|
|
case Type::ExtVector:
|
|
|
|
case Type::FunctionProto:
|
|
|
|
case Type::FunctionNoProto:
|
|
|
|
case Type::Enum:
|
|
|
|
case Type::Paren:
|
|
|
|
case Type::Elaborated:
|
|
|
|
case Type::Attributed:
|
|
|
|
case Type::Auto:
|
|
|
|
case Type::PackExpansion:
|
|
|
|
case Type::ObjCObject:
|
|
|
|
case Type::ObjCInterface:
|
|
|
|
case Type::ObjCObjectPointer:
|
|
|
|
llvm_unreachable("type is illegal as a nested name specifier");
|
|
|
|
|
2011-07-01 08:04:39 +08:00
|
|
|
case Type::SubstTemplateTypeParmPack:
|
|
|
|
// FIXME: not clear how to mangle this!
|
|
|
|
// template <class T...> class A {
|
|
|
|
// template <class U...> void foo(decltype(T::foo(U())) x...);
|
|
|
|
// };
|
|
|
|
Out << "_SUBSTPACK_";
|
|
|
|
break;
|
|
|
|
|
2011-06-29 00:49:23 +08:00
|
|
|
// <unresolved-type> ::= <template-param>
|
|
|
|
// ::= <decltype>
|
|
|
|
// ::= <template-template-param> <template-args>
|
|
|
|
// (this last is not official yet)
|
|
|
|
case Type::TypeOfExpr:
|
|
|
|
case Type::TypeOf:
|
|
|
|
case Type::Decltype:
|
|
|
|
case Type::TemplateTypeParm:
|
|
|
|
case Type::UnaryTransform:
|
2011-07-01 10:19:08 +08:00
|
|
|
case Type::SubstTemplateTypeParm:
|
2011-06-29 00:49:23 +08:00
|
|
|
unresolvedType:
|
|
|
|
assert(!qualifier->getPrefix());
|
|
|
|
|
|
|
|
// We only get here recursively if we're followed by identifiers.
|
|
|
|
if (recursive) Out << 'N';
|
|
|
|
|
2011-07-01 10:19:08 +08:00
|
|
|
// This seems to do everything we want. It's not really
|
|
|
|
// sanctioned for a substituted template parameter, though.
|
2011-06-29 00:49:23 +08:00
|
|
|
mangleType(QualType(type, 0));
|
|
|
|
|
|
|
|
// We never want to print 'E' directly after an unresolved-type,
|
|
|
|
// so we return directly.
|
|
|
|
return;
|
|
|
|
|
|
|
|
case Type::Typedef:
|
|
|
|
mangleSourceName(cast<TypedefType>(type)->getDecl()->getIdentifier());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::UnresolvedUsing:
|
|
|
|
mangleSourceName(cast<UnresolvedUsingType>(type)->getDecl()
|
|
|
|
->getIdentifier());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::Record:
|
|
|
|
mangleSourceName(cast<RecordType>(type)->getDecl()->getIdentifier());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::TemplateSpecialization: {
|
|
|
|
const TemplateSpecializationType *tst
|
|
|
|
= cast<TemplateSpecializationType>(type);
|
2011-07-01 08:04:39 +08:00
|
|
|
TemplateName name = tst->getTemplateName();
|
|
|
|
switch (name.getKind()) {
|
|
|
|
case TemplateName::Template:
|
|
|
|
case TemplateName::QualifiedTemplate: {
|
|
|
|
TemplateDecl *temp = name.getAsTemplateDecl();
|
|
|
|
|
|
|
|
// If the base is a template template parameter, this is an
|
|
|
|
// unresolved type.
|
|
|
|
assert(temp && "no template for template specialization type");
|
|
|
|
if (isa<TemplateTemplateParmDecl>(temp)) goto unresolvedType;
|
|
|
|
|
|
|
|
mangleSourceName(temp->getIdentifier());
|
|
|
|
break;
|
|
|
|
}
|
2011-06-29 00:49:23 +08:00
|
|
|
|
2011-07-01 08:04:39 +08:00
|
|
|
case TemplateName::OverloadedTemplate:
|
|
|
|
case TemplateName::DependentTemplate:
|
|
|
|
llvm_unreachable("invalid base for a template specialization type");
|
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParm: {
|
|
|
|
SubstTemplateTemplateParmStorage *subst
|
|
|
|
= name.getAsSubstTemplateTemplateParm();
|
|
|
|
mangleExistingSubstitution(subst->getReplacement());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TemplateName::SubstTemplateTemplateParmPack: {
|
|
|
|
// FIXME: not clear how to mangle this!
|
|
|
|
// template <template <class U> class T...> class A {
|
|
|
|
// template <class U...> void foo(decltype(T<U>::foo) x...);
|
|
|
|
// };
|
|
|
|
Out << "_SUBSTPACK_";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-06-29 00:49:23 +08:00
|
|
|
|
2011-05-04 09:45:19 +08:00
|
|
|
mangleUnresolvedTemplateArgs(tst->getArgs(), tst->getNumArgs());
|
2011-06-29 00:49:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Type::InjectedClassName:
|
|
|
|
mangleSourceName(cast<InjectedClassNameType>(type)->getDecl()
|
|
|
|
->getIdentifier());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::DependentName:
|
|
|
|
mangleSourceName(cast<DependentNameType>(type)->getIdentifier());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Type::DependentTemplateSpecialization: {
|
|
|
|
const DependentTemplateSpecializationType *tst
|
|
|
|
= cast<DependentTemplateSpecializationType>(type);
|
2011-05-04 09:45:19 +08:00
|
|
|
mangleSourceName(tst->getIdentifier());
|
|
|
|
mangleUnresolvedTemplateArgs(tst->getArgs(), tst->getNumArgs());
|
2011-06-29 00:49:23 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-05-04 09:45:19 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-03-17 12:28:11 +08:00
|
|
|
}
|
2011-04-24 16:23:24 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
case NestedNameSpecifier::Identifier:
|
2010-03-02 07:49:17 +08:00
|
|
|
// Member expressions can have these without prefixes.
|
2011-04-24 16:23:24 +08:00
|
|
|
if (qualifier->getPrefix()) {
|
|
|
|
mangleUnresolvedPrefix(qualifier->getPrefix(), firstQualifierLookup,
|
|
|
|
/*recursive*/ true);
|
|
|
|
} else if (firstQualifierLookup) {
|
|
|
|
|
|
|
|
// Try to make a proper qualifier out of the lookup result, and
|
|
|
|
// then just recurse on that.
|
|
|
|
NestedNameSpecifier *newQualifier;
|
|
|
|
if (TypeDecl *typeDecl = dyn_cast<TypeDecl>(firstQualifierLookup)) {
|
|
|
|
QualType type = getASTContext().getTypeDeclType(typeDecl);
|
|
|
|
|
|
|
|
// Pretend we had a different nested name specifier.
|
|
|
|
newQualifier = NestedNameSpecifier::Create(getASTContext(),
|
|
|
|
/*prefix*/ 0,
|
|
|
|
/*template*/ false,
|
|
|
|
type.getTypePtr());
|
|
|
|
} else if (NamespaceDecl *nspace =
|
|
|
|
dyn_cast<NamespaceDecl>(firstQualifierLookup)) {
|
|
|
|
newQualifier = NestedNameSpecifier::Create(getASTContext(),
|
|
|
|
/*prefix*/ 0,
|
|
|
|
nspace);
|
|
|
|
} else if (NamespaceAliasDecl *alias =
|
|
|
|
dyn_cast<NamespaceAliasDecl>(firstQualifierLookup)) {
|
|
|
|
newQualifier = NestedNameSpecifier::Create(getASTContext(),
|
|
|
|
/*prefix*/ 0,
|
|
|
|
alias);
|
|
|
|
} else {
|
|
|
|
// No sensible mangling to do here.
|
|
|
|
newQualifier = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newQualifier)
|
|
|
|
return mangleUnresolvedPrefix(newQualifier, /*lookup*/ 0, recursive);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Out << "sr";
|
|
|
|
}
|
|
|
|
|
|
|
|
mangleSourceName(qualifier->getAsIdentifier());
|
2010-02-04 09:42:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-24 16:23:24 +08:00
|
|
|
// If this was the innermost part of the NNS, and we fell out to
|
|
|
|
// here, append an 'E'.
|
|
|
|
if (!recursive)
|
|
|
|
Out << 'E';
|
|
|
|
}
|
2010-02-04 09:42:13 +08:00
|
|
|
|
2011-04-24 16:23:24 +08:00
|
|
|
/// Mangle an unresolved-name, which is generally used for names which
|
|
|
|
/// weren't resolved to specific entities.
|
|
|
|
void CXXNameMangler::mangleUnresolvedName(NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
DeclarationName name,
|
|
|
|
unsigned knownArity) {
|
|
|
|
if (qualifier) mangleUnresolvedPrefix(qualifier, firstQualifierLookup);
|
|
|
|
mangleUnqualifiedName(0, name, knownArity);
|
2010-02-04 09:42:13 +08:00
|
|
|
}
|
|
|
|
|
2010-06-08 22:49:03 +08:00
|
|
|
static const FieldDecl *FindFirstNamedDataMember(const RecordDecl *RD) {
|
|
|
|
assert(RD->isAnonymousStructOrUnion() &&
|
|
|
|
"Expected anonymous struct or union!");
|
|
|
|
|
|
|
|
for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const FieldDecl *FD = *I;
|
|
|
|
|
|
|
|
if (FD->getIdentifier())
|
|
|
|
return FD;
|
|
|
|
|
|
|
|
if (const RecordType *RT = FD->getType()->getAs<RecordType>()) {
|
|
|
|
if (const FieldDecl *NamedDataMember =
|
|
|
|
FindFirstNamedDataMember(RT->getDecl()))
|
|
|
|
return NamedDataMember;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We didn't find a named data member.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
|
|
|
|
DeclarationName Name,
|
|
|
|
unsigned KnownArity) {
|
2009-02-13 08:10:09 +08:00
|
|
|
// <unqualified-name> ::= <operator-name>
|
2009-09-09 23:08:12 +08:00
|
|
|
// ::= <ctor-dtor-name>
|
|
|
|
// ::= <source-name>
|
2009-02-13 08:10:09 +08:00
|
|
|
switch (Name.getNameKind()) {
|
2009-10-07 09:45:02 +08:00
|
|
|
case DeclarationName::Identifier: {
|
|
|
|
if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
|
2010-01-24 11:04:27 +08:00
|
|
|
// We must avoid conflicts between internally- and externally-
|
2011-03-22 14:34:45 +08:00
|
|
|
// linked variable and function declaration names in the same TU:
|
|
|
|
// void test() { extern void foo(); }
|
|
|
|
// static void foo();
|
|
|
|
// This naming convention is the same as that followed by GCC,
|
|
|
|
// though it shouldn't actually matter.
|
|
|
|
if (ND && ND->getLinkage() == InternalLinkage &&
|
2010-01-24 11:04:27 +08:00
|
|
|
ND->getDeclContext()->isFileContext())
|
|
|
|
Out << 'L';
|
|
|
|
|
2009-10-07 09:45:02 +08:00
|
|
|
mangleSourceName(II);
|
|
|
|
break;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
// Otherwise, an anonymous entity. We must have a declaration.
|
|
|
|
assert(ND && "mangling empty name without declaration");
|
|
|
|
|
|
|
|
if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
|
|
|
|
if (NS->isAnonymousNamespace()) {
|
|
|
|
// This is how gcc mangles these names.
|
|
|
|
Out << "12_GLOBAL__N_1";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-08 22:49:03 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
|
|
|
|
// We must have an anonymous union or struct declaration.
|
|
|
|
const RecordDecl *RD =
|
|
|
|
cast<RecordDecl>(VD->getType()->getAs<RecordType>()->getDecl());
|
|
|
|
|
|
|
|
// Itanium C++ ABI 5.1.2:
|
|
|
|
//
|
|
|
|
// For the purposes of mangling, the name of an anonymous union is
|
|
|
|
// considered to be the name of the first named data member found by a
|
|
|
|
// pre-order, depth-first, declaration-order walk of the data members of
|
|
|
|
// the anonymous union. If there is no such data member (i.e., if all of
|
|
|
|
// the data members in the union are unnamed), then there is no way for
|
|
|
|
// a program to refer to the anonymous union, and there is therefore no
|
|
|
|
// need to mangle its name.
|
|
|
|
const FieldDecl *FD = FindFirstNamedDataMember(RD);
|
2010-08-06 06:02:13 +08:00
|
|
|
|
|
|
|
// It's actually possible for various reasons for us to get here
|
|
|
|
// with an empty anonymous struct / union. Fortunately, it
|
|
|
|
// doesn't really matter what name we generate.
|
|
|
|
if (!FD) break;
|
2010-06-08 22:49:03 +08:00
|
|
|
assert(FD->getIdentifier() && "Data member name isn't an identifier!");
|
|
|
|
|
|
|
|
mangleSourceName(FD->getIdentifier());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-07 09:45:02 +08:00
|
|
|
// We must have an anonymous struct.
|
|
|
|
const TagDecl *TD = cast<TagDecl>(ND);
|
2011-04-15 22:24:37 +08:00
|
|
|
if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) {
|
2009-10-07 09:45:02 +08:00
|
|
|
assert(TD->getDeclContext() == D->getDeclContext() &&
|
|
|
|
"Typedef should not be in another decl context!");
|
|
|
|
assert(D->getDeclName().getAsIdentifierInfo() &&
|
|
|
|
"Typedef was not named!");
|
|
|
|
mangleSourceName(D->getDeclName().getAsIdentifierInfo());
|
|
|
|
break;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-10-07 09:45:02 +08:00
|
|
|
// Get a unique id for the anonymous struct.
|
|
|
|
uint64_t AnonStructId = Context.getAnonymousStructId(TD);
|
|
|
|
|
|
|
|
// Mangle it as a source name in the form
|
2009-11-21 17:05:47 +08:00
|
|
|
// [n] $_<id>
|
2009-10-07 09:45:02 +08:00
|
|
|
// where n is the length of the string.
|
|
|
|
llvm::SmallString<8> Str;
|
|
|
|
Str += "$_";
|
|
|
|
Str += llvm::utostr(AnonStructId);
|
|
|
|
|
|
|
|
Out << Str.size();
|
|
|
|
Out << Str.str();
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
2009-10-07 09:45:02 +08:00
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
|
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
assert(false && "Can't mangle Objective-C selector names here!");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConstructorName:
|
2009-04-17 09:58:57 +08:00
|
|
|
if (ND == Structor)
|
2009-09-02 08:25:38 +08:00
|
|
|
// If the named decl is the C++ constructor we're mangling, use the type
|
|
|
|
// we were given.
|
2009-04-17 09:58:57 +08:00
|
|
|
mangleCXXCtorType(static_cast<CXXCtorType>(StructorType));
|
2009-04-15 13:36:58 +08:00
|
|
|
else
|
|
|
|
// Otherwise, use the complete constructor name. This is relevant if a
|
|
|
|
// class with a constructor is declared within a constructor.
|
|
|
|
mangleCXXCtorType(Ctor_Complete);
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXDestructorName:
|
2009-04-17 09:58:57 +08:00
|
|
|
if (ND == Structor)
|
2009-09-02 08:25:38 +08:00
|
|
|
// If the named decl is the C++ destructor we're mangling, use the type we
|
|
|
|
// were given.
|
2009-04-17 09:58:57 +08:00
|
|
|
mangleCXXDtorType(static_cast<CXXDtorType>(StructorType));
|
|
|
|
else
|
|
|
|
// Otherwise, use the complete destructor name. This is relevant if a
|
|
|
|
// class with a destructor is declared within a destructor.
|
|
|
|
mangleCXXDtorType(Dtor_Complete);
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
2009-09-09 23:08:12 +08:00
|
|
|
// <operator-name> ::= cv <type> # (cast)
|
2009-02-13 09:28:03 +08:00
|
|
|
Out << "cv";
|
2011-07-12 12:42:08 +08:00
|
|
|
mangleType(Name.getCXXNameType());
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
|
|
|
|
2009-12-22 14:36:32 +08:00
|
|
|
case DeclarationName::CXXOperatorName: {
|
2010-02-04 09:42:13 +08:00
|
|
|
unsigned Arity;
|
|
|
|
if (ND) {
|
|
|
|
Arity = cast<FunctionDecl>(ND)->getNumParams();
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
// If we have a C++ member function, we need to include the 'this' pointer.
|
|
|
|
// FIXME: This does not make sense for operators that are static, but their
|
|
|
|
// names stay the same regardless of the arity (operator new for instance).
|
|
|
|
if (isa<CXXMethodDecl>(ND))
|
|
|
|
Arity++;
|
|
|
|
} else
|
|
|
|
Arity = KnownArity;
|
|
|
|
|
2009-12-22 14:36:32 +08:00
|
|
|
mangleOperatorName(Name.getCXXOverloadedOperator(), Arity);
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
2009-12-22 14:36:32 +08:00
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2009-11-29 15:34:05 +08:00
|
|
|
case DeclarationName::CXXLiteralOperatorName:
|
2009-12-05 05:11:13 +08:00
|
|
|
// FIXME: This mangling is not yet official.
|
2009-12-05 05:01:37 +08:00
|
|
|
Out << "li";
|
2009-11-29 15:34:05 +08:00
|
|
|
mangleSourceName(Name.getCXXLiteralIdentifier());
|
|
|
|
break;
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
assert(false && "Can't mangle a using directive name!");
|
2009-02-13 09:28:03 +08:00
|
|
|
break;
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
|
|
|
|
// <source-name> ::= <positive length number> <identifier>
|
|
|
|
// <number> ::= [n] <non-negative decimal integer>
|
|
|
|
// <identifier> ::= <unqualified source code identifier>
|
|
|
|
Out << II->getLength() << II->getName();
|
|
|
|
}
|
|
|
|
|
2009-12-03 04:32:49 +08:00
|
|
|
void CXXNameMangler::mangleNestedName(const NamedDecl *ND,
|
2010-03-04 03:41:08 +08:00
|
|
|
const DeclContext *DC,
|
|
|
|
bool NoFunction) {
|
2011-01-27 01:36:28 +08:00
|
|
|
// <nested-name>
|
|
|
|
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E
|
|
|
|
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix>
|
|
|
|
// <template-args> E
|
2009-09-26 11:55:37 +08:00
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'N';
|
2011-01-27 01:36:28 +08:00
|
|
|
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
|
2009-09-25 03:53:00 +08:00
|
|
|
mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers()));
|
2011-01-27 01:36:28 +08:00
|
|
|
mangleRefQualifier(Method->getRefQualifier());
|
|
|
|
}
|
|
|
|
|
2009-09-19 03:00:18 +08:00
|
|
|
// Check if we have a template.
|
|
|
|
const TemplateArgumentList *TemplateArgs = 0;
|
2009-11-21 17:05:47 +08:00
|
|
|
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
|
2009-09-19 03:00:18 +08:00
|
|
|
mangleTemplatePrefix(TD);
|
2010-03-11 22:07:00 +08:00
|
|
|
TemplateParameterList *TemplateParameters = TD->getTemplateParameters();
|
|
|
|
mangleTemplateArgs(*TemplateParameters, *TemplateArgs);
|
2010-03-04 03:41:08 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
manglePrefix(DC, NoFunction);
|
2009-09-18 12:29:09 +08:00
|
|
|
mangleUnqualifiedName(ND);
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'E';
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
void CXXNameMangler::mangleNestedName(const TemplateDecl *TD,
|
2009-09-18 10:42:01 +08:00
|
|
|
const TemplateArgument *TemplateArgs,
|
|
|
|
unsigned NumTemplateArgs) {
|
2009-09-28 03:53:49 +08:00
|
|
|
// <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E
|
|
|
|
|
2009-09-18 10:42:01 +08:00
|
|
|
Out << 'N';
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-28 03:53:49 +08:00
|
|
|
mangleTemplatePrefix(TD);
|
2010-03-11 22:07:00 +08:00
|
|
|
TemplateParameterList *TemplateParameters = TD->getTemplateParameters();
|
|
|
|
mangleTemplateArgs(*TemplateParameters, TemplateArgs, NumTemplateArgs);
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-18 10:42:01 +08:00
|
|
|
Out << 'E';
|
|
|
|
}
|
|
|
|
|
2009-04-03 00:24:45 +08:00
|
|
|
void CXXNameMangler::mangleLocalName(const NamedDecl *ND) {
|
|
|
|
// <local-name> := Z <function encoding> E <entity name> [<discriminator>]
|
|
|
|
// := Z <function encoding> E s [<discriminator>]
|
2009-09-09 23:08:12 +08:00
|
|
|
// <discriminator> := _ <non-negative number>
|
2010-03-04 03:41:08 +08:00
|
|
|
const DeclContext *DC = ND->getDeclContext();
|
2011-06-10 03:25:01 +08:00
|
|
|
if (isa<ObjCMethodDecl>(DC) && isa<FunctionDecl>(ND)) {
|
|
|
|
// Don't add objc method name mangling to locally declared function
|
|
|
|
mangleUnqualifiedName(ND);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-03 00:24:45 +08:00
|
|
|
Out << 'Z';
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-05-27 02:25:27 +08:00
|
|
|
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) {
|
|
|
|
mangleObjCMethodName(MD);
|
2010-10-19 05:28:44 +08:00
|
|
|
} else if (const CXXRecordDecl *RD = GetLocalClassDecl(ND)) {
|
|
|
|
mangleFunctionEncoding(cast<FunctionDecl>(RD->getDeclContext()));
|
2010-03-04 03:41:08 +08:00
|
|
|
Out << 'E';
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-10-19 05:28:44 +08:00
|
|
|
// Mangle the name relative to the closest enclosing function.
|
|
|
|
if (ND == RD) // equality ok because RD derived from ND above
|
|
|
|
mangleUnqualifiedName(ND);
|
|
|
|
else
|
|
|
|
mangleNestedName(ND, DC, true /*NoFunction*/);
|
|
|
|
|
2010-03-04 09:02:03 +08:00
|
|
|
unsigned disc;
|
2010-10-19 05:28:44 +08:00
|
|
|
if (Context.getNextDiscriminator(RD, disc)) {
|
2010-03-04 09:02:03 +08:00
|
|
|
if (disc < 10)
|
|
|
|
Out << '_' << disc;
|
2010-03-13 18:17:05 +08:00
|
|
|
else
|
2010-03-04 09:02:03 +08:00
|
|
|
Out << "__" << disc << '_';
|
|
|
|
}
|
2010-03-04 03:41:08 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
else
|
2010-03-04 03:41:08 +08:00
|
|
|
mangleFunctionEncoding(cast<FunctionDecl>(DC));
|
2009-12-10 11:14:39 +08:00
|
|
|
|
2009-04-03 00:24:45 +08:00
|
|
|
Out << 'E';
|
2009-12-12 04:21:38 +08:00
|
|
|
mangleUnqualifiedName(ND);
|
2009-04-03 00:24:45 +08:00
|
|
|
}
|
|
|
|
|
2011-04-24 16:23:24 +08:00
|
|
|
void CXXNameMangler::manglePrefix(NestedNameSpecifier *qualifier) {
|
|
|
|
switch (qualifier->getKind()) {
|
|
|
|
case NestedNameSpecifier::Global:
|
|
|
|
// nothing
|
|
|
|
return;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::Namespace:
|
|
|
|
mangleName(qualifier->getAsNamespace());
|
|
|
|
return;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::NamespaceAlias:
|
|
|
|
mangleName(qualifier->getAsNamespaceAlias()->getNamespace());
|
|
|
|
return;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::TypeSpec:
|
|
|
|
case NestedNameSpecifier::TypeSpecWithTemplate:
|
2011-05-04 09:45:19 +08:00
|
|
|
manglePrefix(QualType(qualifier->getAsType(), 0));
|
2011-04-24 16:23:24 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
case NestedNameSpecifier::Identifier:
|
|
|
|
// Member expressions can have these without prefixes, but that
|
|
|
|
// should end up in mangleUnresolvedPrefix instead.
|
|
|
|
assert(qualifier->getPrefix());
|
|
|
|
manglePrefix(qualifier->getPrefix());
|
|
|
|
|
|
|
|
mangleSourceName(qualifier->getAsIdentifier());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm_unreachable("unexpected nested name specifier");
|
|
|
|
}
|
|
|
|
|
2010-03-04 03:41:08 +08:00
|
|
|
void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) {
|
2009-02-13 08:10:09 +08:00
|
|
|
// <prefix> ::= <prefix> <unqualified-name>
|
|
|
|
// ::= <template-prefix> <template-args>
|
|
|
|
// ::= <template-param>
|
|
|
|
// ::= # empty
|
|
|
|
// ::= <substitution>
|
2009-09-17 12:16:28 +08:00
|
|
|
|
2009-09-23 04:33:31 +08:00
|
|
|
while (isa<LinkageSpecDecl>(DC))
|
|
|
|
DC = DC->getParent();
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-19 02:39:58 +08:00
|
|
|
if (DC->isTranslationUnit())
|
|
|
|
return;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-05-26 01:04:15 +08:00
|
|
|
if (const BlockDecl *Block = dyn_cast<BlockDecl>(DC)) {
|
|
|
|
manglePrefix(DC->getParent(), NoFunction);
|
|
|
|
llvm::SmallString<64> Name;
|
2011-02-11 07:59:36 +08:00
|
|
|
llvm::raw_svector_ostream NameStream(Name);
|
|
|
|
Context.mangleBlock(Block, NameStream);
|
|
|
|
NameStream.flush();
|
2010-05-26 01:04:15 +08:00
|
|
|
Out << Name.size() << Name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-17 12:16:28 +08:00
|
|
|
if (mangleSubstitution(cast<NamedDecl>(DC)))
|
|
|
|
return;
|
2009-09-18 12:29:09 +08:00
|
|
|
|
2009-09-19 04:11:09 +08:00
|
|
|
// Check if we have a template.
|
|
|
|
const TemplateArgumentList *TemplateArgs = 0;
|
2009-11-21 17:05:47 +08:00
|
|
|
if (const TemplateDecl *TD = isTemplate(cast<NamedDecl>(DC), TemplateArgs)) {
|
2009-09-19 04:11:09 +08:00
|
|
|
mangleTemplatePrefix(TD);
|
2010-03-11 22:07:00 +08:00
|
|
|
TemplateParameterList *TemplateParameters = TD->getTemplateParameters();
|
|
|
|
mangleTemplateArgs(*TemplateParameters, *TemplateArgs);
|
2010-03-04 03:41:08 +08:00
|
|
|
}
|
2010-05-26 01:04:15 +08:00
|
|
|
else if(NoFunction && (isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC)))
|
2010-03-04 03:41:08 +08:00
|
|
|
return;
|
2010-05-26 01:04:15 +08:00
|
|
|
else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC))
|
|
|
|
mangleObjCMethodName(Method);
|
2010-03-04 03:41:08 +08:00
|
|
|
else {
|
|
|
|
manglePrefix(DC->getParent(), NoFunction);
|
2009-09-19 04:11:09 +08:00
|
|
|
mangleUnqualifiedName(cast<NamedDecl>(DC));
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 12:16:28 +08:00
|
|
|
addSubstitution(cast<NamedDecl>(DC));
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2010-04-23 11:10:43 +08:00
|
|
|
void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) {
|
|
|
|
// <template-prefix> ::= <prefix> <template unqualified-name>
|
|
|
|
// ::= <template-param>
|
|
|
|
// ::= <substitution>
|
|
|
|
if (TemplateDecl *TD = Template.getAsTemplateDecl())
|
|
|
|
return mangleTemplatePrefix(TD);
|
|
|
|
|
|
|
|
if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName())
|
2011-04-24 16:23:24 +08:00
|
|
|
manglePrefix(Qualified->getQualifier());
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-23 11:10:43 +08:00
|
|
|
if (OverloadedTemplateStorage *Overloaded
|
|
|
|
= Template.getAsOverloadedTemplate()) {
|
2010-05-05 23:23:54 +08:00
|
|
|
mangleUnqualifiedName(0, (*Overloaded->begin())->getDeclName(),
|
2010-04-23 11:10:43 +08:00
|
|
|
UnknownArity);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-23 11:10:43 +08:00
|
|
|
DependentTemplateName *Dependent = Template.getAsDependentTemplateName();
|
|
|
|
assert(Dependent && "Unknown template name kind?");
|
2011-04-24 16:23:24 +08:00
|
|
|
manglePrefix(Dependent->getQualifier());
|
2010-04-28 13:58:56 +08:00
|
|
|
mangleUnscopedTemplateName(Template);
|
2010-04-23 11:10:43 +08:00
|
|
|
}
|
|
|
|
|
2009-09-27 03:45:45 +08:00
|
|
|
void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND) {
|
2009-09-18 12:29:09 +08:00
|
|
|
// <template-prefix> ::= <prefix> <template unqualified-name>
|
|
|
|
// ::= <template-param>
|
|
|
|
// ::= <substitution>
|
2010-02-06 04:45:00 +08:00
|
|
|
// <template-template-param> ::= <template-param>
|
|
|
|
// <substitution>
|
2009-09-18 12:29:09 +08:00
|
|
|
|
2009-09-27 06:18:22 +08:00
|
|
|
if (mangleSubstitution(ND))
|
|
|
|
return;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-02-06 04:45:00 +08:00
|
|
|
// <template-template-param> ::= <template-param>
|
|
|
|
if (const TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(ND)) {
|
|
|
|
mangleTemplateParameter(TTP->getIndex());
|
|
|
|
return;
|
2010-03-13 18:17:05 +08:00
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-19 02:47:07 +08:00
|
|
|
manglePrefix(ND->getDeclContext());
|
2009-09-27 04:13:56 +08:00
|
|
|
mangleUnqualifiedName(ND->getTemplatedDecl());
|
2009-09-27 06:18:22 +08:00
|
|
|
addSubstitution(ND);
|
2009-09-18 12:29:09 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 14:43:17 +08:00
|
|
|
/// Mangles a template name under the production <type>. Required for
|
|
|
|
/// template template arguments.
|
|
|
|
/// <type> ::= <class-enum-type>
|
|
|
|
/// ::= <template-param>
|
|
|
|
/// ::= <substitution>
|
|
|
|
void CXXNameMangler::mangleType(TemplateName TN) {
|
|
|
|
if (mangleSubstitution(TN))
|
|
|
|
return;
|
|
|
|
|
|
|
|
TemplateDecl *TD = 0;
|
|
|
|
|
|
|
|
switch (TN.getKind()) {
|
|
|
|
case TemplateName::QualifiedTemplate:
|
|
|
|
TD = TN.getAsQualifiedTemplateName()->getTemplateDecl();
|
|
|
|
goto HaveDecl;
|
|
|
|
|
|
|
|
case TemplateName::Template:
|
|
|
|
TD = TN.getAsTemplateDecl();
|
|
|
|
goto HaveDecl;
|
|
|
|
|
|
|
|
HaveDecl:
|
|
|
|
if (isa<TemplateTemplateParmDecl>(TD))
|
|
|
|
mangleTemplateParameter(cast<TemplateTemplateParmDecl>(TD)->getIndex());
|
|
|
|
else
|
|
|
|
mangleName(TD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateName::OverloadedTemplate:
|
|
|
|
llvm_unreachable("can't mangle an overloaded template name as a <type>");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateName::DependentTemplate: {
|
|
|
|
const DependentTemplateName *Dependent = TN.getAsDependentTemplateName();
|
|
|
|
assert(Dependent->isIdentifier());
|
|
|
|
|
|
|
|
// <class-enum-type> ::= <name>
|
|
|
|
// <name> ::= <nested-name>
|
2011-04-24 16:23:24 +08:00
|
|
|
mangleUnresolvedPrefix(Dependent->getQualifier(), 0);
|
2010-07-14 14:43:17 +08:00
|
|
|
mangleSourceName(Dependent->getIdentifier());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-07-01 05:59:02 +08:00
|
|
|
case TemplateName::SubstTemplateTemplateParm: {
|
|
|
|
// Substituted template parameters are mangled as the substituted
|
|
|
|
// template. This will check for the substitution twice, which is
|
|
|
|
// fine, but we have to return early so that we don't try to *add*
|
|
|
|
// the substitution twice.
|
|
|
|
SubstTemplateTemplateParmStorage *subst
|
|
|
|
= TN.getAsSubstTemplateTemplateParm();
|
|
|
|
mangleType(subst->getReplacement());
|
|
|
|
return;
|
|
|
|
}
|
2011-06-30 16:33:18 +08:00
|
|
|
|
2011-01-15 14:45:20 +08:00
|
|
|
case TemplateName::SubstTemplateTemplateParmPack: {
|
2011-07-01 08:04:39 +08:00
|
|
|
// FIXME: not clear how to mangle this!
|
|
|
|
// template <template <class> class T...> class A {
|
|
|
|
// template <template <class> class U...> void foo(B<T,U> x...);
|
|
|
|
// };
|
|
|
|
Out << "_SUBSTPACK_";
|
2011-01-15 14:45:20 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-07-14 14:43:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addSubstitution(TN);
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
void
|
2009-02-13 08:10:09 +08:00
|
|
|
CXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity) {
|
|
|
|
switch (OO) {
|
2009-04-17 01:51:27 +08:00
|
|
|
// <operator-name> ::= nw # new
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_New: Out << "nw"; break;
|
|
|
|
// ::= na # new[]
|
|
|
|
case OO_Array_New: Out << "na"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= dl # delete
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Delete: Out << "dl"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= da # delete[]
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Array_Delete: Out << "da"; break;
|
|
|
|
// ::= ps # + (unary)
|
2010-08-19 03:18:59 +08:00
|
|
|
// ::= pl # + (binary or unknown)
|
2010-03-13 18:17:05 +08:00
|
|
|
case OO_Plus:
|
2009-12-22 14:36:32 +08:00
|
|
|
Out << (Arity == 1? "ps" : "pl"); break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= ng # - (unary)
|
2010-08-19 03:18:59 +08:00
|
|
|
// ::= mi # - (binary or unknown)
|
2010-03-13 18:17:05 +08:00
|
|
|
case OO_Minus:
|
2009-12-22 14:36:32 +08:00
|
|
|
Out << (Arity == 1? "ng" : "mi"); break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= ad # & (unary)
|
2010-08-19 03:18:59 +08:00
|
|
|
// ::= an # & (binary or unknown)
|
2010-03-13 18:17:05 +08:00
|
|
|
case OO_Amp:
|
2009-12-22 14:36:32 +08:00
|
|
|
Out << (Arity == 1? "ad" : "an"); break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= de # * (unary)
|
2010-08-19 03:18:59 +08:00
|
|
|
// ::= ml # * (binary or unknown)
|
2010-03-13 18:17:05 +08:00
|
|
|
case OO_Star:
|
2010-08-19 03:18:59 +08:00
|
|
|
// Use binary when unknown.
|
2009-12-22 14:36:32 +08:00
|
|
|
Out << (Arity == 1? "de" : "ml"); break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= co # ~
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Tilde: Out << "co"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= dv # /
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Slash: Out << "dv"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= rm # %
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Percent: Out << "rm"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= or # |
|
|
|
|
case OO_Pipe: Out << "or"; break;
|
|
|
|
// ::= eo # ^
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Caret: Out << "eo"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= aS # =
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Equal: Out << "aS"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= pL # +=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_PlusEqual: Out << "pL"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= mI # -=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_MinusEqual: Out << "mI"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= mL # *=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_StarEqual: Out << "mL"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= dV # /=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_SlashEqual: Out << "dV"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= rM # %=
|
|
|
|
case OO_PercentEqual: Out << "rM"; break;
|
|
|
|
// ::= aN # &=
|
|
|
|
case OO_AmpEqual: Out << "aN"; break;
|
|
|
|
// ::= oR # |=
|
|
|
|
case OO_PipeEqual: Out << "oR"; break;
|
|
|
|
// ::= eO # ^=
|
|
|
|
case OO_CaretEqual: Out << "eO"; break;
|
|
|
|
// ::= ls # <<
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_LessLess: Out << "ls"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= rs # >>
|
|
|
|
case OO_GreaterGreater: Out << "rs"; break;
|
|
|
|
// ::= lS # <<=
|
|
|
|
case OO_LessLessEqual: Out << "lS"; break;
|
|
|
|
// ::= rS # >>=
|
|
|
|
case OO_GreaterGreaterEqual: Out << "rS"; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
// ::= eq # ==
|
|
|
|
case OO_EqualEqual: Out << "eq"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= ne # !=
|
|
|
|
case OO_ExclaimEqual: Out << "ne"; break;
|
|
|
|
// ::= lt # <
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Less: Out << "lt"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= gt # >
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Greater: Out << "gt"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= le # <=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_LessEqual: Out << "le"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= ge # >=
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_GreaterEqual: Out << "ge"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= nt # !
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Exclaim: Out << "nt"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= aa # &&
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_AmpAmp: Out << "aa"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= oo # ||
|
|
|
|
case OO_PipePipe: Out << "oo"; break;
|
|
|
|
// ::= pp # ++
|
|
|
|
case OO_PlusPlus: Out << "pp"; break;
|
|
|
|
// ::= mm # --
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_MinusMinus: Out << "mm"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= cm # ,
|
|
|
|
case OO_Comma: Out << "cm"; break;
|
|
|
|
// ::= pm # ->*
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_ArrowStar: Out << "pm"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= pt # ->
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Arrow: Out << "pt"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= cl # ()
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Call: Out << "cl"; break;
|
2009-04-17 01:51:27 +08:00
|
|
|
// ::= ix # []
|
2009-02-13 08:10:09 +08:00
|
|
|
case OO_Subscript: Out << "ix"; break;
|
2009-12-14 09:45:37 +08:00
|
|
|
|
|
|
|
// ::= qu # ?
|
|
|
|
// The conditional operator can't be overloaded, but we still handle it when
|
|
|
|
// mangling expressions.
|
|
|
|
case OO_Conditional: Out << "qu"; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2009-04-17 01:51:27 +08:00
|
|
|
case OO_None:
|
2009-02-13 08:10:09 +08:00
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
2009-09-09 23:08:12 +08:00
|
|
|
assert(false && "Not an overloaded operator");
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-25 03:53:00 +08:00
|
|
|
void CXXNameMangler::mangleQualifiers(Qualifiers Quals) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, const
|
2009-09-25 03:53:00 +08:00
|
|
|
if (Quals.hasRestrict())
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'r';
|
2009-09-25 03:53:00 +08:00
|
|
|
if (Quals.hasVolatile())
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'V';
|
2009-09-25 03:53:00 +08:00
|
|
|
if (Quals.hasConst())
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'K';
|
2009-09-25 03:53:00 +08:00
|
|
|
|
2010-06-15 07:15:08 +08:00
|
|
|
if (Quals.hasAddressSpace()) {
|
|
|
|
// Extension:
|
|
|
|
//
|
|
|
|
// <type> ::= U <address-space-number>
|
|
|
|
//
|
|
|
|
// where <address-space-number> is a source name consisting of 'AS'
|
|
|
|
// followed by the address space <number>.
|
|
|
|
llvm::SmallString<64> ASString;
|
|
|
|
ASString = "AS" + llvm::utostr_32(Quals.getAddressSpace());
|
|
|
|
Out << 'U' << ASString.size() << ASString;
|
|
|
|
}
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
llvm::StringRef LifetimeName;
|
|
|
|
switch (Quals.getObjCLifetime()) {
|
|
|
|
// Objective-C ARC Extension:
|
|
|
|
//
|
|
|
|
// <type> ::= U "__strong"
|
|
|
|
// <type> ::= U "__weak"
|
|
|
|
// <type> ::= U "__autoreleasing"
|
|
|
|
case Qualifiers::OCL_None:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_Weak:
|
|
|
|
LifetimeName = "__weak";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_Strong:
|
|
|
|
LifetimeName = "__strong";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_Autoreleasing:
|
|
|
|
LifetimeName = "__autoreleasing";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qualifiers::OCL_ExplicitNone:
|
2011-06-18 06:26:49 +08:00
|
|
|
// The __unsafe_unretained qualifier is *not* mangled, so that
|
|
|
|
// __unsafe_unretained types in ARC produce the same manglings as the
|
|
|
|
// equivalent (but, naturally, unqualified) types in non-ARC, providing
|
|
|
|
// better ABI compatibility.
|
|
|
|
//
|
|
|
|
// It's safe to do this because unqualified 'id' won't show up
|
|
|
|
// in any type signatures that need to be mangled.
|
2011-06-16 07:02:42 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!LifetimeName.empty())
|
|
|
|
Out << 'U' << LifetimeName.size() << LifetimeName;
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2011-01-27 01:36:28 +08:00
|
|
|
void CXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) {
|
|
|
|
// <ref-qualifier> ::= R # lvalue reference
|
|
|
|
// ::= O # rvalue-reference
|
|
|
|
// Proposal to Itanium C++ ABI list on 1/26/11
|
|
|
|
switch (RefQualifier) {
|
|
|
|
case RQ_None:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RQ_LValue:
|
|
|
|
Out << 'R';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RQ_RValue:
|
|
|
|
Out << 'O';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-10 11:14:39 +08:00
|
|
|
void CXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
|
2011-02-11 10:52:17 +08:00
|
|
|
Context.mangleObjCMethodName(MD, Out);
|
2009-12-10 11:14:39 +08:00
|
|
|
}
|
|
|
|
|
2011-01-27 04:05:40 +08:00
|
|
|
void CXXNameMangler::mangleType(QualType nonCanon) {
|
2009-03-11 01:07:44 +08:00
|
|
|
// Only operate on the canonical type!
|
2011-01-27 04:05:40 +08:00
|
|
|
QualType canon = nonCanon.getCanonicalType();
|
2009-03-11 01:07:44 +08:00
|
|
|
|
2011-01-27 04:05:40 +08:00
|
|
|
SplitQualType split = canon.split();
|
|
|
|
Qualifiers quals = split.second;
|
|
|
|
const Type *ty = split.first;
|
|
|
|
|
|
|
|
bool isSubstitutable = quals || !isa<BuiltinType>(ty);
|
|
|
|
if (isSubstitutable && mangleSubstitution(canon))
|
2009-09-17 08:43:46 +08:00
|
|
|
return;
|
|
|
|
|
2011-01-27 04:05:40 +08:00
|
|
|
// If we're mangling a qualified array type, push the qualifiers to
|
|
|
|
// the element type.
|
|
|
|
if (quals && isa<ArrayType>(ty)) {
|
|
|
|
ty = Context.getASTContext().getAsArrayType(canon);
|
|
|
|
quals = Qualifiers();
|
|
|
|
|
|
|
|
// Note that we don't update canon: we want to add the
|
|
|
|
// substitution at the canonical type.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quals) {
|
|
|
|
mangleQualifiers(quals);
|
2009-09-25 03:53:00 +08:00
|
|
|
// Recurse: even if the qualified type isn't yet substitutable,
|
|
|
|
// the unqualified type might be.
|
2011-01-27 04:05:40 +08:00
|
|
|
mangleType(QualType(ty, 0));
|
2009-09-17 08:43:46 +08:00
|
|
|
} else {
|
2011-01-27 04:05:40 +08:00
|
|
|
switch (ty->getTypeClass()) {
|
2009-09-05 15:56:18 +08:00
|
|
|
#define ABSTRACT_TYPE(CLASS, PARENT)
|
|
|
|
#define NON_CANONICAL_TYPE(CLASS, PARENT) \
|
2009-09-17 08:43:46 +08:00
|
|
|
case Type::CLASS: \
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
|
2009-09-17 08:43:46 +08:00
|
|
|
return;
|
2009-09-05 15:56:18 +08:00
|
|
|
#define TYPE(CLASS, PARENT) \
|
2009-09-17 08:43:46 +08:00
|
|
|
case Type::CLASS: \
|
2011-01-27 04:05:40 +08:00
|
|
|
mangleType(static_cast<const CLASS##Type*>(ty)); \
|
2009-09-17 08:43:46 +08:00
|
|
|
break;
|
2009-09-05 15:56:18 +08:00
|
|
|
#include "clang/AST/TypeNodes.def"
|
2009-09-17 08:43:46 +08:00
|
|
|
}
|
2009-03-11 01:07:44 +08:00
|
|
|
}
|
2009-09-17 08:43:46 +08:00
|
|
|
|
|
|
|
// Add the substitution.
|
2011-01-27 04:05:40 +08:00
|
|
|
if (isSubstitutable)
|
|
|
|
addSubstitution(canon);
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2010-05-26 13:11:13 +08:00
|
|
|
void CXXNameMangler::mangleNameOrStandardSubstitution(const NamedDecl *ND) {
|
|
|
|
if (!mangleStandardSubstitution(ND))
|
|
|
|
mangleName(ND);
|
|
|
|
}
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleType(const BuiltinType *T) {
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <builtin-type>
|
2009-02-13 08:10:09 +08:00
|
|
|
// <builtin-type> ::= v # void
|
|
|
|
// ::= w # wchar_t
|
|
|
|
// ::= b # bool
|
|
|
|
// ::= c # char
|
|
|
|
// ::= a # signed char
|
|
|
|
// ::= h # unsigned char
|
|
|
|
// ::= s # short
|
|
|
|
// ::= t # unsigned short
|
|
|
|
// ::= i # int
|
|
|
|
// ::= j # unsigned int
|
|
|
|
// ::= l # long
|
|
|
|
// ::= m # unsigned long
|
|
|
|
// ::= x # long long, __int64
|
|
|
|
// ::= y # unsigned long long, __int64
|
|
|
|
// ::= n # __int128
|
|
|
|
// UNSUPPORTED: ::= o # unsigned __int128
|
|
|
|
// ::= f # float
|
|
|
|
// ::= d # double
|
|
|
|
// ::= e # long double, __float80
|
|
|
|
// UNSUPPORTED: ::= g # __float128
|
|
|
|
// UNSUPPORTED: ::= Dd # IEEE 754r decimal floating point (64 bits)
|
|
|
|
// UNSUPPORTED: ::= De # IEEE 754r decimal floating point (128 bits)
|
|
|
|
// UNSUPPORTED: ::= Df # IEEE 754r decimal floating point (32 bits)
|
|
|
|
// UNSUPPORTED: ::= Dh # IEEE 754r half-precision floating point (16 bits)
|
2009-07-14 14:30:34 +08:00
|
|
|
// ::= Di # char32_t
|
|
|
|
// ::= Ds # char16_t
|
2010-11-04 12:31:32 +08:00
|
|
|
// ::= Dn # std::nullptr_t (i.e., decltype(nullptr))
|
2009-02-13 08:10:09 +08:00
|
|
|
// ::= u <source-name> # vendor extended type
|
|
|
|
switch (T->getKind()) {
|
|
|
|
case BuiltinType::Void: Out << 'v'; break;
|
|
|
|
case BuiltinType::Bool: Out << 'b'; break;
|
|
|
|
case BuiltinType::Char_U: case BuiltinType::Char_S: Out << 'c'; break;
|
|
|
|
case BuiltinType::UChar: Out << 'h'; break;
|
|
|
|
case BuiltinType::UShort: Out << 't'; break;
|
|
|
|
case BuiltinType::UInt: Out << 'j'; break;
|
|
|
|
case BuiltinType::ULong: Out << 'm'; break;
|
|
|
|
case BuiltinType::ULongLong: Out << 'y'; break;
|
2009-04-30 10:43:43 +08:00
|
|
|
case BuiltinType::UInt128: Out << 'o'; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
case BuiltinType::SChar: Out << 'a'; break;
|
2010-12-26 07:25:43 +08:00
|
|
|
case BuiltinType::WChar_S:
|
|
|
|
case BuiltinType::WChar_U: Out << 'w'; break;
|
2009-07-14 14:30:34 +08:00
|
|
|
case BuiltinType::Char16: Out << "Ds"; break;
|
|
|
|
case BuiltinType::Char32: Out << "Di"; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
case BuiltinType::Short: Out << 's'; break;
|
|
|
|
case BuiltinType::Int: Out << 'i'; break;
|
|
|
|
case BuiltinType::Long: Out << 'l'; break;
|
|
|
|
case BuiltinType::LongLong: Out << 'x'; break;
|
2009-04-30 10:43:43 +08:00
|
|
|
case BuiltinType::Int128: Out << 'n'; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
case BuiltinType::Float: Out << 'f'; break;
|
|
|
|
case BuiltinType::Double: Out << 'd'; break;
|
|
|
|
case BuiltinType::LongDouble: Out << 'e'; break;
|
2010-11-04 12:31:32 +08:00
|
|
|
case BuiltinType::NullPtr: Out << "Dn"; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
|
|
|
|
case BuiltinType::Overload:
|
|
|
|
case BuiltinType::Dependent:
|
2011-04-27 04:42:42 +08:00
|
|
|
case BuiltinType::BoundMember:
|
2011-04-07 16:22:57 +08:00
|
|
|
case BuiltinType::UnknownAny:
|
2011-05-02 06:35:37 +08:00
|
|
|
llvm_unreachable("mangling a placeholder type");
|
2009-02-13 08:10:09 +08:00
|
|
|
break;
|
2009-07-23 01:14:51 +08:00
|
|
|
case BuiltinType::ObjCId: Out << "11objc_object"; break;
|
|
|
|
case BuiltinType::ObjCClass: Out << "10objc_class"; break;
|
2009-11-22 03:53:08 +08:00
|
|
|
case BuiltinType::ObjCSel: Out << "13objc_selector"; break;
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <function-type>
|
|
|
|
// <function-type> ::= F [Y] <bare-function-type> E
|
|
|
|
void CXXNameMangler::mangleType(const FunctionProtoType *T) {
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'F';
|
2009-05-16 15:57:57 +08:00
|
|
|
// FIXME: We don't have enough information in the AST to produce the 'Y'
|
|
|
|
// encoding for extern "C" function types.
|
2009-02-13 08:10:09 +08:00
|
|
|
mangleBareFunctionType(T, /*MangleReturnType=*/true);
|
|
|
|
Out << 'E';
|
|
|
|
}
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const FunctionNoProtoType *T) {
|
2009-12-12 13:05:38 +08:00
|
|
|
llvm_unreachable("Can't mangle K&R function prototypes");
|
2009-09-05 15:56:18 +08:00
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleBareFunctionType(const FunctionType *T,
|
|
|
|
bool MangleReturnType) {
|
2009-09-05 15:56:18 +08:00
|
|
|
// We should never be mangling something without a prototype.
|
|
|
|
const FunctionProtoType *Proto = cast<FunctionProtoType>(T);
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
// Record that we're in a function type. See mangleFunctionParam
|
|
|
|
// for details on what we're trying to achieve here.
|
|
|
|
FunctionTypeDepthState saved = FunctionTypeDepth.push();
|
|
|
|
|
2009-02-13 08:10:09 +08:00
|
|
|
// <bare-function-type> ::= <signature type>+
|
2011-05-02 06:35:37 +08:00
|
|
|
if (MangleReturnType) {
|
|
|
|
FunctionTypeDepth.enterResultType();
|
2009-09-05 15:56:18 +08:00
|
|
|
mangleType(Proto->getResultType());
|
2011-05-02 06:35:37 +08:00
|
|
|
FunctionTypeDepth.leaveResultType();
|
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2010-06-02 12:40:13 +08:00
|
|
|
if (Proto->getNumArgs() == 0 && !Proto->isVariadic()) {
|
2010-08-22 09:00:03 +08:00
|
|
|
// <builtin-type> ::= v # void
|
2009-04-01 08:15:23 +08:00
|
|
|
Out << 'v';
|
2011-05-02 06:35:37 +08:00
|
|
|
|
|
|
|
FunctionTypeDepth.pop(saved);
|
2009-04-01 08:15:23 +08:00
|
|
|
return;
|
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-02-27 07:50:07 +08:00
|
|
|
for (FunctionProtoType::arg_type_iterator Arg = Proto->arg_type_begin(),
|
2009-09-09 23:08:12 +08:00
|
|
|
ArgEnd = Proto->arg_type_end();
|
2009-02-13 08:10:09 +08:00
|
|
|
Arg != ArgEnd; ++Arg)
|
2011-07-12 12:42:08 +08:00
|
|
|
mangleType(Context.getASTContext().getSignatureParameterType(*Arg));
|
2009-02-13 09:28:03 +08:00
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
FunctionTypeDepth.pop(saved);
|
|
|
|
|
2009-02-13 09:28:03 +08:00
|
|
|
// <builtin-type> ::= z # ellipsis
|
|
|
|
if (Proto->isVariadic())
|
|
|
|
Out << 'z';
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-12-05 06:46:56 +08:00
|
|
|
// <type> ::= <class-enum-type>
|
|
|
|
// <class-enum-type> ::= <name>
|
|
|
|
void CXXNameMangler::mangleType(const UnresolvedUsingType *T) {
|
|
|
|
mangleName(T->getDecl());
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <class-enum-type>
|
2009-09-09 23:08:12 +08:00
|
|
|
// <class-enum-type> ::= <name>
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const EnumType *T) {
|
|
|
|
mangleType(static_cast<const TagType*>(T));
|
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const RecordType *T) {
|
|
|
|
mangleType(static_cast<const TagType*>(T));
|
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleType(const TagType *T) {
|
2009-12-12 02:00:57 +08:00
|
|
|
mangleName(T->getDecl());
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <array-type>
|
|
|
|
// <array-type> ::= A <positive dimension number> _ <element type>
|
|
|
|
// ::= A [<dimension expression>] _ <element type>
|
|
|
|
void CXXNameMangler::mangleType(const ConstantArrayType *T) {
|
|
|
|
Out << 'A' << T->getSize() << '_';
|
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const VariableArrayType *T) {
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << 'A';
|
2010-11-03 00:54:00 +08:00
|
|
|
// decayed vla types (size 0) will just be skipped.
|
|
|
|
if (T->getSizeExpr())
|
|
|
|
mangleExpression(T->getSizeExpr());
|
2009-02-13 08:10:09 +08:00
|
|
|
Out << '_';
|
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const DependentSizedArrayType *T) {
|
|
|
|
Out << 'A';
|
|
|
|
mangleExpression(T->getSizeExpr());
|
|
|
|
Out << '_';
|
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const IncompleteArrayType *T) {
|
2010-09-05 11:40:33 +08:00
|
|
|
Out << "A_";
|
2009-09-05 15:56:18 +08:00
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <pointer-to-member-type>
|
|
|
|
// <pointer-to-member-type> ::= M <class type> <member type>
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleType(const MemberPointerType *T) {
|
|
|
|
Out << 'M';
|
|
|
|
mangleType(QualType(T->getClass(), 0));
|
2009-05-18 01:41:20 +08:00
|
|
|
QualType PointeeType = T->getPointeeType();
|
|
|
|
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(PointeeType)) {
|
2009-09-25 03:53:00 +08:00
|
|
|
mangleQualifiers(Qualifiers::fromCVRMask(FPT->getTypeQuals()));
|
2011-01-27 01:36:28 +08:00
|
|
|
mangleRefQualifier(FPT->getRefQualifier());
|
2009-05-18 01:41:20 +08:00
|
|
|
mangleType(FPT);
|
2010-06-02 12:29:50 +08:00
|
|
|
|
|
|
|
// Itanium C++ ABI 5.1.8:
|
|
|
|
//
|
|
|
|
// The type of a non-static member function is considered to be different,
|
|
|
|
// for the purposes of substitution, from the type of a namespace-scope or
|
|
|
|
// static member function whose type appears similar. The types of two
|
|
|
|
// non-static member functions are considered to be different, for the
|
|
|
|
// purposes of substitution, if the functions are members of different
|
|
|
|
// classes. In other words, for the purposes of substitution, the class of
|
|
|
|
// which the function is a member is considered part of the type of
|
|
|
|
// function.
|
|
|
|
|
|
|
|
// We increment the SeqID here to emulate adding an entry to the
|
|
|
|
// substitution table. We can't actually add it because we don't want this
|
|
|
|
// particular function type to be substituted.
|
|
|
|
++SeqID;
|
2009-09-09 23:08:12 +08:00
|
|
|
} else
|
2009-05-18 01:41:20 +08:00
|
|
|
mangleType(PointeeType);
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= <template-param>
|
2009-02-13 08:10:09 +08:00
|
|
|
void CXXNameMangler::mangleType(const TemplateTypeParmType *T) {
|
2009-09-27 08:38:53 +08:00
|
|
|
mangleTemplateParameter(T->getIndex());
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2011-01-14 10:55:32 +08:00
|
|
|
// <type> ::= <template-param>
|
|
|
|
void CXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T) {
|
2011-07-01 08:04:39 +08:00
|
|
|
// FIXME: not clear how to mangle this!
|
|
|
|
// template <class T...> class A {
|
|
|
|
// template <class U...> void foo(T(*)(U) x...);
|
|
|
|
// };
|
|
|
|
Out << "_SUBSTPACK_";
|
2011-01-14 10:55:32 +08:00
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// <type> ::= P <type> # pointer-to
|
|
|
|
void CXXNameMangler::mangleType(const PointerType *T) {
|
|
|
|
Out << 'P';
|
|
|
|
mangleType(T->getPointeeType());
|
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const ObjCObjectPointerType *T) {
|
|
|
|
Out << 'P';
|
|
|
|
mangleType(T->getPointeeType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= R <type> # reference-to
|
|
|
|
void CXXNameMangler::mangleType(const LValueReferenceType *T) {
|
|
|
|
Out << 'R';
|
|
|
|
mangleType(T->getPointeeType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= O <type> # rvalue reference-to (C++0x)
|
|
|
|
void CXXNameMangler::mangleType(const RValueReferenceType *T) {
|
|
|
|
Out << 'O';
|
|
|
|
mangleType(T->getPointeeType());
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= C <type> # complex pair (C 2000)
|
|
|
|
void CXXNameMangler::mangleType(const ComplexType *T) {
|
|
|
|
Out << 'C';
|
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
|
|
|
|
2010-11-13 01:24:43 +08:00
|
|
|
// ARM's ABI for Neon vector types specifies that they should be mangled as
|
2010-11-16 08:32:18 +08:00
|
|
|
// if they are structs (to match ARM's initial implementation). The
|
|
|
|
// vector type must be one of the special types predefined by ARM.
|
|
|
|
void CXXNameMangler::mangleNeonVectorType(const VectorType *T) {
|
2010-11-13 01:24:43 +08:00
|
|
|
QualType EltType = T->getElementType();
|
2010-11-16 08:32:18 +08:00
|
|
|
assert(EltType->isBuiltinType() && "Neon vector element not a BuiltinType");
|
2010-11-13 01:24:43 +08:00
|
|
|
const char *EltName = 0;
|
2010-11-13 01:24:46 +08:00
|
|
|
if (T->getVectorKind() == VectorType::NeonPolyVector) {
|
|
|
|
switch (cast<BuiltinType>(EltType)->getKind()) {
|
2010-11-13 01:24:49 +08:00
|
|
|
case BuiltinType::SChar: EltName = "poly8_t"; break;
|
|
|
|
case BuiltinType::Short: EltName = "poly16_t"; break;
|
2010-11-16 08:32:18 +08:00
|
|
|
default: llvm_unreachable("unexpected Neon polynomial vector element type");
|
2010-11-13 01:24:46 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (cast<BuiltinType>(EltType)->getKind()) {
|
2010-11-13 01:24:49 +08:00
|
|
|
case BuiltinType::SChar: EltName = "int8_t"; break;
|
|
|
|
case BuiltinType::UChar: EltName = "uint8_t"; break;
|
|
|
|
case BuiltinType::Short: EltName = "int16_t"; break;
|
|
|
|
case BuiltinType::UShort: EltName = "uint16_t"; break;
|
|
|
|
case BuiltinType::Int: EltName = "int32_t"; break;
|
|
|
|
case BuiltinType::UInt: EltName = "uint32_t"; break;
|
|
|
|
case BuiltinType::LongLong: EltName = "int64_t"; break;
|
|
|
|
case BuiltinType::ULongLong: EltName = "uint64_t"; break;
|
|
|
|
case BuiltinType::Float: EltName = "float32_t"; break;
|
2010-11-16 08:32:18 +08:00
|
|
|
default: llvm_unreachable("unexpected Neon vector element type");
|
2010-11-13 01:24:46 +08:00
|
|
|
}
|
2010-11-13 01:24:43 +08:00
|
|
|
}
|
|
|
|
const char *BaseName = 0;
|
2010-11-13 01:24:49 +08:00
|
|
|
unsigned BitSize = (T->getNumElements() *
|
2010-11-16 08:32:12 +08:00
|
|
|
getASTContext().getTypeSize(EltType));
|
2010-11-13 01:24:43 +08:00
|
|
|
if (BitSize == 64)
|
|
|
|
BaseName = "__simd64_";
|
2010-11-16 08:32:18 +08:00
|
|
|
else {
|
|
|
|
assert(BitSize == 128 && "Neon vector type not 64 or 128 bits");
|
2010-11-13 01:24:43 +08:00
|
|
|
BaseName = "__simd128_";
|
2010-11-16 08:32:18 +08:00
|
|
|
}
|
2010-11-13 01:24:43 +08:00
|
|
|
Out << strlen(BaseName) + strlen(EltName);
|
|
|
|
Out << BaseName << EltName;
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
// GNU extension: vector types
|
2010-06-23 14:00:24 +08:00
|
|
|
// <type> ::= <vector-type>
|
|
|
|
// <vector-type> ::= Dv <positive dimension number> _
|
|
|
|
// <extended element type>
|
|
|
|
// ::= Dv [<dimension expression>] _ <element type>
|
|
|
|
// <extended element type> ::= <element type>
|
|
|
|
// ::= p # AltiVec vector pixel
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const VectorType *T) {
|
2010-11-13 01:24:46 +08:00
|
|
|
if ((T->getVectorKind() == VectorType::NeonVector ||
|
2010-11-16 08:32:18 +08:00
|
|
|
T->getVectorKind() == VectorType::NeonPolyVector)) {
|
|
|
|
mangleNeonVectorType(T);
|
2010-11-13 01:24:43 +08:00
|
|
|
return;
|
2010-11-16 08:32:18 +08:00
|
|
|
}
|
2010-03-26 15:18:04 +08:00
|
|
|
Out << "Dv" << T->getNumElements() << '_';
|
2010-11-11 05:56:12 +08:00
|
|
|
if (T->getVectorKind() == VectorType::AltiVecPixel)
|
2010-06-23 14:00:24 +08:00
|
|
|
Out << 'p';
|
2010-11-11 05:56:12 +08:00
|
|
|
else if (T->getVectorKind() == VectorType::AltiVecBool)
|
2010-06-23 14:00:24 +08:00
|
|
|
Out << 'b';
|
|
|
|
else
|
|
|
|
mangleType(T->getElementType());
|
2009-09-05 15:56:18 +08:00
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const ExtVectorType *T) {
|
|
|
|
mangleType(static_cast<const VectorType*>(T));
|
|
|
|
}
|
|
|
|
void CXXNameMangler::mangleType(const DependentSizedExtVectorType *T) {
|
2010-03-26 15:18:04 +08:00
|
|
|
Out << "Dv";
|
|
|
|
mangleExpression(T->getSizeExpr());
|
|
|
|
Out << '_';
|
2009-09-05 15:56:18 +08:00
|
|
|
mangleType(T->getElementType());
|
|
|
|
}
|
|
|
|
|
2010-12-20 10:24:11 +08:00
|
|
|
void CXXNameMangler::mangleType(const PackExpansionType *T) {
|
2011-01-14 00:39:34 +08:00
|
|
|
// <type> ::= Dp <type> # pack expansion (C++0x)
|
2011-01-14 01:44:36 +08:00
|
|
|
Out << "Dp";
|
2010-12-20 10:24:11 +08:00
|
|
|
mangleType(T->getPattern());
|
|
|
|
}
|
|
|
|
|
2009-03-08 06:03:21 +08:00
|
|
|
void CXXNameMangler::mangleType(const ObjCInterfaceType *T) {
|
|
|
|
mangleSourceName(T->getDecl()->getIdentifier());
|
|
|
|
}
|
|
|
|
|
2010-05-15 19:32:37 +08:00
|
|
|
void CXXNameMangler::mangleType(const ObjCObjectType *T) {
|
2010-05-16 01:06:29 +08:00
|
|
|
// We don't allow overloading by different protocol qualification,
|
|
|
|
// so mangling them isn't necessary.
|
2010-05-15 19:32:37 +08:00
|
|
|
mangleType(T->getBaseType());
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const BlockPointerType *T) {
|
2009-12-24 06:31:44 +08:00
|
|
|
Out << "U13block_pointer";
|
|
|
|
mangleType(T->getPointeeType());
|
2009-09-05 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2010-04-27 08:57:59 +08:00
|
|
|
void CXXNameMangler::mangleType(const InjectedClassNameType *T) {
|
|
|
|
// Mangle injected class name types as if the user had written the
|
|
|
|
// specialization out fully. It may not actually be possible to see
|
|
|
|
// this mangling, though.
|
|
|
|
mangleType(T->getInjectedSpecializationType());
|
|
|
|
}
|
|
|
|
|
2009-09-05 15:56:18 +08:00
|
|
|
void CXXNameMangler::mangleType(const TemplateSpecializationType *T) {
|
2010-04-28 13:58:56 +08:00
|
|
|
if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) {
|
|
|
|
mangleName(TD, T->getArgs(), T->getNumArgs());
|
|
|
|
} else {
|
|
|
|
if (mangleSubstitution(QualType(T, 0)))
|
|
|
|
return;
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
mangleTemplatePrefix(T->getTemplateName());
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
// FIXME: GCC does not appear to mangle the template arguments when
|
|
|
|
// the template in question is a dependent template name. Should we
|
|
|
|
// emulate that badness?
|
|
|
|
mangleTemplateArgs(T->getTemplateName(), T->getArgs(), T->getNumArgs());
|
|
|
|
addSubstitution(QualType(T, 0));
|
|
|
|
}
|
2009-09-05 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2010-04-01 01:34:00 +08:00
|
|
|
void CXXNameMangler::mangleType(const DependentNameType *T) {
|
2009-09-26 10:26:02 +08:00
|
|
|
// Typename types are always nested
|
|
|
|
Out << 'N';
|
2011-04-24 16:23:24 +08:00
|
|
|
manglePrefix(T->getQualifier());
|
2010-06-11 08:33:02 +08:00
|
|
|
mangleSourceName(T->getIdentifier());
|
|
|
|
Out << 'E';
|
|
|
|
}
|
2010-06-09 15:26:17 +08:00
|
|
|
|
2010-06-11 08:33:02 +08:00
|
|
|
void CXXNameMangler::mangleType(const DependentTemplateSpecializationType *T) {
|
2011-02-28 08:04:36 +08:00
|
|
|
// Dependently-scoped template types are nested if they have a prefix.
|
2010-06-11 08:33:02 +08:00
|
|
|
Out << 'N';
|
|
|
|
|
|
|
|
// TODO: avoid making this TemplateName.
|
|
|
|
TemplateName Prefix =
|
|
|
|
getASTContext().getDependentTemplateName(T->getQualifier(),
|
|
|
|
T->getIdentifier());
|
|
|
|
mangleTemplatePrefix(Prefix);
|
|
|
|
|
|
|
|
// FIXME: GCC does not appear to mangle the template arguments when
|
|
|
|
// the template in question is a dependent template name. Should we
|
|
|
|
// emulate that badness?
|
|
|
|
mangleTemplateArgs(Prefix, T->getArgs(), T->getNumArgs());
|
2009-09-26 10:26:02 +08:00
|
|
|
Out << 'E';
|
2009-09-05 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2010-03-02 07:49:17 +08:00
|
|
|
void CXXNameMangler::mangleType(const TypeOfType *T) {
|
|
|
|
// FIXME: this is pretty unsatisfactory, but there isn't an obvious
|
|
|
|
// "extension with parameters" mangling.
|
|
|
|
Out << "u6typeof";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleType(const TypeOfExprType *T) {
|
|
|
|
// FIXME: this is pretty unsatisfactory, but there isn't an obvious
|
|
|
|
// "extension with parameters" mangling.
|
|
|
|
Out << "u6typeof";
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleType(const DecltypeType *T) {
|
|
|
|
Expr *E = T->getUnderlyingExpr();
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-03-02 07:49:17 +08:00
|
|
|
// type ::= Dt <expression> E # decltype of an id-expression
|
|
|
|
// # or class member access
|
|
|
|
// ::= DT <expression> E # decltype of an expression
|
|
|
|
|
|
|
|
// This purports to be an exhaustive list of id-expressions and
|
|
|
|
// class member accesses. Note that we do not ignore parentheses;
|
|
|
|
// parentheses change the semantics of decltype for these
|
|
|
|
// expressions (and cause the mangler to use the other form).
|
|
|
|
if (isa<DeclRefExpr>(E) ||
|
|
|
|
isa<MemberExpr>(E) ||
|
|
|
|
isa<UnresolvedLookupExpr>(E) ||
|
|
|
|
isa<DependentScopeDeclRefExpr>(E) ||
|
|
|
|
isa<CXXDependentScopeMemberExpr>(E) ||
|
|
|
|
isa<UnresolvedMemberExpr>(E))
|
|
|
|
Out << "Dt";
|
|
|
|
else
|
|
|
|
Out << "DT";
|
|
|
|
mangleExpression(E);
|
|
|
|
Out << 'E';
|
|
|
|
}
|
|
|
|
|
2011-05-25 06:41:36 +08:00
|
|
|
void CXXNameMangler::mangleType(const UnaryTransformType *T) {
|
|
|
|
// If this is dependent, we need to record that. If not, we simply
|
|
|
|
// mangle it as the underlying type since they are equivalent.
|
|
|
|
if (T->isDependentType()) {
|
|
|
|
Out << 'U';
|
|
|
|
|
|
|
|
switch (T->getUTTKind()) {
|
|
|
|
case UnaryTransformType::EnumUnderlyingType:
|
|
|
|
Out << "3eut";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mangleType(T->getUnderlyingType());
|
|
|
|
}
|
|
|
|
|
2011-02-20 11:19:35 +08:00
|
|
|
void CXXNameMangler::mangleType(const AutoType *T) {
|
|
|
|
QualType D = T->getDeducedType();
|
2011-02-22 04:10:02 +08:00
|
|
|
// <builtin-type> ::= Da # dependent auto
|
|
|
|
if (D.isNull())
|
|
|
|
Out << "Da";
|
|
|
|
else
|
|
|
|
mangleType(D);
|
2011-02-20 11:19:35 +08:00
|
|
|
}
|
|
|
|
|
2010-03-13 18:17:05 +08:00
|
|
|
void CXXNameMangler::mangleIntegerLiteral(QualType T,
|
2009-12-14 09:45:37 +08:00
|
|
|
const llvm::APSInt &Value) {
|
|
|
|
// <expr-primary> ::= L <type> <value number> E # integer literal
|
|
|
|
Out << 'L';
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-14 09:45:37 +08:00
|
|
|
mangleType(T);
|
|
|
|
if (T->isBooleanType()) {
|
|
|
|
// Boolean values are encoded as 0/1.
|
|
|
|
Out << (Value.getBoolValue() ? '1' : '0');
|
|
|
|
} else {
|
2010-07-14 12:20:34 +08:00
|
|
|
mangleNumber(Value);
|
2009-12-14 09:45:37 +08:00
|
|
|
}
|
|
|
|
Out << 'E';
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-14 09:45:37 +08:00
|
|
|
}
|
|
|
|
|
2010-02-04 10:56:29 +08:00
|
|
|
/// Mangles a member expression. Implicit accesses are not handled,
|
|
|
|
/// but that should be okay, because you shouldn't be able to
|
|
|
|
/// make an implicit access in a function template declaration.
|
2011-04-24 16:23:24 +08:00
|
|
|
void CXXNameMangler::mangleMemberExpr(const Expr *base,
|
|
|
|
bool isArrow,
|
|
|
|
NestedNameSpecifier *qualifier,
|
|
|
|
NamedDecl *firstQualifierLookup,
|
|
|
|
DeclarationName member,
|
|
|
|
unsigned arity) {
|
|
|
|
// <expression> ::= dt <expression> <unresolved-name>
|
|
|
|
// ::= pt <expression> <unresolved-name>
|
|
|
|
Out << (isArrow ? "pt" : "dt");
|
|
|
|
mangleExpression(base);
|
|
|
|
mangleUnresolvedName(qualifier, firstQualifierLookup, member, arity);
|
2010-02-04 10:56:29 +08:00
|
|
|
}
|
|
|
|
|
2011-04-28 10:52:03 +08:00
|
|
|
/// Look at the callee of the given call expression and determine if
|
|
|
|
/// it's a parenthesized id-expression which would have triggered ADL
|
|
|
|
/// otherwise.
|
|
|
|
static bool isParenthesizedADLCallee(const CallExpr *call) {
|
|
|
|
const Expr *callee = call->getCallee();
|
|
|
|
const Expr *fn = callee->IgnoreParens();
|
|
|
|
|
|
|
|
// Must be parenthesized. IgnoreParens() skips __extension__ nodes,
|
|
|
|
// too, but for those to appear in the callee, it would have to be
|
|
|
|
// parenthesized.
|
|
|
|
if (callee == fn) return false;
|
|
|
|
|
|
|
|
// Must be an unresolved lookup.
|
|
|
|
const UnresolvedLookupExpr *lookup = dyn_cast<UnresolvedLookupExpr>(fn);
|
|
|
|
if (!lookup) return false;
|
|
|
|
|
|
|
|
assert(!lookup->requiresADL());
|
|
|
|
|
|
|
|
// Must be an unqualified lookup.
|
|
|
|
if (lookup->getQualifier()) return false;
|
|
|
|
|
|
|
|
// Must not have found a class member. Note that if one is a class
|
|
|
|
// member, they're all class members.
|
|
|
|
if (lookup->getNumDecls() > 0 &&
|
|
|
|
(*lookup->decls_begin())->isCXXClassMember())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Otherwise, ADL would have been triggered.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-19 03:18:59 +08:00
|
|
|
void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) {
|
2009-09-21 09:21:10 +08:00
|
|
|
// <expression> ::= <unary operator-name> <expression>
|
2010-02-03 08:55:45 +08:00
|
|
|
// ::= <binary operator-name> <expression> <expression>
|
|
|
|
// ::= <trinary operator-name> <expression> <expression> <expression>
|
2009-09-21 09:21:10 +08:00
|
|
|
// ::= cv <type> expression # conversion with one argument
|
|
|
|
// ::= cv <type> _ <expression>* E # conversion with a different number of arguments
|
2010-08-22 09:00:03 +08:00
|
|
|
// ::= st <type> # sizeof (a type)
|
2009-09-21 09:21:10 +08:00
|
|
|
// ::= at <type> # alignof (a type)
|
|
|
|
// ::= <template-param>
|
|
|
|
// ::= <function-param>
|
|
|
|
// ::= sr <type> <unqualified-name> # dependent name
|
|
|
|
// ::= sr <type> <unqualified-name> <template-args> # dependent template-id
|
2011-06-05 13:27:58 +08:00
|
|
|
// ::= ds <expression> <expression> # expr.*expr
|
2009-09-21 09:21:10 +08:00
|
|
|
// ::= sZ <template-param> # size of a parameter pack
|
2011-01-14 00:39:34 +08:00
|
|
|
// ::= sZ <function-param> # size of a function parameter pack
|
2010-02-03 08:55:45 +08:00
|
|
|
// ::= <expr-primary>
|
2010-02-04 09:42:13 +08:00
|
|
|
// <expr-primary> ::= L <type> <value number> E # integer literal
|
|
|
|
// ::= L <type <value float> E # floating literal
|
|
|
|
// ::= L <mangled-name> E # external name
|
2009-09-21 09:21:10 +08:00
|
|
|
switch (E->getStmtClass()) {
|
2010-04-10 06:26:14 +08:00
|
|
|
case Expr::NoStmtClass:
|
2011-02-09 16:16:59 +08:00
|
|
|
#define ABSTRACT_STMT(Type)
|
2010-04-10 06:26:14 +08:00
|
|
|
#define EXPR(Type, Base)
|
|
|
|
#define STMT(Type, Base) \
|
|
|
|
case Expr::Type##Class:
|
2010-05-05 23:24:00 +08:00
|
|
|
#include "clang/AST/StmtNodes.inc"
|
2010-07-14 12:20:34 +08:00
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
// These all can only appear in local or variable-initialization
|
|
|
|
// contexts and so should never appear in a mangling.
|
|
|
|
case Expr::AddrLabelExprClass:
|
|
|
|
case Expr::BlockDeclRefExprClass:
|
|
|
|
case Expr::CXXThisExprClass:
|
|
|
|
case Expr::DesignatedInitExprClass:
|
|
|
|
case Expr::ImplicitValueInitExprClass:
|
|
|
|
case Expr::InitListExprClass:
|
|
|
|
case Expr::ParenListExprClass:
|
|
|
|
case Expr::CXXScalarValueInitExprClass:
|
2010-02-03 08:55:45 +08:00
|
|
|
llvm_unreachable("unexpected statement kind");
|
|
|
|
break;
|
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
// FIXME: invent manglings for all these.
|
|
|
|
case Expr::BlockExprClass:
|
|
|
|
case Expr::CXXPseudoDestructorExprClass:
|
|
|
|
case Expr::ChooseExprClass:
|
|
|
|
case Expr::CompoundLiteralExprClass:
|
|
|
|
case Expr::ExtVectorElementExprClass:
|
2011-04-15 08:35:48 +08:00
|
|
|
case Expr::GenericSelectionExprClass:
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::ObjCEncodeExprClass:
|
|
|
|
case Expr::ObjCIsaExprClass:
|
|
|
|
case Expr::ObjCIvarRefExprClass:
|
|
|
|
case Expr::ObjCMessageExprClass:
|
|
|
|
case Expr::ObjCPropertyRefExprClass:
|
|
|
|
case Expr::ObjCProtocolExprClass:
|
|
|
|
case Expr::ObjCSelectorExprClass:
|
|
|
|
case Expr::ObjCStringLiteralClass:
|
2011-06-16 07:02:42 +08:00
|
|
|
case Expr::ObjCIndirectCopyRestoreExprClass:
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::OffsetOfExprClass:
|
|
|
|
case Expr::PredefinedExprClass:
|
|
|
|
case Expr::ShuffleVectorExprClass:
|
|
|
|
case Expr::StmtExprClass:
|
|
|
|
case Expr::UnaryTypeTraitExprClass:
|
2010-12-07 08:08:36 +08:00
|
|
|
case Expr::BinaryTypeTraitExprClass:
|
2011-04-28 08:16:57 +08:00
|
|
|
case Expr::ArrayTypeTraitExprClass:
|
2011-04-25 14:54:41 +08:00
|
|
|
case Expr::ExpressionTraitExprClass:
|
2010-09-09 07:47:05 +08:00
|
|
|
case Expr::VAArgExprClass:
|
2010-09-11 04:55:43 +08:00
|
|
|
case Expr::CXXUuidofExprClass:
|
2011-02-10 05:07:24 +08:00
|
|
|
case Expr::CXXNoexceptExprClass:
|
2011-06-04 08:47:47 +08:00
|
|
|
case Expr::CUDAKernelCallExprClass:
|
|
|
|
case Expr::AsTypeExprClass:
|
|
|
|
{
|
2010-04-10 06:26:14 +08:00
|
|
|
// As bad as this diagnostic is, it's better than crashing.
|
|
|
|
Diagnostic &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
|
|
|
|
"cannot yet mangle expression type %0");
|
2010-11-19 04:06:41 +08:00
|
|
|
Diags.Report(E->getExprLoc(), DiagID)
|
2010-04-10 17:39:25 +08:00
|
|
|
<< E->getStmtClassName() << E->getSourceRange();
|
2010-04-10 06:26:14 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
// Even gcc-4.5 doesn't mangle this.
|
|
|
|
case Expr::BinaryConditionalOperatorClass: {
|
|
|
|
Diagnostic &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID =
|
|
|
|
Diags.getCustomDiagID(Diagnostic::Error,
|
|
|
|
"?: operator with omitted middle operand cannot be mangled");
|
|
|
|
Diags.Report(E->getExprLoc(), DiagID)
|
|
|
|
<< E->getStmtClassName() << E->getSourceRange();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are used for internal purposes and cannot be meaningfully mangled.
|
2010-11-16 07:31:06 +08:00
|
|
|
case Expr::OpaqueValueExprClass:
|
|
|
|
llvm_unreachable("cannot mangle opaque value; mangling wrong thing?");
|
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::CXXDefaultArgExprClass:
|
2010-08-19 03:18:59 +08:00
|
|
|
mangleExpression(cast<CXXDefaultArgExpr>(E)->getExpr(), Arity);
|
2010-07-14 12:20:34 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Expr::CXXMemberCallExprClass: // fallthrough
|
2010-02-04 09:42:13 +08:00
|
|
|
case Expr::CallExprClass: {
|
|
|
|
const CallExpr *CE = cast<CallExpr>(E);
|
2011-04-28 10:52:03 +08:00
|
|
|
|
|
|
|
// <expression> ::= cp <simple-id> <expression>* E
|
|
|
|
// We use this mangling only when the call would use ADL except
|
|
|
|
// for being parenthesized. Per discussion with David
|
|
|
|
// Vandervoorde, 2011.04.25.
|
|
|
|
if (isParenthesizedADLCallee(CE)) {
|
|
|
|
Out << "cp";
|
|
|
|
// The callee here is a parenthesized UnresolvedLookupExpr with
|
|
|
|
// no qualifier and should always get mangled as a <simple-id>
|
|
|
|
// anyway.
|
|
|
|
|
|
|
|
// <expression> ::= cl <expression>* E
|
|
|
|
} else {
|
|
|
|
Out << "cl";
|
|
|
|
}
|
|
|
|
|
2010-08-19 03:18:59 +08:00
|
|
|
mangleExpression(CE->getCallee(), CE->getNumArgs());
|
2010-02-04 09:42:13 +08:00
|
|
|
for (unsigned I = 0, N = CE->getNumArgs(); I != N; ++I)
|
|
|
|
mangleExpression(CE->getArg(I));
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'E';
|
2010-02-03 08:55:45 +08:00
|
|
|
break;
|
2010-02-04 09:42:13 +08:00
|
|
|
}
|
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::CXXNewExprClass: {
|
|
|
|
// Proposal from David Vandervoorde, 2010.06.30
|
|
|
|
const CXXNewExpr *New = cast<CXXNewExpr>(E);
|
|
|
|
if (New->isGlobalNew()) Out << "gs";
|
|
|
|
Out << (New->isArray() ? "na" : "nw");
|
|
|
|
for (CXXNewExpr::const_arg_iterator I = New->placement_arg_begin(),
|
|
|
|
E = New->placement_arg_end(); I != E; ++I)
|
|
|
|
mangleExpression(*I);
|
|
|
|
Out << '_';
|
|
|
|
mangleType(New->getAllocatedType());
|
|
|
|
if (New->hasInitializer()) {
|
|
|
|
Out << "pi";
|
|
|
|
for (CXXNewExpr::const_arg_iterator I = New->constructor_arg_begin(),
|
|
|
|
E = New->constructor_arg_end(); I != E; ++I)
|
|
|
|
mangleExpression(*I);
|
|
|
|
}
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-04 10:56:29 +08:00
|
|
|
case Expr::MemberExprClass: {
|
|
|
|
const MemberExpr *ME = cast<MemberExpr>(E);
|
|
|
|
mangleMemberExpr(ME->getBase(), ME->isArrow(),
|
2011-04-24 16:23:24 +08:00
|
|
|
ME->getQualifier(), 0, ME->getMemberDecl()->getDeclName(),
|
2010-08-19 03:18:59 +08:00
|
|
|
Arity);
|
2010-02-04 10:56:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::UnresolvedMemberExprClass: {
|
|
|
|
const UnresolvedMemberExpr *ME = cast<UnresolvedMemberExpr>(E);
|
|
|
|
mangleMemberExpr(ME->getBase(), ME->isArrow(),
|
2011-04-24 16:23:24 +08:00
|
|
|
ME->getQualifier(), 0, ME->getMemberName(),
|
2010-08-19 03:18:59 +08:00
|
|
|
Arity);
|
2010-08-20 08:17:19 +08:00
|
|
|
if (ME->hasExplicitTemplateArgs())
|
|
|
|
mangleTemplateArgs(ME->getExplicitTemplateArgs());
|
2010-02-04 10:56:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXDependentScopeMemberExprClass: {
|
|
|
|
const CXXDependentScopeMemberExpr *ME
|
|
|
|
= cast<CXXDependentScopeMemberExpr>(E);
|
|
|
|
mangleMemberExpr(ME->getBase(), ME->isArrow(),
|
2011-04-24 16:23:24 +08:00
|
|
|
ME->getQualifier(), ME->getFirstQualifierFoundInScope(),
|
|
|
|
ME->getMember(), Arity);
|
2010-08-20 08:17:19 +08:00
|
|
|
if (ME->hasExplicitTemplateArgs())
|
|
|
|
mangleTemplateArgs(ME->getExplicitTemplateArgs());
|
2010-02-04 10:56:29 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
case Expr::UnresolvedLookupExprClass: {
|
|
|
|
const UnresolvedLookupExpr *ULE = cast<UnresolvedLookupExpr>(E);
|
2011-04-24 16:23:24 +08:00
|
|
|
mangleUnresolvedName(ULE->getQualifier(), 0, ULE->getName(), Arity);
|
2011-06-22 06:12:46 +08:00
|
|
|
|
|
|
|
// All the <unresolved-name> productions end in a
|
|
|
|
// base-unresolved-name, where <template-args> are just tacked
|
|
|
|
// onto the end.
|
2010-08-20 08:17:19 +08:00
|
|
|
if (ULE->hasExplicitTemplateArgs())
|
|
|
|
mangleTemplateArgs(ULE->getExplicitTemplateArgs());
|
2010-02-04 09:42:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-03-13 18:17:05 +08:00
|
|
|
case Expr::CXXUnresolvedConstructExprClass: {
|
2010-02-04 09:42:13 +08:00
|
|
|
const CXXUnresolvedConstructExpr *CE = cast<CXXUnresolvedConstructExpr>(E);
|
|
|
|
unsigned N = CE->arg_size();
|
2010-02-03 08:55:45 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
Out << "cv";
|
|
|
|
mangleType(CE->getType());
|
2010-04-11 00:03:31 +08:00
|
|
|
if (N != 1) Out << '_';
|
2010-02-04 09:42:13 +08:00
|
|
|
for (unsigned I = 0; I != N; ++I) mangleExpression(CE->getArg(I));
|
2010-04-11 00:03:31 +08:00
|
|
|
if (N != 1) Out << 'E';
|
2010-03-13 18:17:05 +08:00
|
|
|
break;
|
2010-02-04 09:42:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXTemporaryObjectExprClass:
|
|
|
|
case Expr::CXXConstructExprClass: {
|
|
|
|
const CXXConstructExpr *CE = cast<CXXConstructExpr>(E);
|
|
|
|
unsigned N = CE->getNumArgs();
|
2010-02-03 08:55:45 +08:00
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
Out << "cv";
|
|
|
|
mangleType(CE->getType());
|
2010-04-11 00:03:31 +08:00
|
|
|
if (N != 1) Out << '_';
|
2010-02-04 09:42:13 +08:00
|
|
|
for (unsigned I = 0; I != N; ++I) mangleExpression(CE->getArg(I));
|
2010-04-11 00:03:31 +08:00
|
|
|
if (N != 1) Out << 'E';
|
2010-02-03 08:55:45 +08:00
|
|
|
break;
|
2010-02-04 09:42:13 +08:00
|
|
|
}
|
|
|
|
|
2011-03-12 03:24:49 +08:00
|
|
|
case Expr::UnaryExprOrTypeTraitExprClass: {
|
|
|
|
const UnaryExprOrTypeTraitExpr *SAE = cast<UnaryExprOrTypeTraitExpr>(E);
|
|
|
|
switch(SAE->getKind()) {
|
|
|
|
case UETT_SizeOf:
|
|
|
|
Out << 's';
|
|
|
|
break;
|
|
|
|
case UETT_AlignOf:
|
|
|
|
Out << 'a';
|
|
|
|
break;
|
|
|
|
case UETT_VecStep:
|
|
|
|
Diagnostic &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
|
|
|
|
"cannot yet mangle vec_step expression");
|
|
|
|
Diags.Report(DiagID);
|
|
|
|
return;
|
|
|
|
}
|
2010-02-04 09:42:13 +08:00
|
|
|
if (SAE->isArgumentType()) {
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 't';
|
2010-02-04 09:42:13 +08:00
|
|
|
mangleType(SAE->getArgumentType());
|
|
|
|
} else {
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'z';
|
2010-02-04 09:42:13 +08:00
|
|
|
mangleExpression(SAE->getArgumentExpr());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-11-06 10:50:19 +08:00
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::CXXThrowExprClass: {
|
|
|
|
const CXXThrowExpr *TE = cast<CXXThrowExpr>(E);
|
|
|
|
|
|
|
|
// Proposal from David Vandervoorde, 2010.06.30
|
|
|
|
if (TE->getSubExpr()) {
|
|
|
|
Out << "tw";
|
|
|
|
mangleExpression(TE->getSubExpr());
|
|
|
|
} else {
|
|
|
|
Out << "tr";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXTypeidExprClass: {
|
|
|
|
const CXXTypeidExpr *TIE = cast<CXXTypeidExpr>(E);
|
|
|
|
|
|
|
|
// Proposal from David Vandervoorde, 2010.06.30
|
|
|
|
if (TIE->isTypeOperand()) {
|
|
|
|
Out << "ti";
|
|
|
|
mangleType(TIE->getTypeOperand());
|
|
|
|
} else {
|
|
|
|
Out << "te";
|
|
|
|
mangleExpression(TIE->getExprOperand());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXDeleteExprClass: {
|
|
|
|
const CXXDeleteExpr *DE = cast<CXXDeleteExpr>(E);
|
|
|
|
|
|
|
|
// Proposal from David Vandervoorde, 2010.06.30
|
|
|
|
if (DE->isGlobalDelete()) Out << "gs";
|
|
|
|
Out << (DE->isArrayForm() ? "da" : "dl");
|
|
|
|
mangleExpression(DE->getArgument());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-12-14 09:45:37 +08:00
|
|
|
case Expr::UnaryOperatorClass: {
|
|
|
|
const UnaryOperator *UO = cast<UnaryOperator>(E);
|
2010-03-13 18:17:05 +08:00
|
|
|
mangleOperatorName(UnaryOperator::getOverloadedOperator(UO->getOpcode()),
|
2009-12-14 09:45:37 +08:00
|
|
|
/*Arity=*/1);
|
|
|
|
mangleExpression(UO->getSubExpr());
|
|
|
|
break;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::ArraySubscriptExprClass: {
|
|
|
|
const ArraySubscriptExpr *AE = cast<ArraySubscriptExpr>(E);
|
|
|
|
|
2011-04-15 13:22:18 +08:00
|
|
|
// Array subscript is treated as a syntactically weird form of
|
2010-07-14 12:20:34 +08:00
|
|
|
// binary operator.
|
|
|
|
Out << "ix";
|
|
|
|
mangleExpression(AE->getLHS());
|
|
|
|
mangleExpression(AE->getRHS());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CompoundAssignOperatorClass: // fallthrough
|
2009-12-14 09:45:37 +08:00
|
|
|
case Expr::BinaryOperatorClass: {
|
|
|
|
const BinaryOperator *BO = cast<BinaryOperator>(E);
|
2011-06-05 13:27:58 +08:00
|
|
|
if (BO->getOpcode() == BO_PtrMemD)
|
|
|
|
Out << "ds";
|
|
|
|
else
|
|
|
|
mangleOperatorName(BinaryOperator::getOverloadedOperator(BO->getOpcode()),
|
|
|
|
/*Arity=*/2);
|
2009-12-14 09:45:37 +08:00
|
|
|
mangleExpression(BO->getLHS());
|
2010-03-13 18:17:05 +08:00
|
|
|
mangleExpression(BO->getRHS());
|
2009-12-14 09:45:37 +08:00
|
|
|
break;
|
2010-02-04 10:56:29 +08:00
|
|
|
}
|
2009-12-14 09:45:37 +08:00
|
|
|
|
|
|
|
case Expr::ConditionalOperatorClass: {
|
|
|
|
const ConditionalOperator *CO = cast<ConditionalOperator>(E);
|
|
|
|
mangleOperatorName(OO_Conditional, /*Arity=*/3);
|
|
|
|
mangleExpression(CO->getCond());
|
2010-08-19 03:18:59 +08:00
|
|
|
mangleExpression(CO->getLHS(), Arity);
|
|
|
|
mangleExpression(CO->getRHS(), Arity);
|
2009-12-14 09:45:37 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-01-30 00:37:09 +08:00
|
|
|
case Expr::ImplicitCastExprClass: {
|
2010-08-19 03:18:59 +08:00
|
|
|
mangleExpression(cast<ImplicitCastExpr>(E)->getSubExpr(), Arity);
|
2010-01-30 00:37:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
case Expr::ObjCBridgedCastExprClass: {
|
|
|
|
// Mangle ownership casts as a vendor extended operator __bridge,
|
|
|
|
// __bridge_transfer, or __bridge_retain.
|
|
|
|
llvm::StringRef Kind = cast<ObjCBridgedCastExpr>(E)->getBridgeKindName();
|
|
|
|
Out << "v1U" << Kind.size() << Kind;
|
|
|
|
}
|
|
|
|
// Fall through to mangle the cast itself.
|
|
|
|
|
2010-01-30 00:37:09 +08:00
|
|
|
case Expr::CStyleCastExprClass:
|
|
|
|
case Expr::CXXStaticCastExprClass:
|
|
|
|
case Expr::CXXDynamicCastExprClass:
|
|
|
|
case Expr::CXXReinterpretCastExprClass:
|
|
|
|
case Expr::CXXConstCastExprClass:
|
|
|
|
case Expr::CXXFunctionalCastExprClass: {
|
|
|
|
const ExplicitCastExpr *ECE = cast<ExplicitCastExpr>(E);
|
|
|
|
Out << "cv";
|
|
|
|
mangleType(ECE->getType());
|
|
|
|
mangleExpression(ECE->getSubExpr());
|
|
|
|
break;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-16 13:48:46 +08:00
|
|
|
case Expr::CXXOperatorCallExprClass: {
|
|
|
|
const CXXOperatorCallExpr *CE = cast<CXXOperatorCallExpr>(E);
|
|
|
|
unsigned NumArgs = CE->getNumArgs();
|
|
|
|
mangleOperatorName(CE->getOperator(), /*Arity=*/NumArgs);
|
|
|
|
// Mangle the arguments.
|
|
|
|
for (unsigned i = 0; i != NumArgs; ++i)
|
|
|
|
mangleExpression(CE->getArg(i));
|
|
|
|
break;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-11-06 10:50:19 +08:00
|
|
|
case Expr::ParenExprClass:
|
2010-08-19 03:18:59 +08:00
|
|
|
mangleExpression(cast<ParenExpr>(E)->getSubExpr(), Arity);
|
2009-11-06 10:50:19 +08:00
|
|
|
break;
|
|
|
|
|
2009-09-21 09:21:10 +08:00
|
|
|
case Expr::DeclRefExprClass: {
|
2010-03-01 05:40:32 +08:00
|
|
|
const NamedDecl *D = cast<DeclRefExpr>(E)->getDecl();
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-21 09:21:10 +08:00
|
|
|
switch (D->getKind()) {
|
2010-03-13 18:17:05 +08:00
|
|
|
default:
|
2010-03-01 05:40:32 +08:00
|
|
|
// <expr-primary> ::= L <mangled-name> E # external name
|
|
|
|
Out << 'L';
|
|
|
|
mangle(D, "_Z");
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
case Decl::ParmVar:
|
|
|
|
mangleFunctionParam(cast<ParmVarDecl>(D));
|
|
|
|
break;
|
|
|
|
|
2010-07-24 09:17:35 +08:00
|
|
|
case Decl::EnumConstant: {
|
|
|
|
const EnumConstantDecl *ED = cast<EnumConstantDecl>(D);
|
|
|
|
mangleIntegerLiteral(ED->getType(), ED->getInitVal());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-21 09:21:10 +08:00
|
|
|
case Decl::NonTypeTemplateParm: {
|
|
|
|
const NonTypeTemplateParmDecl *PD = cast<NonTypeTemplateParmDecl>(D);
|
2009-09-27 08:38:53 +08:00
|
|
|
mangleTemplateParameter(PD->getIndex());
|
2009-09-21 09:21:10 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-28 04:11:34 +08:00
|
|
|
break;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2011-01-15 09:15:58 +08:00
|
|
|
case Expr::SubstNonTypeTemplateParmPackExprClass:
|
2011-07-01 08:04:39 +08:00
|
|
|
// FIXME: not clear how to mangle this!
|
|
|
|
// template <unsigned N...> class A {
|
|
|
|
// template <class U...> void foo(U (&x)[N]...);
|
|
|
|
// };
|
|
|
|
Out << "_SUBSTPACK_";
|
2011-01-15 09:15:58 +08:00
|
|
|
break;
|
|
|
|
|
2009-11-20 06:55:06 +08:00
|
|
|
case Expr::DependentScopeDeclRefExprClass: {
|
|
|
|
const DependentScopeDeclRefExpr *DRE = cast<DependentScopeDeclRefExpr>(E);
|
2011-06-22 06:12:46 +08:00
|
|
|
mangleUnresolvedName(DRE->getQualifier(), 0, DRE->getDeclName(), Arity);
|
2009-09-28 04:11:34 +08:00
|
|
|
|
2011-06-22 06:12:46 +08:00
|
|
|
// All the <unresolved-name> productions end in a
|
|
|
|
// base-unresolved-name, where <template-args> are just tacked
|
|
|
|
// onto the end.
|
2010-08-20 08:17:19 +08:00
|
|
|
if (DRE->hasExplicitTemplateArgs())
|
|
|
|
mangleTemplateArgs(DRE->getExplicitTemplateArgs());
|
2009-09-28 04:11:34 +08:00
|
|
|
break;
|
2009-09-21 09:21:10 +08:00
|
|
|
}
|
2009-09-28 04:11:34 +08:00
|
|
|
|
2010-04-10 06:54:09 +08:00
|
|
|
case Expr::CXXBindTemporaryExprClass:
|
|
|
|
mangleExpression(cast<CXXBindTemporaryExpr>(E)->getSubExpr());
|
|
|
|
break;
|
|
|
|
|
2010-12-06 16:20:24 +08:00
|
|
|
case Expr::ExprWithCleanupsClass:
|
|
|
|
mangleExpression(cast<ExprWithCleanups>(E)->getSubExpr(), Arity);
|
2010-04-10 06:54:09 +08:00
|
|
|
break;
|
|
|
|
|
2010-02-04 09:42:13 +08:00
|
|
|
case Expr::FloatingLiteralClass: {
|
|
|
|
const FloatingLiteral *FL = cast<FloatingLiteral>(E);
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'L';
|
2010-02-04 09:42:13 +08:00
|
|
|
mangleType(FL->getType());
|
2010-07-14 12:20:34 +08:00
|
|
|
mangleFloat(FL->getValue());
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'E';
|
2010-02-04 09:42:13 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-04-10 05:48:08 +08:00
|
|
|
case Expr::CharacterLiteralClass:
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'L';
|
2010-04-10 05:48:08 +08:00
|
|
|
mangleType(E->getType());
|
|
|
|
Out << cast<CharacterLiteral>(E)->getValue();
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Expr::CXXBoolLiteralExprClass:
|
|
|
|
Out << "Lb";
|
|
|
|
Out << (cast<CXXBoolLiteralExpr>(E)->getValue() ? '1' : '0');
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
|
2010-07-14 12:20:34 +08:00
|
|
|
case Expr::IntegerLiteralClass: {
|
|
|
|
llvm::APSInt Value(cast<IntegerLiteral>(E)->getValue());
|
|
|
|
if (E->getType()->isSignedIntegerType())
|
|
|
|
Value.setIsSigned(true);
|
|
|
|
mangleIntegerLiteral(E->getType(), Value);
|
2009-12-14 09:45:37 +08:00
|
|
|
break;
|
2010-07-14 12:20:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::ImaginaryLiteralClass: {
|
|
|
|
const ImaginaryLiteral *IE = cast<ImaginaryLiteral>(E);
|
|
|
|
// Mangle as if a complex literal.
|
2010-09-05 11:40:33 +08:00
|
|
|
// Proposal from David Vandevoorde, 2010.06.30.
|
2010-07-14 12:20:34 +08:00
|
|
|
Out << 'L';
|
|
|
|
mangleType(E->getType());
|
|
|
|
if (const FloatingLiteral *Imag =
|
|
|
|
dyn_cast<FloatingLiteral>(IE->getSubExpr())) {
|
|
|
|
// Mangle a floating-point zero of the appropriate type.
|
|
|
|
mangleFloat(llvm::APFloat(Imag->getValue().getSemantics()));
|
|
|
|
Out << '_';
|
|
|
|
mangleFloat(Imag->getValue());
|
|
|
|
} else {
|
2010-09-05 11:40:33 +08:00
|
|
|
Out << "0_";
|
2010-07-14 12:20:34 +08:00
|
|
|
llvm::APSInt Value(cast<IntegerLiteral>(IE->getSubExpr())->getValue());
|
|
|
|
if (IE->getSubExpr()->getType()->isSignedIntegerType())
|
|
|
|
Value.setIsSigned(true);
|
|
|
|
mangleNumber(Value);
|
|
|
|
}
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::StringLiteralClass: {
|
2010-07-16 05:53:03 +08:00
|
|
|
// Revised proposal from David Vandervoorde, 2010.07.15.
|
2010-07-14 12:20:34 +08:00
|
|
|
Out << 'L';
|
2010-07-16 05:53:03 +08:00
|
|
|
assert(isa<ConstantArrayType>(E->getType()));
|
|
|
|
mangleType(E->getType());
|
2010-07-14 12:20:34 +08:00
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::GNUNullExprClass:
|
|
|
|
// FIXME: should this really be mangled the same as nullptr?
|
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
case Expr::CXXNullPtrLiteralExprClass: {
|
|
|
|
// Proposal from David Vandervoorde, 2010.06.30, as
|
|
|
|
// modified by ABI list discussion.
|
|
|
|
Out << "LDnE";
|
|
|
|
break;
|
|
|
|
}
|
2011-01-04 01:17:50 +08:00
|
|
|
|
|
|
|
case Expr::PackExpansionExprClass:
|
|
|
|
Out << "sp";
|
|
|
|
mangleExpression(cast<PackExpansionExpr>(E)->getPattern());
|
|
|
|
break;
|
2011-01-05 02:56:13 +08:00
|
|
|
|
|
|
|
case Expr::SizeOfPackExprClass: {
|
|
|
|
Out << "sZ";
|
|
|
|
const NamedDecl *Pack = cast<SizeOfPackExpr>(E)->getPack();
|
|
|
|
if (const TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(Pack))
|
|
|
|
mangleTemplateParameter(TTP->getIndex());
|
|
|
|
else if (const NonTypeTemplateParmDecl *NTTP
|
|
|
|
= dyn_cast<NonTypeTemplateParmDecl>(Pack))
|
|
|
|
mangleTemplateParameter(NTTP->getIndex());
|
|
|
|
else if (const TemplateTemplateParmDecl *TempTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(Pack))
|
|
|
|
mangleTemplateParameter(TempTP->getIndex());
|
|
|
|
else {
|
2011-01-14 00:39:34 +08:00
|
|
|
// Note: proposed by Mike Herrick on 11/30/10
|
|
|
|
// <expression> ::= sZ <function-param> # size of function parameter pack
|
2011-01-05 02:56:13 +08:00
|
|
|
Diagnostic &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
|
|
|
|
"cannot mangle sizeof...(function parameter pack)");
|
|
|
|
Diags.Report(DiagID);
|
|
|
|
return;
|
|
|
|
}
|
2011-03-03 10:20:19 +08:00
|
|
|
break;
|
2011-01-05 02:56:13 +08:00
|
|
|
}
|
2011-06-22 01:03:29 +08:00
|
|
|
|
|
|
|
case Expr::MaterializeTemporaryExprClass: {
|
|
|
|
mangleExpression(cast<MaterializeTemporaryExpr>(E)->GetTemporaryExpr());
|
|
|
|
break;
|
|
|
|
}
|
2009-09-21 09:21:10 +08:00
|
|
|
}
|
2009-02-13 08:10:09 +08:00
|
|
|
}
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
/// Mangle an expression which refers to a parameter variable.
|
|
|
|
///
|
|
|
|
/// <expression> ::= <function-param>
|
|
|
|
/// <function-param> ::= fp <top-level CV-qualifiers> _ # L == 0, I == 0
|
|
|
|
/// <function-param> ::= fp <top-level CV-qualifiers>
|
|
|
|
/// <parameter-2 non-negative number> _ # L == 0, I > 0
|
|
|
|
/// <function-param> ::= fL <L-1 non-negative number>
|
|
|
|
/// p <top-level CV-qualifiers> _ # L > 0, I == 0
|
|
|
|
/// <function-param> ::= fL <L-1 non-negative number>
|
|
|
|
/// p <top-level CV-qualifiers>
|
|
|
|
/// <I-1 non-negative number> _ # L > 0, I > 0
|
|
|
|
///
|
|
|
|
/// L is the nesting depth of the parameter, defined as 1 if the
|
|
|
|
/// parameter comes from the innermost function prototype scope
|
|
|
|
/// enclosing the current context, 2 if from the next enclosing
|
|
|
|
/// function prototype scope, and so on, with one special case: if
|
|
|
|
/// we've processed the full parameter clause for the innermost
|
|
|
|
/// function type, then L is one less. This definition conveniently
|
|
|
|
/// makes it irrelevant whether a function's result type was written
|
|
|
|
/// trailing or leading, but is otherwise overly complicated; the
|
|
|
|
/// numbering was first designed without considering references to
|
|
|
|
/// parameter in locations other than return types, and then the
|
|
|
|
/// mangling had to be generalized without changing the existing
|
|
|
|
/// manglings.
|
|
|
|
///
|
|
|
|
/// I is the zero-based index of the parameter within its parameter
|
|
|
|
/// declaration clause. Note that the original ABI document describes
|
|
|
|
/// this using 1-based ordinals.
|
|
|
|
void CXXNameMangler::mangleFunctionParam(const ParmVarDecl *parm) {
|
|
|
|
unsigned parmDepth = parm->getFunctionScopeDepth();
|
|
|
|
unsigned parmIndex = parm->getFunctionScopeIndex();
|
|
|
|
|
|
|
|
// Compute 'L'.
|
|
|
|
// parmDepth does not include the declaring function prototype.
|
|
|
|
// FunctionTypeDepth does account for that.
|
|
|
|
assert(parmDepth < FunctionTypeDepth.getDepth());
|
|
|
|
unsigned nestingDepth = FunctionTypeDepth.getDepth() - parmDepth;
|
|
|
|
if (FunctionTypeDepth.isInResultType())
|
|
|
|
nestingDepth--;
|
|
|
|
|
|
|
|
if (nestingDepth == 0) {
|
|
|
|
Out << "fp";
|
|
|
|
} else {
|
|
|
|
Out << "fL" << (nestingDepth - 1) << 'p';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Top-level qualifiers. We don't have to worry about arrays here,
|
|
|
|
// because parameters declared as arrays should already have been
|
|
|
|
// tranformed to have pointer type. FIXME: apparently these don't
|
|
|
|
// get mangled if used as an rvalue of a known non-class type?
|
|
|
|
assert(!parm->getType()->isArrayType()
|
|
|
|
&& "parameter's type is still an array type?");
|
|
|
|
mangleQualifiers(parm->getType().getQualifiers());
|
|
|
|
|
|
|
|
// Parameter index.
|
|
|
|
if (parmIndex != 0) {
|
|
|
|
Out << (parmIndex - 1);
|
|
|
|
}
|
|
|
|
Out << '_';
|
|
|
|
}
|
|
|
|
|
2009-04-15 13:36:58 +08:00
|
|
|
void CXXNameMangler::mangleCXXCtorType(CXXCtorType T) {
|
|
|
|
// <ctor-dtor-name> ::= C1 # complete object constructor
|
|
|
|
// ::= C2 # base object constructor
|
|
|
|
// ::= C3 # complete object allocating constructor
|
|
|
|
//
|
|
|
|
switch (T) {
|
|
|
|
case Ctor_Complete:
|
|
|
|
Out << "C1";
|
|
|
|
break;
|
|
|
|
case Ctor_Base:
|
|
|
|
Out << "C2";
|
|
|
|
break;
|
|
|
|
case Ctor_CompleteAllocating:
|
|
|
|
Out << "C3";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 09:58:57 +08:00
|
|
|
void CXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
|
|
|
|
// <ctor-dtor-name> ::= D0 # deleting destructor
|
|
|
|
// ::= D1 # complete object destructor
|
|
|
|
// ::= D2 # base object destructor
|
|
|
|
//
|
|
|
|
switch (T) {
|
|
|
|
case Dtor_Deleting:
|
|
|
|
Out << "D0";
|
|
|
|
break;
|
|
|
|
case Dtor_Complete:
|
|
|
|
Out << "D1";
|
|
|
|
break;
|
|
|
|
case Dtor_Base:
|
|
|
|
Out << "D2";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 08:17:19 +08:00
|
|
|
void CXXNameMangler::mangleTemplateArgs(
|
|
|
|
const ExplicitTemplateArgumentList &TemplateArgs) {
|
|
|
|
// <template-args> ::= I <template-arg>+ E
|
|
|
|
Out << 'I';
|
2011-05-04 09:45:19 +08:00
|
|
|
for (unsigned i = 0, e = TemplateArgs.NumTemplateArgs; i != e; ++i)
|
|
|
|
mangleTemplateArg(0, TemplateArgs.getTemplateArgs()[i].getArgument());
|
2010-08-20 08:17:19 +08:00
|
|
|
Out << 'E';
|
|
|
|
}
|
|
|
|
|
2010-04-23 11:10:43 +08:00
|
|
|
void CXXNameMangler::mangleTemplateArgs(TemplateName Template,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
|
|
|
unsigned NumTemplateArgs) {
|
|
|
|
if (TemplateDecl *TD = Template.getAsTemplateDecl())
|
|
|
|
return mangleTemplateArgs(*TD->getTemplateParameters(), TemplateArgs,
|
|
|
|
NumTemplateArgs);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2011-05-04 09:45:19 +08:00
|
|
|
mangleUnresolvedTemplateArgs(TemplateArgs, NumTemplateArgs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleUnresolvedTemplateArgs(const TemplateArgument *args,
|
|
|
|
unsigned numArgs) {
|
2010-04-23 11:10:43 +08:00
|
|
|
// <template-args> ::= I <template-arg>+ E
|
|
|
|
Out << 'I';
|
2011-05-04 09:45:19 +08:00
|
|
|
for (unsigned i = 0; i != numArgs; ++i)
|
|
|
|
mangleTemplateArg(0, args[i]);
|
2010-04-23 11:10:43 +08:00
|
|
|
Out << 'E';
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:00 +08:00
|
|
|
void CXXNameMangler::mangleTemplateArgs(const TemplateParameterList &PL,
|
|
|
|
const TemplateArgumentList &AL) {
|
2009-05-16 00:09:15 +08:00
|
|
|
// <template-args> ::= I <template-arg>+ E
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'I';
|
2010-03-11 22:07:00 +08:00
|
|
|
for (unsigned i = 0, e = AL.size(); i != e; ++i)
|
|
|
|
mangleTemplateArg(PL.getParam(i), AL[i]);
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'E';
|
2009-05-16 00:09:15 +08:00
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:00 +08:00
|
|
|
void CXXNameMangler::mangleTemplateArgs(const TemplateParameterList &PL,
|
|
|
|
const TemplateArgument *TemplateArgs,
|
2009-09-18 10:42:01 +08:00
|
|
|
unsigned NumTemplateArgs) {
|
|
|
|
// <template-args> ::= I <template-arg>+ E
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'I';
|
2009-11-21 17:17:15 +08:00
|
|
|
for (unsigned i = 0; i != NumTemplateArgs; ++i)
|
2010-03-11 22:07:00 +08:00
|
|
|
mangleTemplateArg(PL.getParam(i), TemplateArgs[i]);
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'E';
|
2009-09-18 10:42:01 +08:00
|
|
|
}
|
|
|
|
|
2010-03-11 22:07:00 +08:00
|
|
|
void CXXNameMangler::mangleTemplateArg(const NamedDecl *P,
|
|
|
|
const TemplateArgument &A) {
|
2009-09-09 23:08:12 +08:00
|
|
|
// <template-arg> ::= <type> # type or template
|
2009-05-16 00:09:15 +08:00
|
|
|
// ::= X <expression> E # expression
|
|
|
|
// ::= <expr-primary> # simple expressions
|
2011-01-14 00:39:34 +08:00
|
|
|
// ::= J <template-arg>* E # argument pack
|
2009-05-16 00:09:15 +08:00
|
|
|
// ::= sp <expression> # pack expansion of (C++0x)
|
|
|
|
switch (A.getKind()) {
|
2011-01-04 06:36:02 +08:00
|
|
|
case TemplateArgument::Null:
|
|
|
|
llvm_unreachable("Cannot mangle NULL template argument");
|
|
|
|
|
2009-05-16 00:09:15 +08:00
|
|
|
case TemplateArgument::Type:
|
|
|
|
mangleType(A.getAsType());
|
|
|
|
break;
|
2009-12-24 03:30:55 +08:00
|
|
|
case TemplateArgument::Template:
|
2010-07-14 14:43:17 +08:00
|
|
|
// This is mangled as <type>.
|
|
|
|
mangleType(A.getAsTemplate());
|
2010-03-13 18:17:05 +08:00
|
|
|
break;
|
2011-01-06 02:58:31 +08:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
2011-01-14 00:39:34 +08:00
|
|
|
// <type> ::= Dp <type> # pack expansion (C++0x)
|
2011-01-06 02:58:31 +08:00
|
|
|
Out << "Dp";
|
|
|
|
mangleType(A.getAsTemplateOrTemplatePattern());
|
|
|
|
break;
|
2009-09-21 09:21:10 +08:00
|
|
|
case TemplateArgument::Expression:
|
|
|
|
Out << 'X';
|
|
|
|
mangleExpression(A.getAsExpr());
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
2009-12-14 09:45:37 +08:00
|
|
|
case TemplateArgument::Integral:
|
|
|
|
mangleIntegerLiteral(A.getIntegralType(), *A.getAsIntegral());
|
2009-11-21 17:17:15 +08:00
|
|
|
break;
|
|
|
|
case TemplateArgument::Declaration: {
|
2010-04-23 11:10:43 +08:00
|
|
|
assert(P && "Missing template parameter for declaration argument");
|
2009-11-21 17:17:15 +08:00
|
|
|
// <expr-primary> ::= L <mangled-name> E # external name
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-03-11 22:07:00 +08:00
|
|
|
// Clang produces AST's where pointer-to-member-function expressions
|
2009-11-21 17:17:15 +08:00
|
|
|
// and pointer-to-function expressions are represented as a declaration not
|
2010-03-11 22:07:00 +08:00
|
|
|
// an expression. We compensate for it here to produce the correct mangling.
|
|
|
|
NamedDecl *D = cast<NamedDecl>(A.getAsDecl());
|
|
|
|
const NonTypeTemplateParmDecl *Parameter = cast<NonTypeTemplateParmDecl>(P);
|
2011-04-24 16:43:07 +08:00
|
|
|
bool compensateMangling = !Parameter->getType()->isReferenceType();
|
2010-03-11 22:07:00 +08:00
|
|
|
if (compensateMangling) {
|
|
|
|
Out << 'X';
|
|
|
|
mangleOperatorName(OO_Amp, 1);
|
|
|
|
}
|
|
|
|
|
2009-11-21 17:17:15 +08:00
|
|
|
Out << 'L';
|
|
|
|
// References to external entities use the mangled name; if the name would
|
|
|
|
// not normally be manged then mangle it as unqualified.
|
|
|
|
//
|
|
|
|
// FIXME: The ABI specifies that external names here should have _Z, but
|
|
|
|
// gcc leaves this off.
|
2010-03-11 22:07:00 +08:00
|
|
|
if (compensateMangling)
|
|
|
|
mangle(D, "_Z");
|
|
|
|
else
|
|
|
|
mangle(D, "Z");
|
2009-05-16 00:09:15 +08:00
|
|
|
Out << 'E';
|
2010-03-11 22:07:00 +08:00
|
|
|
|
|
|
|
if (compensateMangling)
|
|
|
|
Out << 'E';
|
|
|
|
|
2009-05-16 00:09:15 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-01-04 06:36:02 +08:00
|
|
|
|
|
|
|
case TemplateArgument::Pack: {
|
|
|
|
// Note: proposal by Mike Herrick on 12/20/10
|
|
|
|
Out << 'J';
|
|
|
|
for (TemplateArgument::pack_iterator PA = A.pack_begin(),
|
|
|
|
PAEnd = A.pack_end();
|
|
|
|
PA != PAEnd; ++PA)
|
|
|
|
mangleTemplateArg(P, *PA);
|
|
|
|
Out << 'E';
|
|
|
|
}
|
2009-11-21 17:17:15 +08:00
|
|
|
}
|
2009-05-16 00:09:15 +08:00
|
|
|
}
|
|
|
|
|
2009-09-27 08:38:53 +08:00
|
|
|
void CXXNameMangler::mangleTemplateParameter(unsigned Index) {
|
|
|
|
// <template-param> ::= T_ # first template parameter
|
|
|
|
// ::= T <parameter-2 non-negative number> _
|
|
|
|
if (Index == 0)
|
|
|
|
Out << "T_";
|
|
|
|
else
|
|
|
|
Out << 'T' << (Index - 1) << '_';
|
|
|
|
}
|
|
|
|
|
2011-07-01 08:04:39 +08:00
|
|
|
void CXXNameMangler::mangleExistingSubstitution(QualType type) {
|
|
|
|
bool result = mangleSubstitution(type);
|
|
|
|
assert(result && "no existing substitution for type");
|
|
|
|
(void) result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CXXNameMangler::mangleExistingSubstitution(TemplateName tname) {
|
|
|
|
bool result = mangleSubstitution(tname);
|
|
|
|
assert(result && "no existing substitution for template name");
|
|
|
|
(void) result;
|
|
|
|
}
|
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
// <substitution> ::= S <seq-id> _
|
|
|
|
// ::= S_
|
2009-09-17 12:16:28 +08:00
|
|
|
bool CXXNameMangler::mangleSubstitution(const NamedDecl *ND) {
|
2009-09-27 04:53:44 +08:00
|
|
|
// Try one of the standard substitutions first.
|
|
|
|
if (mangleStandardSubstitution(ND))
|
|
|
|
return true;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-11-07 12:26:04 +08:00
|
|
|
ND = cast<NamedDecl>(ND->getCanonicalDecl());
|
2009-09-17 12:16:28 +08:00
|
|
|
return mangleSubstitution(reinterpret_cast<uintptr_t>(ND));
|
|
|
|
}
|
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
bool CXXNameMangler::mangleSubstitution(QualType T) {
|
2009-09-26 11:55:37 +08:00
|
|
|
if (!T.getCVRQualifiers()) {
|
|
|
|
if (const RecordType *RT = T->getAs<RecordType>())
|
|
|
|
return mangleSubstitution(RT->getDecl());
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
|
|
|
|
|
2009-09-17 11:53:28 +08:00
|
|
|
return mangleSubstitution(TypePtr);
|
|
|
|
}
|
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
bool CXXNameMangler::mangleSubstitution(TemplateName Template) {
|
|
|
|
if (TemplateDecl *TD = Template.getAsTemplateDecl())
|
|
|
|
return mangleSubstitution(TD);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
Template = Context.getASTContext().getCanonicalTemplateName(Template);
|
|
|
|
return mangleSubstitution(
|
|
|
|
reinterpret_cast<uintptr_t>(Template.getAsVoidPointer()));
|
|
|
|
}
|
|
|
|
|
2009-09-17 11:53:28 +08:00
|
|
|
bool CXXNameMangler::mangleSubstitution(uintptr_t Ptr) {
|
2010-04-11 00:03:31 +08:00
|
|
|
llvm::DenseMap<uintptr_t, unsigned>::iterator I = Substitutions.find(Ptr);
|
2009-09-17 08:43:46 +08:00
|
|
|
if (I == Substitutions.end())
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
unsigned SeqID = I->second;
|
|
|
|
if (SeqID == 0)
|
|
|
|
Out << "S_";
|
|
|
|
else {
|
|
|
|
SeqID--;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
// <seq-id> is encoded in base-36, using digits and upper case letters.
|
|
|
|
char Buffer[10];
|
2010-04-11 00:03:31 +08:00
|
|
|
char *BufferPtr = llvm::array_endof(Buffer);
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
if (SeqID == 0) *--BufferPtr = '0';
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
while (SeqID) {
|
|
|
|
assert(BufferPtr > Buffer && "Buffer overflow!");
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-06-09 15:26:17 +08:00
|
|
|
char c = static_cast<char>(SeqID % 36);
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
*--BufferPtr = (c < 10 ? '0' + c : 'A' + c - 10);
|
|
|
|
SeqID /= 36;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2010-04-11 00:03:31 +08:00
|
|
|
Out << 'S'
|
|
|
|
<< llvm::StringRef(BufferPtr, llvm::array_endof(Buffer)-BufferPtr)
|
|
|
|
<< '_';
|
2009-09-17 08:43:46 +08:00
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
static bool isCharType(QualType T) {
|
|
|
|
if (T.isNull())
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
return T->isSpecificBuiltinType(BuiltinType::Char_S) ||
|
|
|
|
T->isSpecificBuiltinType(BuiltinType::Char_U);
|
|
|
|
}
|
|
|
|
|
2009-11-21 17:05:47 +08:00
|
|
|
/// isCharSpecialization - Returns whether a given type is a template
|
2009-09-27 08:12:57 +08:00
|
|
|
/// specialization of a given name with a single argument of type char.
|
|
|
|
static bool isCharSpecialization(QualType T, const char *Name) {
|
|
|
|
if (T.isNull())
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
const RecordType *RT = T->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
|
|
|
const ClassTemplateSpecializationDecl *SD =
|
2009-09-27 08:12:57 +08:00
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl());
|
|
|
|
if (!SD)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!isStdNamespace(SD->getDeclContext()))
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
|
|
|
|
if (TemplateArgs.size() != 1)
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
if (!isCharType(TemplateArgs[0].getAsType()))
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-10-19 05:17:35 +08:00
|
|
|
return SD->getIdentifier()->getName() == Name;
|
2009-09-27 08:12:57 +08:00
|
|
|
}
|
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
template <std::size_t StrLen>
|
2010-11-26 02:29:30 +08:00
|
|
|
static bool isStreamCharSpecialization(const ClassTemplateSpecializationDecl*SD,
|
|
|
|
const char (&Str)[StrLen]) {
|
2009-12-08 03:56:42 +08:00
|
|
|
if (!SD->getIdentifier()->isStr(Str))
|
|
|
|
return false;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
|
|
|
|
if (TemplateArgs.size() != 2)
|
|
|
|
return false;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
if (!isCharType(TemplateArgs[0].getAsType()))
|
|
|
|
return false;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits"))
|
|
|
|
return false;
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
return true;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-09-27 04:53:44 +08:00
|
|
|
bool CXXNameMangler::mangleStandardSubstitution(const NamedDecl *ND) {
|
|
|
|
// <substitution> ::= St # ::std::
|
2009-09-27 07:10:05 +08:00
|
|
|
if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
|
2009-12-04 14:23:23 +08:00
|
|
|
if (isStd(NS)) {
|
2009-09-27 07:10:05 +08:00
|
|
|
Out << "St";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const ClassTemplateDecl *TD = dyn_cast<ClassTemplateDecl>(ND)) {
|
|
|
|
if (!isStdNamespace(TD->getDeclContext()))
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 07:10:05 +08:00
|
|
|
// <substitution> ::= Sa # ::std::allocator
|
|
|
|
if (TD->getIdentifier()->isStr("allocator")) {
|
|
|
|
Out << "Sa";
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 07:14:39 +08:00
|
|
|
// <<substitution> ::= Sb # ::std::basic_string
|
|
|
|
if (TD->getIdentifier()->isStr("basic_string")) {
|
|
|
|
Out << "Sb";
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-27 07:10:05 +08:00
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
|
|
|
if (const ClassTemplateSpecializationDecl *SD =
|
2009-09-27 08:12:57 +08:00
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
|
2010-02-24 02:25:09 +08:00
|
|
|
if (!isStdNamespace(SD->getDeclContext()))
|
|
|
|
return false;
|
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
// <substitution> ::= Ss # ::std::basic_string<char,
|
|
|
|
// ::std::char_traits<char>,
|
|
|
|
// ::std::allocator<char> >
|
|
|
|
if (SD->getIdentifier()->isStr("basic_string")) {
|
|
|
|
const TemplateArgumentList &TemplateArgs = SD->getTemplateArgs();
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
if (TemplateArgs.size() != 3)
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
if (!isCharType(TemplateArgs[0].getAsType()))
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
if (!isCharSpecialization(TemplateArgs[1].getAsType(), "char_traits"))
|
|
|
|
return false;
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-27 08:12:57 +08:00
|
|
|
if (!isCharSpecialization(TemplateArgs[2].getAsType(), "allocator"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Out << "Ss";
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
// <substitution> ::= Si # ::std::basic_istream<char,
|
2009-10-09 01:20:26 +08:00
|
|
|
// ::std::char_traits<char> >
|
2009-12-08 03:56:42 +08:00
|
|
|
if (isStreamCharSpecialization(SD, "basic_istream")) {
|
|
|
|
Out << "Si";
|
|
|
|
return true;
|
|
|
|
}
|
2009-10-09 01:20:26 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
// <substitution> ::= So # ::std::basic_ostream<char,
|
|
|
|
// ::std::char_traits<char> >
|
|
|
|
if (isStreamCharSpecialization(SD, "basic_ostream")) {
|
2009-10-09 01:20:26 +08:00
|
|
|
Out << "So";
|
|
|
|
return true;
|
|
|
|
}
|
2010-03-13 18:17:05 +08:00
|
|
|
|
2009-12-08 03:56:42 +08:00
|
|
|
// <substitution> ::= Sd # ::std::basic_iostream<char,
|
|
|
|
// ::std::char_traits<char> >
|
|
|
|
if (isStreamCharSpecialization(SD, "basic_iostream")) {
|
|
|
|
Out << "Sd";
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-27 08:12:57 +08:00
|
|
|
}
|
2009-09-27 07:10:05 +08:00
|
|
|
return false;
|
2009-09-27 04:53:44 +08:00
|
|
|
}
|
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
void CXXNameMangler::addSubstitution(QualType T) {
|
2009-09-26 11:55:37 +08:00
|
|
|
if (!T.getCVRQualifiers()) {
|
|
|
|
if (const RecordType *RT = T->getAs<RecordType>()) {
|
|
|
|
addSubstitution(RT->getDecl());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-11-21 17:05:47 +08:00
|
|
|
|
2009-09-17 08:43:46 +08:00
|
|
|
uintptr_t TypePtr = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
|
2009-09-17 11:53:28 +08:00
|
|
|
addSubstitution(TypePtr);
|
|
|
|
}
|
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
void CXXNameMangler::addSubstitution(TemplateName Template) {
|
|
|
|
if (TemplateDecl *TD = Template.getAsTemplateDecl())
|
|
|
|
return addSubstitution(TD);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-04-28 13:58:56 +08:00
|
|
|
Template = Context.getASTContext().getCanonicalTemplateName(Template);
|
|
|
|
addSubstitution(reinterpret_cast<uintptr_t>(Template.getAsVoidPointer()));
|
|
|
|
}
|
|
|
|
|
2009-09-17 11:53:28 +08:00
|
|
|
void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
|
|
|
|
assert(!Substitutions.count(Ptr) && "Substitution already exists!");
|
2010-06-02 12:29:50 +08:00
|
|
|
Substitutions[Ptr] = SeqID++;
|
2009-09-17 08:43:46 +08:00
|
|
|
}
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
//
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
/// \brief Mangles the name of the declaration D and emits that name to the
|
|
|
|
/// given output stream.
|
|
|
|
///
|
|
|
|
/// If the declaration D requires a mangled name, this routine will emit that
|
|
|
|
/// mangled name to \p os and return true. Otherwise, \p os will be unchanged
|
|
|
|
/// and this routine will return false. In this case, the caller should just
|
|
|
|
/// emit the identifier of the declaration (\c D->getIdentifier()) as its
|
|
|
|
/// name.
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleName(const NamedDecl *D,
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:14:44 +08:00
|
|
|
assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
|
|
|
|
"Invalid mangleName() call, argument is not a variable or function!");
|
|
|
|
assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
|
|
|
|
"Invalid mangleName() call on 'structor decl!");
|
2009-11-21 17:06:10 +08:00
|
|
|
|
|
|
|
PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
|
|
|
|
getASTContext().getSourceManager(),
|
|
|
|
"Mangling declaration");
|
|
|
|
|
2011-05-02 06:35:37 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out, D);
|
2009-11-21 17:06:22 +08:00
|
|
|
return Mangler.mangle(D);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type,
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out, D, Type);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.mangle(D);
|
|
|
|
}
|
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type,
|
2011-02-11 09:41:00 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out, D, Type);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.mangle(D);
|
|
|
|
}
|
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleThunk(const CXXMethodDecl *MD,
|
|
|
|
const ThunkInfo &Thunk,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2010-03-24 01:17:29 +08:00
|
|
|
// <special-name> ::= T <call-offset> <base encoding>
|
|
|
|
// # base is the nominal target function of thunk
|
|
|
|
// <special-name> ::= Tc <call-offset> <call-offset> <base encoding>
|
|
|
|
// # base is the nominal target function of thunk
|
|
|
|
// # first call-offset is 'this' adjustment
|
|
|
|
// # second call-offset is result adjustment
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-03-24 01:17:29 +08:00
|
|
|
assert(!isa<CXXDestructorDecl>(MD) &&
|
|
|
|
"Use mangleCXXDtor for destructor decls!");
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2010-03-24 01:17:29 +08:00
|
|
|
Mangler.getStream() << "_ZT";
|
|
|
|
if (!Thunk.Return.isEmpty())
|
|
|
|
Mangler.getStream() << 'c';
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-03-24 01:17:29 +08:00
|
|
|
// Mangle the 'this' pointer adjustment.
|
|
|
|
Mangler.mangleCallOffset(Thunk.This.NonVirtual, Thunk.This.VCallOffsetOffset);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-03-24 01:17:29 +08:00
|
|
|
// Mangle the return pointer adjustment if there is one.
|
|
|
|
if (!Thunk.Return.isEmpty())
|
|
|
|
Mangler.mangleCallOffset(Thunk.Return.NonVirtual,
|
|
|
|
Thunk.Return.VBaseOffsetOffset);
|
2010-05-05 23:23:54 +08:00
|
|
|
|
2010-03-24 01:17:29 +08:00
|
|
|
Mangler.mangleFunctionEncoding(MD);
|
|
|
|
}
|
|
|
|
|
2010-05-05 23:23:54 +08:00
|
|
|
void
|
2011-01-14 02:57:25 +08:00
|
|
|
ItaniumMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
|
|
|
|
CXXDtorType Type,
|
|
|
|
const ThisAdjustment &ThisAdjustment,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2010-03-24 01:17:29 +08:00
|
|
|
// <special-name> ::= T <call-offset> <base encoding>
|
|
|
|
// # base is the nominal target function of thunk
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out, DD, Type);
|
2010-03-24 01:17:29 +08:00
|
|
|
Mangler.getStream() << "_ZT";
|
|
|
|
|
|
|
|
// Mangle the 'this' pointer adjustment.
|
2010-05-05 23:23:54 +08:00
|
|
|
Mangler.mangleCallOffset(ThisAdjustment.NonVirtual,
|
2010-03-24 01:17:29 +08:00
|
|
|
ThisAdjustment.VCallOffsetOffset);
|
|
|
|
|
|
|
|
Mangler.mangleFunctionEncoding(DD);
|
|
|
|
}
|
|
|
|
|
2009-11-21 17:06:10 +08:00
|
|
|
/// mangleGuardVariable - Returns the mangled name for a guard variable
|
|
|
|
/// for the passed in VarDecl.
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleItaniumGuardVariable(const VarDecl *D,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= GV <object name> # Guard variable for one-time
|
|
|
|
// # initialization
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZGV";
|
|
|
|
Mangler.mangleName(D);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
2009-08-01 07:15:31 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleReferenceTemporary(const VarDecl *D,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2010-06-27 00:09:40 +08:00
|
|
|
// We match the GCC mangling here.
|
|
|
|
// <special-name> ::= GR <object name>
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2010-06-27 00:09:40 +08:00
|
|
|
Mangler.getStream() << "_ZGR";
|
|
|
|
Mangler.mangleName(D);
|
|
|
|
}
|
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= TV <type> # virtual table
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZTV";
|
2010-05-26 13:11:13 +08:00
|
|
|
Mangler.mangleNameOrStandardSubstitution(RD);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
2009-11-10 09:58:37 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= TT <type> # VTT structure
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZTT";
|
2010-05-26 13:11:13 +08:00
|
|
|
Mangler.mangleNameOrStandardSubstitution(RD);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
2009-11-10 09:41:59 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
|
|
|
|
int64_t Offset,
|
|
|
|
const CXXRecordDecl *Type,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= TC <type> <offset number> _ <base type>
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZTC";
|
2010-05-26 13:11:13 +08:00
|
|
|
Mangler.mangleNameOrStandardSubstitution(RD);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << Offset;
|
2010-04-11 00:03:31 +08:00
|
|
|
Mangler.getStream() << '_';
|
2010-05-26 13:11:13 +08:00
|
|
|
Mangler.mangleNameOrStandardSubstitution(Type);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
2009-11-14 08:14:13 +08:00
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXRTTI(QualType Ty,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= TI <type> # typeinfo structure
|
2009-12-24 06:04:40 +08:00
|
|
|
assert(!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers");
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZTI";
|
|
|
|
Mangler.mangleType(Ty);
|
2009-11-21 17:06:10 +08:00
|
|
|
}
|
|
|
|
|
2011-01-14 02:57:25 +08:00
|
|
|
void ItaniumMangleContext::mangleCXXRTTIName(QualType Ty,
|
2011-02-11 10:52:17 +08:00
|
|
|
llvm::raw_ostream &Out) {
|
2009-11-21 17:12:13 +08:00
|
|
|
// <special-name> ::= TS <type> # typeinfo name (null terminated byte string)
|
2011-02-11 07:59:36 +08:00
|
|
|
CXXNameMangler Mangler(*this, Out);
|
2009-11-21 17:12:13 +08:00
|
|
|
Mangler.getStream() << "_ZTS";
|
|
|
|
Mangler.mangleType(Ty);
|
2009-08-01 02:25:34 +08:00
|
|
|
}
|
2011-01-14 02:57:25 +08:00
|
|
|
|
|
|
|
MangleContext *clang::createItaniumMangleContext(ASTContext &Context,
|
|
|
|
Diagnostic &Diags) {
|
|
|
|
return new ItaniumMangleContext(Context, Diags);
|
|
|
|
}
|