GNU Octave  4.2.1
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-2017 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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "error.h"
28 #include "ovl.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 bool
122 {
123  octave_value label_value = label->rvalue1 ();
124 
125  if (label_value.is_defined ())
126  {
127  if (label_value.is_cell ())
128  {
129  Cell cell (label_value.cell_value ());
130 
131  for (octave_idx_type i = 0; i < cell.rows (); i++)
132  {
133  for (octave_idx_type j = 0; j < cell.columns (); j++)
134  {
135  bool match = val.is_equal (cell(i,j));
136 
137  if (match)
138  return true;
139  }
140  }
141  }
142  else
143  return val.is_equal (label_value);
144  }
145 
146  return false;
147 }
148 
152 {
153  return new tree_switch_case (label ? label->dup (scope, context) : 0,
154  list ? list->dup (scope, context) : 0,
155  lead_comm ? lead_comm->dup () : 0);
156 }
157 
158 void
160 {
161  tw.visit_switch_case (*this);
162 }
163 
164 // List of switch cases.
165 
169 {
171 
172  for (const_iterator p = begin (); p != end (); p++)
173  {
174  const tree_switch_case *elt = *p;
175 
176  new_scl->append (elt ? elt->dup (scope, context) : 0);
177  }
178 
179  return new_scl;
180 }
181 
182 void
184 {
185  tw.visit_switch_case_list (*this);
186 }
187 
188 // Switch.
189 
191 {
192  delete expr;
193  delete list;
194  delete lead_comm;
195  delete trail_comm;
196 }
197 
198 tree_command *
201 {
202  return new tree_switch_command (expr ? expr->dup (scope, context) : 0,
203  list ? list->dup (scope, context) : 0,
204  lead_comm ? lead_comm->dup () : 0,
205  trail_comm ? trail_comm->dup () : 0,
206  line (), column ());
207 }
208 
209 void
211 {
212  tw.visit_switch_command (*this);
213 }
Definition: Cell.h:37
virtual void visit_if_clause(tree_if_clause &)=0
void accept(tree_walker &tw)
Definition: pt-select.cc:159
tree_switch_case_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:167
tree_command * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:96
bool label_matches(const octave_value &val)
Definition: pt-select.cc:121
void accept(tree_walker &tw)
Definition: pt-select.cc:106
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
tree_if_command_list(void)
Definition: pt-select.h:95
bool is_defined(void) const
Definition: ov.h:536
void accept(tree_walker &tw)
Definition: pt-select.cc:210
octave_comment_list * lead_comm
Definition: pt-select.h:154
virtual tree_expression * dup(symbol_table::scope_id, symbol_table::context_id context) const =0
bool is_cell(void) const
Definition: ov.h:545
tree_switch_case * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:150
octave_comment_list * trail_comm
Definition: pt-select.h:157
tree_switch_case_list * list
Definition: pt-select.h:289
tree_switch_command(int l=-1, int c=-1)
Definition: pt-select.h:258
Cell cell_value(void) const
Definition: ov.cc:1687
virtual void visit_if_command(tree_if_command &)=0
tree_if_command(int l=-1, int c=-1)
Definition: pt-select.h:128
tree_statement_list * list
Definition: pt-select.h:208
virtual void visit_switch_case_list(tree_switch_case_list &)=0
~tree_if_clause(void)
Definition: pt-select.cc:40
octave_comment_list * lead_comm
Definition: pt-select.h:211
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
virtual void visit_switch_case(tree_switch_case &)=0
tree_if_command_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:65
~tree_switch_command(void)
Definition: pt-select.cc:190
void accept(tree_walker &tw)
Definition: pt-select.cc:183
virtual void visit_switch_command(tree_switch_command &)=0
virtual int line(void) const
Definition: pt.h:49
tree_expression * label
Definition: pt-select.h:205
virtual octave_value rvalue1(int nargout=1)
Definition: pt-exp.cc:54
std::list< tree_if_clause * >::const_iterator const_iterator
Definition: base-list.h:41
tree_statement_list * list
Definition: pt-select.h:78
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
tree_expression * expr
Definition: pt-select.h:286
p
Definition: lu.cc:138
tree_if_clause(int l=-1, int c=-1)
Definition: pt-select.h:45
~tree_if_command(void)
Definition: pt-select.cc:88
void accept(tree_walker &tw)
Definition: pt-select.cc:81
virtual void visit_if_command_list(tree_if_command_list &)=0
octave_comment_list * trail_comm
Definition: pt-select.h:295
tree_expression * expr
Definition: pt-select.h:75
octave_comment_list * lead_comm
Definition: pt-select.h:81
void accept(tree_walker &tw)
Definition: pt-select.cc:57
tree_switch_case(int l=-1, int c=-1)
Definition: pt-select.h:173
~tree_switch_case(void)
Definition: pt-select.cc:113
void append(const elt_type &s)
Definition: base-list.h:110
tree_command * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:199
octave_comment_list * lead_comm
Definition: pt-select.h:292
octave_comment_list * dup(void) const
Definition: comment-list.cc:33
bool is_equal(const octave_value &) const
Definition: ov.cc:1645
tree_if_command_list * list
Definition: pt-select.h:151
virtual int column(void) const
Definition: pt.h:51
tree_if_clause * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-select.cc:48
tree_statement_list * dup(symbol_table::scope_id scope, symbol_table::context_id context) const
Definition: pt-stmt.cc:306