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 |
3215
|
41 tree_index_expression::tree_index_expression (tree_expression *e = 0, |
|
42 tree_argument_list *lst = 0, |
|
43 int l = -1, int c = -1) |
|
44 : tree_expression (l, c), expr (e), list (lst), |
|
45 arg_nm (lst ? lst->get_arg_names () : string_vector ()) { } |
|
46 |
2980
|
47 tree_index_expression::~tree_index_expression (void) |
|
48 { |
|
49 delete expr; |
|
50 delete list; |
|
51 } |
|
52 |
2991
|
53 // This is useful for printing the name of the variable in an indexed |
|
54 // assignment. |
|
55 |
3534
|
56 std:string |
2991
|
57 tree_index_expression::name (void) const |
|
58 { |
|
59 return expr->name (); |
|
60 } |
|
61 |
2980
|
62 octave_value_list |
|
63 tree_index_expression::rvalue (int nargout) |
|
64 { |
|
65 octave_value_list retval; |
|
66 |
|
67 if (error_state) |
|
68 return retval; |
|
69 |
|
70 octave_value tmp = expr->rvalue (); |
|
71 |
|
72 if (! error_state) |
|
73 { |
|
74 octave_value_list args; |
|
75 |
|
76 if (list) |
|
77 args = list->convert_to_const_vector (); |
|
78 |
|
79 if (! error_state) |
|
80 { |
|
81 if (! args.empty ()) |
|
82 args.stash_name_tags (arg_nm); |
|
83 |
|
84 // XXX FIXME XXX -- is this the right thing to do? |
|
85 if (tmp.is_constant ()) |
|
86 retval = tmp.do_index_op (args); |
|
87 else |
|
88 retval = tmp.do_index_op (nargout, args); |
|
89 } |
|
90 else |
|
91 eval_error (); |
|
92 } |
|
93 else |
|
94 eval_error (); |
|
95 |
|
96 return retval; |
|
97 } |
|
98 |
|
99 octave_value |
|
100 tree_index_expression::rvalue (void) |
|
101 { |
|
102 octave_value retval; |
|
103 |
|
104 octave_value_list tmp = rvalue (1); |
|
105 |
|
106 if (! tmp.empty ()) |
|
107 retval = tmp(0); |
|
108 |
|
109 return retval; |
|
110 } |
|
111 |
|
112 octave_lvalue |
|
113 tree_index_expression::lvalue (void) |
|
114 { |
|
115 octave_lvalue retval; |
|
116 |
|
117 if (! error_state) |
|
118 { |
|
119 retval = expr->lvalue (); |
|
120 |
|
121 if (! error_state) |
|
122 { |
|
123 octave_value_list args; |
|
124 |
|
125 if (list) |
|
126 args = list->convert_to_const_vector (); |
|
127 |
2984
|
128 retval.set_index (args); |
2980
|
129 } |
|
130 } |
|
131 |
|
132 return retval; |
|
133 } |
|
134 |
|
135 void |
|
136 tree_index_expression::eval_error (void) |
|
137 { |
|
138 if (error_state > 0) |
|
139 { |
|
140 int l = line (); |
|
141 int c = column (); |
|
142 |
|
143 if (l != -1 && c != -1) |
|
144 { |
|
145 if (list) |
|
146 ::error ("evaluating index expression near line %d, column %d", |
|
147 l, c); |
|
148 else |
|
149 ::error ("evaluating expression near line %d, column %d", l, c); |
|
150 } |
|
151 else |
|
152 { |
|
153 if (list) |
|
154 ::error ("evaluating index expression"); |
|
155 else |
|
156 ::error ("evaluating expression"); |
|
157 } |
|
158 } |
|
159 } |
|
160 |
|
161 void |
|
162 tree_index_expression::accept (tree_walker& tw) |
|
163 { |
|
164 tw.visit_index_expression (*this); |
|
165 } |
|
166 |
|
167 /* |
|
168 ;;; Local Variables: *** |
|
169 ;;; mode: C++ *** |
|
170 ;;; End: *** |
|
171 */ |