31 #include "clang/Frontend/ASTUnit.h" 32 #include "clang/Tooling/CommonOptionsParser.h" 33 #include "clang/Tooling/Tooling.h" 34 #include "llvm/LineEditor/LineEditor.h" 35 #include "llvm/Support/CommandLine.h" 36 #include "llvm/Support/MemoryBuffer.h" 37 #include "llvm/Support/Signals.h" 41 using namespace clang;
48 static cl::extrahelp
CommonHelp(CommonOptionsParser::HelpMessage);
51 static cl::list<std::string>
Commands(
"c", cl::desc(
"Specify command to run"),
52 cl::value_desc(
"command"),
56 cl::desc(
"Read commands from file"),
57 cl::value_desc(
"file"),
62 cl::desc(
"Preload commands from file and start interactive mode"),
67 std::ifstream Input(FileName.c_str());
68 if (!Input.is_open()) {
69 llvm::errs() << ExeName <<
": cannot open " << FileName <<
"\n";
72 while (Input.good()) {
74 std::getline(Input, Line);
76 QueryRef Q = QueryParser::parse(Line, QS);
77 if (!Q->run(llvm::outs(), QS))
83 int main(
int argc,
const char **argv) {
84 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
89 llvm::errs() << argv[0] <<
": cannot specify both -c and -f\n";
94 llvm::errs() << argv[0]
95 <<
": cannot specify both -c or -f with --preload\n";
99 ClangTool Tool(OptionsParser.getCompilations(),
100 OptionsParser.getSourcePathList());
101 std::vector<std::unique_ptr<ASTUnit>> ASTs;
102 int Status = Tool.buildASTs(ASTs);
107 }
else if (Status == 2) {
109 llvm::errs() <<
"Failed to build AST for some of the files, " 110 <<
"results may be incomplete." 113 assert(Status == 0 &&
"Unexpected status returned");
120 QueryRef Q = QueryParser::parse(*I, QS);
121 if (!Q->run(llvm::outs(), QS))
134 LineEditor LE(
"clang-query");
135 LE.setListCompleter([&QS](StringRef
Line,
size_t Pos) {
136 return QueryParser::complete(Line, Pos, QS);
138 while (llvm::Optional<std::string> Line = LE.readLine()) {
139 QueryRef Q = QueryParser::parse(*Line, QS);
140 Q->run(llvm::outs(), QS);
141 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)