Skip to content

Commit

Permalink
Fix: sure operator broken
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 1, 2017
1 parent fd6a1b3 commit 1af1d4d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/codegen/expr.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#include <limits.h>

#include "phase.h"
Expand Down Expand Up @@ -1933,7 +1932,9 @@ void visit_sure( struct codegen* codegen, struct result* result,
if ( ! sure->already_safe ) {
write_null_check( codegen );
}
result->ref = operand.ref;
result->ref = sure->ref;
result->dim = operand.dim;
result->diminfo_start = operand.diminfo_start;
result->structure = operand.structure;
result->storage = operand.storage;
result->index = operand.index;
Expand Down
1 change: 1 addition & 0 deletions src/parse/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ void read_sure( struct parse* parse, struct expr_reading* reading ) {
sure->node.type = NODE_SURE;
sure->pos = parse->tk_pos;
sure->operand = reading->node;
sure->ref = NULL;
sure->already_safe = false;
reading->node = &sure->node;
p_read_tk( parse );
Expand Down
28 changes: 6 additions & 22 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2105,36 +2105,20 @@ void test_sure( struct semantic* semantic, struct expr_test* test,
semantic->lib->uses_nullable_refs = true;
}
else {
//if ( type.ref->nullable ) {
size_t size = 0;
switch ( type.ref->type ) {
case REF_STRUCTURE:
size = sizeof( struct ref_struct );
break;
case REF_ARRAY:
size = sizeof( struct ref_array );
break;
case REF_FUNCTION:
size = sizeof( struct ref_func );
break;
default:
UNREACHABLE();
}
result->ref = &test->temp_ref.ref;
memcpy( result->ref, type.ref, size );
//}
//else {
// result->ref = type.ref;
if ( type.ref->nullable ) {
result->ref->nullable = false;
sure->ref = s_dup_ref( type.ref );
if ( sure->ref->nullable ) {
sure->ref->nullable = false;
semantic->lib->uses_nullable_refs = true;
}
else {
sure->already_safe = true;
}
result->ref = sure->ref;
result->structure = type.structure;
result->enumeration = type.enumeration;
result->spec = type.spec;
result->data_origin = operand.data_origin;
result->storage = operand.storage;
result->complete = true;
result->usable = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,6 @@ struct object* s_get_ns_object( struct ns* ns, const char* object_name,
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 );

#endif
5 changes: 2 additions & 3 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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 );
static struct ref* dup_ref( struct ref* ref );

void s_init_type_info( struct type_info* type, struct ref* ref,
struct structure* structure, struct enumeration* enumeration,
Expand Down Expand Up @@ -489,7 +488,7 @@ void subscript_array_type( struct semantic* semantic, struct type_info* type,
void s_take_type_snapshot( struct type_info* type,
struct type_snapshot* snapshot ) {
if ( type->implicit_ref ) {
snapshot->ref = dup_ref( type->ref );
snapshot->ref = s_dup_ref( type->ref );
}
else {
snapshot->ref = type->ref;
Expand All @@ -500,7 +499,7 @@ void s_take_type_snapshot( struct type_info* type,
snapshot->spec = type->spec;
}

struct ref* dup_ref( struct ref* ref ) {
struct ref* s_dup_ref( struct ref* ref ) {
size_t size = 0;
switch ( ref->type ) {
case REF_ARRAY: size = sizeof( struct ref_array ); break;
Expand Down
1 change: 1 addition & 0 deletions src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ struct sure {
struct node node;
struct pos pos;
struct node* operand;
struct ref* ref;
bool already_safe;
};

Expand Down

0 comments on commit 1af1d4d

Please sign in to comment.