digitalmars.D - C header file importer using -J
- Peter Alexander (10/10) Nov 14 2010 Would it be theoretically possible to use string mixins, CTFE, and
- BCS (5/21) Nov 14 2010 That should be possible but would be highly complex. In effect you would...
Would it be theoretically possible to use string mixins, CTFE, and import expressions (using the -J switch) to write a function cHeaderInclude such that it may be used like: mixin( cHeaderInclude( import( "someheader.h" ) ) ); I'm imagining that the cHeaderInclude function would parse the C code from the header, convert it to D declarations at compile time, and then returns those declarations to be mixed in, just like an #include would do. Preprocessor defines could be handled with extra parameters: "SOME_DEF=1, ANOTHER_DEF=foo" etc. Am I missing something that would make this impossible?
Nov 14 2010
Hello Peter,Would it be theoretically possible to use string mixins, CTFE, and import expressions (using the -J switch) to write a function cHeaderInclude such that it may be used like: mixin( cHeaderInclude( import( "someheader.h" ) ) ); I'm imagining that the cHeaderInclude function would parse the C code from the header, convert it to D declarations at compile time, and then returns those declarations to be mixed in, just like an #include would do. Preprocessor defines could be handled with extra parameters: "SOME_DEF=1, ANOTHER_DEF=foo" etc. Am I missing something that would make this impossible?That should be possible but would be highly complex. In effect you would need to implement a large chunk of a compiler. Given that there is already a tool to do that offline (http://www.digitalmars.com/d/2.0/htod.html) it would, IMHO, be inadvisable.
Nov 14 2010