rename unknown_size_array to slice

master
Andrew Kelley 2016-04-24 16:33:41 -07:00
parent 8583fd7f9f
commit 3886fdc19b
4 changed files with 23 additions and 23 deletions

View File

@ -870,7 +870,7 @@ struct TypeTableEntryStruct {
TypeStructField *fields;
uint64_t size_bytes;
bool is_invalid; // true if any fields are invalid
bool is_unknown_size_array;
bool is_slice;
BlockContext *block_context;
// set this flag temporarily to detect infinite loops

View File

@ -454,7 +454,7 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *child_type,
unsigned element_count = 2;
entry->data.structure.is_packed = false;
entry->data.structure.is_unknown_size_array = true;
entry->data.structure.is_slice = true;
entry->data.structure.src_field_count = element_count;
entry->data.structure.gen_field_count = element_count;
entry->data.structure.fields = allocate<TypeStructField>(element_count);
@ -1762,8 +1762,8 @@ static bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTable
// unknown size array const
if (expected_type->id == TypeTableEntryIdStruct &&
actual_type->id == TypeTableEntryIdStruct &&
expected_type->data.structure.is_unknown_size_array &&
actual_type->data.structure.is_unknown_size_array &&
expected_type->data.structure.is_slice &&
actual_type->data.structure.is_slice &&
(!actual_type->data.structure.fields[0].type_entry->data.pointer.is_const ||
expected_type->data.structure.fields[0].type_entry->data.pointer.is_const))
{
@ -1966,9 +1966,9 @@ static bool types_match_with_implicit_cast(CodeGen *g, TypeTableEntry *expected_
return true;
}
// implicit constant sized array to unknown size array conversion
// implicit array to slice conversion
if (expected_type->id == TypeTableEntryIdStruct &&
expected_type->data.structure.is_unknown_size_array &&
expected_type->data.structure.is_slice &&
actual_type->id == TypeTableEntryIdArray &&
types_match_const_cast_only(
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
if (container_type->id == TypeTableEntryIdInvalid) {
return container_type;
} else if (container_type->id == TypeTableEntryIdStruct &&
!container_type->data.structure.is_unknown_size_array &&
!container_type->data.structure.is_slice &&
(kind == ContainerInitKindStruct || (kind == ContainerInitKindArray &&
container_init_expr->entries.length == 0)))
{
@ -2352,7 +2352,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
}
return container_type;
} else if (container_type->id == TypeTableEntryIdStruct &&
container_type->data.structure.is_unknown_size_array &&
container_type->data.structure.is_slice &&
kind == ContainerInitKindArray)
{
int elem_count = container_init_expr->entries.length;
@ -2573,7 +2573,7 @@ static TypeTableEntry *analyze_slice_expr(CodeGen *g, ImportTableEntry *import,
return_type = get_slice_type(g, array_type->data.pointer.child_type,
node->data.slice_expr.is_const);
} else if (array_type->id == TypeTableEntryIdStruct &&
array_type->data.structure.is_unknown_size_array)
array_type->data.structure.is_slice)
{
return_type = get_slice_type(g,
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
} else if (array_type->id == TypeTableEntryIdPointer) {
return_type = array_type->data.pointer.child_type;
} else if (array_type->id == TypeTableEntryIdStruct &&
array_type->data.structure.is_unknown_size_array)
array_type->data.structure.is_slice)
{
return_type = array_type->data.structure.fields[0].type_entry->data.pointer.child_type;
} else {
@ -3643,7 +3643,7 @@ static TypeTableEntry *analyze_for_expr(CodeGen *g, ImportTableEntry *import, Bl
} else if (array_type->id == TypeTableEntryIdArray) {
child_type = array_type->data.array.child_type;
} else if (array_type->id == TypeTableEntryIdStruct &&
array_type->data.structure.is_unknown_size_array)
array_type->data.structure.is_slice)
{
TypeTableEntry *pointer_type = array_type->data.structure.fields[0].type_entry;
assert(pointer_type->id == TypeTableEntryIdPointer);
@ -3979,9 +3979,9 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B
return resolve_cast(g, context, node, expr_node, wanted_type, CastOpFloatToInt, false);
}
// explicit cast from fixed size array to unknown size array
// explicit cast from array to slice
if (wanted_type->id == TypeTableEntryIdStruct &&
wanted_type->data.structure.is_unknown_size_array &&
wanted_type->data.structure.is_slice &&
actual_type->id == TypeTableEntryIdArray &&
types_match_const_cast_only(
wanted_type->data.structure.fields[0].type_entry->data.pointer.child_type,

View File

@ -708,7 +708,7 @@ static LLVMValueRef gen_cast_expr(CodeGen *g, AstNode *node) {
{
assert(cast_expr->tmp_ptr);
assert(wanted_type->id == TypeTableEntryIdStruct);
assert(wanted_type->data.structure.is_unknown_size_array);
assert(wanted_type->data.structure.is_slice);
TypeTableEntry *pointer_type = wanted_type->data.structure.fields[0].type_entry;
@ -883,7 +883,7 @@ static LLVMValueRef gen_array_elem_ptr(CodeGen *g, AstNode *source_node, LLVMVal
add_debug_source_node(g, source_node);
return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, "");
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
@ -998,7 +998,7 @@ static LLVMValueRef gen_slice_expr(CodeGen *g, AstNode *node) {
return tmp_struct_ptr;
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind);
@ -1046,7 +1046,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva
if (array_type->id == TypeTableEntryIdPointer) {
child_type = array_type->data.pointer.child_type;
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;
assert(child_ptr_type->id == TypeTableEntryIdPointer);
child_type = child_ptr_type->data.pointer.child_type;
@ -1134,7 +1134,7 @@ static LLVMValueRef gen_lvalue(CodeGen *g, AstNode *expr_node, AstNode *node,
*out_type_entry = array_type->data.pointer.child_type;
target_ref = gen_array_ptr(g, node);
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
*out_type_entry = array_type->data.structure.fields[0].type_entry->data.pointer.child_type;
target_ref = gen_array_ptr(g, node);
} else {
@ -2430,7 +2430,7 @@ static LLVMValueRef gen_for_expr(CodeGen *g, AstNode *node) {
array_type->data.array.len, false);
child_type = array_type->data.array.child_type;
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
TypeTableEntry *child_ptr_type = array_type->data.structure.fields[0].type_entry;
assert(child_ptr_type->id == TypeTableEntryIdPointer);
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
if (var_decl->type) {
TypeTableEntry *var_type = get_type_for_type_node(var_decl->type);
if (var_type->id == TypeTableEntryIdStruct &&
var_type->data.structure.is_unknown_size_array)
var_type->data.structure.is_slice)
{
assert(var_decl->type->type == NodeTypeArrayType);
AstNode *size_node = var_decl->type->data.array_type.size;

View File

@ -331,7 +331,7 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
out_val->ok = true;
if (container_type->id == TypeTableEntryIdStruct &&
!container_type->data.structure.is_unknown_size_array &&
!container_type->data.structure.is_slice &&
kind == ContainerInitKindStruct)
{
int expr_field_count = container_init_expr->entries.length;
@ -367,7 +367,7 @@ static bool eval_container_init_expr(EvalFn *ef, AstNode *node, ConstExprValue *
add_error_note(ef->root->codegen, msg, node, buf_sprintf("unreachable expression here"));
return true;
} else if (container_type->id == TypeTableEntryIdStruct &&
container_type->data.structure.is_unknown_size_array &&
container_type->data.structure.is_slice &&
kind == ContainerInitKindArray)
{
@ -892,7 +892,7 @@ static bool eval_array_access_expr(EvalFn *ef, AstNode *node, ConstExprValue *ou
}
*out_val = *array_val.data.x_ptr.ptr[index_int];
} else if (array_type->id == TypeTableEntryIdStruct) {
assert(array_type->data.structure.is_unknown_size_array);
assert(array_type->data.structure.is_slice);
ConstExprValue *len_value = array_val.data.x_struct.fields[1];
uint64_t len_int = len_value->data.x_bignum.data.x_uint;