One way to do this is to use ASTFrontEndAction , then override the CreateASTConsumer method to create SemaConsumer (instead of ASTConsumer).
Then, in the handleTopLevelDecl method, create a RecursiveASTVisitor, passing it the Sema that will be needed for TreeTransform.
Visit RecursiveASTVisitor TreeTransform, .
PS: scope .
SemaRef.PushFunctionScope();
SemaRef.PushCompoundScope();
.