MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / LookupInMap

Function LookupInMap

eval/eval/container_access_step.cc:92–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void LookupInMap(const MapValue& cel_map, const Value& key,
93 ExecutionFrameBase& frame, Value& result) {
94 if (frame.options().enable_heterogeneous_equality) {
95 // Double isn't a supported key type but may be convertible to an integer.
96 absl::optional<Number> number = CelNumberFromValue(key);
97 if (number.has_value()) {
98 // Consider uint as uint first then try coercion (prefer matching the
99 // original type of the key value).
100 if (key->Is<UintValue>()) {
101 auto lookup =
102 cel_map.Find(key, frame.descriptor_pool(), frame.message_factory(),
103 frame.arena(), &result);
104 if (!lookup.ok()) {
105 result = cel::ErrorValue(std::move(lookup).status());
106 return;
107 }
108 if (*lookup) {
109 ABSL_DCHECK(!result.IsUnknown());
110 return;
111 }
112 }
113 // double / int / uint -> int
114 if (number->LosslessConvertibleToInt()) {
115 auto lookup =
116 cel_map.Find(IntValue(number->AsInt()), frame.descriptor_pool(),
117 frame.message_factory(), frame.arena(), &result);
118 if (!lookup.ok()) {
119 result = cel::ErrorValue(std::move(lookup).status());
120 return;
121 }
122 if (*lookup) {
123 ABSL_DCHECK(!result.IsUnknown());
124 return;
125 }
126 }
127 // double / int -> uint
128 if (number->LosslessConvertibleToUint()) {
129 auto lookup =
130 cel_map.Find(UintValue(number->AsUint()), frame.descriptor_pool(),
131 frame.message_factory(), frame.arena(), &result);
132 if (!lookup.ok()) {
133 result = cel::ErrorValue(std::move(lookup).status());
134 return;
135 }
136 if (*lookup) {
137 ABSL_DCHECK(!result.IsUnknown());
138 return;
139 }
140 }
141 result = cel::ErrorValue(CreateNoSuchKeyError(key->DebugString()));
142 return;
143 }
144 }
145
146 absl::Status status = CheckMapKeyType(key);
147 if (!status.ok()) {
148 result = cel::ErrorValue(std::move(status));
149 return;

Callers 1

LookupInContainerFunction · 0.85

Calls 15

CelNumberFromValueFunction · 0.85
ErrorValueFunction · 0.85
CheckMapKeyTypeFunction · 0.85
IntValueClass · 0.50
UintValueClass · 0.50
CreateNoSuchKeyErrorFunction · 0.50
has_valueMethod · 0.45
FindMethod · 0.45
descriptor_poolMethod · 0.45
message_factoryMethod · 0.45

Tested by

no test coverage detected