Emit GetRootAs methods for all types in Go and Python

This commit is contained in:
Dan Ring
2015-11-21 19:49:33 -05:00
parent 5a401aef57
commit 1f8e3c13e6
7 changed files with 35 additions and 10 deletions

View File

@@ -509,13 +509,12 @@ static void GenTableBuilders(const StructDef &struct_def,
// Generate struct or table methods.
static void GenStruct(const StructDef &struct_def,
std::string *code_ptr,
StructDef *root_struct_def) {
std::string *code_ptr) {
if (struct_def.generated) return;
GenComment(struct_def.doc_comment, code_ptr, nullptr);
BeginClass(struct_def, code_ptr);
if (&struct_def == root_struct_def) {
if (!struct_def.fixed) {
// Generate a special accessor for the table that has been declared as
// the root type.
NewRootTypeFromBuffer(struct_def, code_ptr);
@@ -637,7 +636,7 @@ class GoGenerator : public BaseGenerator {
for (auto it = parser_.structs_.vec.begin();
it != parser_.structs_.vec.end(); ++it) {
std::string declcode;
go::GenStruct(**it, &declcode, parser_.root_struct_def_);
go::GenStruct(**it, &declcode);
if (!SaveType(**it, declcode, true)) return false;
}