pt-loop.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_tree_loop_h)
00024 #define octave_tree_loop_h 1
00025 
00026 class octave_value;
00027 class octave_lvalue;
00028 
00029 class tree_argument_list;
00030 class tree_expression;
00031 class tree_statement_list;
00032 
00033 class tree_walker;
00034 
00035 #include "comment-list.h"
00036 #include "pt-cmd.h"
00037 #include "symtab.h"
00038 
00039 // While.
00040 
00041 class
00042 tree_while_command : public tree_command
00043 {
00044 public:
00045 
00046   tree_while_command (int l = -1, int c = -1)
00047     : tree_command (l, c), expr (0), list (0), lead_comm (0),
00048       trail_comm (0) { }
00049 
00050   tree_while_command (tree_expression *e,
00051                       octave_comment_list *lc = 0,
00052                       octave_comment_list *tc = 0,
00053                       int l = -1, int c = -1)
00054     : tree_command (l, c), expr (e), list (0), lead_comm (lc),
00055       trail_comm (tc) { }
00056 
00057   tree_while_command (tree_expression *e, tree_statement_list *lst,
00058                       octave_comment_list *lc = 0,
00059                       octave_comment_list *tc = 0,
00060                       int l = -1, int c = -1)
00061     : tree_command (l, c), expr (e), list (lst), lead_comm (lc),
00062       trail_comm (tc) { }
00063 
00064   ~tree_while_command (void);
00065 
00066   tree_expression *condition (void) { return expr; }
00067 
00068   tree_statement_list *body (void) { return list; }
00069 
00070   octave_comment_list *leading_comment (void) { return lead_comm; }
00071 
00072   octave_comment_list *trailing_comment (void) { return trail_comm; }
00073 
00074   tree_command *dup (symbol_table::scope_id scope,
00075                      symbol_table::context_id context) const;
00076 
00077   void accept (tree_walker& tw);
00078 
00079 protected:
00080 
00081   // Expression to test.
00082   tree_expression *expr;
00083 
00084   // List of commands to execute.
00085   tree_statement_list *list;
00086 
00087   // Comment preceding WHILE token.
00088   octave_comment_list *lead_comm;
00089 
00090   // Comment preceding ENDWHILE token.
00091   octave_comment_list *trail_comm;
00092 
00093 private:
00094 
00095   // No copying!
00096 
00097   tree_while_command (const tree_while_command&);
00098 
00099   tree_while_command& operator = (const tree_while_command&);
00100 };
00101 
00102 // Do-Until.
00103 
00104 class
00105 tree_do_until_command : public tree_while_command
00106 {
00107 public:
00108 
00109   tree_do_until_command (int l = -1, int c = -1)
00110     : tree_while_command (l, c) { }
00111 
00112   tree_do_until_command (tree_expression *e,
00113                          octave_comment_list *lc = 0,
00114                          octave_comment_list *tc = 0,
00115                          int l = -1, int c = -1)
00116     : tree_while_command (e, lc, tc, l, c) { }
00117 
00118   tree_do_until_command (tree_expression *e, tree_statement_list *lst,
00119                          octave_comment_list *lc = 0,
00120                          octave_comment_list *tc = 0,
00121                          int l = -1, int c = -1)
00122     : tree_while_command (e, lst, lc, tc, l, c) { }
00123 
00124   ~tree_do_until_command (void) { }
00125 
00126   tree_command *dup (symbol_table::scope_id scope,
00127                      symbol_table::context_id context) const;
00128 
00129   void accept (tree_walker& tw);
00130 
00131 private:
00132 
00133   // No copying!
00134 
00135   tree_do_until_command (const tree_do_until_command&);
00136 
00137   tree_do_until_command& operator = (const tree_do_until_command&);
00138 };
00139 
00140 // For.
00141 
00142 class
00143 tree_simple_for_command : public tree_command
00144 {
00145 public:
00146 
00147   tree_simple_for_command (int l = -1, int c = -1)
00148     : tree_command (l, c), parallel (false), lhs (0), expr (0),
00149       maxproc (0), list (0), lead_comm (0), trail_comm (0) { }
00150 
00151   tree_simple_for_command (bool parallel_arg, tree_expression *le,
00152                            tree_expression *re,
00153                            tree_expression *maxproc_arg,
00154                            tree_statement_list *lst,
00155                            octave_comment_list *lc = 0,
00156                            octave_comment_list *tc = 0,
00157                            int l = -1, int c = -1)
00158     : tree_command (l, c), parallel (parallel_arg), lhs (le),
00159       expr (re), maxproc (maxproc_arg), list (lst),
00160       lead_comm (lc), trail_comm (tc) { }
00161 
00162   ~tree_simple_for_command (void);
00163 
00164   bool in_parallel (void) { return parallel; }
00165 
00166   tree_expression *left_hand_side (void) { return lhs; }
00167 
00168   tree_expression *control_expr (void) { return expr; }
00169 
00170   tree_expression *maxproc_expr (void) { return maxproc; }
00171 
00172   tree_statement_list *body (void) { return list; }
00173 
00174   octave_comment_list *leading_comment (void) { return lead_comm; }
00175 
00176   octave_comment_list *trailing_comment (void) { return trail_comm; }
00177 
00178   tree_command *dup (symbol_table::scope_id scope,
00179                      symbol_table::context_id context) const;
00180 
00181   void accept (tree_walker& tw);
00182 
00183 private:
00184 
00185   // TRUE means operate in parallel (subject to the value of the
00186   // maxproc expression).
00187   bool parallel;
00188 
00189   // Expression to modify.
00190   tree_expression *lhs;
00191 
00192   // Expression to evaluate.
00193   tree_expression *expr;
00194 
00195   // Expression to tell how many processors should be used (only valid
00196   // if parallel is TRUE).
00197   tree_expression *maxproc;
00198 
00199   // List of commands to execute.
00200   tree_statement_list *list;
00201 
00202   // Comment preceding FOR token.
00203   octave_comment_list *lead_comm;
00204 
00205   // Comment preceding ENDFOR token.
00206   octave_comment_list *trail_comm;
00207 
00208   // No copying!
00209 
00210   tree_simple_for_command (const tree_simple_for_command&);
00211 
00212   tree_simple_for_command& operator = (const tree_simple_for_command&);
00213 };
00214 
00215 class
00216 tree_complex_for_command : public tree_command
00217 {
00218 public:
00219 
00220   tree_complex_for_command (int l = -1, int c = -1)
00221     : tree_command (l, c), lhs (0), expr (0), list (0), lead_comm (0),
00222       trail_comm (0) { }
00223 
00224   tree_complex_for_command (tree_argument_list *le, tree_expression *re,
00225                             tree_statement_list *lst,
00226                             octave_comment_list *lc = 0,
00227                             octave_comment_list *tc = 0,
00228                             int l = -1, int c = -1)
00229     : tree_command (l, c), lhs (le), expr (re), list (lst),
00230       lead_comm (lc), trail_comm (tc) { }
00231 
00232   ~tree_complex_for_command (void);
00233 
00234   tree_argument_list *left_hand_side (void) { return lhs; }
00235 
00236   tree_expression *control_expr (void) { return expr; }
00237 
00238   tree_statement_list *body (void) { return list; }
00239 
00240   octave_comment_list *leading_comment (void) { return lead_comm; }
00241 
00242   octave_comment_list *trailing_comment (void) { return trail_comm; }
00243 
00244   tree_command *dup (symbol_table::scope_id scope,
00245                      symbol_table::context_id context) const;
00246 
00247   void accept (tree_walker& tw);
00248 
00249 private:
00250 
00251   // Expression to modify.
00252   tree_argument_list *lhs;
00253 
00254   // Expression to evaluate.
00255   tree_expression *expr;
00256 
00257   // List of commands to execute.
00258   tree_statement_list *list;
00259 
00260   // Comment preceding FOR token.
00261   octave_comment_list *lead_comm;
00262 
00263   // Comment preceding ENDFOR token.
00264   octave_comment_list *trail_comm;
00265 
00266   // No copying!
00267 
00268   tree_complex_for_command (const tree_complex_for_command&);
00269 
00270   tree_complex_for_command& operator = (const tree_complex_for_command&);
00271 };
00272 
00273 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines