Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/eval/eval/jump_step.h
Line
Count
Source
1
// Copyright 2017 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#ifndef THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_
16
#define THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_
17
18
#include <cstdint>
19
#include <memory>
20
21
#include "cel/expr/syntax.pb.h"
22
#include "absl/status/status.h"
23
#include "absl/types/optional.h"
24
#include "eval/eval/evaluator_core.h"
25
#include "eval/eval/expression_step_base.h"
26
27
namespace google::api::expr::runtime {
28
29
class JumpStepBase : public ExpressionStepBase {
30
 public:
31
  JumpStepBase(absl::optional<int> jump_offset, int64_t expr_id)
32
12.7k
      : ExpressionStepBase(expr_id, false), jump_offset_(jump_offset) {}
33
34
12.4k
  void set_jump_offset(int offset) { jump_offset_ = offset; }
35
36
526
  absl::Status Jump(ExecutionFrame* frame) const {
37
526
    if (!jump_offset_.has_value()) {
38
0
      return absl::Status(absl::StatusCode::kInternal, "Jump offset not set");
39
0
    }
40
526
    return frame->JumpTo(jump_offset_.value());
41
526
  }
42
43
 private:
44
  absl::optional<int> jump_offset_;
45
};
46
47
// Factory method for Jump step.
48
std::unique_ptr<JumpStepBase> CreateJumpStep(absl::optional<int> jump_offset,
49
                                             int64_t expr_id);
50
51
// Factory method for Conditional Jump step.
52
// Conditional Jump requires a boolean value to sit on the stack.
53
// It is compared to jump_condition, and if matched, jump is performed.
54
// leave on stack indicates whether value should be kept on top of the stack or
55
// removed.
56
std::unique_ptr<JumpStepBase> CreateCondJumpStep(
57
    bool jump_condition, bool leave_on_stack, absl::optional<int> jump_offset,
58
    int64_t expr_id);
59
60
// Factory method for ErrorJump step.
61
// This step performs a Jump when an Error is on the top of the stack.
62
// Value is left on stack if it is a bool or an error.
63
std::unique_ptr<JumpStepBase> CreateBoolCheckJumpStep(
64
    absl::optional<int> jump_offset, int64_t expr_id);
65
66
}  // namespace google::api::expr::runtime
67
68
#endif  // THIRD_PARTY_CEL_CPP_EVAL_EVAL_JUMP_STEP_H_