pt-select.cc

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 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include "error.h"
00028 #include "oct-obj.h"
00029 #include "ov.h"
00030 #include "pt-cmd.h"
00031 #include "pt-exp.h"
00032 #include "pt-select.h"
00033 #include "pt-stmt.h"
00034 #include "pt-walk.h"
00035 #include "Cell.h"
00036 #include "ov-typeinfo.h"
00037 
00038 // If clauses.
00039 
00040 tree_if_clause::~tree_if_clause (void)
00041 {
00042   delete expr;
00043   delete list;
00044   delete lead_comm;
00045 }
00046 
00047 tree_if_clause *
00048 tree_if_clause::dup (symbol_table::scope_id scope,
00049                      symbol_table::context_id context) const
00050 {
00051   return new tree_if_clause (expr ? expr->dup (scope, context) : 0,
00052                              list ? list->dup (scope, context) : 0,
00053                              lead_comm ? lead_comm->dup () : 0);
00054 }
00055 
00056 void
00057 tree_if_clause::accept (tree_walker& tw)
00058 {
00059   tw.visit_if_clause (*this);
00060 }
00061 
00062 // List of if commands.
00063 
00064 tree_if_command_list *
00065 tree_if_command_list::dup (symbol_table::scope_id scope,
00066                            symbol_table::context_id context) const
00067 {
00068   tree_if_command_list *new_icl = new tree_if_command_list ();
00069 
00070   for (const_iterator p = begin (); p != end (); p++)
00071     {
00072       const tree_if_clause *elt = *p;
00073 
00074       new_icl->append (elt ? elt->dup (scope, context) : 0);
00075     }
00076 
00077   return new_icl;
00078 }
00079 
00080 void
00081 tree_if_command_list::accept (tree_walker& tw)
00082 {
00083   tw.visit_if_command_list (*this);
00084 }
00085 
00086 // If.
00087 
00088 tree_if_command::~tree_if_command (void)
00089 {
00090   delete list;
00091   delete lead_comm;
00092   delete trail_comm;
00093 }
00094 
00095 tree_command *
00096 tree_if_command::dup (symbol_table::scope_id scope,
00097                       symbol_table::context_id context) const
00098 {
00099   return new tree_if_command (list ? list->dup (scope, context) : 0,
00100                               lead_comm ? lead_comm->dup () : 0,
00101                               trail_comm ? trail_comm->dup () : 0,
00102                               line (), column ());
00103 }
00104 
00105 void
00106 tree_if_command::accept (tree_walker& tw)
00107 {
00108   tw.visit_if_command (*this);
00109 }
00110 
00111 // Switch cases.
00112 
00113 tree_switch_case::~tree_switch_case (void)
00114 {
00115   delete label;
00116   delete list;
00117   delete lead_comm;
00118 }
00119 
00120 
00121 bool
00122 tree_switch_case::label_matches (const octave_value& val)
00123 {
00124   octave_value label_value = label->rvalue1 ();
00125 
00126   if (! error_state && label_value.is_defined() )
00127     {
00128       if (label_value.is_cell ())
00129         {
00130           Cell cell (label_value.cell_value ());
00131 
00132           for (octave_idx_type i = 0; i < cell.rows (); i++)
00133             {
00134               for (octave_idx_type j = 0; j < cell.columns (); j++)
00135                 {
00136                   bool match = val.is_equal (cell(i,j));
00137 
00138                   if (error_state)
00139                     return false;
00140                   else if (match)
00141                     return true;
00142                 }
00143             }
00144         }
00145       else
00146         {
00147           bool match = val.is_equal (label_value);
00148 
00149           if (error_state)
00150             return false;
00151           else
00152             return match;
00153         }
00154     }
00155 
00156   return false;
00157 }
00158 
00159 tree_switch_case *
00160 tree_switch_case::dup (symbol_table::scope_id scope,
00161                        symbol_table::context_id context) const
00162 {
00163   return new tree_switch_case (label ? label->dup (scope, context) : 0,
00164                                list ? list->dup (scope, context) : 0,
00165                                lead_comm ? lead_comm->dup () : 0);
00166 }
00167 
00168 void
00169 tree_switch_case::accept (tree_walker& tw)
00170 {
00171   tw.visit_switch_case (*this);
00172 }
00173 
00174 // List of switch cases.
00175 
00176 tree_switch_case_list *
00177 tree_switch_case_list::dup (symbol_table::scope_id scope,
00178                             symbol_table::context_id context) const
00179 {
00180   tree_switch_case_list *new_scl = new tree_switch_case_list ();
00181 
00182   for (const_iterator p = begin (); p != end (); p++)
00183     {
00184       const tree_switch_case *elt = *p;
00185 
00186       new_scl->append (elt ? elt->dup (scope, context) : 0);
00187     }
00188 
00189   return new_scl;
00190 }
00191 
00192 void
00193 tree_switch_case_list::accept (tree_walker& tw)
00194 {
00195   tw.visit_switch_case_list (*this);
00196 }
00197 
00198 // Switch.
00199 
00200 tree_switch_command::~tree_switch_command (void)
00201 {
00202   delete expr;
00203   delete list;
00204   delete lead_comm;
00205   delete trail_comm;
00206 }
00207 
00208 tree_command *
00209 tree_switch_command::dup (symbol_table::scope_id scope,
00210                           symbol_table::context_id context) const
00211 {
00212   return new tree_switch_command (expr ? expr->dup (scope, context) : 0,
00213                                   list ? list->dup (scope, context) : 0,
00214                                   lead_comm ? lead_comm->dup () : 0,
00215                                   trail_comm ? trail_comm->dup () : 0,
00216                                   line (), column ());
00217 }
00218 
00219 void
00220 tree_switch_command::accept (tree_walker& tw)
00221 {
00222   tw.visit_switch_command (*this);
00223 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines