summaryrefslogtreecommitdiff
path: root/upbc
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2018-12-31 20:02:20 -0800
committerJoshua Haberman <jhaberman@gmail.com>2018-12-31 20:02:20 -0800
commit0ce9b818153088704a2206635c08574f60df45f1 (patch)
treeb360fb52286b2be9bc5e418b49455d7dba0bd89a /upbc
parentc3011c15483b775123ff40d58fe8c29f93efa431 (diff)
Fixed bugs in array accessors.
Diffstat (limited to 'upbc')
-rw-r--r--upbc/generator.cc39
1 files changed, 33 insertions, 6 deletions
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,
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback