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