[cfe-commits] r69150 - in /cfe/trunk/lib/CodeGen: Mangle.cpp Mangle.h
Anders Carlsson
andersca at mac.com
Tue Apr 14 22:36:59 PDT 2009
Author: andersca
Date: Wed Apr 15 00:36:58 2009
New Revision: 69150
URL: http://llvm.org/viewvc/llvm-project?rev=69150&view=rev
Log:
Add support for mangling C++ constructors. Review appreciated (I'm looking at you, Doug)
Modified:
cfe/trunk/lib/CodeGen/Mangle.cpp
cfe/trunk/lib/CodeGen/Mangle.h
Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=69150&r1=69149&r2=69150&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Wed Apr 15 00:36:58 2009
@@ -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();
+ }
}
Modified: cfe/trunk/lib/CodeGen/Mangle.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.h?rev=69150&r1=69149&r2=69150&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.h (original)
+++ cfe/trunk/lib/CodeGen/Mangle.h Wed Apr 15 00:36:58 2009
@@ -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 @@
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
More information about the cfe-commits
mailing list