Mixin Expressions, can't evalutate string variable
Jacob Carlborg
doob at me.com
Fri Aug 6 01:44:57 PDT 2010
On 2010-08-05 23:50, Andrej Mitrovic wrote:
> On Thu, Aug 5, 2010 at 11:29 PM, Philippe Sigaud
> <philippe.sigaud at gmail.com <mailto:philippe.sigaud at gmail.com>> wrote:
>
>
>
> On Thu, Aug 5, 2010 at 22:24, Andrej Mitrovic
> <andrej.mitrovich at gmail.com <mailto:andrej.mitrovich at gmail.com>> wrote:
>
> Thanks, Steven!
>
> You don't want to know what I'm up to :p.
>
>
> Yes, yes, wo do!
>
>
> I'm using some traits to find out what kind of parameters a
> function takes. I'm also using a demangler from phobos to find
> out the name of the function (But I can't find any
> straightforward way to get a name of a function without getting
> back "1D_5std_5funcName" etc, so I just take a hardcoded slice).
>
>
> You can get the name of an alias using __traits(identifier,
> aliasName), like this for example:
>
> template Name(alias a)
> {
> enum string Name = __traits(identifier, a);
> }
>
> int foo(int i) { return 0;}
>
> import std.stdio;
> void main()
> {
> writeln(Name!foo); // "foo", not "a".
> }
>
>
> As for demangling, how do you do to get mangled names in the first
> place?
>
>
> I was using mangledName!() from std.straits. __traits works prefectly,
> Thanks!
You know there is a .mangleof property for all symbols.
> Anyway, I have a template function which takes as it's
> parameters a function (aliased to func), and some arguments
> (right now just one in my hardcoded code). It then creates a
> string which can be compiled via the mixin. It constructs the
> string by checking the parameter types of func, and for any ref
> or out parameter it detects it appends something like this to a
> string:
> "long var1; long var2; long var3; ".
>
>
> How can you know if a parameter is ref or out?
> I remember seeing something about it in Phobos svn, are you using it?
>
>
> Not svn, it's in 2.047 (maybe in earlier ones as well) in std.traits:
>
> ParameterTypeTuple!(alias) - for the types
> ParameterStorageClassTuple!(alias) - for the storage class
>
> So anyway, at the calling site I have this:
>
> mixin(unpack!(getTimes)(r"C:\\cookies"));
>
> getTimes() is a Phobos function with the signature:
> getTimes(in char[] name, out d_time ftc, out d_time fta, out
> d_time ftm)
>
> And now I automatically have var1, var2, and var3 at my disposal.
>
>
> That's fun :)
>
>
> It was just an exercise for fun but it's cool that things like
> this are possible in D. It would be nice if I could get the
> actual names of the parameters the function takes + the clear
> name of the function itself, that way I'd actually get back
> variables "ftc, fta, ftm" back)
>
>
> I'm pretty sure I saw some code to do this. But maybe that was a D1
> thing, using mangled names, too.
> in dsource/scrapple?
>
> Philippe
>
>
> Dunno, I haven't been using D1 really (actually I tried it some years
> ago with Tango but it left me wanting more so I never stuck around
> much). But D2 is super-fun.
>
>
>
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list