steveire created this revision.
Herald added a subscriber: cfe-commits.
This allows loading a file with pre-defined let commands for example.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D51261
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,11 @@
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));
+
int runCommandsInFile(const char* exeName, std::string const& fileName,
QuerySession& QS)
{
std::ifstream Input(fileName.c_str());
@@ -86,6 +91,12 @@
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 @@
return err;
}
} else {
+ if (!PreloadFile.empty()) {
+ if (auto err = runCommandsInFile(argv[0], PreloadFile, QS))
+ return err;
+ }
LineEditor LE("clang-query");
LE.setListCompleter([&QS](StringRef Line, size_t Pos) {
return QueryParser::complete(Line, Pos, QS);
Index: clang-query/tool/ClangQuery.cpp
===================================================================
--- clang-query/tool/ClangQuery.cpp
+++ clang-query/tool/ClangQuery.cpp
@@ -58,6 +58,11 @@
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));
+
int runCommandsInFile(const char* exeName, std::string const& fileName, QuerySession& QS)
{
std::ifstream Input(fileName.c_str());
@@ -86,6 +91,12 @@
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 @@
return err;
}
} else {
+ if (!PreloadFile.empty()) {
+ if (auto err = runCommandsInFile(argv[0], PreloadFile, QS))
+ return err;
+ }
LineEditor LE("clang-query");
LE.setListCompleter([&QS](StringRef Line, size_t Pos) {
return QueryParser::complete(Line, Pos, QS);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits