I have an idea for something. I know I can't be the only one to think this way but I can't find very much information on it.

Basically, I want compile-time enforcement of semantic rules.

For one example--I asked previously here--if it was possible to generate a compile-time warning or error if someone used a function without checking the return value. But that is one specific implementation of a more abstract idea: Setting up rulesets to prevent common developer errors in my codebase that trigger at compile-time.

I'm wondering how to go about a more general-purpose setup.

Now, if I was using C/C++, I could generate the AST (Abstract Syntax Tree) with Clang. (And if you've never done it, I strongly recommend it, it's quite beautiful.) Clang also has libclang for modifying and generating AST on-the-fly which opens up huge potential--but back to the point: if I can find how to get LDC2 to generate AST, I could write a parser and scan the AST for patterns.

I've seen DIP50 and AST Macros which are very interesting... but as far as I know, it's not implemented in any compiler.

So the question is: Is there a way to get LDC2 to generate AST or similar, and if not, any other way to go about this?

And lastly, is there a proper term for this process, and/or a field of research? I have found GCC MELT. But documentation is sparse and it seems restricted to GCC and C/C++. I guess you could call this "static analysis" with custom rules?

Reply via email to