A convenience wrapper for offset-calculating logic.
| 155 | |
| 156 | // A convenience wrapper for offset-calculating logic. |
| 157 | class Jump { |
| 158 | public: |
| 159 | // Default constructor for empty jump. |
| 160 | // |
| 161 | // Users must check that jump is non-empty before calling member functions. |
| 162 | explicit Jump() : self_index_{-1, nullptr}, jump_step_(nullptr) {} |
| 163 | Jump(ProgramStepIndex self_index, JumpStepBase* jump_step) |
| 164 | : self_index_(self_index), jump_step_(jump_step) {} |
| 165 | |
| 166 | static absl::StatusOr<int> CalculateOffset(ProgramStepIndex base, |
| 167 | ProgramStepIndex target) { |
| 168 | if (target.subexpression != base.subexpression) { |
| 169 | return absl::InternalError( |
| 170 | "Jump target must be contained in the parent" |
| 171 | "subexpression"); |
| 172 | } |
| 173 | |
| 174 | int offset = base.subexpression->CalculateOffset(base.index, target.index); |
| 175 | return offset; |
| 176 | } |
| 177 | |
| 178 | absl::Status set_target(ProgramStepIndex target) { |
| 179 | CEL_ASSIGN_OR_RETURN(int offset, CalculateOffset(self_index_, target)); |
| 180 | |
| 181 | jump_step_->set_jump_offset(offset); |
| 182 | return absl::OkStatus(); |
| 183 | } |
| 184 | |
| 185 | bool exists() { return jump_step_ != nullptr; } |
| 186 | |
| 187 | private: |
| 188 | ProgramStepIndex self_index_; |
| 189 | JumpStepBase* jump_step_; |
| 190 | }; |
| 191 | |
| 192 | class CondVisitor { |
| 193 | public: |
no outgoing calls
no test coverage detected