[cfe-dev] RE : AST Transformation

Grégory Ruch gregory.ruch at heig-vd.ch
Mon Apr 4 08:38:29 PDT 2011


Thank for your reply.

On 03/31/2011 05:35 PM, Nico Weber wrote:
> On Thu, Mar 31, 2011 at 8:10 AM, Konstantin Tokarev <annulen at yandex.ru> wrote:
>>
>> 31.03.2011, 18:59, "Nico Weber" <thakis at chromium.org>:
>>> On Thu, Mar 31, 2011 at 1:51 AM, Konstantin Tokarev <annulen at yandex.ru>; wrote:
>>>
>>>>  31.03.2011, 11:24, "Ruch Grégory" <gregory.ruch at heig-vd.ch>;:
>>>>>  But the question is more technical about Clang. Can we just implement AST transformation plugin and let the normal execution of Clang to build the executable ? I've read that pretty-print do not garantee to get reparsable code, therefore I throught that it will be better to build directly the executable.
>>>>  I'd like to join this part of question (but not in obfuscation aspect).
>>>>
>>>>  AFAIU, plugins like PrintFunctionNames can only replace Clang AST
>>>>  transformation, but not add one to compilation process.
>>> You can use -add-plugin to run plugins in addition to codegen, but the
>>> plugins will run _after_ codegen, because the AST is currently
>>> designed to be immutable.
Have you got an example that explain how to use -add-plugin. I'm trying
to use PrintFunctionNames example unsuccessful.
>>>>  More specifically, I'm trying to create C++ frontend explicitly supporting
>>>>  features of Qt Framework. Goal is to provide additional compile-time
>>>>  diagnostics and optimizations. To achieve it, I'd like to interact with AST
>>>>  when it is constructed (via custom ASTConsumer or maybe PPCallbacks,
>>>>  or both), then perform some transformations of this AST, and return it back
>>>>  into compilation process.
>>> That's currently not possible.
>> Did you mean "it's impossible to transform AST" or just "it's impossible to hook in
>> before CodeGen"?
> The AST is designed to be immutable after construction, so "it's
> impossible to transform AST".
>
With this post and other we have found interest about AST
transformation. Could it be a future feature ?

Actually there are -add-plugin that run after codeGen but could it be
possible to add the possibility to run it before and let the programmer
assume to make correct transformations?

Best regards
Greg
>> --
>> Regards,
>> Konstantin
>>




More information about the cfe-dev mailing list