YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/bfpg/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/bfpg/directory.h" for more general overall information.
22
//--------------------------------------------------------------------------------------------------
23
24
#ifndef YB_BFPG_BASE_OPERATOR_H
25
#define YB_BFPG_BASE_OPERATOR_H
26
27
#include <memory>
28
29
#include "yb/bfpg/bfdecl.h"
30
#include "yb/bfpg/gen_opcodes.h"
31
32
namespace yb {
33
namespace bfpg {
34
35
class BFOperator {
36
 public:
37
  typedef std::shared_ptr<BFOperator> SharedPtr;
38
  typedef std::shared_ptr<const BFOperator> SharedPtrConst;
39
40
295
  BFOpcode opcode() const {
41
295
    return opcode_;
42
295
  }
43
44
526
  BFOpcode overloaded_opcode() const {
45
526
    return overloaded_opcode_;
46
526
  }
47
48
26
  const BFDecl *op_decl() const {
49
26
    return op_decl_;
50
26
  }
51
52
282
  const std::vector<DataType>& param_types() const {
53
282
    return op_decl_->param_types();
54
282
  }
55
56
16
  const DataType& return_type() const {
57
16
    return op_decl_->return_type();
58
16
  }
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
1.68M
        op_decl_(op_decl) {
69
1.68M
  }
70
71
1.56M
  virtual ~BFOperator() {
72
1.56M
  }
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 bfpg
89
} // namespace yb
90
91
#endif  // YB_BFPG_BASE_OPERATOR_H