Skip to content

Commit

Permalink
Refactor: change script body to a block node
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Nov 2, 2016
1 parent 897bf93 commit 3535d68
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/codegen/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void write_script( struct codegen* codegen, struct script* script ) {
}
alloc_param_indexes( &record, script->params );
alloc_funcscopevars_indexes( &record, &script->funcscope_vars );
c_write_stmt( codegen, script->body );
c_write_block( codegen, script->body );
c_pcd( codegen, PCD_TERMINATE );
script->size = record.size;
codegen->func = NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/parse/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ void p_read_func_body( struct parse* parse, struct func* func ) {
// TODO: Remove `parse.local_vars` fields.
struct list* prev_local_vars = parse->local_vars;
parse->local_vars = &impl->vars;
p_read_top_stmt( parse, &body, true );
p_read_top_block( parse, &body, true );
impl->body = body.block_node;
parse->local_vars = prev_local_vars;
}
Expand Down Expand Up @@ -2190,8 +2190,8 @@ void read_script_body( struct parse* parse, struct script* script ) {
struct stmt_reading body;
p_init_stmt_reading( &body, &script->labels );
parse->local_vars = &script->vars;
p_read_top_stmt( parse, &body, false );
script->body = body.node;
p_read_top_block( parse, &body, false );
script->body = body.block_node;
parse->local_vars = NULL;
}

Expand Down
4 changes: 2 additions & 2 deletions src/parse/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ void p_read_stream( struct parse* parse );
void p_test_tk( struct parse* parse, enum tk type );
void p_test_preptk( struct parse* parse, enum tk type );
void p_test_stream( struct parse* parse, enum tk type );
void p_read_top_stmt( struct parse* parse, struct stmt_reading* reading,
bool need_block );
void p_read_top_block( struct parse* parse, struct stmt_reading* reading,
bool explicit_block );
void p_skip_block( struct parse* parse );
void p_init_expr_reading( struct expr_reading* reading, bool in_constant,
bool skip_assign, bool skip_func_call, bool expect_expr );
Expand Down
6 changes: 3 additions & 3 deletions src/parse/stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void p_init_stmt_reading( struct stmt_reading* reading, struct list* labels ) {
reading->block_node = NULL;
}

void p_read_top_stmt( struct parse* parse, struct stmt_reading* reading,
bool need_block ) {
if ( need_block ) {
void p_read_top_block( struct parse* parse, struct stmt_reading* reading,
bool explicit_block ) {
if ( explicit_block ) {
read_block( parse, reading );
}
else {
Expand Down
4 changes: 2 additions & 2 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ void s_test_func_body( struct semantic* semantic, struct func* func ) {
semantic->topfunc_test = &test;
}
semantic->func_test = &test;
s_test_body( semantic, &impl->body->node );
s_test_top_block( semantic, impl->body );
semantic->func_test = test.parent;
impl->returns = test.returns;
if ( ! impl->nested ) {
Expand Down Expand Up @@ -2357,7 +2357,7 @@ void test_script_body( struct semantic* semantic, struct script* script ) {
&script->funcscope_vars, script );
semantic->topfunc_test = &test;
semantic->func_test = semantic->topfunc_test;
s_test_body( semantic, script->body );
s_test_top_block( semantic, script->body );
script->nested_funcs = test.nested_funcs;
semantic->topfunc_test = NULL;
semantic->func_test = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void s_test_expr_type( struct semantic* semantic, struct expr_test* test,
struct type_info* result_type, struct expr* expr );
void s_test_bool_expr( struct semantic* semantic, struct expr* expr );
void s_init_stmt_test( struct stmt_test*, struct stmt_test* );
void s_test_body( struct semantic* semantic, struct node* node );
void s_test_top_block( struct semantic* semantic, struct block* block );
void s_add_scope( struct semantic* semantic, bool func_scope );
void s_pop_scope( struct semantic* semantic );
void s_test_script( struct semantic* semantic, struct script* script );
Expand Down
12 changes: 3 additions & 9 deletions src/semantic/stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,12 @@ void s_init_stmt_test( struct stmt_test* test, struct stmt_test* parent ) {
test->case_allowed = false;
}

void s_test_body( struct semantic* semantic, struct node* node ) {
void s_test_top_block( struct semantic* semantic, struct block* block ) {
struct stmt_test test;
s_init_stmt_test( &test, NULL );
test.manual_scope = true;
if ( node->type == NODE_BLOCK ) {
test_block( semantic, &test,
( struct block* ) node );
check_dup_label( semantic );
}
else {
test_stmt( semantic, &test, node );
}
test_block( semantic, &test, block );
check_dup_label( semantic );
}

void test_block( struct semantic* semantic, struct stmt_test* test,
Expand Down
2 changes: 1 addition & 1 deletion src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ struct script {
SCRIPT_FLAG_CLIENTSIDE = 0x2
} flags;
struct param* params;
struct node* body;
struct block* body;
struct func* nested_funcs;
struct call* nested_calls;
struct list labels;
Expand Down

0 comments on commit 3535d68

Please sign in to comment.