# HG changeset patch # User John W. Eaton # Date 1362870594 18000 # Node ID 90dfd98a915a1a73ad2c935387fcc4ab187b4f3e # Parent d8c0f46efaf09701dc7e8e4ef7461d99a9d3bb70# Parent 38bd5ae8463b254038e5a06cc6cd5db7bdbedf2e maint: periodic merge of default to classdef diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/module.mk --- a/libinterp/parse-tree/module.mk Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/module.mk Sat Mar 09 18:09:54 2013 -0500 @@ -21,6 +21,7 @@ PARSE_TREE_INC = \ parse-tree/pt-all.h \ parse-tree/pt-arg-list.h \ + parse-tree/pt-array-list.h \ parse-tree/pt-assign.h \ parse-tree/pt-binop.h \ parse-tree/pt-bp.h \ @@ -54,6 +55,7 @@ PARSE_TREE_SRC = \ parse-tree/pt-arg-list.cc \ + parse-tree/pt-array-list.cc \ parse-tree/pt-assign.cc \ parse-tree/pt-binop.cc \ parse-tree/pt-bp.cc \ diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/oct-parse.in.yy Sat Mar 09 18:09:54 2013 -0500 @@ -258,7 +258,8 @@ // Nonterminals we construct. %type stash_comment function_beg %type classdef_beg -%type sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep opt_comma +%type sep_no_nl opt_sep_no_nl nl opt_nl sep opt_sep +%type opt_comma opt_semi %type input %type string constant magic_colon %type anon_fcn_handle @@ -493,9 +494,7 @@ } ; -matrix_rows : matrix_rows1 - { $$ = $1; } - | matrix_rows1 ';' // Ignore trailing semicolon. +matrix_rows : matrix_rows1 opt_semi { $$ = $1; } ; @@ -516,9 +515,7 @@ { $$ = curr_parser.finish_cell ($2); } ; -cell_rows : cell_rows1 - { $$ = $1; } - | cell_rows1 ';' // Ignore trailing semicolon. +cell_rows : cell_rows1 opt_semi { $$ = $1; } ; @@ -532,9 +529,7 @@ ; cell_or_matrix_row - : arg_list - { $$ = curr_parser.validate_matrix_row ($1); } - | arg_list ',' // Ignore trailing comma. + : arg_list opt_comma { $$ = curr_parser.validate_matrix_row ($1); } ; @@ -1549,6 +1544,12 @@ { $$ = ','; } ; +opt_semi : // empty + { $$ = 0; } + | ';' + { $$ = ';'; } + ; + %% // Generic error messages. @@ -3220,12 +3221,12 @@ return row; } -// Finish building a matrix list. +// Finish building an array_list. tree_expression * -octave_parser::finish_matrix (tree_matrix *m) +octave_parser::finish_array_list (tree_array_list *array_list) { - tree_expression *retval = m; + tree_expression *retval = array_list; unwind_protect frame; @@ -3238,24 +3239,25 @@ discard_error_messages = true; discard_warning_messages = true; - if (m->all_elements_are_constant ()) + if (array_list->all_elements_are_constant ()) { - octave_value tmp = m->rvalue1 (); + octave_value tmp = array_list->rvalue1 (); if (! (error_state || warning_state)) { tree_constant *tc_retval - = new tree_constant (tmp, m->line (), m->column ()); + = new tree_constant (tmp, array_list->line (), + array_list->column ()); std::ostringstream buf; tree_print_code tpc (buf); - m->accept (tpc); + array_list->accept (tpc); tc_retval->stash_original_text (buf.str ()); - delete m; + delete array_list; retval = tc_retval; } @@ -3264,12 +3266,20 @@ return retval; } +// Finish building a matrix list. + +tree_expression * +octave_parser::finish_matrix (tree_matrix *m) +{ + return finish_array_list (m); +} + // Finish building a cell list. tree_expression * octave_parser::finish_cell (tree_cell *c) { - return finish_matrix (c); + return finish_array_list (c); } void diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/parse.h --- a/libinterp/parse-tree/parse.h Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/parse.h Sat Mar 09 18:09:54 2013 -0500 @@ -41,6 +41,7 @@ class tree; class tree_anon_fcn_handle; class tree_argument_list; +class tree_array_list; class tree_cell; class tree_classdef; class tree_classdef_attribute_list; @@ -384,6 +385,10 @@ // Validate argument list forming a matrix or cell row. tree_argument_list *validate_matrix_row (tree_argument_list *row); + // Finish building an array_list (common action for finish_matrix + // and finish_cell). + tree_expression *finish_array_list (tree_array_list *a); + // Finish building a matrix list. tree_expression *finish_matrix (tree_matrix *m); diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-arg-list.h --- a/libinterp/parse-tree/pt-arg-list.h Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/pt-arg-list.h Sat Mar 09 18:09:54 2013 -0500 @@ -33,6 +33,7 @@ #include "str-vec.h" #include "base-list.h" +#include "symtab.h" // Argument lists. Used to hold the list of expressions that are the // arguments in a function call or index expression. diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-array-list.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/parse-tree/pt-array-list.cc Sat Mar 09 18:09:54 2013 -0500 @@ -0,0 +1,108 @@ +/* + +Copyright (C) 2013 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "error.h" +#include "pt-array-list.h" + +tree_array_list::~tree_array_list (void) +{ + while (! empty ()) + { + iterator p = begin (); + delete *p; + erase (p); + } +} + +bool +tree_array_list::all_elements_are_constant (void) const +{ + for (const_iterator p = begin (); p != end (); p++) + { + octave_quit (); + + tree_argument_list *elt = *p; + + if (! elt->all_elements_are_constant ()) + return false; + } + + return true; +} + +bool +tree_array_list::has_magic_end (void) const +{ + for (const_iterator p = begin (); p != end (); p++) + { + octave_quit (); + + tree_argument_list *elt = *p; + + if (elt && elt->has_magic_end ()) + return true; + } + + return false; +} + +void +tree_array_list::copy_base (const tree_array_list& array_list) +{ + tree_expression::copy_base (array_list); +} + +void +tree_array_list::copy_base (const tree_array_list& array_list, + symbol_table::scope_id scope, + symbol_table::context_id context) +{ + for (const_iterator p = array_list.begin (); p != array_list.end (); p++) + { + const tree_argument_list *elt = *p; + + append (elt ? elt->dup (scope, context) : 0); + } + + copy_base (*this); +} + +tree_expression * +tree_array_list::dup (symbol_table::scope_id scope, + symbol_table::context_id context) const +{ + panic_impossible (); + return 0; +} + +void +tree_array_list::accept (tree_walker&) +{ + panic_impossible (); +} + diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-array-list.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/parse-tree/pt-array-list.h Sat Mar 09 18:09:54 2013 -0500 @@ -0,0 +1,72 @@ +/* + +Copyright (C) 2013 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if !defined (octave_tree_array_list_h) +#define octave_tree_array_list_h 1 + +#include "base-list.h" +#include "pt-arg-list.h" +#include "pt-exp.h" +#include "symtab.h" + +// Base class for cell arrays and matrices. + +class +tree_array_list : public tree_expression, + public octave_base_list +{ +public: + + tree_array_list (tree_argument_list *row = 0, int l = -1, int c = -1) + : tree_expression (l, c), octave_base_list () + { + if (row) + append (row); + } + + ~tree_array_list (void); + + bool all_elements_are_constant (void) const; + + bool has_magic_end (void) const; + + void copy_base (const tree_array_list& array_list); + + void copy_base (const tree_array_list& array_list, + symbol_table::scope_id scope, + symbol_table::context_id context); + + tree_expression *dup (symbol_table::scope_id scope, + symbol_table::context_id context) const; + + void accept (tree_walker& tw); + +private: + + // No copying! + + tree_array_list (const tree_array_list&); + + tree_array_list& operator = (const tree_array_list&); +}; + +#endif diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-cell.cc --- a/libinterp/parse-tree/pt-cell.cc Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/pt-cell.cc Sat Mar 09 18:09:54 2013 -0500 @@ -27,17 +27,12 @@ #include #include "Cell.h" -#include "defun.h" -#include "error.h" #include "oct-obj.h" #include "pt-arg-list.h" -#include "pt-bp.h" #include "pt-exp.h" #include "pt-cell.h" #include "pt-walk.h" -#include "utils.h" #include "ov.h" -#include "variables.h" octave_value tree_cell::rvalue1 (int) @@ -107,14 +102,7 @@ { tree_cell *new_cell = new tree_cell (0, line (), column ()); - for (const_iterator p = begin (); p != end (); p++) - { - const tree_argument_list *elt = *p; - - new_cell->append (elt ? elt->dup (scope, context) : 0); - } - - new_cell->copy_base (*this); + new_cell->copy_base (*this, scope, context); return new_cell; } diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-cell.h --- a/libinterp/parse-tree/pt-cell.h Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/pt-cell.h Sat Mar 09 18:09:54 2013 -0500 @@ -37,12 +37,13 @@ // General cells. class -tree_cell : public tree_matrix +tree_cell : public tree_array_list { public: tree_cell (tree_argument_list *row = 0, int l = -1, int c = -1) - : tree_matrix (row, l, c) { } + : tree_array_list (row, l, c) + { } ~tree_cell (void) { } diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-mat.cc --- a/libinterp/parse-tree/pt-mat.cc Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/pt-mat.cc Sat Mar 09 18:09:54 2013 -0500 @@ -655,48 +655,6 @@ ok = ! error_state; } -tree_matrix::~tree_matrix (void) -{ - while (! empty ()) - { - iterator p = begin (); - delete *p; - erase (p); - } -} - -bool -tree_matrix::has_magic_end (void) const -{ - for (const_iterator p = begin (); p != end (); p++) - { - octave_quit (); - - tree_argument_list *elt = *p; - - if (elt && elt->has_magic_end ()) - return true; - } - - return false; -} - -bool -tree_matrix::all_elements_are_constant (void) const -{ - for (const_iterator p = begin (); p != end (); p++) - { - octave_quit (); - - tree_argument_list *elt = *p; - - if (! elt->all_elements_are_constant ()) - return false; - } - - return true; -} - octave_value_list tree_matrix::rvalue (int nargout) { @@ -1174,14 +1132,7 @@ { tree_matrix *new_matrix = new tree_matrix (0, line (), column ()); - for (const_iterator p = begin (); p != end (); p++) - { - const tree_argument_list *elt = *p; - - new_matrix->append (elt ? elt->dup (scope, context) : 0); - } - - new_matrix->copy_base (*this); + new_matrix->copy_base (*this, scope, context); return new_matrix; } diff -r d8c0f46efaf0 -r 90dfd98a915a libinterp/parse-tree/pt-mat.h --- a/libinterp/parse-tree/pt-mat.h Sat Mar 09 17:54:40 2013 -0500 +++ b/libinterp/parse-tree/pt-mat.h Sat Mar 09 18:09:54 2013 -0500 @@ -32,6 +32,7 @@ class tree_walker; #include "base-list.h" +#include "pt-array-list.h" #include "pt-exp.h" #include "symtab.h" @@ -39,23 +40,15 @@ // other matrices, variables, and functions. class -tree_matrix : public tree_expression, - public octave_base_list +tree_matrix : public tree_array_list { public: tree_matrix (tree_argument_list *row = 0, int l = -1, int c = -1) - : tree_expression (l, c) - { - if (row) - append (row); - } + : tree_array_list (row, l, c) + { } - ~tree_matrix (void); - - bool has_magic_end (void) const; - - bool all_elements_are_constant (void) const; + ~tree_matrix (void) { } bool rvalue_ok (void) const { return true; } diff -r d8c0f46efaf0 -r 90dfd98a915a liboctave/util/base-list.h --- a/liboctave/util/base-list.h Sat Mar 09 17:54:40 2013 -0500 +++ b/liboctave/util/base-list.h Sat Mar 09 18:09:54 2013 -0500 @@ -23,6 +23,8 @@ #if !defined (octave_base_list_h) #define octave_base_list_h 1 +#include + #include template