diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-06-28 23:47:06 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-06-28 23:47:06 +0100 |
| commit | 94afcec7577f24d7f027f72765928e6dc5738234 (patch) | |
| tree | 3928353bd29c2d6b9f501243edf1fed52bf320c9 /src/check_stmt.cpp | |
| parent | 4f28e9e1fbc1d2a61c3996b2813214e2344e7e6a (diff) | |
:: style procedure declarations; remove old parsing code
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 21e960a06..32d6e9d91 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1812,161 +1812,5 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { } } case_end; - - - case_ast_node(gd, GenDecl, node); - GB_ASSERT(!c->context.scope->is_file); - for_array(i, gd->specs) { - AstNode *spec = gd->specs[i]; - switch (gd->token.kind) { - case Token_var: { - ast_node(vd, ValueSpec, spec); - - Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count); - isize entity_count = 0; - - if (gd->flags & VarDeclFlag_thread_local) { - gd->flags &= ~VarDeclFlag_thread_local; - error(node, "`thread_local` may only be applied to a variable declaration"); - } - - for_array(i, vd->names) { - AstNode *name = vd->names[i]; - Entity *entity = NULL; - if (name->kind != AstNode_Ident) { - error(name, "A variable declaration must be an identifier"); - } else { - Token token = name->Ident; - String str = token.string; - Entity *found = NULL; - // NOTE(bill): Ignore assignments to `_` - if (str != "_") { - found = current_scope_lookup_entity(c->context.scope, str); - } - if (found == NULL) { - entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, false); - entity->identifier = name; - - AstNode *fl = c->context.curr_foreign_library; - if (fl != NULL) { - GB_ASSERT(fl->kind == AstNode_Ident); - entity->Variable.is_foreign = true; - entity->Variable.foreign_library_ident = fl; - } - } else { - TokenPos pos = found->token.pos; - error(token, - "Redeclaration of `%.*s` in this scope\n" - "\tat %.*s(%td:%td)", - LIT(str), LIT(pos.file), pos.line, pos.column); - entity = found; - } - } - if (entity == NULL) { - entity = make_entity_dummy_variable(c->allocator, c->global_scope, ast_node_token(name)); - } - entity->parent_proc_decl = c->context.curr_proc_decl; - entities[entity_count++] = entity; - } - - Type *init_type = NULL; - if (vd->type) { - init_type = check_type(c, vd->type, NULL); - if (init_type == NULL) { - init_type = t_invalid; - } - } - - for (isize i = 0; i < entity_count; i++) { - Entity *e = entities[i]; - GB_ASSERT(e != NULL); - if (e->flags & EntityFlag_Visited) { - e->type = t_invalid; - continue; - } - e->flags |= EntityFlag_Visited; - - if (e->type == NULL) { - e->type = init_type; - } - } - - check_arity_match(c, vd); - check_init_variables(c, entities, entity_count, vd->values, str_lit("variable declaration")); - - for (isize i = 0; i < entity_count; i++) { - Entity *e = entities[i]; - if (e->Variable.is_foreign) { - if (vd->values.count > 0) { - error(e->token, "A foreign variable declaration cannot have a default value"); - } - init_entity_foreign_library(c, e); - - String name = e->token.string; - auto *fp = &c->info.foreigns; - HashKey key = hash_string(name); - Entity **found = map_get(fp, key); - if (found) { - Entity *f = *found; - TokenPos pos = f->token.pos; - Type *this_type = base_type(e->type); - Type *other_type = base_type(f->type); - if (!are_types_identical(this_type, other_type)) { - error(e->token, - "Foreign entity `%.*s` previously declared elsewhere with a different type\n" - "\tat %.*s(%td:%td)", - LIT(name), LIT(pos.file), pos.line, pos.column); - } - } else { - map_set(fp, key, e); - } - } - add_entity(c, c->context.scope, e->identifier, e); - } - - if ((gd->flags & VarDeclFlag_using) != 0) { - Token token = ast_node_token(node); - if (vd->type != NULL && entity_count > 1) { - error(token, "`using` can only be applied to one variable of the same type"); - // TODO(bill): Should a `continue` happen here? - } - - for (isize entity_index = 0; entity_index < entity_count; entity_index++) { - Entity *e = entities[entity_index]; - if (e == NULL) { - continue; - } - if (e->kind != Entity_Variable) { - continue; - } - bool is_immutable = e->Variable.is_immutable; - String name = e->token.string; - Type *t = base_type(type_deref(e->type)); - - if (is_type_struct(t) || is_type_raw_union(t)) { - Scope *scope = scope_of_node(&c->info, t->Record.node); - for_array(i, scope->elements.entries) { - Entity *f = scope->elements.entries[i].value; - if (f->kind == Entity_Variable) { - Entity *uvar = make_entity_using_variable(c->allocator, e, f->token, f->type); - uvar->Variable.is_immutable = is_immutable; - Entity *prev = scope_insert_entity(c->context.scope, uvar); - if (prev != NULL) { - error(token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(prev->token.string)); - return; - } - } - } - } else { - // NOTE(bill): skip the rest to remove extra errors - error(token, "`using` can only be applied to variables of type struct or raw_union"); - return; - } - } - } - } break; - } - } - case_end; } } |