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

Method DoEvaluate

eval/eval/create_struct_step.cc:69–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67};
68
69absl::StatusOr<Value> CreateStructStepForStruct::DoEvaluate(
70 ExecutionFrame* frame) const {
71 int entries_size = entries_.size();
72
73 auto args = frame->value_stack().GetSpan(entries_size);
74
75 for (const auto& arg : args) {
76 if (arg.IsError()) {
77 return arg;
78 }
79 }
80
81 if (frame->enable_unknowns()) {
82 absl::optional<UnknownValue> unknown_set =
83 frame->attribute_utility().IdentifyAndMergeUnknowns(
84 args, frame->value_stack().GetAttributeSpan(entries_size),
85 /*use_partial=*/true);
86 if (unknown_set.has_value()) {
87 return *unknown_set;
88 }
89 }
90
91 CEL_ASSIGN_OR_RETURN(auto builder,
92 frame->type_provider().NewValueBuilder(
93 name_, frame->message_factory(), frame->arena()));
94 if (builder == nullptr) {
95 return ErrorValue(
96 absl::NotFoundError(absl::StrCat("Unable to find builder: ", name_)));
97 }
98
99 for (int i = 0; i < entries_size; ++i) {
100 const auto& entry = entries_[i];
101 const auto& arg = args[i];
102 if (optional_indices_.contains(static_cast<int32_t>(i))) {
103 if (auto optional_arg = arg.AsOptional(); optional_arg) {
104 if (!optional_arg->HasValue()) {
105 continue;
106 }
107 Value optional_arg_value;
108 optional_arg->Value(&optional_arg_value);
109 if (optional_arg_value.IsError()) {
110 // Error should never be in optional, but better safe than sorry.
111 return optional_arg_value;
112 }
113 CEL_ASSIGN_OR_RETURN(
114 absl::optional<ErrorValue> error_value,
115 builder->SetFieldByName(entry, std::move(optional_arg_value)));
116 if (error_value) {
117 return std::move(*error_value);
118 }
119 } else {
120 return cel::TypeConversionError(arg.DebugString(), "optional_type");
121 }
122 } else {
123 CEL_ASSIGN_OR_RETURN(absl::optional<ErrorValue> error_value,
124 builder->SetFieldByName(entry, arg));
125 if (error_value) {
126 return std::move(*error_value);

Callers

nothing calls this directly

Calls 15

ErrorValueFunction · 0.85
TypeConversionErrorFunction · 0.85
GetSpanMethod · 0.80
GetAttributeSpanMethod · 0.80
HasValueMethod · 0.80
CEL_ASSIGN_OR_RETURNFunction · 0.70
sizeMethod · 0.45
IsErrorMethod · 0.45
enable_unknownsMethod · 0.45
has_valueMethod · 0.45
AsOptionalMethod · 0.45

Tested by

no test coverage detected