Add the "quit" command as a way to terminate clang-query interactive sessions.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@244206 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
4d2f6f7111
Коммит
4ac5595dd0
|
@ -44,7 +44,14 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
|
|||
" 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче