Compiler-assisted code reflection for IDEs

Per Nordlöw per.nordlow at
Fri Jul 16 14:38:07 UTC 2021

On Friday, 16 July 2021 at 10:02:06 UTC, SealabJaster wrote:
> I was wondering if functionality can be added onto the compiler 
> (DMD at least, due to its speed) which allows for external 
> tooling to gain accurate information about the code?
> Take the above struct for example, maybe when the plugin 
> detects the following:
> ```d
> S!int myS;
> ```
> It could make a call to the compiler like: `dmd myapp.d 
> -reflect "myapp.S!(int)"`, where the compiler would return all 
> the info it can (It's a struct, it has a member of int called 
> a, etc.)
> It's just a rough idea, but I hope you can see what I'm trying 
> to suggest, and why I feel it's at least worth asking about.
> In other words, build some much needed language service 
> functionality into the compiler, to allow the actual language 
> servers to provide a much higher quality experience. Naively 
> assuming it's as simple as that :3

That's absolutely possible. DMD is available as a library. You 
basically take the source code feed it to the engine, apply 
whatever compiler passes you want, and accept the results using a 
visitor of your choice. There are already visitors available; I'd 
suggest starting with `SemanticTimeTransitiveVisitor` because 
it's a transitive visitor (less boiler-plate) that should be 
applied after all the semantic phases has been applied.

I suggest you first get in contact with the developers of 
Visual-D (Rainer Schutze) code-d, DCD (D completion daemon) and 
others to see what's already been done. They likely have similar 

Good luck!

More information about the Digitalmars-d mailing list