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

Method DoEvaluate

eval/eval/create_map_step.cc:70–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68};
69
70absl::StatusOr<Value> CreateStructStepForMap::DoEvaluate(
71 ExecutionFrame* frame) const {
72 auto args = frame->value_stack().GetSpan(2 * entry_count_);
73
74 for (const auto& arg : args) {
75 if (arg.IsError()) {
76 return arg;
77 }
78 }
79
80 if (frame->enable_unknowns()) {
81 absl::optional<UnknownValue> unknown_set =
82 frame->attribute_utility().IdentifyAndMergeUnknowns(
83 args, frame->value_stack().GetAttributeSpan(args.size()), true);
84 if (unknown_set.has_value()) {
85 return *unknown_set;
86 }
87 }
88
89 MapValueBuilderPtr builder = NewMapValueBuilder(frame->arena());
90 builder->Reserve(entry_count_);
91
92 for (size_t i = 0; i < entry_count_; i += 1) {
93 const auto& map_key = args[2 * i];
94 CEL_RETURN_IF_ERROR(cel::CheckMapKey(map_key)).With(ErrorValueReturn());
95 const auto& map_value = args[(2 * i) + 1];
96 if (optional_indices_.contains(static_cast<int32_t>(i))) {
97 if (auto optional_map_value = map_value.AsOptional();
98 optional_map_value) {
99 if (!optional_map_value->HasValue()) {
100 continue;
101 }
102 Value optional_map_value_value;
103 optional_map_value->Value(&optional_map_value_value);
104 if (optional_map_value_value.IsError()) {
105 // Error should never be in optional, but better safe than sorry.
106 return optional_map_value_value;
107 }
108 CEL_RETURN_IF_ERROR(
109 builder->Put(map_key, std::move(optional_map_value_value)));
110 } else {
111 return cel::TypeConversionError(map_value.DebugString(),
112 "optional_type");
113 }
114 } else {
115 CEL_RETURN_IF_ERROR(builder->Put(map_key, map_value));
116 }
117 }
118
119 return std::move(*builder).Build();
120}
121
122absl::Status CreateStructStepForMap::Evaluate(ExecutionFrame* frame) const {
123 if (frame->value_stack().size() < 2 * entry_count_) {

Callers

nothing calls this directly

Calls 15

CheckMapKeyFunction · 0.85
ErrorValueReturnClass · 0.85
TypeConversionErrorFunction · 0.85
GetSpanMethod · 0.80
GetAttributeSpanMethod · 0.80
WithMethod · 0.80
HasValueMethod · 0.80
IsErrorMethod · 0.45
enable_unknownsMethod · 0.45
sizeMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected