aboutsummaryrefslogtreecommitdiff
path: root/src/checker/stmt.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2016-08-30 00:04:14 +0100
committerGinger Bill <bill@gingerbill.org>2016-08-30 00:04:14 +0100
commit0eaf7bd830dcda6e00f80eefed36bdf7beb02d5d (patch)
tree3e65c52384458031b5ede490429c9c1938d8ba0b /src/checker/stmt.cpp
parent593563d8eabf725ac851f4c3c72cd32b5a71aa7c (diff)
Begin "Everything's a namespace"
Diffstat (limited to 'src/checker/stmt.cpp')
-rw-r--r--src/checker/stmt.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/checker/stmt.cpp b/src/checker/stmt.cpp
index 9e54a73e3..a0d1838a8 100644
--- a/src/checker/stmt.cpp
+++ b/src/checker/stmt.cpp
@@ -685,6 +685,75 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
}
case_end;
+ case_ast_node(us, UsingStmt, node);
+ switch (us->node->kind) {
+ case_ast_node(es, ExprStmt, us->node);
+ AstNode *ident = es->expr;
+ GB_ASSERT(ident->kind == AstNode_Ident);
+ String name = ident->Ident.token.string;
+
+ Entity *e = scope_lookup_entity(c, c->context.scope, name);
+ if (e == NULL) {
+ error(&c->error_collector, us->token, "`using` applied to an unknown entity");
+ return;
+ }
+
+ switch (e->kind) {
+ case Entity_TypeName: {
+ Type *t = get_base_type(e->type);
+ if (t->kind == Type_Enum) {
+ for (isize i = 0; i < t->Enum.field_count; i++) {
+ Entity *f = t->Enum.fields[i];
+ Entity *found = scope_insert_entity(c->context.scope, f);
+ if (found != NULL) {
+ error(&c->error_collector, us->token, "Namespace collision while `using` `%.*s` of the constant: %.*s", LIT(name), LIT(found->token.string));
+ return;
+ }
+ f->using_parent = e;
+ }
+ } else if (t->kind == Type_Struct) {
+ for (isize i = 0; i < t->Struct.other_field_count; i++) {
+ Entity *f = t->Struct.other_fields[i];
+ Entity *found = scope_insert_entity(c->context.scope, f);
+ if (found != NULL) {
+ error(&c->error_collector, us->token, "Namespace collision while `using` `%.*s` of: %.*s", LIT(name), LIT(found->token.string));
+ return;
+ }
+ f->using_parent = e;
+ }
+ }
+ } break;
+
+ case Entity_Constant:
+ error(&c->error_collector, us->token, "`using` cannot be applied to a constant");
+ break;
+
+ case Entity_Procedure:
+ case Entity_Builtin:
+ error(&c->error_collector, us->token, "`using` cannot be applied to a procedure");
+ break;
+
+ default:
+ GB_PANIC("TODO(bill): using Ident");
+ }
+ case_end;
+
+ case_ast_node(vd, VarDecl, us->node);
+ GB_PANIC("TODO(bill): using VarDecl");
+ case_end;
+
+
+ default:
+ error(&c->error_collector, us->token, "Invalid AST: Using Statement");
+ break;
+ }
+ case_end;
+
+
+
+
+
+
case_ast_node(vd, VarDecl, node);
isize entity_count = vd->name_count;
isize entity_index = 0;