[qfcc] Implement auto as per c23

That was surprisingly easy, which makes me worried I missed something.
This commit is contained in:
Bill Currie 2023-08-18 16:05:54 +09:00
parent cb4b073e47
commit b9fd7a46af
4 changed files with 19 additions and 2 deletions

View file

@ -120,6 +120,7 @@ typedef struct specifier_s {
#define VEC_TYPE(type_name, base_type) extern type_t type_##type_name;
#include "tools/qfcc/include/vec_types.h"
extern type_t type_auto;
extern type_t type_invalid;
extern type_t type_floatfield;

View file

@ -587,6 +587,16 @@ initialize_def (symbol_t *sym, expr_t *init, defspace_t *space,
sym->type = array_type (sym->type->t.array.type,
num_elements (init));
}
if (sym->type == &type_auto) {
if (init) {
if (!(sym->type = get_type (init))) {
sym->type = type_default;
}
} else {
error (0, "'auto' requires an initialized data declaration");
sym->type = type_default;
}
}
sym->s.def = new_def (sym->name, sym->type, space, storage);
reloc_attach_relocs (relocs, &sym->s.def->relocs);
}

View file

@ -415,6 +415,7 @@ static keyword_t at_keywords[] = {
{"static", STATIC },
{"sizeof", SIZEOF },
{"not", NOT },
{"auto", TYPE_SPEC, .spec = { .type = &type_auto } },
};
// These keywords require the QuakeForge VM to be of any use. ie, they cannot

View file

@ -79,6 +79,11 @@ type_t type_invalid = {
.name = "invalid",
};
type_t type_auto = {
.type = ev_invalid,
.name = "auto",
};
#define VEC_TYPE(type_name, base_type) \
type_t type_##type_name = { \
.type = ev_##base_type, \
@ -527,8 +532,8 @@ find_type (type_t *type)
type_t *check;
int i, count;
if (!type)
return 0;
if (!type || type == &type_auto)
return type;
if (type->freeable) {
switch (type->meta) {