Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/function_descriptor.cc
Line
Count
Source
1
// Copyright 2023 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "common/function_descriptor.h"
16
17
#include <algorithm>
18
#include <cstddef>
19
20
#include "absl/base/macros.h"
21
#include "absl/types/span.h"
22
#include "common/kind.h"
23
24
namespace cel {
25
26
bool FunctionDescriptor::ShapeMatches(bool receiver_style,
27
8.40M
                                      absl::Span<const Kind> types) const {
28
8.40M
  if (this->receiver_style() != receiver_style) {
29
290k
    return false;
30
290k
  }
31
32
8.11M
  if (this->types().size() != types.size()) {
33
203k
    return false;
34
203k
  }
35
36
8.68M
  for (size_t i = 0; i < this->types().size(); i++) {
37
8.68M
    Kind this_type = this->types()[i];
38
8.68M
    Kind other_type = types[i];
39
8.68M
    if (this_type != Kind::kAny && other_type != Kind::kAny &&
40
8.46M
        this_type != other_type) {
41
7.91M
      return false;
42
7.91M
    }
43
8.68M
  }
44
0
  return true;
45
7.91M
}
46
47
0
bool FunctionDescriptor::operator==(const FunctionDescriptor& other) const {
48
0
  return impl_.get() == other.impl_.get() ||
49
0
         (name() == other.name() &&
50
0
          receiver_style() == other.receiver_style() &&
51
0
          types().size() == other.types().size() &&
52
0
          std::equal(types().begin(), types().end(), other.types().begin()));
53
0
}
54
55
0
bool FunctionDescriptor::operator<(const FunctionDescriptor& other) const {
56
0
  if (impl_.get() == other.impl_.get()) {
57
0
    return false;
58
0
  }
59
0
  if (name() < other.name()) {
60
0
    return true;
61
0
  }
62
0
  if (name() != other.name()) {
63
0
    return false;
64
0
  }
65
0
  if (receiver_style() < other.receiver_style()) {
66
0
    return true;
67
0
  }
68
0
  if (receiver_style() != other.receiver_style()) {
69
0
    return false;
70
0
  }
71
0
  auto lhs_begin = types().begin();
72
0
  auto lhs_end = types().end();
73
0
  auto rhs_begin = other.types().begin();
74
0
  auto rhs_end = other.types().end();
75
0
  while (lhs_begin != lhs_end && rhs_begin != rhs_end) {
76
0
    if (*lhs_begin < *rhs_begin) {
77
0
      return true;
78
0
    }
79
0
    if (!(*lhs_begin == *rhs_begin)) {
80
0
      return false;
81
0
    }
82
0
    lhs_begin++;
83
0
    rhs_begin++;
84
0
  }
85
0
  if (lhs_begin == lhs_end && rhs_begin == rhs_end) {
86
    // Neither has any elements left, they are equal.
87
0
    return false;
88
0
  }
89
0
  if (lhs_begin == lhs_end) {
90
    // Left has no more elements. Right is greater.
91
0
    return true;
92
0
  }
93
  // Right has no more elements. Left is greater.
94
0
  ABSL_ASSERT(rhs_begin == rhs_end);
95
0
  return false;
96
0
}
97
98
}  // namespace cel