www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2774] New: Functions-as-properties makes it impossible to get the .mangleof a function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774

           Summary: Functions-as-properties makes it impossible to get the
                    .mangleof a function
           Product: D
           Version: 1.041
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jarrett.billingsley gmail.com


class A{}
pragma(msg, A.mangleof); // prints "C5dtest1A" as expected

void foo() {}

pragma(msg, foo.mangleof); // prints "v" since typeof(foo) is the same as
typeof(foo())
pragma(msg, (&foo).mangleof); // prints PFZv, symbol info lost

template T(alias f)
{
        pragma(msg, f.mangleof); // prints "v"
        const T = "dummy";
}

pragma(msg, T!(foo));


It'd be really nice to get the mangle of functions.  It'd make it possible to
determine whether a function is static or not, as well as the ref-ness of its
params.  But DMD currently turns any reference to the function into a call to
it as soon as possible, making it impossible to do so.


-- 
Mar 31 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774





------- Comment #1 from jarrett.billingsley gmail.com  2009-03-31 20:13 -------
OK, so you can find out the ref-ness of params from (&foo).mangleof, but the
name and the member-ness are still both lost.  

class A { void foo() {} static void bar() {} }
pragma(msg, (&A.foo).mangleof); // prints PFZv
pragma(msg, (&A.bar).mangleof); // also prints PFZv


-- 
Mar 31 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774





--- Comment #2 from Shin Fujishiro <rsinfu gmail.com>  2009-05-26 02:51:35 PDT
---
Created an attachment (id=380)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=380)
Add .mangleof (DMD 2.030)

This patch adds .mangleof property to variables, functions, and templates.

Example and output:
--------------------
int var;
void foo();
template T(int n) {}
pragma(msg, var.mangleof);
pragma(msg, foo.mangleof);
pragma(msg, T!(42).mangleof);
--------------------
_D4test3vari
_D4test3fooFZv
4test10__T1TVi42Z
--------------------

BTW, you can't tell whether a parameter has the "in" parameter storage class
from .mangleof. The "in" storage class is not embedded in type mangling (by
spec). You may want to use this instead:
--------------------
import std.traits;
void foo(int a, in int b, ref int c);
enum b_stringof = ParameterTypeTuple!(foo)[1 .. 2].stringof;
pragma(msg, b_stringof);
--------------------
(in const(int))
--------------------
The slicing [1 .. 2] does the trick.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #380 is|0                           |1
           obsolete|                            |




--- Comment #3 from Shin Fujishiro <rsinfu gmail.com>  2009-05-26 07:34:28 PDT
---
Created an attachment (id=381)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=381)
Add .mangleof (DMD 1.041, 1.045, and 2.030)

I'm sorry, the old patch is wrong; it did not deal with DMD 1.041. This fixed
one is tested on DMD 1.041, 1.045, and 2.030.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 26 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774





--- Comment #4 from Shin Fujishiro <rsinfu gmail.com>  2009-05-27 13:23:56 PDT
---
(From update of attachment 381)
Please insert the following "case TOKtype" in addition to the patch. It handles
Type.mangleof.

+        Dsymbol *ds = NULL;
+        switch (e1->op)
+        {

+ e = e1->type->dotExp(sc, e1, ident); + e = e->semantic(sc); + return e; +
+            case TOKimport:

---- Forgot to explain what the patch does. The patch modifies DotIdExp::semantic so that .mangleof is evaluated before resolveProperty (which transforms the property syntax foobar.func into a function call). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 27 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2774





--- Comment #5 from Jarrett Billingsley <jarrett.billingsley gmail.com> 
2009-05-27 16:05:02 PDT ---
You're pretty awesome.

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