Skip to content

Commit

Permalink
Refactor: handling of script number 0
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Nov 2, 2016
1 parent 3535d68 commit 4abbd10
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
13 changes: 6 additions & 7 deletions src/parse/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1885,17 +1885,16 @@ void read_script_number( struct parse* parse, struct script* script ) {
parse->tk == TK_SHIFT_L ) {
p_read_tk( parse );
// The token between the `<<` and `>>` tokens must be the digit `0`.
if ( parse->tk == TK_LIT_DECIMAL && parse->tk_text[ 0 ] == '0' &&
parse->tk_length == 1 ) {
p_read_tk( parse );
p_test_tk( parse, TK_SHIFT_R );
p_read_tk( parse );
}
else {
if ( ! ( parse->tk == TK_LIT_DECIMAL && parse->tk_text[ 0 ] == '0' &&
parse->tk_length == 1 ) ) {
p_unexpect_diag( parse );
p_unexpect_last_name( parse, NULL, "the digit `0`" );
p_bail( parse );
}
script->number = parse->task->raw0_expr;
p_read_tk( parse );
p_test_tk( parse, TK_SHIFT_R );
p_read_tk( parse );
}
else if ( parse->lang == LANG_ACS && parse->tk == TK_LIT_STRING ) {
struct indexed_string* string = t_intern_script_name( parse->task,
Expand Down
9 changes: 9 additions & 0 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ static void alloc_value_index_struct( struct value_index_alloc*,
struct multi_value*, struct structure* );
static void test_script_number( struct semantic* semantic,
struct script* script );
static void test_nonzero_script_number( struct semantic* semantic,
struct script* script );
static void test_script_param_list( struct semantic* semantic,
struct script* script );
static void test_script_body( struct semantic* semantic,
Expand Down Expand Up @@ -2276,6 +2278,13 @@ void s_test_script( struct semantic* semantic, struct script* script ) {
}

void test_script_number( struct semantic* semantic, struct script* script ) {
if ( script->number != semantic->task->raw0_expr ) {
test_nonzero_script_number( semantic, script );
}
}

void test_nonzero_script_number( struct semantic* semantic,
struct script* script ) {
struct expr_test expr;
s_init_expr_test( &expr, true, false );
s_test_expr( semantic, &expr, script->number );
Expand Down
7 changes: 3 additions & 4 deletions src/semantic/phase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,10 +1091,9 @@ void match_dup_script( struct semantic* semantic, struct script* script,
}
// Script numbers.
else if ( ! script->named_script && ! prev_script->named_script ) {
if ( t_get_script_number( script ) ==
t_get_script_number( prev_script ) ) {
if ( script->number->value == prev_script->number->value ) {
s_diag( semantic, DIAG_POS_ERR, &script->pos,
"duplicate script %d", t_get_script_number( script ) );
"duplicate script %d", script->number->value );
s_diag( semantic, DIAG_POS, &prev_script->pos,
"script already found here" );
s_bail( semantic );
Expand All @@ -1113,7 +1112,7 @@ void assign_script_numbers( struct semantic* semantic ) {
--named_script_number;
}
else {
script->assigned_number = t_get_script_number( script );
script->assigned_number = script->number->value;
}
list_next( &i );
}
Expand Down
10 changes: 1 addition & 9 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void t_init( struct task* task, struct options* options, jmp_buf* bail ) {
expr->root = &literal->node;
expr->folded = true;
task->dummy_expr = expr;
task->raw0_expr = expr;

str_init( &task->err_file_dir );
str_copy( &task->err_file_dir, "", 0 );
Expand Down Expand Up @@ -284,15 +285,6 @@ void t_init_type_members( struct task* task ) {
}
} */

int t_get_script_number( struct script* script ) {
if ( script->number ) {
return script->number->value;
}
else {
return 0;
}
}

void t_diag( struct task* task, int flags, ... ) {
va_list args;
va_start( args, flags );
Expand Down
3 changes: 2 additions & 1 deletion src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,9 @@ struct task {
struct name* array_name;
struct name* str_name;
struct func* append_func;
// Both `dummy_expr` and `raw0_expr` refer to the same node.
struct expr* dummy_expr;
struct expr* raw0_expr;
struct ns* upmost_ns;
struct str err_file_dir;
};
Expand All @@ -1175,7 +1177,6 @@ struct task {
void t_init( struct task*, struct options*, jmp_buf* );
void t_copy_name( struct name*, bool full, struct str* buffer );
int t_full_name_length( struct name* );
int t_get_script_number( struct script* );
void t_print_name( struct name* );
void t_diag( struct task*, int flags, ... );
void t_diag_args( struct task* task, int flags, va_list* args );
Expand Down

0 comments on commit 4abbd10

Please sign in to comment.