dlang-community / D-Scanner

Swiss-army knife for D source code
Boost Software License 1.0
242 stars 80 forks source link

--declarations: allow (at least partial) static analysis to filter results #387

Open timotheecour opened 7 years ago

timotheecour commented 7 years ago

eg:

dscanner --declarations --ctfe_config=" -version=linux -version=foo"

obviously making this 100% correct would potentially require full semantic analysis but perhaps some simple cases could be handled?

version(foo){ void fun(){} }

else{

version(linux) void fun(){}

else void fun(){} }

enum foo=false; static if(foo){ void fun(){} }

also related: https://github.com/Hackerpilot/Dscanner/issues/214 (would be nice, as i did above, to allow overriding OS)

timotheecour commented 7 years ago

Out of curiosity, how complex would that feature be to implement?

ghost commented 7 years ago

Low complexity. I already did something similar but for another application that uses libdparse.

timotheecour commented 7 years ago

Great; is there any code you could share for starters? or at least insights?

ghost commented 7 years ago

Sure. It's about accepting or not a visitor depending on the token text that's in a version.

I've looked at the file that does the job and it's an AST visitor so this will be similar to my stuff:

ghost commented 7 years ago

There was an unsafe access in the first link...changed now.