authorgravatar for info@bnoordhuis.nlBen Noordhuis <info@bnoordhuis.nl> 2018-02-07 20:38:49+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-07 14:38:49-05:00
log0090c2d70b89cc6b5ab02bdc02aa49c4caf71a5a
tree3ad1caa3ee17dc7ee71d19f343121f429b101f5d
parent917e6fe3707a82f76c48e484735b86937831451f

DRY 'is slice?' conditionals in parser (#750)


2 files changed, 3 insertions(+), 11 deletions(-)

src/analyze.cpp+1-5
...@@ -3380,11 +3380,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *...@@ -3380,11 +3380,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
3380 }3380 }
33813381
3382 // slice const3382 // slice const
3383 if (expected_type->id == TypeTableEntryIdStruct &&3383 if (is_slice(expected_type) && is_slice(actual_type)) {
3384 actual_type->id == TypeTableEntryIdStruct &&
3385 expected_type->data.structure.is_slice &&
3386 actual_type->data.structure.is_slice)
3387 {
3388 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;3384 TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry;
3389 TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;3385 TypeTableEntry *expected_ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
3390 if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) &&3386 if ((!actual_ptr_type->data.pointer.is_const || expected_ptr_type->data.pointer.is_const) &&
src/ir.cpp+2-6
...@@ -6369,10 +6369,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6369,10 +6369,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6369 }6369 }
63706370
6371 // implicit [N]T to []const T6371 // implicit [N]T to []const T
6372 if (expected_type->id == TypeTableEntryIdStruct &&6372 if (is_slice(expected_type) && actual_type->id == TypeTableEntryIdArray) {
6373 expected_type->data.structure.is_slice &&
6374 actual_type->id == TypeTableEntryIdArray)
6375 {
6376 TypeTableEntry *ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;6373 TypeTableEntry *ptr_type = expected_type->data.structure.fields[slice_ptr_index].type_entry;
6377 assert(ptr_type->id == TypeTableEntryIdPointer);6374 assert(ptr_type->id == TypeTableEntryIdPointer);
63786375
...@@ -6384,8 +6381,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,...@@ -6384,8 +6381,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
6384 }6381 }
63856382
6386 // implicit &const [N]T to []const T6383 // implicit &const [N]T to []const T
6387 if (expected_type->id == TypeTableEntryIdStruct &&6384 if (is_slice(expected_type) &&
6388 expected_type->data.structure.is_slice &&
6389 actual_type->id == TypeTableEntryIdPointer &&6385 actual_type->id == TypeTableEntryIdPointer &&
6390 actual_type->data.pointer.is_const &&6386 actual_type->data.pointer.is_const &&
6391 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)6387 actual_type->data.pointer.child_type->id == TypeTableEntryIdArray)