/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/tree_node.h
Line | Count | Source (jump to first uncovered line) |
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 | | // Parse Tree Declaration. |
16 | | // |
17 | | // This modules includes declarations of the base class for tree nodes. Parser whose rules are |
18 | | // defined in parser_gram.y will create these nodes and link them together to form parse tree. |
19 | | //-------------------------------------------------------------------------------------------------- |
20 | | |
21 | | #ifndef YB_YQL_CQL_QL_PTREE_TREE_NODE_H_ |
22 | | #define YB_YQL_CQL_QL_PTREE_TREE_NODE_H_ |
23 | | |
24 | | #include "yb/util/enums.h" |
25 | | |
26 | | #include "yb/util/memory/mc_types.h" |
27 | | |
28 | | #include "yb/yql/cql/ql/ptree/ptree_fwd.h" |
29 | | |
30 | | #include "yb/util/status_fwd.h" |
31 | | |
32 | | namespace yb { |
33 | | namespace ql { |
34 | | |
35 | | class SemContext; |
36 | | |
37 | | YB_DEFINE_ENUM(TreeNodeOpcode, |
38 | | (kNoOp) |
39 | | (kPTListNode) |
40 | | (kPTCreateKeyspace) |
41 | | (kPTUseKeyspace) |
42 | | (kPTAlterKeyspace) |
43 | | (kPTCreateTable) |
44 | | (kPTAlterTable) |
45 | | (kPTTypeField) |
46 | | (kPTCreateType) |
47 | | (kPTCreateIndex) |
48 | | (kPTTruncateStmt) |
49 | | (kPTDropStmt) |
50 | | (kPTSelectStmt) |
51 | | (kPTInsertStmt) |
52 | | (kPTDeleteStmt) |
53 | | (kPTUpdateStmt) |
54 | | (kPTCreateRole) |
55 | | (kPTAlterRole) |
56 | | (kPTGrantRevokePermission) |
57 | | (kPTGrantRevokeRole) |
58 | | (kPTStartTransaction) |
59 | | (kPTCommit) |
60 | | (kPTName) |
61 | | (kPTProperty) |
62 | | (kPTStatic) |
63 | | (kPTConstraint) |
64 | | (kPTCollection) |
65 | | (kPTPrimitiveType) |
66 | | (kPTColumnDefinition) |
67 | | (kPTAlterColumnDefinition) |
68 | | (kPTDmlUsingClauseElement) |
69 | | (kPTTableRef) |
70 | | (kPTOrderBy) |
71 | | (kPTRoleOption) |
72 | | (kPTExplainStmt) |
73 | | (kPTInsertValuesClause) |
74 | | (kPTInsertJsonClause) |
75 | | |
76 | | // Expressions. |
77 | | (kPTExpr) |
78 | | (kPTRef) |
79 | | (kPTSubscript) |
80 | | (kPTAllColumns) |
81 | | (kPTAssign) |
82 | | (kPTBindVar) |
83 | | (kPTJsonOp)); |
84 | | |
85 | | // TreeNode base class. |
86 | | class TreeNode : public MCBase { |
87 | | public: |
88 | | //------------------------------------------------------------------------------------------------ |
89 | | // Public types. |
90 | | typedef MCSharedPtr<TreeNode> SharedPtr; |
91 | | typedef MCSharedPtr<const TreeNode> SharedPtrConst; |
92 | | |
93 | | //------------------------------------------------------------------------------------------------ |
94 | | // Public functions. |
95 | | explicit TreeNode(MemoryContext *memctx = nullptr, YBLocationPtr loc = nullptr); |
96 | | virtual ~TreeNode(); |
97 | | |
98 | | // Node type. |
99 | | virtual TreeNodeOpcode opcode() const = 0; |
100 | | |
101 | | // shared_ptr support. |
102 | | template<typename... TypeArgs> |
103 | | inline static TreeNode::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) { |
104 | | return MCMakeShared<TreeNode>(memctx, std::forward<TypeArgs>(args)...); |
105 | | } |
106 | | |
107 | | // Run semantics analysis on this node. |
108 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context); |
109 | | |
110 | | // Is this a DML statement? |
111 | 238k | virtual bool IsDml() const { |
112 | 238k | return false; |
113 | 238k | } |
114 | | |
115 | | // Is this treenode a top level node that is used to query data from tablet server? |
116 | 230 | virtual bool IsTopLevelReadNode() const { |
117 | 230 | return false; |
118 | 230 | } |
119 | | |
120 | | // Access functions to this node location. |
121 | 83.3k | const YBLocation& loc() const { |
122 | 83.3k | return *loc_; |
123 | 83.3k | } |
124 | 0 | void set_loc(const TreeNode& other) { |
125 | 0 | loc_ = other.loc_; |
126 | 0 | } |
127 | 4.62k | const YBLocationPtr& loc_ptr() const { |
128 | 4.62k | return loc_; |
129 | 4.62k | } |
130 | | |
131 | 1.41k | void set_internal() { |
132 | 1.41k | internal_ = true; |
133 | 1.41k | } |
134 | | |
135 | | protected: |
136 | | YBLocationPtr loc_; |
137 | | |
138 | | bool internal_ = false; |
139 | | }; |
140 | | |
141 | | } // namespace ql |
142 | | } // namespace yb |
143 | | |
144 | | #endif // YB_YQL_CQL_QL_PTREE_TREE_NODE_H_ |