Disallow using on an enum declaration.

This commit is contained in:
gingerBill
2021-08-05 17:46:42 +01:00
parent dd8fa1d690
commit 0d257c61cd
3 changed files with 21 additions and 20 deletions
+11 -3
View File
@@ -474,10 +474,12 @@ foreign kernel32 {
} }
using MEMORY_RESOURCE_NOTIFICATION_TYPE :: enum c_int { MEMORY_RESOURCE_NOTIFICATION_TYPE :: enum c_int {
LowMemoryResourceNotification, LowMemoryResourceNotification,
HighMemoryResourceNotification, HighMemoryResourceNotification,
} }
LowMemoryResourceNotification :: MEMORY_RESOURCE_NOTIFICATION_TYPE.LowMemoryResourceNotification;
HighMemoryResourceNotification :: MEMORY_RESOURCE_NOTIFICATION_TYPE.HighMemoryResourceNotification;
foreign kernel32 { foreign kernel32 {
@@ -598,12 +600,16 @@ foreign kernel32 {
) -> BOOL ---; ) -> BOOL ---;
} }
using OFFER_PRIORITY :: enum c_int { OFFER_PRIORITY :: enum c_int {
VmOfferPriorityVeryLow = 1, VmOfferPriorityVeryLow = 1,
VmOfferPriorityLow, VmOfferPriorityLow,
VmOfferPriorityBelowNormal, VmOfferPriorityBelowNormal,
VmOfferPriorityNormal, VmOfferPriorityNormal,
} }
VmOfferPriorityVeryLow :: OFFER_PRIORITY.VmOfferPriorityVeryLow;
VmOfferPriorityLow :: OFFER_PRIORITY.VmOfferPriorityLow;
VmOfferPriorityBelowNormal :: OFFER_PRIORITY.VmOfferPriorityBelowNormal;
VmOfferPriorityNormal :: OFFER_PRIORITY.VmOfferPriorityNormal;
foreign kernel32 { foreign kernel32 {
OfferVirtualMemory :: proc( OfferVirtualMemory :: proc(
@@ -638,9 +644,11 @@ foreign kernel32 {
) -> HANDLE ---; ) -> HANDLE ---;
} }
using WIN32_MEMORY_INFORMATION_CLASS :: enum c_int { WIN32_MEMORY_INFORMATION_CLASS :: enum c_int {
MemoryRegionInfo, MemoryRegionInfo,
} }
MemoryRegionInfo :: WIN32_MEMORY_INFORMATION_CLASS.MemoryRegionInfo;
WIN32_MEMORY_REGION_INFORMATION :: struct { WIN32_MEMORY_REGION_INFORMATION :: struct {
AllocationBase: PVOID, AllocationBase: PVOID,
AllocationProtect: ULONG, AllocationProtect: ULONG,
+7 -17
View File
@@ -778,16 +778,6 @@ using_statement :: proc() {
// Note: usingd fields can still be referred by name. // Note: usingd fields can still be referred by name.
} }
{ // using on an enum declaration
using Foo :: enum {A, B, C};
f0 := A;
f1 := B;
f2 := C;
fmt.println(f0, f1, f2);
fmt.println(len(Foo));
}
} }
@@ -1337,7 +1327,7 @@ bit_set_type :: proc() {
fmt.println("\n# bit_set type"); fmt.println("\n# bit_set type");
{ {
using Day :: enum { Day :: enum {
Sunday, Sunday,
Monday, Monday,
Tuesday, Tuesday,
@@ -1348,20 +1338,20 @@ bit_set_type :: proc() {
}; };
Days :: distinct bit_set[Day]; Days :: distinct bit_set[Day];
WEEKEND :: Days{Sunday, Saturday}; WEEKEND :: Days{.Sunday, .Saturday};
d: Days; d: Days;
d = {Sunday, Monday}; d = {.Sunday, .Monday};
e := d + WEEKEND; e := d + WEEKEND;
e += {Monday}; e += {.Monday};
fmt.println(d, e); fmt.println(d, e);
ok := Saturday in e; // `in` is only allowed for `map` and `bit_set` types ok := .Saturday in e; // `in` is only allowed for `map` and `bit_set` types
fmt.println(ok); fmt.println(ok);
if Saturday in e { if .Saturday in e {
fmt.println("Saturday in", e); fmt.println("Saturday in", e);
} }
X :: Saturday in WEEKEND; // Constant evaluation X :: .Saturday in WEEKEND; // Constant evaluation
fmt.println(X); fmt.println(X);
fmt.println("Cardinality:", card(e)); fmt.println("Cardinality:", card(e));
} }
+3
View File
@@ -294,6 +294,8 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def)
// using decl // using decl
if (decl->is_using) { if (decl->is_using) {
warning(init_expr, "'using' an enum declaration is not allowed, prefer using implicit selector expressions e.g. '.A'");
#if 0
// NOTE(bill): Must be an enum declaration // NOTE(bill): Must be an enum declaration
if (te->kind == Ast_EnumType) { if (te->kind == Ast_EnumType) {
Scope *parent = e->scope; Scope *parent = e->scope;
@@ -317,6 +319,7 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *init_expr, Type *def)
} }
} }
} }
#endif
} }
} }