/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_property.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_YQL_CQL_QL_PTREE_PT_PROPERTY_H_ |
15 | | #define YB_YQL_CQL_QL_PTREE_PT_PROPERTY_H_ |
16 | | |
17 | | #include "yb/gutil/strings/substitute.h" |
18 | | #include "yb/yql/cql/ql/ptree/list_node.h" |
19 | | #include "yb/yql/cql/ql/ptree/tree_node.h" |
20 | | |
21 | | namespace yb { |
22 | | namespace ql { |
23 | | |
24 | 1.23k | #define RETURN_SEM_CONTEXT_ERROR_NOT_OK(s) do { \ |
25 | 1.12k | ::yb::Status _s = (s); \ |
26 | 1.12k | if (PREDICT_FALSE(!_s.ok())) { \ |
27 | 138 | auto err_str = s.ToUserMessage(); \ |
28 | 138 | return sem_context->Error(this, err_str.c_str(), \ |
29 | 138 | ErrorCode::INVALID_TABLE_PROPERTY); \ |
30 | 138 | } \ |
31 | 989 | } while (0) |
32 | | |
33 | | class PTProperty : public TreeNode { |
34 | | public: |
35 | | //------------------------------------------------------------------------------------------------ |
36 | | // Public types. |
37 | | typedef MCSharedPtr<PTProperty> SharedPtr; |
38 | | typedef MCSharedPtr<const PTProperty> SharedPtrConst; |
39 | | |
40 | | //------------------------------------------------------------------------------------------------ |
41 | | // Constructors and destructor. |
42 | | PTProperty(MemoryContext *memctx, |
43 | | YBLocationPtr loc, |
44 | | const MCSharedPtr<MCString>& lhs_, |
45 | | const PTExprPtr& rhs_); |
46 | | |
47 | | PTProperty(MemoryContext *memctx, |
48 | | YBLocationPtr loc); |
49 | | |
50 | | virtual ~PTProperty(); |
51 | | |
52 | | // Node type. |
53 | 0 | virtual TreeNodeOpcode opcode() const override { |
54 | 0 | return TreeNodeOpcode::kPTProperty; |
55 | 0 | } |
56 | | |
57 | | template<typename... TypeArgs> |
58 | | inline static PTProperty::SharedPtr MakeShared(MemoryContext *memctx, |
59 | | TypeArgs&&... args) { |
60 | | return MCMakeShared<PTProperty>(memctx, std::forward<TypeArgs>(args)...); |
61 | | } |
62 | | |
63 | | // Node semantics analysis. |
64 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override = 0; |
65 | | |
66 | 3.80k | MCSharedPtr<MCString> lhs() const { |
67 | 3.80k | return lhs_; |
68 | 3.80k | } |
69 | | |
70 | 2.24k | PTExprPtr rhs() const { |
71 | 2.24k | return rhs_; |
72 | 2.24k | } |
73 | | |
74 | | static CHECKED_STATUS GetIntValueFromExpr(PTExprPtr expr, |
75 | | const string& property_name, |
76 | | int64_t *val); |
77 | | |
78 | | static CHECKED_STATUS GetDoubleValueFromExpr(PTExprPtr expr, |
79 | | const string& property_name, |
80 | | long double *val); |
81 | | |
82 | | static CHECKED_STATUS GetBoolValueFromExpr(PTExprPtr expr, |
83 | | const string& property_name, |
84 | | bool *val); |
85 | | |
86 | | static CHECKED_STATUS GetStringValueFromExpr(PTExprPtr expr, |
87 | | bool to_lower_case, |
88 | | const string& property_name, |
89 | | string *val); |
90 | | |
91 | | protected: |
92 | | // Parts of an expression 'lhs_ = rhs_' where lhs stands for left-hand side, and rhs for |
93 | | // right-hand side. |
94 | | MCSharedPtr<MCString> lhs_; |
95 | | PTExprPtr rhs_; |
96 | | }; |
97 | | |
98 | | class PTPropertyListNode : public TreeListNode<PTProperty> { |
99 | | public: |
100 | | //------------------------------------------------------------------------------------------------ |
101 | | // Public types. |
102 | | typedef MCSharedPtr<PTPropertyListNode> SharedPtr; |
103 | | typedef MCSharedPtr<const PTPropertyListNode> SharedPtrConst; |
104 | | |
105 | | explicit PTPropertyListNode(MemoryContext *memory_context, |
106 | | YBLocationPtr loc, |
107 | | const MCSharedPtr<PTProperty>& tnode = nullptr) |
108 | 0 | : TreeListNode<PTProperty>(memory_context, loc, tnode) { |
109 | 0 | } |
110 | | |
111 | 0 | virtual ~PTPropertyListNode() { |
112 | 0 | } |
113 | | |
114 | | // Append a PTPropertyList to this list. |
115 | 0 | void AppendList(const MCSharedPtr<PTPropertyListNode>& tnode_list) { |
116 | 0 | if (tnode_list == nullptr) { |
117 | 0 | return; |
118 | 0 | } |
119 | 0 | for (const auto& tnode : tnode_list->node_list()) { |
120 | 0 | Append(tnode); |
121 | 0 | } |
122 | 0 | } |
123 | | |
124 | | template<typename... TypeArgs> |
125 | | inline static PTPropertyListNode::SharedPtr MakeShared(MemoryContext *memctx, |
126 | | TypeArgs&&...args) { |
127 | | return MCMakeShared<PTPropertyListNode>(memctx, std::forward<TypeArgs>(args)...); |
128 | | } |
129 | | |
130 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
131 | | }; |
132 | | |
133 | | } // namespace ql |
134 | | } // namespace yb |
135 | | |
136 | | #endif // YB_YQL_CQL_QL_PTREE_PT_PROPERTY_H_ |