aboutsummaryrefslogtreecommitdiff
path: root/src/check_decl.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-12-03 23:03:40 +0000
committergingerBill <bill@gingerbill.org>2017-12-03 23:03:40 +0000
commit596a2c835554a26cb0ad1f83892a3a11c04bad25 (patch)
tree432c9cbf862d33c840c8664a4f31587e142cfc35 /src/check_decl.cpp
parent9f52b2c2834a3a7248784492a3ede3a8a9063f6a (diff)
Procedure grouping `foo :: proc[foo16, foo32];`
Diffstat (limited to 'src/check_decl.cpp')
-rw-r--r--src/check_decl.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index b7bd91183..7b01c259e 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -708,6 +708,47 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
check_init_variables(c, entities, entity_count, init_expr_list, context_name);
}
+void check_proc_grouping_decl(Checker *c, Entity *pg_entity, DeclInfo *d) {
+ GB_ASSERT(pg_entity->kind == Entity_ProcedureGrouping);
+ auto *pge = &pg_entity->ProcedureGrouping;
+
+ ast_node(pg, ProcGrouping, d->init_expr);
+
+ array_init(&pge->entities, c->allocator, pg->args.count);
+
+
+ PtrSet<Entity *> entity_map = {};
+ ptr_set_init(&entity_map, heap_allocator());
+ defer (ptr_set_destroy(&entity_map));
+
+ for_array(i, pg->args) {
+ AstNode *arg = pg->args[i];
+ Entity *e = nullptr;
+ Operand o = {};
+ if (arg->kind == AstNode_Ident) {
+ e = check_ident(c, &o, arg, nullptr, nullptr, true);
+ } else if (arg->kind == AstNode_SelectorExpr) {
+ e = check_selector(c, &o, arg, nullptr);
+ }
+ if (e == nullptr) {
+ error(arg, "Expected a valid entity name in procedure grouping");
+ continue;
+ }
+ if (e->kind != Entity_Procedure) {
+ error(arg, "Expected a procedure entity");
+ continue;
+ }
+
+ if (ptr_set_exists(&entity_map, e)) {
+ error(arg, "Previous use of `%.*s` in procedure grouping", LIT(e->token.string));
+ continue;
+ }
+ ptr_set_add(&entity_map, e);
+
+ array_add(&pge->entities, e);
+ }
+}
+
void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
if (e->type != nullptr) {
return;
@@ -745,6 +786,11 @@ void check_entity_decl(Checker *c, Entity *e, DeclInfo *d, Type *named_type) {
case Entity_Procedure:
check_proc_decl(c, e, d);
break;
+
+ case Entity_ProcedureGrouping:
+ // error(e->token, "Procedure groupings are not yet supported");
+ check_proc_grouping_decl(c, e, d);
+ break;
}
c->context = prev;