Question of RecursiveASTVisitor class

AFAIK OpenMP is still work in progress… Hope Alexey knows more about this.

Hi Alexey:

do you have any idea about this issue?

Yes, the problem is that there is no dump support for CapturedStmt. I'll fix it ASAP.

Best regards,
Alexey Bataev

ok, but the parser can parse it, i mean the AST is there, right?

Yes, frontend builds AST node

Best regards,
Alexey Bataev

i wonder that whether it is possible to restore the preprocessed tokens when
i output the AST.

for example, this is the input file:

#define COND

void test(int var)
{
#ifdef COND
var = 1;
#else
var = 2;
#endif
}

when the parser builds the AST, we will lose some parts of the code,
so is it possible to output the AST which is the same with the input?

Hi there:

suppose i have already built the AST of the following compound Stmt, i will traversal this
AST twice,

{
… // A
… // B
}

in the first traverse, i use Rewrite.InsertText to insert “int var” between A and B,

in the second traverse, can i use visitvardecl method to visit “int var”?

Not sure, if this answers your question (given all the unrelated text you
are quoting) but towards the end of the tutorial video of Manuel Klimek,
https://www.youtube.com/watch?v=VqCkCDFLSsc, Richard answers the question.
The inserted rewrites are not affecting your ast, thus new matches/visits
will not see your rewrite, unless you rebuild the AST with the rewritten
code (text).

Citing from the link below:

" It is pretty much the same as editing the AST directly. You can do all the source editing in memory in a single tool, and do the compile step on the changed source from the same tool; no need to write anything to disk (in fact, the rewriting tools all have the source in memory before they edit the files on disk). "

i think this is what i want. but i can not find any related APIs to do this job. Could any one point this out for me?

To present my question again:
i already have the AST for the following code:
{
… // A
… // B
}

For instance, i intend to insert Decl “int var”(say C) between A and B, i want to rebuild the AST, so
i can get a new AST presenting the following code:

{
… // A
int var; // C
… // B
}

i will do other transformation based on this new AST.

Sincerely
hui

You’d use the Rewriter to modify the source buffers, and then use that information to overlay the files and re-parse the translation unit.