pull/13171/head
Josh Haberman 6 years ago
parent cf35baa1ad
commit 0c64c4b594
  1. 9
      upb/legacy_msg_reflection.c
  2. 3
      upb/legacy_msg_reflection.h
  3. 15
      upb/msg.h
  4. 15
      upbc/generator.cc

@ -211,15 +211,6 @@ bool upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
/** upb_map *******************************************************************/
struct upb_map {
upb_fieldtype_t key_type;
upb_fieldtype_t val_type;
/* We may want to optimize this to use inttable where possible, for greater
* efficiency and lower memory footprint. */
upb_strtable strtab;
upb_arena *arena;
};
static void upb_map_tokey(upb_fieldtype_t type, upb_msgval *key,
const char **out_key, size_t *out_len) {
switch (type) {

@ -7,9 +7,6 @@
#include "upb/port_def.inc"
struct upb_map;
typedef struct upb_map upb_map;
struct upb_mapiter;
typedef struct upb_mapiter upb_mapiter;

@ -11,6 +11,8 @@
#include <stdint.h>
#include <string.h>
#include "upb/table.int.h"
#include "upb/upb.h"
#ifdef __cplusplus
@ -55,6 +57,19 @@ typedef struct {
upb_arena *arena;
} upb_array;
/* Our internal representation for maps. */
typedef struct {
/* First element must be upb_array so code like parser/serializer can treat
* map fields as array. */
upb_array array;
/* A side index whose values are indexes into the array. May be NULL. */
union {
upb_strtable *strtab;
upb_inttable *inttab;
} table;
} upb_map;
upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);
upb_msg *upb_msg_new(const upb_msglayout *l, upb_arena *a);

@ -368,8 +368,10 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
GetSizeInit(layout.GetOneofCaseOffset(oneof)));
}
for (auto field : FieldNumberOrder(message)) {
// Generate const methods.
for (auto field : FieldNumberOrder(message)) {
// Generate hazzer (if any).
if (layout.HasHasbit(field)) {
output(
"UPB_INLINE bool $0_has_$1(const $0 *msg) { "
@ -384,6 +386,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
field->number());
}
// Generate getter.
if (field->is_repeated()) {
output(
"UPB_INLINE $0 const* $1_$2(const $1 *msg, size_t *len) { "
@ -409,8 +412,15 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
output("\n");
// Generate mutable methods.
for (auto field : FieldNumberOrder(message)) {
if (field->is_repeated()) {
if (message->options().map_entry() && field->name() == "key") {
// Emit nothing, map keys cannot be changed directly. Users must use
// the mutators of the map itself.
} else if (field->is_map()) {
// TODO(haberman): add map-based mutators.
} else if (field->is_repeated()) {
output(
"UPB_INLINE $0* $1_mutable_$2($1 *msg, size_t *len) {\n"
" return ($0*)_upb_array_mutable_accessor(msg, $3, len);\n"
@ -453,6 +463,7 @@ void GenerateMessageInHeader(const protobuf::Descriptor* message, Output& output
UpbType(field));
}
} else {
// Non-repeated field.
output("UPB_INLINE void $0_set_$1($0 *msg, $2 value) {\n", msgname,
field->name(), CType(field));
if (field->containing_oneof()) {

Loading…
Cancel
Save