On Thu, Oct 18, 2012 at 9:34 AM, mefyl <mefyl@xxxxxxxxxxxx> wrote: > > * I can retrieve source file location of declarations with > DECL_SOURCE_LOCATION without any problem, but I can't get locations for > expressions since their EXPR_LOCATION is always null. I used the > PLUGIN_PRE_GENERICIZE hook, which AFAIK is the earliest, so I expected > locations to still be there. Did I miss something, or is there no way to > retrieve such locations from plugins, in which case my example seems > impossible ? Most expressions should have locations these days. It is certainly true that there will be some that do not. Hard to say more without more details. > * Even if we suppose I fixed the previous issue, from what I inferred from the > AST, a reference to a variable is directly represented by the corresponding > VAR_DECL. That is, in "int x; int y; x + y;", "x + y" is a PLUS_EXPR whose > operands are the VAR_DECL corresponding to "int x" and "int y". This would > make it impossible for me to get the location of "x" and "y", since they are > not represented as such by nodes in the AST. That is correct. > I fear that due to the compiler nature of GCC, the AST I'm working on is > altered, with some processing and simplification already applied, preventing > source-to-source code transformation since one cannot map ast chunks back to > source files. Could anyone confirm or point me in some direction if I'm wrong > ? In the case it's indeed impossible, is there any intent to improve this > aspect, like giving access to earlier stages of the AST (freshly parsed, with > only variable bindings for instance) ? This would enable to write extremely > powerfull analysis & refactoring tools. Unfortunately the GCC AST almost certainly does not retain enough information for the kind of transformations you want to do. This is a deficiency in the AST, but I can't even estimate how difficult it would be to fix. Ian