From 7cde43ea0abf2022a0c800c7af1d5f1ec2033bea Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 14 Nov 2009 15:49:21 -0800 Subject: Renamed upb_msg_fielddef -> upb_fielddef, upb_enum -> upb_enumdef. --- lang_ext/python/pb.c | 8 +++---- src/upb.h | 2 +- src/upb_array.h | 4 ++-- src/upb_context.c | 6 +++--- src/upb_def.c | 22 ++++++++++--------- src/upb_def.h | 56 ++++++++++++++++++++++++------------------------- src/upb_inlinedefs.c | 2 +- src/upb_mm.c | 14 ++++++------- src/upb_mm.h | 12 +++++------ src/upb_msg.c | 22 +++++++++---------- src/upb_msg.h | 8 +++---- src/upb_struct.h | 8 +++---- src/upb_text.c | 6 +++--- tests/test_vs_proto2.cc | 6 +++--- tools/upbc.c | 20 +++++++++--------- 15 files changed, 99 insertions(+), 97 deletions(-) diff --git a/lang_ext/python/pb.c b/lang_ext/python/pb.c index 634b397..2c63184 100644 --- a/lang_ext/python/pb.c +++ b/lang_ext/python/pb.c @@ -60,7 +60,7 @@ typedef struct { typedef struct { PyObject_HEAD; PyUpb_PbMsg *msg; - struct upb_msg_fielddef *f; + struct upb_fielddef *f; PyUpb_PbBoundFieldOpCode code; } PyUpb_PbBoundFieldOp; @@ -299,7 +299,7 @@ PyObject* fieldop_call(PyObject *callable, PyObject *args, PyObject *kw) PyUpb_PbMsg *pymsg = op->msg; struct upb_mm_ref *msgref = &(pymsg->ref); struct upb_msg *msg = pymsg->ref.p.msg; - struct upb_msg_fielddef *f = op->f; + struct upb_fielddef *f = op->f; union upb_value_ptr p = upb_msg_getptr(msg, f); switch(op->code) { case OP_HAS: @@ -654,7 +654,7 @@ static bool ends_with(struct upb_string *str, struct upb_string *suffix, } } -PyObject *PyUpb_NewPbBoundFieldOp(PyUpb_PbMsg *msgobj, struct upb_msg_fielddef *f, +PyObject *PyUpb_NewPbBoundFieldOp(PyUpb_PbMsg *msgobj, struct upb_fielddef *f, PyUpb_PbBoundFieldOpCode code) { /* Type check that this operation on a field of this type makes sense. */ @@ -750,7 +750,7 @@ PyObject* msg_getattro(PyObject *obj, PyObject *attr_name) opcode = OP_GET; field_name = str; } - struct upb_msg_fielddef *f = upb_msg_fieldbyname(def, &field_name); + struct upb_fielddef *f = upb_msg_fieldbyname(def, &field_name); if(f) { PyObject *op = PyUpb_NewPbBoundFieldOp(msgobj, f, opcode); if(op) return op; diff --git a/src/upb.h b/src/upb.h index 9ad141d..e8ec001 100644 --- a/src/upb.h +++ b/src/upb.h @@ -224,7 +224,7 @@ INLINE void upb_value_write(union upb_value_ptr ptr, union upb_value val, // All the different definitions that can occur in .proto files. union upb_symbol_ref { struct upb_msgdef *msg; - struct upb_enum *_enum; + struct upb_enumdef *_enum; struct upb_svc *svc; }; diff --git a/src/upb_array.h b/src/upb_array.h index 577cbd4..70923b6 100644 --- a/src/upb_array.h +++ b/src/upb_array.h @@ -23,7 +23,7 @@ #define UPB_ARRAY_H_ #include -#include "upb_msg.h" /* Because we use upb_msg_fielddef */ +#include "upb_def.h" /* Because we use upb_fielddef */ #ifdef __cplusplus extern "C" { @@ -43,7 +43,7 @@ INLINE union upb_value_ptr upb_array_getelementptr(struct upb_array *arr, /* Allocation/Deallocation/Resizing. ******************************************/ -INLINE struct upb_array *upb_array_new(struct upb_msg_fielddef *f) +INLINE struct upb_array *upb_array_new(struct upb_fielddef *f) { struct upb_array *arr = (struct upb_array*)malloc(sizeof(*arr)); upb_mmhead_init(&arr->mmhead); diff --git a/src/upb_context.c b/src/upb_context.c index 2ac14c6..2d558d9 100644 --- a/src/upb_context.c +++ b/src/upb_context.c @@ -57,7 +57,7 @@ static void free_symtab(struct upb_strtable *t) for(; e; e = upb_strtable_next(t, &e->e)) { switch(e->type) { case UPB_SYM_MESSAGE: upb_msgdef_free(e->ref.msg); break; - case UPB_SYM_ENUM: upb_enum_free(e->ref._enum); break; + case UPB_SYM_ENUM: upb_enumdef_free(e->ref._enum); break; default: break; /* TODO */ } free(e->ref.msg); /* The pointer is the same for all. */ @@ -211,7 +211,7 @@ static void insert_enum(struct upb_strtable *t, e.e.key = fqname; e.type = UPB_SYM_ENUM; e.ref._enum = malloc(sizeof(*e.ref._enum)); - upb_enum_init(e.ref._enum, ed, c); + upb_enumdef_init(e.ref._enum, ed, c); upb_strtable_insert(t, &e.e); } @@ -291,7 +291,7 @@ void addfd(struct upb_strtable *addto, struct upb_strtable *existingdefs, if(e->type == UPB_SYM_MESSAGE) { struct upb_msgdef *m = e->ref.msg; for(unsigned int i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[i]; union upb_symbol_ref ref; if(fd->type == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE || diff --git a/src/upb_def.c b/src/upb_def.c index 5450f5f..00a0610 100644 --- a/src/upb_def.c +++ b/src/upb_def.c @@ -66,7 +66,7 @@ void upb_msgdef_init(struct upb_msgdef *m, google_protobuf_DescriptorProto *d, size_t max_align = 0; for(unsigned int i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[i]; struct upb_type_info *type_info = &upb_type_info[fd->type]; @@ -103,7 +103,7 @@ void upb_msgdef_free(struct upb_msgdef *m) free(m->field_descriptors); } -void upb_msgdef_setref(struct upb_msgdef *m, struct upb_msg_fielddef *f, +void upb_msgdef_setref(struct upb_msgdef *m, struct upb_fielddef *f, union upb_symbol_ref ref) { struct google_protobuf_FieldDescriptorProto *d = upb_msg_field_descriptor(f, m); @@ -118,28 +118,30 @@ void upb_msgdef_setref(struct upb_msgdef *m, struct upb_msg_fielddef *f, } -void upb_enum_init(struct upb_enum *e, +void upb_enumdef_init(struct upb_enumdef *e, struct google_protobuf_EnumDescriptorProto *ed, struct upb_context *c) { int num_values = ed->set_flags.has.value ? ed->value->len : 0; e->descriptor = ed; e->context = c; upb_atomic_refcount_init(&e->refcount, 0); - upb_strtable_init(&e->nametoint, num_values, sizeof(struct upb_enum_ntoi_entry)); - upb_inttable_init(&e->inttoname, num_values, sizeof(struct upb_enum_iton_entry)); + upb_strtable_init(&e->nametoint, num_values, + sizeof(struct upb_enumdef_ntoi_entry)); + upb_inttable_init(&e->inttoname, num_values, + sizeof(struct upb_enumdef_iton_entry)); for(int i = 0; i < num_values; i++) { google_protobuf_EnumValueDescriptorProto *value = ed->value->elements[i]; - struct upb_enum_ntoi_entry ntoi_entry = {.e = {.key = *value->name}, - .value = value->number}; - struct upb_enum_iton_entry iton_entry = {.e = {.key = value->number}, - .string = value->name}; + struct upb_enumdef_ntoi_entry ntoi_entry = {.e = {.key = *value->name}, + .value = value->number}; + struct upb_enumdef_iton_entry iton_entry = {.e = {.key = value->number}, + .string = value->name}; upb_strtable_insert(&e->nametoint, &ntoi_entry.e); upb_inttable_insert(&e->inttoname, &iton_entry.e); } } -void upb_enum_free(struct upb_enum *e) { +void upb_enumdef_free(struct upb_enumdef *e) { upb_strtable_free(&e->nametoint); upb_inttable_free(&e->inttoname); } diff --git a/src/upb_def.h b/src/upb_def.h index a5d6d4c..8cbaab6 100644 --- a/src/upb_def.h +++ b/src/upb_def.h @@ -5,8 +5,8 @@ * * Provides definitions of .proto constructs: * - upb_msgdef: describes a "message" construct. - * - upb_msg_fielddef: describes a message field. - * - upb_enum: describes an enum. + * - upb_fielddef: describes a message field. + * - upb_enumdef: describes an enum. * (TODO: descriptions of extensions and services). * * This file contains routines for creating and manipulating the definitions @@ -25,7 +25,7 @@ extern "C" { /* Message definition. ********************************************************/ -struct upb_msg_fielddef; +struct upb_fielddef; struct upb_context; /* Structure that describes a single .proto message type. */ struct upb_msgdef { @@ -39,7 +39,7 @@ struct upb_msgdef { uint32_t num_required_fields; /* Required fields have the lowest set bytemasks. */ struct upb_inttable fields_by_num; struct upb_strtable fields_by_name; - struct upb_msg_fielddef *fields; + struct upb_fielddef *fields; struct google_protobuf_FieldDescriptorProto **field_descriptors; }; @@ -48,7 +48,7 @@ struct upb_msgdef { * because copies of this struct are in the hash table that is read in the * critical path of parsing. Minimizing the size of this struct increases * cache-friendliness. */ -struct upb_msg_fielddef { +struct upb_fielddef { union upb_symbol_ref ref; uint32_t byte_offset; /* Where to find the data. */ uint16_t field_index; /* Indexes upb_msgdef.fields and indicates set bit */ @@ -56,26 +56,26 @@ struct upb_msg_fielddef { upb_label_t label; }; -INLINE bool upb_issubmsg(struct upb_msg_fielddef *f) { +INLINE bool upb_issubmsg(struct upb_fielddef *f) { return upb_issubmsgtype(f->type); } -INLINE bool upb_isstring(struct upb_msg_fielddef *f) { +INLINE bool upb_isstring(struct upb_fielddef *f) { return upb_isstringtype(f->type); } -INLINE bool upb_isarray(struct upb_msg_fielddef *f) { +INLINE bool upb_isarray(struct upb_fielddef *f) { return f->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REPEATED; } -INLINE bool upb_field_ismm(struct upb_msg_fielddef *f) { +INLINE bool upb_field_ismm(struct upb_fielddef *f) { return upb_isarray(f) || upb_isstring(f) || upb_issubmsg(f); } -INLINE bool upb_elem_ismm(struct upb_msg_fielddef *f) { +INLINE bool upb_elem_ismm(struct upb_fielddef *f) { return upb_isstring(f) || upb_issubmsg(f); } /* Defined iff upb_field_ismm(f). */ -INLINE upb_mm_ptrtype upb_field_ptrtype(struct upb_msg_fielddef *f) { +INLINE upb_mm_ptrtype upb_field_ptrtype(struct upb_fielddef *f) { if(upb_isarray(f)) return UPB_MM_ARR_REF; else if(upb_isstring(f)) return UPB_MM_STR_REF; else if(upb_issubmsg(f)) return UPB_MM_MSG_REF; @@ -83,15 +83,15 @@ INLINE upb_mm_ptrtype upb_field_ptrtype(struct upb_msg_fielddef *f) { } /* Defined iff upb_elem_ismm(f). */ -INLINE upb_mm_ptrtype upb_elem_ptrtype(struct upb_msg_fielddef *f) { +INLINE upb_mm_ptrtype upb_elem_ptrtype(struct upb_fielddef *f) { if(upb_isstring(f)) return UPB_MM_STR_REF; else if(upb_issubmsg(f)) return UPB_MM_MSG_REF; else return -1; } -/* Can be used to retrieve a field descriptor given the upb_msg_fielddef. */ +/* Can be used to retrieve a field descriptor given the upb_fielddef. */ INLINE struct google_protobuf_FieldDescriptorProto *upb_msg_field_descriptor( - struct upb_msg_fielddef *f, struct upb_msgdef *m) { + struct upb_fielddef *f, struct upb_msgdef *m) { return m->field_descriptors[f->field_index]; } @@ -104,18 +104,18 @@ INLINE struct google_protobuf_FieldDescriptorProto *upb_msg_field_descriptor( struct upb_fieldsbynum_entry { struct upb_inttable_entry e; - struct upb_msg_fielddef f; + struct upb_fielddef f; }; struct upb_fieldsbyname_entry { struct upb_strtable_entry e; - struct upb_msg_fielddef f; + struct upb_fielddef f; }; /* Looks up a field by name or number. While these are written to be as fast * as possible, it will still be faster to cache the results of this lookup if * possible. These return NULL if no such field is found. */ -INLINE struct upb_msg_fielddef *upb_msg_fieldbynum(struct upb_msgdef *m, +INLINE struct upb_fielddef *upb_msg_fieldbynum(struct upb_msgdef *m, uint32_t number) { struct upb_fieldsbynum_entry *e = (struct upb_fieldsbynum_entry*)upb_inttable_fast_lookup( @@ -123,7 +123,7 @@ INLINE struct upb_msg_fielddef *upb_msg_fieldbynum(struct upb_msgdef *m, return e ? &e->f : NULL; } -INLINE struct upb_msg_fielddef *upb_msg_fieldbyname(struct upb_msgdef *m, +INLINE struct upb_fielddef *upb_msg_fieldbyname(struct upb_msgdef *m, struct upb_string *name) { struct upb_fieldsbyname_entry *e = (struct upb_fieldsbyname_entry*)upb_strtable_lookup( @@ -133,7 +133,7 @@ INLINE struct upb_msg_fielddef *upb_msg_fieldbyname(struct upb_msgdef *m, /* Enums. *********************************************************************/ -struct upb_enum { +struct upb_enumdef { upb_atomic_refcount_t refcount; struct upb_context *context; struct google_protobuf_EnumDescriptorProto *descriptor; @@ -141,22 +141,22 @@ struct upb_enum { struct upb_inttable inttoname; }; -struct upb_enum_ntoi_entry { +struct upb_enumdef_ntoi_entry { struct upb_strtable_entry e; uint32_t value; }; -struct upb_enum_iton_entry { +struct upb_enumdef_iton_entry { struct upb_inttable_entry e; struct upb_string *string; }; /* Initializes and frees an enum, respectively. Caller retains ownership of * ed, but it must outlive e. */ -void upb_enum_init(struct upb_enum *e, - struct google_protobuf_EnumDescriptorProto *ed, - struct upb_context *c); -void upb_enum_free(struct upb_enum *e); +void upb_enumdef_init(struct upb_enumdef *e, + struct google_protobuf_EnumDescriptorProto *ed, + struct upb_context *c); +void upb_enumdef_free(struct upb_enumdef *e); /* Internal functions. ********************************************************/ @@ -166,7 +166,7 @@ void upb_enum_free(struct upb_enum *e); * * Caller retains ownership of d, but the msg will contain references to it, so * it must outlive the msg. Note that init does not resolve - * upb_msg_fielddef.ref the caller should do that post-initialization by + * upb_fielddef.ref the caller should do that post-initialization by * calling upb_msg_ref() below. * * fqname indicates the fully-qualified name of this message. Ownership of @@ -189,10 +189,10 @@ void upb_msgdef_sortfds(struct google_protobuf_FieldDescriptorProto **fds, size_t num); /* Clients use this function on a previously initialized upb_msgdef to resolve - * the "ref" field in the upb_msg_fielddef. Since messages can refer to each + * the "ref" field in the upb_fielddef. Since messages can refer to each * other in mutually-recursive ways, this step must be separated from * initialization. */ -void upb_msgdef_setref(struct upb_msgdef *m, struct upb_msg_fielddef *f, +void upb_msgdef_setref(struct upb_msgdef *m, struct upb_fielddef *f, union upb_symbol_ref ref); #ifdef __cplusplus diff --git a/src/upb_inlinedefs.c b/src/upb_inlinedefs.c index 7a55e06..7100849 100644 --- a/src/upb_inlinedefs.c +++ b/src/upb_inlinedefs.c @@ -14,7 +14,7 @@ #define INLINE #include "upb_array.h" #include "upb_context.h" -#include "upb_enum.h" +#include "upb_def.h" #include "upb_mm.h" #include "upb_msg.h" #include "upb_parse.h" diff --git a/src/upb_mm.c b/src/upb_mm.c index 6f9a028..212c2a2 100644 --- a/src/upb_mm.c +++ b/src/upb_mm.c @@ -20,7 +20,7 @@ static void upb_mm_destroy(union upb_value_ptr p, upb_mm_ptrtype type) void upb_msg_destroy(struct upb_msg *msg) { uint32_t i; for(i = 0; i < msg->def->num_fields; i++) { - struct upb_msg_fielddef *f = &msg->def->fields[i]; + struct upb_fielddef *f = &msg->def->fields[i]; if(!upb_msg_isset(msg, f) || !upb_field_ismm(f)) continue; upb_mm_destroy(upb_msg_getptr(msg, f), upb_field_ptrtype(f)); } @@ -42,7 +42,7 @@ void upb_array_destroy(struct upb_array *arr) } static union upb_mmptr upb_mm_newptr(upb_mm_ptrtype type, - struct upb_msg_fielddef *f) + struct upb_fielddef *f) { union upb_mmptr p = {NULL}; switch(type) { @@ -96,7 +96,7 @@ struct upb_mm_ref *upb_mm_newmsg_ref(struct upb_msgdef *def, struct upb_mm *mm) } struct upb_mm_ref *upb_mm_getfieldref(struct upb_mm_ref *msgref, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, bool *refcreated) { assert(upb_field_ismm(f)); @@ -121,7 +121,7 @@ struct upb_mm_ref *upb_mm_getelemref(struct upb_mm_ref *arrref, upb_arraylen_t i bool *refcreated) { struct upb_array *arr = arrref->p.arr; - struct upb_msg_fielddef *f = arr->fielddef; + struct upb_fielddef *f = arr->fielddef; assert(upb_elem_ismm(f)); assert(i < arr->len); union upb_value_ptr p = upb_array_getelementptr(arr, i); @@ -161,7 +161,7 @@ void upb_mm_release(struct upb_mm_ref *ref) } void upb_mm_msg_set(struct upb_mm_ref *from_msg_ref, struct upb_mm_ref *to_ref, - struct upb_msg_fielddef *f) + struct upb_fielddef *f) { assert(upb_field_ismm(f)); union upb_mmptr fromval = from_msg_ref->p; @@ -179,7 +179,7 @@ void upb_mm_msg_set(struct upb_mm_ref *from_msg_ref, struct upb_mm_ref *to_ref, upb_mm_ref(toval, type); } -void upb_mm_msgclear(struct upb_mm_ref *from_msg_ref, struct upb_msg_fielddef *f) +void upb_mm_msgclear(struct upb_mm_ref *from_msg_ref, struct upb_fielddef *f) { assert(upb_field_ismm(f)); union upb_mmptr fromval = from_msg_ref->p; @@ -196,7 +196,7 @@ void upb_mm_msgclear_all(struct upb_mm_ref *from) { struct upb_msgdef *def = from->p.msg->def; for(uint32_t i = 0; i < def->num_fields; i++) { - struct upb_msg_fielddef *f = &def->fields[i]; + struct upb_fielddef *f = &def->fields[i]; if(!upb_field_ismm(f)) continue; upb_mm_msgclear(from, f); } diff --git a/src/upb_mm.h b/src/upb_mm.h index 88cb043..2e3e082 100644 --- a/src/upb_mm.h +++ b/src/upb_mm.h @@ -40,7 +40,7 @@ typedef int16_t upb_mm_id; struct upb_msg; struct upb_array; struct upb_string; -struct upb_msg_fielddef; +struct upb_fielddef; struct upb_mm_ref; /* Info about a mm. */ @@ -76,7 +76,7 @@ struct upb_mm_ref *upb_mm_getref(union upb_mmptr p, upb_mm_ptrtype type, * returns it, otherwise calls the given callback to create one. 'created' * indicates whether a new reference was created. */ struct upb_mm_ref *upb_mm_getfieldref(struct upb_mm_ref *msgref, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, bool *refcreated); /* Array len must be < i. */ struct upb_mm_ref *upb_mm_getelemref(struct upb_mm_ref *arrref, upb_arraylen_t i, @@ -87,16 +87,16 @@ struct upb_mm_ref *upb_mm_getelemref(struct upb_mm_ref *arrref, upb_arraylen_t i void upb_mm_release(struct upb_mm_ref *ref); void upb_mm_msgset(struct upb_mm_ref *msg, struct upb_mm_ref *to, - struct upb_msg_fielddef *f); -void upb_mm_msgclear(struct upb_mm_ref *from, struct upb_msg_fielddef *f); + struct upb_fielddef *f); +void upb_mm_msgclear(struct upb_mm_ref *from, struct upb_fielddef *f); void upb_mm_msgclear_all(struct upb_mm_ref *from); void upb_mm_arrset(struct upb_mm_ref *from, struct upb_mm_ref *to, uint32_t i); /* Defined iff upb_field_ismm(f). */ -INLINE upb_mm_ptrtype upb_field_ptrtype(struct upb_msg_fielddef *f); +INLINE upb_mm_ptrtype upb_field_ptrtype(struct upb_fielddef *f); /* Defined iff upb_elem_ismm(f). */ -INLINE upb_mm_ptrtype upb_elem_ptrtype(struct upb_msg_fielddef *f); +INLINE upb_mm_ptrtype upb_elem_ptrtype(struct upb_fielddef *f); INLINE void upb_mm_unref(union upb_mmptr p, upb_mm_ptrtype type); diff --git a/src/upb_msg.c b/src/upb_msg.c index 4c78063..926eda0 100644 --- a/src/upb_msg.c +++ b/src/upb_msg.c @@ -30,7 +30,7 @@ struct upb_msgparser { * should be stored, taking into account whether f is an array that may need to * be allocated or resized. */ static union upb_value_ptr get_value_ptr(struct upb_msg *msg, - struct upb_msg_fielddef *f) + struct upb_fielddef *f) { union upb_value_ptr p = upb_msg_getptr(msg, f); if(upb_isarray(f)) { @@ -54,7 +54,7 @@ static upb_field_type_t tag_cb(void *udata, struct upb_tag *tag, void **user_field_desc) { struct upb_msgparser *mp = udata; - struct upb_msg_fielddef *f = + struct upb_fielddef *f = upb_msg_fieldbynum(mp->top->msg->def, tag->field_number); if(!f || !upb_check_type(tag->wire_type, f->type)) return 0; /* Skip unknown or fields of the wrong type. */ @@ -66,7 +66,7 @@ static void *value_cb(void *udata, uint8_t *buf, uint8_t *end, void *user_field_desc, struct upb_status *status) { struct upb_msgparser *mp = udata; - struct upb_msg_fielddef *f = user_field_desc; + struct upb_fielddef *f = user_field_desc; struct upb_msg *msg = mp->top->msg; union upb_value_ptr p = get_value_ptr(msg, f); upb_msg_set(msg, f); @@ -78,7 +78,7 @@ static void str_cb(void *udata, uint8_t *str, void *udesc) { struct upb_msgparser *mp = udata; - struct upb_msg_fielddef *f = udesc; + struct upb_fielddef *f = udesc; struct upb_msg *msg = mp->top->msg; union upb_value_ptr p = get_value_ptr(msg, f); upb_msg_set(msg, f); @@ -103,7 +103,7 @@ static void str_cb(void *udata, uint8_t *str, static void start_cb(void *udata, void *user_field_desc) { struct upb_msgparser *mp = udata; - struct upb_msg_fielddef *f = user_field_desc; + struct upb_fielddef *f = user_field_desc; struct upb_msg *oldmsg = mp->top->msg; union upb_value_ptr p = get_value_ptr(oldmsg, f); @@ -185,7 +185,7 @@ static size_t get_msgsize(struct upb_msgsizes *sizes, struct upb_msg *m); /* Returns a size of a value as it will be serialized. Does *not* include * the size of the tag -- that is already accounted for. */ static size_t get_valuesize(struct upb_msgsizes *sizes, union upb_value_ptr p, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, google_protobuf_FieldDescriptorProto *fd) { switch(f->type) { @@ -227,7 +227,7 @@ static size_t get_msgsize(struct upb_msgsizes *sizes, struct upb_msg *m) size_t size = 0; /* We iterate over fields and arrays in reverse order. */ for(int32_t i = m->def->num_fields - 1; i >= 0; i--) { - struct upb_msg_fielddef *f = &m->def->fields[i]; + struct upb_fielddef *f = &m->def->fields[i]; google_protobuf_FieldDescriptorProto *fd = upb_msg_field_descriptor(f, m->def); if(!upb_msg_isset(m, f)) continue; union upb_value_ptr p = upb_msg_getptr(m, f); @@ -306,7 +306,7 @@ void upb_msg_serialize_init(struct upb_msg_serialize_state *s, struct upb_msg *m #if 0 static uint8_t *serialize_tag(uint8_t *buf, uint8_t *end, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, struct upb_status *status) { /* TODO: need to have the field number also. */ @@ -331,7 +331,7 @@ size_t upb_msg_serialize(struct upb_msg_serialize_state *s, struct upb_msgdef *m = s->top->m; while(buf < end) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; //union upb_value_ptr p = upb_msg_getptr(msg, f); buf = serialize_tag(buf, end, f, status); if(f->type == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE) { @@ -382,7 +382,7 @@ bool upb_value_eql(union upb_value_ptr p1, union upb_value_ptr p2, } bool upb_array_eql(struct upb_array *arr1, struct upb_array *arr2, - struct upb_msg_fielddef *f, bool recursive) + struct upb_fielddef *f, bool recursive) { if(arr1->len != arr2->len) return false; if(upb_issubmsg(f)) { @@ -416,7 +416,7 @@ bool upb_msg_eql(struct upb_msg *msg1, struct upb_msg *msg2, bool recursive) * padding) and memcmp the masked messages. */ for(uint32_t i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; bool msg1set = upb_msg_isset(msg1, f); bool msg2set = upb_msg_isset(msg2, f); if(msg1set != msg2set) return false; diff --git a/src/upb_msg.h b/src/upb_msg.h index 552e2dc..4ca1e2a 100644 --- a/src/upb_msg.h +++ b/src/upb_msg.h @@ -70,7 +70,7 @@ INLINE struct upb_msg *upb_msg_new(struct upb_msgdef *md) { /* Returns a pointer to a specific field in a message. */ INLINE union upb_value_ptr upb_msg_getptr(struct upb_msg *msg, - struct upb_msg_fielddef *f) { + struct upb_fielddef *f) { union upb_value_ptr p; p._void = &msg->data[f->byte_offset]; return p; @@ -95,19 +95,19 @@ INLINE uint8_t upb_isset_mask(uint32_t field_index) { } /* Returns true if the given field is set, false otherwise. */ -INLINE void upb_msg_set(struct upb_msg *msg, struct upb_msg_fielddef *f) +INLINE void upb_msg_set(struct upb_msg *msg, struct upb_fielddef *f) { msg->data[upb_isset_offset(f->field_index)] |= upb_isset_mask(f->field_index); } /* Clears the set bit for this field in the given message. */ -INLINE void upb_msg_unset(struct upb_msg *msg, struct upb_msg_fielddef *f) +INLINE void upb_msg_unset(struct upb_msg *msg, struct upb_fielddef *f) { msg->data[upb_isset_offset(f->field_index)] &= ~upb_isset_mask(f->field_index); } /* Tests whether the given field is set. */ -INLINE bool upb_msg_isset(struct upb_msg *msg, struct upb_msg_fielddef *f) +INLINE bool upb_msg_isset(struct upb_msg *msg, struct upb_fielddef *f) { return msg->data[upb_isset_offset(f->field_index)] & upb_isset_mask(f->field_index); } diff --git a/src/upb_struct.h b/src/upb_struct.h index c83978f..094c207 100644 --- a/src/upb_struct.h +++ b/src/upb_struct.h @@ -47,7 +47,7 @@ INLINE void upb_mmhead_ref(struct upb_mmhead *head) { /* These are all self describing. */ struct upb_msgdef; -struct upb_msg_fielddef; +struct upb_fielddef; struct upb_msg { struct upb_mmhead mmhead; @@ -58,7 +58,7 @@ struct upb_msg { typedef uint32_t upb_arraylen_t; /* can be at most 2**32 elements long. */ struct upb_array { struct upb_mmhead mmhead; - struct upb_msg_fielddef *fielddef; /* Defines the type of the array. */ + struct upb_fielddef *fielddef; /* Defines the type of the array. */ union upb_value_ptr elements; upb_arraylen_t len; /* Number of elements in "elements". */ upb_arraylen_t size; /* Memory we own. */ @@ -78,7 +78,7 @@ struct upb_string { #define UPB_DEFINE_ARRAY_TYPE(name, type) \ struct name ## _array { \ struct upb_mmhead mmhead; \ - struct upb_msg_fielddef *fielddef; \ + struct upb_fielddef *fielddef; \ type elements; \ upb_arraylen_t len; \ upb_arraylen_t size; \ @@ -99,7 +99,7 @@ UPB_DEFINE_ARRAY_TYPE(upb_msg, void*) #define UPB_DEFINE_MSG_ARRAY(msg_type) \ UPB_MSG_ARRAY(msg_type) { \ struct upb_mmhead mmhead; \ - struct upb_msg_fielddef *fielddef; \ + struct upb_fielddef *fielddef; \ msg_type **elements; \ upb_arraylen_t len; \ upb_arraylen_t size; \ diff --git a/src/upb_text.c b/src/upb_text.c index bed4b43..ade8888 100644 --- a/src/upb_text.c +++ b/src/upb_text.c @@ -83,7 +83,7 @@ void upb_text_pop(struct upb_text_printer *p, } static void printval(struct upb_text_printer *printer, union upb_value_ptr p, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, google_protobuf_FieldDescriptorProto *fd, FILE *stream); @@ -92,7 +92,7 @@ static void printmsg(struct upb_text_printer *printer, struct upb_msg *msg, { struct upb_msgdef *m = msg->def; for(uint32_t i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; google_protobuf_FieldDescriptorProto *fd = upb_msg_field_descriptor(f, m); if(!upb_msg_isset(msg, f)) continue; union upb_value_ptr p = upb_msg_getptr(msg, f); @@ -109,7 +109,7 @@ static void printmsg(struct upb_text_printer *printer, struct upb_msg *msg, } static void printval(struct upb_text_printer *printer, union upb_value_ptr p, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, google_protobuf_FieldDescriptorProto *fd, FILE *stream) { diff --git a/tests/test_vs_proto2.cc b/tests/test_vs_proto2.cc index 71dc1da..8674d58 100644 --- a/tests/test_vs_proto2.cc +++ b/tests/test_vs_proto2.cc @@ -24,7 +24,7 @@ void compare(const google::protobuf::Message& proto2_msg, void compare_arrays(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, const google::protobuf::FieldDescriptor *proto2_f, - struct upb_msg *upb_msg, struct upb_msg_fielddef *upb_f) + struct upb_msg *upb_msg, struct upb_fielddef *upb_f) { struct upb_array *arr = *upb_msg_getptr(upb_msg, upb_f).arr; ASSERT(arr->len == (upb_arraylen_t)r->FieldSize(proto2_msg, proto2_f)); @@ -78,7 +78,7 @@ void compare_arrays(const google::protobuf::Reflection *r, void compare_values(const google::protobuf::Reflection *r, const google::protobuf::Message& proto2_msg, const google::protobuf::FieldDescriptor *proto2_f, - struct upb_msg *upb_msg, struct upb_msg_fielddef *upb_f) + struct upb_msg *upb_msg, struct upb_fielddef *upb_f) { union upb_value_ptr p = upb_msg_getptr(upb_msg, upb_f); switch(upb_f->type) { @@ -134,7 +134,7 @@ void compare(const google::protobuf::Message& proto2_msg, ASSERT((uint32_t)d->field_count() == def->num_fields); for(uint32_t i = 0; i < def->num_fields; i++) { - struct upb_msg_fielddef *upb_f = &def->fields[i]; + struct upb_fielddef *upb_f = &def->fields[i]; struct google_protobuf_FieldDescriptorProto *upb_fd = upb_msg_field_descriptor(upb_f, def); const google::protobuf::FieldDescriptor *proto2_f = diff --git a/tools/upbc.c b/tools/upbc.c index f43634f..263f4e3 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -185,7 +185,7 @@ static void write_h(struct upb_symtab_entry *entries[], int num_entries, fputs(" } has;\n", stream); fputs(" } set_flags;\n", stream); for(uint32_t j = 0; j < m->num_fields; j++) { - struct upb_msg_fielddef *f = &m->fields[j]; + struct upb_fielddef *f = &m->fields[j]; struct google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[j]; if(f->type == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_GROUP || f->type == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE) { @@ -256,7 +256,7 @@ struct strtable_entry { struct typetable_entry { struct upb_strtable_entry e; - struct upb_msg_fielddef *field; + struct upb_fielddef *field; struct upb_string *cident; /* Type name converted with to_cident(). */ /* A list of all values of this type, in an established order. */ union upb_value *values; @@ -290,7 +290,7 @@ static void add_strings_from_msg(void *data, struct upb_msgdef *m, struct upb_strtable *t); static void add_strings_from_value(union upb_value_ptr p, - struct upb_msg_fielddef *f, + struct upb_fielddef *f, struct upb_strtable *t) { if(upb_isstringtype(f->type)) { @@ -306,7 +306,7 @@ static void add_strings_from_msg(void *data, struct upb_msgdef *m, struct upb_strtable *t) { for(uint32_t i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; if(!upb_msg_isset(data, f)) continue; union upb_value_ptr p = upb_msg_getptr(data, f); if(upb_isarray(f)) { @@ -325,7 +325,7 @@ static void add_strings_from_msg(void *data, struct upb_msgdef *m, * TODO: make these use a generic msg visitor. */ struct typetable_entry *get_or_insert_typeentry(struct upb_strtable *t, - struct upb_msg_fielddef *f) + struct upb_fielddef *f) { struct upb_string *type_name = upb_issubmsg(f) ? upb_strdup(&f->ref.msg->fqname) : upb_strdupc(upb_type_info[f->type].ctype); @@ -348,7 +348,7 @@ struct typetable_entry *get_or_insert_typeentry(struct upb_strtable *t, return type_e; } -static void add_value(union upb_value_ptr p, struct upb_msg_fielddef *f, +static void add_value(union upb_value_ptr p, struct upb_fielddef *f, struct upb_strtable *t) { struct typetable_entry *type_e = get_or_insert_typeentry(t, f); @@ -362,7 +362,7 @@ static void add_value(union upb_value_ptr p, struct upb_msg_fielddef *f, static void add_submsgs(void *data, struct upb_msgdef *m, struct upb_strtable *t) { for(uint32_t i = 0; i < m->num_fields; i++) { - struct upb_msg_fielddef *f = &m->fields[i]; + struct upb_fielddef *f = &m->fields[i]; if(!upb_msg_isset(data, f)) continue; union upb_value_ptr p = upb_msg_getptr(data, f); if(upb_isarray(f)) { @@ -472,7 +472,7 @@ static void write_message_c(void *data, struct upb_msgdef *m, upb_strtable_init(&types, 16, sizeof(struct typetable_entry)); union upb_value val = {.msg = data}; /* A fake field to get the recursion going. */ - struct upb_msg_fielddef fake_field = { + struct upb_fielddef fake_field = { .type = GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_TYPE_MESSAGE, .ref = {.msg = m} }; @@ -521,7 +521,7 @@ static void write_message_c(void *data, struct upb_msgdef *m, /* Print set flags. */ fputs(" {.set_flags = {.has = {\n", stream); for(unsigned int j = 0; j < m->num_fields; j++) { - struct upb_msg_fielddef *f = &m->fields[j]; + struct upb_fielddef *f = &m->fields[j]; google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[j]; fprintf(stream, " ." UPB_STRFMT " = ", UPB_STRARG(fd->name)); if(upb_msg_isset(msgdata, f)) @@ -533,7 +533,7 @@ static void write_message_c(void *data, struct upb_msgdef *m, fputs(" }},\n", stream); /* Print msg data. */ for(unsigned int j = 0; j < m->num_fields; j++) { - struct upb_msg_fielddef *f = &m->fields[j]; + struct upb_fielddef *f = &m->fields[j]; google_protobuf_FieldDescriptorProto *fd = m->field_descriptors[j]; union upb_value val = upb_value_read(upb_msg_getptr(msgdata, f), f->type); fprintf(stream, " ." UPB_STRFMT " = ", UPB_STRARG(fd->name)); -- cgit v1.2.3