Mercurial > hg > octave-lyh
annotate libinterp/parse-tree/pt-decl.h @ 17509:5f884a545c06
Fix uminus op support with scalar type
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Thu, 26 Sep 2013 04:56:03 +0800 |
parents | 3f43e9d6d86e |
children |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2982 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2982 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2982 | 20 |
21 */ | |
22 | |
23 #if !defined (octave_tree_decl_h) | |
24 #define octave_tree_decl_h 1 | |
25 | |
26 class tree_expression; | |
27 class tree_identifier; | |
28 | |
29 class tree_walker; | |
30 | |
31 #include <string> | |
32 | |
4219 | 33 #include "base-list.h" |
6215 | 34 #include "oct-lvalue.h" |
2982 | 35 #include "pt-cmd.h" |
6215 | 36 #include "pt-id.h" |
7336 | 37 #include "symtab.h" |
2982 | 38 |
39 // List of expressions that make up a declaration statement. | |
40 | |
41 class | |
42 tree_decl_elt | |
43 { | |
44 public: | |
45 | |
46 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0) | |
47 : id (i), expr (e) { } | |
48 | |
49 ~tree_decl_elt (void); | |
50 | |
6215 | 51 bool eval (void); |
52 | |
53 bool is_defined (void) { return id ? id->is_defined () : false; } | |
54 | |
7336 | 55 bool is_variable (void) { return id ? id->is_variable () : false; } |
56 | |
6215 | 57 void mark_as_formal_parameter (void) |
58 { | |
59 if (id) | |
60 id->mark_as_formal_parameter (); | |
61 } | |
62 | |
63 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; } | |
64 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
65 // 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
|
66 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
|
67 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
68 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
|
69 } |
6215 | 70 |
71 octave_value_list rvalue (int nargout) | |
72 { | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
73 octave_value_list retval; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
74 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
75 if (nargout > 1) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
76 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
|
77 else |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
78 retval = rvalue1 (nargout); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
79 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
80 return retval; |
6215 | 81 } |
82 | |
83 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); } | |
2982 | 84 |
85 tree_identifier *ident (void) { return id; } | |
86 | |
15337
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
87 std::string name (void) { return id ? id->name () : ""; } |
3f43e9d6d86e
JIT compile anonymous functions
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
88 |
2982 | 89 tree_expression *expression (void) { return expr; } |
90 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
91 tree_decl_elt *dup (symbol_table::scope_id scope, |
10313 | 92 symbol_table::context_id context) const; |
5861 | 93 |
2982 | 94 void accept (tree_walker& tw); |
95 | |
96 private: | |
97 | |
98 // An identifier to tag with the declared property. | |
99 tree_identifier *id; | |
100 | |
101 // An initializer expression (may be zero); | |
102 tree_expression *expr; | |
2988 | 103 |
104 // No copying! | |
105 | |
106 tree_decl_elt (const tree_decl_elt&); | |
107 | |
108 tree_decl_elt& operator = (const tree_decl_elt&); | |
2982 | 109 }; |
110 | |
111 class | |
4219 | 112 tree_decl_init_list : public octave_base_list<tree_decl_elt *> |
2982 | 113 { |
114 public: | |
115 | |
4219 | 116 tree_decl_init_list (void) { } |
2982 | 117 |
4219 | 118 tree_decl_init_list (tree_decl_elt *t) { append (t); } |
2982 | 119 |
120 ~tree_decl_init_list (void) | |
121 { | |
4219 | 122 while (! empty ()) |
10313 | 123 { |
124 iterator p = begin (); | |
125 delete *p; | |
126 erase (p); | |
127 } | |
2982 | 128 } |
129 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
130 tree_decl_init_list *dup (symbol_table::scope_id scope, |
10313 | 131 symbol_table::context_id context) const; |
5861 | 132 |
2982 | 133 void accept (tree_walker& tw); |
2988 | 134 |
135 private: | |
136 | |
137 // No copying! | |
138 | |
139 tree_decl_init_list (const tree_decl_init_list&); | |
140 | |
141 tree_decl_init_list& operator = (const tree_decl_init_list&); | |
2982 | 142 }; |
143 | |
144 // Base class for declaration commands -- global, static, etc. | |
145 | |
146 class | |
147 tree_decl_command : public tree_command | |
148 { | |
149 public: | |
150 | |
3523 | 151 tree_decl_command (const std::string& n, int l = -1, int c = -1) |
7336 | 152 : tree_command (l, c), cmd_name (n), init_list (0) { } |
2982 | 153 |
3523 | 154 tree_decl_command (const std::string& n, tree_decl_init_list *t, |
10313 | 155 int l = -1, int c = -1) |
7336 | 156 : tree_command (l, c), cmd_name (n), init_list (t) { } |
2982 | 157 |
158 ~tree_decl_command (void); | |
159 | |
160 tree_decl_init_list *initializer_list (void) { return init_list; } | |
161 | |
3523 | 162 std::string name (void) { return cmd_name; } |
2982 | 163 |
164 protected: | |
165 | |
166 // The name of this command -- global, static, etc. | |
3523 | 167 std::string cmd_name; |
2982 | 168 |
169 // The list of variables or initializers in this declaration command. | |
170 tree_decl_init_list *init_list; | |
2988 | 171 |
172 private: | |
173 | |
174 // No copying! | |
175 | |
176 tree_decl_command (const tree_decl_command&); | |
177 | |
178 tree_decl_command& operator = (const tree_decl_command&); | |
2982 | 179 }; |
180 | |
181 // Global. | |
182 | |
183 class | |
184 tree_global_command : public tree_decl_command | |
185 { | |
186 public: | |
187 | |
188 tree_global_command (int l = -1, int c = -1) | |
189 : tree_decl_command ("global", l, c) { } | |
190 | |
191 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1) | |
192 : tree_decl_command ("global", t, l, c) { } | |
193 | |
194 ~tree_global_command (void) { } | |
195 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
196 tree_command *dup (symbol_table::scope_id scope, |
10313 | 197 symbol_table::context_id context) const; |
5861 | 198 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
199 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
|
200 |
2988 | 201 private: |
202 | |
2989 | 203 static void do_init (tree_decl_elt& elt); |
204 | |
2988 | 205 // No copying! |
206 | |
207 tree_global_command (const tree_global_command&); | |
208 | |
209 tree_global_command& operator = (const tree_global_command&); | |
2982 | 210 }; |
211 | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
212 // Persistent. |
2982 | 213 |
214 class | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
215 tree_persistent_command : public tree_decl_command |
2982 | 216 { |
217 public: | |
218 | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
219 tree_persistent_command (int l = -1, int c = -1) |
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
220 : tree_decl_command ("persistent", l, c) { } |
2982 | 221 |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
222 tree_persistent_command (tree_decl_init_list *t, int l = -1, int c = -1) |
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
223 : tree_decl_command ("persistent", t, l, c) { } |
2982 | 224 |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
225 ~tree_persistent_command (void) { } |
2982 | 226 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
227 tree_command *dup (symbol_table::scope_id scope, |
10313 | 228 symbol_table::context_id context) const; |
5861 | 229 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8523
diff
changeset
|
230 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
|
231 |
2988 | 232 private: |
233 | |
2989 | 234 static void do_init (tree_decl_elt& elt); |
235 | |
2988 | 236 // No copying! |
237 | |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
238 tree_persistent_command (const tree_persistent_command&); |
2988 | 239 |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
240 tree_persistent_command& operator = (const tree_persistent_command&); |
2982 | 241 }; |
242 | |
243 #endif |