aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-02-05 13:01:15 +0000
committergingerBill <bill@gingerbill.org>2022-02-05 13:01:15 +0000
commit97be86710306702a672309b23fbe8d38f1e6eeec (patch)
treeb8794b78149da6ec960250a1597073c6f7ec250f /src
parent1553137c2365c3980488a6455fd83f0fcb9e28ca (diff)
Rename `#partial[Enum]Type` to `#sparse[Enum]Type` for non-contiguous enum fields
Diffstat (limited to 'src')
-rw-r--r--src/check_type.cpp13
-rw-r--r--src/llvm_backend_type.cpp4
-rw-r--r--src/parser.cpp2
-rw-r--r--src/types.cpp4
4 files changed, 15 insertions, 8 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index a6d82c86e..6d3e32466 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -2713,29 +2713,30 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
Type *t = alloc_type_enumerated_array(elem, index, bt->Enum.min_value, bt->Enum.max_value, Token_Invalid);
- bool is_partial = false;
+ bool is_sparse = false;
if (at->tag != nullptr) {
GB_ASSERT(at->tag->kind == Ast_BasicDirective);
String name = at->tag->BasicDirective.name.string;
- if (name == "partial") {
- is_partial = true;
+ if (name == "sparse") {
+ is_sparse = true;
} else {
error(at->tag, "Invalid tag applied to an enumerated array, got #%.*s", LIT(name));
}
}
- if (!is_partial && t->EnumeratedArray.count > bt->Enum.fields.count) {
+ if (!is_sparse && t->EnumeratedArray.count > bt->Enum.fields.count) {
error(e, "Non-contiguous enumeration used as an index in an enumerated array");
long long ea_count = cast(long long)t->EnumeratedArray.count;
long long enum_count = cast(long long)bt->Enum.fields.count;
error_line("\tenumerated array length: %lld\n", ea_count);
error_line("\tenum field count: %lld\n", enum_count);
- error_line("\tSuggestion: prepend #partial to the enumerated array to allow for non-named elements\n");
+ error_line("\tSuggestion: prepend #sparse to the enumerated array to allow for non-contiguous elements\n");
if (2*enum_count < ea_count) {
error_line("\tWarning: the number of named elements is much smaller than the length of the array, are you sure this is what you want?\n");
- error_line("\t this warning will be removed if #partial is applied\n");
+ error_line("\t this warning will be removed if #sparse is applied\n");
}
}
+ t->EnumeratedArray.is_sparse = is_sparse;
*type = t;
diff --git a/src/llvm_backend_type.cpp b/src/llvm_backend_type.cpp
index e1332c6f3..1d6297164 100644
--- a/src/llvm_backend_type.cpp
+++ b/src/llvm_backend_type.cpp
@@ -454,7 +454,7 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
case Type_EnumeratedArray: {
tag = lb_const_ptr_cast(m, variant_ptr, t_type_info_enumerated_array_ptr);
- LLVMValueRef vals[6] = {
+ LLVMValueRef vals[7] = {
lb_get_type_info_ptr(m, t->EnumeratedArray.elem).value,
lb_get_type_info_ptr(m, t->EnumeratedArray.index).value,
lb_const_int(m, t_int, type_size_of(t->EnumeratedArray.elem)).value,
@@ -463,6 +463,8 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
// Unions
LLVMConstNull(lb_type(m, t_type_info_enum_value)),
LLVMConstNull(lb_type(m, t_type_info_enum_value)),
+
+ lb_const_bool(m, t_bool, t->EnumeratedArray.is_sparse).value,
};
lbValue res = {};
diff --git a/src/parser.cpp b/src/parser.cpp
index 6db71bc4a..7302b18a9 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -2134,7 +2134,7 @@ Ast *parse_operand(AstFile *f, bool lhs) {
break;
}
return original_type;
- } else if (name.string == "partial") {
+ } else if (name.string == "sparse") {
Ast *tag = ast_basic_directive(f, token, name);
Ast *original_type = parse_type(f);
Ast *type = unparen_expr(original_type);
diff --git a/src/types.cpp b/src/types.cpp
index 07951196a..e0d35a12c 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -221,6 +221,7 @@ struct TypeProc {
ExactValue *max_value; \
i64 count; \
TokenKind op; \
+ bool is_sparse; \
}) \
TYPE_KIND(Slice, struct { Type *elem; }) \
TYPE_KIND(DynamicArray, struct { Type *elem; }) \
@@ -3830,6 +3831,9 @@ gbString write_type_to_string(gbString str, Type *type) {
break;
case Type_EnumeratedArray:
+ if (type->EnumeratedArray.is_sparse) {
+ str = gb_string_appendc(str, "#sparse");
+ }
str = gb_string_append_rune(str, '[');
str = write_type_to_string(str, type->EnumeratedArray.index);
str = gb_string_append_rune(str, ']');