From 919fea438a5ac5366684cfa26d2bb3d17519cb60 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Mon, 18 May 2015 10:55:20 -0700 Subject: Ported upb to C89, for greater portability. A large part of this change contains surface-level porting, like moving variable declarations to the top of the block. However there are a few more substantial things too: - moved internal-only struct definitions to a separate file (structdefs.int.h), for greater encapsulation and ABI compatibility. - removed the UPB_UPCAST macro, since it requires access to the internal-only struct definitions. Replaced uses with calls to inline, type-safe casting functions. - removed the UPB_DEFINE_CLASS/UPB_DEFINE_STRUCT macros. Class and struct definitions are now more explicit -- you get to see the actual class/struct keywords in the source. The casting convenience functions have been moved into UPB_DECLARE_DERIVED_TYPE() and UPB_DECLARE_DERIVED_TYPE2(). - the new way that we duplicate base methods in derived types is also more convenient and requires less duplication. It is also less greppable, but hopefully that is not too big a problem. Compiler flags (-std=c89 -pedantic) should help to rigorously enforce that the code is free of C99-isms. A few functions are not available in C89 (strtoll). There are temporary, hacky solutions in place. --- upb/json/parser.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'upb/json/parser.h') diff --git a/upb/json/parser.h b/upb/json/parser.h index b932adf..2facb45 100644 --- a/upb/json/parser.h +++ b/upb/json/parser.h @@ -18,23 +18,24 @@ namespace upb { namespace json { class Parser; -} // namespace json -} // namespace upb +} /* namespace json */ +} /* namespace upb */ #endif -UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser); +UPB_DECLARE_TYPE(upb::json::Parser, upb_json_parser) /* upb::json::Parser **********************************************************/ -// Preallocation hint: parser won't allocate more bytes than this when first -// constructed. This hint may be an overestimate for some build configurations. -// But if the parser library is upgraded without recompiling the application, -// it may be an underestimate. +/* Preallocation hint: parser won't allocate more bytes than this when first + * constructed. This hint may be an overestimate for some build configurations. + * But if the parser library is upgraded without recompiling the application, + * it may be an underestimate. */ #define UPB_JSON_PARSER_SIZE 3568 #ifdef __cplusplus -// Parses an incoming BytesStream, pushing the results to the destination sink. +/* Parses an incoming BytesStream, pushing the results to the destination + * sink. */ class upb::json::Parser { public: static Parser* Create(Environment* env, Sink* output); @@ -42,7 +43,7 @@ class upb::json::Parser { BytesSink* input(); private: - UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser); + UPB_DISALLOW_POD_OPS(Parser, upb::json::Parser) }; #endif @@ -64,10 +65,10 @@ inline Parser* Parser::Create(Environment* env, Sink* output) { inline BytesSink* Parser::input() { return upb_json_parser_input(this); } -} // namespace json -} // namespace upb +} /* namespace json */ +} /* namespace upb */ #endif -#endif // UPB_JSON_PARSER_H_ +#endif /* UPB_JSON_PARSER_H_ */ -- cgit v1.2.3