commit 2678ff52c2291d65015da08f6e5d01a2ad49627a
parent 361cf2cdcc64a6fc1a8c6bf38864fe0b997876ef
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 20 Jan 2021 16:19:29 -0500
check: add types to declarations
Diffstat:
3 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/include/check.h b/include/check.h
@@ -50,6 +50,7 @@ struct declaration {
union {
struct function_decl func;
struct global_decl global;
+ const struct type *_type;
};
};
diff --git a/src/check.c b/src/check.c
@@ -1300,6 +1300,19 @@ check_global(struct context *ctx,
return decl;
}
+static struct declaration *
+check_type(struct context *ctx,
+ const struct ast_decl *adecl)
+{
+ const struct type *type =
+ type_store_lookup_atype(&ctx->store, adecl->type.type);
+ struct declaration *decl = xcalloc(1, sizeof(struct declaration));
+ decl->type = DECL_TYPE;
+ decl->_type = type;
+ mkident(ctx, &decl->ident, &adecl->type.ident);
+ return decl;
+}
+
static struct declarations **
check_declarations(struct context *ctx,
const struct ast_decls *adecls,
@@ -1310,16 +1323,17 @@ check_declarations(struct context *ctx,
struct declaration *decl = NULL;
const struct ast_decl *adecl = &adecls->decl;
switch (adecl->decl_type) {
+ case AST_DECL_CONST:
+ break; // Handled in scan
case AST_DECL_FUNC:
decl = check_function(ctx, adecl);
break;
- case AST_DECL_TYPE:
- break; // Handled in scan
case AST_DECL_GLOBAL:
decl = check_global(ctx, adecl);
break;
- case AST_DECL_CONST:
- break; // Handled in scan
+ case AST_DECL_TYPE:
+ decl = check_type(ctx, adecl);
+ break;
}
if (decl) {
diff --git a/src/gen.c b/src/gen.c
@@ -1920,7 +1920,8 @@ gen_decl(struct gen_context *ctx, const struct declaration *decl)
break;
case DECL_TYPE:
case DECL_CONSTANT:
- assert(0); // Invariant
+ // Nothing to do
+ break;
}
}