aboutsummaryrefslogtreecommitdiff
path: root/src/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug.c')
-rw-r--r--src/debug.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/src/debug.c b/src/debug.c
index f3540f0..8ef4293 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -134,14 +134,27 @@ void semantic_error(struct scope *scope, struct ast *node,
va_end(args);
}
+void type_error(struct scope *scope, struct type *type,
+ const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ struct src_issue issue;
+ issue.level = SRC_ERROR;
+ issue.loc = type->loc;
+ issue.fctx = scope->fctx;
+ _issue(issue, fmt, args);
+ va_end(args);
+}
+
void type_mismatch(struct scope *scope, struct ast *node,
struct type *l, struct type *r)
{
- const char *ls = type_str(l);
- const char *rs = type_str(r);
+ char *ls = type_str(l);
+ char *rs = type_str(r);
semantic_error(scope, node, "type mismatch: %s vs %s\n", ls, rs);
- free((void *)ls);
- free((void *)rs);
+ free(ls);
+ free(rs);
}
void move_error(struct ast *new_use, struct ast *prev_use)
@@ -213,6 +226,16 @@ static void _type_str(FILE *f, struct type *type)
fprintf(f, "void");
break;
+ case TYPE_NIL:
+ fprintf(f, "nil");
+ break;
+
+ case TYPE_ARR:
+ /** @todo length? */
+ fprintf(f, "[]");
+ _type_list_str(f, tarr_base(type));
+ break;
+
case TYPE_PTR:
fprintf(f, "*");
_type_list_str(f, tptr_base(type));
@@ -244,16 +267,10 @@ static void _type_str(FILE *f, struct type *type)
_type_list_str(f, type->t0);
fprintf(f, ")");
break;
-
- case TYPE_CONSTRUCT:
- fprintf(f, "%s![", type->id);
- _type_list_str(f, type->t0);
- fprintf(f, "]");
- break;
}
}
-const char *type_str(struct type *t)
+char *type_str(struct type *t)
{
if (!t)
return strdup("NULL");