Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/parser/macro_registry.h
Line
Count
Source
1
// Copyright 2024 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_PARSER_MACRO_REGISTRY_H_
16
#define THIRD_PARTY_CEL_CPP_PARSER_MACRO_REGISTRY_H_
17
18
#include <cstddef>
19
#include <vector>
20
21
#include "absl/container/flat_hash_map.h"
22
#include "absl/status/status.h"
23
#include "absl/strings/string_view.h"
24
#include "absl/types/optional.h"
25
#include "absl/types/span.h"
26
#include "parser/macro.h"
27
28
namespace cel {
29
30
class MacroRegistry final {
31
 public:
32
21.4k
  MacroRegistry() = default;
33
34
  // Move-only.
35
0
  MacroRegistry(MacroRegistry&&) = default;
36
  MacroRegistry& operator=(MacroRegistry&&) = default;
37
38
  // Registers `macro`.
39
  absl::Status RegisterMacro(const Macro& macro);
40
41
  // Registers all `macros`. If an error is encountered registering one, the
42
  // rest are not registered and the error is returned.
43
  absl::Status RegisterMacros(absl::Span<const Macro> macros);
44
45
  absl::optional<Macro> FindMacro(absl::string_view name, size_t arg_count,
46
                                  bool receiver_style) const;
47
48
  // Returns a copy of all registered macros.
49
  std::vector<Macro> ListMacros() const;
50
51
 private:
52
  bool RegisterMacroImpl(const Macro& macro);
53
54
  absl::flat_hash_map<absl::string_view, Macro> macros_;
55
};
56
57
}  // namespace cel
58
59
#endif  // THIRD_PARTY_CEL_CPP_PARSER_MACRO_REGISTRY_H_