blob: 67f907d1c44ed0d40868329528da1c6aa937e6b5 [file] [log] [blame]
Peter Collingbourne8b1265b2013-11-08 00:08:23 +00001//===--- QueryParser.h - clang-query ----------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H
12
13#include "Query.h"
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000014#include "QuerySession.h"
Peter Collingbourned9a0f252014-02-01 01:42:46 +000015#include "llvm/LineEditor/LineEditor.h"
Eugene Zelenko05f7e6a2016-03-17 17:02:25 +000016#include <cstddef>
Peter Collingbourned9a0f252014-02-01 01:42:46 +000017
Peter Collingbourne8b1265b2013-11-08 00:08:23 +000018namespace clang {
19namespace query {
20
Peter Collingbourned9a0f252014-02-01 01:42:46 +000021class QuerySession;
22
23class QueryParser {
24public:
Dmitri Gribenko23077e32014-03-02 16:48:59 +000025 /// Parse \a Line as a query.
Peter Collingbourned9a0f252014-02-01 01:42:46 +000026 ///
27 /// \return A QueryRef representing the query, which may be an InvalidQuery.
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000028 static QueryRef parse(StringRef Line, const QuerySession &QS);
Peter Collingbourned9a0f252014-02-01 01:42:46 +000029
Dmitri Gribenko23077e32014-03-02 16:48:59 +000030 /// Compute a list of completions for \a Line assuming a cursor at
31 /// \param Pos characters past the start of \a Line, ordered from most
Peter Collingbourned9a0f252014-02-01 01:42:46 +000032 /// likely to least likely.
33 ///
Dmitri Gribenko23077e32014-03-02 16:48:59 +000034 /// \return A vector of completions for \a Line.
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000035 static std::vector<llvm::LineEditor::Completion>
36 complete(StringRef Line, size_t Pos, const QuerySession &QS);
Peter Collingbourned9a0f252014-02-01 01:42:46 +000037
38private:
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000039 QueryParser(StringRef Line, const QuerySession &QS)
Mandeep Singh Grang7c7ea7d2016-11-08 07:50:19 +000040 : Begin(Line.begin()), End(Line.end()), CompletionPos(nullptr), QS(QS) {}
Peter Collingbourned9a0f252014-02-01 01:42:46 +000041
42 StringRef lexWord();
43
44 template <typename T> struct LexOrCompleteWord;
Peter Collingbourned9a0f252014-02-01 01:42:46 +000045
46 QueryRef parseSetBool(bool QuerySession::*Var);
47 QueryRef parseSetOutputKind();
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000048 QueryRef completeMatcherExpression();
Peter Collingbourned9a0f252014-02-01 01:42:46 +000049
50 QueryRef endQuery(QueryRef Q);
51
52 /// \brief Parse [\p Begin,\p End).
53 ///
54 /// \return A reference to the parsed query object, which may be an
55 /// \c InvalidQuery if a parse error occurs.
56 QueryRef doParse();
57
58 const char *Begin;
59 const char *End;
60
61 const char *CompletionPos;
62 std::vector<llvm::LineEditor::Completion> Completions;
Samuel Benzaquen1f6066c2014-04-23 14:04:52 +000063
64 const QuerySession &QS;
Peter Collingbourned9a0f252014-02-01 01:42:46 +000065};
Peter Collingbourne8b1265b2013-11-08 00:08:23 +000066
67} // namespace query
68} // namespace clang
69
Eugene Zelenko05f7e6a2016-03-17 17:02:25 +000070#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H