[clang-tools-extra] r341144 - Extract runCommandsInFile method

Stephen Kelly via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 30 16:25:38 PDT 2018


Author: steveire
Date: Thu Aug 30 16:25:38 2018
New Revision: 341144

URL: http://llvm.org/viewvc/llvm-project?rev=341144&view=rev
Log:
Extract runCommandsInFile method

Subscribers: cfe-commits

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

Modified:
    clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp

Modified: clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp?rev=341144&r1=341143&r2=341144&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp (original)
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp Thu Aug 30 16:25:38 2018
@@ -58,6 +58,24 @@ static cl::list<std::string> CommandFile
                                           cl::value_desc("file"),
                                           cl::cat(ClangQueryCategory));
 
+bool runCommandsInFile(const char *ExeName, std::string const &FileName,
+                       QuerySession &QS) {
+  std::ifstream Input(FileName.c_str());
+  if (!Input.is_open()) {
+    llvm::errs() << ExeName << ": cannot open " << FileName << "\n";
+    return 1;
+  }
+  while (Input.good()) {
+    std::string Line;
+    std::getline(Input, Line);
+
+    QueryRef Q = QueryParser::parse(Line, QS);
+    if (!Q->run(llvm::outs(), QS))
+      return true;
+  }
+  return false;
+}
+
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
@@ -84,19 +102,8 @@ int main(int argc, const char **argv) {
     }
   } else if (!CommandFiles.empty()) {
     for (auto I = CommandFiles.begin(), E = CommandFiles.end(); I != E; ++I) {
-      std::ifstream Input(I->c_str());
-      if (!Input.is_open()) {
-        llvm::errs() << argv[0] << ": cannot open " << *I << "\n";
+      if (runCommandsInFile(argv[0], *I, QS))
         return 1;
-      }
-      while (Input.good()) {
-        std::string Line;
-        std::getline(Input, Line);
-
-        QueryRef Q = QueryParser::parse(Line, QS);
-        if (!Q->run(llvm::outs(), QS))
-          return 1;
-      }
     }
   } else {
     LineEditor LE("clang-query");




More information about the cfe-commits mailing list