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 "oct-map.h" |
|
33 #include "oct-obj.h" |
2979
|
34 #include "oct-lvalue.h" |
2982
|
35 #include "ov.h" |
2887
|
36 #include "pager.h" |
|
37 #include "pt-indir.h" |
|
38 #include "pt-walk.h" |
|
39 #include "utils.h" |
2956
|
40 #include "variables.h" |
2887
|
41 |
|
42 // Indirect references to values (structure elements). |
|
43 |
|
44 tree_indirect_ref::~tree_indirect_ref (void) |
|
45 { |
2971
|
46 delete expr; |
2887
|
47 } |
|
48 |
|
49 string |
|
50 tree_indirect_ref::name (void) const |
|
51 { |
2982
|
52 // ??? FIXME ??? |
|
53 string xname = expr->name (); |
|
54 |
|
55 return (xname == "<unknown>") ? xname : xname + "." + nm; |
2971
|
56 } |
2887
|
57 |
2971
|
58 octave_value_list |
|
59 tree_indirect_ref::rvalue (int nargout) |
|
60 { |
|
61 octave_value_list retval; |
|
62 |
|
63 if (nargout > 1) |
2972
|
64 error ("invalid number of output arguments for structure reference"); |
2887
|
65 else |
|
66 { |
2971
|
67 octave_value_list tmp = expr->rvalue (nargout); |
2887
|
68 |
2971
|
69 if (tmp.empty ()) |
2972
|
70 eval_error (); |
2971
|
71 else |
|
72 { |
|
73 octave_value val = tmp(0).do_struct_elt_index_op (nm); |
2887
|
74 |
2971
|
75 if (print_result () && nargout == 0 && val.is_defined ()) |
2982
|
76 { |
|
77 // ??? FIXME ??? |
|
78 |
|
79 string xname = name (); |
|
80 |
|
81 if (xname == "<unknown>") |
|
82 bind_ans (val, true); |
|
83 else |
|
84 val.print_with_name (octave_stdout, xname); |
|
85 } |
2887
|
86 |
2971
|
87 retval = val; |
2887
|
88 } |
|
89 } |
|
90 |
|
91 return retval; |
|
92 } |
|
93 |
2971
|
94 octave_value |
|
95 tree_indirect_ref::rvalue (void) |
2887
|
96 { |
2971
|
97 octave_value retval; |
2887
|
98 |
2971
|
99 octave_value_list tmp = rvalue (1); |
2963
|
100 |
2971
|
101 if (! tmp.empty ()) |
|
102 retval = tmp(0); |
2887
|
103 |
|
104 return retval; |
|
105 } |
|
106 |
2979
|
107 octave_lvalue |
2971
|
108 tree_indirect_ref::lvalue (void) |
|
109 { |
2979
|
110 octave_lvalue tmp = expr->lvalue (); |
2971
|
111 |
|
112 if (tmp.is_undefined () || ! tmp.is_map ()) |
|
113 tmp.define (Octave_map ()); |
|
114 |
|
115 return tmp.struct_elt_ref (nm); |
|
116 } |
|
117 |
2887
|
118 void |
|
119 tree_indirect_ref::accept (tree_walker& tw) |
|
120 { |
|
121 tw.visit_indirect_ref (*this); |
|
122 } |
|
123 |
2972
|
124 void |
|
125 tree_indirect_ref::eval_error (void) const |
|
126 { |
|
127 if (error_state > 0) |
|
128 ::error ("evaluating structure reference operator near line %d, column %d", |
2973
|
129 line (), column ()); |
2972
|
130 } |
|
131 |
2887
|
132 /* |
|
133 ;;; Local Variables: *** |
|
134 ;;; mode: C++ *** |
|
135 ;;; End: *** |
|
136 */ |