aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-04-15 05:36:58 +0000
committerAnders Carlsson <andersca@mac.com>2009-04-15 05:36:58 +0000
commit3ac86b59b03086ce2acc1ddf3b30ffcd18aeeb65 (patch)
tree055fada88061cf1cf5e0442465e8b503c5e385fc /lib/CodeGen
parent839324d564c7263402fb49e73c307817a0e5992c (diff)
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/Mangle.cpp62
-rw-r--r--lib/CodeGen/Mangle.h5
2 files changed, 57 insertions, 10 deletions
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 3d78b23810..c8d9de2d33 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -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();
+ }
}
diff --git a/lib/CodeGen/Mangle.h b/lib/CodeGen/Mangle.h
index b3f88b0d68..a8ca09d1cf 100644
--- a/lib/CodeGen/Mangle.h
+++ b/lib/CodeGen/Mangle.h
@@ -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