diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-09-18 01:01:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-09-18 01:01:15 -0400 |
| commit | 2158bb97fc2a9744c5ed1bf4b5cd056498904925 (patch) | |
| tree | 7c4f0d1c0e21649d23b624a4cb254464398c349b | |
| parent | 0829e1a2d1fc1c1d284b6e929a62479cdd01064e (diff) | |
Clean up struct code a bit
| -rw-r--r-- | compile.c | 11 | ||||
| -rw-r--r-- | enums.c | 2 | ||||
| -rw-r--r-- | structs.c | 6 | ||||
| -rw-r--r-- | structs.h | 2 |
4 files changed, 8 insertions, 13 deletions
@@ -833,10 +833,8 @@ CORD compile_statement(env_t *env, ast_t *ast) ") Table$remove(&cache, cache.entries.data + cache.entries.stride*Int$random(I(0), I(cache.entries.length-1)), table_type);\n"); } - CORD arg_typedef = compile_struct_typedef(env, args_def); + CORD arg_typedef = compile_struct_header(env, args_def); env->code->local_typedefs = CORD_all(env->code->local_typedefs, arg_typedef); - env->code->staticdefs = CORD_all(env->code->staticdefs, - "extern const TypeInfo ", namespace_prefix(env->libname, env->namespace), arg_type_name, ";\n"); CORD wrapper = CORD_all( is_private ? CORD_EMPTY : "public ", ret_type_code, " ", name, arg_signature, "{\n" "static Table_t cache = {};\n", @@ -3803,12 +3801,7 @@ CORD compile_statement_header(env_t *env, ast_t *ast) } } case StructDef: { - auto def = Match(ast, StructDef); - CORD full_name = CORD_cat(namespace_prefix(env->libname, env->namespace), def->name); - return CORD_all( - compile_struct_typedef(env, ast), - "extern const TypeInfo ", full_name, ";\n", - compile_namespace_header(env, def->name, def->namespace)); + return compile_struct_header(env, ast); } case EnumDef: { return compile_enum_header(env, ast); @@ -218,7 +218,7 @@ CORD compile_enum_header(env_t *env, ast_t *ast) enum_def = CORD_all(enum_def, "} tag;\n" "union {\n"); for (tag_ast_t *tag = def->tags; tag; tag = tag->next) { - CORD field_def = compile_struct_typedef(env, WrapAST(ast, StructDef, .name=CORD_to_const_char_star(CORD_all(def->name, "$", tag->name)), .fields=tag->fields)); + CORD field_def = compile_struct_header(env, WrapAST(ast, StructDef, .name=CORD_to_const_char_star(CORD_all(def->name, "$", tag->name)), .fields=tag->fields)); all_defs = CORD_all(all_defs, field_def); enum_def = CORD_all(enum_def, full_name, "$", tag->name, "_t $", tag->name, ";\n"); } @@ -171,7 +171,7 @@ void compile_struct_def(env_t *env, ast_t *ast) compile_namespace(env, def->name, def->namespace); } -CORD compile_struct_typedef(env_t *env, ast_t *ast) +CORD compile_struct_header(env_t *env, ast_t *ast) { auto def = Match(ast, StructDef); CORD full_name = CORD_cat(namespace_prefix(env->libname, env->namespace), def->name); @@ -192,7 +192,9 @@ CORD compile_struct_typedef(env_t *env, ast_t *ast) "typedef struct {\n", full_name, "_t value;\n" "Bool_t is_null:1;\n" - "} ", namespace_prefix(env->libname, env->namespace), "$Optional", def->name, "_t;\n"); + "} ", namespace_prefix(env->libname, env->namespace), "$Optional", def->name, "_t;\n" + "extern const TypeInfo ", full_name, ";\n", + compile_namespace_header(env, def->name, def->namespace)); } // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 @@ -8,6 +8,6 @@ #include "environment.h" void compile_struct_def(env_t *env, ast_t *ast); -CORD compile_struct_typedef(env_t *env, ast_t *ast); +CORD compile_struct_header(env_t *env, ast_t *ast); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
