steveire created this revision. Herald added a subscriber: cfe-commits. Repository: rCTE Clang Tools Extra
https://reviews.llvm.org/D51260 Files: clang-query/tool/ClangQuery.cpp Index: clang-query/tool/ClangQuery.cpp =================================================================== --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,24 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +int 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 1; + } + return 0; +} + 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"; - 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; - } + if (auto err = runCommandsInFile(argv[0], *I, QS)) + return err; } } else { LineEditor LE("clang-query");
Index: clang-query/tool/ClangQuery.cpp =================================================================== --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -58,6 +58,24 @@ cl::value_desc("file"), cl::cat(ClangQueryCategory)); +int 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 1; + } + return 0; +} + 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"; - 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; - } + if (auto err = runCommandsInFile(argv[0], *I, QS)) + return err; } } else { LineEditor LE("clang-query");
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits