aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compile.c11
-rw-r--r--enums.c2
-rw-r--r--structs.c6
-rw-r--r--structs.h2
4 files changed, 8 insertions, 13 deletions
diff --git a/compile.c b/compile.c
index 89948455..f836cee0 100644
--- a/compile.c
+++ b/compile.c
@@ -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);
diff --git a/enums.c b/enums.c
index 7e2fec67..ab993786 100644
--- a/enums.c
+++ b/enums.c
@@ -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");
}
diff --git a/structs.c b/structs.c
index 6584eac8..48fce6dd 100644
--- a/structs.c
+++ b/structs.c
@@ -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
diff --git a/structs.h b/structs.h
index 0f7b0ad8..166a382b 100644
--- a/structs.h
+++ b/structs.h
@@ -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