зеркало из https://github.com/microsoft/clang-1.git
Add support for mangling C++ constructors. Review appreciated (I'm looking at you, Doug)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69150 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
839324d564
Коммит
3ac86b59b0
|
@ -29,13 +29,17 @@ namespace {
|
|||
ASTContext &Context;
|
||||
llvm::raw_ostream &Out;
|
||||
|
||||
const CXXConstructorDecl *Ctor;
|
||||
CXXCtorType CtorType;
|
||||
|
||||
public:
|
||||
CXXNameMangler(ASTContext &C, llvm::raw_ostream &os)
|
||||
: Context(C), Out(os) { }
|
||||
: Context(C), Out(os), Ctor(0), CtorType(Ctor_Complete) { }
|
||||
|
||||
bool mangle(const NamedDecl *D);
|
||||
void mangleGuardVariable(const VarDecl *D);
|
||||
|
||||
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type);
|
||||
|
||||
private:
|
||||
bool mangleFunctionDecl(const FunctionDecl *FD);
|
||||
|
||||
|
@ -58,6 +62,7 @@ namespace {
|
|||
void mangleType(const TemplateTypeParmType *T);
|
||||
void mangleType(const ObjCInterfaceType *T);
|
||||
void mangleExpression(Expr *E);
|
||||
void mangleCXXCtorType(CXXCtorType T);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -125,6 +130,15 @@ bool CXXNameMangler::mangle(const NamedDecl *D) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void CXXNameMangler::mangleCXXCtor(const CXXConstructorDecl *D,
|
||||
CXXCtorType Type) {
|
||||
assert(!Ctor && "Ctor already set!");
|
||||
Ctor = D;
|
||||
CtorType = Type;
|
||||
|
||||
mangle(D);
|
||||
}
|
||||
|
||||
void CXXNameMangler::mangleGuardVariable(const VarDecl *D)
|
||||
{
|
||||
// <special-name> ::= GV <object name> # Guard variable for one-time
|
||||
|
@ -184,13 +198,14 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND) {
|
|||
break;
|
||||
|
||||
case DeclarationName::CXXConstructorName:
|
||||
// <ctor-dtor-name> ::= C1 # complete object constructor
|
||||
// ::= C2 # base object constructor
|
||||
// ::= C3 # complete object allocating constructor
|
||||
//
|
||||
// FIXME: We don't even have all of these constructors
|
||||
// in the AST yet.
|
||||
Out << "C1";
|
||||
if (ND == Ctor)
|
||||
// If the named decl is the C++ constructor we're mangling, use the
|
||||
// type we were given.
|
||||
mangleCXXCtorType(CtorType);
|
||||
else
|
||||
// Otherwise, use the complete constructor name. This is relevant if a
|
||||
// class with a constructor is declared within a constructor.
|
||||
mangleCXXCtorType(Ctor_Complete);
|
||||
break;
|
||||
|
||||
case DeclarationName::CXXDestructorName:
|
||||
|
@ -578,6 +593,24 @@ void CXXNameMangler::mangleExpression(Expr *E) {
|
|||
assert(false && "Cannot mangle expressions yet");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
namespace clang {
|
||||
/// \brief Mangles the name of the declaration D and emits that name
|
||||
/// to the given output stream.
|
||||
|
@ -597,7 +630,8 @@ namespace clang {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// mangleGuardVariable - Mangles the m
|
||||
/// mangleGuardVariable - Returns the mangled name for a guard variable
|
||||
/// for the passed in VarDecl.
|
||||
void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
|
||||
llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(Context, os);
|
||||
|
@ -605,5 +639,13 @@ namespace clang {
|
|||
|
||||
os.flush();
|
||||
}
|
||||
|
||||
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
||||
ASTContext &Context, llvm::raw_ostream &os) {
|
||||
CXXNameMangler Mangler(Context, os);
|
||||
Mangler.mangleCXXCtor(D, Type);
|
||||
|
||||
os.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,12 +18,15 @@
|
|||
#ifndef LLVM_CLANG_CODEGEN_MANGLE_H
|
||||
#define LLVM_CLANG_CODEGEN_MANGLE_H
|
||||
|
||||
#include "CGCXX.h"
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
}
|
||||
|
||||
namespace clang {
|
||||
class ASTContext;
|
||||
class CXXConstructorDecl;
|
||||
class NamedDecl;
|
||||
class VarDecl;
|
||||
|
||||
|
@ -31,6 +34,8 @@ namespace clang {
|
|||
llvm::raw_ostream &os);
|
||||
void mangleGuardVariable(const VarDecl *D, ASTContext &Context,
|
||||
llvm::raw_ostream &os);
|
||||
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
||||
ASTContext &Context, llvm::raw_ostream &os);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче