pt-select.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_select_h)
00024 #define octave_tree_select_h 1
00025 
00026 class expression;
00027 class tree_statement_list;
00028 
00029 class tree_walker;
00030 
00031 #include "base-list.h"
00032 #include "comment-list.h"
00033 #include "pt-cmd.h"
00034 #include "symtab.h"
00035 
00036 // If.
00037 
00038 class
00039 tree_if_clause : public tree
00040 {
00041 public:
00042 
00043   tree_if_clause (int l = -1, int c = -1)
00044     : tree (l, c), expr (0), list (0), lead_comm (0) { }
00045 
00046   tree_if_clause (tree_statement_list *sl, octave_comment_list *lc = 0,
00047                   int l = -1, int c = -1)
00048     : tree (l, c), expr (0), list (sl), lead_comm (lc) { }
00049 
00050   tree_if_clause (tree_expression *e, tree_statement_list *sl,
00051                   octave_comment_list *lc = 0,
00052                   int l = -1, int c = -1)
00053     : tree (l, c), expr (e), list (sl), lead_comm (lc) { }
00054 
00055   ~tree_if_clause (void);
00056 
00057   bool is_else_clause (void) { return ! expr; }
00058 
00059   tree_expression *condition (void) { return expr; }
00060 
00061   tree_statement_list *commands (void) { return list; }
00062 
00063   octave_comment_list *leading_comment (void) { return lead_comm; }
00064 
00065   tree_if_clause *dup (symbol_table::scope_id scope,
00066                        symbol_table::context_id context) const;
00067 
00068   void accept (tree_walker& tw);
00069 
00070 private:
00071 
00072   // The condition to test.
00073   tree_expression *expr;
00074 
00075   // The list of statements to evaluate if expr is true.
00076   tree_statement_list *list;
00077 
00078   // Comment preceding ELSE or ELSEIF token.
00079   octave_comment_list *lead_comm;
00080 
00081   // No copying!
00082 
00083   tree_if_clause (const tree_if_clause&);
00084 
00085   tree_if_clause& operator = (const tree_if_clause&);
00086 };
00087 
00088 class
00089 tree_if_command_list : public octave_base_list<tree_if_clause *>
00090 {
00091 public:
00092 
00093   tree_if_command_list (void) { }
00094 
00095   tree_if_command_list (tree_if_clause *t) { append (t); }
00096 
00097   ~tree_if_command_list (void)
00098     {
00099       while (! empty ())
00100         {
00101           iterator p = begin ();
00102           delete *p;
00103           erase (p);
00104         }
00105     }
00106 
00107   tree_if_command_list *dup (symbol_table::scope_id scope,
00108                              symbol_table::context_id context) const;
00109 
00110   void accept (tree_walker& tw);
00111 
00112 private:
00113 
00114   // No copying!
00115 
00116   tree_if_command_list (const tree_if_command_list&);
00117 
00118   tree_if_command_list& operator = (const tree_if_command_list&);
00119 };
00120 
00121 class
00122 tree_if_command : public tree_command
00123 {
00124 public:
00125 
00126   tree_if_command (int l = -1, int c = -1)
00127     : tree_command (l, c), list (0), lead_comm (0), trail_comm (0) { }
00128 
00129   tree_if_command (tree_if_command_list *lst, octave_comment_list *lc,
00130                    octave_comment_list *tc, int l = -1, int c = -1)
00131     : tree_command (l, c), list (lst), lead_comm (lc), trail_comm (tc) { }
00132 
00133   ~tree_if_command (void);
00134 
00135   tree_if_command_list *cmd_list (void) { return list; }
00136 
00137   octave_comment_list *leading_comment (void) { return lead_comm; }
00138 
00139   octave_comment_list *trailing_comment (void) { return trail_comm; }
00140 
00141   tree_command *dup (symbol_table::scope_id scope,
00142                      symbol_table::context_id context) const;
00143 
00144   void accept (tree_walker& tw);
00145 
00146 private:
00147 
00148   // List of if commands (if, elseif, elseif, ... else, endif)
00149   tree_if_command_list *list;
00150 
00151   // Comment preceding IF token.
00152   octave_comment_list *lead_comm;
00153 
00154   // Comment preceding ENDIF token.
00155   octave_comment_list *trail_comm;
00156 
00157   // No copying!
00158 
00159   tree_if_command (const tree_if_command&);
00160 
00161   tree_if_command& operator = (const tree_if_command&);
00162 };
00163 
00164 // Switch.
00165 
00166 class
00167 tree_switch_case : public tree
00168 {
00169 public:
00170 
00171   tree_switch_case (int l = -1, int c = -1)
00172     : tree (l, c), label (0), list (0), lead_comm (0) { }
00173 
00174   tree_switch_case (tree_statement_list *sl, octave_comment_list *lc = 0,
00175                     int l = -1, int c = -1)
00176     : tree (l, c), label (0), list (sl), lead_comm (lc) { }
00177 
00178   tree_switch_case (tree_expression *e, tree_statement_list *sl,
00179                     octave_comment_list *lc = 0,
00180                     int l = -1, int c = -1)
00181     : tree (l, c), label (e), list (sl), lead_comm (lc) { }
00182 
00183   ~tree_switch_case (void);
00184 
00185   bool is_default_case (void) { return ! label; }
00186 
00187   bool label_matches (const octave_value& val);
00188 
00189   tree_expression *case_label (void) { return label; }
00190 
00191   tree_statement_list *commands (void) { return list; }
00192 
00193   octave_comment_list *leading_comment (void) { return lead_comm; }
00194 
00195   tree_switch_case *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   // The case label.
00203   tree_expression *label;
00204 
00205   // The list of statements to evaluate if the label matches.
00206   tree_statement_list *list;
00207 
00208   // Comment preceding CASE or OTHERWISE token.
00209   octave_comment_list *lead_comm;
00210 
00211   // No copying!
00212 
00213   tree_switch_case (const tree_switch_case&);
00214 
00215   tree_switch_case& operator = (const tree_switch_case&);
00216 };
00217 
00218 class
00219 tree_switch_case_list : public octave_base_list<tree_switch_case *>
00220 {
00221 public:
00222 
00223   tree_switch_case_list (void) { }
00224 
00225   tree_switch_case_list (tree_switch_case *t) { append (t); }
00226 
00227   ~tree_switch_case_list (void)
00228     {
00229       while (! empty ())
00230         {
00231           iterator p = begin ();
00232           delete *p;
00233           erase (p);
00234         }
00235     }
00236 
00237   tree_switch_case_list *dup (symbol_table::scope_id scope,
00238                               symbol_table::context_id context) const;
00239 
00240   void accept (tree_walker& tw);
00241 
00242 private:
00243 
00244   // No copying!
00245 
00246   tree_switch_case_list (const tree_switch_case_list&);
00247 
00248   tree_switch_case_list& operator = (const tree_switch_case_list&);
00249 };
00250 
00251 class
00252 tree_switch_command : public tree_command
00253 {
00254 public:
00255 
00256   tree_switch_command (int l = -1, int c = -1)
00257     : tree_command (l, c), expr (0), list (0), lead_comm (0),
00258       trail_comm (0) { }
00259 
00260   tree_switch_command (tree_expression *e, tree_switch_case_list *lst,
00261                        octave_comment_list *lc, octave_comment_list *tc,
00262                        int l = -1, int c = -1)
00263     : tree_command (l, c), expr (e), list (lst), lead_comm (lc),
00264       trail_comm (tc) { }
00265 
00266   ~tree_switch_command (void);
00267 
00268   tree_expression *switch_value (void) { return expr; }
00269 
00270   tree_switch_case_list *case_list (void) { return list; }
00271 
00272   octave_comment_list *leading_comment (void) { return lead_comm; }
00273 
00274   octave_comment_list *trailing_comment (void) { return trail_comm; }
00275 
00276   tree_command *dup (symbol_table::scope_id scope,
00277                      symbol_table::context_id context) const;
00278 
00279   void accept (tree_walker& tw);
00280 
00281 private:
00282 
00283   // Value on which to switch.
00284   tree_expression *expr;
00285 
00286   // List of cases (case 1, case 2, ..., default)
00287   tree_switch_case_list *list;
00288 
00289   // Comment preceding SWITCH token.
00290   octave_comment_list *lead_comm;
00291 
00292   // Comment preceding ENDSWITCH token.
00293   octave_comment_list *trail_comm;
00294 
00295   // No copying!
00296 
00297   tree_switch_command (const tree_switch_command&);
00298 
00299   tree_switch_command& operator = (const tree_switch_command&);
00300 };
00301 
00302 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines