00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_tree_decl_h)
00025 #define octave_tree_decl_h 1
00026
00027 class tree_expression;
00028 class tree_identifier;
00029
00030 class tree_walker;
00031
00032 #include <string>
00033
00034 #include "base-list.h"
00035 #include "oct-lvalue.h"
00036 #include "pt-cmd.h"
00037 #include "pt-id.h"
00038 #include "symtab.h"
00039
00040
00041
00042 class
00043 tree_decl_elt
00044 {
00045 public:
00046
00047 tree_decl_elt (tree_identifier *i = 0, tree_expression *e = 0)
00048 : id (i), expr (e) { }
00049
00050 ~tree_decl_elt (void);
00051
00052 bool eval (void);
00053
00054 bool is_defined (void) { return id ? id->is_defined () : false; }
00055
00056 bool is_variable (void) { return id ? id->is_variable () : false; }
00057
00058 void mark_as_formal_parameter (void)
00059 {
00060 if (id)
00061 id->mark_as_formal_parameter ();
00062 }
00063
00064 bool lvalue_ok (void) { return id ? id->lvalue_ok () : false; }
00065
00066
00067 octave_value rvalue1 (int nargout = 1)
00068 {
00069 return id ? id->rvalue1 (nargout).storable_value () : octave_value ();
00070 }
00071
00072 octave_value_list rvalue (int nargout)
00073 {
00074 octave_value_list retval;
00075
00076 if (nargout > 1)
00077 error ("invalid number of output arguments in declaration list");
00078 else
00079 retval = rvalue1 (nargout);
00080
00081 return retval;
00082 }
00083
00084 octave_lvalue lvalue (void) { return id ? id->lvalue () : octave_lvalue (); }
00085
00086 tree_identifier *ident (void) { return id; }
00087
00088 tree_expression *expression (void) { return expr; }
00089
00090 tree_decl_elt *dup (symbol_table::scope_id scope,
00091 symbol_table::context_id context) const;
00092
00093 void accept (tree_walker& tw);
00094
00095 private:
00096
00097
00098 tree_identifier *id;
00099
00100
00101 tree_expression *expr;
00102
00103
00104
00105 tree_decl_elt (const tree_decl_elt&);
00106
00107 tree_decl_elt& operator = (const tree_decl_elt&);
00108 };
00109
00110 class
00111 tree_decl_init_list : public octave_base_list<tree_decl_elt *>
00112 {
00113 public:
00114
00115 tree_decl_init_list (void) { }
00116
00117 tree_decl_init_list (tree_decl_elt *t) { append (t); }
00118
00119 ~tree_decl_init_list (void)
00120 {
00121 while (! empty ())
00122 {
00123 iterator p = begin ();
00124 delete *p;
00125 erase (p);
00126 }
00127 }
00128
00129 tree_decl_init_list *dup (symbol_table::scope_id scope,
00130 symbol_table::context_id context) const;
00131
00132 void accept (tree_walker& tw);
00133
00134 private:
00135
00136
00137
00138 tree_decl_init_list (const tree_decl_init_list&);
00139
00140 tree_decl_init_list& operator = (const tree_decl_init_list&);
00141 };
00142
00143
00144
00145 class
00146 tree_decl_command : public tree_command
00147 {
00148 public:
00149
00150 tree_decl_command (const std::string& n, int l = -1, int c = -1)
00151 : tree_command (l, c), cmd_name (n), init_list (0) { }
00152
00153 tree_decl_command (const std::string& n, tree_decl_init_list *t,
00154 int l = -1, int c = -1)
00155 : tree_command (l, c), cmd_name (n), init_list (t) { }
00156
00157 ~tree_decl_command (void);
00158
00159 tree_decl_init_list *initializer_list (void) { return init_list; }
00160
00161 std::string name (void) { return cmd_name; }
00162
00163 protected:
00164
00165
00166 std::string cmd_name;
00167
00168
00169 tree_decl_init_list *init_list;
00170
00171 private:
00172
00173
00174
00175 tree_decl_command (const tree_decl_command&);
00176
00177 tree_decl_command& operator = (const tree_decl_command&);
00178 };
00179
00180
00181
00182 class
00183 tree_global_command : public tree_decl_command
00184 {
00185 public:
00186
00187 tree_global_command (int l = -1, int c = -1)
00188 : tree_decl_command ("global", l, c) { }
00189
00190 tree_global_command (tree_decl_init_list *t, int l = -1, int c = -1)
00191 : tree_decl_command ("global", t, l, c) { }
00192
00193 ~tree_global_command (void) { }
00194
00195 tree_command *dup (symbol_table::scope_id scope,
00196 symbol_table::context_id context) const;
00197
00198 void accept (tree_walker& tw);
00199
00200 private:
00201
00202 static void do_init (tree_decl_elt& elt);
00203
00204
00205
00206 tree_global_command (const tree_global_command&);
00207
00208 tree_global_command& operator = (const tree_global_command&);
00209 };
00210
00211
00212
00213 class
00214 tree_static_command : public tree_decl_command
00215 {
00216 public:
00217
00218 tree_static_command (int l = -1, int c = -1)
00219 : tree_decl_command ("static", l, c) { }
00220
00221 tree_static_command (tree_decl_init_list *t, int l = -1, int c = -1)
00222 : tree_decl_command ("static", t, l, c) { }
00223
00224 ~tree_static_command (void) { }
00225
00226 tree_command *dup (symbol_table::scope_id scope,
00227 symbol_table::context_id context) const;
00228
00229 void accept (tree_walker& tw);
00230
00231 private:
00232
00233 static void do_init (tree_decl_elt& elt);
00234
00235
00236
00237 tree_static_command (const tree_static_command&);
00238
00239 tree_static_command& operator = (const tree_static_command&);
00240 };
00241
00242 #endif
00243
00244
00245
00246
00247
00248