Mercurial > hg > octave-nkf
annotate src/pt-decl.h @ 7767:71f068b22fcc
scope and context fixes for function handles
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 07 May 2008 13:45:30 -0400 |
parents | 745a8299c2b5 |
children | 283989f2da9b |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
2982 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2982 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2982 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_tree_decl_h) | |
25 #define octave_tree_decl_h 1 | |
26 | |
27 class tree_expression; | |
28 class tree_identifier; | |
29 | |
30 class tree_walker; | |
31 | |
32 #include <string> | |
33 | |
4219 | 34 #include "base-list.h" |
6215 | 35 #include "oct-lvalue.h" |
2982 | 36 #include "pt-cmd.h" |
6215 | 37 #include "pt-id.h" |
7336 | 38 #include "symtab.h" |
2982 | 39 |
40 // List of expressions that make up a declaration statement. | |
41 | |
42 class | |
43 tree_decl_elt | |
44 { | |
45 public: | |
46 | |
2989 | 47 typedef void (*eval_fcn) (tree_decl_elt &); |
2982 | 48 |
49 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) | |
50 : id (i), expr (e) { } | |
51 | |
52 ~tree_decl_elt (void); | |
53 | |
6215 | 54 bool eval (void); |
55 | |
56 bool is_defined (void) { return id ? id->is_defined () : false; } | |
57 | |
7336 | 58 bool is_variable (void) { return id ? id->is_variable () : false; } |
59 | |
6215 | 60 void mark_as_formal_parameter (void) |
61 { | |
62 if (id) | |
63 id->mark_as_formal_parameter (); | |
64 } | |
65 | |
66 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } | |
67 | |
68 octave_value rvalue (void) { return id ? id->rvalue () : octave_value (); } | |
69 | |
70 octave_value_list rvalue (int nargout) | |
71 { | |
72 return id ? id->rvalue (nargout) : octave_value_list (); | |
73 } | |
74 | |
75 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } | |
2982 | 76 |
77 tree_identifier *ident (void) { return id; } | |
78 | |
79 tree_expression *expression (void) { return expr; } | |
80 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
81 tree_decl_elt *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
82 symbol_table::context_id context); |
5861 | 83 |
2982 | 84 void accept (tree_walker& tw); |
85 | |
86 private: | |
87 | |
88 // An identifier to tag with the declared property. | |
89 tree_identifier *id; | |
90 | |
91 // An initializer expression (may be zero); | |
92 tree_expression *expr; | |
2988 | 93 |
94 // No copying! | |
95 | |
96 tree_decl_elt (const tree_decl_elt&); | |
97 | |
98 tree_decl_elt& operator = (const tree_decl_elt&); | |
2982 | 99 }; |
100 | |
101 class | |
4219 | 102 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982 | 103 { |
104 public: | |
105 | |
4219 | 106 tree_decl_init_list (void) { } |
2982 | 107 |
4219 | 108 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982 | 109 |
110 ~tree_decl_init_list (void) | |
111 { | |
4219 | 112 while (! empty ()) |
2982 | 113 { |
4219 | 114 iterator p = begin (); |
115 delete *p; | |
116 erase (p); | |
2982 | 117 } |
118 } | |
119 | |
2989 | 120 void eval (tree_decl_elt::eval_fcn); |
2982 | 121 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
122 tree_decl_init_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
123 symbol_table::context_id context); |
5861 | 124 |
2982 | 125 void accept (tree_walker& tw); |
2988 | 126 |
127 private: | |
128 | |
129 // No copying! | |
130 | |
131 tree_decl_init_list (const tree_decl_init_list&); | |
132 | |
133 tree_decl_init_list& operator = (const tree_decl_init_list&); | |
2982 | 134 }; |
135 | |
136 // Base class for declaration commands -- global, static, etc. | |
137 | |
138 class | |
139 tree_decl_command : public tree_command | |
140 { | |
141 public: | |
142 | |
3523 | 143 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
7336 | 144 : tree_command (l, c), cmd_name (n), init_list (0) { } |
2982 | 145 |
3523 | 146 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982 | 147 int l = -1, int c = -1) |
7336 | 148 : tree_command (l, c), cmd_name (n), init_list (t) { } |
2982 | 149 |
150 ~tree_decl_command (void); | |
151 | |
152 tree_decl_init_list *initializer_list (void) { return init_list; } | |
153 | |
154 void accept (tree_walker& tw); | |
155 | |
3523 | 156 std::string name (void) { return cmd_name; } |
2982 | 157 |
158 protected: | |
159 | |
160 // The name of this command -- global, static, etc. | |
3523 | 161 std::string cmd_name; |
2982 | 162 |
163 // The list of variables or initializers in this declaration command. | |
164 tree_decl_init_list *init_list; | |
2988 | 165 |
166 private: | |
167 | |
168 // No copying! | |
169 | |
170 tree_decl_command (const tree_decl_command&); | |
171 | |
172 tree_decl_command& operator = (const tree_decl_command&); | |
2982 | 173 }; |
174 | |
175 // Global. | |
176 | |
177 class | |
178 tree_global_command : public tree_decl_command | |
179 { | |
180 public: | |
181 | |
182 tree_global_command (int l = -1, int c = -1) | |
183 : tree_decl_command ("global", l, c) { } | |
184 | |
185 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
186 : tree_decl_command ("global", t, l, c) { } | |
187 | |
188 ~tree_global_command (void) { } | |
189 | |
190 void eval (void); | |
2988 | 191 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
192 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
193 symbol_table::context_id context); |
5861 | 194 |
2988 | 195 private: |
196 | |
2989 | 197 static void do_init (tree_decl_elt& elt); |
198 | |
2988 | 199 // No copying! |
200 | |
201 tree_global_command (const tree_global_command&); | |
202 | |
203 tree_global_command& operator = (const tree_global_command&); | |
2982 | 204 }; |
205 | |
206 // Static. | |
207 | |
208 class | |
209 tree_static_command : public tree_decl_command | |
210 { | |
211 public: | |
212 | |
213 tree_static_command (int l = -1, int c = -1) | |
214 : tree_decl_command ("static", l, c) { } | |
215 | |
216 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
217 : tree_decl_command ("static", t, l, c) { } | |
218 | |
219 ~tree_static_command (void) { } | |
220 | |
221 void eval (void); | |
2988 | 222 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
223 tree_command *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
224 symbol_table::context_id context); |
5861 | 225 |
2988 | 226 private: |
227 | |
2989 | 228 static void do_init (tree_decl_elt& elt); |
229 | |
2988 | 230 // No copying! |
231 | |
232 tree_static_command (const tree_static_command&); | |
233 | |
234 tree_static_command& operator = (const tree_static_command&); | |
2982 | 235 }; |
236 | |
237 #endif | |
238 | |
239 /* | |
240 ;;; Local Variables: *** | |
241 ;;; mode: C++ *** | |
242 ;;; End: *** | |
243 */ |