Automated rollback of commit 694d7935747a5b4eac351b757ad8ff22599c8077.
[google-protobuf.git] / upb_generator / minitable / names_internal.cc
blob86058f6fbf6892d5cc4d299054902aab7bea4e31
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2023 Google LLC. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #include "upb_generator/minitable/names_internal.h"
10 #include <string>
12 #include "absl/strings/str_replace.h"
13 #include "absl/strings/string_view.h"
14 #include "upb_generator/common/names.h"
16 namespace upb {
17 namespace generator {
19 namespace {
21 std::string ToCIdent(absl::string_view str) {
22 return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}});
25 } // namespace
27 std::string MiniTableHeaderFilename(absl::string_view proto_filename,
28 bool bootstrap) {
29 std::string base;
30 if (bootstrap) {
31 if (IsDescriptorProto(proto_filename)) {
32 base = "upb/reflection/stage1/";
33 } else {
34 base = "upb_generator/stage1/";
37 return base + StripExtension(proto_filename) + ".upb_minitable.h";
40 std::string MiniTableFieldsVarName(absl::string_view msg_full_name) {
41 return ToCIdent(msg_full_name) + "__fields";
44 std::string MiniTableSubMessagesVarName(absl::string_view msg_full_name) {
45 return ToCIdent(msg_full_name) + "__submsgs";
48 } // namespace generator
49 } // namespace upb