Mercurial > hg > octave-nkf
changeset 8471:02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 12 Jan 2009 19:03:33 -0500 |
parents | 5da39b223f61 |
children | 5451f7460ea6 |
files | src/ChangeLog src/parse.y src/pt-stmt.h |
diffstat | 3 files changed, 36 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2009-01-12 John W. Eaton <jwe@octave.org> + * pt-stmt.h (tree_statement::is_null_statement): New function. + * parse.y (set_stmt_print_flag): Return list. Remove trailing + null statements from list. + (list, simple_list): Simplify action. + (make_statement, make_statement_list, append_statement_list): + Always create statements and them to the list. + * base-list.h (octave_base_list::push_front, octave_base_list::push_back, octave_base_list::pop_front, octave_base_list::pop_back): New functions.
--- a/src/parse.y +++ b/src/parse.y @@ -311,7 +311,7 @@ maybe_warn_missing_semi (tree_statement_list *); // Set the print flag for a statement based on the separator type. -static void +static tree_statement_list * set_stmt_print_flag (tree_statement_list *, char, bool); // Create a statement list. @@ -327,16 +327,9 @@ static tree_statement * make_statement (T *arg) { - tree_statement *retval = 0; - - if (arg) - { - octave_comment_list *comment = octave_comment_buffer::get_comment (); - - retval = new tree_statement (arg, comment); - } - - return retval; + octave_comment_list *comment = octave_comment_buffer::get_comment (); + + return new tree_statement (arg, comment); } #define ABORT_PARSE \ @@ -521,10 +514,7 @@ ; simple_list : simple_list1 opt_sep_no_nl - { - set_stmt_print_flag ($1, $2, false); - $$ = $1; - } + { $$ = set_stmt_print_flag ($1, $2, false); } ; simple_list1 : statement @@ -540,10 +530,7 @@ ; list : list1 opt_sep - { - set_stmt_print_flag ($1, $2, true); - $$ = $1; - } + { $$ = set_stmt_print_flag ($1, $2, true); } ; list1 : statement @@ -2834,17 +2821,16 @@ } } -static void +static tree_statement_list * set_stmt_print_flag (tree_statement_list *list, char sep, bool warn_missing_semi) { + tree_statement *tmp = list->back (); + switch (sep) { case ';': - { - tree_statement *tmp = list->back (); - tmp->set_print_flag (0); - } + tmp->set_print_flag (0); break; case 0: @@ -2858,28 +2844,34 @@ warning ("unrecognized separator type!"); break; } + + // Even if a statement is null, we add it to the list then remove it + // here so that the print flag is applied to the correct statement. + + if (tmp->is_null_statement ()) + { + list->pop_back (); + delete tmp; + } + + return list; } static tree_statement_list * make_statement_list (tree_statement *stmt) { - return stmt ? new tree_statement_list (stmt) : new tree_statement_list (); + return new tree_statement_list (stmt); } static tree_statement_list * append_statement_list (tree_statement_list *list, char sep, tree_statement *stmt, bool warn_missing_semi) { - tree_statement_list *retval = list; - - if (stmt) - { - set_stmt_print_flag (list, sep, warn_missing_semi); - - list->append (stmt); - } - - return retval; + set_stmt_print_flag (list, sep, warn_missing_semi); + + list->append (stmt); + + return list; } static void
--- a/src/pt-stmt.h +++ b/src/pt-stmt.h @@ -78,6 +78,8 @@ octave_comment_list *comment_text (void) { return comm; } + bool is_null_statement (void) const { return ! (cmd || expr || comm); } + // Allow modification of this statement. Note that there is no // checking. If you use these, are you sure you knwo what you are // doing?