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
diff --git a/lib/CodeGen/Mangle.cpp b/lib/CodeGen/Mangle.cpp
index 3d78b23..c8d9de2 100644
--- a/lib/CodeGen/Mangle.cpp
+++ b/lib/CodeGen/Mangle.cpp
@@ -29,13 +29,17 @@
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 @@
void mangleType(const TemplateTypeParmType *T);
void mangleType(const ObjCInterfaceType *T);
void mangleExpression(Expr *E);
+ void mangleCXXCtorType(CXXCtorType T);
};
}
@@ -125,6 +130,15 @@
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 @@
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 @@
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 @@
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 @@
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();
+ }
}