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/structdefs.int.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'upb/structdefs.int.h') diff --git a/upb/structdefs.int.h b/upb/structdefs.int.h index 467963b..467374a 100644 --- a/upb/structdefs.int.h +++ b/upb/structdefs.int.h @@ -33,6 +33,7 @@ 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 @@ -43,7 +44,7 @@ struct upb_def { }; #define UPB_DEF_INIT(name, type, refs, ref2s) \ - { UPB_REFCOUNT_INIT(refs, ref2s), name, type, false } + { UPB_REFCOUNT_INIT(refs, ref2s), name, NULL, type, false } /* upb_fielddef ***************************************************************/ @@ -114,10 +115,10 @@ struct upb_msgdef { * descriptor.upb.c. */ bool map_entry; - /* Do primitive values in this message have explicit presence or not? + /* Whether this message has proto2 or proto3 semantics. * TODO: set this flag properly for static descriptors; regenerate * descriptor.upb.c. */ - bool primitives_have_presence; + upb_syntax_t syntax; /* TODO(haberman): proper extension ranges (there can be multiple). */ }; @@ -173,5 +174,15 @@ struct upb_symtab { #define UPB_SYMTAB_INIT(symtab, refs, ref2s) \ { UPB_REFCOUNT_INIT(refs, ref2s), symtab } +struct upb_filedef { + upb_refcounted base; + + const char *name; + const char *package; + upb_syntax_t syntax; + + upb_inttable defs; + upb_inttable deps; +}; #endif /* UPB_STATICINIT_H_ */ -- cgit v1.2.3