diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-10-30 02:44:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-10-30 02:44:15 -0400 |
| commit | a0178a1e0ccfd706f6d69b5b4a876f1ee70cdc28 (patch) | |
| tree | 54ebe2a8e036610444a412bdfae3056a225c62a3 /structs.c | |
| parent | 61af5802a78384d7c115738d5a87d7b5102d5b0c (diff) | |
Bugfix for empty struct typeinfos
Diffstat (limited to 'structs.c')
| -rw-r--r-- | structs.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -27,16 +27,20 @@ void compile_struct_def(env_t *env, ast_t *ast) short_name = strrchr(short_name, '$') + 1; env->code->typeinfos = CORD_all("public const TypeInfo_t ", full_name, ";\n", env->code->typeinfos); - CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {%zu, %zu, .tag=StructInfo, .StructInfo.name=\"%s\"%s, " - ".StructInfo.num_fields=%ld, .StructInfo.fields=(NamedType_t[%d]){", + CORD typeinfo = CORD_asprintf("public const TypeInfo_t %r = {.size=%zu, .align=%zu, .tag=StructInfo, .StructInfo.name=\"%s\"%s, " + ".StructInfo.num_fields=%ld", full_name, type_size(t), type_align(t), short_name, def->secret ? ", .StructInfo.is_secret=true" : "", - num_fields, num_fields); - for (arg_ast_t *f = def->fields; f; f = f->next) { - type_t *field_type = get_arg_ast_type(env, f); - typeinfo = CORD_all(typeinfo, "{\"", f->name, "\", ", compile_type_info(env, field_type), "}"); - if (f->next) typeinfo = CORD_all(typeinfo, ", "); + num_fields); + if (def->fields) { + typeinfo = CORD_asprintf("%r, .StructInfo.fields=(NamedType_t[%d]){", typeinfo, num_fields); + for (arg_ast_t *f = def->fields; f; f = f->next) { + type_t *field_type = get_arg_ast_type(env, f); + typeinfo = CORD_all(typeinfo, "{\"", f->name, "\", ", compile_type_info(env, field_type), "}"); + if (f->next) typeinfo = CORD_all(typeinfo, ", "); + } + typeinfo = CORD_all(typeinfo, "}"); } - typeinfo = CORD_all(typeinfo, "}};\n"); + typeinfo = CORD_all(typeinfo, "};\n"); env->code->typeinfos = CORD_all(env->code->typeinfos, typeinfo); compile_namespace(env, def->name, def->namespace); |
