/Users/deen/code/yugabyte-db/src/yb/bfql/bfql_template.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 | | // This module defines a few templates to be used in file "bfql.h". It defines the actual |
16 | | // implementation for compilation and execution of a builtin call. |
17 | | //-------------------------------------------------------------------------------------------------- |
18 | | |
19 | | #ifndef YB_BFQL_BFQL_TEMPLATE_H_ |
20 | | #define YB_BFQL_BFQL_TEMPLATE_H_ |
21 | | |
22 | | #include <fcntl.h> |
23 | | |
24 | | #include <functional> |
25 | | #include <vector> |
26 | | |
27 | | #include "yb/bfql/gen_opcodes.h" |
28 | | #include "yb/bfql/gen_operator.h" |
29 | | |
30 | | #include "yb/gutil/integral_types.h" |
31 | | #include "yb/gutil/macros.h" |
32 | | #include "yb/gutil/strings/substitute.h" |
33 | | |
34 | | #include "yb/util/fault_injection.h" |
35 | | #include "yb/util/logging.h" |
36 | | |
37 | | namespace yb { |
38 | | namespace bfql { |
39 | | |
40 | | //-------------------------------------------------------------------------------------------------- |
41 | | // Find the builtin opcode, declaration, and return type for a builtin call. |
42 | | // Inputs: Builtin function name and parameter types. |
43 | | // Outputs: opcode and bfdecl. |
44 | | // In/Out parameter: return_type |
45 | | // If return_type is given, check if it is compatible with the declaration. |
46 | | // If not, return_type is an output parameter whose value is the return type of the builtin. |
47 | | Status FindOpcodeByType(const string& ql_name, |
48 | | const std::vector<DataType>& actual_types, |
49 | | BFOpcode *opcode, |
50 | | const BFDecl **bfdecl, |
51 | | DataType *return_type); |
52 | | |
53 | | // The effect is the same as function "FindOpcodeByType()", but it takes arguments instead types. |
54 | | // NOTE: |
55 | | // RTypePtr can be either a raw (*) or shared (const shared_ptr&) pointer. |
56 | | // PTypePtrCollection can be any standard collection of PType raw or shared pointer. |
57 | | // std::vector<PTypePtr>, std::list<PTypePtr>, std::set<PTypePtr>, ... |
58 | | template<typename PTypePtrCollection, typename RTypePtr> |
59 | | Status FindOpcode(const string& ql_name, |
60 | | const PTypePtrCollection& params, |
61 | | BFOpcode *opcode, |
62 | | const BFDecl **bfdecl, |
63 | 1.15k | RTypePtr result) { |
64 | | |
65 | | // Read argument types. |
66 | 1.15k | std::vector<DataType> actual_types(params.size(), DataType::UNKNOWN_DATA); |
67 | 1.15k | int pindex = 0; |
68 | 1.59k | for (const auto& param : params) { |
69 | 1.59k | actual_types[pindex] = param->ql_type_id(); |
70 | 1.59k | pindex++; |
71 | 1.59k | } |
72 | | |
73 | | // Get the opcode and declaration. |
74 | 1.15k | if (result == nullptr) { |
75 | 0 | return FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, nullptr); |
76 | 0 | } |
77 | | |
78 | | // Get the opcode, declaration, and return type. |
79 | 1.15k | DataType return_type = result->ql_type_id(); |
80 | 1.15k | RETURN_NOT_OK(FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, &return_type)); |
81 | 1.02k | result->set_ql_type_id(return_type); |
82 | | |
83 | 1.02k | return Status::OK(); |
84 | 1.15k | } _ZN2yb4bfql10FindOpcodeINSt3__16vectorINS2_10shared_ptrINS0_11BFTestValueEEENS2_9allocatorIS6_EEEERKS6_EENS_6StatusERKNS2_12basic_stringIcNS2_11char_traitsIcEENS7_IcEEEERKT_PNS0_8BFOpcodeEPPKNS0_6BFDeclET0_ Line | Count | Source | 63 | 88 | RTypePtr result) { | 64 | | | 65 | | // Read argument types. | 66 | 88 | std::vector<DataType> actual_types(params.size(), DataType::UNKNOWN_DATA); | 67 | 88 | int pindex = 0; | 68 | 134 | for (const auto& param : params) { | 69 | 134 | actual_types[pindex] = param->ql_type_id(); | 70 | 134 | pindex++; | 71 | 134 | } | 72 | | | 73 | | // Get the opcode and declaration. | 74 | 88 | if (result == nullptr) { | 75 | 0 | return FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, nullptr); | 76 | 0 | } | 77 | | | 78 | | // Get the opcode, declaration, and return type. | 79 | 88 | DataType return_type = result->ql_type_id(); | 80 | 88 | RETURN_NOT_OK(FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, &return_type)); | 81 | 46 | result->set_ql_type_id(return_type); | 82 | | | 83 | 46 | return Status::OK(); | 84 | 88 | } |
_ZN2yb4bfql10FindOpcodeINSt3__16vectorIPNS0_11BFTestValueENS2_9allocatorIS5_EEEES5_EENS_6StatusERKNS2_12basic_stringIcNS2_11char_traitsIcEENS6_IcEEEERKT_PNS0_8BFOpcodeEPPKNS0_6BFDeclET0_ Line | Count | Source | 63 | 4 | RTypePtr result) { | 64 | | | 65 | | // Read argument types. | 66 | 4 | std::vector<DataType> actual_types(params.size(), DataType::UNKNOWN_DATA); | 67 | 4 | int pindex = 0; | 68 | 32 | for (const auto& param : params) { | 69 | 32 | actual_types[pindex] = param->ql_type_id(); | 70 | 32 | pindex++; | 71 | 32 | } | 72 | | | 73 | | // Get the opcode and declaration. | 74 | 4 | if (result == nullptr) { | 75 | 0 | return FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, nullptr); | 76 | 0 | } | 77 | | | 78 | | // Get the opcode, declaration, and return type. | 79 | 4 | DataType return_type = result->ql_type_id(); | 80 | 4 | RETURN_NOT_OK(FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, &return_type)); | 81 | 2 | result->set_ql_type_id(return_type); | 82 | | | 83 | 2 | return Status::OK(); | 84 | 4 | } |
_ZN2yb4bfql10FindOpcodeINSt3__16vectorINS2_10shared_ptrINS_2ql6PTExprEEENS2_9allocatorIS7_EEEERKS7_EENS_6StatusERKNS2_12basic_stringIcNS2_11char_traitsIcEENS8_IcEEEERKT_PNS0_8BFOpcodeEPPKNS0_6BFDeclET0_ Line | Count | Source | 63 | 1.06k | RTypePtr result) { | 64 | | | 65 | | // Read argument types. | 66 | 1.06k | std::vector<DataType> actual_types(params.size(), DataType::UNKNOWN_DATA); | 67 | 1.06k | int pindex = 0; | 68 | 1.42k | for (const auto& param : params) { | 69 | 1.42k | actual_types[pindex] = param->ql_type_id(); | 70 | 1.42k | pindex++; | 71 | 1.42k | } | 72 | | | 73 | | // Get the opcode and declaration. | 74 | 1.06k | if (result == nullptr) { | 75 | 0 | return FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, nullptr); | 76 | 0 | } | 77 | | | 78 | | // Get the opcode, declaration, and return type. | 79 | 1.06k | DataType return_type = result->ql_type_id(); | 80 | 1.06k | RETURN_NOT_OK(FindOpcodeByType(ql_name, actual_types, opcode, bfdecl, &return_type)); | 81 | 979 | result->set_ql_type_id(return_type); | 82 | | | 83 | 979 | return Status::OK(); | 84 | 1.06k | } |
|
85 | | } // namespace bfql |
86 | | } // namespace yb |
87 | | |
88 | | #endif // YB_BFQL_BFQL_TEMPLATE_H_ |