| 873 | } |
| 874 | |
| 875 | CheckedError Parser::AddField(StructDef &struct_def, const std::string &name, |
| 876 | const Type &type, FieldDef **dest) { |
| 877 | auto &field = *new FieldDef(); |
| 878 | field.value.offset = |
| 879 | FieldIndexToOffset(static_cast<voffset_t>(struct_def.fields.vec.size())); |
| 880 | field.name = name; |
| 881 | field.file = struct_def.file; |
| 882 | field.value.type = type; |
| 883 | if (struct_def.fixed) { // statically compute the field offset |
| 884 | auto size = InlineSize(type); |
| 885 | auto alignment = InlineAlignment(type); |
| 886 | // structs_ need to have a predictable format, so we need to align to |
| 887 | // the largest scalar |
| 888 | struct_def.minalign = std::max(struct_def.minalign, alignment); |
| 889 | struct_def.PadLastField(alignment); |
| 890 | field.value.offset = static_cast<voffset_t>(struct_def.bytesize); |
| 891 | struct_def.bytesize += size; |
| 892 | } |
| 893 | if (struct_def.fields.Add(name, &field)) |
| 894 | return Error("field already exists: " + name); |
| 895 | *dest = &field; |
| 896 | return NoError(); |
| 897 | } |
| 898 | |
| 899 | CheckedError Parser::ParseField(StructDef &struct_def) { |
| 900 | std::string name = attribute_; |
nothing calls this directly
no test coverage detected