CUBRID Engine  latest
func_type.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * func_type.hpp
21  */
22 
23 #ifndef _FUNC_TYPE_HPP_
24 #define _FUNC_TYPE_HPP_
25 
26 #include "parse_type.hpp"
27 #include "string_buffer.hpp"
28 #include <vector>
29 
30 struct parser_context;
31 struct parser_node;
32 
33 using pt_group_arg_type = std::vector<pt_arg_type>;
35 {
36  pt_arg_type ret; //return type
37  pt_group_arg_type fix; //fixed arguments types
38  pt_group_arg_type rep; //repetitive arguments types
39 
40  void to_string_buffer (string_buffer &sb) const;
41 };
42 using func_all_signatures = std::vector<func_signature>;
43 
44 namespace func_type
45 {
46  // helpers
47  enum class type_compatibility
48  {
49  EQUIVALENT,
50  COERCIBLE,
52  };
53 
55  {
59 
61  };
62 
64  {
66  std::vector<argument_resolve> m_args_resolve;
69 
71 
73  };
74 
75  bool cmp_types_equivalent (const pt_arg_type &type, pt_type_enum type_enum);
76  bool cmp_types_castable (const pt_arg_type &type, pt_type_enum type_enum);
77 
79  bool can_signature_have_collation (const pt_arg_type &arg_sig);
80  bool sig_has_json_args (const func_signature &sig);
81 
82  class Node
83  {
84  private:
88 
89  public:
91  : m_parser (parser)
92  , m_node (node)
93  {
94  }
95 
96  parser_node *get_arg (size_t index);
97 
98  PT_NODE *type_checking ();
99 
100  protected:
101  bool preprocess(); //preprocess current function node type for special cases
102  const func_signature *get_signature (const func_all_signatures &signatures);
103  void set_return_type (const func_signature &signature); //set return type for current node in current context
104  bool apply_signature (const func_signature &signature); //apply function signature with casts if necessary
105 
106  parser_node *apply_argument (parser_node *prev, parser_node *arg, const argument_resolve &arg_res);
107 
108  const char *get_types (const func_all_signatures &signatures, size_t index, string_buffer &sb);
109  bool check_arg_compat (const pt_arg_type &arg_signature, const PT_NODE *arg_node,
110  signature_compatibility &compat, argument_resolve &resolved_type, bool args_to_utf8);
111  void invalid_arg_error (const pt_arg_type &arg_sgn, const PT_NODE *arg_node, const func_signature &func_sgn);
112  void invalid_coll_error (const func_signature &func_sgn);
113  void invalid_arg_count_error (std::size_t arg_count, const func_signature &func_sgn);
114  }; //class Node
115 } //namespace func_type
116 
117 bool pt_are_equivalent_types (const PT_ARG_TYPE def_type, const PT_TYPE_ENUM op_type);
118 PT_TYPE_ENUM pt_get_equivalent_type (const PT_ARG_TYPE def_type, const PT_TYPE_ENUM arg_type);
119 
120 #endif
parser_context * m_parser
Definition: func_type.hpp:85
bool can_signature_have_collation(const pt_arg_type &arg_sig)
Definition: func_type.cpp:625
bool cmp_types_equivalent(const pt_arg_type &type, pt_type_enum type_enum)
Definition: func_type.cpp:651
std::vector< func_signature > func_all_signatures
Definition: func_type.hpp:42
enum pt_type_enum PT_TYPE_ENUM
Definition: parse_tree.h:962
bool cmp_types_castable(const pt_arg_type &type, pt_type_enum type_enum)
Definition: func_type.cpp:658
pt_coll_infer m_coll_infer
Definition: func_type.hpp:58
bool pt_are_equivalent_types(const PT_ARG_TYPE def_type, const PT_TYPE_ENUM op_type)
Definition: func_type.cpp:1359
signature_compatibility m_best_signature
Definition: func_type.hpp:87
std::vector< argument_resolve > m_args_resolve
Definition: func_type.hpp:66
TP_DOMAIN_COLL_ACTION
Definition: object_domain.h:62
pt_group_arg_type rep
Definition: func_type.hpp:38
parser_node * m_node
Definition: func_type.hpp:86
void to_string_buffer(string_buffer &sb) const
Definition: func_type.cpp:537
SP_PARSER_CTX * parser
TP_DOMAIN_COLL_ACTION m_collation_action
Definition: func_type.hpp:68
pt_arg_type ret
Definition: func_type.hpp:36
pt_group_arg_type fix
Definition: func_type.hpp:37
PT_TYPE_ENUM pt_get_equivalent_type(const PT_ARG_TYPE def_type, const PT_TYPE_ENUM arg_type)
Definition: func_type.cpp:1482
std::vector< pt_arg_type > pt_group_arg_type
Definition: func_type.hpp:33
const func_signature * m_signature
Definition: func_type.hpp:70
Node(parser_context *parser, parser_node *node)
Definition: func_type.hpp:90
pt_type_enum
Definition: parse_tree.h:907
bool is_type_with_collation(PT_TYPE_ENUM type)
Definition: func_type.cpp:619
type_compatibility
Definition: func_type.hpp:47
bool sig_has_json_args(const func_signature &sig)
Definition: func_type.cpp:599