From 340bd013380f23eeb3aadd6d1eb0209c5fe7312e Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 6 Sep 2018 18:10:45 -0700 Subject: Removed default instance and oneof array from tables. --- tools/make_c_api.lua | 72 ++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 45 deletions(-) (limited to 'tools/make_c_api.lua') diff --git a/tools/make_c_api.lua b/tools/make_c_api.lua index 47a5b08..cf1cfdc 100644 --- a/tools/make_c_api.lua +++ b/tools/make_c_api.lua @@ -306,20 +306,20 @@ local function get_message_layout(msg) -- Place discriminator enum and data. local data = place(offset, oneof_maxsize, maxsize) local case = place(offset, {4, 4}, maxsize) - offsets[oneof] = {data, case} + offsets[oneof] = case + + -- Place oneof fields. + for oneof in msg:oneofs() do + for field in oneof:fields() do + offsets[field] = data + end + end end -- Align overall size up to max size. alignup(offset, maxsize) local size = copysize(offset) - -- Place oneof defaults. - for oneof in msg:oneofs() do - for field in oneof:fields() do - offsets[field] = place(offset, sizeof(field), maxsize) - end - end - return hasbit_indexes, offsets, size end @@ -399,7 +399,7 @@ local function write_h_file(filedef, append) append('} %s_oneofcases;\n', fullname) append('UPB_INLINE %s_oneofcases %s_%s_case(const %s* msg) { ' .. 'return UPB_FIELD_AT(msg, int, %s); }\n', - fullname, msgname, oneof:name(), msgname, get_sizeinit(offset[2])) + fullname, msgname, oneof:name(), msgname, get_sizeinit(offset)) append('\n') end @@ -407,10 +407,11 @@ local function write_h_file(filedef, append) append('UPB_INLINE %s %s_%s(const %s *msg) {', ctype(field, true), msgname, field:name(), msgname) if field:containing_oneof() then - local offset = offsets[field:containing_oneof()] + local data_offset = offsets[field] + local case_offset = offsets[field:containing_oneof()] append(' return UPB_READ_ONEOF(msg, %s, %s, %s, %s, %s); }\n', - ctype(field, true), get_sizeinit(offset[1]), - get_sizeinit(offset[2]), field:number(), field_default(field)) + ctype(field, true), get_sizeinit(data_offset), + get_sizeinit(case_offset), field:number(), field_default(field)) else append(' return UPB_FIELD_AT(msg, %s, %s); }\n', ctype(field, true), get_sizeinit(offsets[field])) @@ -423,9 +424,10 @@ local function write_h_file(filedef, append) append('UPB_INLINE void %s_set_%s(%s *msg, %s value) { ', msgname, field:name(), msgname, ctype(field)) if field:containing_oneof() then - local offset = offsets[field:containing_oneof()] + local data_offset = offsets[field] + local case_offset = offsets[field:containing_oneof()] append('UPB_WRITE_ONEOF(msg, %s, %s, value, %s, %s); }\n', - ctype(field), get_sizeinit(offset[1]), get_sizeinit(offset[2]), + ctype(field), get_sizeinit(data_offset), get_sizeinit(case_offset), field:number()) else append('UPB_FIELD_AT(msg, %s, %s) = value; }\n', @@ -474,7 +476,6 @@ local function write_c_file(filedef, hfilename, append) local hasbit_indexes, offsets, size = get_message_layout(msg) local oneofs_layout_order = get_oneof_layout_order(msg) local oneof_count = 0 - local oneof_indexes = {} -- Another sorted array in field number order. local fields_number_order = {} @@ -492,23 +493,6 @@ local function write_c_file(filedef, hfilename, append) return a:number() < b:number() end) - for _, oneof in ipairs(oneofs_layout_order) do - oneof_indexes[oneof] = oneof_count - oneof_count = oneof_count + 1 - end - - if oneof_count > 0 then - local oneofs_array_name = msgname .. "_oneofs" - oneofs_array_ref = "&" .. oneofs_array_name .. "[0]" - append('static const upb_msglayout_oneof %s[%s] = {\n', - oneofs_array_name, oneof_count) - for _, oneof in ipairs(oneofs_layout_order) do - local offset = offsets[oneof] - append(' {%s, %s},\n', get_sizeinit(offset[1]), get_sizeinit(offset[2])) - end - append('};\n\n') - end - if submsg_count > 0 then -- TODO(haberman): could save a little bit of space by only generating a -- "submsgs" array for every strongly-connected component. @@ -540,19 +524,21 @@ local function write_c_file(filedef, hfilename, append) append('static const upb_msglayout_field %s[%s] = {\n', fields_array_name, field_count) for _, field in ipairs(fields_number_order) do - local submsg_index = "UPB_NO_SUBMSG" - local oneof_index = "UPB_NOT_IN_ONEOF" + local submsg_index = "0" if field:type() == upb.TYPE_MESSAGE then submsg_index = submsg_indexes[field:subdef()] end - if field:containing_oneof() then - oneof_index = oneof_indexes[field:containing_oneof()] + local presence = 0 + if has_hasbit(field) then + presence = hasbit_indexes[field] + 1 + elseif field:containing_oneof() then + local case_ofs = offsets[field:containing_oneof()] + presence = get_sizeinit({(-case_ofs[1]) - 1, (-case_ofs[2]) - 1}) end - append(' {%s, %s, %s, %s, %s, %s, %s},\n', + append(' {%s, %s, %s, %s, %s, %s},\n', field:number(), get_sizeinit(offsets[field]), - hasbit_indexes[field] or "UPB_NO_HASBIT", - oneof_index, + presence, submsg_index, field:descriptor_type(), field:label()) @@ -563,13 +549,9 @@ local function write_c_file(filedef, hfilename, append) append('const upb_msglayout %s_msginit = {\n', msgname) append(' %s,\n', submsgs_array_ref) append(' %s,\n', fields_array_ref) - append(' %s,\n', oneofs_array_ref) - append(' NULL, /* TODO. default_msg */\n') - append(' %s, %s, %s, %s, %s\n', + append(' %s, %s, %s,\n', get_sizeinit(size), field_count, - oneof_count, - 'false', -- TODO: extendable - msg:file():syntax() == upb.SYNTAX_PROTO2 + 'false' -- TODO: extendable ) append('};\n\n') -- cgit v1.2.3 From a4db17592949bbc22d9c3a97e52d228ba3d3ec81 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 6 Sep 2018 21:58:11 -0700 Subject: Removed unnecessary struct definition with "int a". --- google/protobuf/descriptor.upb.h | 81 ++++++++++++++++++++++++++-------------- tools/make_c_api.lua | 7 +++- 2 files changed, 60 insertions(+), 28 deletions(-) (limited to 'tools/make_c_api.lua') diff --git a/google/protobuf/descriptor.upb.h b/google/protobuf/descriptor.upb.h index 07ce6f1..7afa8c5 100644 --- a/google/protobuf/descriptor.upb.h +++ b/google/protobuf/descriptor.upb.h @@ -16,33 +16,60 @@ #include "upb/port_def.inc" UPB_BEGIN_EXTERN_C -typedef struct google_protobuf_FileDescriptorSet { int a; } google_protobuf_FileDescriptorSet; -typedef struct google_protobuf_FileDescriptorProto { int a; } google_protobuf_FileDescriptorProto; -typedef struct google_protobuf_DescriptorProto { int a; } google_protobuf_DescriptorProto; -typedef struct google_protobuf_DescriptorProto_ExtensionRange { int a; } google_protobuf_DescriptorProto_ExtensionRange; -typedef struct google_protobuf_DescriptorProto_ReservedRange { int a; } google_protobuf_DescriptorProto_ReservedRange; -typedef struct google_protobuf_ExtensionRangeOptions { int a; } google_protobuf_ExtensionRangeOptions; -typedef struct google_protobuf_FieldDescriptorProto { int a; } google_protobuf_FieldDescriptorProto; -typedef struct google_protobuf_OneofDescriptorProto { int a; } google_protobuf_OneofDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto { int a; } google_protobuf_EnumDescriptorProto; -typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange { int a; } google_protobuf_EnumDescriptorProto_EnumReservedRange; -typedef struct google_protobuf_EnumValueDescriptorProto { int a; } google_protobuf_EnumValueDescriptorProto; -typedef struct google_protobuf_ServiceDescriptorProto { int a; } google_protobuf_ServiceDescriptorProto; -typedef struct google_protobuf_MethodDescriptorProto { int a; } google_protobuf_MethodDescriptorProto; -typedef struct google_protobuf_FileOptions { int a; } google_protobuf_FileOptions; -typedef struct google_protobuf_MessageOptions { int a; } google_protobuf_MessageOptions; -typedef struct google_protobuf_FieldOptions { int a; } google_protobuf_FieldOptions; -typedef struct google_protobuf_OneofOptions { int a; } google_protobuf_OneofOptions; -typedef struct google_protobuf_EnumOptions { int a; } google_protobuf_EnumOptions; -typedef struct google_protobuf_EnumValueOptions { int a; } google_protobuf_EnumValueOptions; -typedef struct google_protobuf_ServiceOptions { int a; } google_protobuf_ServiceOptions; -typedef struct google_protobuf_MethodOptions { int a; } google_protobuf_MethodOptions; -typedef struct google_protobuf_UninterpretedOption { int a; } google_protobuf_UninterpretedOption; -typedef struct google_protobuf_UninterpretedOption_NamePart { int a; } google_protobuf_UninterpretedOption_NamePart; -typedef struct google_protobuf_SourceCodeInfo { int a; } google_protobuf_SourceCodeInfo; -typedef struct google_protobuf_SourceCodeInfo_Location { int a; } google_protobuf_SourceCodeInfo_Location; -typedef struct google_protobuf_GeneratedCodeInfo { int a; } google_protobuf_GeneratedCodeInfo; -typedef struct google_protobuf_GeneratedCodeInfo_Annotation { int a; } google_protobuf_GeneratedCodeInfo_Annotation; +struct google_protobuf_FileDescriptorSet; +struct google_protobuf_FileDescriptorProto; +struct google_protobuf_DescriptorProto; +struct google_protobuf_DescriptorProto_ExtensionRange; +struct google_protobuf_DescriptorProto_ReservedRange; +struct google_protobuf_ExtensionRangeOptions; +struct google_protobuf_FieldDescriptorProto; +struct google_protobuf_OneofDescriptorProto; +struct google_protobuf_EnumDescriptorProto; +struct google_protobuf_EnumDescriptorProto_EnumReservedRange; +struct google_protobuf_EnumValueDescriptorProto; +struct google_protobuf_ServiceDescriptorProto; +struct google_protobuf_MethodDescriptorProto; +struct google_protobuf_FileOptions; +struct google_protobuf_MessageOptions; +struct google_protobuf_FieldOptions; +struct google_protobuf_OneofOptions; +struct google_protobuf_EnumOptions; +struct google_protobuf_EnumValueOptions; +struct google_protobuf_ServiceOptions; +struct google_protobuf_MethodOptions; +struct google_protobuf_UninterpretedOption; +struct google_protobuf_UninterpretedOption_NamePart; +struct google_protobuf_SourceCodeInfo; +struct google_protobuf_SourceCodeInfo_Location; +struct google_protobuf_GeneratedCodeInfo; +struct google_protobuf_GeneratedCodeInfo_Annotation; +typedef struct google_protobuf_FileDescriptorSet google_protobuf_FileDescriptorSet; +typedef struct google_protobuf_FileDescriptorProto google_protobuf_FileDescriptorProto; +typedef struct google_protobuf_DescriptorProto google_protobuf_DescriptorProto; +typedef struct google_protobuf_DescriptorProto_ExtensionRange google_protobuf_DescriptorProto_ExtensionRange; +typedef struct google_protobuf_DescriptorProto_ReservedRange google_protobuf_DescriptorProto_ReservedRange; +typedef struct google_protobuf_ExtensionRangeOptions google_protobuf_ExtensionRangeOptions; +typedef struct google_protobuf_FieldDescriptorProto google_protobuf_FieldDescriptorProto; +typedef struct google_protobuf_OneofDescriptorProto google_protobuf_OneofDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto google_protobuf_EnumDescriptorProto; +typedef struct google_protobuf_EnumDescriptorProto_EnumReservedRange google_protobuf_EnumDescriptorProto_EnumReservedRange; +typedef struct google_protobuf_EnumValueDescriptorProto google_protobuf_EnumValueDescriptorProto; +typedef struct google_protobuf_ServiceDescriptorProto google_protobuf_ServiceDescriptorProto; +typedef struct google_protobuf_MethodDescriptorProto google_protobuf_MethodDescriptorProto; +typedef struct google_protobuf_FileOptions google_protobuf_FileOptions; +typedef struct google_protobuf_MessageOptions google_protobuf_MessageOptions; +typedef struct google_protobuf_FieldOptions google_protobuf_FieldOptions; +typedef struct google_protobuf_OneofOptions google_protobuf_OneofOptions; +typedef struct google_protobuf_EnumOptions google_protobuf_EnumOptions; +typedef struct google_protobuf_EnumValueOptions google_protobuf_EnumValueOptions; +typedef struct google_protobuf_ServiceOptions google_protobuf_ServiceOptions; +typedef struct google_protobuf_MethodOptions google_protobuf_MethodOptions; +typedef struct google_protobuf_UninterpretedOption google_protobuf_UninterpretedOption; +typedef struct google_protobuf_UninterpretedOption_NamePart google_protobuf_UninterpretedOption_NamePart; +typedef struct google_protobuf_SourceCodeInfo google_protobuf_SourceCodeInfo; +typedef struct google_protobuf_SourceCodeInfo_Location google_protobuf_SourceCodeInfo_Location; +typedef struct google_protobuf_GeneratedCodeInfo google_protobuf_GeneratedCodeInfo; +typedef struct google_protobuf_GeneratedCodeInfo_Annotation google_protobuf_GeneratedCodeInfo_Annotation; /* Enums */ diff --git a/tools/make_c_api.lua b/tools/make_c_api.lua index cf1cfdc..bf79b26 100644 --- a/tools/make_c_api.lua +++ b/tools/make_c_api.lua @@ -343,7 +343,12 @@ local function write_h_file(filedef, append) -- Forward-declare types defined in this file. for msg in filedef:defs(upb.DEF_MSG) do local msgname = to_cident(msg:full_name()) - append('typedef struct %s { int a; } %s;\n', msgname, msgname) + append('struct %s;\n', msgname) + end + + for msg in filedef:defs(upb.DEF_MSG) do + local msgname = to_cident(msg:full_name()) + append('typedef struct %s %s;\n', msgname, msgname) end -- Forward-declare types not in this file, but used as submessages. -- cgit v1.2.3