Any way to get file/line for symbol declaration?

Manu turkeyman at gmail.com
Sun Jun 9 22:17:08 UTC 2019


On Sun, Jun 9, 2019 at 2:40 PM Andre Pany via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Sunday, 9 June 2019 at 21:26:52 UTC, Manu wrote:
> > I have some reflection-heavy validation code, it's necessary
> > that I emit meaningful error messages to the user explaining
> > when inputs don't meet expectation.
> >
> > I'm finding that emitting an FQN along with the error messages
> > is not
> > super productive.
> > I'd REALLY like to emit the error with the proper file and line
> > prefix
> > so that you can click and code editors will go to the problem
> > declaration.
> >
> > I can't find any way to dig the Loc of the declaration from the
> > symbol reference. Does anyone know any tricks? Should I make a
> > PR to expose the symbol Loc as a traits?
>
> I have a very similar use case. I need for a module name the
> filename. I also thought about s.th. like
> __traits(file, "module name")
> The idea is, the return value is the same like __FILE__ in the
> scope of the module.
>
> Anything which would enable it would be very welcome.

I'm thinking something like: __traits(getLoc, symbol) ==
AliasSeq!(file, line, column) for the declaration of the symbol
specified.


More information about the Digitalmars-d mailing list