2980
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 #include "oct-lvalue.h" |
|
34 #include "ov.h" |
2982
|
35 #include "pt-arg-list.h" |
2980
|
36 #include "pt-idx.h" |
|
37 #include "pt-walk.h" |
|
38 |
|
39 // Index expressions. |
|
40 |
|
41 tree_index_expression::~tree_index_expression (void) |
|
42 { |
|
43 delete expr; |
|
44 delete list; |
|
45 } |
|
46 |
2991
|
47 // This is useful for printing the name of the variable in an indexed |
|
48 // assignment. |
|
49 |
|
50 string |
|
51 tree_index_expression::name (void) const |
|
52 { |
|
53 return expr->name (); |
|
54 } |
|
55 |
2980
|
56 octave_value_list |
|
57 tree_index_expression::rvalue (int nargout) |
|
58 { |
|
59 octave_value_list retval; |
|
60 |
|
61 if (error_state) |
|
62 return retval; |
|
63 |
|
64 octave_value tmp = expr->rvalue (); |
|
65 |
|
66 if (! error_state) |
|
67 { |
|
68 octave_value_list args; |
|
69 |
|
70 if (list) |
|
71 args = list->convert_to_const_vector (); |
|
72 |
|
73 if (! error_state) |
|
74 { |
|
75 if (! args.empty ()) |
|
76 args.stash_name_tags (arg_nm); |
|
77 |
|
78 // XXX FIXME XXX -- is this the right thing to do? |
|
79 if (tmp.is_constant ()) |
|
80 retval = tmp.do_index_op (args); |
|
81 else |
|
82 retval = tmp.do_index_op (nargout, args); |
|
83 } |
|
84 else |
|
85 eval_error (); |
|
86 } |
|
87 else |
|
88 eval_error (); |
|
89 |
|
90 return retval; |
|
91 } |
|
92 |
|
93 octave_value |
|
94 tree_index_expression::rvalue (void) |
|
95 { |
|
96 octave_value retval; |
|
97 |
|
98 octave_value_list tmp = rvalue (1); |
|
99 |
|
100 if (! tmp.empty ()) |
|
101 retval = tmp(0); |
|
102 |
|
103 return retval; |
|
104 } |
|
105 |
|
106 octave_lvalue |
|
107 tree_index_expression::lvalue (void) |
|
108 { |
|
109 octave_lvalue retval; |
|
110 |
|
111 if (! error_state) |
|
112 { |
|
113 retval = expr->lvalue (); |
|
114 |
|
115 if (! error_state) |
|
116 { |
|
117 octave_value_list args; |
|
118 |
|
119 if (list) |
|
120 args = list->convert_to_const_vector (); |
|
121 |
2984
|
122 retval.set_index (args); |
2980
|
123 } |
|
124 } |
|
125 |
|
126 return retval; |
|
127 } |
|
128 |
|
129 void |
|
130 tree_index_expression::eval_error (void) |
|
131 { |
|
132 if (error_state > 0) |
|
133 { |
|
134 int l = line (); |
|
135 int c = column (); |
|
136 |
|
137 if (l != -1 && c != -1) |
|
138 { |
|
139 if (list) |
|
140 ::error ("evaluating index expression near line %d, column %d", |
|
141 l, c); |
|
142 else |
|
143 ::error ("evaluating expression near line %d, column %d", l, c); |
|
144 } |
|
145 else |
|
146 { |
|
147 if (list) |
|
148 ::error ("evaluating index expression"); |
|
149 else |
|
150 ::error ("evaluating expression"); |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 void |
|
156 tree_index_expression::accept (tree_walker& tw) |
|
157 { |
|
158 tw.visit_index_expression (*this); |
|
159 } |
|
160 |
|
161 /* |
|
162 ;;; Local Variables: *** |
|
163 ;;; mode: C++ *** |
|
164 ;;; End: *** |
|
165 */ |