Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/eval/compiler/check_ast_extensions.cc
Line
Count
Source
1
// Copyright 2026 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 "eval/compiler/check_ast_extensions.h"
16
17
#include <vector>
18
19
#include "absl/container/flat_hash_set.h"
20
#include "absl/status/status.h"
21
#include "absl/status/statusor.h"
22
#include "absl/strings/str_cat.h"
23
#include "absl/strings/string_view.h"
24
#include "common/ast.h"
25
#include "common/ast/metadata.h"
26
27
namespace google::api::expr::runtime {
28
29
absl::StatusOr<std::vector<cel::ExtensionSpec>>
30
10.3k
ExtractAndValidateRuntimeExtensions(const cel::Ast& ast) {
31
10.3k
  std::vector<cel::ExtensionSpec> runtime_extensions;
32
10.3k
  absl::flat_hash_set<absl::string_view> seen_extension_ids;
33
34
10.3k
  for (const cel::ExtensionSpec& extension : ast.source_info().extensions()) {
35
0
    bool is_runtime = false;
36
0
    for (const cel::ExtensionSpec::Component& component :
37
0
         extension.affected_components()) {
38
0
      if (component == cel::ExtensionSpec::Component::kRuntime) {
39
0
        is_runtime = true;
40
0
        break;
41
0
      }
42
0
    }
43
44
0
    if (!is_runtime) {
45
0
      continue;
46
0
    }
47
48
0
    if (!seen_extension_ids.insert(extension.id()).second) {
49
0
      return absl::InvalidArgumentError(
50
0
          absl::StrCat("duplicate extension ID: ", extension.id()));
51
0
    }
52
0
    runtime_extensions.push_back(extension);
53
0
  }
54
55
10.3k
  return runtime_extensions;
56
10.3k
}
57
58
}  // namespace google::api::expr::runtime