sequence of visiting declarations/statements in RecursiveASTVisitor


I try to transform some objective-c-code to Java. For this,
i subclassed the RecursiveASTVisitor, visit the decls/
statements and transform them.
To see the structure of the code as clang it sees, i first
print every declaration and statement with their
corresponding sourcerange. Thus, i can see that a "normal"
function-declaration (FunctionDecl), that is located somewhere
between the objective-c code, will be not visited until all
the other objective-c-method-declarations (ObjCMethodDecl)
have been visited - effectively it seems as clang jumps back
inside the sourcecode.
Is this the wanted behavior and when yes, why?

This is a bug. Objective-C’s ASTs are still a bit messy w.r.t. the ordering of declarations. libclang has a few hacks to work around the issues, but in the long term, we want to fix the ASTs themselves rather than hack up the visitor.

  • Doug