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

Function MakeStackMachinePath

eval/eval/create_struct_step_test.cc:73–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71using ::testing::Pointwise;
72
73absl::StatusOr<ExecutionPath> MakeStackMachinePath(absl::string_view field) {
74 ExecutionPath path;
75
76 CEL_ASSIGN_OR_RETURN(auto step0, CreateIdentStep("message", /*expr_id=*/-1));
77
78 auto step1 = CreateCreateStructStep("google.api.expr.runtime.TestMessage",
79 {std::string(field)},
80 /*optional_indices=*/{},
81
82 /*id=*/-1);
83
84 path.push_back(std::move(step0));
85 path.push_back(std::move(step1));
86
87 return path;
88}
89
90absl::StatusOr<ExecutionPath> MakeRecursivePath(absl::string_view field) {
91 ExecutionPath path;
92
93 std::vector<std::unique_ptr<DirectExpressionStep>> deps;
94 deps.push_back(CreateDirectIdentStep("message", -1));
95
96 auto step1 =
97 CreateDirectCreateStructStep("google.api.expr.runtime.TestMessage",
98 {std::string(field)}, std::move(deps),
99 /*optional_indices=*/{},
100
101 /*id=*/-1);
102
103 path.push_back(std::make_unique<WrappedDirectStep>(std::move(step1), -1));
104
105 return path;
106}
107
108// Helper method. Creates simple pipeline containing CreateStruct step that
109// builds message and runs it.
110absl::StatusOr<CelValue> RunExpression(
111 const absl_nonnull std::shared_ptr<const RuntimeEnv>& env,
112 absl::string_view field, const CelValue& value, google::protobuf::Arena* arena,
113 bool enable_unknowns, bool enable_recursive_planning) {
114 google::protobuf::LinkMessageReflection<google::api::expr::runtime::TestMessage>();
115 CEL_ASSIGN_OR_RETURN(auto maybe_type,
116 env->type_registry.GetComposedTypeProvider().FindType(
117 "google.api.expr.runtime.TestMessage"));
118 if (!maybe_type.has_value()) {
119 return absl::Status(absl::StatusCode::kFailedPrecondition,
120 "missing proto message type");
121 }
122
123 cel::RuntimeOptions options;
124 if (enable_unknowns) {
125 options.unknown_processing = cel::UnknownProcessingOptions::kAttributeOnly;
126 }
127 ExecutionPath path;
128
129 if (enable_recursive_planning) {
130 CEL_ASSIGN_OR_RETURN(path, MakeRecursivePath(field));

Callers

nothing calls this directly

Calls 4

FlatExpressionClass · 0.85
InsertValueMethod · 0.80
CEL_ASSIGN_OR_RETURNFunction · 0.70
EvaluateMethod · 0.45

Tested by

no test coverage detected