Comment #0 by jarrett.billingsley — 2009-03-31T20:04:57Z
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.
Comment #1 by jarrett.billingsley — 2009-03-31T20:13:01Z
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
Comment #2 by rsinfu — 2009-05-26T02:51:35Z
Created attachment 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.
Comment #3 by rsinfu — 2009-05-26T07:34:28Z
Created attachment 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.
Comment #4 by rsinfu — 2009-05-27T13:23:56Z
Comment on attachment 381
Add .mangleof (DMD 1.041, 1.045, and 2.030)
Please insert the following "case TOKtype" in addition to the patch. It handles Type.mangleof.
>+ Dsymbol *ds = NULL;
>+ switch (e1->op)
>+ {
+ case TOKtype:
+ 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).
Comment #5 by jarrett.billingsley — 2009-05-27T16:05:02Z