Protobuf Team Bot | 52c9b98 | 2022-08-26 14:35:38 -0700 | [diff] [blame] | 1 | /* |
| 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 Bot | 30af08f | 2023-04-24 08:50:25 -0700 | [diff] [blame] | 33 | #include "absl/base/attributes.h" |
Protobuf Team Bot | 52c9b98 | 2022-08-26 14:35:38 -0700 | [diff] [blame] | 34 | #include "absl/container/flat_hash_map.h" |
Protobuf Team Bot | 30af08f | 2023-04-24 08:50:25 -0700 | [diff] [blame] | 35 | #include "absl/strings/string_view.h" |
Mike Kruskal | 2b011bc | 2022-11-10 11:51:09 -0800 | [diff] [blame] | 36 | #include "google/protobuf/descriptor.h" |
Joshua Haberman | e41a2d7 | 2023-01-11 21:25:34 -0800 | [diff] [blame] | 37 | #include "upb/reflection/def.hpp" |
Protobuf Team Bot | 52c9b98 | 2022-08-26 14:35:38 -0700 | [diff] [blame] | 38 | |
| 39 | namespace upbc { |
| 40 | |
| 41 | using 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). |
| 46 | std::string ResolveFieldName(const google::protobuf::FieldDescriptor* field, |
| 47 | const NameToFieldDescriptorMap& field_names); |
| 48 | |
| 49 | // Returns field map by name to use for conflict checks. |
| 50 | NameToFieldDescriptorMap CreateFieldNameMap(const google::protobuf::Descriptor* message); |
| 51 | |
Joshua Haberman | e41a2d7 | 2023-01-11 21:25:34 -0800 | [diff] [blame] | 52 | using 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). |
| 57 | std::string ResolveFieldName(upb::FieldDefPtr field, |
| 58 | const NameToFieldDefMap& field_names); |
| 59 | |
| 60 | // Returns field map by name to use for conflict checks. |
| 61 | NameToFieldDefMap CreateFieldNameMap(upb::MessageDefPtr message); |
| 62 | |
Protobuf Team Bot | 30af08f | 2023-04-24 08:50:25 -0700 | [diff] [blame] | 63 | // Private array getter name postfix for repeated fields. |
| 64 | ABSL_CONST_INIT extern const absl::string_view kRepeatedFieldArrayGetterPostfix; |
| 65 | ABSL_CONST_INIT extern const absl::string_view |
| 66 | kRepeatedFieldMutableArrayGetterPostfix; |
| 67 | |
Protobuf Team Bot | 52c9b98 | 2022-08-26 14:35:38 -0700 | [diff] [blame] | 68 | } // namespace upbc |
| 69 | |
| 70 | #endif // UPB_PROTOS_GENERATOR_NAMES_H |