forked from cel-expr/cel-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_list_step.cc
More file actions
76 lines (59 loc) · 2.1 KB
/
Copy pathcreate_list_step.cc
File metadata and controls
76 lines (59 loc) · 2.1 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
#include "eval/eval/create_list_step.h"
#include "absl/status/statusor.h"
#include "eval/public/containers/container_backed_list_impl.h"
namespace google {
namespace api {
namespace expr {
namespace runtime {
namespace {
class CreateListStep : public ExpressionStepBase {
public:
CreateListStep(int64_t expr_id, int list_size)
: ExpressionStepBase(expr_id), list_size_(list_size) {}
absl::Status Evaluate(ExecutionFrame* frame) const override;
private:
int list_size_;
};
absl::Status CreateListStep::Evaluate(ExecutionFrame* frame) const {
if (list_size_ < 0) {
return absl::Status(absl::StatusCode::kInternal,
"CreateListStep: list size is <0");
}
if (!frame->value_stack().HasEnough(list_size_)) {
return absl::Status(absl::StatusCode::kInternal,
"CreateListStep: stack underflow");
}
auto args = frame->value_stack().GetSpan(list_size_);
CelValue result;
const UnknownSet* unknown_set = nullptr;
if (frame->enable_unknowns()) {
unknown_set = frame->attribute_utility().MergeUnknowns(
args, frame->value_stack().GetAttributeSpan(list_size_),
/*initial_set=*/nullptr,
/*use_partial=*/true);
if (unknown_set != nullptr) {
result = CelValue::CreateUnknownSet(unknown_set);
}
}
if (unknown_set == nullptr) {
CelList* cel_list = google::protobuf::Arena::Create<ContainerBackedListImpl>(
frame->arena(), std::vector<CelValue>(args.begin(), args.end()));
result = CelValue::CreateList(cel_list);
}
frame->value_stack().Pop(list_size_);
frame->value_stack().Push(result);
return absl::OkStatus();
}
} // namespace
// Factory method for CreateList - based Execution step
absl::StatusOr<std::unique_ptr<ExpressionStep>> CreateCreateListStep(
const google::api::expr::v1alpha1::Expr::CreateList* create_list_expr,
int64_t expr_id) {
std::unique_ptr<ExpressionStep> step = absl::make_unique<CreateListStep>(
expr_id, create_list_expr->elements_size());
return std::move(step);
}
} // namespace runtime
} // namespace expr
} // namespace api
} // namespace google