00001 /* 00002 00003 Copyright (C) 1999-2012 John W. Eaton 00004 00005 This file is part of Octave. 00006 00007 Octave is free software; you can redistribute it and/or modify it 00008 under the terms of the GNU General Public License as published by the 00009 Free Software Foundation; either version 3 of the License, or (at your 00010 option) any later version. 00011 00012 Octave is distributed in the hope that it will be useful, but WITHOUT 00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Octave; see the file COPYING. If not, see 00019 <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #ifdef HAVE_CONFIG_H 00024 #include <config.h> 00025 #endif 00026 00027 #include <iostream> 00028 00029 #include "Cell.h" 00030 #include "defun.h" 00031 #include "error.h" 00032 #include "oct-obj.h" 00033 #include "pt-arg-list.h" 00034 #include "pt-bp.h" 00035 #include "pt-exp.h" 00036 #include "pt-cell.h" 00037 #include "pt-walk.h" 00038 #include "utils.h" 00039 #include "ov.h" 00040 #include "variables.h" 00041 00042 octave_value 00043 tree_cell::rvalue1 (int) 00044 { 00045 octave_value retval; 00046 00047 octave_idx_type nr = length (); 00048 octave_idx_type nc = -1; 00049 00050 Cell val; 00051 00052 int i = 0; 00053 00054 for (iterator p = begin (); p != end (); p++) 00055 { 00056 tree_argument_list *elt = *p; 00057 00058 octave_value_list row = elt->convert_to_const_vector (); 00059 00060 if (nr == 1) 00061 // Optimize the single row case. 00062 val = row.cell_value (); 00063 else if (nc < 0) 00064 { 00065 nc = row.length (); 00066 00067 val = Cell (nr, nc); 00068 } 00069 else 00070 { 00071 octave_idx_type this_nc = row.length (); 00072 00073 if (nc != this_nc) 00074 { 00075 ::error ("number of columns must match"); 00076 return retval; 00077 } 00078 } 00079 00080 for (octave_idx_type j = 0; j < nc; j++) 00081 val(i,j) = row(j); 00082 00083 i++; 00084 } 00085 00086 retval = val; 00087 00088 return retval; 00089 } 00090 00091 octave_value_list 00092 tree_cell::rvalue (int nargout) 00093 { 00094 octave_value_list retval; 00095 00096 if (nargout > 1) 00097 error ("invalid number of output arguments for cell array"); 00098 else 00099 retval = rvalue1 (nargout); 00100 00101 return retval; 00102 } 00103 00104 tree_expression * 00105 tree_cell::dup (symbol_table::scope_id scope, 00106 symbol_table::context_id context) const 00107 { 00108 tree_cell *new_cell = new tree_cell (0, line (), column ()); 00109 00110 for (const_iterator p = begin (); p != end (); p++) 00111 { 00112 const tree_argument_list *elt = *p; 00113 00114 new_cell->append (elt ? elt->dup (scope, context) : 0); 00115 } 00116 00117 new_cell->copy_base (*this); 00118 00119 return new_cell; 00120 } 00121 00122 void 00123 tree_cell::accept (tree_walker& tw) 00124 { 00125 tw.visit_cell (*this); 00126 }