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-stmt.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 <typeinfo>
28
29
#include "
quit.h
"
30
31
#include "
defun.h
"
32
#include "
error.h
"
33
#include "
gripes.h
"
34
#include "
ov.h
"
35
#include "
octave-link.h
"
36
#include "
oct-lvalue.h
"
37
#include "
input.h
"
38
#include "
pager.h
"
39
#include "
pt-bp.h
"
40
#include "
pt-cmd.h
"
41
#include "
pt-id.h
"
42
#include "
pt-idx.h
"
43
#include "
pt-jump.h
"
44
#include "
pt-pr-code.h
"
45
#include "
pt-stmt.h
"
46
#include "
pt-walk.h
"
47
#include "
unwind-prot.h
"
48
#include "
utils.h
"
49
#include "
variables.h
"
50
51
// A list of commands to be executed.
52
53
tree_statement::~tree_statement
(
void
)
54
{
55
delete
cmd
;
56
delete
expr
;
57
delete
comm
;
58
}
59
60
void
61
tree_statement::set_print_flag
(
bool
print_flag)
62
{
63
if
(
expr
)
64
expr
->
set_print_flag
(print_flag);
65
}
66
67
bool
68
tree_statement::print_result
(
void
)
69
{
70
return
expr
&&
expr
->
print_result
();
71
}
72
73
void
74
tree_statement::set_breakpoint
(
void
)
75
{
76
if
(
cmd
)
77
cmd
->
set_breakpoint
();
78
else
if
(
expr
)
79
expr
->
set_breakpoint
();
80
}
81
82
void
83
tree_statement::delete_breakpoint
(
void
)
84
{
85
if
(
cmd
)
86
cmd
->
delete_breakpoint
();
87
else
if
(
expr
)
88
expr
->
delete_breakpoint
();
89
}
90
91
bool
92
tree_statement::is_breakpoint
(
void
)
const
93
{
94
return
cmd
?
cmd
->
is_breakpoint
() : (
expr
?
expr
->
is_breakpoint
() :
false
);
95
}
96
97
int
98
tree_statement::line
(
void
)
const
99
{
100
return
cmd
?
cmd
->
line
() : (
expr
?
expr
->
line
() : -1);
101
}
102
103
int
104
tree_statement::column
(
void
)
const
105
{
106
return
cmd
?
cmd
->
column
() : (
expr
?
expr
->
column
() : -1);
107
}
108
109
void
110
tree_statement::set_location
(
int
l,
int
c)
111
{
112
if
(
cmd
)
113
cmd
->
set_location
(l, c);
114
else
if
(
expr
)
115
expr
->
set_location
(l, c);
116
}
117
118
void
119
tree_statement::echo_code
(
void
)
120
{
121
tree_print_code
tpc (
octave_stdout
,
VPS4
);
122
123
accept
(tpc);
124
}
125
126
bool
127
tree_statement::is_end_of_fcn_or_script
(
void
)
const
128
{
129
bool
retval =
false
;
130
131
if
(
cmd
)
132
{
133
tree_no_op_command
*no_op_cmd
134
=
dynamic_cast<
tree_no_op_command
*
>
(
cmd
);
135
136
if
(no_op_cmd)
137
retval = no_op_cmd->
is_end_of_fcn_or_script
();
138
}
139
140
return
retval;
141
}
142
143
bool
144
tree_statement::is_end_of_file
(
void
)
const
145
{
146
bool
retval =
false
;
147
148
if
(
cmd
)
149
{
150
tree_no_op_command
*no_op_cmd
151
=
dynamic_cast<
tree_no_op_command
*
>
(
cmd
);
152
153
if
(no_op_cmd)
154
retval = no_op_cmd->
is_end_of_file
();
155
}
156
157
return
retval;
158
}
159
160
tree_statement
*
161
tree_statement::dup
(
symbol_table::scope_id
scope,
162
symbol_table::context_id
context
)
const
163
{
164
tree_statement
*new_stmt =
new
tree_statement
();
165
166
new_stmt->
cmd
=
cmd
?
cmd
->
dup
(scope, context) : 0;
167
168
new_stmt->
expr
=
expr
?
expr
->
dup
(scope, context) : 0;
169
170
new_stmt->
comm
=
comm
?
comm
->
dup
() : 0;
171
172
return
new_stmt;
173
}
174
175
void
176
tree_statement::accept
(
tree_walker
& tw)
177
{
178
tw.
visit_statement
(*
this
);
179
}
180
181
int
182
tree_statement_list::set_breakpoint
(
int
line
)
183
{
184
tree_breakpoint
tbp (line,
tree_breakpoint::set
);
185
accept
(tbp);
186
187
return
tbp.
get_line
();
188
}
189
190
void
191
tree_statement_list::delete_breakpoint
(
int
line
)
192
{
193
if
(line < 0)
194
{
195
octave_value_list
bp_lst =
list_breakpoints
();
196
197
int
len = bp_lst.
length
();
198
199
for
(
int
i = 0; i < len; i++)
200
{
201
tree_breakpoint
tbp (i,
tree_breakpoint::clear
);
202
accept
(tbp);
203
}
204
}
205
else
206
{
207
tree_breakpoint
tbp (line,
tree_breakpoint::clear
);
208
accept
(tbp);
209
}
210
}
211
212
octave_value_list
213
tree_statement_list::list_breakpoints
(
void
)
214
{
215
tree_breakpoint
tbp (0,
tree_breakpoint::list
);
216
accept
(tbp);
217
218
return
tbp.
get_list
();
219
}
220
221
bp_table::intmap
222
tree_statement_list::add_breakpoint
(
const
std::string& file,
223
const
bp_table::intmap
&
line
)
224
{
225
bp_table::intmap
retval;
226
227
octave_idx_type
len = line.size ();
228
229
for
(
int
i = 0; i < len; i++)
230
{
231
bp_table::const_intmap_iterator
p = line.find (i);
232
233
if
(p != line.end ())
234
{
235
int
lineno = p->second;
236
237
retval[i] =
set_breakpoint
(lineno);
238
239
if
(retval[i] != 0 && ! file.empty ())
240
octave_link::update_breakpoint
(
true
, file, retval[i]);
241
}
242
}
243
244
return
retval;
245
}
246
247
bp_table::intmap
248
tree_statement_list::remove_all_breakpoints
(
const
std::string& file)
249
{
250
bp_table::intmap
retval;
251
252
octave_value_list
bkpts =
list_breakpoints
();
253
254
for
(
int
i = 0; i < bkpts.
length
(); i++)
255
{
256
int
lineno =
static_cast<
int
>
(bkpts(i).int_value ());
257
258
delete_breakpoint
(lineno);
259
260
retval[i] = lineno;
261
262
if
(! file.empty ())
263
octave_link::update_breakpoint
(
false
, file, lineno);
264
}
265
266
return
retval;
267
}
268
269
270
tree_statement_list
*
271
tree_statement_list::dup
(
symbol_table::scope_id
scope,
272
symbol_table::context_id
context
)
const
273
{
274
tree_statement_list
*new_list =
new
tree_statement_list
();
275
276
new_list->
function_body
=
function_body
;
277
278
for
(
const_iterator
p =
begin
(); p !=
end
(); p++)
279
{
280
const
tree_statement
*elt = *p;
281
282
new_list->
append
(elt ? elt->
dup
(scope, context) : 0);
283
}
284
285
return
new_list;
286
}
287
288
void
289
tree_statement_list::accept
(
tree_walker
& tw)
290
{
291
tw.
visit_statement_list
(*
this
);
292
}
Generated on Mon Dec 30 2013 03:04:38 for GNU Octave by
1.8.1.2