aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp27
-rw-r--r--src/check_type.cpp24
-rw-r--r--src/checker.cpp2
-rw-r--r--src/checker.hpp2
-rw-r--r--src/ir.cpp3
-rw-r--r--src/parser.hpp6
-rw-r--r--src/types.cpp1
7 files changed, 33 insertions, 32 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 0ce662570..847296eef 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -248,6 +248,33 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Type *def)
named->Named.base = bt;
e->TypeName.is_type_alias = true;
}
+
+ // using decl
+ if (decl->is_using) {
+ // NOTE(bill): Must be an enum declaration
+ if (te->kind == Ast_EnumType) {
+ Scope *parent = ctx->scope->parent;
+ if (parent->flags&ScopeFlag_File) {
+ // NOTE(bill): Use package scope
+ parent = parent->parent;
+ }
+
+ Type *t = base_type(e->type);
+ GB_ASSERT(t->kind == Type_Enum);
+
+ for_array(i, t->Enum.fields) {
+ Entity *f = t->Enum.fields[i];
+ if (f->kind != Entity_Constant) {
+ continue;
+ }
+ String name = f->token.string;
+ if (is_blank_ident(name)) {
+ continue;
+ }
+ add_entity(ctx->checker, parent, nullptr, f);
+ }
+ }
+ }
}
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 4f44e0c4d..77b370619 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -600,29 +600,7 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
GB_ASSERT(fields.count <= et->fields.count);
- enum_type->Enum.fields = fields;
- enum_type->Enum.is_using = et->is_using;
- // TODO(bill): Should this be done elsewhere? e.g. delayed
- if (et->is_using) {
- Scope *parent = ctx->scope->parent;
- if (parent->flags&ScopeFlag_File) {
- // NOTE(bill): Use package scope
- parent = parent->parent;
- }
- for_array(i, fields) {
- Entity *f = fields[i];
- if (f->kind != Entity_Constant) {
- continue;
- }
- String name = f->token.string;
- if (is_blank_ident(name)) {
- continue;
- }
- add_entity(ctx->checker, parent, nullptr, f);
- }
- }
-
- Scope *s = ctx->scope;
+ enum_type->Enum.fields = fields;
enum_type->Enum.names = make_names_field_for_struct(ctx, ctx->scope);
}
diff --git a/src/checker.cpp b/src/checker.cpp
index 9f59788b8..6bd10fb3b 100644
--- a/src/checker.cpp
+++ b/src/checker.cpp
@@ -2123,7 +2123,7 @@ void check_collect_value_decl(CheckerContext *c, Ast *decl) {
if (vd->is_using) {
if (e->kind == Entity_TypeName && init->kind == Ast_EnumType) {
- init->EnumType.is_using = true;
+ d->is_using = true;
} else {
error(name, "'using' is not allowed on this constant value declaration");
}
diff --git a/src/checker.hpp b/src/checker.hpp
index a257e7809..310a99542 100644
--- a/src/checker.hpp
+++ b/src/checker.hpp
@@ -187,10 +187,10 @@ struct DeclInfo {
Ast * type_expr;
Ast * init_expr;
- // Array<Ast *> init_expr_list;
Array<Ast *> attributes;
Ast * proc_lit; // Ast_ProcLit
Type * gen_proc_type; // Precalculated
+ bool is_using;
PtrSet<Entity *> deps;
PtrSet<Type *> type_info_deps;
diff --git a/src/ir.cpp b/src/ir.cpp
index 3a7691326..036727326 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -8163,9 +8163,6 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
irValue *base = ir_type_info(proc, t->Enum.base_type);
ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 0), base);
- // is_using
- ir_emit_store(proc, ir_emit_struct_ep(proc, tag, 3), ir_const_bool(t->Enum.is_using));
-
if (t->Enum.fields.count > 0) {
auto fields = t->Enum.fields;
irValue *name_array = ir_generate_array(m, t_string, fields.count,
diff --git a/src/parser.hpp b/src/parser.hpp
index 30ce225e5..d542a8b7a 100644
--- a/src/parser.hpp
+++ b/src/parser.hpp
@@ -435,9 +435,9 @@ AST_KIND(_TypeBegin, "", bool) \
Ast *type; \
}) \
AST_KIND(PolyType, "polymorphic type", struct { \
- Token token; \
- Ast *type; \
- Ast *specialization; \
+ Token token; \
+ Ast * type; \
+ Ast * specialization; \
}) \
AST_KIND(ProcType, "procedure type", struct { \
Token token; \
diff --git a/src/types.cpp b/src/types.cpp
index e0ab91e90..240224059 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -135,7 +135,6 @@ struct TypeStruct {
Scope * scope; \
Entity * names; \
Type * base_type; \
- bool is_using; \
}) \
TYPE_KIND(Union, struct { \
Array<Type *> variants; \