Skip to content

Commit

Permalink
Refactor: remove is_onedim_intelem_array_ref from expression testing
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 1, 2017
1 parent a5d4eb4 commit f8dea4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ static void test_strcpy( struct semantic* semantic, struct expr_test* test,
struct result* result, struct strcpy_call* call );
static void test_memcpy( struct semantic* semantic, struct expr_test* test,
struct result* result, struct memcpy_call* call );
static bool is_onedim_intelem_array_ref( struct semantic* semantic,
struct result* result );
static bool is_int_value( struct semantic* semantic, struct result* result );
static bool is_str_value( struct semantic* semantic, struct result* result );
static void test_conversion( struct semantic* semantic, struct expr_test* test,
Expand Down Expand Up @@ -2600,7 +2598,9 @@ void test_strcpy( struct semantic* semantic, struct expr_test* test,
struct result arg;
init_result( &arg );
test_root( semantic, test, &arg, call->array );
if ( ! is_onedim_intelem_array_ref( semantic, &arg ) ) {
struct type_info type;
init_type_info( semantic, &type, &arg );
if ( ! s_is_onedim_int_array_ref( semantic, &type ) ) {
s_diag( semantic, DIAG_POS_ERR, &call->array->pos,
"array argument not a one-dimensional, "
"integer element-type array-reference" );
Expand Down Expand Up @@ -2727,14 +2727,6 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
}
}

bool is_onedim_intelem_array_ref( struct semantic* semantic,
struct result* result ) {
bool onedim_array = ( result->dim && ! result->dim->next ) ||
( result->ref_dim == 1 );
bool int_elem = ( result->spec == SPEC_INT );
return ( onedim_array && int_elem );
}

bool is_int_value( struct semantic* semantic, struct result* result ) {
return ( is_value_type( semantic, result ) &&
result->spec == s_spec( semantic, SPEC_INT ) );
Expand Down
2 changes: 2 additions & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,7 @@ bool s_in_msgbuild_block( struct semantic* semantic );
struct ref* s_dup_ref( struct ref* ref );
bool s_is_array_ref( struct type_info* type );
bool s_is_struct( struct type_info* type );
bool s_is_onedim_int_array_ref( struct semantic* semantic,
struct type_info* type );

#endif
9 changes: 9 additions & 0 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@ bool s_is_onedim_int_array( struct type_info* type ) {
! type->ref && ( type->spec == SPEC_INT || type->spec == SPEC_RAW ) );
}

bool s_is_onedim_int_array_ref( struct semantic* semantic,
struct type_info* type ) {
bool one_dim_array = ( ( type->dim && ! type->dim->next ) ||
( type->ref && type->ref->type == REF_ARRAY &&
( ( struct ref_array* ) type->ref )->dim_count == 1 ) );
bool integer_elements = ( type->spec == SPEC_INT );
return ( one_dim_array && integer_elements );
}

bool s_is_int_value( struct type_info* type ) {
struct type_info required_type;
s_init_type_info_scalar( &required_type, SPEC_INT );
Expand Down

0 comments on commit f8dea4c

Please sign in to comment.