Skip to content

Commit

Permalink
Work on testing of increment operation
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 2, 2017
1 parent 96830cb commit 358594b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ static void test_inc( struct semantic* semantic, struct expr_test* test,
struct result* result, struct inc* inc );
static bool perform_inc( struct semantic* semantic, struct inc* inc,
struct result* operand, struct result* result );
static bool perform_primitive_inc( struct semantic* semantic, struct inc* inc,
struct result* operand, struct result* result );
static void test_cast( struct semantic* semantic, struct expr_test* test,
struct result* result, struct cast* cast );
static bool valid_cast( struct semantic* semantic, struct cast* cast,
Expand Down Expand Up @@ -1129,7 +1131,7 @@ void fold_logical_not( struct semantic* semantic, struct result* operand,
}
}

void test_inc( struct semantic* semantic, struct expr_test* test,
static void test_inc( struct semantic* semantic, struct expr_test* test,
struct result* result, struct inc* inc ) {
struct result operand;
init_result( &operand );
Expand Down Expand Up @@ -1160,27 +1162,31 @@ void test_inc( struct semantic* semantic, struct expr_test* test,
}
}

bool perform_inc( struct semantic* semantic, struct inc* inc,
static bool perform_inc( struct semantic* semantic, struct inc* inc,
struct result* operand, struct result* result ) {
if ( s_is_value_type( &operand->type ) ) {
switch ( operand->type.spec ) {
case SPEC_RAW:
case SPEC_INT:
case SPEC_FIXED:
break;
default:
return false;
}
s_init_type_info_scalar( &result->type, operand->type.spec );
result->complete = true;
result->usable = true;
inc->fixed = ( operand->type.spec == SPEC_FIXED );
return true;
switch ( s_describe_type( &operand->type ) ) {
case TYPEDESC_PRIMITIVE:
return perform_primitive_inc( semantic, inc, operand, result );
default:
return false;
}
// Reference type.
else {
}

static bool perform_primitive_inc( struct semantic* semantic, struct inc* inc,
struct result* operand, struct result* result ) {
switch ( operand->type.spec ) {
case SPEC_RAW:
case SPEC_INT:
case SPEC_FIXED:
break;
default:
return false;
}
s_init_type_info_scalar( &result->type, operand->type.spec );
result->complete = true;
result->usable = true;
inc->fixed = ( operand->type.spec == SPEC_FIXED );
return true;
}

void test_cast( struct semantic* semantic, struct expr_test* test,
Expand Down
13 changes: 13 additions & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ enum subscript_result {
SUBSCRIPTRESULT_PRIMITIVE
};

enum type_description {
TYPEDESC_NONE,
TYPEDESC_ARRAY,
TYPEDESC_ARRAYREF,
TYPEDESC_STRUCTREF,
TYPEDESC_FUNCREF,
TYPEDESC_NULLREF,
TYPEDESC_STRUCT,
TYPEDESC_ENUM,
TYPEDESC_PRIMITIVE
};

struct semantic {
struct task* task;
struct library* main_lib;
Expand Down Expand Up @@ -231,5 +243,6 @@ bool s_is_onedim_int_array_ref( struct semantic* semantic,
struct type_info* type );
enum subscript_result s_subscript_array_ref( struct semantic* semantic,
struct type_info* type, struct type_info* element_type );
enum type_description s_describe_type( struct type_info* type );

#endif
26 changes: 26 additions & 0 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,29 @@ bool s_is_struct( struct type_info* type ) {
( type->ref && type->ref->type == REF_STRUCTURE ) ||
( ! type->ref && type->spec == SPEC_STRUCT ) ) );
}

enum type_description s_describe_type( struct type_info* type ) {
if ( type->dim ) {
return TYPEDESC_ARRAY;
}
else if ( type->ref ) {
switch ( type->ref->type ) {
case REF_STRUCTURE: return TYPEDESC_STRUCTREF;
case REF_ARRAY: return TYPEDESC_ARRAYREF;
case REF_FUNCTION: return TYPEDESC_FUNCREF;
case REF_NULL: return TYPEDESC_NULLREF;
default:
UNREACHABLE();
return TYPEDESC_NONE;
}
}
else if ( type->structure ) {
return TYPEDESC_STRUCT;
}
else if ( type->enumeration ) {
return TYPEDESC_ENUM;
}
else {
return TYPEDESC_PRIMITIVE;
}
}

0 comments on commit 358594b

Please sign in to comment.