Skip to content

Commit

Permalink
Refactor: remove is_struct 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 2d64600 commit a5d4eb4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ 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,
struct access* access, struct result* lside );
static bool is_struct( struct result* result );
static void unknown_member( struct semantic* semantic, struct access* access,
struct result* lside );
static void test_call( struct semantic* semantic, struct expr_test* test,
Expand Down Expand Up @@ -1527,7 +1526,7 @@ struct object* access_object( struct semantic* semantic, struct access* access,
struct result* lside ) {
struct type_info type;
init_type_info( semantic, &type, lside );
if ( is_struct( lside ) ) {
if ( s_is_struct( &type ) ) {
struct name* name = t_extend_name( lside->structure->body,
access->name );
if ( lside->ref && lside->ref->nullable ) {
Expand Down Expand Up @@ -1563,17 +1562,11 @@ struct object* access_object( struct semantic* semantic, struct access* access,
}
}

bool is_struct( struct result* result ) {
return ( ! result->dim && (
( result->ref && result->ref->type == REF_STRUCTURE ) ||
( ! result->ref && result->spec == SPEC_STRUCT ) ) );
}

void unknown_member( struct semantic* semantic, struct access* access,
struct result* lside ) {
struct type_info type;
init_type_info( semantic, &type, lside );
if ( is_struct( lside ) ) {
if ( s_is_struct( &type ) ) {
if ( lside->structure->anon ) {
s_diag( semantic, DIAG_POS_ERR, &access->pos,
"`%s` not a member of anonymous struct", access->name );
Expand Down Expand Up @@ -2665,7 +2658,7 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
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 ) ) ) {
if ( ! ( s_is_array_ref( &dst_type ) || s_is_struct( &dst_type ) ) ) {
s_diag( semantic, DIAG_POS_ERR, &call->destination->pos,
"destination not an array or structure" );
s_bail( semantic );
Expand Down Expand Up @@ -2729,7 +2722,7 @@ void test_memcpy( struct semantic* semantic, struct expr_test* test,
result->spec = s_spec( semantic, SPEC_BOOL );
result->complete = true;
result->usable = true;
if ( is_struct( &dst ) ) {
if ( s_is_struct( &dst_type ) ) {
call->type = MEMCPY_STRUCT;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,6 @@ 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 );
bool s_is_struct( struct type_info* type );

#endif
6 changes: 6 additions & 0 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,9 @@ bool s_is_enumerator( struct type_info* type ) {
bool s_is_null( struct type_info* type ) {
return ( s_is_ref_type( type ) && type->ref->type == REF_NULL );
}

bool s_is_struct( struct type_info* type ) {
return ( ! type->dim && (
( type->ref && type->ref->type == REF_STRUCTURE ) ||
( ! type->ref && type->spec == SPEC_STRUCT ) ) );
}

0 comments on commit a5d4eb4

Please sign in to comment.