aboutsummaryrefslogtreecommitdiff
path: root/src/structs.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-23 19:28:08 -0400
commitfcda36561d668f43bac91ea31cd55cbbd605d330 (patch)
treeeb74c0b17df584af0fd8154422ad924e04c96cc2 /src/structs.c
parent414b0c7472c87c5a013029aefef49e2dbc41e700 (diff)
Autoformat everything with clang-format
Diffstat (limited to 'src/structs.c')
-rw-r--r--src/structs.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/structs.c b/src/structs.c
index 0bcb8a08..9be38d1f 100644
--- a/src/structs.c
+++ b/src/structs.c
@@ -5,31 +5,33 @@
#include "compile.h"
#include "environment.h"
#include "naming.h"
-#include "stdlib/text.h"
#include "stdlib/tables.h"
+#include "stdlib/text.h"
#include "typecheck.h"
-Text_t compile_struct_typeinfo(env_t *env, type_t *t, const char *name, arg_ast_t *fields, bool is_secret, bool is_opaque)
-{
+Text_t compile_struct_typeinfo(env_t *env, type_t *t, const char *name, arg_ast_t *fields, bool is_secret,
+ bool is_opaque) {
Text_t typeinfo_name = namespace_name(env, env->namespace, Texts(name, "$$info"));
- Text_t type_code = Match(t, StructType)->external ?
- Text$from_str(name) : Texts("struct ", namespace_name(env, env->namespace, Texts(name, "$$struct")));
+ Text_t type_code = Match(t, StructType)->external
+ ? Text$from_str(name)
+ : Texts("struct ", namespace_name(env, env->namespace, Texts(name, "$$struct")));
int num_fields = 0;
for (arg_ast_t *f = fields; f; f = f->next)
num_fields += 1;
const char *short_name = name;
- if (strchr(short_name, '$'))
- short_name = strrchr(short_name, '$') + 1;
+ if (strchr(short_name, '$')) short_name = strrchr(short_name, '$') + 1;
const char *metamethods = is_packed_data(t) ? "PackedData$metamethods" : "Struct$metamethods";
- Text_t typeinfo = Texts("public const TypeInfo_t ", typeinfo_name,
- " = {.size=sizeof(", type_code, "), .align=__alignof__(", type_code, "), "
- ".metamethods=", metamethods, ", "
- ".tag=StructInfo, .StructInfo.name=\"", short_name, "\"",
- is_secret ? Text(", .StructInfo.is_secret=true") : EMPTY_TEXT,
- is_opaque ? Text(", .StructInfo.is_opaque=true") : EMPTY_TEXT,
- ", .StructInfo.num_fields=", String(num_fields));
+ Text_t typeinfo = Texts(
+ "public const TypeInfo_t ", typeinfo_name, " = {.size=sizeof(", type_code, "), .align=__alignof__(", type_code,
+ "), "
+ ".metamethods=",
+ metamethods,
+ ", "
+ ".tag=StructInfo, .StructInfo.name=\"",
+ short_name, "\"", is_secret ? Text(", .StructInfo.is_secret=true") : EMPTY_TEXT,
+ is_opaque ? Text(", .StructInfo.is_opaque=true") : EMPTY_TEXT, ", .StructInfo.num_fields=", String(num_fields));
if (fields) {
typeinfo = Texts(typeinfo, ", .StructInfo.fields=(NamedType_t[", String(num_fields), "]){");
for (arg_ast_t *f = fields; f; f = f->next) {
@@ -42,12 +44,12 @@ Text_t compile_struct_typeinfo(env_t *env, type_t *t, const char *name, arg_ast_
return Texts(typeinfo, "};\n");
}
-Text_t compile_struct_header(env_t *env, ast_t *ast)
-{
+Text_t compile_struct_header(env_t *env, ast_t *ast) {
DeclareMatch(def, ast, StructDef);
Text_t typeinfo_name = namespace_name(env, env->namespace, Texts(def->name, "$$info"));
- Text_t type_code = def->external ? Text$from_str(def->name)
- : Texts("struct ", namespace_name(env, env->namespace, Texts(def->name, "$$struct")));
+ Text_t type_code = def->external
+ ? Text$from_str(def->name)
+ : Texts("struct ", namespace_name(env, env->namespace, Texts(def->name, "$$struct")));
Text_t fields = EMPTY_TEXT;
for (arg_ast_t *field = def->fields; field; field = field->next) {
@@ -65,12 +67,13 @@ Text_t compile_struct_header(env_t *env, ast_t *ast)
Text_t struct_code = def->external ? EMPTY_TEXT : Texts(type_code, " {\n", fields, "};\n");
type_t *t = Table$str_get(*env->types, def->name);
- Text_t unpadded_size = def->opaque ? Texts("sizeof(", type_code, ")") : Text$from_str(String((int64_t)unpadded_struct_size(t)));
+ Text_t unpadded_size =
+ def->opaque ? Texts("sizeof(", type_code, ")") : Text$from_str(String((int64_t)unpadded_struct_size(t)));
Text_t typeinfo_code = Texts("extern const TypeInfo_t ", typeinfo_name, ";\n");
Text_t optional_code = EMPTY_TEXT;
if (!def->opaque) {
optional_code = Texts("DEFINE_OPTIONAL_TYPE(", compile_type(t), ", ", unpadded_size, ", ",
- namespace_name(env, env->namespace, Texts("$Optional", def->name, "$$type")), ");\n");
+ namespace_name(env, env->namespace, Texts("$Optional", def->name, "$$type")), ");\n");
}
return Texts(struct_code, optional_code, typeinfo_code);
}