[clang] df1a17c - [clang-check] Add tokens-dump in clang-check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 00:41:00 PST 2021


Author: Haojian Wu
Date: 2021-02-11T09:40:47+01:00
New Revision: df1a17c219c073427f9d00eb042057bb3a4a3c64

URL: https://github.com/llvm/llvm-project/commit/df1a17c219c073427f9d00eb042057bb3a4a3c64
DIFF: https://github.com/llvm/llvm-project/commit/df1a17c219c073427f9d00eb042057bb3a4a3c64.diff

LOG: [clang-check] Add tokens-dump in clang-check.

It is useful for syntax-tree developement.

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D96017

Added: 
    

Modified: 
    clang/tools/clang-check/ClangCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-check/ClangCheck.cpp b/clang/tools/clang-check/ClangCheck.cpp
index 4be3ce980c81..11fdeb71fd9e 100644
--- a/clang/tools/clang-check/ClangCheck.cpp
+++ b/clang/tools/clang-check/ClangCheck.cpp
@@ -88,6 +88,9 @@ static cl::opt<bool> FixWhatYouCan(
 static cl::opt<bool> SyntaxTreeDump("syntax-tree-dump",
                                     cl::desc("dump the syntax tree"),
                                     cl::cat(ClangCheckCategory));
+static cl::opt<bool> TokensDump("tokens-dump",
+                                cl::desc("dump the preprocessed tokens"),
+                                cl::cat(ClangCheckCategory));
 
 namespace {
 
@@ -148,6 +151,8 @@ class DumpSyntaxTree : public clang::ASTFrontendAction {
 
       void HandleTranslationUnit(clang::ASTContext &AST) override {
         clang::syntax::TokenBuffer TB = std::move(Collector).consume();
+        if (TokensDump)
+          llvm::outs() << TB.dumpForTests();
         clang::syntax::Arena A(AST.getSourceManager(), AST.getLangOpts(), TB);
         llvm::outs() << clang::syntax::buildSyntaxTree(A, AST)->dump(
             AST.getSourceManager());
@@ -217,7 +222,7 @@ int main(int argc, const char **argv) {
     FrontendFactory = newFrontendActionFactory<clang::ento::AnalysisAction>();
   else if (Fixit)
     FrontendFactory = newFrontendActionFactory<ClangCheckFixItAction>();
-  else if (SyntaxTreeDump)
+  else if (SyntaxTreeDump || TokensDump)
     FrontendFactory = newFrontendActionFactory<DumpSyntaxTree>();
   else
     FrontendFactory = newFrontendActionFactory(&CheckFactory);


        


More information about the cfe-commits mailing list