Mercurial > hg > octave-nkf
annotate src/pt-decl.h @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 35cd375d4bb3 |
children | cd96d29c5efa |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 2000, 2002, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 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 | |
47 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) | |
48 : id (i), expr (e) { } | |
49 | |
50 ~tree_decl_elt (void); | |
51 | |
6215 | 52 bool eval (void); |
53 | |
54 bool is_defined (void) { return id ? id->is_defined () : false; } | |
55 | |
7336 | 56 bool is_variable (void) { return id ? id->is_variable () : false; } |
57 | |
6215 | 58 void mark_as_formal_parameter (void) |
59 { | |
60 if (id) | |
61 id->mark_as_formal_parameter (); | |
62 } | |
63 | |
64 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } | |
65 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
66 // Do not allow functions to return null values. |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
67 octave_value rvalue1 (int nargout = 1) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
68 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
69 return id ? id->rvalue1 (nargout).storable_value () : octave_value (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
70 } |
6215 | 71 |
72 octave_value_list rvalue (int nargout) | |
73 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
74 octave_value_list retval; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
75 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
76 if (nargout > 1) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
77 error ("invalid number of output arguments in declaration list"); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
78 else |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
79 retval = rvalue1 (nargout); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
80 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
81 return retval; |
6215 | 82 } |
83 | |
84 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } | |
2982 | 85 |
86 tree_identifier *ident (void) { return id; } | |
87 | |
88 tree_expression *expression (void) { return expr; } | |
89 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
90 tree_decl_elt *dup (symbol_table::scope_id scope, |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
91 symbol_table::context_id context) const; |
5861 | 92 |
2982 | 93 void accept (tree_walker& tw); |
94 | |
95 private: | |
96 | |
97 // An identifier to tag with the declared property. | |
98 tree_identifier *id; | |
99 | |
100 // An initializer expression (may be zero); | |
101 tree_expression *expr; | |
2988 | 102 |
103 // No copying! | |
104 | |
105 tree_decl_elt (const tree_decl_elt&); | |
106 | |
107 tree_decl_elt& operator = (const tree_decl_elt&); | |
2982 | 108 }; |
109 | |
110 class | |
4219 | 111 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982 | 112 { |
113 public: | |
114 | |
4219 | 115 tree_decl_init_list (void) { } |
2982 | 116 |
4219 | 117 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982 | 118 |
119 ~tree_decl_init_list (void) | |
120 { | |
4219 | 121 while (! empty ()) |
2982 | 122 { |
4219 | 123 iterator p = begin (); |
124 delete *p; | |
125 erase (p); | |
2982 | 126 } |
127 } | |
128 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
129 tree_decl_init_list *dup (symbol_table::scope_id scope, |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
130 symbol_table::context_id context) const; |
5861 | 131 |
2982 | 132 void accept (tree_walker& tw); |
2988 | 133 |
134 private: | |
135 | |
136 // No copying! | |
137 | |
138 tree_decl_init_list (const tree_decl_init_list&); | |
139 | |
140 tree_decl_init_list& operator = (const tree_decl_init_list&); | |
2982 | 141 }; |
142 | |
143 // Base class for declaration commands -- global, static, etc. | |
144 | |
145 class | |
146 tree_decl_command : public tree_command | |
147 { | |
148 public: | |
149 | |
3523 | 150 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
7336 | 151 : tree_command (l, c), cmd_name (n), init_list (0) { } |
2982 | 152 |
3523 | 153 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
2982 | 154 int l = -1, int c = -1) |
7336 | 155 : tree_command (l, c), cmd_name (n), init_list (t) { } |
2982 | 156 |
157 ~tree_decl_command (void); | |
158 | |
159 tree_decl_init_list *initializer_list (void) { return init_list; } | |
160 | |
3523 | 161 std::string name (void) { return cmd_name; } |
2982 | 162 |
163 protected: | |
164 | |
165 // The name of this command -- global, static, etc. | |
3523 | 166 std::string cmd_name; |
2982 | 167 |
168 // The list of variables or initializers in this declaration command. | |
169 tree_decl_init_list *init_list; | |
2988 | 170 |
171 private: | |
172 | |
173 // No copying! | |
174 | |
175 tree_decl_command (const tree_decl_command&); | |
176 | |
177 tree_decl_command& operator = (const tree_decl_command&); | |
2982 | 178 }; |
179 | |
180 // Global. | |
181 | |
182 class | |
183 tree_global_command : public tree_decl_command | |
184 { | |
185 public: | |
186 | |
187 tree_global_command (int l = -1, int c = -1) | |
188 : tree_decl_command ("global", l, c) { } | |
189 | |
190 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
191 : tree_decl_command ("global", t, l, c) { } | |
192 | |
193 ~tree_global_command (void) { } | |
194 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
195 tree_command *dup (symbol_table::scope_id scope, |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
196 symbol_table::context_id context) const; |
5861 | 197 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
198 void accept (tree_walker& tw); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
199 |
2988 | 200 private: |
201 | |
2989 | 202 static void do_init (tree_decl_elt& elt); |
203 | |
2988 | 204 // No copying! |
205 | |
206 tree_global_command (const tree_global_command&); | |
207 | |
208 tree_global_command& operator = (const tree_global_command&); | |
2982 | 209 }; |
210 | |
211 // Static. | |
212 | |
213 class | |
214 tree_static_command : public tree_decl_command | |
215 { | |
216 public: | |
217 | |
218 tree_static_command (int l = -1, int c = -1) | |
219 : tree_decl_command ("static", l, c) { } | |
220 | |
221 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
222 : tree_decl_command ("static", t, l, c) { } | |
223 | |
224 ~tree_static_command (void) { } | |
225 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
226 tree_command *dup (symbol_table::scope_id scope, |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
227 symbol_table::context_id context) const; |
5861 | 228 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
229 void accept (tree_walker& tw); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
230 |
2988 | 231 private: |
232 | |
2989 | 233 static void do_init (tree_decl_elt& elt); |
234 | |
2988 | 235 // No copying! |
236 | |
237 tree_static_command (const tree_static_command&); | |
238 | |
239 tree_static_command& operator = (const tree_static_command&); | |
2982 | 240 }; |
241 | |
242 #endif | |
243 | |
244 /* | |
245 ;;; Local Variables: *** | |
246 ;;; mode: C++ *** | |
247 ;;; End: *** | |
248 */ |