Skip to content

Commit

Permalink
Refactor: variable size and initializer offset calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 6, 2017
1 parent be878ae commit c03ddf0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 51 deletions.
6 changes: 5 additions & 1 deletion src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,10 @@ static bool test_var_finish( struct semantic* semantic, struct var* var ) {
if ( var->storage == STORAGE_WORLD || var->storage == STORAGE_GLOBAL ) {
test_worldglobal_var( semantic, var );
}
s_calc_var_size( var );
if ( var->initial ) {
s_calc_var_value_index( var );
}
return true;
}

Expand Down Expand Up @@ -1813,6 +1817,7 @@ static void test_auto_var( struct semantic* semantic, struct var* var ) {
var->force_local_scope );
var->object.resolved = true;
describe_var( var );
s_calc_var_size( var );
}

static void assign_inferred_type( struct semantic* semantic, struct var* var,
Expand Down Expand Up @@ -1848,7 +1853,6 @@ static void assign_inferred_type( struct semantic* semantic, struct var* var,

void s_test_local_var( struct semantic* semantic, struct var* var ) {
s_test_var( semantic, var );
s_calc_var_size( var );
if ( var->initial ) {
s_calc_var_value_index( var );
}
Expand Down
5 changes: 1 addition & 4 deletions src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ static void test_subscript( struct semantic* semantic, struct expr_test* test,
else {
struct str string;
str_init( &string );
s_present_type( &lside.type, &string );
s_present_type( &lside.type, &string );
s_diag( semantic, DIAG_POS_ERR, &subscript->pos,
"subscript operation not supported for given operand (`%s`)",
string.value );
Expand Down Expand Up @@ -1591,9 +1591,6 @@ static void test_subscript_array( struct semantic* semantic,
result->folded = true;
}
result->dim = lside->dim->next;
}
else {

}
break;
case SUBSCRIPTRESULT_STRUCT:
Expand Down
46 changes: 0 additions & 46 deletions src/semantic/phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ static void check_dup_scripts( struct semantic* semantic );
static void match_dup_script( struct semantic* semantic, struct script* script,
struct script* prev_script, bool imported );
static void assign_script_numbers( struct semantic* semantic );
static void calc_map_var_size( struct semantic* semantic );
static void calc_map_value_index( struct semantic* semantic );
static void bind_private_name( struct name* name, struct object* object );
static void bind_func_name( struct semantic* semantic, struct name* name,
struct object* object );
Expand Down Expand Up @@ -196,8 +194,6 @@ static void test_acs( struct semantic* semantic ) {
test_module_acs( semantic, semantic->main_lib );
check_dup_scripts( semantic );
assign_script_numbers( semantic );
calc_map_var_size( semantic );
calc_map_value_index( semantic );
}

static void test_module_acs( struct semantic* semantic, struct library* lib ) {
Expand Down Expand Up @@ -278,8 +274,6 @@ static void test_bcs( struct semantic* semantic ) {
test_objects_bodies( semantic );
check_dup_scripts( semantic );
assign_script_numbers( semantic );
calc_map_var_size( semantic );
calc_map_value_index( semantic );
// TODO: Refactor this.
if ( ! semantic->main_lib->importable ) {
struct list_iter i;
Expand Down Expand Up @@ -1242,46 +1236,6 @@ static void assign_script_numbers( struct semantic* semantic ) {
}
}

static void calc_map_var_size( struct semantic* semantic ) {
// Imported variables.
struct list_iter i;
list_iterate( &semantic->main_lib->dynamic, &i );
while ( ! list_end( &i ) ) {
struct library* lib = list_data( &i );
struct list_iter k;
list_iterate( &lib->vars, &k );
while ( ! list_end( &k ) ) {
s_calc_var_size( list_data( &k ) );
list_next( &k );
}
list_next( &i );
}
// External variables.
list_iterate( &semantic->main_lib->external_vars, &i );
while ( ! list_end( &i ) ) {
s_calc_var_size( list_data( &i ) );
list_next( &i );
}
// Variables.
list_iterate( &semantic->main_lib->vars, &i );
while ( ! list_end( &i ) ) {
s_calc_var_size( list_data( &i ) );
list_next( &i );
}
}

static void calc_map_value_index( struct semantic* semantic ) {
struct list_iter i;
list_iterate( &semantic->main_lib->vars, &i );
while ( ! list_end( &i ) ) {
struct var* var = list_data( &i );
if ( var->initial ) {
s_calc_var_value_index( var );
}
list_next( &i );
}
}

void s_add_scope( struct semantic* semantic, bool func_scope ) {
struct scope* scope;
if ( semantic->free_scope ) {
Expand Down

0 comments on commit c03ddf0

Please sign in to comment.