/Users/deen/code/yugabyte-db/src/yb/yql/cql/ql/ptree/pt_create_type.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 | | // Tree node definitions for CREATE TYPE statement. |
16 | | //-------------------------------------------------------------------------------------------------- |
17 | | |
18 | | #ifndef YB_YQL_CQL_QL_PTREE_PT_CREATE_TYPE_H |
19 | | #define YB_YQL_CQL_QL_PTREE_PT_CREATE_TYPE_H |
20 | | |
21 | | #include "yb/yql/cql/ql/ptree/list_node.h" |
22 | | #include "yb/yql/cql/ql/ptree/tree_node.h" |
23 | | #include "yb/yql/cql/ql/ptree/pt_type.h" |
24 | | #include "yb/yql/cql/ql/ptree/pt_name.h" |
25 | | |
26 | | namespace yb { |
27 | | namespace ql { |
28 | | |
29 | | //-------------------------------------------------------------------------------------------------- |
30 | | // Field of User-Defined Type |
31 | | |
32 | | class PTTypeField : public TreeNode { |
33 | | public: |
34 | | //------------------------------------------------------------------------------------------------ |
35 | | // Public types. |
36 | | typedef MCSharedPtr<PTTypeField> SharedPtr; |
37 | | typedef MCSharedPtr<const PTTypeField> SharedPtrConst; |
38 | | |
39 | | //------------------------------------------------------------------------------------------------ |
40 | | // Constructor and destructor. |
41 | | PTTypeField(MemoryContext *memctx, |
42 | | YBLocationPtr loc, |
43 | | const MCSharedPtr<MCString>& name, |
44 | | const PTBaseType::SharedPtr& datatype); |
45 | | virtual ~PTTypeField(); |
46 | | |
47 | | // Node type. |
48 | 0 | virtual TreeNodeOpcode opcode() const override { |
49 | 0 | return TreeNodeOpcode::kPTTypeField; |
50 | 0 | } |
51 | | |
52 | | template<typename... TypeArgs> |
53 | | inline static PTTypeField::SharedPtr MakeShared(MemoryContext *memctx, |
54 | 133 | TypeArgs&&... args) { |
55 | 133 | return MCMakeShared<PTTypeField>(memctx, std::forward<TypeArgs>(args)...); |
56 | 133 | } |
57 | | |
58 | | // Node semantics analysis. |
59 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
60 | | |
61 | 89 | const char *yb_name() const { |
62 | 89 | return name_->c_str(); |
63 | 89 | } |
64 | | |
65 | 0 | const PTBaseType::SharedPtr& datatype() const { |
66 | 0 | return datatype_; |
67 | 0 | } |
68 | | |
69 | 89 | std::shared_ptr<QLType> ql_type() const { |
70 | 89 | return datatype_->ql_type(); |
71 | 89 | } |
72 | | |
73 | | private: |
74 | | const MCSharedPtr<MCString> name_; |
75 | | PTBaseType::SharedPtr datatype_; |
76 | | }; |
77 | | |
78 | | using PTTypeFieldListNode = TreeListNode<PTTypeField>; |
79 | | |
80 | | //-------------------------------------------------------------------------------------------------- |
81 | | // CREATE TABLE statement. |
82 | | |
83 | | class PTCreateType : public TreeNode { |
84 | | public: |
85 | | //------------------------------------------------------------------------------------------------ |
86 | | // Public types. |
87 | | typedef MCSharedPtr<PTCreateType> SharedPtr; |
88 | | typedef MCSharedPtr<const PTCreateType> SharedPtrConst; |
89 | | |
90 | | //------------------------------------------------------------------------------------------------ |
91 | | // Constructor and destructor. |
92 | | PTCreateType(MemoryContext *memctx, |
93 | | YBLocationPtr loc, |
94 | | const PTQualifiedName::SharedPtr& name, |
95 | | const PTTypeFieldListNode::SharedPtr& fields, |
96 | | bool create_if_not_exists); |
97 | | virtual ~PTCreateType(); |
98 | | |
99 | | // Node type. |
100 | 238 | virtual TreeNodeOpcode opcode() const override { |
101 | 238 | return TreeNodeOpcode::kPTCreateType; |
102 | 238 | } |
103 | | |
104 | | // Support for shared_ptr. |
105 | | template<typename... TypeArgs> |
106 | 85 | inline static PTCreateType::SharedPtr MakeShared(MemoryContext *memctx, TypeArgs&&... args) { |
107 | 85 | return MCMakeShared<PTCreateType>(memctx, std::forward<TypeArgs>(args)...); |
108 | 85 | } |
109 | | |
110 | | // Node semantics analysis. |
111 | | virtual CHECKED_STATUS Analyze(SemContext *sem_context) override; |
112 | | void PrintSemanticAnalysisResult(SemContext *sem_context); |
113 | | |
114 | | // column lists. |
115 | 47 | PTTypeFieldListNode::SharedPtr fields() const { |
116 | 47 | return fields_; |
117 | 47 | } |
118 | | |
119 | 1 | bool create_if_not_exists() const { |
120 | 1 | return create_if_not_exists_; |
121 | 1 | } |
122 | | |
123 | | // Type name. |
124 | 1 | PTQualifiedName::SharedPtr type_name() const { |
125 | 1 | return name_; |
126 | 1 | } |
127 | | |
128 | 83 | client::YBTableName yb_type_name() const { |
129 | 83 | return name_->ToTableName(); |
130 | 83 | } |
131 | | |
132 | | private: |
133 | | PTQualifiedName::SharedPtr name_; |
134 | | PTTypeFieldListNode::SharedPtr fields_; |
135 | | |
136 | | bool create_if_not_exists_; |
137 | | }; |
138 | | |
139 | | } // namespace ql |
140 | | } // namespace yb |
141 | | |
142 | | #endif // YB_YQL_CQL_QL_PTREE_PT_CREATE_TYPE_H |