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/symtab.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'upb/symtab.h') diff --git a/upb/symtab.h b/upb/symtab.h index ffe9f73..9a41c03 100644 --- a/upb/symtab.h +++ b/upb/symtab.h @@ -108,12 +108,17 @@ class upb::SymbolTable { * only a few messages are changing. We may want to add a way of adding a * tree of frozen defs to the symtab (perhaps an alternate constructor where * you pass the root of the tree?) */ - bool Add(Def*const* defs, int n, void* ref_donor, upb_status* status); + bool Add(Def*const* defs, size_t n, void* ref_donor, Status* status); bool Add(const std::vector& defs, void *owner, Status* status) { return Add((Def*const*)&defs[0], defs.size(), owner, status); } + /* Resolves all subdefs for messages in this file and attempts to freeze the + * file. If this succeeds, adds all the symbols to this SymbolTable + * (replacing any existing ones with the same names). */ + bool AddFile(FileDef* file, Status* s); + private: UPB_DISALLOW_POD_OPS(SymbolTable, upb::SymbolTable) }; @@ -134,8 +139,9 @@ const upb_def *upb_symtab_resolve(const upb_symtab *s, const char *base, const upb_def *upb_symtab_lookup(const upb_symtab *s, const char *sym); const upb_msgdef *upb_symtab_lookupmsg(const upb_symtab *s, const char *sym); const upb_enumdef *upb_symtab_lookupenum(const upb_symtab *s, const char *sym); -bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, int n, void *ref_donor, - upb_status *status); +bool upb_symtab_add(upb_symtab *s, upb_def *const*defs, size_t n, + void *ref_donor, upb_status *status); +bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status* status); /* upb_symtab_iter i; * for(upb_symtab_begin(&i, s, type); !upb_symtab_done(&i); @@ -177,9 +183,12 @@ inline const MessageDef *SymbolTable::LookupMessage(const char *sym) const { return upb_symtab_lookupmsg(this, sym); } inline bool SymbolTable::Add( - Def*const* defs, int n, void* ref_donor, upb_status* status) { + Def*const* defs, size_t n, void* ref_donor, Status* status) { return upb_symtab_add(this, (upb_def*const*)defs, n, ref_donor, status); } +inline bool SymbolTable::AddFile(FileDef* file, Status* s) { + return upb_symtab_addfile(this, file, s); +} } /* namespace upb */ #endif -- cgit v1.2.3