Bug 2774 – Functions-as-properties makes it impossible to get the .mangleof a function

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2009-03-31T20:04:00Z
Last change time
2015-06-09T05:12:01Z
Keywords
patch, spec
Assigned to
bugzilla
Creator
jarrett.billingsley
Blocks
3107

Attachments

IDFilenameSummaryContent-TypeSize
380enh_mangleof.patchAdd .mangleof (DMD 2.030)text/plain910
381enh_mangleof.patchAdd .mangleof (DMD 1.041, 1.045, and 2.030)text/plain1063

Comments

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
You're pretty awesome.
Comment #6 by k.hara.pg — 2011-07-14T04:37:42Z
Comment #7 by bugzilla — 2011-08-11T15:12:27Z