Search code examples
clangabstract-syntax-treellvm-clang

Adding nodes to Clang's AST


I need to insert new nodes to AST. for instance, adding a namespace to a function: Turning this -

void foo();

into this -

namespace bar {
    void foo();
}

I read How to clone or create an AST Stmt node of clang? but I prefer not using source-to-source compilation

Tnx


Solution

  • The answer can be found here http://clang-developers.42468.n3.nabble.com/Adding-nodes-to-Clang-s-AST-td4054800.html

    However, the nodes are added to the compiled AST - for instance, in case one wants to inject a namespace to the code, he can't use the namespace directly via the code because the lexer don't know about it.