Peter Collingbourne | 8b1265b | 2013-11-08 00:08:23 +0000 | [diff] [blame] | 1 | //===--- 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 Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 14 | #include "QuerySession.h" |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 15 | #include "llvm/LineEditor/LineEditor.h" |
Eugene Zelenko | 05f7e6a | 2016-03-17 17:02:25 +0000 | [diff] [blame] | 16 | #include <cstddef> |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 17 | |
Peter Collingbourne | 8b1265b | 2013-11-08 00:08:23 +0000 | [diff] [blame] | 18 | namespace clang { |
| 19 | namespace query { |
| 20 | |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 21 | class QuerySession; |
| 22 | |
| 23 | class QueryParser { |
| 24 | public: |
Dmitri Gribenko | 23077e3 | 2014-03-02 16:48:59 +0000 | [diff] [blame] | 25 | /// Parse \a Line as a query. |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 26 | /// |
| 27 | /// \return A QueryRef representing the query, which may be an InvalidQuery. |
Samuel Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 28 | static QueryRef parse(StringRef Line, const QuerySession &QS); |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 29 | |
Dmitri Gribenko | 23077e3 | 2014-03-02 16:48:59 +0000 | [diff] [blame] | 30 | /// 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 Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 32 | /// likely to least likely. |
| 33 | /// |
Dmitri Gribenko | 23077e3 | 2014-03-02 16:48:59 +0000 | [diff] [blame] | 34 | /// \return A vector of completions for \a Line. |
Samuel Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 35 | static std::vector<llvm::LineEditor::Completion> |
| 36 | complete(StringRef Line, size_t Pos, const QuerySession &QS); |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
Samuel Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 39 | QueryParser(StringRef Line, const QuerySession &QS) |
Craig Topper | 6014c49 | 2014-06-10 04:50:50 +0000 | [diff] [blame] | 40 | : Begin(Line.begin()), End(Line.end()), |
Craig Topper | f61be9c | 2014-06-09 02:03:06 +0000 | [diff] [blame] | 41 | CompletionPos(nullptr), QS(QS) {} |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 42 | |
| 43 | StringRef lexWord(); |
| 44 | |
| 45 | template <typename T> struct LexOrCompleteWord; |
| 46 | template <typename T> LexOrCompleteWord<T> lexOrCompleteWord(StringRef &Str); |
| 47 | |
| 48 | QueryRef parseSetBool(bool QuerySession::*Var); |
| 49 | QueryRef parseSetOutputKind(); |
Samuel Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 50 | QueryRef completeMatcherExpression(); |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 51 | |
| 52 | QueryRef endQuery(QueryRef Q); |
| 53 | |
| 54 | /// \brief Parse [\p Begin,\p End). |
| 55 | /// |
| 56 | /// \return A reference to the parsed query object, which may be an |
| 57 | /// \c InvalidQuery if a parse error occurs. |
| 58 | QueryRef doParse(); |
| 59 | |
| 60 | const char *Begin; |
| 61 | const char *End; |
| 62 | |
| 63 | const char *CompletionPos; |
| 64 | std::vector<llvm::LineEditor::Completion> Completions; |
Samuel Benzaquen | 1f6066c | 2014-04-23 14:04:52 +0000 | [diff] [blame] | 65 | |
| 66 | const QuerySession &QS; |
Peter Collingbourne | d9a0f25 | 2014-02-01 01:42:46 +0000 | [diff] [blame] | 67 | }; |
Peter Collingbourne | 8b1265b | 2013-11-08 00:08:23 +0000 | [diff] [blame] | 68 | |
| 69 | } // namespace query |
| 70 | } // namespace clang |
| 71 | |
Eugene Zelenko | 05f7e6a | 2016-03-17 17:02:25 +0000 | [diff] [blame] | 72 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H |