From 0ce9b818153088704a2206635c08574f60df45f1 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 31 Dec 2018 20:02:20 -0800 Subject: Fixed bugs in array accessors. --- upbc/generator.cc | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'upbc') diff --git a/upbc/generator.cc b/upbc/generator.cc index a40b4c3..c076c9c 100644 --- a/upbc/generator.cc +++ b/upbc/generator.cc @@ -219,6 +219,34 @@ std::string CTypeInternal(const protobuf::FieldDescriptor* field, } } +std::string UpbType(const protobuf::FieldDescriptor* field) { + switch (field->cpp_type()) { + case protobuf::FieldDescriptor::CPPTYPE_MESSAGE: + return "UPB_TYPE_MESSAGE"; + case protobuf::FieldDescriptor::CPPTYPE_ENUM: + return "UPB_TYPE_ENUM"; + case protobuf::FieldDescriptor::CPPTYPE_BOOL: + return "UPB_TYPE_BOOL"; + case protobuf::FieldDescriptor::CPPTYPE_FLOAT: + return "UPB_TYPE_FLOAT"; + case protobuf::FieldDescriptor::CPPTYPE_INT32: + return "UPB_TYPE_INT32"; + case protobuf::FieldDescriptor::CPPTYPE_UINT32: + return "UPB_TYPE_UINT32"; + case protobuf::FieldDescriptor::CPPTYPE_DOUBLE: + return "UPB_TYPE_DOUBLE"; + case protobuf::FieldDescriptor::CPPTYPE_INT64: + return "UPB_TYPE_INT64"; + case protobuf::FieldDescriptor::CPPTYPE_UINT64: + return "UPB_TYPE_UINT64"; + case protobuf::FieldDescriptor::CPPTYPE_STRING: + return "UPB_TYPE_STRING"; + default: + fprintf(stderr, "Unexpected type"); + abort(); + } +} + std::string FieldDefault(const protobuf::FieldDescriptor* field) { switch (field->cpp_type()) { case protobuf::FieldDescriptor::CPPTYPE_MESSAGE: @@ -380,12 +408,13 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output output( "UPB_INLINE $0* $1_$2_resize($1 *msg, size_t len, " "upb_arena *arena) {\n" - " return ($0*)_upb_array_resize_accessor(msg, $3, len, $4, $5, arena);\n" + " return ($0*)_upb_array_resize_accessor(msg, $3, len, $4, $5, " + "arena);\n" "}\n", CType(field), msgname, field->name(), GetSizeInit(layout.GetFieldOffset(field)), GetSizeInit(MessageLayout::SizeOfUnwrapped(field).size), - "(upb_fieldtype_t)0" /* TODO */); + UpbType(field)); if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { output( "UPB_INLINE struct $0* $1_add_$2($1 *msg, upb_arena *arena) {\n" @@ -399,8 +428,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output MessageInit(field->message_type()), GetSizeInit(layout.GetFieldOffset(field)), GetSizeInit(MessageLayout::SizeOfUnwrapped(field).size), - "(upb_fieldtype_t)0" /* TODO */ - ); + UpbType(field)); } else { output( "UPB_INLINE bool $1_add_$2($1 *msg, $0 val, upb_arena *arena) {\n" @@ -410,8 +438,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output CType(field), msgname, field->name(), GetSizeInit(layout.GetFieldOffset(field)), GetSizeInit(MessageLayout::SizeOfUnwrapped(field).size), - "(upb_fieldtype_t)0" /* TODO */ - ); + UpbType(field)); } } else { output("UPB_INLINE void $0_set_$1($0 *msg, $2 value) {\n", msgname, -- cgit v1.2.3