forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunknown_function_result_set.cc
More file actions
99 lines (82 loc) · 2.54 KB
/
Copy pathunknown_function_result_set.cc
File metadata and controls
99 lines (82 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "eval/public/unknown_function_result_set.h"
#include <type_traits>
#include "absl/container/btree_set.h"
#include "eval/public/cel_function.h"
#include "eval/public/cel_options.h"
#include "eval/public/cel_value.h"
#include "eval/public/set_util.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
namespace {
// Tests that lhs descriptor is less than (name, receiver call style,
// arg types).
// Argument type Any is not treated specially. For example:
// {"f", false, {kAny}} > {"f", false, {kInt64}}
bool DescriptorLessThan(const CelFunctionDescriptor& lhs,
const CelFunctionDescriptor& rhs) {
if (lhs.name() < rhs.name()) {
return true;
}
if (lhs.name() > rhs.name()) {
return false;
}
if (lhs.receiver_style() < rhs.receiver_style()) {
return true;
}
if (lhs.receiver_style() > rhs.receiver_style()) {
return false;
}
if (lhs.types() >= rhs.types()) {
return false;
}
return true;
}
bool UnknownFunctionResultLessThan(const UnknownFunctionResult& lhs,
const UnknownFunctionResult& rhs) {
if (DescriptorLessThan(lhs.descriptor(), rhs.descriptor())) {
return true;
}
if (DescriptorLessThan(rhs.descriptor(), lhs.descriptor())) {
return false;
}
if (lhs.arguments().size() < rhs.arguments().size()) {
return true;
}
if (lhs.arguments().size() > rhs.arguments().size()) {
return false;
}
for (size_t i = 0; i < lhs.arguments().size(); i++) {
if (CelValueLessThan(lhs.arguments()[i], rhs.arguments()[i])) {
return true;
}
if (CelValueLessThan(rhs.arguments()[i], lhs.arguments()[i])) {
return false;
}
}
// equal
return false;
}
} // namespace
bool UnknownFunctionComparator::operator()(
const UnknownFunctionResult* lhs, const UnknownFunctionResult* rhs) const {
return UnknownFunctionResultLessThan(*lhs, *rhs);
}
bool UnknownFunctionResult::IsEqualTo(
const UnknownFunctionResult& other) const {
return !(UnknownFunctionResultLessThan(*this, other) ||
UnknownFunctionResultLessThan(other, *this));
}
// Implementation for merge constructor.
UnknownFunctionResultSet::UnknownFunctionResultSet(
const UnknownFunctionResultSet& lhs, const UnknownFunctionResultSet& rhs)
: unknown_function_results_(lhs.unknown_function_results()) {
for (const UnknownFunctionResult* call : rhs.unknown_function_results()) {
unknown_function_results_.insert(call);
}
}
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google