| author | |
| committer | |
| log | 3886fdc19b624e6fa47dcd02b627548bc7a7ada0 |
| tree | b73b5f700b5514e78c48d755086fe21dc12099aa |
| parent | 8583fd7f9f96887fe685354662b1fc076ebeb031 |
4 files changed, 23 insertions(+), 23 deletions(-)
src/all_types.hpp+1-1| ... | ... | @@ -870,7 +870,7 @@ struct TypeTableEntryStruct { |
| 870 | 870 | TypeStructField *fields; |
| 871 | 871 | uint64_t size_bytes; |
| 872 | 872 | bool is_invalid; // true if any fields are invalid |
| 873 | bool is_unknown_size_array; | |
| 873 | bool is_slice; | |
| 874 | 874 | BlockContext *block_context; |
| 875 | 875 | |
| 876 | 876 | // set this flag temporarily to detect infinite loops |
src/analyze.cpp+12-12| ... | ... | @@ -454,7 +454,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *child_type, |
| 454 | 454 | |
| 455 | 455 | unsigned element_count = 2; |
| 456 | 456 | entry->data.structure.is_packed = false; |
| 457 | entry->data.structure.is_unknown_size_array = true; | |
| 457 | entry->data.structure.is_slice = true; | |
| 458 | 458 | entry->data.structure.src_field_count = element_count; |
| 459 | 459 | entry->data.structure.gen_field_count = element_count; |
| 460 | 460 | entry->data.structure.fields = allocate<TypeStructField>(element_count); |
| ... | ... | @@ -1762,8 +1762,8 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable |
| 1762 | 1762 | // unknown size array const |
| 1763 | 1763 | if (expected_type->id == TypeTableEntryIdStruct && |
| 1764 | 1764 | actual_type->id == TypeTableEntryIdStruct && |
| 1765 | expected_type->data.structure.is_unknown_size_array && | |
| 1766 | actual_type->data.structure.is_unknown_size_array && | |
| 1765 | expected_type->data.structure.is_slice && | |
| 1766 | actual_type->data.structure.is_slice && | |
| 1767 | 1767 | (!actual_type->data.structure.fields[0].type_entry->data.pointer.is_const || |
| 1768 | 1768 | expected_type->data.structure.fields[0].type_entry->data.pointer.is_const)) |
| 1769 | 1769 | { |
| ... | ... | @@ -1966,9 +1966,9 @@ static bool types_match_with_implicit_cast(CodeGen *g, TypeTableEntry *expected_ |
| 1966 | 1966 | return true; |
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | // implicit constant sized array to unknown size array conversion | |
| 1969 | // implicit array to slice conversion | |
| 1970 | 1970 | if (expected_type->id == TypeTableEntryIdStruct && |
| 1971 | expected_type->data.structure.is_unknown_size_array && | |
| 1971 | expected_type->data.structure.is_slice && | |
| 1972 | 1972 | actual_type->id == TypeTableEntryIdArray && |
| 1973 | 1973 | types_match_const_cast_only( |
| 1974 | 1974 | expected_type->data.structure.fields[0].type_entry->data.pointer.child_type, |
| ... | ... | @@ -2273,7 +2273,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry |
| 2273 | 2273 | if (container_type->id == TypeTableEntryIdInvalid) { |
| 2274 | 2274 | return container_type; |
| 2275 | 2275 | } else if (container_type->id == TypeTableEntryIdStruct && |
| 2276 | !container_type->data.structure.is_unknown_size_array && | |
| 2276 | !container_type->data.structure.is_slice && | |
| 2277 | 2277 | (kind == ContainerInitKindStruct || (kind == ContainerInitKindArray && |
| 2278 | 2278 | container_init_expr->entries.length == 0))) |
| 2279 | 2279 | { |
| ... | ... | @@ -2352,7 +2352,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry |
| 2352 | 2352 | } |
| 2353 | 2353 | return container_type; |
| 2354 | 2354 | } else if (container_type->id == TypeTableEntryIdStruct && |
| 2355 | container_type->data.structure.is_unknown_size_array && | |
| 2355 | container_type->data.structure.is_slice && | |
| 2356 | 2356 | kind == ContainerInitKindArray) |
| 2357 | 2357 | { |
| 2358 | 2358 | int elem_count = container_init_expr->entries.length; |
| ... | ... | @@ -2573,7 +2573,7 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import, |
| 2573 | 2573 | return_type = get_slice_type(g, array_type->data.pointer.child_type, |
| 2574 | 2574 | node->data.slice_expr.is_const); |
| 2575 | 2575 | } else if (array_type->id == TypeTableEntryIdStruct && |
| 2576 | array_type->data.structure.is_unknown_size_array) | |
| 2576 | array_type->data.structure.is_slice) | |
| 2577 | 2577 | { |
| 2578 | 2578 | return_type = get_slice_type(g, |
| 2579 | 2579 | array_type->data.structure.fields[0].type_entry->data.pointer.child_type, |
| ... | ... | @@ -2623,7 +2623,7 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i |
| 2623 | 2623 | } else if (array_type->id == TypeTableEntryIdPointer) { |
| 2624 | 2624 | return_type = array_type->data.pointer.child_type; |
| 2625 | 2625 | } else if (array_type->id == TypeTableEntryIdStruct && |
| 2626 | array_type->data.structure.is_unknown_size_array) | |
| 2626 | array_type->data.structure.is_slice) | |
| 2627 | 2627 | { |
| 2628 | 2628 | return_type = array_type->data.structure.fields[0].type_entry->data.pointer.child_type; |
| 2629 | 2629 | } else { |
| ... | ... | @@ -3643,7 +3643,7 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl |
| 3643 | 3643 | } else if (array_type->id == TypeTableEntryIdArray) { |
| 3644 | 3644 | child_type = array_type->data.array.child_type; |
| 3645 | 3645 | } else if (array_type->id == TypeTableEntryIdStruct && |
| 3646 | array_type->data.structure.is_unknown_size_array) | |
| 3646 | array_type->data.structure.is_slice) | |
| 3647 | 3647 | { |
| 3648 | 3648 | TypeTableEntry *pointer_type = array_type->data.structure.fields[0].type_entry; |
| 3649 | 3649 | assert(pointer_type->id == TypeTableEntryIdPointer); |
| ... | ... | @@ -3979,9 +3979,9 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B |
| 3979 | 3979 | return resolve_cast(g, context, node, expr_node, wanted_type, CastOpFloatToInt, false); |
| 3980 | 3980 | } |
| 3981 | 3981 | |
| 3982 | // explicit cast from fixed size array to unknown size array | |
| 3982 | // explicit cast from array to slice | |
| 3983 | 3983 | if (wanted_type->id == TypeTableEntryIdStruct && |
| 3984 | wanted_type->data.structure.is_unknown_size_array && | |
| 3984 | wanted_type->data.structure.is_slice && | |
| 3985 | 3985 | actual_type->id == TypeTableEntryIdArray && |
| 3986 | 3986 | types_match_const_cast_only( |
| 3987 | 3987 | wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type, |
src/codegen.cpp+7-7| ... | ... | @@ -708,7 +708,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) { |
| 708 | 708 | { |
| 709 | 709 | assert(cast_expr->tmp_ptr); |
| 710 | 710 | assert(wanted_type->id == TypeTableEntryIdStruct); |
| 711 | assert(wanted_type->data.structure.is_unknown_size_array); | |
| 711 | assert(wanted_type->data.structure.is_slice); | |
| 712 | 712 | |
| 713 | 713 | TypeTableEntry *pointer_type = wanted_type->data.structure.fields[0].type_entry; |
| 714 | 714 | |
| ... | ... | @@ -883,7 +883,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal |
| 883 | 883 | add_debug_source_node(g, source_node); |
| 884 | 884 | return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); |
| 885 | 885 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 886 | assert(array_type->data.structure.is_unknown_size_array); | |
| 886 | assert(array_type->data.structure.is_slice); | |
| 887 | 887 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); |
| 888 | 888 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 889 | 889 | |
| ... | ... | @@ -998,7 +998,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) { |
| 998 | 998 | |
| 999 | 999 | return tmp_struct_ptr; |
| 1000 | 1000 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 1001 | assert(array_type->data.structure.is_unknown_size_array); | |
| 1001 | assert(array_type->data.structure.is_slice); | |
| 1002 | 1002 | assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); |
| 1003 | 1003 | assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); |
| 1004 | 1004 | |
| ... | ... | @@ -1046,7 +1046,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva |
| 1046 | 1046 | if (array_type->id == TypeTableEntryIdPointer) { |
| 1047 | 1047 | child_type = array_type->data.pointer.child_type; |
| 1048 | 1048 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 1049 | assert(array_type->data.structure.is_unknown_size_array); | |
| 1049 | assert(array_type->data.structure.is_slice); | |
| 1050 | 1050 | TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry; |
| 1051 | 1051 | assert(child_ptr_type->id == TypeTableEntryIdPointer); |
| 1052 | 1052 | child_type = child_ptr_type->data.pointer.child_type; |
| ... | ... | @@ -1134,7 +1134,7 @@ static LLVMValueRef gen_lvalue(CodeGen *g, AstNode *expr_node, AstNode *node, |
| 1134 | 1134 | *out_type_entry = array_type->data.pointer.child_type; |
| 1135 | 1135 | target_ref = gen_array_ptr(g, node); |
| 1136 | 1136 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 1137 | assert(array_type->data.structure.is_unknown_size_array); | |
| 1137 | assert(array_type->data.structure.is_slice); | |
| 1138 | 1138 | *out_type_entry = array_type->data.structure.fields[0].type_entry->data.pointer.child_type; |
| 1139 | 1139 | target_ref = gen_array_ptr(g, node); |
| 1140 | 1140 | } else { |
| ... | ... | @@ -2430,7 +2430,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) { |
| 2430 | 2430 | array_type->data.array.len, false); |
| 2431 | 2431 | child_type = array_type->data.array.child_type; |
| 2432 | 2432 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 2433 | assert(array_type->data.structure.is_unknown_size_array); | |
| 2433 | assert(array_type->data.structure.is_slice); | |
| 2434 | 2434 | TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry; |
| 2435 | 2435 | assert(child_ptr_type->id == TypeTableEntryIdPointer); |
| 2436 | 2436 | child_type = child_ptr_type->data.pointer.child_type; |
| ... | ... | @@ -2537,7 +2537,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa |
| 2537 | 2537 | if (var_decl->type) { |
| 2538 | 2538 | TypeTableEntry *var_type = get_type_for_type_node(var_decl->type); |
| 2539 | 2539 | if (var_type->id == TypeTableEntryIdStruct && |
| 2540 | var_type->data.structure.is_unknown_size_array) | |
| 2540 | var_type->data.structure.is_slice) | |
| 2541 | 2541 | { |
| 2542 | 2542 | assert(var_decl->type->type == NodeTypeArrayType); |
| 2543 | 2543 | AstNode *size_node = var_decl->type->data.array_type.size; |
src/eval.cpp+3-3| ... | ... | @@ -331,7 +331,7 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue * |
| 331 | 331 | out_val->ok = true; |
| 332 | 332 | |
| 333 | 333 | if (container_type->id == TypeTableEntryIdStruct && |
| 334 | !container_type->data.structure.is_unknown_size_array && | |
| 334 | !container_type->data.structure.is_slice && | |
| 335 | 335 | kind == ContainerInitKindStruct) |
| 336 | 336 | { |
| 337 | 337 | int expr_field_count = container_init_expr->entries.length; |
| ... | ... | @@ -367,7 +367,7 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue * |
| 367 | 367 | add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here")); |
| 368 | 368 | return true; |
| 369 | 369 | } else if (container_type->id == TypeTableEntryIdStruct && |
| 370 | container_type->data.structure.is_unknown_size_array && | |
| 370 | container_type->data.structure.is_slice && | |
| 371 | 371 | kind == ContainerInitKindArray) |
| 372 | 372 | { |
| 373 | 373 | |
| ... | ... | @@ -892,7 +892,7 @@ static bool eval_array_access_expr(EvalFn *ef, AstNode *node, ConstExprValue *ou |
| 892 | 892 | } |
| 893 | 893 | *out_val = *array_val.data.x_ptr.ptr[index_int]; |
| 894 | 894 | } else if (array_type->id == TypeTableEntryIdStruct) { |
| 895 | assert(array_type->data.structure.is_unknown_size_array); | |
| 895 | assert(array_type->data.structure.is_slice); | |
| 896 | 896 | |
| 897 | 897 | ConstExprValue *len_value = array_val.data.x_struct.fields[1]; |
| 898 | 898 | uint64_t len_int = len_value->data.x_bignum.data.x_uint; |