diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGCXX.cpp | 10 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGRtti.cpp | 12 | ||||
-rw-r--r-- | clang/lib/CodeGen/CGVtable.cpp | 6 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 2 | ||||
-rw-r--r-- | clang/lib/CodeGen/Mangle.cpp | 353 | ||||
-rw-r--r-- | clang/lib/CodeGen/Mangle.h | 90 |
6 files changed, 234 insertions, 239 deletions
diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 45a441eb158..30e8a3d5b83 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -152,7 +152,7 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D, llvm::SmallString<256> GuardVName; llvm::raw_svector_ostream GuardVOut(GuardVName); - mangleGuardVariable(CGM.getMangleContext(), &D, GuardVOut); + CGM.getMangleContext().mangleGuardVariable(&D, GuardVOut); // Create the guard variable. llvm::GlobalValue *GuardV = @@ -756,7 +756,7 @@ const char *CodeGenModule::getMangledCXXCtorName(const CXXConstructorDecl *D, CXXCtorType Type) { llvm::SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - mangleCXXCtor(getMangleContext(), D, Type, Out); + getMangleContext().mangleCXXCtor(D, Type, Out); Name += '\0'; return UniqueMangledName(Name.begin(), Name.end()); @@ -794,7 +794,7 @@ const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D, CXXDtorType Type) { llvm::SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - mangleCXXDtor(getMangleContext(), D, Type, Out); + getMangleContext().mangleCXXDtor(D, Type, Out); Name += '\0'; return UniqueMangledName(Name.begin(), Name.end()); @@ -946,7 +946,7 @@ llvm::Constant *CodeGenModule::BuildThunk(const CXXMethodDecl *MD, bool Extern, int64_t nv, int64_t v) { llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleThunk(getMangleContext(), MD, nv, v, Out); + getMangleContext().mangleThunk(MD, nv, v, Out); llvm::GlobalVariable::LinkageTypes linktype; linktype = llvm::GlobalValue::WeakAnyLinkage; if (!Extern) @@ -970,7 +970,7 @@ llvm::Constant *CodeGenModule::BuildCovariantThunk(const CXXMethodDecl *MD, int64_t v_r) { llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCovariantThunk(getMangleContext(), MD, nv_t, v_t, nv_r, v_r, Out); + getMangleContext().mangleCovariantThunk(MD, nv_t, v_t, nv_r, v_r, Out); llvm::GlobalVariable::LinkageTypes linktype; linktype = llvm::GlobalValue::WeakAnyLinkage; if (!Extern) diff --git a/clang/lib/CodeGen/CGRtti.cpp b/clang/lib/CodeGen/CGRtti.cpp index 38a17b3c396..7d08c941b27 100644 --- a/clang/lib/CodeGen/CGRtti.cpp +++ b/clang/lib/CodeGen/CGRtti.cpp @@ -50,7 +50,7 @@ public: llvm::Constant *BuildName(QualType Ty, bool Hidden, bool Extern) { llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXRttiName(CGM.getMangleContext(), Ty, Out); + CGM.getMangleContext().mangleCXXRttiName(Ty, Out); llvm::StringRef Name = Out.str(); llvm::GlobalVariable::LinkageTypes linktype; @@ -100,7 +100,7 @@ public: llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXRtti(CGM.getMangleContext(), Ty, Out); + CGM.getMangleContext().mangleCXXRtti(Ty, Out); llvm::StringRef Name = Out.str(); C = CGM.getModule().getGlobalVariable(Name); @@ -195,8 +195,8 @@ public: llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXRtti(CGM.getMangleContext(), CGM.getContext().getTagDeclType(RD), - Out); + CGM.getMangleContext().mangleCXXRtti(CGM.getContext().getTagDeclType(RD), + Out); llvm::StringRef Name = Out.str(); llvm::GlobalVariable *GV; @@ -291,7 +291,7 @@ public: llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXRtti(CGM.getMangleContext(), Ty, Out); + CGM.getMangleContext().mangleCXXRtti(Ty, Out); llvm::StringRef Name = Out.str(); llvm::GlobalVariable *GV; @@ -345,7 +345,7 @@ public: llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXRtti(CGM.getMangleContext(), Ty, Out); + CGM.getMangleContext().mangleCXXRtti(Ty, Out); llvm::StringRef Name = Out.str(); llvm::GlobalVariable *GV; diff --git a/clang/lib/CodeGen/CGVtable.cpp b/clang/lib/CodeGen/CGVtable.cpp index 40448f8fd5e..d99a426aeee 100644 --- a/clang/lib/CodeGen/CGVtable.cpp +++ b/clang/lib/CodeGen/CGVtable.cpp @@ -793,9 +793,9 @@ llvm::Constant *CodeGenModule::GenerateVtable(const CXXRecordDecl *LayoutClass, llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); if (LayoutClass != RD) - mangleCXXCtorVtable(getMangleContext(), LayoutClass, Offset/8, RD, Out); + getMangleContext().mangleCXXCtorVtable(LayoutClass, Offset/8, RD, Out); else - mangleCXXVtable(getMangleContext(), RD, Out); + getMangleContext().mangleCXXVtable(RD, Out); llvm::StringRef Name = Out.str(); std::vector<llvm::Constant *> methods; @@ -1043,7 +1043,7 @@ llvm::Constant *CodeGenModule::GenerateVTT(const CXXRecordDecl *RD) { llvm::SmallString<256> OutName; llvm::raw_svector_ostream Out(OutName); - mangleCXXVTT(getMangleContext(), RD, Out); + getMangleContext().mangleCXXVTT(RD, Out); llvm::StringRef Name = Out.str(); llvm::GlobalVariable::LinkageTypes linktype; diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index b8027d8314d..4a30eedeff8 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -168,7 +168,7 @@ const char *CodeGenModule::getMangledName(const NamedDecl *ND) { llvm::SmallString<256> Name; llvm::raw_svector_ostream Out(Name); - if (!mangleName(getMangleContext(), ND, Out)) { + if (!getMangleContext().mangleName(ND, Out)) { assert(ND->getIdentifier() && "Attempt to mangle unnamed decl."); return ND->getNameAsCString(); } diff --git a/clang/lib/CodeGen/Mangle.cpp b/clang/lib/CodeGen/Mangle.cpp index ca0ef14dbbb..bfd33bbfdf1 100644 --- a/clang/lib/CodeGen/Mangle.cpp +++ b/clang/lib/CodeGen/Mangle.cpp @@ -29,94 +29,95 @@ using namespace clang; namespace { - class VISIBILITY_HIDDEN CXXNameMangler { - MangleContext &Context; - llvm::raw_ostream &Out; +/// CXXNameMangler - Manage the mangling of a single name. +class VISIBILITY_HIDDEN CXXNameMangler { + MangleContext &Context; + llvm::raw_ostream &Out; - const CXXMethodDecl *Structor; - unsigned StructorType; - CXXCtorType CtorType; + const CXXMethodDecl *Structor; + unsigned StructorType; + CXXCtorType CtorType; - llvm::DenseMap<uintptr_t, unsigned> Substitutions; + llvm::DenseMap<uintptr_t, unsigned> Substitutions; public: - CXXNameMangler(MangleContext &C, llvm::raw_ostream &os) - : Context(C), Out(os), Structor(0), StructorType(0) { } - - bool mangle(const NamedDecl *D); - void mangleCalloffset(int64_t nv, int64_t v); - void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v); - void mangleCovariantThunk(const FunctionDecl *FD, - int64_t nv_t, int64_t v_t, - int64_t nv_r, int64_t v_r); - void mangleGuardVariable(const VarDecl *D); - - void mangleCXXVtable(const CXXRecordDecl *RD); - void mangleCXXVTT(const CXXRecordDecl *RD); - void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset, - const CXXRecordDecl *Type); - void mangleCXXRtti(QualType Ty); - void mangleCXXRttiName(QualType Ty); - void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type); - void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type); + CXXNameMangler(MangleContext &C, llvm::raw_ostream &os) + : Context(C), Out(os), Structor(0), StructorType(0) { } - private: - bool mangleSubstitution(const NamedDecl *ND); - bool mangleSubstitution(QualType T); - bool mangleSubstitution(uintptr_t Ptr); + bool mangle(const NamedDecl *D); + void mangleCalloffset(int64_t nv, int64_t v); + void mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v); + void mangleCovariantThunk(const FunctionDecl *FD, + int64_t nv_t, int64_t v_t, + int64_t nv_r, int64_t v_r); + void mangleGuardVariable(const VarDecl *D); + + void mangleCXXVtable(const CXXRecordDecl *RD); + void mangleCXXVTT(const CXXRecordDecl *RD); + void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset, + const CXXRecordDecl *Type); + void mangleCXXRtti(QualType Ty); + void mangleCXXRttiName(QualType Ty); + void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type); + void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type); - bool mangleStandardSubstitution(const NamedDecl *ND); + private: + bool mangleSubstitution(const NamedDecl *ND); + bool mangleSubstitution(QualType T); + bool mangleSubstitution(uintptr_t Ptr); - void addSubstitution(const NamedDecl *ND) { - ND = cast<NamedDecl>(ND->getCanonicalDecl()); + bool mangleStandardSubstitution(const NamedDecl *ND); - addSubstitution(reinterpret_cast<uintptr_t>(ND)); - } - void addSubstitution(QualType T); - void addSubstitution(uintptr_t Ptr); - - bool mangleFunctionDecl(const FunctionDecl *FD); - - void mangleFunctionEncoding(const FunctionDecl *FD); - void mangleName(const NamedDecl *ND); - void mangleName(const TemplateDecl *TD, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void mangleUnqualifiedName(const NamedDecl *ND); - void mangleUnscopedName(const NamedDecl *ND); - void mangleUnscopedTemplateName(const TemplateDecl *ND); - void mangleSourceName(const IdentifierInfo *II); - void mangleLocalName(const NamedDecl *ND); - void mangleNestedName(const NamedDecl *ND); - void mangleNestedName(const TemplateDecl *TD, - const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void manglePrefix(const DeclContext *DC); - void mangleTemplatePrefix(const TemplateDecl *ND); - void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); - void mangleQualifiers(Qualifiers Quals); - void mangleType(QualType T); + void addSubstitution(const NamedDecl *ND) { + ND = cast<NamedDecl>(ND->getCanonicalDecl()); - // Declare manglers for every type class. + addSubstitution(reinterpret_cast<uintptr_t>(ND)); + } + void addSubstitution(QualType T); + void addSubstitution(uintptr_t Ptr); + + bool mangleFunctionDecl(const FunctionDecl *FD); + + void mangleFunctionEncoding(const FunctionDecl *FD); + void mangleName(const NamedDecl *ND); + void mangleName(const TemplateDecl *TD, + const TemplateArgument *TemplateArgs, + unsigned NumTemplateArgs); + void mangleUnqualifiedName(const NamedDecl *ND); + void mangleUnscopedName(const NamedDecl *ND); + void mangleUnscopedTemplateName(const TemplateDecl *ND); + void mangleSourceName(const IdentifierInfo *II); + void mangleLocalName(const NamedDecl *ND); + void mangleNestedName(const NamedDecl *ND); + void mangleNestedName(const TemplateDecl *TD, + const TemplateArgument *TemplateArgs, + unsigned NumTemplateArgs); + void manglePrefix(const DeclContext *DC); + void mangleTemplatePrefix(const TemplateDecl *ND); + void mangleOperatorName(OverloadedOperatorKind OO, unsigned Arity); + void mangleQualifiers(Qualifiers Quals); + void mangleType(QualType T); + + // Declare manglers for every type class. #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" - void mangleType(const TagType*); - void mangleBareFunctionType(const FunctionType *T, - bool MangleReturnType); - void mangleExpression(const Expr *E); - void mangleCXXCtorType(CXXCtorType T); - void mangleCXXDtorType(CXXDtorType T); + void mangleType(const TagType*); + void mangleBareFunctionType(const FunctionType *T, + bool MangleReturnType); + void mangleExpression(const Expr *E); + void mangleCXXCtorType(CXXCtorType T); + void mangleCXXDtorType(CXXDtorType T); - void mangleTemplateArgs(const TemplateArgument *TemplateArgs, - unsigned NumTemplateArgs); - void mangleTemplateArgumentList(const TemplateArgumentList &L); - void mangleTemplateArgument(const TemplateArgument &A); + void mangleTemplateArgs(const TemplateArgument *TemplateArgs, + unsigned NumTemplateArgs); + void mangleTemplateArgumentList(const TemplateArgumentList &L); + void mangleTemplateArgument(const TemplateArgument &A); - void mangleTemplateParameter(unsigned Index); - }; + void mangleTemplateParameter(unsigned Index); +}; } static bool isInCLinkageSpecification(const Decl *D) { @@ -425,9 +426,9 @@ void CXXNameMangler::mangleThunk(const FunctionDecl *FD, int64_t nv, mangleFunctionEncoding(FD); } - void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD, - int64_t nv_t, int64_t v_t, - int64_t nv_r, int64_t v_r) { +void CXXNameMangler::mangleCovariantThunk(const FunctionDecl *FD, + int64_t nv_t, int64_t v_t, + int64_t nv_r, int64_t v_r) { // <special-name> ::= Tc <call-offset> <call-offset> <base encoding> // # base is the nominal target function of thunk // # first call-offset is 'this' adjustment @@ -1376,126 +1377,122 @@ void CXXNameMangler::addSubstitution(uintptr_t Ptr) { Substitutions[Ptr] = SeqID; } -namespace clang { - /// \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. - bool mangleName(MangleContext &Context, const NamedDecl *D, - llvm::raw_ostream &os) { - assert(!isa<CXXConstructorDecl>(D) && - "Use mangleCXXCtor for constructor decls!"); - assert(!isa<CXXDestructorDecl>(D) && - "Use mangleCXXDtor for destructor decls!"); - - PrettyStackTraceDecl CrashInfo(const_cast<NamedDecl *>(D), SourceLocation(), - Context.getASTContext().getSourceManager(), - "Mangling declaration"); - - CXXNameMangler Mangler(Context, os); - if (!Mangler.mangle(D)) - return false; +// - os.flush(); - return true; - } +/// \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. +bool MangleContext::mangleName(const NamedDecl *D, llvm::raw_ostream &os) { + assert(!isa<CXXConstructorDecl>(D) && + "Use mangleCXXCtor for constructor decls!"); + assert(!isa<CXXDestructorDecl>(D) && + "Use mangleCXXDtor for destructor decls!"); + + PrettyStackTraceDecl CrashInfo(D, SourceLocation(), + getASTContext().getSourceManager(), + "Mangling declaration"); + + CXXNameMangler Mangler(*this, os); + if (!Mangler.mangle(D)) + return false; - /// \brief Mangles the a thunk with the offset n for the declaration D and - /// emits that name to the given output stream. - void mangleThunk(MangleContext &Context, const FunctionDecl *FD, - int64_t nv, int64_t v, llvm::raw_ostream &os) { - // FIXME: Hum, we might have to thunk these, fix. - assert(!isa<CXXDestructorDecl>(FD) && - "Use mangleCXXDtor for destructor decls!"); - - CXXNameMangler Mangler(Context, os); - Mangler.mangleThunk(FD, nv, v); - os.flush(); - } + os.flush(); + return true; +} - /// \brief Mangles the a covariant thunk for the declaration D and emits that - /// name to the given output stream. - void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD, - int64_t nv_t, int64_t v_t, - int64_t nv_r, int64_t v_r, - llvm::raw_ostream &os) { - // FIXME: Hum, we might have to thunk these, fix. - assert(!isa<CXXDestructorDecl>(FD) && - "Use mangleCXXDtor for destructor decls!"); - - CXXNameMangler Mangler(Context, os); - Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r); - os.flush(); - } +/// \brief Mangles the a thunk with the offset n for the declaration D and +/// emits that name to the given output stream. +void MangleContext::mangleThunk(const FunctionDecl *FD, int64_t nv, int64_t v, + llvm::raw_ostream &os) { + // FIXME: Hum, we might have to thunk these, fix. + assert(!isa<CXXDestructorDecl>(FD) && + "Use mangleCXXDtor for destructor decls!"); - /// mangleGuardVariable - Returns the mangled name for a guard variable - /// for the passed in VarDecl. - void mangleGuardVariable(MangleContext &Context, const VarDecl *D, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleGuardVariable(D); + CXXNameMangler Mangler(*this, os); + Mangler.mangleThunk(FD, nv, v); + os.flush(); +} - os.flush(); - } +/// \brief Mangles the a covariant thunk for the declaration D and emits that +/// name to the given output stream. +void MangleContext::mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, + int64_t v_t, int64_t nv_r, int64_t v_r, + llvm::raw_ostream &os) { + // FIXME: Hum, we might have to thunk these, fix. + assert(!isa<CXXDestructorDecl>(FD) && + "Use mangleCXXDtor for destructor decls!"); - void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D, - CXXCtorType Type, llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXCtor(D, Type); + CXXNameMangler Mangler(*this, os); + Mangler.mangleCovariantThunk(FD, nv_t, v_t, nv_r, v_r); + os.flush(); +} - os.flush(); - } +/// mangleGuardVariable - Returns the mangled name for a guard variable +/// for the passed in VarDecl. +void MangleContext::mangleGuardVariable(const VarDecl *D, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleGuardVariable(D); - void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D, - CXXDtorType Type, llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXDtor(D, Type); + os.flush(); +} - os.flush(); - } +void MangleContext::mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXCtor(D, Type); - void mangleCXXVtable(MangleContext &Context, const CXXRecordDecl *RD, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXVtable(RD); + os.flush(); +} - os.flush(); - } +void MangleContext::mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXDtor(D, Type); + + os.flush(); +} - void mangleCXXVTT(MangleContext &Context, const CXXRecordDecl *RD, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXVTT(RD); +void MangleContext::mangleCXXVtable(const CXXRecordDecl *RD, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXVtable(RD); - os.flush(); - } + os.flush(); +} - void mangleCXXCtorVtable(MangleContext &Context, const CXXRecordDecl *RD, - int64_t Offset, const CXXRecordDecl *Type, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXCtorVtable(RD, Offset, Type); +void MangleContext::mangleCXXVTT(const CXXRecordDecl *RD, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXVTT(RD); - os.flush(); - } + os.flush(); +} - void mangleCXXRtti(MangleContext &Context, QualType Ty, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXRtti(Ty); +void MangleContext::mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset, + const CXXRecordDecl *Type, + llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXCtorVtable(RD, Offset, Type); - os.flush(); - } + os.flush(); +} - void mangleCXXRttiName(MangleContext &Context, QualType Ty, - llvm::raw_ostream &os) { - CXXNameMangler Mangler(Context, os); - Mangler.mangleCXXRttiName(Ty); +void MangleContext::mangleCXXRtti(QualType Ty, llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXRtti(Ty); - os.flush(); - } + os.flush(); +} + +void MangleContext::mangleCXXRttiName(QualType Ty, llvm::raw_ostream &os) { + CXXNameMangler Mangler(*this, os); + Mangler.mangleCXXRttiName(Ty); + + os.flush(); } diff --git a/clang/lib/CodeGen/Mangle.h b/clang/lib/CodeGen/Mangle.h index 458708fca6a..8268aa2869d 100644 --- a/clang/lib/CodeGen/Mangle.h +++ b/clang/lib/CodeGen/Mangle.h @@ -23,61 +23,59 @@ #include "llvm/ADT/DenseMap.h" namespace llvm { - class raw_ostream; +class raw_ostream; } namespace clang { - class ASTContext; - class CXXConstructorDecl; - class CXXDestructorDecl; - class FunctionDecl; - class NamedDecl; - class VarDecl; +class ASTContext; +class CXXConstructorDecl; +class CXXDestructorDecl; +class FunctionDecl; +class NamedDecl; +class VarDecl; - class MangleContext { - ASTContext &Context; - - llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds; +/// MangleContext - Context for tracking state which persists across multiple +/// calls to the C++ name mangler. +class MangleContext { + ASTContext &Context; - public: - explicit MangleContext(ASTContext &Context) + llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds; + +public: + explicit MangleContext(ASTContext &Context) : Context(Context) { } - - ASTContext &getASTContext() const { return Context; } - - uint64_t getAnonymousStructId(const TagDecl *TD) { - std::pair<llvm::DenseMap<const TagDecl *, - uint64_t>::iterator, bool> Result = + + ASTContext &getASTContext() const { return Context; } + + 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; - } - }; + return Result.first->second; + } - bool mangleName(MangleContext &Context, const NamedDecl *D, - llvm::raw_ostream &os); - void mangleThunk(MangleContext &Context, const FunctionDecl *FD, - int64_t n, int64_t vn, llvm::raw_ostream &os); - void mangleCovariantThunk(MangleContext &Context, const FunctionDecl *FD, - int64_t nv_t, int64_t v_t, - int64_t nv_r, int64_t v_r, - llvm::raw_ostream &os); - void mangleGuardVariable(MangleContext &Context, const VarDecl *D, - llvm::raw_ostream &os); - void mangleCXXVtable(MangleContext &Context, const CXXRecordDecl *RD, - llvm::raw_ostream &os); - void mangleCXXVTT(MangleContext &Context, const CXXRecordDecl *RD, - llvm::raw_ostream &os); - void mangleCXXCtorVtable(MangleContext &Context, const CXXRecordDecl *RD, - int64_t Offset, const CXXRecordDecl *Type, - llvm::raw_ostream &os); - void mangleCXXRtti(MangleContext &Context, QualType T, + /// @name Mangler Entry Points + /// @{ + + bool mangleName(const NamedDecl *D, llvm::raw_ostream &os); + void mangleThunk(const FunctionDecl *FD, int64_t n, int64_t vn, + llvm::raw_ostream &os); + void mangleCovariantThunk(const FunctionDecl *FD, int64_t nv_t, int64_t v_t, + int64_t nv_r, int64_t v_r, llvm::raw_ostream &os); + void mangleGuardVariable(const VarDecl *D, llvm::raw_ostream &os); + void mangleCXXVtable(const CXXRecordDecl *RD, llvm::raw_ostream &os); + void mangleCXXVTT(const CXXRecordDecl *RD, llvm::raw_ostream &os); + void mangleCXXCtorVtable(const CXXRecordDecl *RD, int64_t Offset, + const CXXRecordDecl *Type, llvm::raw_ostream &os); + void mangleCXXRtti(QualType T, llvm::raw_ostream &os); + void mangleCXXRttiName(QualType T, llvm::raw_ostream &os); + void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type, + llvm::raw_ostream &os); + void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type, llvm::raw_ostream &os); - void mangleCXXRttiName(MangleContext &Context, QualType T, - llvm::raw_ostream &os); - void mangleCXXCtor(MangleContext &Context, const CXXConstructorDecl *D, - CXXCtorType Type, llvm::raw_ostream &os); - void mangleCXXDtor(MangleContext &Context, const CXXDestructorDecl *D, - CXXDtorType Type, llvm::raw_ostream &os); + + /// @} +}; } #endif |