D-Scanner icon indicating copy to clipboard operation
D-Scanner copied to clipboard

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

Open timotheecour opened this issue 8 years ago • 5 comments

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 avatar Dec 13 '16 07:12 timotheecour

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

timotheecour avatar Jun 10 '17 18:06 timotheecour

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

ghost avatar Jun 11 '17 17:06 ghost

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

timotheecour avatar Jun 11 '17 20:06 timotheecour

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).

ghost avatar Jun 11 '17 20:06 ghost

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

ghost avatar Jun 11 '17 23:06 ghost