blob: 7eef159451cce631666000f83bd9f73009042c93 [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
3// https://developers.google.com/protocol-buffers/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// * Redistributions of source code must retain the above copyright
10// notice, this list of conditions and the following disclaimer.
11// * Redistributions in binary form must reproduce the above
12// copyright notice, this list of conditions and the following disclaimer
13// in the documentation and/or other materials provided with the
14// distribution.
15// * Neither the name of Google LLC nor the names of its
16// contributors may be used to endorse or promote products derived from
17// this software without specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31#ifndef UPB_PROTOS_GENERATOR_NAMES_H
32#define UPB_PROTOS_GENERATOR_NAMES_H
33
34#include <string>
35
36#include "absl/base/attributes.h"
37#include "absl/container/flat_hash_map.h"
38#include "absl/strings/string_view.h"
39#include "google/protobuf/descriptor.h"
40#include "upb/reflection/def.hpp"
41
Adam Cozzette12c7bb02023-09-28 12:54:11 -070042namespace upb {
43namespace generator {
Adam Cozzette501ecec2023-09-26 14:36:20 -070044
45using NameToFieldDescriptorMap =
46 absl::flat_hash_map<absl::string_view, const google::protobuf::FieldDescriptor*>;
47
48// Returns field name by resolving naming conflicts across
49// proto field names (such as clear_ prefixes).
50std::string ResolveFieldName(const google::protobuf::FieldDescriptor* field,
51 const NameToFieldDescriptorMap& field_names);
52
53// Returns field map by name to use for conflict checks.
54NameToFieldDescriptorMap CreateFieldNameMap(const google::protobuf::Descriptor* message);
55
56using NameToFieldDefMap =
57 absl::flat_hash_map<absl::string_view, upb::FieldDefPtr>;
58
59// Returns field name by resolving naming conflicts across
60// proto field names (such as clear_ prefixes).
61std::string ResolveFieldName(upb::FieldDefPtr field,
62 const NameToFieldDefMap& field_names);
63
64// Returns field map by name to use for conflict checks.
65NameToFieldDefMap CreateFieldNameMap(upb::MessageDefPtr message);
66
67// Private array getter name postfix for repeated fields.
68ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldArrayGetterPostfix;
69ABSL_CONST_INIT extern const absl::string_view
70 kRepeatedFieldMutableArrayGetterPostfix;
71
Adam Cozzette12c7bb02023-09-28 12:54:11 -070072} // namespace generator
73} // namespace upb
Adam Cozzette501ecec2023-09-26 14:36:20 -070074
75#endif // UPB_PROTOS_GENERATOR_NAMES_H