Fix IR print bug for empty structs;

This commit is contained in:
gingerBill
2017-07-28 11:35:01 +01:00
parent f0980c0a98
commit 28be0ad69b
5 changed files with 29 additions and 11 deletions
+2 -1
View File
@@ -1733,7 +1733,8 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
DeclInfo *d = make_declaration_info(c->allocator, c->context.scope, c->context.decl);
Entity *e = nullptr;
if (is_ast_node_type(init)) {
if (is_ast_node_type(init) ||
(vd->type != nullptr && vd->type->kind == AstNode_TypeType)) {
e = make_entity_type_name(c->allocator, d->scope, token, nullptr);
if (vd->type != nullptr) {
error(name, "A type declaration cannot have an type parameter");
+2 -3
View File
@@ -6370,9 +6370,8 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
case_ast_node(ds, DeferStmt, node);
ir_emit_comment(proc, str_lit("DeferStmt"));
isize scope_index = proc->scope_index;
if (ds->stmt->kind == AstNode_BlockStmt) {
scope_index--;
}
// TODO(bill): What was the original rationale behind this line?
// if (ds->stmt->kind == AstNode_BlockStmt) scope_index--;
ir_add_defer_node(proc, scope_index, ds->stmt);
case_end;
+8 -4
View File
@@ -246,10 +246,14 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
case Basic_any: ir_fprintf(f, "%%..any"); return;
}
break;
case Type_Pointer:
ir_print_type(f, m, t->Pointer.elem);
ir_fprintf(f, "*");
return;
case Type_Pointer: {
if (!is_type_named(t->Pointer.elem) && is_type_empty_struct(t->Pointer.elem)) {
ir_print_type(f, m, t_rawptr);
} else {
ir_print_type(f, m, t->Pointer.elem);
ir_fprintf(f, "*");
}
} return;
case Type_Array:
ir_fprintf(f, "[%lld x ", t->Array.count);
ir_print_type(f, m, t->Array.elem);
+13 -3
View File
@@ -3250,12 +3250,22 @@ AstNode *parse_value_decl(AstFile *f, Array<AstNode *> names, CommentGroup docs)
Array<AstNode *> values = {};
Token colon = expect_token_after(f, Token_Colon, "identifier list");
type = parse_type_attempt(f);
if (f->curr_token.kind == Token_type) {
type = ast_type_type(f, advance_token(f), nullptr);
is_mutable = false;
} else {
type = parse_type_attempt(f);
}
if (f->curr_token.kind == Token_Eq ||
f->curr_token.kind == Token_Colon) {
Token sep = advance_token(f);
is_mutable = sep.kind != Token_Colon;
Token sep = {};
if (!is_mutable) {
sep = expect_token_after(f, Token_Colon, "type");
} else {
sep = advance_token(f);
is_mutable = sep.kind != Token_Colon;
}
values = parse_rhs_expr_list(f);
if (values.count > names.count) {
syntax_error(f->curr_token, "Too many values on the right hand side of the declaration");
+4
View File
@@ -878,6 +878,10 @@ bool is_type_empty_union(Type *t) {
t = base_type(t);
return t->kind == Type_Union && t->Union.variants.count == 0;
}
bool is_type_empty_struct(Type *t) {
t = base_type(t);
return t->kind == Type_Struct && !t->Struct.is_raw_union && t->Struct.fields.count == 0;
}
bool is_type_valid_for_keys(Type *t) {