|
|
@ -106,6 +106,12 @@ struct upb_filedef { |
|
|
|
int ext_count; |
|
|
|
int ext_count; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct upb_symtab { |
|
|
|
|
|
|
|
upb_arena *arena; |
|
|
|
|
|
|
|
upb_strtable syms; /* full_name -> packed def ptr */ |
|
|
|
|
|
|
|
upb_strtable files; /* file_name -> upb_filedef* */ |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
/* Inside a symtab we store tagged pointers to specific def types. */ |
|
|
|
/* Inside a symtab we store tagged pointers to specific def types. */ |
|
|
|
typedef enum { |
|
|
|
typedef enum { |
|
|
|
UPB_DEFTYPE_MSG = 0, |
|
|
|
UPB_DEFTYPE_MSG = 0, |
|
|
@ -124,12 +130,6 @@ static upb_value pack_def(const void *ptr, upb_deftype_t type) { |
|
|
|
return upb_value_constptr((const void*)num); |
|
|
|
return upb_value_constptr((const void*)num); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct upb_symtab { |
|
|
|
|
|
|
|
upb_arena *arena; |
|
|
|
|
|
|
|
upb_strtable syms; /* full_name -> packed def ptr */ |
|
|
|
|
|
|
|
upb_strtable files; /* file_name -> upb_filedef* */ |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ |
|
|
|
/* isalpha() etc. from <ctype.h> are locale-dependent, which we don't want. */ |
|
|
|
static bool upb_isbetween(char c, char low, char high) { |
|
|
|
static bool upb_isbetween(char c, char low, char high) { |
|
|
|
return c >= low && c <= high; |
|
|
|
return c >= low && c <= high; |
|
|
@ -825,97 +825,6 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter) { |
|
|
|
upb_inttable_iter_setdone(iter); |
|
|
|
upb_inttable_iter_setdone(iter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* upb_filedef ****************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_name(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_package(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->package; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_phpprefix(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->phpprefix; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_phpnamespace(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->phpnamespace; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upb_syntax_t upb_filedef_syntax(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->syntax; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_msgcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->msg_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_depcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->dep_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_enumcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->enum_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->dep_count ? NULL : f->deps[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->enum_count ? NULL : &f->enums[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void upb_symtab_free(upb_symtab *s) { |
|
|
|
|
|
|
|
upb_arena_free(s->arena); |
|
|
|
|
|
|
|
upb_gfree(s); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upb_symtab *upb_symtab_new() { |
|
|
|
|
|
|
|
upb_symtab *s = upb_gmalloc(sizeof(*s)); |
|
|
|
|
|
|
|
upb_alloc *alloc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!s) { |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s->arena = upb_arena_new(); |
|
|
|
|
|
|
|
alloc = upb_arena_alloc(s->arena); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, alloc) || |
|
|
|
|
|
|
|
!upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, alloc)) { |
|
|
|
|
|
|
|
upb_arena_free(s->arena); |
|
|
|
|
|
|
|
upb_gfree(s); |
|
|
|
|
|
|
|
s = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup(&s->syms, sym, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_MSG) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, |
|
|
|
|
|
|
|
size_t len) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup2(&s->syms, sym, len, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_MSG) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup(&s->syms, sym, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_ENUM) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Code to build defs from descriptor protos. *********************************/ |
|
|
|
/* Code to build defs from descriptor protos. *********************************/ |
|
|
|
|
|
|
|
|
|
|
|
/* There is a question of how much validation to do here. It will be difficult
|
|
|
|
/* There is a question of how much validation to do here. It will be difficult
|
|
|
@ -1593,8 +1502,9 @@ static bool build_filedef( |
|
|
|
if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data, |
|
|
|
if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data, |
|
|
|
dep_name.size, &v)) { |
|
|
|
dep_name.size, &v)) { |
|
|
|
upb_status_seterrf(ctx->status, |
|
|
|
upb_status_seterrf(ctx->status, |
|
|
|
"Depends on file '%s', but it has not been loaded", |
|
|
|
"Depends on file '" UPB_STRVIEW_FORMAT |
|
|
|
dep_name.data); |
|
|
|
"', but it has not been loaded", |
|
|
|
|
|
|
|
UPB_STRVIEW_ARGS(dep_name)); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
file->deps[i] = upb_value_getconstptr(v); |
|
|
|
file->deps[i] = upb_value_getconstptr(v); |
|
|
@ -1656,6 +1566,102 @@ static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx, |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* upb_filedef ****************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_name(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_package(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->package; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_phpprefix(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->phpprefix; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *upb_filedef_phpnamespace(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->phpnamespace; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upb_syntax_t upb_filedef_syntax(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->syntax; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_msgcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->msg_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_depcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->dep_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int upb_filedef_enumcount(const upb_filedef *f) { |
|
|
|
|
|
|
|
return f->enum_count; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->dep_count ? NULL : f->deps[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->msg_count ? NULL : &f->msgs[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) { |
|
|
|
|
|
|
|
return i < 0 || i >= f->enum_count ? NULL : &f->enums[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void upb_symtab_free(upb_symtab *s) { |
|
|
|
|
|
|
|
upb_arena_free(s->arena); |
|
|
|
|
|
|
|
upb_gfree(s); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upb_symtab *upb_symtab_new() { |
|
|
|
|
|
|
|
upb_symtab *s = upb_gmalloc(sizeof(*s)); |
|
|
|
|
|
|
|
upb_alloc *alloc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!s) { |
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s->arena = upb_arena_new(); |
|
|
|
|
|
|
|
alloc = upb_arena_alloc(s->arena); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, alloc) || |
|
|
|
|
|
|
|
!upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, alloc)) { |
|
|
|
|
|
|
|
upb_arena_free(s->arena); |
|
|
|
|
|
|
|
upb_gfree(s); |
|
|
|
|
|
|
|
s = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return s; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup(&s->syms, sym, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_MSG) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_msgdef *upb_symtab_lookupmsg2(const upb_symtab *s, const char *sym, |
|
|
|
|
|
|
|
size_t len) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup2(&s->syms, sym, len, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_MSG) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup(&s->syms, sym, &v) ? |
|
|
|
|
|
|
|
unpack_def(v, UPB_DEFTYPE_ENUM) : NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upb_filedef *upb_symtab_lookupfile(const upb_symtab *s, const char *name) { |
|
|
|
|
|
|
|
upb_value v; |
|
|
|
|
|
|
|
return upb_strtable_lookup(&s->files, name, &v) ? upb_value_getconstptr(v) |
|
|
|
|
|
|
|
: NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const upb_filedef *upb_symtab_addfile( |
|
|
|
const upb_filedef *upb_symtab_addfile( |
|
|
|
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, |
|
|
|
upb_symtab *s, const google_protobuf_FileDescriptorProto *file_proto, |
|
|
|
upb_status *status) { |
|
|
|
upb_status *status) { |
|
|
|