Skip to content

Commit

Permalink
Refactor: remove is_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 1af1d4d commit 95f0a43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ static void warn_bounds_violation( struct semantic* semantic,
static void test_subscript_str( struct semantic* semantic,
struct expr_test* test, struct result* result, struct result* lside,
struct subscript* subscript );
static bool is_array_ref( struct result* result );
static void test_access( struct semantic* semantic, struct expr_test* test,
struct result* result, struct access* access );
static struct object* access_object( struct semantic* semantic,
Expand Down Expand Up @@ -1348,7 +1347,9 @@ void test_subscript( struct semantic* semantic, struct expr_test* test,
struct result lside;
init_result( &lside );
test_suffix( semantic, test, &lside, subscript->lside );
if ( is_array_ref( &lside ) ) {
struct type_info type;
init_type_info( semantic, &type, &lside );
if ( s_is_array_ref( &type ) ) {
test_subscript_array( semantic, test, result, &lside, subscript );
}
else if ( lside.spec == SPEC_STR ) {
Expand All @@ -1361,10 +1362,6 @@ void test_subscript( struct semantic* semantic, struct expr_test* test,
}
}

bool is_array_ref( struct result* result ) {
return ( result->dim || ( result->ref && result->ref->type == REF_ARRAY ) );
}

void test_subscript_array( struct semantic* semantic, struct expr_test* test,
struct result* result, struct result* lside, struct subscript* subscript ) {
struct result index;
Expand Down Expand Up @@ -2666,14 +2663,17 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
struct result dst;
init_result( &dst );
test_root( semantic, test, &dst, call->destination );
if ( ! ( is_array_ref( &dst ) || is_struct( &dst ) ) ) {
struct type_info dst_type;
init_type_info( semantic, &dst_type, &dst );
s_decay( semantic, &dst_type );
if ( ! ( s_is_array_ref( &dst_type ) || is_struct( &dst ) ) ) {
s_diag( semantic, DIAG_POS_ERR, &call->destination->pos,
"destination not an array or structure" );
s_bail( semantic );
}
// It doesn't look pretty if we allow struct variables to be specified with
// the array format-item, so make sure the argument is an array.
if ( call->array_cast && ! is_array_ref( &dst ) ) {
if ( call->array_cast && ! s_is_array_ref( &dst_type ) ) {
s_diag( semantic, DIAG_POS_ERR, &call->destination->pos,
"destination not an array" );
s_bail( semantic );
Expand Down Expand Up @@ -2703,11 +2703,8 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
struct result src;
init_result( &src );
test_root( semantic, test, &src, call->source );
struct type_info dst_type;
struct type_info src_type;
init_type_info( semantic, &dst_type, &dst );
init_type_info( semantic, &src_type, &src );
s_decay( semantic, &dst_type );
s_decay( semantic, &src_type );
if ( ! s_same_type( &src_type, &dst_type ) ) {
s_type_mismatch( semantic, "source", &src_type,
Expand All @@ -2724,7 +2721,7 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
"source-offset not an integer value" );
s_bail( semantic );
}
if ( ! is_array_ref( &dst ) ) {
if ( ! s_is_array_ref( &dst_type ) ) {
s_diag( semantic, DIAG_POS_ERR, &call->source_offset->pos,
"source-offset specified for non-array source" );
s_bail( semantic );
Expand Down
1 change: 1 addition & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,6 @@ bool s_is_enumerator( struct type_info* type );
bool s_is_null( struct type_info* type );
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 );

#endif
5 changes: 2 additions & 3 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ static void present_spec( int spec, struct str* string );
static void present_ref( struct ref* ref, struct str* string );
static void present_dim( struct type_info* type, struct str* string );
static void present_param_list( struct param* param, struct str* string );
static bool is_array_ref_type( struct type_info* type );
static void subscript_array_type( struct semantic* semantic,
struct type_info* type, struct type_info* element_type );

Expand Down Expand Up @@ -420,7 +419,7 @@ void s_iterate_type( struct semantic* semantic, struct type_info* type,
s_init_type_info_scalar( &iter->value, s_spec( semantic, SPEC_INT ) );
iter->available = true;
}
else if ( is_array_ref_type( type ) ) {
else if ( s_is_array_ref( type ) ) {
s_init_type_info_scalar( &iter->key, s_spec( semantic, SPEC_INT ) );
subscript_array_type( semantic, type, &iter->value );
iter->available = true;
Expand All @@ -434,7 +433,7 @@ bool s_is_str_value_type( struct type_info* type ) {
return ( s_is_value_type( type ) && type->spec == SPEC_STR );
}

inline bool is_array_ref_type( struct type_info* type ) {
bool s_is_array_ref( struct type_info* type ) {
return ( type->dim || ( type->ref && type->ref->type == REF_ARRAY ) );
}

Expand Down

0 comments on commit 95f0a43

Please sign in to comment.