From 0c22081e5f5aef99b702b159d9568d90f661b1e8 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Mon, 17 Apr 2017 19:58:43 +0100 Subject: [PATCH] Fix error printing for basic directives --- core/_preload.odin | 1 + core/os_windows.odin | 4 ++++ src/check_expr.c | 12 ++++++++++-- src/checker.c | 5 +++-- src/entity.c | 4 +++- src/tokenizer.c | 32 ++++++++++++++++---------------- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/core/_preload.odin b/core/_preload.odin index d76845c87..9153f2b55 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -39,6 +39,7 @@ Type_Info_Record :: struct #ordered { Type_Info :: union { size: int, align: int, + Named{name: string, base: ^Type_Info}, Integer{signed: bool}, Float{}, diff --git a/core/os_windows.odin b/core/os_windows.odin index d5847c3db..84c8587ea 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -210,6 +210,10 @@ read_entire_file :: proc(name: string) -> ([]byte, bool) { return nil, false; } + if length == 0 { + return nil, true; + } + data := make([]byte, length); if data == nil { return nil, false; diff --git a/src/check_expr.c b/src/check_expr.c index afb8ce0c4..e5c88d66a 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -2366,9 +2366,9 @@ bool check_is_castable_to(Checker *c, Operand *operand, Type *y) { return true; } if (is_type_string(src) && is_type_u8_slice(dst)) { - if (is_type_typed(src)) { + // if (is_type_typed(src)) { return true; - } + // } } // proc <-> proc @@ -2404,6 +2404,8 @@ void check_cast(Checker *c, Operand *x, Type *type) { } else if (check_is_castable_to(c, x, type)) { if (x->mode != Addressing_Constant) { x->mode = Addressing_Value; + } else if (is_type_slice(type) && is_type_string(x->type)) { + x->mode = Addressing_Value; } can_convert = true; } @@ -4935,6 +4937,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t check_ident(c, o, node, NULL, type_hint, false); case_end; + case_ast_node(bl, BasicLit, node); Type *t = t_invalid; switch (bl->kind) { @@ -5929,6 +5932,11 @@ gbString write_expr_to_string(gbString str, AstNode *node) { str = string_append_token(str, *bl); case_end; + case_ast_node(bd, BasicDirective, node); + str = gb_string_appendc(str, "#"); + str = gb_string_append_length(str, bd->name.text, bd->name.len); + case_end; + case_ast_node(pl, ProcLit, node); str = write_expr_to_string(str, pl->type); case_end; diff --git a/src/checker.c b/src/checker.c index c0bc83273..2f41f77a1 100644 --- a/src/checker.c +++ b/src/checker.c @@ -1521,10 +1521,11 @@ void check_collect_entities(Checker *c, AstNodeArray nodes, bool is_file_scope) AstNode *up_init = unparen_expr(init); if (up_init != NULL && is_ast_node_type(up_init)) { + AstNode *type = up_init; e = make_entity_type_name(c->allocator, d->scope, name->Ident, NULL); // TODO(bill): What if vd->type != NULL??? How to handle this case? - d->type_expr = init; - d->init_expr = init; + d->type_expr = type; + d->init_expr = type; } else if (up_init != NULL && up_init->kind == AstNode_Alias) { error_node(up_init, "#alias declarations are not yet supported"); continue; diff --git a/src/entity.c b/src/entity.c index d721df221..bfd8f8064 100644 --- a/src/entity.c +++ b/src/entity.c @@ -75,7 +75,9 @@ struct Entity { bool is_immutable; bool is_thread_local; } Variable; - i32 TypeName; + struct { + bool is_type_alias; + } TypeName; struct { bool is_foreign; String foreign_name; diff --git a/src/tokenizer.c b/src/tokenizer.c index 59ed09deb..331ca0f77 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -64,18 +64,18 @@ TOKEN_KIND(Token__ComparisonBegin, "_ComparisonBegin"), \ TOKEN_KIND(Token_GtEq, ">="), \ TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \ \ - TOKEN_KIND(Token_OpenParen, "("), \ - TOKEN_KIND(Token_CloseParen, ")"), \ - TOKEN_KIND(Token_OpenBracket, "["), \ - TOKEN_KIND(Token_CloseBracket, "]"), \ - TOKEN_KIND(Token_OpenBrace, "{"), \ - TOKEN_KIND(Token_CloseBrace, "}"), \ - TOKEN_KIND(Token_Colon, ":"), \ - TOKEN_KIND(Token_Semicolon, ";"), \ - TOKEN_KIND(Token_Period, "."), \ - TOKEN_KIND(Token_Comma, ","), \ - TOKEN_KIND(Token_Ellipsis, ".."), \ - /* TOKEN_KIND(Token_HalfOpenRange, "..<"), */ \ + TOKEN_KIND(Token_OpenParen, "("), \ + TOKEN_KIND(Token_CloseParen, ")"), \ + TOKEN_KIND(Token_OpenBracket, "["), \ + TOKEN_KIND(Token_CloseBracket, "]"), \ + TOKEN_KIND(Token_OpenBrace, "{"), \ + TOKEN_KIND(Token_CloseBrace, "}"), \ + TOKEN_KIND(Token_Colon, ":"), \ + TOKEN_KIND(Token_Semicolon, ";"), \ + TOKEN_KIND(Token_Period, "."), \ + TOKEN_KIND(Token_Comma, ","), \ + TOKEN_KIND(Token_Ellipsis, ".."), \ + TOKEN_KIND(Token_HalfOpenRange, "..<"), \ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \ \ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \ @@ -870,10 +870,10 @@ Token tokenizer_get_token(Tokenizer *t) { if (t->curr_rune == '.') { // Could be an ellipsis advance_to_next_rune(t); token.kind = Token_Ellipsis; - // if (t->curr_rune == '<') { - // advance_to_next_rune(t); - // token.kind = Token_HalfOpenRange; - // } + if (t->curr_rune == '<') { + advance_to_next_rune(t); + token.kind = Token_HalfOpenRange; + } } break;