mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[cexpr] Require designated initializers for exprtype_t
This will make expanding it much safer in the future.
This commit is contained in:
parent
8a411dc120
commit
db5b77c838
8 changed files with 100 additions and 91 deletions
|
@ -55,7 +55,7 @@ typedef struct exprtype_s {
|
|||
binop_t *binops;
|
||||
unop_t *unops;
|
||||
void *data;
|
||||
} exprtype_t;
|
||||
} __attribute__((designated_init)) exprtype_t;
|
||||
|
||||
typedef struct exprval_s {
|
||||
exprtype_t *type;
|
||||
|
|
|
@ -124,10 +124,10 @@ unop_t int_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_int = {
|
||||
"int",
|
||||
sizeof (int),
|
||||
int_binops,
|
||||
int_unops,
|
||||
.name = "int",
|
||||
.size = sizeof (int),
|
||||
.binops = int_binops,
|
||||
.unops = int_unops,
|
||||
};
|
||||
|
||||
BINOP(uint, shl, unsigned, <<)
|
||||
|
@ -179,10 +179,10 @@ unop_t uint_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_uint = {
|
||||
"uint",
|
||||
sizeof (unsigned),
|
||||
uint_binops,
|
||||
uint_unops,
|
||||
.name = "uint",
|
||||
.size = sizeof (unsigned),
|
||||
.binops = uint_binops,
|
||||
.unops = uint_unops,
|
||||
};
|
||||
|
||||
BINOP(size_t, shl, unsigned, <<)
|
||||
|
@ -248,10 +248,10 @@ unop_t size_t_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_size_t = {
|
||||
"size_t",
|
||||
sizeof (size_t),
|
||||
size_t_binops,
|
||||
size_t_unops,
|
||||
.name = "size_t",
|
||||
.size = sizeof (size_t),
|
||||
.binops = size_t_binops,
|
||||
.unops = size_t_unops,
|
||||
};
|
||||
|
||||
BINOP(float, add, float, +)
|
||||
|
@ -333,10 +333,10 @@ unop_t float_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_float = {
|
||||
"float",
|
||||
sizeof (float),
|
||||
float_binops,
|
||||
float_unops,
|
||||
.name = "float",
|
||||
.size = sizeof (float),
|
||||
.binops = float_binops,
|
||||
.unops = float_unops,
|
||||
};
|
||||
|
||||
BINOP(double, add, double, +)
|
||||
|
@ -397,10 +397,10 @@ unop_t double_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_double = {
|
||||
"double",
|
||||
sizeof (double),
|
||||
double_binops,
|
||||
double_unops,
|
||||
.name = "double",
|
||||
.size = sizeof (double),
|
||||
.binops = double_binops,
|
||||
.unops = double_unops,
|
||||
};
|
||||
|
||||
BINOP(vector, add, vec4f_t, +)
|
||||
|
@ -546,10 +546,10 @@ unop_t vector_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_vector = {
|
||||
"vector",
|
||||
sizeof (vec4f_t),
|
||||
vector_binops,
|
||||
vector_unops,
|
||||
.name = "vector",
|
||||
.size = sizeof (vec4f_t),
|
||||
.binops = vector_binops,
|
||||
.unops = vector_unops,
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -588,31 +588,31 @@ unop_t quaternion_unops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_quaternion = {
|
||||
"quaterion",
|
||||
sizeof (vec4f_t),
|
||||
quaternion_binops,
|
||||
quaternion_unops,
|
||||
.name = "quaterion",
|
||||
.size = sizeof (vec4f_t),
|
||||
.binops = quaternion_binops,
|
||||
.unops = quaternion_unops,
|
||||
};
|
||||
|
||||
exprtype_t cexpr_exprval = {
|
||||
"exprval",
|
||||
sizeof (exprval_t *),
|
||||
0, // can't actually do anything with an exprval
|
||||
0,
|
||||
.name = "exprval",
|
||||
.size = sizeof (exprval_t *),
|
||||
.binops = 0, // can't actually do anything with an exprval
|
||||
.unops = 0,
|
||||
};
|
||||
|
||||
exprtype_t cexpr_field = {
|
||||
"field",
|
||||
0, // has no size of its own, rather, it's the length of the name
|
||||
0, // can't actually do anything with a field
|
||||
0,
|
||||
.name = "field",
|
||||
.size = 0, // has no size of its own, rather, it's the length of the name
|
||||
.binops = 0, // can't actually do anything with a field
|
||||
.unops = 0,
|
||||
};
|
||||
|
||||
exprtype_t cexpr_function = {
|
||||
"function",
|
||||
0, // has no size of its own
|
||||
0, // can't actually do anything with a function other than call
|
||||
0,
|
||||
.name = "function",
|
||||
.size = 0, // has no size of its own
|
||||
.binops = 0,// can't actually do anything with a function other than call
|
||||
.unops = 0,
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -711,10 +711,10 @@ binop_t plitem_binops[] = {
|
|||
};
|
||||
|
||||
exprtype_t cexpr_plitem = {
|
||||
"plitem",
|
||||
sizeof (plitem_t *),
|
||||
plitem_binops,
|
||||
0,
|
||||
.name = "plitem",
|
||||
.size = sizeof (plitem_t *),
|
||||
.binops = plitem_binops,
|
||||
.unops = 0,
|
||||
};
|
||||
|
||||
VISIBLE binop_t *
|
||||
|
|
|
@ -114,10 +114,10 @@ static binop_t cvar_binops[] = {
|
|||
};
|
||||
|
||||
static exprtype_t cvar_type = {
|
||||
"cvar",
|
||||
sizeof (void *), // ref to struct (will always be 0)
|
||||
cvar_binops,
|
||||
0,
|
||||
.name = "cvar",
|
||||
.size = sizeof (void *), // ref to struct (will always be 0)
|
||||
.binops = cvar_binops,
|
||||
.unops = 0,
|
||||
};
|
||||
|
||||
VISIBLE exprval_t *
|
||||
|
|
|
@ -50,11 +50,11 @@ exprarray_t int_array_4_data = {
|
|||
sizeof (array) / sizeof (array[0]),
|
||||
};
|
||||
exprtype_t int_array_4 = {
|
||||
"int[4]",
|
||||
4 * sizeof (int),
|
||||
cexpr_array_binops,
|
||||
0,
|
||||
&int_array_4_data,
|
||||
.name = "int[4]",
|
||||
.size = 4 * sizeof (int),
|
||||
.binops = cexpr_array_binops,
|
||||
.unops = 0,
|
||||
.data = &int_array_4_data,
|
||||
};
|
||||
|
||||
exprsym_t symbols[] = {
|
||||
|
|
|
@ -89,16 +89,17 @@ skip_value(string name)
|
|||
strip_bit = 1;
|
||||
}
|
||||
|
||||
fprintf (output_file, "static exprtype_t %s_type = {\n", [self name]);
|
||||
fprintf (output_file, "\t\"%s\",\n", [self name]);
|
||||
fprintf (output_file, "\tsizeof (int),\n");
|
||||
fprintf (output_file, "exprtype_t %s_type = {\n", [self name]);
|
||||
fprintf (output_file, "\t.name = \"%s\",\n", [self name]);
|
||||
fprintf (output_file, "\t.size = sizeof (int),\n");
|
||||
if (strip_bit) {
|
||||
fprintf (output_file, "\tflag_binops,\n");
|
||||
fprintf (output_file, "\tflag_unops,\n");
|
||||
fprintf (output_file, "\t.binops = flag_binops,\n");
|
||||
fprintf (output_file, "\t.unops = flag_unops,\n");
|
||||
} else {
|
||||
fprintf (output_file, "\tenum_binops,\n");
|
||||
fprintf (output_file, "\t0,\n");
|
||||
fprintf (output_file, "\t.binops = enum_binops,\n");
|
||||
fprintf (output_file, "\t.unops = 0,\n");
|
||||
}
|
||||
fprintf (output_file, "\t.data = &%s_enum,\n", [self name]);
|
||||
fprintf (output_file, "};\n");
|
||||
|
||||
if (![self isEmpty]) {
|
||||
|
@ -114,7 +115,7 @@ skip_value(string name)
|
|||
}
|
||||
fprintf (output_file, "};\n");
|
||||
}
|
||||
fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", [self name]);
|
||||
fprintf (output_file, "exprsym_t %s_symbols[] = {\n", [self name]);
|
||||
for (int i = 0, index = 0; i < type.strct.num_fields; i++) {
|
||||
qfot_var_t *var = &type.strct.fields[i];
|
||||
if (skip_value (var.name)) {
|
||||
|
@ -137,10 +138,10 @@ skip_value(string name)
|
|||
}
|
||||
fprintf (output_file, "\t{ }\n");
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (output_file, "static exprtab_t %s_symtab = {\n", [self name]);
|
||||
fprintf (output_file, "exprtab_t %s_symtab = {\n", [self name]);
|
||||
fprintf (output_file, "\t%s_symbols,\n", [self name]);
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (output_file, "static exprenum_t %s_enum = {\n", [self name]);
|
||||
fprintf (output_file, "exprenum_t %s_enum = {\n", [self name]);
|
||||
fprintf (output_file, "\t&%s_type,\n", [self name]);
|
||||
fprintf (output_file, "\t&%s_symtab,\n", [self name]);
|
||||
fprintf (output_file, "};\n");
|
||||
|
@ -163,6 +164,10 @@ skip_value(string name)
|
|||
" const plitem_t *item, void *data, plitem_t *messages,"
|
||||
" void *context);\n",
|
||||
[self name]);
|
||||
fprintf (header_file, "extern exprenum_t %s_enum;\n", [self name]);
|
||||
fprintf (header_file, "extern exprtype_t %s_type;\n", [self name]);
|
||||
fprintf (header_file, "extern exprtab_t %s_symtab;\n", [self name]);
|
||||
fprintf (header_file, "extern exprsym_t %s_symbols[];\n", [self name]);
|
||||
}
|
||||
|
||||
-(void) writeSymtabInit
|
||||
|
|
|
@ -52,11 +52,13 @@
|
|||
fprintf (output_file, "\t%d,\n", ele_count);
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (output_file, "exprtype_t %s_type = {\n", [self name]);
|
||||
fprintf (output_file, "\t\"%s[%d]\",\n", [ele_type name], ele_count);
|
||||
fprintf (output_file, "\t%d * sizeof (%s),\n", ele_count, [ele_type name]);
|
||||
fprintf (output_file, "\tcexpr_array_binops,\n");
|
||||
fprintf (output_file, "\t0,\n");
|
||||
fprintf (output_file, "\t&%s_array,\n", [self name]);
|
||||
fprintf (output_file, "\t.name = \"%s[%d]\",\n", [ele_type name],
|
||||
ele_count);
|
||||
fprintf (output_file, "\t.size = %d * sizeof (%s),\n", ele_count,
|
||||
[ele_type name]);
|
||||
fprintf (output_file, "\t.binops = cexpr_array_binops,\n");
|
||||
fprintf (output_file, "\t.unops = 0,\n");
|
||||
fprintf (output_file, "\t.data = &%s_array,\n", [self name]);
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (output_file, "\n");
|
||||
fprintf (header_file, "extern exprtype_t %s_type;\n", [self name]);
|
||||
|
|
|
@ -189,11 +189,11 @@
|
|||
fprintf (output_file, "};\n");
|
||||
|
||||
fprintf (output_file, "exprtype_t %s_type = {\n", [self outname]);
|
||||
fprintf (output_file, "\t\"%s\",\n", [self outname]);
|
||||
fprintf (output_file, "\tsizeof (%s),\n", [self outname]);
|
||||
fprintf (output_file, "\tcexpr_struct_binops,\n");
|
||||
fprintf (output_file, "\t0,\n");
|
||||
fprintf (output_file, "\t&%s_symtab,\n", [self outname]);
|
||||
fprintf (output_file, "\t.name = \"%s\",\n", [self outname]);
|
||||
fprintf (output_file, "\t.size = sizeof (%s),\n", [self outname]);
|
||||
fprintf (output_file, "\t.binops = cexpr_struct_binops,\n");
|
||||
fprintf (output_file, "\t.unops = 0,\n");
|
||||
fprintf (output_file, "\t.data = &%s_symtab,\n", [self outname]);
|
||||
fprintf (output_file, "};\n");
|
||||
fprintf (output_file, "\n");
|
||||
fprintf (header_file, "extern exprtype_t %s_type;\n", [self outname]);
|
||||
|
|
|
@ -589,9 +589,11 @@ parse_VkImage (const plitem_t *item, void **data, plitem_t *messages,
|
|||
}
|
||||
|
||||
exprtype_t VkImageView_type = {
|
||||
"VkImageView",
|
||||
sizeof (VkImageView),
|
||||
0, 0, 0
|
||||
.name = "VkImageView",
|
||||
.size = sizeof (VkImageView),
|
||||
.binops = 0,
|
||||
.unops = 0,
|
||||
.data = 0
|
||||
};
|
||||
|
||||
static int
|
||||
|
@ -805,10 +807,10 @@ data_array (const exprval_t **params, exprval_t *result, exprctx_t *context)
|
|||
}
|
||||
|
||||
static exprtype_t data_array_type = {
|
||||
"array",
|
||||
sizeof (data_array_t *),
|
||||
0,
|
||||
0,
|
||||
.name = "array",
|
||||
.size = sizeof (data_array_t *),
|
||||
.binops = 0,
|
||||
.unops = 0,
|
||||
};
|
||||
static exprfunc_t data_array_func[] = {
|
||||
{ &data_array_type, -1, 0, data_array },
|
||||
|
@ -877,11 +879,11 @@ static exprtab_t qfv_output_t_symtab = {
|
|||
qfv_output_t_symbols,
|
||||
};
|
||||
exprtype_t qfv_output_t_type = {
|
||||
"qfv_output_t",
|
||||
sizeof (qfv_output_t),
|
||||
cexpr_struct_binops,
|
||||
0,
|
||||
&qfv_output_t_symtab,
|
||||
.name = "qfv_output_t",
|
||||
.size = sizeof (qfv_output_t),
|
||||
.binops = cexpr_struct_binops,
|
||||
.unops = 0,
|
||||
.data = &qfv_output_t_symtab,
|
||||
};
|
||||
|
||||
static exprsym_t vulkan_frameset_t_symbols[] = {
|
||||
|
@ -892,11 +894,11 @@ static exprtab_t vulkan_frameset_t_symtab = {
|
|||
vulkan_frameset_t_symbols,
|
||||
};
|
||||
exprtype_t vulkan_frameset_t_type = {
|
||||
"frameset",
|
||||
sizeof (vulkan_frameset_t *),
|
||||
cexpr_struct_binops,
|
||||
0,
|
||||
&vulkan_frameset_t_symtab,
|
||||
.name = "frameset",
|
||||
.size = sizeof (vulkan_frameset_t *),
|
||||
.binops = cexpr_struct_binops,
|
||||
.unops = 0,
|
||||
.data = &vulkan_frameset_t_symtab,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in a new issue