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 "google/protobuf/compiler/hpb/output.h" 9 10 #include <string> 11 12 #include "upb_generator/c/names.h" 13 #include "upb_generator/minitable/names.h" 14 15 namespace google::protobuf::hpb_generator { 16 namespace { 17 18 namespace protobuf = ::proto2; 19 20 } // namespace 21 ToCIdent(absl::string_view str)22std::string ToCIdent(absl::string_view str) { 23 return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}}); 24 } 25 ToPreproc(absl::string_view str)26std::string ToPreproc(absl::string_view str) { 27 return absl::AsciiStrToUpper(ToCIdent(str)); 28 } 29 EmitFileWarning(const protobuf::FileDescriptor * file,Output & output)30void EmitFileWarning(const protobuf::FileDescriptor* file, Output& output) { 31 output( 32 R"cc( 33 /* This file was generated by hpb_generator (Handle Protobuf) " 34 from the input 35 * file: 36 * 37 * $0 38 * 39 * Do not edit -- your changes will be discarded when the file is 40 * regenerated. */ 41 )cc", 42 file->name()); 43 output("\n"); 44 } 45 46 std::string MessageName(const protobuf::Descriptor* descriptor) { 47 return upb::generator::CApiMessageType(descriptor->full_name()); 48 } 49 50 std::string FileLayoutName(const google::protobuf::FileDescriptor* file) { 51 return upb::generator::MiniTableFileVarName(file->name()); 52 } 53 54 std::string CHeaderFilename(const google::protobuf::FileDescriptor* file) { 55 return upb::generator::CApiHeaderFilename(file->name()); 56 } 57 58 } // namespace protobuf 59 } // namespace google::hpb_generator 60