blob: cfba0266c3768f904b3782e2b4aec0080765d4e5 [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"
14
Peter Collingbourned9a0f252014-02-01 01:42:46 +000015#include <stddef.h>
16#include "llvm/LineEditor/LineEditor.h"
17
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:
25 /// Parse \param Line as a query.
26 ///
27 /// \return A QueryRef representing the query, which may be an InvalidQuery.
28 static QueryRef parse(StringRef Line);
29
30 /// Compute a list of completions for \param Line assuming a cursor at
31 /// \param Pos characters past the start of \param Line, ordered from most
32 /// likely to least likely.
33 ///
34 /// \return A vector of completions for \param Line.
35 static std::vector<llvm::LineEditor::Completion> complete(StringRef Line,
36 size_t Pos);
37
38private:
39 QueryParser(StringRef Line)
40 : Begin(Line.data()), End(Line.data() + Line.size()), CompletionPos(0) {}
41
42 StringRef lexWord();
43
44 template <typename T> struct LexOrCompleteWord;
45 template <typename T> LexOrCompleteWord<T> lexOrCompleteWord(StringRef &Str);
46
47 QueryRef parseSetBool(bool QuerySession::*Var);
48 QueryRef parseSetOutputKind();
49
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;
63};
Peter Collingbourne8b1265b2013-11-08 00:08:23 +000064
65} // namespace query
66} // namespace clang
67
68#endif