| 713 | } |
| 714 | |
| 715 | CheckedError Parser::AddField(StructDef &struct_def, const std::string &name, |
| 716 | const Type &type, FieldDef **dest) { |
| 717 | auto &field = *new FieldDef(); |
| 718 | field.value.offset = |
| 719 | FieldIndexToOffset(static_cast<voffset_t>(struct_def.fields.vec.size())); |
| 720 | field.name = name; |
| 721 | field.file = struct_def.file; |
| 722 | field.value.type = type; |
| 723 | if (struct_def.fixed) { // statically compute the field offset |
| 724 | auto size = InlineSize(type); |
| 725 | auto alignment = InlineAlignment(type); |
| 726 | // structs_ need to have a predictable format, so we need to align to |
| 727 | // the largest scalar |
| 728 | struct_def.minalign = std::max(struct_def.minalign, alignment); |
| 729 | struct_def.PadLastField(alignment); |
| 730 | field.value.offset = static_cast<voffset_t>(struct_def.bytesize); |
| 731 | struct_def.bytesize += size; |
| 732 | } |
| 733 | if (struct_def.fields.Add(name, &field)) |
| 734 | return Error("field already exists: " + name); |
| 735 | *dest = &field; |
| 736 | return NoError(); |
| 737 | } |
| 738 | |
| 739 | CheckedError Parser::ParseField(StructDef &struct_def) { |
| 740 | std::string name = attribute_; |
nothing calls this directly
no test coverage detected