Skip to content

Commit

Permalink
Refactor: remove value.string_initz field
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 6, 2017
1 parent c03ddf0 commit 269edc0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/codegen/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,12 @@ static void write_aini( struct codegen* codegen, struct var* var ) {
while ( value ) {
// Nullify uninitialized space.
if ( count < value->index && ( ( value->expr->value &&
! value->string_initz ) || value->string_initz ) ) {
value->type != VALUE_STRINGINITZ ) ||
value->type == VALUE_STRINGINITZ ) ) {
c_add_int_zero( codegen, value->index - count );
count = value->index;
}
if ( value->string_initz ) {
if ( value->type == VALUE_STRINGINITZ ) {
struct indexed_string_usage* usage =
( struct indexed_string_usage* ) value->expr->root;
for ( int i = 0; i < usage->string->length; ++i ) {
Expand All @@ -589,7 +590,7 @@ static int count_nonzero_initz( struct var* var ) {
int count = 0;
struct value* value = var->value;
while ( value ) {
if ( value->string_initz ) {
if ( value->type == VALUE_STRINGINITZ ) {
struct indexed_string_usage* usage =
( struct indexed_string_usage* ) value->expr->root;
count = value->index + usage->string->length;
Expand Down Expand Up @@ -620,11 +621,12 @@ static void write_initz( struct codegen* codegen, struct initz_w* writing,
int index = writing->base + value->index;
// Nullify uninitialized space.
if ( writing->done < index && ( ( value->expr->value &&
! value->string_initz ) || value->string_initz ) ) {
value->type != VALUE_STRINGINITZ ) ||
value->type == VALUE_STRINGINITZ ) ) {
c_add_int_zero( codegen, index - writing->done );
writing->done = index;
}
if ( value->string_initz ) {
if ( value->type == VALUE_STRINGINITZ ) {
struct indexed_string_usage* usage =
( struct indexed_string_usage* ) value->expr->root;
for ( int i = 0; i < usage->string->length; ++i ) {
Expand Down
9 changes: 5 additions & 4 deletions src/codegen/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ static void visit_local_var( struct codegen* codegen, struct var* var ) {
write_multi_initz_acs( codegen, var );
}
else {
if ( ! var->initial->multi && var->value->string_initz ) {
if ( ! var->initial->multi &&
var->value->type == VALUE_STRINGINITZ ) {
write_string_initz( codegen, var, var->value, true );
}
else {
Expand Down Expand Up @@ -286,7 +287,7 @@ static void visit_world_var( struct codegen* codegen, struct var* var ) {
if ( var->initial->multi ) {
write_multi_initz( codegen, var );
}
else if ( var->value->string_initz ) {
else if ( var->value->type == VALUE_STRINGINITZ ) {
write_string_initz( codegen, var, var->value, true );
}
else {
Expand All @@ -308,7 +309,7 @@ static void write_multi_initz( struct codegen* codegen, struct var* var ) {
struct value* value = var->value;
while ( value ) {
int index = 0;
if ( value->string_initz ) {
if ( value->type == VALUE_STRINGINITZ ) {
struct indexed_string_usage* usage =
( struct indexed_string_usage* ) value->expr->root;
index = value->index + usage->string->length + 1;
Expand Down Expand Up @@ -338,7 +339,7 @@ static void write_multi_initz( struct codegen* codegen, struct var* var ) {
// -----------------------------------------------------------------------
value = var->value;
while ( value ) {
if ( value->string_initz ) {
if ( value->type == VALUE_STRINGINITZ ) {
// Don't include the NUL character if the element to contain the
// character has been nullified.
struct indexed_string_usage* usage =
Expand Down
1 change: 0 additions & 1 deletion src/parse/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,6 @@ static struct value* alloc_value( void ) {
value->next = NULL;
value->type = VALUE_OTHER;
value->index = 0;
value->string_initz = false;
return value;
}

Expand Down
5 changes: 2 additions & 3 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,6 @@ static bool test_string_initz( struct semantic* semantic, struct dim* dim,
dim->length = string->length + 1;
}
}
value->string_initz = true;
value->type = VALUE_STRINGINITZ;
return true;
}
Expand Down Expand Up @@ -2529,7 +2528,7 @@ static void alloc_value_index( struct value_index_alloc* alloc,
}
else {
alloc->value->index = alloc->index;
if ( alloc->value->string_initz ) {
if ( alloc->value->type == VALUE_STRINGINITZ ) {
alloc->index += dim->next->length;
}
else {
Expand Down Expand Up @@ -2568,7 +2567,7 @@ static void alloc_value_index_struct( struct value_index_alloc* alloc,
}
else {
alloc->value->index = alloc->index;
if ( alloc->value->string_initz ) {
if ( alloc->value->type == VALUE_STRINGINITZ ) {
alloc->index += member->dim->length;
}
else {
Expand Down
1 change: 0 additions & 1 deletion src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,6 @@ struct value {
VALUE_FUNC
} type;
int index;
bool string_initz;
};

struct multi_value {
Expand Down

0 comments on commit 269edc0

Please sign in to comment.