digitalmars.D - __traits proposal possible? or must be AST macros?
I want to propose a new __traits to extract the raw code in a function and/or class. Getting that as a compile-time string would allow for compile-time transformations of that code. Just as the Blade library (by Don Clugston) uses mixins to inject code generated from expressions, this could modify instead if create code. This may allow for some metaprogramming tricks with functions, like substitution of all int variables to double, with no need to reimplement the function (just processing it), and extract all these operations to project-agnostic modules, so it could transform any function. Although this could be done entirely with current mixins, you need to implement the function as a string mixin from scratch, but with this you wouldn't need to, just create it with ints and pass it to a generic "int->double local variables converter" at source level. THIS IS A NA¤VE EXAMPLE, but there could be others: - print the full content of a function with code that has been "mixed in" at compile-time (metaprogram debugging) - check the use of specific keywords - change specific keywords - analyze code style :P - identify certain patterns for extraction/removal/warning. I guess the intention of AST macros is to make this totally unnecessary, but this perhaps is easy to implement and is of any interest for people around. ...or this is just impossible because of the moment at which __traits are evaluated? Please, enlighten me.
Jan 12 2010