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

Method Evaluate

eval/eval/evaluator_core.cc:106–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104} // namespace
105
106absl::StatusOr<cel::Value> ExecutionFrame::Evaluate(
107 EvaluationListener& listener) {
108 const size_t initial_stack_size = value_stack().size();
109
110 if (!listener) {
111 for (const ExpressionStep* expr = Next();
112 ABSL_PREDICT_TRUE(expr != nullptr); expr = Next()) {
113 if (EvaluationStatus status(expr->Evaluate(this)); !status.ok()) {
114 return std::move(status).Consume();
115 }
116 }
117 } else {
118 for (const ExpressionStep* expr = Next();
119 ABSL_PREDICT_TRUE(expr != nullptr); expr = Next()) {
120 if (EvaluationStatus status(expr->Evaluate(this)); !status.ok()) {
121 return std::move(status).Consume();
122 }
123
124 if (pc_ == 0 || !expr->comes_from_ast()) {
125 // Skip if we just started a Call or if the step doesn't map to an
126 // AST id.
127 continue;
128 }
129
130 if (ABSL_PREDICT_FALSE(value_stack().empty())) {
131 ABSL_LOG(ERROR) << "Stack is empty after a ExpressionStep.Evaluate. "
132 "Try to disable short-circuiting.";
133 continue;
134 }
135 if (EvaluationStatus status(listener(expr->id(), value_stack().Peek(),
136 descriptor_pool(), message_factory(),
137 arena()));
138 !status.ok()) {
139 return std::move(status).Consume();
140 }
141 }
142 }
143
144 const size_t final_stack_size = value_stack().size();
145 if (ABSL_PREDICT_FALSE(final_stack_size != initial_stack_size + 1 ||
146 final_stack_size == 0)) {
147 return absl::InternalError(absl::StrCat(
148 "Stack error during evaluation: expected=", initial_stack_size + 1,
149 ", actual=", final_stack_size));
150 }
151
152 cel::Value value = std::move(value_stack().Peek());
153 value_stack().Pop(1);
154 return value;
155}
156
157FlatExpressionEvaluatorState FlatExpression::MakeEvaluatorState(
158 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,

Callers 1

EvaluateWithCallbackMethod · 0.45

Calls 8

sizeMethod · 0.45
okMethod · 0.45
ConsumeMethod · 0.45
comes_from_astMethod · 0.45
emptyMethod · 0.45
idMethod · 0.45
PeekMethod · 0.45
PopMethod · 0.45

Tested by

no test coverage detected