2887
|
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 "gripes.h" |
|
33 #include "oct-map.h" |
|
34 #include "oct-obj.h" |
|
35 #include "oct-sym.h" |
2955
|
36 #include "oct-var-ref.h" |
2887
|
37 #include "pager.h" |
|
38 #include "pt-const.h" |
|
39 #include "pt-id.h" |
|
40 #include "pt-indir.h" |
|
41 #include "pt-walk.h" |
2900
|
42 #include "symtab.h" |
2887
|
43 #include "utils.h" |
|
44 |
|
45 // Indirect references to values (structure elements). |
|
46 |
|
47 tree_indirect_ref::~tree_indirect_ref (void) |
|
48 { |
|
49 if (! preserve_ident) |
|
50 delete id; |
|
51 |
|
52 if (! preserve_indir) |
|
53 delete indir; |
|
54 } |
|
55 |
|
56 void |
|
57 tree_indirect_ref::mark_for_possible_ans_assign (void) |
|
58 { |
|
59 maybe_do_ans_assign = true; |
|
60 |
|
61 if (is_identifier_only ()) |
|
62 id->mark_for_possible_ans_assign (); |
|
63 } |
|
64 |
|
65 string |
|
66 tree_indirect_ref::name (void) const |
|
67 { |
|
68 string retval; |
|
69 |
|
70 if (is_identifier_only ()) |
|
71 retval = id->name (); |
|
72 else |
|
73 { |
|
74 if (id) |
|
75 retval = id->name (); |
|
76 else if (indir) |
|
77 retval = indir->name (); |
|
78 else |
|
79 panic_impossible (); |
|
80 |
|
81 retval.append ("."); |
|
82 retval.append (nm); |
|
83 } |
|
84 |
|
85 return retval; |
|
86 } |
|
87 |
|
88 octave_value |
|
89 tree_indirect_ref::eval (bool print) |
|
90 { |
|
91 octave_value retval; |
|
92 |
|
93 if (is_identifier_only ()) |
|
94 retval = id->eval (print); |
|
95 else |
|
96 { |
|
97 retval = value (); |
|
98 |
|
99 if (! error_state && retval.is_defined ()) |
|
100 { |
|
101 if (maybe_do_ans_assign) |
|
102 bind_ans (retval, print); |
|
103 else if (print) |
2900
|
104 retval.print_with_name (octave_stdout, name ()); |
2887
|
105 } |
|
106 } |
|
107 |
|
108 return retval; |
|
109 } |
|
110 |
|
111 octave_value_list |
|
112 tree_indirect_ref::eval (bool print, int nargout, |
|
113 const octave_value_list& args) |
|
114 { |
|
115 octave_value_list retval; |
|
116 |
|
117 if (is_identifier_only ()) |
|
118 retval = id->eval (print, nargout, args); |
|
119 else |
|
120 { |
|
121 octave_value tmp = value (); |
|
122 |
|
123 if (! error_state && tmp.is_defined ()) |
|
124 { |
|
125 retval = tmp.index (args); |
|
126 |
|
127 if (! error_state) |
|
128 { |
|
129 if (maybe_do_ans_assign && nargout == 1 |
|
130 && retval.length () > 0 && retval(0).is_defined ()) |
|
131 bind_ans (retval(0), print); |
|
132 } |
|
133 } |
|
134 } |
|
135 |
|
136 return retval; |
|
137 } |
|
138 |
|
139 void |
|
140 tree_indirect_ref::accept (tree_walker& tw) |
|
141 { |
|
142 tw.visit_indirect_ref (*this); |
|
143 } |
|
144 |
|
145 octave_value |
|
146 tree_indirect_ref::value (void) const |
|
147 { |
|
148 octave_value retval; |
|
149 |
|
150 if (is_identifier_only ()) |
|
151 retval = id->value (); |
|
152 else |
|
153 { |
|
154 if (id) |
|
155 retval = id->value (); |
|
156 else if (indir) |
|
157 retval = indir->value (); |
|
158 else |
|
159 panic_impossible (); |
|
160 |
|
161 if (! error_state) |
|
162 retval = retval.struct_elt_val (nm); |
|
163 } |
|
164 |
|
165 return retval; |
|
166 } |
|
167 |
2948
|
168 octave_variable_reference |
2887
|
169 tree_indirect_ref::reference (void) |
|
170 { |
|
171 if (is_identifier_only ()) |
|
172 return id->reference (); |
|
173 else |
|
174 { |
2948
|
175 octave_variable_reference tmp; |
|
176 |
2887
|
177 if (id) |
2948
|
178 tmp = id->reference (); |
2887
|
179 else if (indir) |
2948
|
180 tmp = indir->reference (); |
2887
|
181 else |
2948
|
182 panic_impossible (); |
|
183 |
|
184 if (tmp.is_undefined ()) |
|
185 tmp.define (Octave_map ()); |
|
186 |
|
187 return tmp.struct_elt_ref (nm); |
2887
|
188 } |
|
189 } |
|
190 |
|
191 /* |
|
192 ;;; Local Variables: *** |
|
193 ;;; mode: C++ *** |
|
194 ;;; End: *** |
|
195 */ |