Thread overview | |||||
---|---|---|---|---|---|
|
April 05, 2016 [dmd-internals] Getting the calling scope for a function (e.g. to get __FUNC__ from the caller) | ||||
---|---|---|---|---|
| ||||
To get to know DMD a bit more, I decided to implement __GENSYM__, as touched upon in Nordlöw's post on Units of Measurements[1]. My implementation uses the mangled name of the instantiation scope and an associated counter to create a unique string, and works great for template default parameters (which is where I imagine it would see use). For completeness though, I wanted to make it work as a function default parameter as well. Looking at how __FILE__ and __LINE__ are implemented, they use only Loc, not Scope. Is it at all possible to get the calling scope for a function? [1]: http://forum.dlang.org/post/mtniwehednpdofmcftwc@forum.dlang.org _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
April 05, 2016 Re: [dmd-internals] Getting the calling scope for a function (e.g. to get __FUNC__ from the caller) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen Kjaeraas | > On 5 apr 2016, at 16:54, Simen Kjaeraas via dmd-internals <dmd-internals@puremagic.com> wrote: > > To get to know DMD a bit more, I decided to implement __GENSYM__, as touched upon in Nordlöw's post on Units of Measurements[1]. > > My implementation uses the mangled name of the instantiation scope and an associated counter to create a unique string, and works great for template default parameters (which is where I imagine it would see use). > > For completeness though, I wanted to make it work as a function default parameter as well. Looking at how __FILE__ and __LINE__ are implemented, they use only Loc, not Scope. Is it at all possible to get the calling scope for a function? Not sure where you’re looking but I would guess __FILE_ and __LINE__ are handled here [1], where the scope is available. [1 ]https://github.com/D-Programming-Language/dmd/blob/master/src/expression.d#L1446 -- /Jacob Carlborg _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
April 06, 2016 Re: [dmd-internals] Getting the calling scope for a function (e.g. to get __FUNC__ from the caller) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Tuesday, 5 April 2016 at 19:59:15 UTC, Jacob Carlborg wrote: >> On 5 apr 2016, at 16:54, Simen Kjaeraas via dmd-internals <dmd-internals@puremagic.com> wrote: >> >> To get to know DMD a bit more, I decided to implement __GENSYM__, as touched upon in Nordlöw's post on Units of Measurements[1]. >> >> My implementation uses the mangled name of the instantiation scope and an associated counter to create a unique string, and works great for template default parameters (which is where I imagine it would see use). >> >> For completeness though, I wanted to make it work as a function default parameter as well. Looking at how __FILE__ and __LINE__ are implemented, they use only Loc, not Scope. Is it at all possible to get the calling scope for a function? > > Not sure where you’re looking but I would guess __FILE_ and __LINE__ are handled here [1], where the scope is available. > > [1] https://github.com/D-Programming-Language/dmd/blob/master/src/expression.d#L1446 Thanks! I realized I'd misunderstood how __FUNCTION__ works, which is the one I should have been looking at. That takes care using __GENSYM__ in functions, and SCOPEctfe handles using it in module or aggregate scopes: struct S { enum s = __GENSYM__; } So it seems to be working now. Thanks a lot! -- Simen _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
Copyright © 1999-2021 by the D Language Foundation