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 |
|
47 octave_value_list |
|
48 tree_index_expression::rvalue (int nargout) |
|
49 { |
|
50 octave_value_list retval; |
|
51 |
|
52 if (error_state) |
|
53 return retval; |
|
54 |
|
55 octave_value tmp = expr->rvalue (); |
|
56 |
|
57 if (! error_state) |
|
58 { |
|
59 octave_value_list args; |
|
60 |
|
61 if (list) |
|
62 args = list->convert_to_const_vector (); |
|
63 |
|
64 if (! error_state) |
|
65 { |
|
66 if (! args.empty ()) |
|
67 args.stash_name_tags (arg_nm); |
|
68 |
|
69 // XXX FIXME XXX -- is this the right thing to do? |
|
70 if (tmp.is_constant ()) |
|
71 retval = tmp.do_index_op (args); |
|
72 else |
|
73 retval = tmp.do_index_op (nargout, args); |
|
74 } |
|
75 else |
|
76 eval_error (); |
|
77 } |
|
78 else |
|
79 eval_error (); |
|
80 |
|
81 return retval; |
|
82 } |
|
83 |
|
84 octave_value |
|
85 tree_index_expression::rvalue (void) |
|
86 { |
|
87 octave_value retval; |
|
88 |
|
89 octave_value_list tmp = rvalue (1); |
|
90 |
|
91 if (! tmp.empty ()) |
|
92 retval = tmp(0); |
|
93 |
|
94 return retval; |
|
95 } |
|
96 |
|
97 octave_lvalue |
|
98 tree_index_expression::lvalue (void) |
|
99 { |
|
100 octave_lvalue retval; |
|
101 |
|
102 if (! error_state) |
|
103 { |
|
104 retval = expr->lvalue (); |
|
105 |
|
106 if (! error_state) |
|
107 { |
|
108 octave_value_list args; |
|
109 |
|
110 if (list) |
|
111 args = list->convert_to_const_vector (); |
|
112 |
|
113 retval.index (args); |
|
114 } |
|
115 } |
|
116 |
|
117 return retval; |
|
118 } |
|
119 |
|
120 void |
|
121 tree_index_expression::eval_error (void) |
|
122 { |
|
123 if (error_state > 0) |
|
124 { |
|
125 int l = line (); |
|
126 int c = column (); |
|
127 |
|
128 if (l != -1 && c != -1) |
|
129 { |
|
130 if (list) |
|
131 ::error ("evaluating index expression near line %d, column %d", |
|
132 l, c); |
|
133 else |
|
134 ::error ("evaluating expression near line %d, column %d", l, c); |
|
135 } |
|
136 else |
|
137 { |
|
138 if (list) |
|
139 ::error ("evaluating index expression"); |
|
140 else |
|
141 ::error ("evaluating expression"); |
|
142 } |
|
143 } |
|
144 } |
|
145 |
|
146 void |
|
147 tree_index_expression::accept (tree_walker& tw) |
|
148 { |
|
149 tw.visit_index_expression (*this); |
|
150 } |
|
151 |
|
152 /* |
|
153 ;;; Local Variables: *** |
|
154 ;;; mode: C++ *** |
|
155 ;;; End: *** |
|
156 */ |