Coverage Report

Created: 2025-11-29 07:01

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
20
#include "absl/container/flat_hash_map.h"
21
#include "absl/status/status.h"
22
#include "absl/strings/string_view.h"
23
#include "absl/types/optional.h"
24
#include "absl/types/span.h"
25
#include "parser/macro.h"
26
27
namespace cel {
28
29
class MacroRegistry final {
30
 public:
31
4.20k
  MacroRegistry() = default;
32
33
  // Move-only.
34
0
  MacroRegistry(MacroRegistry&&) = default;
35
  MacroRegistry& operator=(MacroRegistry&&) = default;
36
37
  // Registers `macro`.
38
  absl::Status RegisterMacro(const Macro& macro);
39
40
  // Registers all `macros`. If an error is encountered registering one, the
41
  // rest are not registered and the error is returned.
42
  absl::Status RegisterMacros(absl::Span<const Macro> macros);
43
44
  absl::optional<Macro> FindMacro(absl::string_view name, size_t arg_count,
45
                                  bool receiver_style) const;
46
47
 private:
48
  bool RegisterMacroImpl(const Macro& macro);
49
50
  absl::flat_hash_map<absl::string_view, Macro> macros_;
51
};
52
53
}  // namespace cel
54
55
#endif  // THIRD_PARTY_CEL_CPP_PARSER_MACRO_REGISTRY_H_