WIP, core library compiles now.

pull/13171/head
Joshua Haberman 6 years ago
parent bfa3c015bb
commit 336402b4d7
  1. 33
      BUILD
  2. 216
      CMakeLists.txt
  3. 780
      upb/bindings/lua/def.c
  4. 722
      upb/def.c
  5. 13
      upb/def.h
  6. 4
      upb/handlers.c
  7. 126
      upb/json/parser.c
  8. 3
      upb/json/parser.h
  9. 20
      upb/json/parser.rl
  10. 2
      upb/json/printer.c
  11. 9
      upb/msg.h
  12. 4
      upb/pb/textprinter.c
  13. 196
      upb/structdefs.int.h

33
BUILD

@ -27,7 +27,6 @@ cc_library(
"upb/port_undef.inc",
"upb/refcounted.c",
"upb/sink.c",
"upb/structdefs.int.h",
"upb/structs.int.h",
"upb/table.c",
"upb/table.int.h",
@ -429,13 +428,6 @@ proto_library(
],
)
genrule(
name = "copy_google_descriptor_pb",
srcs = [":google_descriptor_proto"],
outs = ["generated/google/protobuf/descriptor.pb"],
cmd = "cp $< $@",
)
genrule(
name = "generate_descriptor_c",
srcs = ["google/protobuf/descriptor.proto"],
@ -462,16 +454,16 @@ genrule(
cmd = "cp $< $@",
)
genrule(
name = "generated_json_test_proto_upbdefs",
srcs = ["generated/tests/json/test.proto.pb"],
outs = [
"generated/tests/json/test.upbdefs.h",
"generated/tests/json/test.upbdefs.c",
],
cmd = "UPBC=$$PWD/$(location :lua_upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC --generate-upbdefs $$INFILE",
tools = [":lua_upbc"],
)
#genrule(
# name = "generated_json_test_proto_upbdefs",
# srcs = ["generated/tests/json/test.proto.pb"],
# outs = [
# "generated/tests/json/test.upbdefs.h",
# "generated/tests/json/test.upbdefs.c",
# ],
# cmd = "UPBC=$$PWD/$(location :lua_upbc); INFILE=$$PWD/$<; cd $(GENDIR)/generated && $$UPBC --generate-upbdefs $$INFILE",
# tools = [":lua_upbc"],
#)
genrule(
name = "generate_json_ragel",
@ -488,11 +480,6 @@ generated_file_staleness_test(
"google/protobuf/descriptor.upb.c",
"google/protobuf/descriptor.upb.h",
"tests/json/test.proto.pb",
"tests/json/test.upbdefs.c",
"tests/json/test.upbdefs.h",
"upb/descriptor/descriptor.pb",
"upb/descriptor/descriptor.upbdefs.c",
"upb/descriptor/descriptor.upbdefs.h",
"upb/json/parser.c",
"upb/pb/compile_decoder_x64.h",
],

@ -57,209 +57,6 @@ elseif(UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id")
endif()
<<<<<<< HEAD
FIND_PACKAGE(Lua)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/Makefile.am")
set(PROTOBUF_FOUND TRUE)
endif()
find_program(RAGEL NAMES ragel)
if(LUA_FOUND)
include_directories(${LUA_INCLUDE_DIR})
add_library(upb_c SHARED
upb/bindings/lua/upb.c
upb/bindings/lua/def.c
upb/bindings/lua/msg.c
)
target_link_libraries(upb_c LINK_PRIVATE
upbpb_pic
upbdef_pic
upbhandlers_pic upb_pic )
add_library(pb_c SHARED
upb/bindings/lua/upb/pb.c
)
target_link_libraries(pb_c LINK_PRIVATE upb_c upbpb_pic)
set_target_properties(upb_c
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua"
PREFIX ""
SUFFIX ".so")
set_target_properties(pb_c
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua/upb"
PREFIX ""
SUFFIX ".so")
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
DEPENDS ${CMAKE_SOURCE_DIR}/tools/upbc
${CMAKE_SOURCE_DIR}/tools/upbc.lua
${CMAKE_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
upb_c
pb_c
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/tools/upbc
${CMAKE_SOURCE_DIR}/tools/upbc.lua
${CMAKE_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_CURRENT_BINARY_DIR}/tools)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb.lua
DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua
${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua
DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua
${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua/upb)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
DEPENDS upb/pb/compile_decoder_x64.dasc
COMMAND
cd ${CMAKE_CURRENT_SOURCE_DIR} &&
lua third_party/dynasm/dynasm.lua
-c upb/pb/compile_decoder_x64.dasc
> ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
)
add_custom_target(
genfiles2 ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h
)
add_test(
NAME testlua
COMMAND lua ${CMAKE_SOURCE_DIR}/tests/bindings/lua/test_upb.lua
${CMAKE_SOURCE_DIR}/tests/bindings/lua/test_upb.pb.lua
)
set_property(TEST testlua PROPERTY ENVIRONMENT
LUA_PATH=${CMAKE_SOURCE_DIR}/third_party/lunit/?.lua$<SEMICOLON>${CMAKE_SOURCE_DIR}/upb/bindings/lua/?.lua
LUA_CPATH=${CMAKE_BINARY_DIR}/upb/bindings/lua/?.so
)
set_tests_properties(testlua
PROPERTIES
DEPENDS "upb_c;pb_c"
)
enable_testing()
endif()
if(LUA_FOUND AND PROTOBUF_FOUND)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE)
set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE)
set(protobuf_BUILD_CONFORMANCE ON CACHE BOOL "Build conformance tests" FORCE)
add_subdirectory(third_party/protobuf/cmake)
add_custom_target(
upbc ALL
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/make_c_api.lua
${CMAKE_CURRENT_SOURCE_DIR}/tools/upbc.lua
${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_BINARY_DIR}/lua/upb.lua
${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c
${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto
COMMAND protoc --include_imports
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto
${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/src/google/protobuf/test_messages_proto3.proto
-I${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance
-I${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/src
-o${CMAKE_CURRENT_BINARY_DIR}/conformance.pb &&
tools/upbc ${CMAKE_CURRENT_BINARY_DIR}/conformance.pb
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.c
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc
${CMAKE_CURRENT_SOURCE_DIR}/google/protobuf/descriptor.proto
COMMAND protoc
${CMAKE_CURRENT_SOURCE_DIR}/google/protobuf/descriptor.proto
-I${CMAKE_CURRENT_SOURCE_DIR}
-o${CMAKE_CURRENT_BINARY_DIR}/descriptor.pb &&
tools/upbc ${CMAKE_CURRENT_BINARY_DIR}/descriptor.pb
)
add_custom_target(
genfiles ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h
)
add_executable(conformance_upb
tests/conformance_upb.c
${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c
${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c
)
target_link_libraries(conformance_upb LINK_PRIVATE
upb
)
add_custom_target(
conformance
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb
${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb
)
endif()
if (RAGEL)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c
DEPENDS upb/json/parser.rl
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && RAGEL -C -o ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c upb/json/parser.rl
)
endif()
configure_file(tools/copy_genfiles.sh.in tools/copy_genfiles.sh)
set(UPB_SRCS
upb/decode.c
upb/encode.c
upb/msg.c
upb/table.c
upb/upb.c
)
set (UPBDEF_SRCS
upb/def.c
upb/msgfactory.c
)
set(UPBHANDLERS_SRCS
upb/sink.c
upb/handlers.c
)
set(UPBPB_SRCS
=======
enable_testing()
add_library(upb
@ -290,15 +87,7 @@ add_library(upb
upb/refcounted.h
upb/sink.h
upb/upb.h)
add_library(upb_descriptor
upb/descriptor/descriptor.upbdefs.c
upb/descriptor/reader.c
upb/descriptor/descriptor.upbdefs.h
upb/descriptor/reader.h)
target_link_libraries(upb_descriptor
upb)
add_library(upb_pb
>>>>>>> cmake-mac-fixes
upb/pb/compile_decoder.c
upb/pb/decoder.c
upb/pb/decoder.int.h
@ -308,11 +97,9 @@ add_library(upb_pb
upb/pb/varint.int.h
upb/pb/decoder.h
upb/pb/encoder.h
upb/pb/glue.h
upb/pb/textprinter.h)
target_link_libraries(upb_pb
upb
upb_descriptor)
upb)
add_library(upb_json
upb/json/parser.c
upb/json/printer.c
@ -369,7 +156,6 @@ add_executable(test_cpp
add_test(NAME test_cpp COMMAND test_cpp)
target_link_libraries(test_cpp
upb
upb_descriptor
upb_pb
upb_test)
add_executable(test_table

File diff suppressed because it is too large Load Diff

@ -2,8 +2,10 @@
#include "upb/def.h"
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "google/protobuf/descriptor.upb.h"
#include "upb/handlers.h"
typedef struct {
@ -29,6 +31,7 @@ struct upb_fielddef {
uint64_t uint;
double dbl;
float flt;
bool boolean;
str_t *str;
} defaultval;
const upb_msgdef *msgdef;
@ -48,14 +51,11 @@ struct upb_fielddef {
};
struct upb_msgdef {
upb_filedef *file;
const upb_filedef *file;
const char *full_name;
uint32_t selector_count;
uint32_t submsg_field_count;
upb_fielddef **fields;
upb_oneofdef **oneofs;
/* Tables for looking up fields by number and name. */
upb_inttable itof;
upb_strtable ntof;
@ -82,11 +82,6 @@ struct upb_oneofdef {
upb_inttable itof;
};
struct upb_symtab {
upb_arena arena;
upb_strtable symtab;
};
struct upb_filedef {
const char *name;
const char *package;
@ -94,8 +89,37 @@ struct upb_filedef {
const char *phpnamespace;
upb_syntax_t syntax;
upb_inttable defs;
upb_inttable deps;
const upb_msgdef **msgs;
const upb_enumdef **enums;
const upb_filedef **deps;
int msgcount;
int enumcount;
int depcount;
};
/* Inside a symtab we store tagged pointers to specific def types. */
typedef enum {
UPB_DEFTYPE_MSG = 0,
UPB_DEFTYPE_ENUM = 1,
UPB_DEFTYPE_FIELD = 2,
UPB_DEFTYPE_ONEOF = 3
} upb_deftype_t;
static const void *unpack_def(upb_value v, upb_deftype_t type) {
uintptr_t num = (uintptr_t)upb_value_getconstptr(v);
return (num & 3) == type ? (const void*)(num & ~3) : NULL;
}
static upb_value pack_def(const void *ptr, upb_deftype_t type) {
uintptr_t num = (uintptr_t)ptr | type;
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. */
@ -111,7 +135,9 @@ static bool upb_isalphanum(char c) {
return upb_isletter(c) || upb_isbetween(c, '0', '9');
}
static bool upb_isident(const char *str, size_t len, bool full, upb_status *s) {
static bool upb_isident(upb_stringview name, bool full, upb_status *s) {
const char *str = name.data;
size_t len = name.size;
bool start = true;
size_t i;
for (i = 0; i < len; i++) {
@ -141,7 +167,7 @@ static bool upb_isident(const char *str, size_t len, bool full, upb_status *s) {
return !start;
}
static const char *shortname(const char *fullname) {
static const char *shortdefname(const char *fullname) {
const char *p;
if (fullname == NULL) {
@ -388,22 +414,12 @@ err:
/* upb_enumdef ****************************************************************/
#if 0
bool upb_enumdef_init(upb_enumdef *e) {
upb_def_init(&e->base, UPB_DEF_ENUM);
if (!upb_strtable_init(&e->ntoi, UPB_CTYPE_INT32)) goto err2;
if (!upb_inttable_init(&e->iton, UPB_CTYPE_CSTR)) goto err1;
return true;
}
#endif
const char *upb_enumdef_fullname(const upb_enumdef *e) {
return e->full_name;
}
const char *upb_enumdef_name(const upb_enumdef *e) {
return shortname(e->full_name);
return shortdefname(e->full_name);
}
#if 0
@ -499,43 +515,10 @@ int32_t upb_enum_iter_number(upb_enum_iter *iter) {
/* upb_fielddef ***************************************************************/
static void upb_fielddef_init_default(upb_fielddef *f);
const char *upb_fielddef_fullname(const upb_fielddef *f) {
return f->full_name;
}
#if 0
upb_fielddef *upb_fielddef_new(const void *o) {
upb_fielddef *f = upb_gmalloc(sizeof(*f));
if (!f) return NULL;
upb_def_init(&f->base, UPB_DEF_FIELD);
f->msg.def = NULL;
f->sub.def = NULL;
f->oneof = NULL;
f->subdef_is_symbolic = false;
f->label_ = UPB_LABEL_OPTIONAL;
f->type_ = UPB_TYPE_INT32;
f->number_ = 0;
f->type_is_set_ = false;
f->tagdelim = false;
f->is_extension_ = false;
f->lazy_ = false;
f->packed_ = true;
/* For the moment we default this to UPB_INTFMT_VARIABLE, since it will work
* with all integer types and is in some since more "default" since the most
* normal-looking proto2 types int32/int64/uint32/uint64 use variable.
*
* Other options to consider:
* - there is no default; users must set this manually (like type).
* - default signed integers to UPB_INTFMT_ZIGZAG, since it's more likely to
* be an optimal default for signed integers. */
f->intfmt = UPB_INTFMT_VARIABLE;
return f;
}
#endif
upb_fieldtype_t upb_fielddef_type(const upb_fielddef *f) {
switch (f->type_) {
case UPB_DESCRIPTOR_TYPE_DOUBLE:
@ -699,32 +682,6 @@ const char *upb_fielddef_defaultstr(const upb_fielddef *f, size_t *len) {
return str->str;
}
#if 0
static void upb_fielddef_init_default(upb_fielddef *f) {
f->default_is_string = false;
switch (upb_fielddef_type(f)) {
case UPB_TYPE_DOUBLE: f->defaultval.dbl = 0; break;
case UPB_TYPE_FLOAT: f->defaultval.flt = 0; break;
case UPB_TYPE_INT32:
case UPB_TYPE_INT64: f->defaultval.sint = 0; break;
case UPB_TYPE_UINT64:
case UPB_TYPE_UINT32:
case UPB_TYPE_BOOL: f->defaultval.uint = 0; break;
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
f->defaultval.bytes = newstr("", 0);
f->default_is_string = true;
break;
case UPB_TYPE_MESSAGE: break;
case UPB_TYPE_ENUM:
/* This is our special sentinel that indicates "not set" for an enum. */
f->default_is_string = true;
f->defaultval.bytes = NULL;
break;
}
}
#endif
const upb_msgdef *upb_fielddef_msgsubdef(const upb_fielddef *f) {
UPB_ASSERT(upb_fielddef_type(f) == UPB_TYPE_MESSAGE);
return f->sub.msgdef;
@ -735,38 +692,6 @@ const upb_enumdef *upb_fielddef_enumsubdef(const upb_fielddef *f) {
return f->sub.enumdef;
}
#if 0
bool upb_fielddef_setnumber(upb_fielddef *f, uint32_t number, upb_status *s) {
if (upb_fielddef_containingtype(f)) {
upb_status_seterrmsg(
s, "cannot change field number after adding to a message");
return false;
}
if (number == 0 || number > UPB_MAX_FIELDNUMBER) {
upb_status_seterrf(s, "invalid field number (%u)", number);
return false;
}
f->number_ = number;
return true;
}
static bool upb_subdef_typecheck(upb_fielddef *f, const upb_def *subdef,
upb_status *s) {
if (f->type_ == UPB_TYPE_MESSAGE) {
if (upb_dyncast_msgdef(subdef)) return true;
upb_status_seterrmsg(s, "invalid subdef type for this submessage field");
return false;
} else if (f->type_ == UPB_TYPE_ENUM) {
if (upb_dyncast_enumdef(subdef)) return true;
upb_status_seterrmsg(s, "invalid subdef type for this enum field");
return false;
} else {
upb_status_seterrmsg(s, "only message and enum fields can have a subdef");
return false;
}
}
#endif
bool upb_fielddef_issubmsg(const upb_fielddef *f) {
return upb_fielddef_type(f) == UPB_TYPE_MESSAGE;
}
@ -812,7 +737,7 @@ const char *upb_msgdef_fullname(const upb_msgdef *m) {
}
const char *upb_msgdef_name(const upb_msgdef *m) {
return shortname(m->full_name);
return shortdefname(m->full_name);
}
upb_syntax_t upb_msgdef_syntax(const upb_msgdef *m) {
@ -827,16 +752,6 @@ static bool check_field_add(const upb_msgdef *m, const upb_fielddef *f,
if (upb_fielddef_containingtype(f) != NULL) {
upb_status_seterrmsg(s, "fielddef already belongs to a message");
return false;
} else if (upb_fielddef_name(f) == NULL || upb_fielddef_number(f) == 0) {
upb_status_seterrmsg(s, "field name or number were not set");
return false;
} else if (upb_msgdef_itof(m, upb_fielddef_number(f))) {
upb_status_seterrmsg(s, "duplicate field number");
return false;
} else if (upb_strtable_lookup(&m->ntof, upb_fielddef_name(f), NULL)) {
upb_status_seterrmsg(s, "name conflicts with existing field or oneof");
return false;
}
return true;
}
@ -1156,38 +1071,6 @@ void upb_oneof_iter_setdone(upb_oneof_iter *iter) {
/* upb_filedef ****************************************************************/
upb_filedef *upb_filedef_new(const void *owner) {
upb_filedef *f = upb_gmalloc(sizeof(*f));
if (!f) {
return NULL;
}
f->package = NULL;
f->name = NULL;
f->phpprefix = NULL;
f->phpnamespace = NULL;
f->syntax = UPB_SYNTAX_PROTO2;
if (!upb_inttable_init(&f->defs, UPB_CTYPE_CONSTPTR)) {
goto err;
}
if (!upb_inttable_init(&f->deps, UPB_CTYPE_CONSTPTR)) {
goto err2;
}
return f;
err2:
upb_inttable_uninit(&f->defs);
err:
upb_gfree(f);
return NULL;
}
const char *upb_filedef_name(const upb_filedef *f) {
return f->name;
}
@ -1208,32 +1091,28 @@ upb_syntax_t upb_filedef_syntax(const upb_filedef *f) {
return f->syntax;
}
size_t upb_filedef_defcount(const upb_filedef *f) {
return upb_inttable_count(&f->defs);
int upb_filedef_msgcount(const upb_filedef *f) {
return f->msgcount;
}
size_t upb_filedef_depcount(const upb_filedef *f) {
return upb_inttable_count(&f->deps);
int upb_filedef_depcount(const upb_filedef *f) {
return f->depcount;
}
const upb_def *upb_filedef_def(const upb_filedef *f, size_t i) {
upb_value v;
int upb_filedef_enumcount(const upb_filedef *f) {
return f->enumcount;
}
if (upb_inttable_lookup32(&f->defs, i, &v)) {
return upb_value_getconstptr(v);
} else {
return NULL;
}
const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i) {
return i < 0 || i >= f->depcount ? NULL : f->deps[i];
}
const upb_filedef *upb_filedef_dep(const upb_filedef *f, size_t i) {
upb_value v;
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i) {
return i < 0 || i >= f->msgcount ? NULL : f->msgs[i];
}
if (upb_inttable_lookup32(&f->deps, i, &v)) {
return upb_value_getconstptr(v);
} else {
return NULL;
}
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i) {
return i < 0 || i >= f->enumcount ? NULL : f->enums[i];
}
void upb_symtab_free(upb_symtab *s) {
@ -1243,53 +1122,44 @@ void upb_symtab_free(upb_symtab *s) {
upb_symtab *upb_symtab_new() {
upb_symtab *s = upb_gmalloc(sizeof(*s));
upb_alloc *alloc;
if (!s) {
return NULL;
}
if (!upb_arena_init(&s->arena)) goto err2;
if (!upb_strtable_init2(&s->symtab, UPB_CTYPE_PTR,
upb_arena_alloc(&s->arena))) {
goto err1;
}
return s;
upb_arena_init(&s->arena);
alloc = upb_arena_alloc(&s->arena);
err1:
upb_arena_uninit(&s->arena);
err2:
upb_gfree(s);
if (!upb_strtable_init2(&s->syms, UPB_CTYPE_CONSTPTR, alloc) ||
!upb_strtable_init2(&s->files, UPB_CTYPE_CONSTPTR, alloc)) {
upb_arena_uninit(&s->arena);
upb_gfree(s);
s = NULL;
}
return s;
}
const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym) {
upb_value v;
upb_def *ret = upb_strtable_lookup(&s->symtab, sym, &v) ?
upb_value_getptr(v) : NULL;
return ret;
}
const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym) {
upb_value v;
upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
upb_value_getptr(v) : NULL;
return def ? upb_dyncast_msgdef(def) : NULL;
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;
upb_def *def = upb_strtable_lookup2(&s->symtab, sym, len, &v) ?
upb_value_getptr(v) : NULL;
return def ? upb_dyncast_msgdef(def) : NULL;
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;
upb_def *def = upb_strtable_lookup(&s->symtab, sym, &v) ?
upb_value_getptr(v) : NULL;
return def ? upb_dyncast_enumdef(def) : NULL;
return upb_strtable_lookup(&s->syms, sym, &v) ?
unpack_def(v, UPB_DEFTYPE_ENUM) : NULL;
}
#if 0
/* Given a symbol and the base symbol inside which it is defined, find the
* symbol's definition in t. */
static upb_def *upb_resolvename(const upb_strtable *t,
@ -1311,11 +1181,10 @@ static upb_def *upb_resolvename(const upb_strtable *t,
const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
const char *sym) {
upb_def *ret = upb_resolvename(&s->symtab, base, sym);
upb_def *ret = upb_resolvename(&s->syms, base, sym);
return ret;
}
#if 0
/* Now using the table, resolve symbolic references for subdefs. */
upb_strtable_begin(&iter, &addtab);
for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
@ -1338,7 +1207,7 @@ const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
* there, try existing defs. */
upb_def *subdef = upb_resolvename(&addtab, base, name);
if (subdef == NULL) {
subdef = upb_resolvename(&s->symtab, base, name);
subdef = upb_resolvename(&s->syms, base, name);
}
if (subdef == NULL) {
upb_status_seterrf(
@ -1352,76 +1221,258 @@ const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base,
}
#endif
/* Code to build defs from descriptor protos. *********************************/
/* There is a question of how much validation to do here. It will be difficult
* to perfectly match the amount of validation performed by proto2. But since
* this code is used to directly build defs from Ruby (for example) we do need
* to validate important constraints like uniqueness of names and numbers. */
#define CHK(x) if (!(x)) return false
#define CHK_OOM(x) if (!(x)) { upb_upberr_setoom(ctx->status); return false; }
typedef struct {
const upb_symtab *symtab;
const upb_filedef *file; /* File we are building. */
upb_alloc *alloc; /* Allocate defs here. */
upb_alloc *tmp; /* Alloc for addtab and any other tmp data. */
upb_strtable *addtab; /* full_name -> packed def ptr for new defs. */
upb_status *status; /* Record errors here. */
} symtab_addctx;
static const char *makefullname(const char *prefix, upb_stringview name) {
return NULL;
}
static bool symtab_add(const symtab_addctx *ctx, const char *name,
upb_value v) {
upb_value tmp;
if (upb_strtable_lookup(ctx->addtab, name, &tmp) ||
upb_strtable_lookup(&ctx->symtab->syms, name, &tmp)) {
upb_status_seterrf(ctx->status, "Duplicate symbol '%s'", name);
return false;
}
CHK_OOM(upb_strtable_insert3(ctx->addtab, name, strlen(name), v, ctx->tmp));
return true;
}
static bool create_oneofdef(
upb_symtab *s, const google_protobuf_OneofDescriptorProto *oneof_proto,
upb_msgdef *m, upb_status *s) {
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_oneofdef *o = upb_malloc(alloc, sizeof(upb_oneofdef));
const symtab_addctx *ctx, upb_msgdef *m,
const google_protobuf_OneofDescriptorProto *oneof_proto) {
upb_oneofdef *o = upb_malloc(ctx->alloc, sizeof(*o));
upb_stringview name = google_protobuf_OneofDescriptorProto_name(oneof_proto);
upb_value o_ptr = upb_value_ptr(o);
CHK(o);
CHK(upb_inttable_init2(&o->itof, UPB_CTYPE_PTR, alloc));
CHK(upb_strtable_init2(&o->ntof, UPB_CTYPE_PTR, alloc));
CHK_OOM(o);
CHK_OOM(upb_inttable_init2(&o->itof, UPB_CTYPE_PTR, ctx->alloc));
CHK_OOM(upb_strtable_init2(&o->ntof, UPB_CTYPE_PTR, ctx->alloc));
o->index = upb_strtable_count(&m->ntof);
o->name = upb_strdup2(name.data, name.size, alloc);
o->name = upb_strdup2(name.data, name.size, ctx->alloc);
o->parent = m;
CHK(upb_strtable_insert3(&m->ntof, name.data, name.size, o_ptr, alloc));
CHK_OOM(upb_strtable_insert3(&m->ntof, name.data, name.size, o_ptr,
ctx->alloc));
return true;
}
static bool create_field(
upb_symtab *s, const google_protobuf_FieldDescriptorProto *field_proto,
upb_msgdef *m, upb_status *s) {
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_fielddef *f = upb_malloc(alloc, sizeof(upb_fielddef));
const google_protobuf_MessageOptions *options;
static bool parse_default(const char *str, size_t len, upb_fielddef *f) {
char *end;
switch (upb_fielddef_type(f)) {
case UPB_TYPE_INT32: {
long val = strtol(str, &end, 0);
CHK(val <= INT32_MAX && val >= INT32_MIN && errno != ERANGE && !*end);
f->defaultval.sint = val;
break;
}
case UPB_TYPE_ENUM:
case UPB_TYPE_INT64: {
/* XXX: Need to write our own strtoll, since it's not available in c89. */
long long val = strtol(str, &end, 0);
CHK(val <= INT64_MAX && val >= INT64_MIN && errno != ERANGE && !*end);
f->defaultval.sint = val;
break;
}
case UPB_TYPE_UINT32: {
unsigned long val = strtoul(str, &end, 0);
CHK(val <= UINT32_MAX && errno != ERANGE && !*end);
f->defaultval.uint = val;
break;
}
case UPB_TYPE_UINT64: {
/* XXX: Need to write our own strtoull, since it's not available in c89. */
unsigned long long val = strtoul(str, &end, 0);
CHK(val <= UINT64_MAX && errno != ERANGE && !*end);
f->defaultval.uint = val;
break;
}
case UPB_TYPE_DOUBLE: {
double val = strtod(str, &end);
CHK(errno != ERANGE && !*end);
f->defaultval.dbl = val;
break;
}
case UPB_TYPE_FLOAT: {
/* XXX: Need to write our own strtof, since it's not available in c89. */
float val = strtod(str, &end);
CHK(errno != ERANGE && !*end);
f->defaultval.dbl = val;
break;
}
case UPB_TYPE_BOOL: {
if (strcmp(str, "false") == 0) {
f->defaultval.boolean = false;
} else if (strcmp(str, "true") == 0) {
f->defaultval.boolean = true;
} else {
return false;
}
}
case UPB_TYPE_STRING:
f->defaultval.str = newstr(str, len);
break;
case UPB_TYPE_BYTES:
/* XXX: need to interpret the C-escaped value. */
f->defaultval.str = newstr(str, len);
case UPB_TYPE_MESSAGE:
/* Should not have a default value. */
return false;
}
return true;
}
static bool create_fielddef(
const symtab_addctx *ctx, const char *prefix, upb_msgdef *m,
const google_protobuf_FieldDescriptorProto *field_proto) {
upb_alloc *alloc = ctx->alloc;
upb_fielddef *f = upb_malloc(ctx->alloc, sizeof(*f));
const google_protobuf_FieldOptions *options;
upb_stringview defaultval, name;
upb_value packed_v = pack_def(f, UPB_DEFTYPE_FIELD);
upb_value v = upb_value_constptr(f);
const char *shortname;
CHK_OOM(f);
memset(f, 0, sizeof(*f));
name = google_protobuf_FieldDescriptorProto_name(field_proto);
/* TODO(haberman): use hazzers. */
if (name.size == 0 || f->number_ == 0) {
upb_status_seterrmsg(ctx->status, "field name or number were not set");
return false;
}
CHK(upb_isident(name, false, ctx->status));
f->full_name = makefullname(prefix, name);
f->type_ = (int)google_protobuf_FieldDescriptorProto_type(field_proto);
f->label_ = (int)google_protobuf_FieldDescriptorProto_label(field_proto);
f->number_ = google_protobuf_FieldDescriptorProto_number(field_proto);
shortname = shortdefname(f->full_name);
if (f->number_ == 0 || f->number_ > UPB_MAX_FIELDNUMBER) {
upb_status_seterrf(ctx->status, "invalid field number (%u)", f->number_);
return false;
}
#if 0
//f->oneof
//f->sub
#endif
defaultval = google_protobuf_FieldDescriptorProto_default_value(field_proto);
if (defaultval.data) {
CHK(parse_default(defaultval.data, defaultval.size, f));
}
options = google_protobuf_FieldDescriptorProto_options(field_proto);
if (options) {
f->lazy_ = google_protobuf_FieldOptions_lazy(options);
f->packed_ = google_protobuf_FieldOptions_packed(options);
}
if (m) {
/* direct message field. */
if (!upb_strtable_insert3(&m->ntof, name.data, name.size, packed_v, alloc)) {
upb_status_seterrf(ctx->status, "duplicate name (%s)", shortname);
return false;
}
if (!upb_inttable_insert2(&m->itof, f->number_, v, alloc)) {
upb_status_seterrf(ctx->status, "duplicate field number (%u)", f->number_);
return false;
}
f->msgdef = m;
f->is_extension_ = false;
} else {
/* extension field. */
f->is_extension_ = true;
}
return true;
}
static bool create_enumdef(
const symtab_addctx *ctx, const char *prefix,
const google_protobuf_EnumDescriptorProto *enum_proto) {
upb_enumdef *e = upb_malloc(ctx->alloc, sizeof(*e));
const upb_array *arr;
upb_stringview name;
size_t i;
CHK(f);
name = google_protobuf_EnumDescriptorProto_name(enum_proto);
CHK(upb_isident(name, false, ctx->status));
f->msgdef = m;
e->full_name = makefullname(prefix, name);
e->defaultval = 0;
union {
int64_t sint;
uint64_t uint;
double dbl;
float flt;
void *bytes;
} defaultval;
const upb_msgdef *msgdef;
union {
const upb_msgdef *msgdef;
const upb_msgdef *enumdef;
} sub;
const upb_oneofdef *oneof;
bool is_extension_;
bool lazy_;
bool packed_;
upb_intfmt_t intfmt;
bool tagdelim;
upb_fieldtype_t type_;
upb_label_t label_;
uint32_t number_;
uint32_t selector_base; /* Used to index into a upb::Handlers table. */
uint32_t index_;
CHK_OOM(e);
CHK_OOM(upb_strtable_init2(&e->ntoi, UPB_CTYPE_INT32, ctx->alloc));
CHK_OOM(upb_inttable_init2(&e->iton, UPB_CTYPE_CSTR, ctx->alloc));
arr = google_protobuf_EnumDescriptorProto_value(enum_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_EnumValueDescriptorProto *value =
upb_msgval_getptr(upb_array_get(arr, i));
upb_stringview name = google_protobuf_EnumValueDescriptorProto_name(value);
char *name2 = upb_strdup2(name.data, name.size, ctx->alloc);
int32_t num = google_protobuf_EnumValueDescriptorProto_number(value);
upb_value v = upb_value_int32(num);
CHK_OOM(name2 && upb_strtable_insert(&e->ntoi, name2, v));
if (!upb_inttable_lookup(&e->iton, num, NULL)) {
CHK_OOM(upb_inttable_insert(&e->iton, num, upb_value_cstr(name2)));
}
}
return true;
}
static bool create_msgdef(upb_symtab *s,
const google_protobuf_DescriptorProto *msg_proto,
upb_symtab *addtab, upb_status *status) {
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_msgdef *m = upb_malloc(alloc, sizeof(upb_msgdef));
static bool create_msgdef(const symtab_addctx *ctx, const char *prefix,
const google_protobuf_DescriptorProto *msg_proto) {
upb_msgdef *m = upb_malloc(ctx->alloc, sizeof(upb_msgdef));
const google_protobuf_MessageOptions *options;
const upb_array *arr;
size_t i;
upb_stringview name;
CHK(m);
CHK(upb_inttable_init2(&m->itof, UPB_CTYPE_PTR, alloc));
CHK(upb_strtable_init2(&m->ntof, UPB_CTYPE_PTR, alloc));
CHK_OOM(m);
CHK_OOM(upb_inttable_init2(&m->itof, UPB_CTYPE_PTR, ctx->alloc));
CHK_OOM(upb_strtable_init2(&m->ntof, UPB_CTYPE_PTR, ctx->alloc));
name = google_protobuf_DescriptorProto_name(msg_proto);
CHK(upb_isident(name, false, ctx->status));
m->file = ctx->file;
m->full_name = makefullname(prefix, name);
m->map_entry = false;
options = google_protobuf_DescriptorProto_options(msg_proto);
@ -1434,118 +1485,181 @@ static bool create_msgdef(upb_symtab *s,
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_OneofDescriptorProto *oneof_proto =
(const void *)upb_array_get(arr, i);
CHK(create_oneofdef(s, oneof_proto, m, status));
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_oneofdef(ctx, m, oneof_proto));
}
arr = google_protobuf_DescriptorProto_field(msg_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_FieldDescriptorProto *field_proto =
(const void *)upb_array_get(arr, i);
CHK(create_fielddef(s, field_proto, m, status));
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_fielddef(ctx, m->full_name, m, field_proto));
}
CHK(assign_msg_indices(m, ctx->status));
assign_msg_wellknowntype(m);
symtab_add(ctx, m->full_name, pack_def(m, UPB_DEFTYPE_MSG));
/* This message is built. Now build nested messages and enums. */
arr = google_protobuf_DescriptorProto_enum_type(msg_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_EnumDescriptorProto *enum_proto =
(const void *)upb_array_get(arr, i);
CHK(create_enumdef(s, enum_proto, addtab, status));
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_enumdef(ctx, m->full_name, enum_proto));
}
arr = google_protobuf_DescriptorProto_nested_type(msg_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_DescriptorProto *msg_proto2 =
(const void *)upb_array_get(arr, i);
CHK(create_msgdef(s, msg_proto2, addtab, status));
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_msgdef(ctx, m->full_name, msg_proto2));
}
return true;
}
static char* strviewdup(upb_symtab *symtab, upb_stringview view) {
static char* strviewdup(const symtab_addctx *ctx, upb_stringview view) {
if (view.size == 0) {
return NULL;
}
return upb_strdup2(view.data, view.size, upb_arena_alloc(&symtab->arena));
return upb_strdup2(view.data, view.size, ctx->alloc);
}
bool upb_symtab_addfile(upb_symtab *s, const char *buf, size_t len,
upb_status *status) {
upb_arena tmparena;
upb_strtable addtab;
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_stringview serialized = upb_stringview_make(buf, len);
const google_protobuf_FileDescriptorProto *file_proto;
static bool build_filedef(
const symtab_addctx *ctx, upb_filedef *file,
const google_protobuf_FileDescriptorProto *file_proto) {
const google_protobuf_FileOptions *file_options_proto;
upb_filedef *file = upb_malloc(alloc, sizeof(*file));
const upb_array *arr;
upb_strtable_iter iter;
size_t i;
upb_arena_init(&tmparena);
upb_strtable_init2(&addtab, UPB_CTYPE_PTR, upb_arena_alloc(&tmparena));
file_proto =
google_protobuf_FileDescriptorProto_parsenew(serialized, &tmparena);
const upb_array *arr;
size_t i, n;
upb_stringview syntax, package;
if (!file_proto || !file) goto err;
package = google_protobuf_FileDescriptorProto_package(file_proto);
CHK(upb_isident(package, true, ctx->status));
file->name =
strviewdup(s, google_protobuf_FileDescriptorProto_name(file_proto));
file->package =
strviewdup(s, google_protobuf_FileDescriptorProto_package(file_proto));
strviewdup(ctx, google_protobuf_FileDescriptorProto_name(file_proto));
file->package = strviewdup(ctx, package);
file->phpprefix = NULL;
file->phpnamespace = NULL;
syntax = google_protobuf_FileDescriptorProto_syntax(file_proto);
if (upb_stringview_eql(syntax, upb_stringview_makez("proto2"))) {
file->syntax = UPB_SYNTAX_PROTO2;
} else if (upb_stringview_eql(syntax, upb_stringview_makez("proto3"))) {
file->syntax = UPB_SYNTAX_PROTO3;
} else {
upb_status_seterrf(ctx->status, "Invalid syntax '%s'", syntax);
return false;
}
/* Read options. */
file_options_proto = google_protobuf_FileDescriptorProto_options(file_proto);
if (file_options_proto) {
file->phpprefix =
strviewdup(s, google_protobuf_FileOptions_php_class_prefix(file_proto));
file->phpnamespace =
strviewdup(s, google_protobuf_FileOptions_php_namespace(file_proto));
file->phpprefix = strviewdup(
ctx, google_protobuf_FileOptions_php_class_prefix(file_options_proto));
file->phpnamespace = strviewdup(
ctx, google_protobuf_FileOptions_php_namespace(file_options_proto));
}
arr = google_protobuf_FileDescriptorProto_message_type(file_proto);
/* Resolve dependencies. */
arr = google_protobuf_FileDescriptorProto_dependency(file_proto);
n = upb_array_size(arr);
file->deps = upb_malloc(ctx->alloc, sizeof(*file->deps) * n) ;
CHK_OOM(file->deps);
for (i = 0; i < n; i++) {
upb_stringview dep_name = upb_msgval_getstr(upb_array_get(arr, i));
upb_value v;
if (!upb_strtable_lookup2(&ctx->symtab->files, dep_name.data,
dep_name.size, &v)) {
upb_status_seterrf(ctx->status,
"Depends on file '%s', but it has not been loaded",
dep_name.data);
return false;
}
file->deps[i] = upb_value_getconstptr(v);
}
/* Create messages. */
arr = google_protobuf_FileDescriptorProto_message_type(file_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_DescriptorProto *msg_proto =
(const void *)upb_array_get(arr, i);
if (!create_msgdef(s, msg_proto, &addtab, status)) goto err;
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_msgdef(ctx, file->package, msg_proto));
}
arr = google_protobuf_FileDescriptorProto_enum_type(file_proto);
/* Create enums. */
arr = google_protobuf_FileDescriptorProto_enum_type(file_proto);
for (i = 0; i < upb_array_size(arr); i++) {
const google_protobuf_EnumDescriptorProto *enum_proto =
(const void *)upb_array_get(arr, i);
if (!create_enumdef(s, enum_proto, &addtab, status)) goto err;
upb_msgval_getptr(upb_array_get(arr, i));
CHK(create_enumdef(ctx, file->package, enum_proto));
}
/* Now that all names are in the table, resolve references. */
upb_strtable_begin(&iter, &addtab);
upb_strtable_begin(&iter, ctx->addtab);
for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
}
/* Success; add addtab to symtab. */
upb_strtable_begin(&iter, &addtab);
return true;
}
static bool upb_symtab_addtotabs(upb_symtab *s, symtab_addctx *ctx,
upb_status *status) {
const upb_filedef *file = ctx->file;
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_strtable_iter iter;
CHK_OOM(upb_strtable_insert3(&s->files, file->name, strlen(file->name),
upb_value_constptr(file), alloc));
upb_strtable_begin(&iter, ctx->addtab);
for (; !upb_strtable_done(&iter); upb_strtable_next(&iter)) {
const char *key = upb_strtable_iter_key(&iter);
size_t keylen = upb_strtable_iter_keylen(&iter);
size_t keylen = upb_strtable_iter_keylength(&iter);
upb_value value = upb_strtable_iter_value(&iter);
upb_strtable_insert3(&s->symtab, key, keylen, value, alloc);
CHK_OOM(upb_strtable_insert3(&s->syms, key, keylen, value, alloc));
}
return true;
}
bool upb_symtab_addfile(upb_symtab *s,
const google_protobuf_FileDescriptorProto *file_proto,
upb_status *status) {
upb_arena tmparena;
upb_strtable addtab;
symtab_addctx ctx;
upb_alloc *alloc = upb_arena_alloc(&s->arena);
upb_filedef *file = upb_malloc(alloc, sizeof(*file));
bool ok;
ctx.file = file;
ctx.alloc = alloc;
ctx.tmp = upb_arena_alloc(&tmparena);
ctx.addtab = &addtab;
ctx.status = status;
upb_arena_init(&tmparena);
ok = file &&
upb_strtable_init2(&addtab, UPB_CTYPE_PTR, ctx.tmp) &&
build_filedef(&ctx, file, file_proto) &&
upb_symtab_addtotabs(s, &ctx, status);
err:
upb_arena_uninit(&tmparena);
return false;
return ok;
}
bool upb_symtab_addset(upb_symtab *s, const char *buf, size_t len,
upb_status *status) {
return true;
}
#undef CHK
#undef CHK_OOM

@ -19,6 +19,7 @@
#include "upb/upb.h"
#include "upb/table.int.h"
#include "google/protobuf/descriptor.upb.h"
#ifdef __cplusplus
#include <cstring>
@ -665,6 +666,13 @@ const char *upb_filedef_package(const upb_filedef *f);
const char *upb_filedef_phpprefix(const upb_filedef *f);
const char *upb_filedef_phpnamespace(const upb_filedef *f);
upb_syntax_t upb_filedef_syntax(const upb_filedef *f);
int upb_filedef_depcount(const upb_filedef *f);
int upb_filedef_msgcount(const upb_filedef *f);
int upb_filedef_enumcount(const upb_filedef *f);
const upb_filedef *upb_filedef_dep(const upb_filedef *f, int i);
const upb_msgdef *upb_filedef_msg(const upb_filedef *f, int i);
const upb_enumdef *upb_filedef_enum(const upb_filedef *f, int i);
UPB_END_EXTERN_C
@ -708,10 +716,9 @@ const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym);
const upb_msgdef *upb_symtab_lookupmsg2(
const upb_symtab *s, const char *sym, size_t len);
const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym);
bool upb_symtab_addfile(upb_symtab *s, const char *buf, size_t len,
bool upb_symtab_addfile(upb_symtab *s,
const google_protobuf_FileDescriptorProto* file,
upb_status *status);
bool upb_symtab_addset(upb_symtab *s, const char *buf, size_t len,
upb_status *status);
UPB_END_EXTERN_C

@ -84,7 +84,7 @@ static upb_handlers *newformsg(const upb_msgdef *m, const void *owner,
if (!upb_fielddef_issubmsg(f)) continue;
subdef = upb_downcast_msgdef(upb_fielddef_subdef(f));
subdef = upb_fielddef_msgsubdef(f);
if (upb_inttable_lookupptr(&s->tab, subdef, &subm_ent)) {
upb_handlers_setsubhandlers(h, f, upb_value_getptr(subm_ent));
} else {
@ -392,7 +392,7 @@ bool upb_handlers_setsubhandlers(upb_handlers *h, const upb_fielddef *f,
UPB_ASSERT(!upb_handlers_isfrozen(h));
UPB_ASSERT(upb_fielddef_issubmsg(f));
if (SUBH_F(h, f)) return false; /* Can't reset. */
if (upb_msgdef_upcast(upb_handlers_msgdef(sub)) != upb_fielddef_subdef(f)) {
if (upb_handlers_msgdef(sub) != upb_fielddef_msgsubdef(f)) {
return false;
}
SUBH_F(h, f) = sub;

@ -264,10 +264,6 @@ struct upb_json_parsermethod {
upb_byteshandler input_handler_;
/* Mainly for the purposes of refcounting, so all the fielddefs we point
* to stay alive. */
const upb_msgdef *msg;
/* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */
upb_inttable name_tables;
};
@ -1327,8 +1323,7 @@ static bool end_stringval_nontop(upb_json_parser *p) {
case UPB_TYPE_ENUM: {
/* Resolve enum symbolic name to integer value. */
const upb_enumdef *enumdef =
(const upb_enumdef*)upb_fielddef_subdef(p->top->f);
const upb_enumdef *enumdef = upb_fielddef_enumsubdef(p->top->f);
size_t len;
const char *buf = accumulate_getptr(p, &len);
@ -2414,11 +2409,11 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */
#line 2576 "upb/json/parser.rl"
#line 2571 "upb/json/parser.rl"
#line 2422 "upb/json/parser.c"
#line 2417 "upb/json/parser.c"
static const char _json_actions[] = {
0, 1, 0, 1, 1, 1, 3, 1,
4, 1, 6, 1, 7, 1, 8, 1,
@ -2665,7 +2660,7 @@ static const int json_en_value_machine = 75;
static const int json_en_main = 1;
#line 2579 "upb/json/parser.rl"
#line 2574 "upb/json/parser.rl"
size_t parse(void *closure, const void *hd, const char *buf, size_t size,
const upb_bufhandle *handle) {
@ -2688,7 +2683,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume(parser, buf);
#line 2692 "upb/json/parser.c"
#line 2687 "upb/json/parser.c"
{
int _klen;
unsigned int _trans;
@ -2763,83 +2758,83 @@ _match:
switch ( *_acts++ )
{
case 1:
#line 2427 "upb/json/parser.rl"
#line 2422 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 2:
#line 2429 "upb/json/parser.rl"
#line 2424 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 23;goto _again;} }
break;
case 3:
#line 2433 "upb/json/parser.rl"
#line 2428 "upb/json/parser.rl"
{ start_text(parser, p); }
break;
case 4:
#line 2434 "upb/json/parser.rl"
#line 2429 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_text(parser, p)); }
break;
case 5:
#line 2440 "upb/json/parser.rl"
#line 2435 "upb/json/parser.rl"
{ start_hex(parser); }
break;
case 6:
#line 2441 "upb/json/parser.rl"
#line 2436 "upb/json/parser.rl"
{ hexdigit(parser, p); }
break;
case 7:
#line 2442 "upb/json/parser.rl"
#line 2437 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_hex(parser)); }
break;
case 8:
#line 2448 "upb/json/parser.rl"
#line 2443 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(escape(parser, p)); }
break;
case 9:
#line 2454 "upb/json/parser.rl"
#line 2449 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 10:
#line 2466 "upb/json/parser.rl"
#line 2461 "upb/json/parser.rl"
{ start_duration_base(parser, p); }
break;
case 11:
#line 2467 "upb/json/parser.rl"
#line 2462 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_duration_base(parser, p)); }
break;
case 12:
#line 2469 "upb/json/parser.rl"
#line 2464 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 13:
#line 2474 "upb/json/parser.rl"
#line 2469 "upb/json/parser.rl"
{ start_timestamp_base(parser, p); }
break;
case 14:
#line 2475 "upb/json/parser.rl"
#line 2470 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_base(parser, p)); }
break;
case 15:
#line 2477 "upb/json/parser.rl"
#line 2472 "upb/json/parser.rl"
{ start_timestamp_fraction(parser, p); }
break;
case 16:
#line 2478 "upb/json/parser.rl"
#line 2473 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_fraction(parser, p)); }
break;
case 17:
#line 2480 "upb/json/parser.rl"
#line 2475 "upb/json/parser.rl"
{ start_timestamp_zone(parser, p); }
break;
case 18:
#line 2481 "upb/json/parser.rl"
#line 2476 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_timestamp_zone(parser, p)); }
break;
case 19:
#line 2483 "upb/json/parser.rl"
#line 2478 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
case 20:
#line 2488 "upb/json/parser.rl"
#line 2483 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_TIMESTAMP)) {
{stack[top++] = cs; cs = 47;goto _again;}
@ -2851,11 +2846,11 @@ _match:
}
break;
case 21:
#line 2499 "upb/json/parser.rl"
#line 2494 "upb/json/parser.rl"
{ p--; {stack[top++] = cs; cs = 75;goto _again;} }
break;
case 22:
#line 2504 "upb/json/parser.rl"
#line 2499 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_member(parser, p);
@ -2865,11 +2860,11 @@ _match:
}
break;
case 23:
#line 2511 "upb/json/parser.rl"
#line 2506 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_membername(parser)); }
break;
case 24:
#line 2514 "upb/json/parser.rl"
#line 2509 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
end_any_member(parser, p);
@ -2879,7 +2874,7 @@ _match:
}
break;
case 25:
#line 2525 "upb/json/parser.rl"
#line 2520 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
start_any_object(parser, p);
@ -2889,7 +2884,7 @@ _match:
}
break;
case 26:
#line 2534 "upb/json/parser.rl"
#line 2529 "upb/json/parser.rl"
{
if (is_wellknown_msg(parser, UPB_WELLKNOWN_ANY)) {
CHECK_RETURN_TOP(end_any_object(parser, p));
@ -2899,54 +2894,54 @@ _match:
}
break;
case 27:
#line 2546 "upb/json/parser.rl"
#line 2541 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_array(parser)); }
break;
case 28:
#line 2550 "upb/json/parser.rl"
#line 2545 "upb/json/parser.rl"
{ end_array(parser); }
break;
case 29:
#line 2555 "upb/json/parser.rl"
#line 2550 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_number(parser, p)); }
break;
case 30:
#line 2556 "upb/json/parser.rl"
#line 2551 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 31:
#line 2558 "upb/json/parser.rl"
#line 2553 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_stringval(parser)); }
break;
case 32:
#line 2559 "upb/json/parser.rl"
#line 2554 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_stringval(parser)); }
break;
case 33:
#line 2561 "upb/json/parser.rl"
#line 2556 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 34:
#line 2563 "upb/json/parser.rl"
#line 2558 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 35:
#line 2565 "upb/json/parser.rl"
#line 2560 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 36:
#line 2567 "upb/json/parser.rl"
#line 2562 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(start_subobject_full(parser)); }
break;
case 37:
#line 2568 "upb/json/parser.rl"
#line 2563 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
case 38:
#line 2573 "upb/json/parser.rl"
#line 2568 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; goto _again;} }
break;
#line 2950 "upb/json/parser.c"
#line 2945 "upb/json/parser.c"
}
}
@ -2963,32 +2958,32 @@ _again:
while ( __nacts-- > 0 ) {
switch ( *__acts++ ) {
case 0:
#line 2425 "upb/json/parser.rl"
#line 2420 "upb/json/parser.rl"
{ p--; {cs = stack[--top]; if ( p == pe )
goto _test_eof;
goto _again;} }
break;
case 30:
#line 2556 "upb/json/parser.rl"
#line 2551 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_number(parser, p)); }
break;
case 33:
#line 2561 "upb/json/parser.rl"
#line 2556 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, true)); }
break;
case 34:
#line 2563 "upb/json/parser.rl"
#line 2558 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_bool(parser, false)); }
break;
case 35:
#line 2565 "upb/json/parser.rl"
#line 2560 "upb/json/parser.rl"
{ CHECK_RETURN_TOP(end_null(parser)); }
break;
case 37:
#line 2568 "upb/json/parser.rl"
#line 2563 "upb/json/parser.rl"
{ end_subobject_full(parser); }
break;
#line 2992 "upb/json/parser.c"
#line 2987 "upb/json/parser.c"
}
}
}
@ -2996,7 +2991,7 @@ goto _again;} }
_out: {}
}
#line 2601 "upb/json/parser.rl"
#line 2596 "upb/json/parser.rl"
if (p != pe) {
upb_status_seterrf(&parser->status, "Parse error at '%.*s'\n", pe - p, p);
@ -3044,13 +3039,13 @@ static void json_parser_reset(upb_json_parser *p) {
/* Emit Ragel initialization of the parser. */
#line 3048 "upb/json/parser.c"
#line 3043 "upb/json/parser.c"
{
cs = json_start;
top = 0;
}
#line 2648 "upb/json/parser.rl"
#line 2643 "upb/json/parser.rl"
p->current_state = cs;
p->parser_top = top;
accumulate_clear(p);
@ -3060,13 +3055,6 @@ static void json_parser_reset(upb_json_parser *p) {
upb_status_clear(&p->status);
}
static void visit_json_parsermethod(const upb_refcounted *r,
upb_refcounted_visit *visit,
void *closure) {
const upb_json_parsermethod *method = (upb_json_parsermethod*)r;
visit(r, upb_msgdef_upcast2(method->msg), closure);
}
static void free_json_parsermethod(upb_refcounted *r) {
upb_json_parsermethod *method = (upb_json_parsermethod*)r;
@ -3183,14 +3171,10 @@ upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md,
const void* owner) {
static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod,
free_json_parsermethod};
static const struct upb_refcounted_vtbl vtbl = {NULL, free_json_parsermethod};
upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret));
upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner);
ret->msg = md;
upb_ref2(md, ret);
upb_byteshandler_init(&ret->input_handler_);
upb_byteshandler_setstring(&ret->input_handler_, parse, ret);
upb_byteshandler_setendstr(&ret->input_handler_, end, ret);

@ -52,7 +52,8 @@ class upb::json::ParserMethod {
/* Include base methods from upb::ReferenceCounted. */
UPB_REFCOUNTED_CPPMETHODS
/* Returns handlers for parsing according to the specified schema. */
/* Returns handlers for parsing according to the specified schema.
* The MessageDef must outlive the ParserMethod. */
static reffed_ptr<const ParserMethod> New(const upb::MessageDef* md);
/* The destination handlers that are statically bound to this method.

@ -262,10 +262,6 @@ struct upb_json_parsermethod {
upb_byteshandler input_handler_;
/* Mainly for the purposes of refcounting, so all the fielddefs we point
* to stay alive. */
const upb_msgdef *msg;
/* Keys are upb_msgdef*, values are upb_strtable (json_name -> fielddef) */
upb_inttable name_tables;
};
@ -1325,8 +1321,7 @@ static bool end_stringval_nontop(upb_json_parser *p) {
case UPB_TYPE_ENUM: {
/* Resolve enum symbolic name to integer value. */
const upb_enumdef *enumdef =
(const upb_enumdef*)upb_fielddef_subdef(p->top->f);
const upb_enumdef *enumdef = upb_fielddef_enumsubdef(p->top->f);
size_t len;
const char *buf = accumulate_getptr(p, &len);
@ -2654,13 +2649,6 @@ static void json_parser_reset(upb_json_parser *p) {
upb_status_clear(&p->status);
}
static void visit_json_parsermethod(const upb_refcounted *r,
upb_refcounted_visit *visit,
void *closure) {
const upb_json_parsermethod *method = (upb_json_parsermethod*)r;
visit(r, upb_msgdef_upcast2(method->msg), closure);
}
static void free_json_parsermethod(upb_refcounted *r) {
upb_json_parsermethod *method = (upb_json_parsermethod*)r;
@ -2777,14 +2765,10 @@ upb_bytessink *upb_json_parser_input(upb_json_parser *p) {
upb_json_parsermethod *upb_json_parsermethod_new(const upb_msgdef* md,
const void* owner) {
static const struct upb_refcounted_vtbl vtbl = {visit_json_parsermethod,
free_json_parsermethod};
static const struct upb_refcounted_vtbl vtbl = {NULL, free_json_parsermethod};
upb_json_parsermethod *ret = upb_gmalloc(sizeof(*ret));
upb_refcounted_init(upb_json_parsermethod_upcast_mutable(ret), &vtbl, owner);
ret->msg = md;
upb_ref2(md, ret);
upb_byteshandler_init(&ret->input_handler_);
upb_byteshandler_setstring(&ret->input_handler_, parse, ret);
upb_byteshandler_setendstr(&ret->input_handler_, end, ret);

@ -585,7 +585,7 @@ static void set_enum_hd(upb_handlers *h,
bool preserve_fieldnames,
upb_handlerattr *attr) {
EnumHandlerData *hd = upb_gmalloc(sizeof(EnumHandlerData));
hd->enumdef = (const upb_enumdef *)upb_fielddef_subdef(f);
hd->enumdef = upb_fielddef_enumsubdef(f);
hd->keyname = newstrpc(h, f, preserve_fieldnames);
upb_handlers_addcleanup(h, hd, upb_gfree);
upb_handlerattr_sethandlerdata(attr, hd);

@ -22,6 +22,7 @@
#define UPB_MSG_H_
#include <stdint.h>
#include <string.h>
#include "upb/upb.h"
#ifdef __cplusplus
@ -86,6 +87,14 @@ UPB_INLINE upb_stringview upb_stringview_make(const char *data, size_t size) {
return ret;
}
UPB_INLINE upb_stringview upb_stringview_makez(const char *data) {
return upb_stringview_make(data, strlen(data));
}
UPB_INLINE bool upb_stringview_eql(upb_stringview a, upb_stringview b) {
return a.size == b.size && memcmp(a.data, b.data, a.size) == 0;
}
#define UPB_STRINGVIEW_INIT(ptr, len) {ptr, len}

@ -183,7 +183,7 @@ static bool textprinter_putenum(void *closure, const void *handler_data,
int32_t val) {
upb_textprinter *p = closure;
const upb_fielddef *f = handler_data;
const upb_enumdef *enum_def = upb_downcast_enumdef(upb_fielddef_subdef(f));
const upb_enumdef *enum_def = upb_fielddef_enumsubdef(f);
const char *label = upb_enumdef_iton(enum_def, val);
if (label) {
indent(p);
@ -292,7 +292,7 @@ static void onmreg(const void *c, upb_handlers *h) {
break;
case UPB_TYPE_MESSAGE: {
const char *name =
upb_fielddef_istagdelim(f)
upb_fielddef_descriptortype(f) == UPB_DESCRIPTOR_TYPE_GROUP
? shortname(upb_msgdef_fullname(upb_fielddef_msgsubdef(f)))
: upb_fielddef_name(f);
upb_handlerattr_sethandlerdata(&attr, name);

@ -1,196 +0,0 @@
/*
** This file contains definitions of structs that should be considered private
** and NOT stable across versions of upb.
**
** The only reason they are declared here and not in .c files is to allow upb
** and the application (if desired) to embed statically-initialized instances
** of structures like defs.
**
** If you include this file, all guarantees of ABI compatibility go out the
** window! Any code that includes this file needs to recompile against the
** exact same version of upb that they are linking against.
**
** You also need to recompile if you change the value of the UPB_DEBUG_REFS
** flag.
*/
#include "upb/def.h"
#ifndef UPB_STATICINIT_H_
#define UPB_STATICINIT_H_
#ifdef __cplusplus
/* Because of how we do our typedefs, this header can't be included from C++. */
#error This file cannot be included from C++
#endif
/* upb_refcounted *************************************************************/
/* upb_def ********************************************************************/
struct upb_def {
upb_refcounted base;
const char *fullname;
const upb_filedef* file;
char type; /* A upb_deftype_t (char to save space) */
/* Used as a flag during the def's mutable stage. Must be false unless
* it is currently being used by a function on the stack. This allows
* us to easily determine which defs were passed into the function's
* current invocation. */
bool came_from_user;
};
#define UPB_DEF_INIT(name, type, vtbl, refs, ref2s) \
{ UPB_REFCOUNT_INIT(vtbl, refs, ref2s), name, NULL, type, false }
/* upb_fielddef ***************************************************************/
struct upb_fielddef {
upb_def base;
union {
int64_t sint;
uint64_t uint;
double dbl;
float flt;
void *bytes;
} defaultval;
union {
const upb_msgdef *def; /* If !msg_is_symbolic. */
char *name; /* If msg_is_symbolic. */
} msg;
union {
const upb_def *def; /* If !subdef_is_symbolic. */
char *name; /* If subdef_is_symbolic. */
} sub; /* The msgdef or enumdef for this field, if upb_hassubdef(f). */
bool subdef_is_symbolic;
bool msg_is_symbolic;
const upb_oneofdef *oneof;
bool default_is_string;
bool type_is_set_; /* False until type is explicitly set. */
bool is_extension_;
bool lazy_;
bool packed_;
upb_intfmt_t intfmt;
bool tagdelim;
upb_fieldtype_t type_;
upb_label_t label_;
uint32_t number_;
uint32_t selector_base; /* Used to index into a upb::Handlers table. */
uint32_t index_;
};
extern const struct upb_refcounted_vtbl upb_fielddef_vtbl;
#define UPB_FIELDDEF_INIT(label, type, intfmt, tagdelim, is_extension, lazy, \
packed, name, num, msgdef, subdef, selector_base, \
index, defaultval, refs, ref2s) \
{ \
UPB_DEF_INIT(name, UPB_DEF_FIELD, &upb_fielddef_vtbl, refs, ref2s), \
defaultval, {msgdef}, {subdef}, NULL, false, false, \
type == UPB_TYPE_STRING || type == UPB_TYPE_BYTES, true, is_extension, \
lazy, packed, intfmt, tagdelim, type, label, num, selector_base, index \
}
/* upb_msgdef *****************************************************************/
struct upb_msgdef {
upb_def base;
size_t selector_count;
uint32_t submsg_field_count;
/* Tables for looking up fields by number and name. */
upb_inttable itof; /* int to field */
upb_strtable ntof; /* name to field/oneof */
/* Is this a map-entry message? */
bool map_entry;
/* Whether this message has proto2 or proto3 semantics. */
upb_syntax_t syntax;
/* Type of well known type message. UPB_WELLKNOWN_UNSPECIFIED for
* non-well-known message. */
upb_wellknowntype_t well_known_type;
/* TODO(haberman): proper extension ranges (there can be multiple). */
};
extern const struct upb_refcounted_vtbl upb_msgdef_vtbl;
/* TODO: also support static initialization of the oneofs table. This will be
* needed if we compile in descriptors that contain oneofs. */
#define UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, \
map_entry, syntax, well_known_type, refs, ref2s) \
{ \
UPB_DEF_INIT(name, UPB_DEF_MSG, &upb_fielddef_vtbl, refs, ref2s), \
selector_count, submsg_field_count, itof, ntof, map_entry, syntax, \
well_known_type \
}
/* upb_enumdef ****************************************************************/
struct upb_enumdef {
upb_def base;
upb_strtable ntoi;
upb_inttable iton;
int32_t defaultval;
};
extern const struct upb_refcounted_vtbl upb_enumdef_vtbl;
#define UPB_ENUMDEF_INIT(name, ntoi, iton, defaultval, refs, ref2s) \
{ UPB_DEF_INIT(name, UPB_DEF_ENUM, &upb_enumdef_vtbl, refs, ref2s), ntoi, \
iton, defaultval }
/* upb_oneofdef ***************************************************************/
struct upb_oneofdef {
upb_refcounted base;
uint32_t index; /* Index within oneofs. */
const char *name;
upb_strtable ntof;
upb_inttable itof;
const upb_msgdef *parent;
};
extern const struct upb_refcounted_vtbl upb_oneofdef_vtbl;
#define UPB_ONEOFDEF_INIT(name, ntof, itof, refs, ref2s) \
{ UPB_REFCOUNT_INIT(&upb_oneofdef_vtbl, refs, ref2s), 0, name, ntof, itof }
/* upb_symtab *****************************************************************/
struct upb_symtab {
upb_refcounted base;
upb_strtable symtab;
};
struct upb_filedef {
upb_refcounted base;
const char *name;
const char *package;
const char *phpprefix;
const char *phpnamespace;
upb_syntax_t syntax;
upb_inttable defs;
upb_inttable deps;
};
extern const struct upb_refcounted_vtbl upb_filedef_vtbl;
#endif /* UPB_STATICINIT_H_ */
Loading…
Cancel
Save