Index: tools/clang-diff/ClangDiff.cpp =================================================================== --- tools/clang-diff/ClangDiff.cpp +++ tools/clang-diff/ClangDiff.cpp @@ -25,9 +25,14 @@ static cl::opt ASTDump("ast-dump", - cl::desc("Print the internal representation of the AST as JSON."), + cl::desc("Print the internal representation of the AST."), cl::init(false), cl::cat(ClangDiffCategory)); +static cl::opt ASTDumpJson( + "ast-dump-json", + cl::desc("Print the internal representation of the AST as JSON."), + cl::init(false), cl::cat(ClangDiffCategory)); + static cl::opt NoCompilationDatabase( "no-compilation-database", cl::desc( @@ -168,6 +173,15 @@ OS << "(" << Id << ")"; } +static void printTree(raw_ostream &OS, diff::SyntaxTree &Tree) { + for (diff::NodeId Id : Tree) { + for (int I = 0; I < Tree.getNode(Id).Depth; ++I) + OS << " "; + printNode(OS, Tree, Id); + OS << "\n"; + } +} + static void printDstChange(raw_ostream &OS, diff::ASTDiff &Diff, diff::SyntaxTree &SrcTree, diff::SyntaxTree &DstTree, diff::NodeId Dst) { @@ -208,7 +222,7 @@ return 1; } - if (ASTDump) { + if (ASTDump || ASTDumpJson) { if (!DestinationPath.empty()) { llvm::errs() << "Error: Please specify exactly one filename.\n"; return 1; @@ -217,6 +231,10 @@ if (!AST) return 1; diff::SyntaxTree Tree(AST->getASTContext()); + if (ASTDump) { + printTree(llvm::outs(), Tree); + return 0; + } llvm::outs() << R"({"filename":")"; printJsonString(llvm::outs(), SourcePath); llvm::outs() << R"(","root":)";