/Users/deen/code/yugabyte-db/src/yb/bfql/base_operator.h
Line | Count | Source |
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 the interface BFOperator, which is a wrapper around C++ function pointers. |
16 | | // |
17 | | // For each builtin function, one operator is generated and used to compile and execute its call. |
18 | | // - During compilation, the signature BFDecl is used to type checking. |
19 | | // - During execution, the Exec function is used. |
20 | | // |
21 | | // See the header of file "/util/bfql/directory.h" for more general overall information. |
22 | | //-------------------------------------------------------------------------------------------------- |
23 | | |
24 | | #ifndef YB_BFQL_BASE_OPERATOR_H_ |
25 | | #define YB_BFQL_BASE_OPERATOR_H_ |
26 | | |
27 | | #include <memory> |
28 | | |
29 | | #include "yb/bfql/bfdecl.h" |
30 | | #include "yb/bfql/gen_opcodes.h" |
31 | | |
32 | | namespace yb { |
33 | | namespace bfql { |
34 | | |
35 | | class BFOperator { |
36 | | public: |
37 | | typedef std::shared_ptr<BFOperator> SharedPtr; |
38 | | typedef std::shared_ptr<const BFOperator> SharedPtrConst; |
39 | | |
40 | 8.43k | BFOpcode opcode() const { |
41 | 8.43k | return opcode_; |
42 | 8.43k | } |
43 | | |
44 | 13.0k | BFOpcode overloaded_opcode() const { |
45 | 13.0k | return overloaded_opcode_; |
46 | 13.0k | } |
47 | | |
48 | 2.19k | const BFDecl *op_decl() const { |
49 | 2.19k | return op_decl_; |
50 | 2.19k | } |
51 | | |
52 | 7.33k | const std::vector<DataType>& param_types() const { |
53 | 7.33k | return op_decl_->param_types(); |
54 | 7.33k | } |
55 | | |
56 | 1.13k | const DataType& return_type() const { |
57 | 1.13k | return op_decl_->return_type(); |
58 | 1.13k | } |
59 | | |
60 | | protected: |
61 | | // BFOperators are constructed only for the operator table, and this construction can be called |
62 | | // only by its subclasses. |
63 | | BFOperator(BFOpcode opcode, |
64 | | BFOpcode overloaded_opcode, |
65 | | const BFDecl *op_decl) |
66 | | : opcode_(opcode), |
67 | | overloaded_opcode_(overloaded_opcode), |
68 | 2.72M | op_decl_(op_decl) { |
69 | 2.72M | } |
70 | | |
71 | 1.80M | virtual ~BFOperator() { |
72 | 1.80M | } |
73 | | |
74 | | // The opcode of this operator, and the original opcode that this operator is overloading. |
75 | | // Suppose Xyz() function is overloaded into 4 different versions, we'd have 4 different opcodes. |
76 | | // The overloaded_opcode value will help creating a chain to link all overloading functions. |
77 | | // opcode_ = OP_XYZ_1 , overloaded_opcode_ = OP_XYZ_1 |
78 | | // opcode_ = OP_XYZ_2 , overloaded_opcode_ = OP_XYZ_1 |
79 | | // opcode_ = OP_XYZ_3 , overloaded_opcode_ = OP_XYZ_2 |
80 | | // opcode_ = OP_XYZ_4 , overloaded_opcode_ = OP_XYZ_3 |
81 | | BFOpcode opcode_; |
82 | | BFOpcode overloaded_opcode_; |
83 | | |
84 | | // Operator declaration, an entry in buitin function directory. |
85 | | const BFDecl *op_decl_; |
86 | | }; |
87 | | |
88 | | } // namespace bfql |
89 | | } // namespace yb |
90 | | |
91 | | #endif // YB_BFQL_BASE_OPERATOR_H_ |