Browse Source

Merge branch 'master' of https://github.com/gingerBill/Odin

Ginger Bill 8 years ago
parent
commit
3546391311
6 changed files with 41 additions and 23 deletions
  1. 3 3
      src/check_expr.cpp
  2. 2 1
      src/checker.cpp
  3. 2 3
      src/ir.cpp
  4. 17 13
      src/ir_print.cpp
  5. 13 3
      src/parser.cpp
  6. 4 0
      src/types.cpp

+ 3 - 3
src/check_expr.cpp

@@ -4619,10 +4619,10 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h
 
 			bool implicit_is_found = is_entity_implicitly_imported(e, entity);
 			bool is_not_exported = !is_entity_exported(entity);
-			if (!implicit_is_found) {
-				is_not_exported = false;
-			} else if (entity->kind == Entity_ImportName) {
+			if (entity->kind == Entity_ImportName) {
 				is_not_exported = true;
+			} else if (!implicit_is_found) {
+				is_not_exported = false;
 			}
 
 			if (is_not_exported) {

+ 2 - 1
src/checker.cpp

@@ -1734,7 +1734,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
src/ir.cpp

@@ -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;
 

+ 17 - 13
src/ir_print.cpp

@@ -183,10 +183,9 @@ void ir_print_proc_type_without_pointer(irFileBuffer *f, irModule *m, Type *t) {
 	ir_fprintf(f, " (");
 	if (t->Proc.return_by_pointer) {
 		ir_print_type(f, m, reduce_tuple_to_single_type(t->Proc.results));
-		ir_fprintf(f, "* sret noalias ");
-		if (param_count > 0) {
-			ir_fprintf(f, ", ");
-		}
+		// ir_fprintf(f, "* sret noalias ");
+		ir_fprintf(f, "* noalias ");
+		if (param_count > 0) ir_fprintf(f, ", ");
 	}
 	isize param_index = 0;
 	for (isize i = 0; i < param_count; i++) {
@@ -247,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);
@@ -333,12 +336,16 @@ void ir_print_type(irFileBuffer *f, irModule *m, Type *t) {
 
 
 	case Type_Named:
-		if (is_type_struct(t) || is_type_union(t)) {
+		switch (base_type(t)->kind) {
+		case Type_Struct:
+		case Type_Union: {
 			String *name = map_get(&m->entity_names, hash_pointer(t->Named.type_name));
 			GB_ASSERT_MSG(name != nullptr, "%.*s %p", LIT(t->Named.name), t->Named.type_name);
 			ir_print_encoded_local(f, *name);
-		} else {
+		} break;
+		default:
 			ir_print_type(f, m, base_type(t));
+			break;
 		}
 		return;
 	case Type_Tuple:
@@ -1718,9 +1725,6 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
 void ir_print_type_name(irFileBuffer *f, irModule *m, irValue *v) {
 	GB_ASSERT(v->kind == irValue_TypeName);
 	Type *bt = base_type(ir_type(v));
-	if (!is_type_struct(bt) && !is_type_union(bt)) {
-		return;
-	}
 	ir_print_encoded_local(f, v->TypeName.name);
 	ir_fprintf(f, " = type ");
 	ir_print_type(f, m, base_type(v->TypeName.type));

+ 13 - 3
src/parser.cpp

@@ -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 - 0
src/types.cpp

@@ -881,6 +881,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) {