32 #include "clang/Frontend/ASTUnit.h" 33 #include "clang/Tooling/CommonOptionsParser.h" 34 #include "clang/Tooling/Tooling.h" 35 #include "llvm/LineEditor/LineEditor.h" 36 #include "llvm/Support/CommandLine.h" 37 #include "llvm/Support/MemoryBuffer.h" 38 #include "llvm/Support/Signals.h" 42 using namespace clang;
49 static cl::extrahelp
CommonHelp(CommonOptionsParser::HelpMessage);
52 static cl::list<std::string>
Commands(
"c", cl::desc(
"Specify command to run"),
53 cl::value_desc(
"command"),
57 cl::desc(
"Read commands from file"),
58 cl::value_desc(
"file"),
63 cl::desc(
"Preload commands from file and start interactive mode"),
68 std::ifstream Input(FileName.c_str());
69 if (!Input.is_open()) {
70 llvm::errs() << ExeName <<
": cannot open " << FileName <<
"\n";
73 while (Input.good()) {
75 std::getline(Input, Line);
77 QueryRef Q = QueryParser::parse(Line, QS);
78 if (!Q->run(llvm::outs(), QS))
84 int main(
int argc,
const char **argv) {
85 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
90 llvm::errs() << argv[0] <<
": cannot specify both -c and -f\n";
95 llvm::errs() << argv[0]
96 <<
": cannot specify both -c or -f with --preload\n";
100 ClangTool Tool(OptionsParser.getCompilations(),
101 OptionsParser.getSourcePathList());
102 std::vector<std::unique_ptr<ASTUnit>> ASTs;
103 int Status = Tool.buildASTs(ASTs);
108 }
else if (Status == 2) {
110 llvm::errs() <<
"Failed to build AST for some of the files, " 111 <<
"results may be incomplete." 114 assert(Status == 0 &&
"Unexpected status returned");
121 QueryRef Q = QueryParser::parse(*I, QS);
122 if (!Q->run(llvm::outs(), QS))
135 LineEditor LE(
"clang-query");
136 LE.setListCompleter([&QS](StringRef
Line,
size_t Pos) {
137 return QueryParser::complete(Line, Pos, QS);
139 while (llvm::Optional<std::string> Line = LE.readLine()) {
140 QueryRef Q = QueryParser::parse(*Line, QS);
141 Q->run(llvm::outs(), QS);
142 llvm::outs().flush();
Some operations such as code completion produce a set of candidates.
static cl::list< std::string > Commands("c", cl::desc("Specify command to run"), cl::value_desc("command"), cl::cat(ClangQueryCategory))
Represents the state for a particular clang-query session.
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage)
static cl::OptionCategory ClangQueryCategory("clang-query options")
static cl::list< std::string > CommandFiles("f", cl::desc("Read commands from file"), 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))
llvm::IntrusiveRefCntPtr< Query > QueryRef
int main(int argc, const char **argv)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
bool runCommandsInFile(const char *ExeName, std::string const &FileName, QuerySession &QS)