[PATCH] D51260: Extract runCommandsInFile method

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 30 16:26:40 PDT 2018


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341144: Extract runCommandsInFile method (authored by steveire, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51260?vs=162554&id=163444#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51260

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


Index: clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
===================================================================
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
@@ -58,6 +58,24 @@
                                           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 @@
     }
   } 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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51260.163444.patch
Type: text/x-patch
Size: 1630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180830/e3407095/attachment.bin>


More information about the cfe-commits mailing list