[clang-tools-extra] r244206 - Add the "quit" command as a way to terminate clang-query interactive sessions.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 04:56:58 PDT 2015
Author: aaronballman
Date: Thu Aug 6 06:56:57 2015
New Revision: 244206
URL: http://llvm.org/viewvc/llvm-project?rev=244206&view=rev
Log:
Add the "quit" command as a way to terminate clang-query interactive sessions.
Modified:
clang-tools-extra/trunk/clang-query/Query.cpp
clang-tools-extra/trunk/clang-query/Query.h
clang-tools-extra/trunk/clang-query/QueryParser.cpp
clang-tools-extra/trunk/clang-query/QuerySession.h
clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
Modified: clang-tools-extra/trunk/clang-query/Query.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.cpp?rev=244206&r1=244205&r2=244206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/Query.cpp (original)
+++ clang-tools-extra/trunk/clang-query/Query.cpp Thu Aug 6 06:56:57 2015
@@ -44,7 +44,14 @@ bool HelpQuery::run(llvm::raw_ostream &O
" set output (diag|print|dump) "
"Set whether to print bindings as diagnostics,\n"
" "
- "AST pretty prints or AST dumps.\n\n";
+ "AST pretty prints or AST dumps.\n"
+ " quit "
+ "Terminates the query session.\n\n";
+ return true;
+}
+
+bool QuitQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
+ QS.Terminate = true;
return true;
}
Modified: clang-tools-extra/trunk/clang-query/Query.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.h?rev=244206&r1=244205&r2=244206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/Query.h (original)
+++ clang-tools-extra/trunk/clang-query/Query.h Thu Aug 6 06:56:57 2015
@@ -32,6 +32,7 @@ enum QueryKind {
QK_Match,
QK_SetBool,
QK_SetOutputKind,
+ QK_Quit
};
class QuerySession;
@@ -76,6 +77,14 @@ struct HelpQuery : Query {
static bool classof(const Query *Q) { return Q->Kind == QK_Help; }
};
+/// Query for "quit".
+struct QuitQuery : Query {
+ QuitQuery() : Query(QK_Quit) {}
+ bool run(llvm::raw_ostream &OS, QuerySession &QS) const override;
+
+ static bool classof(const Query *Q) { return Q->Kind == QK_Quit; }
+};
+
/// Query for "match MATCHER".
struct MatchQuery : Query {
MatchQuery(const ast_matchers::dynamic::DynTypedMatcher &Matcher)
Modified: clang-tools-extra/trunk/clang-query/QueryParser.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/QueryParser.cpp?rev=244206&r1=244205&r2=244206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/QueryParser.cpp (original)
+++ clang-tools-extra/trunk/clang-query/QueryParser.cpp Thu Aug 6 06:56:57 2015
@@ -142,6 +142,7 @@ enum ParsedQueryKind {
PQK_Match,
PQK_Set,
PQK_Unlet,
+ PQK_Quit
};
enum ParsedQueryVariable {
@@ -181,6 +182,7 @@ QueryRef QueryParser::doParse() {
.Case("match", PQK_Match)
.Case("set", PQK_Set)
.Case("unlet", PQK_Unlet)
+ .Case("quit", PQK_Quit)
.Default(PQK_Invalid);
switch (QKind) {
@@ -190,6 +192,9 @@ QueryRef QueryParser::doParse() {
case PQK_Help:
return endQuery(new HelpQuery);
+ case PQK_Quit:
+ return endQuery(new QuitQuery);
+
case PQK_Let: {
StringRef Name = lexWord();
Modified: clang-tools-extra/trunk/clang-query/QuerySession.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/QuerySession.h?rev=244206&r1=244205&r2=244206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/QuerySession.h (original)
+++ clang-tools-extra/trunk/clang-query/QuerySession.h Thu Aug 6 06:56:57 2015
@@ -25,11 +25,12 @@ namespace query {
class QuerySession {
public:
QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
- : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true) {}
+ : ASTs(ASTs), OutKind(OK_Diag), BindRoot(true), Terminate(false) {}
llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
OutputKind OutKind;
bool BindRoot;
+ bool Terminate;
llvm::StringMap<ast_matchers::dynamic::VariantValue> NamedValues;
};
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=244206&r1=244205&r2=244206&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp (original)
+++ clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp Thu Aug 6 06:56:57 2015
@@ -111,6 +111,8 @@ int main(int argc, const char **argv) {
QueryRef Q = QueryParser::parse(*Line, QS);
Q->run(llvm::outs(), QS);
llvm::outs().flush();
+ if (QS.Terminate)
+ break;
}
}
More information about the cfe-commits
mailing list