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 7 8 #include "upb_generator/minitable/names_internal.h" 9 10 #include <string> 11 12 #include "absl/strings/str_replace.h" 13 #include "absl/strings/string_view.h" 14 #include "upb_generator/common/names.h" 15 16 namespace upb { 17 namespace generator { 18 19 namespace { 20 ToCIdent(absl::string_view str)21std::string ToCIdent(absl::string_view str) { 22 return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}}); 23 } 24 25 } // namespace 26 MiniTableHeaderFilename(absl::string_view proto_filename,bool bootstrap)27std::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/"; 35 } 36 } 37 return base + StripExtension(proto_filename) + ".upb_minitable.h"; 38 } 39 MiniTableFieldsVarName(absl::string_view msg_full_name)40std::string MiniTableFieldsVarName(absl::string_view msg_full_name) { 41 return ToCIdent(msg_full_name) + "__fields"; 42 } 43 MiniTableSubMessagesVarName(absl::string_view msg_full_name)44std::string MiniTableSubMessagesVarName(absl::string_view msg_full_name) { 45 return ToCIdent(msg_full_name) + "__submsgs"; 46 } 47 48 } // namespace generator 49 } // namespace upb 50