3353
|
1 /* |
|
2 |
|
3 Copyright (C) 1999 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
3353
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
3353
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
3503
|
27 #include <iostream> |
3353
|
28 |
|
29 #include "Cell.h" |
|
30 #include "defun.h" |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 #include "pt-arg-list.h" |
3770
|
34 #include "pt-bp.h" |
3353
|
35 #include "pt-exp.h" |
|
36 #include "pt-cell.h" |
|
37 #include "pt-walk.h" |
|
38 #include "utils.h" |
|
39 #include "ov.h" |
|
40 #include "variables.h" |
|
41 |
|
42 octave_value |
|
43 tree_cell::rvalue (void) |
|
44 { |
|
45 octave_value retval; |
|
46 |
3770
|
47 MAYBE_DO_BREAKPOINT; |
|
48 |
5275
|
49 octave_idx_type nr = length (); |
|
50 octave_idx_type nc = -1; |
3353
|
51 |
4501
|
52 Cell val; |
3353
|
53 |
|
54 int i = 0; |
|
55 |
4219
|
56 for (iterator p = begin (); p != end (); p++) |
3353
|
57 { |
4219
|
58 tree_argument_list *elt = *p; |
3353
|
59 |
|
60 octave_value_list row = elt->convert_to_const_vector (); |
|
61 |
4501
|
62 if (nc < 0) |
|
63 { |
|
64 nc = row.length (); |
|
65 |
|
66 val = Cell (nr, nc); |
|
67 } |
|
68 else |
|
69 { |
5275
|
70 octave_idx_type this_nc = row.length (); |
4501
|
71 |
|
72 if (nc != this_nc) |
|
73 { |
|
74 ::error ("number of columns must match"); |
|
75 return retval; |
|
76 } |
|
77 } |
|
78 |
5275
|
79 for (octave_idx_type j = 0; j < nc; j++) |
3353
|
80 val(i,j) = row(j); |
|
81 |
|
82 i++; |
|
83 } |
|
84 |
|
85 retval = val; |
|
86 |
|
87 return retval; |
|
88 } |
|
89 |
3556
|
90 octave_value_list |
|
91 tree_cell::rvalue (int nargout) |
|
92 { |
|
93 octave_value_list retval; |
|
94 |
|
95 if (nargout > 1) |
|
96 error ("invalid number of output arguments for cell array"); |
|
97 else |
|
98 retval = rvalue (); |
|
99 |
|
100 return retval; |
|
101 } |
|
102 |
5861
|
103 tree_expression * |
|
104 tree_cell::dup (symbol_table *sym_tab) |
|
105 { |
|
106 tree_cell *new_cell = new tree_cell (0, line (), column ()); |
|
107 |
|
108 for (iterator p = begin (); p != end (); p++) |
|
109 { |
|
110 tree_argument_list *elt = *p; |
|
111 |
6039
|
112 new_cell->append (elt ? elt->dup (sym_tab) : 0); |
5861
|
113 } |
|
114 |
|
115 new_cell->copy_base (*this); |
|
116 |
|
117 return new_cell; |
|
118 } |
|
119 |
3353
|
120 void |
|
121 tree_cell::accept (tree_walker& tw) |
|
122 { |
|
123 tw.visit_cell (*this); |
|
124 } |
|
125 |
|
126 /* |
|
127 ;;; Local Variables: *** |
|
128 ;;; mode: C++ *** |
|
129 ;;; End: *** |
|
130 */ |