www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4620] New: C++ constructor and template mangling, C++ ABI patch

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: matthias.fauconneau 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

      */
-
-    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: -------
Aug 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4620




2010-08-11 05:15:03 PDT ---
Created an attachment (id=713)
Patch against r615

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4620


Adam D. Ruppe <destructionator gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |destructionator gmail.com



10:15:03 PST ---
I'd really like to see something happen with this. Even if it doesn't work for
everything, calling more C++ is only a good thing for D.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 11 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4620


Igor Stepanov <wazar.leollone yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wazar.leollone yahoo.com



08:24:08 PDT ---
PING. This issue is interested for me? Can this feature be merged or this issue
is invalid?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 19 2013