diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2017-08-19 09:36:14 +0000 |
|---|---|---|
| committer | Johannes Altmanninger <aclopte@gmail.com> | 2017-08-19 09:36:14 +0000 |
| commit | a1d2b5d54f6797453906c04eb58b7df0089e62e4 (patch) | |
| tree | 4dee11ca42b03bbcb4f729a54635ef9ffd16ac59 /clang/tools/clang-diff | |
| parent | d5f1fad77c5e6df07f940d5c24e32ebe43100fa5 (diff) | |
| download | bcm5719-llvm-a1d2b5d54f6797453906c04eb58b7df0089e62e4.tar.gz bcm5719-llvm-a1d2b5d54f6797453906c04eb58b7df0089e62e4.zip | |
[clang-diff] Add option to dump the AST, one node per line
Summary:
This is done with -ast-dump; the JSON variant has been renamed to
-ast-dump-json.
Reviewers: arphaman
Differential Revision: https://reviews.llvm.org/D36180
llvm-svn: 311232
Diffstat (limited to 'clang/tools/clang-diff')
| -rw-r--r-- | clang/tools/clang-diff/ClangDiff.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/clang/tools/clang-diff/ClangDiff.cpp b/clang/tools/clang-diff/ClangDiff.cpp index 165174add5c..2eca374b863 100644 --- a/clang/tools/clang-diff/ClangDiff.cpp +++ b/clang/tools/clang-diff/ClangDiff.cpp @@ -25,9 +25,14 @@ static cl::OptionCategory ClangDiffCategory("clang-diff options"); static cl::opt<bool> 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<bool> ASTDumpJson( + "ast-dump-json", + cl::desc("Print the internal representation of the AST as JSON."), + cl::init(false), cl::cat(ClangDiffCategory)); + static cl::opt<std::string> SourcePath(cl::Positional, cl::desc("<source>"), cl::Required, cl::cat(ClangDiffCategory)); @@ -166,6 +171,15 @@ static void printNode(raw_ostream &OS, diff::SyntaxTree &Tree, 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) { @@ -213,7 +227,7 @@ int main(int argc, const char **argv) { addExtraArgs(CommonCompilations); - if (ASTDump) { + if (ASTDump || ASTDumpJson) { if (!DestinationPath.empty()) { llvm::errs() << "Error: Please specify exactly one filename.\n"; return 1; @@ -222,6 +236,10 @@ int main(int argc, const char **argv) { 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":)"; |

