GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libinterp
parse-tree
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
40
tree_if_clause::~tree_if_clause
(
void
)
41
{
42
delete
expr
;
43
delete
list
;
44
delete
lead_comm
;
45
}
46
47
tree_if_clause
*
48
tree_if_clause::dup
(
symbol_table::scope_id
scope,
49
symbol_table::context_id
context
)
const
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
57
tree_if_clause::accept
(
tree_walker
& tw)
58
{
59
tw.
visit_if_clause
(*
this
);
60
}
61
62
// List of if commands.
63
64
tree_if_command_list
*
65
tree_if_command_list::dup
(
symbol_table::scope_id
scope,
66
symbol_table::context_id
context
)
const
67
{
68
tree_if_command_list
*new_icl =
new
tree_if_command_list
();
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
81
tree_if_command_list::accept
(
tree_walker
& tw)
82
{
83
tw.
visit_if_command_list
(*
this
);
84
}
85
86
// If.
87
88
tree_if_command::~tree_if_command
(
void
)
89
{
90
delete
list
;
91
delete
lead_comm
;
92
delete
trail_comm
;
93
}
94
95
tree_command
*
96
tree_if_command::dup
(
symbol_table::scope_id
scope,
97
symbol_table::context_id
context
)
const
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
106
tree_if_command::accept
(
tree_walker
& tw)
107
{
108
tw.
visit_if_command
(*
this
);
109
}
110
111
// Switch cases.
112
113
tree_switch_case::~tree_switch_case
(
void
)
114
{
115
delete
label
;
116
delete
list
;
117
delete
lead_comm
;
118
}
119
120
121
bool
122
tree_switch_case::label_matches
(
const
octave_value
& val)
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
159
tree_switch_case
*
160
tree_switch_case::dup
(
symbol_table::scope_id
scope,
161
symbol_table::context_id
context
)
const
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
169
tree_switch_case::accept
(
tree_walker
& tw)
170
{
171
tw.
visit_switch_case
(*
this
);
172
}
173
174
// List of switch cases.
175
176
tree_switch_case_list
*
177
tree_switch_case_list::dup
(
symbol_table::scope_id
scope,
178
symbol_table::context_id
context
)
const
179
{
180
tree_switch_case_list
*new_scl =
new
tree_switch_case_list
();
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
193
tree_switch_case_list::accept
(
tree_walker
& tw)
194
{
195
tw.
visit_switch_case_list
(*
this
);
196
}
197
198
// Switch.
199
200
tree_switch_command::~tree_switch_command
(
void
)
201
{
202
delete
expr
;
203
delete
list
;
204
delete
lead_comm
;
205
delete
trail_comm
;
206
}
207
208
tree_command
*
209
tree_switch_command::dup
(
symbol_table::scope_id
scope,
210
symbol_table::context_id
context
)
const
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
220
tree_switch_command::accept
(
tree_walker
& tw)
221
{
222
tw.
visit_switch_command
(*
this
);
223
}
Generated on Mon Dec 30 2013 03:04:38 for GNU Octave by
1.8.1.2