GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pt-select.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include "error.h"
28 #include "oct-obj.h"
29 #include "ov.h"
30 #include "pt-cmd.h"
31 #include "pt-exp.h"
32 #include "pt-select.h"
33 #include "pt-stmt.h"
34 #include "pt-walk.h"
35 #include "Cell.h"
36 #include "ov-typeinfo.h"
37 
38 // If clauses.
39 
41 {
42  delete expr;
43  delete list;
44  delete lead_comm;
45 }
46 
50 {
51  return new tree_if_clause (expr ? expr->dup (scope, context) : 0,
52  list ? list->dup (scope, context) : 0,
53  lead_comm ? lead_comm->dup () : 0);
54 }
55 
56 void
58 {
59  tw.visit_if_clause (*this);
60 }
61 
62 // List of if commands.
63 
67 {
69 
70  for (const_iterator p = begin (); p != end (); p++)
71  {
72  const tree_if_clause *elt = *p;
73 
74  new_icl->append (elt ? elt->dup (scope, context) : 0);
75  }
76 
77  return new_icl;
78 }
79 
80 void
82 {
83  tw.visit_if_command_list (*this);
84 }
85 
86 // If.
87 
89 {
90  delete list;
91  delete lead_comm;
92  delete trail_comm;
93 }
94 
98 {
99  return new tree_if_command (list ? list->dup (scope, context) : 0,
100  lead_comm ? lead_comm->dup () : 0,
101  trail_comm ? trail_comm->dup () : 0,
102  line (), column ());
103 }
104 
105 void
107 {
108  tw.visit_if_command (*this);
109 }
110 
111 // Switch cases.
112 
114 {
115  delete label;
116  delete list;
117  delete lead_comm;
118 }
119 
120 
121 bool
123 {
124  octave_value label_value = label->rvalue1 ();
125 
126  if (! error_state && label_value.is_defined () )
127  {
128  if (label_value.is_cell ())
129  {
130  Cell cell (label_value.cell_value ());
131 
132  for (octave_idx_type i = 0; i < cell.rows (); i++)
133  {
134  for (octave_idx_type j = 0; j < cell.columns (); j++)
135  {
136  bool match = val.is_equal (cell(i,j));
137 
138  if (error_state)
139  return false;
140  else if (match)
141  return true;
142  }
143  }
144  }
145  else
146  {
147  bool match = val.is_equal (label_value);
148 
149  if (error_state)
150  return false;
151  else
152  return match;
153  }
154  }
155 
156  return false;
157 }
158 
162 {
163  return new tree_switch_case (label ? label->dup (scope, context) : 0,
164  list ? list->dup (scope, context) : 0,
165  lead_comm ? lead_comm->dup () : 0);
166 }
167 
168 void
170 {
171  tw.visit_switch_case (*this);
172 }
173 
174 // List of switch cases.
175 
179 {
181 
182  for (const_iterator p = begin (); p != end (); p++)
183  {
184  const tree_switch_case *elt = *p;
185 
186  new_scl->append (elt ? elt->dup (scope, context) : 0);
187  }
188 
189  return new_scl;
190 }
191 
192 void
194 {
195  tw.visit_switch_case_list (*this);
196 }
197 
198 // Switch.
199 
201 {
202  delete expr;
203  delete list;
204  delete lead_comm;
205  delete trail_comm;
206 }
207 
208 tree_command *
211 {
212  return new tree_switch_command (expr ? expr->dup (scope, context) : 0,
213  list ? list->dup (scope, context) : 0,
214  lead_comm ? lead_comm->dup () : 0,
215  trail_comm ? trail_comm->dup () : 0,
216  line (), column ());
217 }
218 
219 void
221 {
222  tw.visit_switch_command (*this);
223 }