diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-21 09:06:10 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-21 09:06:10 +0000 |
commit | 1b0771170921b9e752a50ea2cf87814bff92c834 (patch) | |
tree | a01fd6ceaac4b355942ebc66155230699e62ff09 /lib/CodeGen/Mangle.cpp | |
parent | c52365674b5b157a0486f75c12dd9f4cc41d8089 (diff) |
Sink free mangle* methods into MangleContext.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@89547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/Mangle.cpp')
-rw-r--r-- | lib/CodeGen/Mangle.cpp | 353 |
1 files changed, 175 insertions, 178 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp index ca0ef14dbb..bfd33bbfdf 100644 --- a/lib/CodeGen/Mangle.cpp +++ b/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(); } |