Author: steveire Date: Thu Aug 30 16:25:44 2018 New Revision: 341145 URL: http://llvm.org/viewvc/llvm-project?rev=341145&view=rev Log: Add preload option to clang-query
Summary: This allows loading a file with pre-defined let commands for example. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51261 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=341145&r1=341144&r2=341145&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:44 2018 @@ -58,6 +58,11 @@ static cl::list<std::string> CommandFile cl::value_desc("file"), cl::cat(ClangQueryCategory)); +static cl::opt<std::string> PreloadFile( + "preload", + cl::desc("Preload commands from file and start interactive mode"), + cl::value_desc("file"), cl::cat(ClangQueryCategory)); + bool runCommandsInFile(const char *ExeName, std::string const &FileName, QuerySession &QS) { std::ifstream Input(FileName.c_str()); @@ -86,6 +91,12 @@ int main(int argc, const char **argv) { return 1; } + if ((!Commands.empty() || !CommandFiles.empty()) && !PreloadFile.empty()) { + llvm::errs() << argv[0] + << ": cannot specify both -c or -f with --preload\n"; + return 1; + } + ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); std::vector<std::unique_ptr<ASTUnit>> ASTs; @@ -106,6 +117,10 @@ int main(int argc, const char **argv) { return 1; } } else { + if (!PreloadFile.empty()) { + if (runCommandsInFile(argv[0], PreloadFile, QS)) + return 1; + } LineEditor LE("clang-query"); LE.setListCompleter([&QS](StringRef Line, size_t Pos) { return QueryParser::complete(Line, Pos, QS); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits