Mercurial > hg > octave-nkf
changeset 16237:70f465930546
rearrange class heirarchy for tree_cell and tree_matrix
* pt-array-list.h, pt-array-list.cc: New files.
(tree_array_list): New class.
* pt-cell.h, pt-cell.cc (tree_cell): Derive from tree_array_list.
* pt-mat.h, pt-mat.cc (tree_matrix): Derive from tree_array_list.
* oct-parse.in.yy (octave_parser::finish_array_list): New function
adapted from octave_parser::finish_matrix.
(octave_parser::finish_matrix, octave_parser::finish_cell):
Call finish_array_list to do the work.
* pt-arg-list.h: Include symtab.h.
* base-list.h: Include cstdlib.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 09 Mar 2013 18:04:51 -0500 |
parents | c31fd42f9000 |
children | 38bd5ae8463b |
files | libinterp/parse-tree/module.mk libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h libinterp/parse-tree/pt-arg-list.h libinterp/parse-tree/pt-array-list.cc libinterp/parse-tree/pt-array-list.h libinterp/parse-tree/pt-cell.cc libinterp/parse-tree/pt-cell.h libinterp/parse-tree/pt-mat.cc libinterp/parse-tree/pt-mat.h liboctave/util/base-list.h |
diffstat | 11 files changed, 218 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/module.mk +++ b/libinterp/parse-tree/module.mk @@ -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 \ @@ -52,6 +53,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 \
--- a/libinterp/parse-tree/oct-parse.in.yy +++ b/libinterp/parse-tree/oct-parse.in.yy @@ -2956,12 +2956,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; @@ -2974,24 +2974,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; } @@ -3000,12 +3001,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
--- a/libinterp/parse-tree/parse.h +++ b/libinterp/parse-tree/parse.h @@ -41,6 +41,7 @@ class tree; class tree_anon_fcn_handle; class tree_argument_list; +class tree_array_list; class tree_cell; class tree_colon_expression; class tree_command; @@ -330,6 +331,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);
--- a/libinterp/parse-tree/pt-arg-list.h +++ b/libinterp/parse-tree/pt-arg-list.h @@ -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.
new file mode 100644 --- /dev/null +++ b/libinterp/parse-tree/pt-array-list.cc @@ -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 +<http://www.gnu.org/licenses/>. + +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <iostream> + +#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 (); +} +
new file mode 100644 --- /dev/null +++ b/libinterp/parse-tree/pt-array-list.h @@ -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 +<http://www.gnu.org/licenses/>. + +*/ + +#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<tree_argument_list *> +{ +public: + + tree_array_list (tree_argument_list *row = 0, int l = -1, int c = -1) + : tree_expression (l, c), octave_base_list<tree_argument_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
--- a/libinterp/parse-tree/pt-cell.cc +++ b/libinterp/parse-tree/pt-cell.cc @@ -27,17 +27,12 @@ #include <iostream> #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; }
--- a/libinterp/parse-tree/pt-cell.h +++ b/libinterp/parse-tree/pt-cell.h @@ -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) { }
--- a/libinterp/parse-tree/pt-mat.cc +++ b/libinterp/parse-tree/pt-mat.cc @@ -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; }
--- a/libinterp/parse-tree/pt-mat.h +++ b/libinterp/parse-tree/pt-mat.h @@ -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_argument_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; }