xref: /llvm-project/clang-tools-extra/clang-query/QueryParser.h (revision 027899dab6ac31a34e17b0f43eeb3d00e310a361)
18b1265b3SPeter Collingbourne //===--- QueryParser.h - clang-query ----------------------------*- C++ -*-===//
28b1265b3SPeter Collingbourne //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
68b1265b3SPeter Collingbourne //
78b1265b3SPeter Collingbourne //===----------------------------------------------------------------------===//
88b1265b3SPeter Collingbourne 
98b1265b3SPeter Collingbourne #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H
108b1265b3SPeter Collingbourne #define LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H
118b1265b3SPeter Collingbourne 
128b1265b3SPeter Collingbourne #include "Query.h"
131f6066c9SSamuel Benzaquen #include "QuerySession.h"
14d9a0f254SPeter Collingbourne #include "llvm/LineEditor/LineEditor.h"
1505f7e6aeSEugene Zelenko #include <cstddef>
16d9a0f254SPeter Collingbourne 
178b1265b3SPeter Collingbourne namespace clang {
188b1265b3SPeter Collingbourne namespace query {
198b1265b3SPeter Collingbourne 
20d9a0f254SPeter Collingbourne class QuerySession;
21d9a0f254SPeter Collingbourne 
22d9a0f254SPeter Collingbourne class QueryParser {
23d9a0f254SPeter Collingbourne public:
2423077e3eSDmitri Gribenko   /// Parse \a Line as a query.
25d9a0f254SPeter Collingbourne   ///
26d9a0f254SPeter Collingbourne   /// \return A QueryRef representing the query, which may be an InvalidQuery.
271f6066c9SSamuel Benzaquen   static QueryRef parse(StringRef Line, const QuerySession &QS);
28d9a0f254SPeter Collingbourne 
2923077e3eSDmitri Gribenko   /// Compute a list of completions for \a Line assuming a cursor at
3023077e3eSDmitri Gribenko   /// \param Pos characters past the start of \a Line, ordered from most
31d9a0f254SPeter Collingbourne   /// likely to least likely.
32d9a0f254SPeter Collingbourne   ///
3323077e3eSDmitri Gribenko   /// \return A vector of completions for \a Line.
341f6066c9SSamuel Benzaquen   static std::vector<llvm::LineEditor::Completion>
351f6066c9SSamuel Benzaquen   complete(StringRef Line, size_t Pos, const QuerySession &QS);
36d9a0f254SPeter Collingbourne 
37d9a0f254SPeter Collingbourne private:
QueryParser(StringRef Line,const QuerySession & QS)381f6066c9SSamuel Benzaquen   QueryParser(StringRef Line, const QuerySession &QS)
39de453362SStephen Kelly       : Line(Line), CompletionPos(nullptr), QS(QS) {}
40d9a0f254SPeter Collingbourne 
41d9a0f254SPeter Collingbourne   StringRef lexWord();
42d9a0f254SPeter Collingbourne 
43d9a0f254SPeter Collingbourne   template <typename T> struct LexOrCompleteWord;
44d9a0f254SPeter Collingbourne 
45d9a0f254SPeter Collingbourne   QueryRef parseSetBool(bool QuerySession::*Var);
46*027899daSAlexander Kornienko   QueryRef parseSetTraversalKind(TraversalKind QuerySession::*Var);
47a49fe5d8SStephen Kelly   template <typename QueryType> QueryRef parseSetOutputKind();
481f6066c9SSamuel Benzaquen   QueryRef completeMatcherExpression();
49d9a0f254SPeter Collingbourne 
50d9a0f254SPeter Collingbourne   QueryRef endQuery(QueryRef Q);
51d9a0f254SPeter Collingbourne 
52282dc72cSDmitri Gribenko   /// Parse [\p Begin,\p End).
538b1265b3SPeter Collingbourne   ///
548b1265b3SPeter Collingbourne   /// \return A reference to the parsed query object, which may be an
558b1265b3SPeter Collingbourne   /// \c InvalidQuery if a parse error occurs.
56d9a0f254SPeter Collingbourne   QueryRef doParse();
57d9a0f254SPeter Collingbourne 
58de453362SStephen Kelly   StringRef Line;
59d9a0f254SPeter Collingbourne 
60d9a0f254SPeter Collingbourne   const char *CompletionPos;
61d9a0f254SPeter Collingbourne   std::vector<llvm::LineEditor::Completion> Completions;
621f6066c9SSamuel Benzaquen 
631f6066c9SSamuel Benzaquen   const QuerySession &QS;
64d9a0f254SPeter Collingbourne };
658b1265b3SPeter Collingbourne 
668b1265b3SPeter Collingbourne } // namespace query
678b1265b3SPeter Collingbourne } // namespace clang
688b1265b3SPeter Collingbourne 
6905f7e6aeSEugene Zelenko #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_QUERY_QUERY_PARSER_H
70