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