diff options
| author | gingerBill <ginger.bill.22@gmail.com> | 2016-08-05 00:54:05 +0100 |
|---|---|---|
| committer | gingerBill <ginger.bill.22@gmail.com> | 2016-08-05 00:54:05 +0100 |
| commit | 2aaef48c5c362bb3e04d0c9cd1e722e21b3755e5 (patch) | |
| tree | f7b99cda983ce6226384127672abea74459b05b3 /src/checker | |
| parent | 19aea1f19895b035e8abb424987f48df6bc52c53 (diff) | |
String support
Diffstat (limited to 'src/checker')
| -rw-r--r-- | src/checker/checker.cpp | 37 | ||||
| -rw-r--r-- | src/checker/expr.cpp | 5 | ||||
| -rw-r--r-- | src/checker/stmt.cpp | 22 |
3 files changed, 30 insertions, 34 deletions
diff --git a/src/checker/checker.cpp b/src/checker/checker.cpp index 53ce8ac18..98e371e33 100644 --- a/src/checker/checker.cpp +++ b/src/checker/checker.cpp @@ -219,6 +219,23 @@ void destroy_scope(Scope *scope) { // NOTE(bill): No need to free scope as it "should" be allocated in an arena (except for the global scope) } +void add_scope(Checker *c, AstNode *node, Scope *scope) { + GB_ASSERT(node != NULL); + GB_ASSERT(scope != NULL); + map_set(&c->info.scopes, hash_pointer(node), scope); +} + + +void check_open_scope(Checker *c, AstNode *stmt) { + GB_ASSERT(is_ast_node_stmt(stmt) || stmt->kind == AstNode_ProcType); + Scope *scope = make_scope(c->context.scope, c->allocator); + add_scope(c, stmt, scope); + c->context.scope = scope; +} + +void check_close_scope(Checker *c) { + c->context.scope = c->context.scope->parent; +} void scope_lookup_parent_entity(Scope *s, String name, Scope **scope, Entity **entity) { u64 key = hash_string(name); @@ -359,7 +376,6 @@ void init_checker(Checker *c, Parser *parser) { c->sizes.word_size = 8; c->sizes.max_align = 8; - gb_array_init(c->procedure_stack, a); gb_array_init(c->procedures, a); @@ -487,25 +503,6 @@ void check_procedure_later(Checker *c, AstFile *file, Token token, DeclInfo *dec gb_array_append(c->procedures, info); } - - -void add_scope(Checker *c, AstNode *node, Scope *scope) { - GB_ASSERT(node != NULL); - GB_ASSERT(scope != NULL); - map_set(&c->info.scopes, hash_pointer(node), scope); -} - - -void check_open_scope(Checker *c, AstNode *statement) { - Scope *scope = make_scope(c->context.scope, c->allocator); - add_scope(c, statement, scope); - c->context.scope = scope; -} - -void check_close_scope(Checker *c) { - c->context.scope = c->context.scope->parent; -} - void check_add_deferred_stmt(Checker *c, AstNode *stmt) { GB_ASSERT(stmt != NULL); GB_ASSERT(is_ast_node_stmt(stmt)); diff --git a/src/checker/expr.cpp b/src/checker/expr.cpp index 7a1fdb70e..4129e6e73 100644 --- a/src/checker/expr.cpp +++ b/src/checker/expr.cpp @@ -954,6 +954,7 @@ b32 check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *valu } Entity *lookup_field(Type *type, AstNode *field_node, isize *index = NULL) { + GB_ASSERT(type != NULL); GB_ASSERT(field_node->kind == AstNode_Ident); type = get_base_type(type); if (type->kind == Type_Pointer) @@ -1192,7 +1193,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id) if (is_type_string(t)) { if (operand->mode == Addressing_Constant) { mode = Addressing_Constant; - value = make_exact_value_integer(operand->value.value_string.len); + value = make_exact_value_integer(operand->value.value_string); } else { mode = Addressing_Value; } @@ -1683,7 +1684,6 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ if (o->mode == Addressing_Constant) { max_count = o->value.value_string.len; } - o->mode = Addressing_Value; o->type = t_u8; } break; @@ -1743,6 +1743,7 @@ ExpressionKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *typ if (o->mode == Addressing_Constant) { max_count = o->value.value_string.len; } + o->type = t_string; o->mode = Addressing_Value; } break; diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp index 676e74fa9..67ade56a5 100644 --- a/src/checker/stmt.cpp +++ b/src/checker/stmt.cpp @@ -408,11 +408,15 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) { e->type = proc_type; ast_node(pd, ProcDecl, d->proc_decl); -#if 1 Scope *original_curr_scope = c->context.scope; c->context.scope = c->global_scope; check_open_scope(c, pd->type); -#endif + defer ({ + check_close_scope(c); + c->context.scope = original_curr_scope; + }); + + check_procedure_type(c, proc_type, pd->type); b32 is_foreign = false; b32 is_inline = false; @@ -455,11 +459,6 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) { } } -#if 1 - check_close_scope(c); - c->context.scope = original_curr_scope; -#endif - } void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count, AstNode *type_expr, AstNode *init_expr) { @@ -554,8 +553,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { case_end; case_ast_node(ids, IncDecStmt, node); - Token op = {}; - op = ids->op; + Token op = ids->op; switch (ids->op.kind) { case Token_Increment: op.kind = Token_Add; @@ -717,9 +715,9 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) { result_count = proc_type->procedure.results->tuple.variable_count; if (result_count != rs->result_count) { error(&c->error_collector, rs->token, "Expected %td return %s, got %td", - result_count, - (result_count != 1 ? "values" : "value"), - rs->result_count); + result_count, + (result_count != 1 ? "values" : "value"), + rs->result_count); } else if (result_count > 0) { auto *tuple = &proc_type->procedure.results->tuple; check_init_variables(c, tuple->variables, tuple->variable_count, |