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