[Issue 4620] New: C++ constructor and template mangling, C++ ABI patch
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 11 05:10:49 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4620
Summary: C++ constructor and template mangling, C++ ABI patch
Product: D
Version: D1 & D2
Platform: Other
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: matthias.fauconneau at gmail.com
--- Comment #0 from Matthias Fauconneau <matthias.fauconneau at gmail.com> 2010-08-11 05:10:46 PDT ---
Created an attachment (id=712)
Demo: using Qt through native C++ interface (without compiled bindings)
--- a/cppmangle.c 2010-08-11 13:28:34.000000000 +0200
+++ b/cppmangle.c 2010-08-11 13:28:34.000000000 +0200
@@ -106,14 +106,36 @@
Dsymbol *p = s->toParent();
if (p && !p->isModule())
{
+ TemplateInstance *ti = p->isTemplateInstance();
+ if(ti)
+ {
+ char *name = ti->name->toChars();
+ buf->printf("%d%s", strlen(name), name);
+ buf->writeByte('I');
+ for (size_t j = 0; j < ti->tiargs->dim; j++)
+ {
+ Object *o = (Object *)ti->tiargs->data[j];
+ Type *t = isType(o);
+ if (t) t->toCppMangle(buf, cms);
+ }
+ buf->writeByte('E');
+ return;
+ }
+
buf->writeByte('N');
FuncDeclaration *fd = s->isFuncDeclaration();
- if (fd->isConst())
+ if (fd && fd->isConst())
buf->writeByte('K');
prefix_name(buf, cms, p);
- source_name(buf, s);
+ cms->components.push(s);
+ if (!strcmp(s->ident->toChars(), "__ctor")) {
+ buf->writeByte('C');
+ buf->writeByte('1');
+ } else {
+ source_name(buf, s);
+ }
buf->writeByte('E');
}
@@ -197,10 +219,11 @@
* z ellipsis
* u <source-name> # vendor extended type
*/
-
- if (isConst())
+ if (isConst()) {
+ if (cms->substitute(buf, this))
+ return;
buf->writeByte('K');
-
+ }
switch (ty)
{
case Tvoid: c = 'v'; break;
@@ -320,6 +343,11 @@
void TypeStruct::toCppMangle(OutBuffer *buf, CppMangleState *cms)
{
+ if (isConst())
+ {
+ if ( !cms->substitute(buf, this) )
+ buf->writeByte('K');
+ }
if (!cms->substitute(buf, sym))
cpp_mangle_name(buf, cms, sym);
}
--- a/expression.c 2010-08-11 13:16:54.000000000 +0200
+++ b/expression.c 2010-08-11 13:16:54.000000000 +0200
@@ -6741,6 +6741,10 @@
e = new DotTemplateExp(loc, av, td);
}
e = new CallExp(loc, e, arguments);
+ if (cf && cf->linkage != LINKd)
+ { //C++ constructor return void
+ e = new CommaExp(loc, e, new VarExp(loc, tmp));
+ }
#if !STRUCTTHISREF
/* Constructors return a pointer to the instance
*/
--- a/e2ir.c 2010-08-11 11:51:32.000000000 +0200
+++ b/e2ir.c 2010-08-11 11:51:32.000000000 +0200
@@ -137,7 +137,7 @@
{
Parameter *p = Parameter::getNth(tf->parameters, i - j);
- if (p->storageClass & (STCout | STCref))
+ if (p->storageClass & (STCout | STCref) || (p->type->ty ==
Tstruct && tf->linkage != LINKd))
{
// Convert argument to a pointer,
// use AddrExp::toElem()
@@ -1733,11 +1733,18 @@
if (member)
{ // Call constructor
ez = callfunc(loc, irs, 1, type, ez, ectype, member, member->type,
NULL, arguments);
+ TypeFunction* tf = (TypeFunction *)(member->type);
+ if (tf->linkage != LINKd)
+ { //C++ constructor return void
+ ez = el_combine(ez, el_same(&ex));
+ }
#if STRUCTTHISREF
- /* Structs return a ref, which gets automatically dereferenced.
- * But we want a pointer to the instance.
- */
- ez = el_una(OPaddr, TYnptr, ez);
+ else {
+ /* Structs return a ref, which gets automatically
dereferenced.
+ * But we want a pointer to the instance.
+ */
+ ez = el_una(OPaddr, TYnptr, ez);
+ }
#endif
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list