/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/parser/parse_context.h
Line | Count | Source |
1 | | //-------------------------------------------------------------------------------------------------- |
2 | | // Copyright (c) YugaByte, Inc. |
3 | | // |
4 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
5 | | // in compliance with the License. You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
10 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
11 | | // or implied. See the License for the specific language governing permissions and limitations |
12 | | // under the License. |
13 | | // |
14 | | // |
15 | | // Entry point for the parsing process. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #ifndef YB_YQL_CQL_QL_PARSER_PARSE_CONTEXT_H_ |
19 | | #define YB_YQL_CQL_QL_PARSER_PARSE_CONTEXT_H_ |
20 | | |
21 | | #include "yb/yql/cql/ql/parser/location.h" |
22 | | #include "yb/yql/cql/ql/ptree/process_context.h" |
23 | | |
24 | | #include "yb/util/mem_tracker.h" |
25 | | |
26 | | namespace yb { |
27 | | namespace ql { |
28 | | |
29 | | // Parsing context. |
30 | | class ParseContext : public ProcessContext { |
31 | | public: |
32 | | //------------------------------------------------------------------------------------------------ |
33 | | // Public types. |
34 | | typedef std::unique_ptr<ParseContext> UniPtr; |
35 | | typedef std::unique_ptr<const ParseContext> UniPtrConst; |
36 | | |
37 | | //------------------------------------------------------------------------------------------------ |
38 | | // Constructor & destructor. |
39 | | ParseContext(const std::string& stmt, |
40 | | bool reparsed = false, |
41 | | const MemTrackerPtr& mem_tracker = nullptr, |
42 | | const bool internal = false); |
43 | | virtual ~ParseContext(); |
44 | | |
45 | | // Read a maximum of 'max_size' bytes from SQL statement of this parsing context into the |
46 | | // provided buffer 'buf'. Scanner will call this function when looking for next token. |
47 | | size_t Read(char* buf, size_t max_size); |
48 | | |
49 | | // Add a bind variable. |
50 | 14.3k | void AddBindVariable(PTBindVar *var) { |
51 | 14.3k | bind_variables_.insert(var); |
52 | 14.3k | } |
53 | | |
54 | | // Return the list of bind variables found during parsing. |
55 | | void GetBindVariables(MCVector<PTBindVar*> *vars); |
56 | | |
57 | | // Handling parsing warning. |
58 | | void Warn(const location& loc, const char *msg, ErrorCode error_code); |
59 | | |
60 | | // Handling parsing error. |
61 | | CHECKED_STATUS Error(const location& loc, |
62 | | const char *msg, |
63 | | ErrorCode error_code, |
64 | | const char* token = nullptr); |
65 | | CHECKED_STATUS Error(const location& loc, const char *msg, const char* token = nullptr); |
66 | | CHECKED_STATUS Error(const location& loc, ErrorCode error_code, const char* token = nullptr); |
67 | | |
68 | | // Access function for ql_file_. |
69 | 336k | std::istream *ql_file() { |
70 | 336k | return ql_file_.get(); |
71 | 336k | } |
72 | | |
73 | | // Access function for trace_scanning_. |
74 | 334k | bool trace_scanning() const { |
75 | 334k | return trace_scanning_; |
76 | 334k | } |
77 | | |
78 | | // Access function for trace_parsing_. |
79 | 335k | bool trace_parsing() const { |
80 | 335k | return trace_parsing_; |
81 | 335k | } |
82 | | |
83 | | private: |
84 | | // List of bind variables in the statement being parsed ordered by the ordinal position in the |
85 | | // statement. |
86 | | struct SetCmp { |
87 | | bool operator() (const PTBindVar* v1, const PTBindVar* v2) const; |
88 | | }; |
89 | | |
90 | | MCSet<PTBindVar*, SetCmp> bind_variables_; |
91 | | |
92 | | // Ordinal position for the next bind variable for the statement to be parsed. |
93 | | int64_t bind_pos_ = 0; |
94 | | |
95 | | //------------------------------------------------------------------------------------------------ |
96 | | // We don't use istream (i.e. file) as input when parsing. In the future, if we also support file |
97 | | // as an SQL input, we need to define a constructor that takes a file as input and initializes |
98 | | // "ql_file_" accordingly. |
99 | | std::unique_ptr<std::istream> ql_file_; |
100 | | |
101 | | //------------------------------------------------------------------------------------------------ |
102 | | // NOTE: All entities below this line in this modules are copies of PostgreQL's code. We made |
103 | | // some minor changes to avoid lint errors such as using '{' for if blocks, change the comment |
104 | | // style from '/**/' to '//', and post-fix data members with "_". |
105 | | //------------------------------------------------------------------------------------------------ |
106 | | size_t stmt_offset_; // SQL statement to be scanned. |
107 | | bool trace_scanning_; // Scanner trace flag. |
108 | | bool trace_parsing_; // Parser trace flag. |
109 | | }; |
110 | | |
111 | | } // namespace ql |
112 | | } // namespace yb |
113 | | |
114 | | #endif // YB_YQL_CQL_QL_PARSER_PARSE_CONTEXT_H_ |