Coverage Report

Created: 2025-11-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/ast/source_info_proto.cc
Line
Count
Source
1
// Copyright 2022 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
#include "common/ast/source_info_proto.h"
16
17
#include <cstdint>
18
#include <utility>
19
20
#include "cel/expr/checked.pb.h"
21
#include "cel/expr/syntax.pb.h"
22
#include "google/protobuf/duration.pb.h"
23
#include "google/protobuf/struct.pb.h"
24
#include "google/protobuf/timestamp.pb.h"
25
#include "absl/status/status.h"
26
#include "common/ast.h"
27
#include "common/ast/expr_proto.h"
28
#include "internal/status_macros.h"
29
30
namespace cel::ast_internal {
31
32
using ::cel::ast_internal::ExprToProto;
33
34
using ExprPb = cel::expr::Expr;
35
using ParsedExprPb = cel::expr::ParsedExpr;
36
using CheckedExprPb = cel::expr::CheckedExpr;
37
using ExtensionPb = cel::expr::SourceInfo::Extension;
38
39
absl::Status SourceInfoToProto(const cel::SourceInfo& source_info,
40
1.32k
                               cel::expr::SourceInfo* out) {
41
1.32k
  cel::expr::SourceInfo& result = *out;
42
1.32k
  result.set_syntax_version(source_info.syntax_version());
43
1.32k
  result.set_location(source_info.location());
44
45
1.28M
  for (int32_t line_offset : source_info.line_offsets()) {
46
1.28M
    result.add_line_offsets(line_offset);
47
1.28M
  }
48
49
1.32k
  for (auto pos_iter = source_info.positions().begin();
50
1.71M
       pos_iter != source_info.positions().end(); ++pos_iter) {
51
1.71M
    (*result.mutable_positions())[pos_iter->first] = pos_iter->second;
52
1.71M
  }
53
54
1.32k
  for (auto macro_iter = source_info.macro_calls().begin();
55
1.32k
       macro_iter != source_info.macro_calls().end(); ++macro_iter) {
56
0
    ExprPb& dest_macro = (*result.mutable_macro_calls())[macro_iter->first];
57
0
    CEL_RETURN_IF_ERROR(ExprToProto(macro_iter->second, &dest_macro));
58
0
  }
59
60
1.32k
  for (const auto& extension : source_info.extensions()) {
61
0
    auto* extension_pb = result.add_extensions();
62
0
    extension_pb->set_id(extension.id());
63
0
    auto* version_pb = extension_pb->mutable_version();
64
0
    version_pb->set_major(extension.version().major());
65
0
    version_pb->set_minor(extension.version().minor());
66
67
0
    for (auto component : extension.affected_components()) {
68
0
      switch (component) {
69
0
        case cel::ExtensionSpec::Component::kParser:
70
0
          extension_pb->add_affected_components(ExtensionPb::COMPONENT_PARSER);
71
0
          break;
72
0
        case cel::ExtensionSpec::Component::kTypeChecker:
73
0
          extension_pb->add_affected_components(
74
0
              ExtensionPb::COMPONENT_TYPE_CHECKER);
75
0
          break;
76
0
        case cel::ExtensionSpec::Component::kRuntime:
77
0
          extension_pb->add_affected_components(ExtensionPb::COMPONENT_RUNTIME);
78
0
          break;
79
0
        default:
80
0
          extension_pb->add_affected_components(
81
0
              ExtensionPb::COMPONENT_UNSPECIFIED);
82
0
          break;
83
0
      }
84
0
    }
85
0
  }
86
87
1.32k
  return absl::OkStatus();
88
1.32k
}
89
90
}  // namespace cel::ast_internal