How can I turn on the "dump" printing of the AST?


The ASTPrinter has the option to print the addresses and fields of the AST objects, but I can't find a way to invoke this from the command line. Is there a way?

When I hack the ASTPrinter source like this:

      virtual void HandleTranslationUnit(ASTContext &Context) {
        PrintingPolicy Policy = Context.PrintingPolicy;
- Policy.Dump = Dump;
+ Policy.Dump = true;
        Context.getTranslationUnitDecl()->print(Out, Policy);

it doesn't print class names & addresses for function declarations, just their bodies, e.g.:

int foo(int x, int y) {
         return x + y;

prints as:

int foo(int x, int y) (CompoundStmt 0xad6b460 <./t.c:1:23, line:3:1>
   (ReturnStmt 0xad6afa0 <line:2:2, col:13>
     (BinaryOperator 0xad717a0 <col:9, col:13> 'int' '+'
       (DeclRefExpr 0xad71720 <col:9> 'int' ParmVar='x' 0xad5d910)
       (DeclRefExpr 0xad71760 <col:13> 'int' ParmVar='y' 0xad6c360))))

Is there a way to get it to print the declarations as well?


clang -cc1 -ast-dump file.c