From e6fa3f9d869765544b8e424e8573fe8d9af35534 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 19 Apr 2016 15:41:33 -0700 Subject: Changed schema for JSON test to be defined in a .proto file. (#54) * Changed schema for JSON test to be defined in a .proto file. Before we had lots of code to build these schemas manually, but this was verbose and made it difficult to add to the schema easily. Now we can just write a .proto file and adding fields is easy. To avoid making the tests depend on upbc (and thus Lua) we check in the generated schema. * Made protobuf-compiler a dependency of "make genfiles." * For genfiles download recent protoc that can handle proto3. * Only use new protoc for genfiles. --- tools/dump_cinit.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'tools/dump_cinit.lua') diff --git a/tools/dump_cinit.lua b/tools/dump_cinit.lua index 17be8d9..e01e150 100644 --- a/tools/dump_cinit.lua +++ b/tools/dump_cinit.lua @@ -292,8 +292,12 @@ local function gettables(def) end end -local function emit_file_warning(append) - append('/* This file was generated by upbc (the upb compiler).\n') +local function emit_file_warning(filedef, append) + append('/* This file was generated by upbc (the upb compiler) from the input\n') + append(' * file:\n') + append(' *\n') + append(' * %s\n', filedef:name()) + append(' *\n') append(' * Do not edit -- your changes will be discarded when the file is\n') append(' * regenerated. */\n\n') end @@ -402,7 +406,7 @@ local function dump_defs_c(filedef, append) end -- Emit forward declarations. - emit_file_warning(append) + emit_file_warning(filedef, append) append('#include \n\n') append('#include "upb/def.h"\n') append('#include "upb/structdefs.int.h"\n\n') @@ -432,13 +436,15 @@ local function dump_defs_c(filedef, append) local tables = gettables(m) -- UPB_MSGDEF_INIT(name, selector_count, submsg_field_count, itof, ntof, -- refs, ref2s) - append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s,' .. - '&reftables[%d], &reftables[%d]),\n', + append(' UPB_MSGDEF_INIT("%s", %d, %d, %s, %s, %s, %s,' .. + ' &reftables[%d], &reftables[%d]),\n', m:full_name(), upbtable.msgdef_selector_count(m), upbtable.msgdef_submsg_field_count(m), dumper:inttable(tables.int), dumper:strtable(tables.str), + boolstr(m:_map_entry()), + const(m, "syntax"), reftable, reftable + 1) reftable = reftable + 2 end @@ -627,17 +633,17 @@ local print_classes local function print_message(def, map, indent, append) append("\n") - append("%sclass %s : public upb::reffed_ptr {\n", + append("%sclass %s : public ::upb::reffed_ptr {\n", indent, def:name()) append("%s public:\n", indent) - append("%s %s(const upb::MessageDef* m, const void *ref_donor = NULL)\n", + append("%s %s(const ::upb::MessageDef* m, const void *ref_donor = NULL)\n", indent, def:name()) append("%s : reffed_ptr(m, ref_donor) {\n", indent) append("%s assert(upbdefs_%s_is(m));\n", indent, to_cident(def:full_name())) append("%s }\n", indent) append("\n") append("%s static %s get() {\n", indent, def:name()) - append("%s const upb::MessageDef* m = upbdefs_%s_get(&m);\n", indent, to_cident(def:full_name())) + append("%s const ::upb::MessageDef* m = upbdefs_%s_get(&m);\n", indent, to_cident(def:full_name())) append("%s return %s(m, &m);\n", indent, def:name()) append("%s }\n", indent) -- TODO(haberman): add fields @@ -647,16 +653,16 @@ end local function print_enum(def, indent, append) append("\n") - append("%sclass %s : public upb::reffed_ptr {\n", + append("%sclass %s : public ::upb::reffed_ptr {\n", indent, def:name()) append("%s public:\n", indent) - append("%s %s(const upb::EnumDef* e, const void *ref_donor = NULL)\n", + append("%s %s(const ::upb::EnumDef* e, const void *ref_donor = NULL)\n", indent, def:name()) append("%s : reffed_ptr(e, ref_donor) {\n", indent) append("%s assert(upbdefs_%s_is(e));\n", indent, to_cident(def:full_name())) append("%s }\n", indent) append("%s static %s get() {\n", indent, def:name()) - append("%s const upb::EnumDef* e = upbdefs_%s_get(&e);\n", indent, to_cident(def:full_name())) + append("%s const ::upb::EnumDef* e = upbdefs_%s_get(&e);\n", indent, to_cident(def:full_name())) append("%s return %s(e, &e);\n", indent, def:name()) append("%s }\n", indent) append("%s};\n", indent) @@ -686,7 +692,7 @@ local function dump_defs_h(file, append, linktab) append(" * actually storing protobufs. It only contains *defs* which\n") append(" * let you reflect over a protobuf *schema*.\n") append(" */\n") - emit_file_warning(append) + emit_file_warning(file, append) append('#ifndef %s_UPB_H_\n', basename_preproc) append('#define %s_UPB_H_\n\n', basename_preproc) append('#include "upb/def.h"\n\n') -- cgit v1.2.3