D-Scanner
D-Scanner copied to clipboard
--declarations: allow (at least partial) static analysis to filter results
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)
Out of curiosity, how complex would that feature be to implement?
Low complexity. I already did something similar but for another application that uses libdparse.
Great; is there any code you could share for starters? or at least insights?
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:
- accept or not : https://github.com/BBasile/Coedit/blob/master/dastworx/src/mainfun.d#L36
- set the versions for the current platform: https://github.com/BBasile/Coedit/blob/master/dastworx/src/common.d#L71 (and two pr three things under the AA declaration).
There was an unsafe access in the first link...changed now.