Added support for public dependencies.

pull/13171/head
Joshua Haberman 6 years ago
parent ef9499cb44
commit c58541ea04
  1. 1
      BUILD
  2. 33
      generated_for_cmake/google/protobuf/descriptor.upb.h
  3. 34
      upbc/generator.cc

@ -74,6 +74,7 @@ cc_library(
upb_proto_library( upb_proto_library(
name = "descriptor_upbproto", name = "descriptor_upbproto",
deps = ["@com_google_protobuf//:descriptor_proto"], deps = ["@com_google_protobuf//:descriptor_proto"],
visibility = ["//visibility:public"],
) )
cc_library( cc_library(

@ -10,12 +10,12 @@
#define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_ #define GOOGLE_PROTOBUF_DESCRIPTOR_PROTO_UPB_H_
#include "upb/generated_util.h" #include "upb/generated_util.h"
#include "upb/msg.h" #include "upb/msg.h"
#include "upb/decode.h" #include "upb/decode.h"
#include "upb/encode.h" #include "upb/encode.h"
#include "upb/port_def.inc" #include "upb/port_def.inc"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -102,8 +102,6 @@ extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit;
extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit; extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit;
extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit; extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit;
/* Enums */
typedef enum { typedef enum {
google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1, google_protobuf_FieldDescriptorProto_LABEL_OPTIONAL = 1,
google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2, google_protobuf_FieldDescriptorProto_LABEL_REQUIRED = 2,
@ -186,7 +184,6 @@ UPB_INLINE struct google_protobuf_FileDescriptorProto* google_protobuf_FileDescr
return sub; return sub;
} }
/* google.protobuf.FileDescriptorProto */ /* google.protobuf.FileDescriptorProto */
UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_FileDescriptorProto *google_protobuf_FileDescriptorProto_new(upb_arena *arena) {
@ -340,7 +337,6 @@ UPB_INLINE void google_protobuf_FileDescriptorProto_set_syntax(google_protobuf_F
UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value; UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(20, 40)) = value;
} }
/* google.protobuf.DescriptorProto */ /* google.protobuf.DescriptorProto */
UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_DescriptorProto *google_protobuf_DescriptorProto_new(upb_arena *arena) {
@ -487,7 +483,6 @@ UPB_INLINE bool google_protobuf_DescriptorProto_add_reserved_name(google_protobu
msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); msg, UPB_SIZE(44, 88), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
} }
/* google.protobuf.DescriptorProto.ExtensionRange */ /* google.protobuf.DescriptorProto.ExtensionRange */
UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) { UPB_INLINE google_protobuf_DescriptorProto_ExtensionRange *google_protobuf_DescriptorProto_ExtensionRange_new(upb_arena *arena) {
@ -531,7 +526,6 @@ UPB_INLINE struct google_protobuf_ExtensionRangeOptions* google_protobuf_Descrip
return sub; return sub;
} }
/* google.protobuf.DescriptorProto.ReservedRange */ /* google.protobuf.DescriptorProto.ReservedRange */
UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) { UPB_INLINE google_protobuf_DescriptorProto_ReservedRange *google_protobuf_DescriptorProto_ReservedRange_new(upb_arena *arena) {
@ -560,7 +554,6 @@ UPB_INLINE void google_protobuf_DescriptorProto_ReservedRange_set_end(google_pro
UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
} }
/* google.protobuf.ExtensionRangeOptions */ /* google.protobuf.ExtensionRangeOptions */
UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_ExtensionRangeOptions *google_protobuf_ExtensionRangeOptions_new(upb_arena *arena) {
@ -591,7 +584,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_Extension
return sub; return sub;
} }
/* google.protobuf.FieldDescriptorProto */ /* google.protobuf.FieldDescriptorProto */
UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_FieldDescriptorProto *google_protobuf_FieldDescriptorProto_new(upb_arena *arena) {
@ -677,7 +669,6 @@ UPB_INLINE void google_protobuf_FieldDescriptorProto_set_json_name(google_protob
UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value; UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(64, 96)) = value;
} }
/* google.protobuf.OneofDescriptorProto */ /* google.protobuf.OneofDescriptorProto */
UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_OneofDescriptorProto *google_protobuf_OneofDescriptorProto_new(upb_arena *arena) {
@ -715,7 +706,6 @@ UPB_INLINE struct google_protobuf_OneofOptions* google_protobuf_OneofDescriptorP
return sub; return sub;
} }
/* google.protobuf.EnumDescriptorProto */ /* google.protobuf.EnumDescriptorProto */
UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_EnumDescriptorProto *google_protobuf_EnumDescriptorProto_new(upb_arena *arena) {
@ -792,7 +782,6 @@ UPB_INLINE bool google_protobuf_EnumDescriptorProto_add_reserved_name(google_pro
msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); msg, UPB_SIZE(24, 48), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
} }
/* google.protobuf.EnumDescriptorProto.EnumReservedRange */ /* google.protobuf.EnumDescriptorProto.EnumReservedRange */
UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) { UPB_INLINE google_protobuf_EnumDescriptorProto_EnumReservedRange *google_protobuf_EnumDescriptorProto_EnumReservedRange_new(upb_arena *arena) {
@ -821,7 +810,6 @@ UPB_INLINE void google_protobuf_EnumDescriptorProto_EnumReservedRange_set_end(go
UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
} }
/* google.protobuf.EnumValueDescriptorProto */ /* google.protobuf.EnumValueDescriptorProto */
UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_EnumValueDescriptorProto *google_protobuf_EnumValueDescriptorProto_new(upb_arena *arena) {
@ -865,7 +853,6 @@ UPB_INLINE struct google_protobuf_EnumValueOptions* google_protobuf_EnumValueDes
return sub; return sub;
} }
/* google.protobuf.ServiceDescriptorProto */ /* google.protobuf.ServiceDescriptorProto */
UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_ServiceDescriptorProto *google_protobuf_ServiceDescriptorProto_new(upb_arena *arena) {
@ -917,7 +904,6 @@ UPB_INLINE struct google_protobuf_ServiceOptions* google_protobuf_ServiceDescrip
return sub; return sub;
} }
/* google.protobuf.MethodDescriptorProto */ /* google.protobuf.MethodDescriptorProto */
UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) { UPB_INLINE google_protobuf_MethodDescriptorProto *google_protobuf_MethodDescriptorProto_new(upb_arena *arena) {
@ -979,7 +965,6 @@ UPB_INLINE void google_protobuf_MethodDescriptorProto_set_server_streaming(googl
UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value; UPB_FIELD_AT(msg, bool, UPB_SIZE(2, 2)) = value;
} }
/* google.protobuf.FileOptions */ /* google.protobuf.FileOptions */
UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_FileOptions *google_protobuf_FileOptions_new(upb_arena *arena) {
@ -1130,7 +1115,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FileOptio
return sub; return sub;
} }
/* google.protobuf.MessageOptions */ /* google.protobuf.MessageOptions */
UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_MessageOptions *google_protobuf_MessageOptions_new(upb_arena *arena) {
@ -1185,7 +1169,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MessageOp
return sub; return sub;
} }
/* google.protobuf.FieldOptions */ /* google.protobuf.FieldOptions */
UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_FieldOptions *google_protobuf_FieldOptions_new(upb_arena *arena) {
@ -1252,7 +1235,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_FieldOpti
return sub; return sub;
} }
/* google.protobuf.OneofOptions */ /* google.protobuf.OneofOptions */
UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_OneofOptions *google_protobuf_OneofOptions_new(upb_arena *arena) {
@ -1283,7 +1265,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_OneofOpti
return sub; return sub;
} }
/* google.protobuf.EnumOptions */ /* google.protobuf.EnumOptions */
UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_EnumOptions *google_protobuf_EnumOptions_new(upb_arena *arena) {
@ -1326,7 +1307,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumOptio
return sub; return sub;
} }
/* google.protobuf.EnumValueOptions */ /* google.protobuf.EnumValueOptions */
UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_EnumValueOptions *google_protobuf_EnumValueOptions_new(upb_arena *arena) {
@ -1363,7 +1343,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_EnumValue
return sub; return sub;
} }
/* google.protobuf.ServiceOptions */ /* google.protobuf.ServiceOptions */
UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_ServiceOptions *google_protobuf_ServiceOptions_new(upb_arena *arena) {
@ -1400,7 +1379,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_ServiceOp
return sub; return sub;
} }
/* google.protobuf.MethodOptions */ /* google.protobuf.MethodOptions */
UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) { UPB_INLINE google_protobuf_MethodOptions *google_protobuf_MethodOptions_new(upb_arena *arena) {
@ -1443,7 +1421,6 @@ UPB_INLINE struct google_protobuf_UninterpretedOption* google_protobuf_MethodOpt
return sub; return sub;
} }
/* google.protobuf.UninterpretedOption */ /* google.protobuf.UninterpretedOption */
UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) { UPB_INLINE google_protobuf_UninterpretedOption *google_protobuf_UninterpretedOption_new(upb_arena *arena) {
@ -1510,7 +1487,6 @@ UPB_INLINE void google_protobuf_UninterpretedOption_set_aggregate_value(google_p
UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value; UPB_FIELD_AT(msg, upb_strview, UPB_SIZE(48, 64)) = value;
} }
/* google.protobuf.UninterpretedOption.NamePart */ /* google.protobuf.UninterpretedOption.NamePart */
UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) { UPB_INLINE google_protobuf_UninterpretedOption_NamePart *google_protobuf_UninterpretedOption_NamePart_new(upb_arena *arena) {
@ -1539,7 +1515,6 @@ UPB_INLINE void google_protobuf_UninterpretedOption_NamePart_set_is_extension(go
UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value; UPB_FIELD_AT(msg, bool, UPB_SIZE(1, 1)) = value;
} }
/* google.protobuf.SourceCodeInfo */ /* google.protobuf.SourceCodeInfo */
UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) { UPB_INLINE google_protobuf_SourceCodeInfo *google_protobuf_SourceCodeInfo_new(upb_arena *arena) {
@ -1570,7 +1545,6 @@ UPB_INLINE struct google_protobuf_SourceCodeInfo_Location* google_protobuf_Sourc
return sub; return sub;
} }
/* google.protobuf.SourceCodeInfo.Location */ /* google.protobuf.SourceCodeInfo.Location */
UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) { UPB_INLINE google_protobuf_SourceCodeInfo_Location *google_protobuf_SourceCodeInfo_Location_new(upb_arena *arena) {
@ -1632,7 +1606,6 @@ UPB_INLINE bool google_protobuf_SourceCodeInfo_Location_add_leading_detached_com
msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena); msg, UPB_SIZE(28, 56), UPB_SIZE(8, 16), UPB_TYPE_STRING, &val, arena);
} }
/* google.protobuf.GeneratedCodeInfo */ /* google.protobuf.GeneratedCodeInfo */
UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) { UPB_INLINE google_protobuf_GeneratedCodeInfo *google_protobuf_GeneratedCodeInfo_new(upb_arena *arena) {
@ -1663,7 +1636,6 @@ UPB_INLINE struct google_protobuf_GeneratedCodeInfo_Annotation* google_protobuf_
return sub; return sub;
} }
/* google.protobuf.GeneratedCodeInfo.Annotation */ /* google.protobuf.GeneratedCodeInfo.Annotation */
UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) { UPB_INLINE google_protobuf_GeneratedCodeInfo_Annotation *google_protobuf_GeneratedCodeInfo_Annotation_new(upb_arena *arena) {
@ -1709,7 +1681,6 @@ UPB_INLINE void google_protobuf_GeneratedCodeInfo_Annotation_set_end(google_prot
UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value; UPB_FIELD_AT(msg, int32_t, UPB_SIZE(8, 8)) = value;
} }
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif

@ -487,7 +487,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
} }
} }
output("\n\n"); output("\n");
} }
void WriteHeader(const protobuf::FileDescriptor* file, Output& output) { void WriteHeader(const protobuf::FileDescriptor* file, Output& output) {
@ -495,15 +495,30 @@ void WriteHeader(const protobuf::FileDescriptor* file, Output& output) {
output( output(
"#ifndef $0_UPB_H_\n" "#ifndef $0_UPB_H_\n"
"#define $0_UPB_H_\n\n" "#define $0_UPB_H_\n\n"
"#include \"upb/generated_util.h\"\n\n" "#include \"upb/generated_util.h\"\n"
"#include \"upb/msg.h\"\n\n" "#include \"upb/msg.h\"\n"
"#include \"upb/decode.h\"\n" "#include \"upb/decode.h\"\n"
"#include \"upb/encode.h\"\n" "#include \"upb/encode.h\"\n\n",
ToPreproc(file->name()));
for (int i = 0; i < file->public_dependency_count(); i++) {
const auto& name = file->public_dependency(i)->name();
if (i == 0) {
output("/* Public Imports. */\n");
}
output("#include \"$0\"\n", HeaderFilename(name));
if (i == file->public_dependency_count() - 1) {
output("\n");
}
}
output(
"#include \"upb/port_def.inc\"\n" "#include \"upb/port_def.inc\"\n"
"\n"
"#ifdef __cplusplus\n" "#ifdef __cplusplus\n"
"extern \"C\" {\n" "extern \"C\" {\n"
"#endif\n\n", "#endif\n"
ToPreproc(file->name())); "\n");
std::vector<const protobuf::Descriptor*> this_file_messages = std::vector<const protobuf::Descriptor*> this_file_messages =
SortedMessages(file); SortedMessages(file);
@ -540,12 +555,13 @@ void WriteHeader(const protobuf::FileDescriptor* file, Output& output) {
output("extern const upb_msglayout $0;\n", MessageInit(pair.second)); output("extern const upb_msglayout $0;\n", MessageInit(pair.second));
} }
if (!this_file_messages.empty()) {
output("\n");
}
std::vector<const protobuf::EnumDescriptor*> this_file_enums = std::vector<const protobuf::EnumDescriptor*> this_file_enums =
SortedEnums(file); SortedEnums(file);
output(
"\n"
"/* Enums */\n\n");
for (auto enumdesc : this_file_enums) { for (auto enumdesc : this_file_enums) {
output("typedef enum {\n"); output("typedef enum {\n");
DumpEnumValues(enumdesc, output); DumpEnumValues(enumdesc, output);

Loading…
Cancel
Save