From e9d79d2441732264e2b990a5b2dc76d13724db07 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Wed, 16 Mar 2016 18:07:32 -0700 Subject: Added upb::FileDef, which represents the file defs are declared in. It is entirely optional: MessageDef/EnumDef can still exist on their own. But this can represent a def's file when it is desirable to do so (eg. for code generators). This approach will require that we change the way we handle extensions. But I think it will be a good change overall. Specifically, we previously handled extensions by duplicating the extended message and then adding the extension as a regular field to the duplicated message. This required also duplicating any messages that could reach the extended message. In the new world we will need a way of declaring and looking up extensions separately from the message being extended. This change also involves some notable changes to the generated code: - files are now called foo.upbdefs.h instead of foo.upb.h. This reflects the fact that we might possibly generate several different output files for a .proto file, and this one is just for defs. - we no longer generate selectors in the .h file. - the upbdefs.c no longer vends a SymbolTable. Now it vends the individual messages (and possibly a FileDef later). I think this will compose better once we can generate files where one generated files imports another. We also make the descriptor reader vend a list of FileDefs now. This is the best conceptual match for parsing a FileDescriptorSet. --- upb/descriptor/reader.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'upb/descriptor/reader.h') diff --git a/upb/descriptor/reader.h b/upb/descriptor/reader.h index e345f53..a6fc7f0 100644 --- a/upb/descriptor/reader.h +++ b/upb/descriptor/reader.h @@ -39,14 +39,9 @@ class upb::descriptor::Reader { /* The reader's input; this is where descriptor.proto data should be sent. */ Sink* input(); - /* Returns an array of all defs that have been parsed, and transfers ownership - * of them to "owner". The number of defs is stored in *n. Ownership of the - * returned array is retained and is invalidated by any other call into - * Reader. - * - * These defs are not frozen or resolved; they are ready to be added to a - * symtab. */ - upb::Def** GetDefs(void* owner, int* n); + /* Use to get the FileDefs that have been parsed. */ + size_t file_count() const; + FileDef* file(size_t i) const; /* Builds and returns handlers for the reader, owned by "owner." */ static Handlers* NewHandlers(const void* owner); @@ -62,7 +57,8 @@ UPB_BEGIN_EXTERN_C /* C API. */ upb_descreader *upb_descreader_create(upb_env *e, const upb_handlers *h); upb_sink *upb_descreader_input(upb_descreader *r); -upb_def **upb_descreader_getdefs(upb_descreader *r, void *owner, int *n); +size_t upb_descreader_filecount(const upb_descreader *r); +upb_filedef *upb_descreader_file(const upb_descreader *r, size_t i); const upb_handlers *upb_descreader_newhandlers(const void *owner); UPB_END_EXTERN_C @@ -75,8 +71,11 @@ inline Reader* Reader::Create(Environment* e, const Handlers *h) { return upb_descreader_create(e, h); } inline Sink* Reader::input() { return upb_descreader_input(this); } -inline upb::Def** Reader::GetDefs(void* owner, int* n) { - return upb_descreader_getdefs(this, owner, n); +inline size_t Reader::file_count() const { + return upb_descreader_filecount(this); +} +inline FileDef* Reader::file(size_t i) const { + return upb_descreader_file(this, i); } } /* namespace descriptor */ } /* namespace upb */ -- cgit v1.2.3