1739
|
1 /* |
|
2 |
1827
|
3 Copyright (C) 1996 John W. Eaton |
1739
|
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 (octave_tree_fvc2_h) |
|
24 #define octave_tree_fvc2_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 class ostream; |
|
31 |
|
32 #include <SLList.h> |
|
33 |
|
34 class symbol_record; |
2391
|
35 class tree_constant; |
1739
|
36 class tree_function; |
|
37 |
2124
|
38 class tree_walker; |
|
39 |
1739
|
40 #include "mappers.h" |
|
41 #include "pt-fvc-base.h" |
|
42 #include "variables.h" |
|
43 |
|
44 // Symbols from the symbol table. |
|
45 |
|
46 class |
|
47 tree_identifier : public tree_fvc |
|
48 { |
|
49 friend class tree_index_expression; |
|
50 |
|
51 public: |
2124
|
52 |
1739
|
53 tree_identifier (int l = -1, int c = -1) |
1827
|
54 : tree_fvc (l, c), sym (0), maybe_do_ans_assign (false) { } |
1739
|
55 |
|
56 tree_identifier (symbol_record *s, int l = -1, int c = -1) |
1827
|
57 : tree_fvc (l, c), sym (s), maybe_do_ans_assign (false) { } |
1739
|
58 |
|
59 ~tree_identifier (void) { } |
|
60 |
1827
|
61 bool is_identifier (void) const |
|
62 { return true; } |
1739
|
63 |
1755
|
64 string name (void) const; |
1739
|
65 |
2391
|
66 tree_identifier *define (tree_constant *t); |
1739
|
67 tree_identifier *define (tree_function *t); |
|
68 |
1755
|
69 void document (const string& s); |
1739
|
70 |
2391
|
71 octave_value assign (const octave_value& t); |
|
72 octave_value assign (const octave_value_list& args, const octave_value& t); |
1739
|
73 |
1827
|
74 bool is_defined (void); |
1739
|
75 |
2391
|
76 void increment (void); |
|
77 |
|
78 void decrement (void); |
1739
|
79 |
1827
|
80 tree_fvc *do_lookup (bool& script_file_executed, bool exec_script = true); |
1739
|
81 |
|
82 void link_to_global (void); |
|
83 |
|
84 void mark_as_formal_parameter (void); |
|
85 |
|
86 void mark_for_possible_ans_assign (void) |
1827
|
87 { maybe_do_ans_assign = true; } |
1739
|
88 |
2086
|
89 octave_value eval (bool print); |
1739
|
90 |
2447
|
91 octave_value_list eval (bool print, int nargout, |
|
92 const octave_value_list& args); |
1739
|
93 |
|
94 void eval_undefined_error (void); |
|
95 |
2124
|
96 void accept (tree_walker& tw); |
1739
|
97 |
2391
|
98 octave_value value (void) const; |
|
99 |
|
100 octave_value& reference (void); |
|
101 |
1739
|
102 private: |
2124
|
103 |
|
104 // The symbol record that this identifier references. |
1739
|
105 symbol_record *sym; |
2124
|
106 |
|
107 // True if we should consider assigning the result of evaluating |
|
108 // this identifier to the built-in variable ans. |
1827
|
109 bool maybe_do_ans_assign; |
1739
|
110 }; |
|
111 |
|
112 // Indirect references to values (structure references). |
|
113 |
|
114 class |
|
115 tree_indirect_ref : public tree_fvc |
|
116 { |
|
117 public: |
2124
|
118 |
1739
|
119 tree_indirect_ref (int l = -1, int c = -1) |
2391
|
120 : tree_fvc (l, c), id (0), indir (0), nm (), |
|
121 preserve_ident (false), preserve_indir (false), |
|
122 maybe_do_ans_assign (false) { } |
1739
|
123 |
|
124 tree_indirect_ref (tree_identifier *i, int l = -1, int c = -1) |
2391
|
125 : tree_fvc (l, c), id (i), indir (0), nm (), |
|
126 preserve_ident (false), preserve_indir (false), |
|
127 maybe_do_ans_assign (false) { } |
|
128 |
|
129 tree_indirect_ref (tree_indirect_ref *i, const string& n, |
|
130 int l = -1, int c = -1) |
|
131 : tree_fvc (l, c), id (0), indir (i), nm (n), |
|
132 preserve_ident (false), preserve_indir (false), |
|
133 maybe_do_ans_assign (false) { } |
1739
|
134 |
|
135 ~tree_indirect_ref (void); |
|
136 |
1827
|
137 bool is_indirect_ref (void) const |
|
138 { return true; } |
1739
|
139 |
1827
|
140 bool is_identifier_only (void) const |
2391
|
141 { return (id && nm.empty ()); } |
1739
|
142 |
|
143 tree_identifier *ident (void) |
|
144 { return id; } |
|
145 |
2391
|
146 tree_indirect_ref *indirect (void) |
|
147 { return indir; } |
|
148 |
1739
|
149 void preserve_identifier (void) |
1827
|
150 { preserve_ident = true; } |
1739
|
151 |
2391
|
152 void preserve_indirect (void) |
|
153 { preserve_indir = true; } |
|
154 |
|
155 void mark_for_possible_ans_assign (void) |
|
156 { |
|
157 maybe_do_ans_assign = true; |
|
158 |
|
159 if (is_identifier_only ()) |
|
160 id->mark_for_possible_ans_assign (); |
|
161 } |
|
162 |
1755
|
163 string name (void) const; |
1739
|
164 |
2086
|
165 octave_value eval (bool print); |
1739
|
166 |
2124
|
167 octave_value_list eval (bool print, int nargout, |
|
168 const octave_value_list& args); |
1739
|
169 |
2391
|
170 octave_value value (void) const; |
|
171 octave_value& reference (void); |
|
172 |
|
173 string elt_name (void) |
|
174 { return nm; } |
2124
|
175 |
|
176 void accept (tree_walker& tw); |
1739
|
177 |
|
178 private: |
2124
|
179 |
|
180 // The identifier for this structure reference. For example, in |
2391
|
181 // a.b.c, a is the id. |
1739
|
182 tree_identifier *id; |
2124
|
183 |
2391
|
184 // This element just points to another indirect reference. |
|
185 tree_indirect_ref *indir; |
|
186 |
|
187 // The sub-element name. |
|
188 string nm; |
2124
|
189 |
|
190 // True if we should not delete the identifier. |
1827
|
191 bool preserve_ident; |
2391
|
192 |
|
193 // True if we should not delete the indirect reference. |
|
194 bool preserve_indir; |
|
195 |
|
196 // True if we should consider assigning the result of evaluating |
|
197 // this identifier to the built-in variable ans. |
|
198 bool maybe_do_ans_assign; |
1739
|
199 }; |
|
200 |
|
201 // Builtin functions. |
|
202 |
|
203 class |
|
204 tree_builtin : public tree_fvc |
|
205 { |
|
206 public: |
2124
|
207 |
1755
|
208 tree_builtin (const string& nm = string ()); |
1739
|
209 |
2089
|
210 tree_builtin (const builtin_mapper_function& m_fcn, |
|
211 const string& nm = string ()); |
1739
|
212 |
1755
|
213 tree_builtin (Octave_builtin_fcn f, const string& nm = string ()); |
1739
|
214 |
|
215 ~tree_builtin (void) { } // XXX ?? XXX |
|
216 |
|
217 // int is_builtin (void) const; |
|
218 |
1827
|
219 bool is_mapper_function (void) const |
1739
|
220 { return is_mapper; } |
|
221 |
2086
|
222 octave_value eval (bool print); |
1739
|
223 |
2086
|
224 octave_value_list eval (bool print, int nargout, const octave_value_list& args); |
1739
|
225 |
1755
|
226 string name (void) const |
1739
|
227 { return my_name; } |
|
228 |
2124
|
229 void accept (tree_walker& tw); |
1739
|
230 |
|
231 private: |
2124
|
232 |
|
233 // True if this is a mapper function. |
1827
|
234 bool is_mapper; |
2124
|
235 |
|
236 // A structure describing the mapper function. |
2088
|
237 builtin_mapper_function mapper_fcn; |
2124
|
238 |
|
239 // The actual function, if it is not a mapper. |
1739
|
240 Octave_builtin_fcn fcn; |
2124
|
241 |
|
242 // The name of this function. |
1755
|
243 string my_name; |
1739
|
244 }; |
|
245 |
|
246 #endif |
|
247 |
|
248 /* |
|
249 ;;; Local Variables: *** |
|
250 ;;; mode: C++ *** |
|
251 ;;; End: *** |
|
252 */ |