diff options
author | Stephen Kelly <steveire@gmail.com> | 2018-08-30 23:25:38 +0000 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2018-08-30 23:25:38 +0000 |
commit | 7dfed0b22c27d69be338a89f9a1e5bf1e9653209 (patch) | |
tree | 6d892295003bff158f894b4af8d65ec541b4d4a2 /clang-tools-extra/clang-query/tool/ClangQuery.cpp | |
parent | 347b989cefdca2bd0272086ce3923199a5667aa3 (diff) | |
download | bcm5719-llvm-7dfed0b22c27d69be338a89f9a1e5bf1e9653209.tar.gz bcm5719-llvm-7dfed0b22c27d69be338a89f9a1e5bf1e9653209.zip |
Extract runCommandsInFile method
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D51260
llvm-svn: 341144
Diffstat (limited to 'clang-tools-extra/clang-query/tool/ClangQuery.cpp')
-rw-r--r-- | clang-tools-extra/clang-query/tool/ClangQuery.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/clang-tools-extra/clang-query/tool/ClangQuery.cpp b/clang-tools-extra/clang-query/tool/ClangQuery.cpp index 669dc40e362..d0a4a80a370 100644 --- a/clang-tools-extra/clang-query/tool/ClangQuery.cpp +++ b/clang-tools-extra/clang-query/tool/ClangQuery.cpp @@ -58,6 +58,24 @@ static cl::list<std::string> CommandFiles("f", 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"); |