Mercurial > hg > octave-lyh
annotate libinterp/parse-tree/pt-pr-code.cc @ 17257:923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
* oct-parse.in.yy (except_command): Handle exception identifiers.
* oct-parse.in.yy, parse.h (octave_base_parser::make_try_command):
New arg, ID.
* pt-except.cc, pt-except.h (tree_try_catch_command::expr_id): New
data member.
(tree_command::tree_command): Initialize it.
(tree_command::~tree_command): Delete it.
(tree_command::identifier): New function.
* pt-check.cc (tree_checker::visit_try_catch_command): Check for valid
expr_id.
* pt-pr-code.cc (tree_print_code::visit_try_catch_command):
Print expr_id.
* pt-eval.cc (tree_evaluator::visit_try_catch_command): Assign message
and identifier to variable.
* try.tst: New test.
* NEWS: Note change.
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Tue, 13 Aug 2013 19:35:53 +0200 |
parents | 2fc554ffbc28 |
children |
rev | line source |
---|---|
2123 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13246
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2123 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2123 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2123 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3665 | 27 #include <cctype> |
28 | |
3503 | 29 #include <iostream> |
2123 | 30 |
3665 | 31 #include "comment-list.h" |
2123 | 32 #include "error.h" |
2969 | 33 #include "ov-usr-fcn.h" |
2123 | 34 #include "pr-output.h" |
2988 | 35 #include "pt-all.h" |
2123 | 36 |
37 void | |
5861 | 38 tree_print_code::visit_anon_fcn_handle (tree_anon_fcn_handle& afh) |
39 { | |
40 indent (); | |
41 | |
42 print_parens (afh, "("); | |
43 | |
44 os << "@("; | |
45 | |
46 tree_parameter_list *param_list = afh.parameter_list (); | |
47 | |
48 if (param_list) | |
49 param_list->accept (*this); | |
50 | |
51 os << ") "; | |
52 | |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
53 print_fcn_handle_body (afh.body ()); |
5861 | 54 |
55 print_parens (afh, ")"); | |
56 } | |
57 | |
58 void | |
2123 | 59 tree_print_code::visit_argument_list (tree_argument_list& lst) |
60 { | |
4219 | 61 tree_argument_list::iterator p = lst.begin (); |
2123 | 62 |
4219 | 63 while (p != lst.end ()) |
2123 | 64 { |
4219 | 65 tree_expression *elt = *p++; |
2123 | 66 |
67 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
68 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 elt->accept (*this); |
2123 | 70 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
71 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
72 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 } |
2123 | 74 } |
75 } | |
76 | |
77 void | |
78 tree_print_code::visit_binary_expression (tree_binary_expression& expr) | |
79 { | |
80 indent (); | |
81 | |
2961 | 82 print_parens (expr, "("); |
2123 | 83 |
84 tree_expression *op1 = expr.lhs (); | |
85 | |
86 if (op1) | |
87 op1->accept (*this); | |
88 | |
89 os << " " << expr.oper () << " "; | |
90 | |
91 tree_expression *op2 = expr.rhs (); | |
92 | |
93 if (op2) | |
94 op2->accept (*this); | |
95 | |
2961 | 96 print_parens (expr, ")"); |
2123 | 97 } |
98 | |
99 void | |
4207 | 100 tree_print_code::visit_break_command (tree_break_command&) |
2123 | 101 { |
102 indent (); | |
103 | |
104 os << "break"; | |
105 } | |
106 | |
107 void | |
108 tree_print_code::visit_colon_expression (tree_colon_expression& expr) | |
109 { | |
110 indent (); | |
111 | |
2961 | 112 print_parens (expr, "("); |
2123 | 113 |
114 tree_expression *op1 = expr.base (); | |
115 | |
116 if (op1) | |
117 op1->accept (*this); | |
118 | |
119 // Stupid syntax. | |
120 | |
121 tree_expression *op3 = expr.increment (); | |
122 | |
123 if (op3) | |
124 { | |
125 os << ":"; | |
126 op3->accept (*this); | |
127 } | |
128 | |
129 tree_expression *op2 = expr.limit (); | |
130 | |
131 if (op2) | |
132 { | |
133 os << ":"; | |
134 op2->accept (*this); | |
135 } | |
136 | |
2961 | 137 print_parens (expr, ")"); |
2123 | 138 } |
139 | |
140 void | |
4207 | 141 tree_print_code::visit_continue_command (tree_continue_command&) |
2123 | 142 { |
143 indent (); | |
144 | |
145 os << "continue"; | |
146 } | |
147 | |
148 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
149 tree_print_code::do_decl_command (tree_decl_command& cmd) |
2846 | 150 { |
151 indent (); | |
152 | |
153 os << cmd.name () << " "; | |
154 | |
155 tree_decl_init_list *init_list = cmd.initializer_list (); | |
156 | |
157 if (init_list) | |
158 init_list->accept (*this); | |
159 } | |
160 | |
161 void | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
162 tree_print_code::visit_global_command (tree_global_command& cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
163 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
164 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
165 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
166 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
167 void |
14294
9e3983c8963c
deprecate the static keyword
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
168 tree_print_code::visit_persistent_command (tree_persistent_command& cmd) |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
169 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
170 do_decl_command (cmd); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
171 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
172 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
173 void |
2846 | 174 tree_print_code::visit_decl_elt (tree_decl_elt& cmd) |
175 { | |
176 tree_identifier *id = cmd.ident (); | |
177 | |
178 if (id) | |
179 id->accept (*this); | |
180 | |
2969 | 181 tree_expression *expr = cmd.expression (); |
2846 | 182 |
2969 | 183 if (expr) |
184 { | |
185 os << " = "; | |
186 | |
187 expr->accept (*this); | |
188 } | |
2846 | 189 } |
190 | |
191 void | |
192 tree_print_code::visit_decl_init_list (tree_decl_init_list& lst) | |
193 { | |
4219 | 194 tree_decl_init_list::iterator p = lst.begin (); |
2846 | 195 |
4219 | 196 while (p != lst.end ()) |
2846 | 197 { |
4219 | 198 tree_decl_elt *elt = *p++; |
2846 | 199 |
200 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
201 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 elt->accept (*this); |
2846 | 203 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
205 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 } |
2846 | 207 } |
208 } | |
209 | |
210 void | |
2969 | 211 tree_print_code::visit_simple_for_command (tree_simple_for_command& cmd) |
2123 | 212 { |
3665 | 213 print_comment_list (cmd.leading_comment ()); |
214 | |
2123 | 215 indent (); |
216 | |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
217 os << (cmd.in_parallel () ? "parfor " : "for "); |
2123 | 218 |
2969 | 219 tree_expression *lhs = cmd.left_hand_side (); |
2123 | 220 |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
221 tree_expression *maxproc = cmd.maxproc_expr (); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
222 |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
223 if (maxproc) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
224 os << "("; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
225 |
2969 | 226 if (lhs) |
227 lhs->accept (*this); | |
2123 | 228 |
229 os << " = "; | |
230 | |
231 tree_expression *expr = cmd.control_expr (); | |
232 | |
233 if (expr) | |
234 expr->accept (*this); | |
235 | |
13245
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
236 if (maxproc) |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
237 { |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
238 os << ", "; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
239 maxproc->accept (*this); |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
240 os << ")"; |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
241 } |
027a2186cd90
parfor keyword and infrastructure, but handle parfor as normal for loop for now
John W. Eaton <jwe@octave.org>
parents:
13219
diff
changeset
|
242 |
2123 | 243 newline (); |
244 | |
245 tree_statement_list *list = cmd.body (); | |
246 | |
247 if (list) | |
248 { | |
249 increment_indent_level (); | |
3665 | 250 |
2123 | 251 list->accept (*this); |
3665 | 252 |
2123 | 253 decrement_indent_level (); |
254 } | |
255 | |
3665 | 256 print_indented_comment (cmd.trailing_comment ()); |
257 | |
2123 | 258 indent (); |
259 | |
13246 | 260 os << (cmd.in_parallel () ? "endparfor" : "endfor"); |
2123 | 261 } |
262 | |
263 void | |
2969 | 264 tree_print_code::visit_complex_for_command (tree_complex_for_command& cmd) |
265 { | |
3665 | 266 print_comment_list (cmd.leading_comment ()); |
267 | |
2969 | 268 indent (); |
269 | |
270 os << "for ["; | |
4676 | 271 nesting.push ('['); |
2969 | 272 |
273 tree_argument_list *lhs = cmd.left_hand_side (); | |
274 | |
275 if (lhs) | |
276 lhs->accept (*this); | |
277 | |
4676 | 278 nesting.pop (); |
2969 | 279 os << "] = "; |
280 | |
281 tree_expression *expr = cmd.control_expr (); | |
282 | |
283 if (expr) | |
284 expr->accept (*this); | |
285 | |
286 newline (); | |
287 | |
288 tree_statement_list *list = cmd.body (); | |
289 | |
290 if (list) | |
291 { | |
292 increment_indent_level (); | |
3665 | 293 |
2969 | 294 list->accept (*this); |
3665 | 295 |
2969 | 296 decrement_indent_level (); |
297 } | |
298 | |
3665 | 299 print_indented_comment (cmd.trailing_comment ()); |
300 | |
2969 | 301 indent (); |
302 | |
303 os << "endfor"; | |
304 } | |
305 | |
306 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
307 tree_print_code::visit_octave_user_script (octave_user_script& fcn) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
308 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
309 reset (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
310 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
311 tree_statement_list *cmd_list = fcn.body (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
312 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
313 if (cmd_list) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
314 cmd_list->accept (*this); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
315 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
316 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
317 void |
2891 | 318 tree_print_code::visit_octave_user_function (octave_user_function& fcn) |
2123 | 319 { |
320 reset (); | |
321 | |
2891 | 322 visit_octave_user_function_header (fcn); |
2123 | 323 |
324 tree_statement_list *cmd_list = fcn.body (); | |
325 | |
326 if (cmd_list) | |
327 { | |
328 increment_indent_level (); | |
3665 | 329 |
2123 | 330 cmd_list->accept (*this); |
3665 | 331 |
2123 | 332 decrement_indent_level (); |
333 } | |
334 | |
2891 | 335 visit_octave_user_function_trailer (fcn); |
2123 | 336 } |
337 | |
338 void | |
2891 | 339 tree_print_code::visit_octave_user_function_header (octave_user_function& fcn) |
2123 | 340 { |
3665 | 341 octave_comment_list *leading_comment = fcn.leading_comment (); |
342 | |
343 if (leading_comment) | |
344 { | |
345 print_comment_list (leading_comment); | |
346 newline (); | |
347 } | |
348 | |
2123 | 349 indent (); |
350 | |
351 os << "function "; | |
352 | |
353 tree_parameter_list *ret_list = fcn.return_list (); | |
354 | |
355 if (ret_list) | |
356 { | |
357 bool takes_var_return = fcn.takes_var_return (); | |
358 | |
359 int len = ret_list->length (); | |
360 | |
361 if (len > 1 || takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
362 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
363 os << "["; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
364 nesting.push ('['); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
365 } |
2123 | 366 |
367 ret_list->accept (*this); | |
368 | |
369 if (takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
370 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
371 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
372 os << ", "; |
2123 | 373 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
374 os << "varargout"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
375 } |
2123 | 376 |
377 if (len > 1 || takes_var_return) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
378 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
379 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 } |
2123 | 382 |
383 os << " = "; | |
384 } | |
385 | |
4748 | 386 std::string fcn_name = fcn.name (); |
2123 | 387 |
3523 | 388 os << (fcn_name.empty () ? std::string ("(empty)") : fcn_name) << " "; |
2123 | 389 |
390 tree_parameter_list *param_list = fcn.parameter_list (); | |
391 | |
392 if (param_list) | |
393 { | |
394 bool takes_varargs = fcn.takes_varargs (); | |
395 | |
396 int len = param_list->length (); | |
397 | |
398 if (len > 0 || takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 os << "("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
401 nesting.push ('('); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 } |
2123 | 403 |
404 param_list->accept (*this); | |
405 | |
406 if (takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 os << ", "; |
2123 | 410 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 os << "varargin"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 } |
2123 | 413 |
414 if (len > 0 || takes_varargs) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
416 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
417 os << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
418 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
419 } |
2123 | 420 } |
421 else | |
422 { | |
423 os << "()"; | |
424 newline (); | |
425 } | |
426 } | |
427 | |
428 void | |
3665 | 429 tree_print_code::visit_octave_user_function_trailer (octave_user_function& fcn) |
2123 | 430 { |
3665 | 431 print_indented_comment (fcn.trailing_comment ()); |
432 | |
2123 | 433 newline (); |
434 } | |
435 | |
436 void | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
437 tree_print_code::visit_function_def (tree_function_def& fdef) |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
438 { |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
439 indent (); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
440 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
441 octave_value fcn = fdef.function (); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
442 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
443 octave_function *f = fcn.function_value (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
444 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
445 if (f) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
446 f->accept (*this); |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
447 } |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
448 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
449 void |
2123 | 450 tree_print_code::visit_identifier (tree_identifier& id) |
451 { | |
452 indent (); | |
453 | |
2961 | 454 print_parens (id, "("); |
2123 | 455 |
3523 | 456 std::string nm = id.name (); |
457 os << (nm.empty () ? std::string ("(empty)") : nm); | |
2123 | 458 |
2961 | 459 print_parens (id, ")"); |
2123 | 460 } |
461 | |
462 void | |
463 tree_print_code::visit_if_clause (tree_if_clause& cmd) | |
464 { | |
465 tree_expression *expr = cmd.condition (); | |
466 | |
467 if (expr) | |
468 expr->accept (*this); | |
469 | |
470 newline (); | |
471 | |
472 tree_statement_list *list = cmd.commands (); | |
473 | |
474 if (list) | |
475 { | |
3665 | 476 increment_indent_level (); |
477 | |
2123 | 478 list->accept (*this); |
479 | |
480 decrement_indent_level (); | |
481 } | |
482 } | |
483 | |
484 void | |
485 tree_print_code::visit_if_command (tree_if_command& cmd) | |
486 { | |
3665 | 487 print_comment_list (cmd.leading_comment ()); |
488 | |
2123 | 489 indent (); |
490 | |
491 os << "if "; | |
492 | |
493 tree_if_command_list *list = cmd.cmd_list (); | |
494 | |
495 if (list) | |
496 list->accept (*this); | |
497 | |
3665 | 498 print_indented_comment (cmd.trailing_comment ()); |
499 | |
2123 | 500 indent (); |
501 | |
502 os << "endif"; | |
503 } | |
504 | |
505 void | |
506 tree_print_code::visit_if_command_list (tree_if_command_list& lst) | |
507 { | |
4219 | 508 tree_if_command_list::iterator p = lst.begin (); |
2123 | 509 |
510 bool first_elt = true; | |
511 | |
4219 | 512 while (p != lst.end ()) |
2123 | 513 { |
4219 | 514 tree_if_clause *elt = *p++; |
2123 | 515 |
516 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
517 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 if (! first_elt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
519 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
520 print_indented_comment (elt->leading_comment ()); |
3665 | 521 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 indent (); |
2123 | 523 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 if (elt->is_else_clause ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 os << "else"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
527 os << "elseif "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
528 } |
2123 | 529 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
530 elt->accept (*this); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
531 } |
2123 | 532 |
533 first_elt = false; | |
534 } | |
535 } | |
536 | |
537 void | |
538 tree_print_code::visit_index_expression (tree_index_expression& expr) | |
539 { | |
540 indent (); | |
541 | |
2961 | 542 print_parens (expr, "("); |
2123 | 543 |
3010 | 544 tree_expression *e = expr.expression (); |
2123 | 545 |
2969 | 546 if (e) |
13219
cf5ebc0e47e4
fix warnings for unused but set variables and shadowed variables
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
547 e->accept (*this); |
2123 | 548 |
4219 | 549 std::list<tree_argument_list *> arg_lists = expr.arg_lists (); |
3933 | 550 std::string type_tags = expr.type_tags (); |
4219 | 551 std::list<string_vector> arg_names = expr.arg_names (); |
2123 | 552 |
3933 | 553 int n = type_tags.length (); |
554 | |
4219 | 555 std::list<tree_argument_list *>::iterator p_arg_lists = arg_lists.begin (); |
556 std::list<string_vector>::iterator p_arg_names = arg_names.begin (); | |
3933 | 557 |
558 for (int i = 0; i < n; i++) | |
2123 | 559 { |
3933 | 560 switch (type_tags[i]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
561 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
562 case '(': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
563 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
564 char nc = nesting.top (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
565 if ((nc == '[' || nc == '{') && expr.paren_count () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
566 os << "("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
567 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
568 os << " ("; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
569 nesting.push ('('); |
4676 | 570 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
571 tree_argument_list *l = *p_arg_lists; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
572 if (l) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
573 l->accept (*this); |
4676 | 574 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
576 os << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
577 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
578 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
579 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
580 case '{': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
581 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
582 char nc = nesting.top (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 if ((nc == '[' || nc == '{') && expr.paren_count () == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 os << "{"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
586 os << " {"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 // We only care about whitespace inside [] and {} when we |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 // are defining matrix and cell objects, not when indexing. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 nesting.push ('('); |
4676 | 590 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 tree_argument_list *l = *p_arg_lists; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
592 if (l) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
593 l->accept (*this); |
4676 | 594 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
595 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
596 os << "}"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
598 break; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
599 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
600 case '.': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
601 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
602 string_vector nm = *p_arg_names; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
603 assert (nm.length () == 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
604 os << "." << nm(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
605 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
606 break; |
3933 | 607 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
608 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
609 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
610 } |
3933 | 611 |
4219 | 612 p_arg_lists++; |
613 p_arg_names++; | |
3930 | 614 } |
2123 | 615 |
2961 | 616 print_parens (expr, ")"); |
2123 | 617 } |
618 | |
619 void | |
620 tree_print_code::visit_matrix (tree_matrix& lst) | |
621 { | |
622 indent (); | |
623 | |
2961 | 624 print_parens (lst, "("); |
2123 | 625 |
626 os << "["; | |
4676 | 627 nesting.push ('['); |
2123 | 628 |
4219 | 629 tree_matrix::iterator p = lst.begin (); |
2123 | 630 |
4219 | 631 while (p != lst.end ()) |
2123 | 632 { |
4219 | 633 tree_argument_list *elt = *p++; |
2123 | 634 |
635 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
636 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
637 elt->accept (*this); |
2123 | 638 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
639 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
640 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 } |
2123 | 642 } |
643 | |
4676 | 644 nesting.pop (); |
2123 | 645 os << "]"; |
646 | |
2961 | 647 print_parens (lst, ")"); |
2123 | 648 } |
649 | |
650 void | |
3351 | 651 tree_print_code::visit_cell (tree_cell& lst) |
652 { | |
653 indent (); | |
654 | |
655 print_parens (lst, "("); | |
656 | |
657 os << "{"; | |
4676 | 658 nesting.push ('{'); |
3351 | 659 |
4219 | 660 tree_cell::iterator p = lst.begin (); |
3351 | 661 |
4219 | 662 while (p != lst.end ()) |
3351 | 663 { |
4219 | 664 tree_argument_list *elt = *p++; |
3351 | 665 |
666 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
667 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
668 elt->accept (*this); |
3351 | 669 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
670 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
672 } |
3351 | 673 } |
674 | |
4676 | 675 nesting.pop (); |
3351 | 676 os << "}"; |
677 | |
678 print_parens (lst, ")"); | |
679 } | |
680 | |
681 void | |
2969 | 682 tree_print_code::visit_multi_assignment (tree_multi_assignment& expr) |
2123 | 683 { |
684 indent (); | |
685 | |
2961 | 686 print_parens (expr, "("); |
2123 | 687 |
2969 | 688 tree_argument_list *lhs = expr.left_hand_side (); |
2123 | 689 |
690 if (lhs) | |
691 { | |
692 int len = lhs->length (); | |
693 | |
694 if (len > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
695 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
696 os << "["; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
697 nesting.push ('['); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
698 } |
2123 | 699 |
700 lhs->accept (*this); | |
701 | |
702 if (len > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
704 nesting.pop (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
705 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
706 } |
2123 | 707 } |
708 | |
3208 | 709 os << " " << expr.oper () << " "; |
2123 | 710 |
2969 | 711 tree_expression *rhs = expr.right_hand_side (); |
2123 | 712 |
713 if (rhs) | |
714 rhs->accept (*this); | |
715 | |
2961 | 716 print_parens (expr, ")"); |
2123 | 717 } |
718 | |
719 void | |
2620 | 720 tree_print_code::visit_no_op_command (tree_no_op_command& cmd) |
721 { | |
722 indent (); | |
723 | |
724 os << cmd.original_command (); | |
725 } | |
726 | |
727 void | |
2372 | 728 tree_print_code::visit_constant (tree_constant& val) |
2123 | 729 { |
730 indent (); | |
731 | |
2961 | 732 print_parens (val, "("); |
2123 | 733 |
2942 | 734 val.print_raw (os, true, print_original_text); |
2123 | 735 |
2961 | 736 print_parens (val, ")"); |
2123 | 737 } |
738 | |
739 void | |
4342 | 740 tree_print_code::visit_fcn_handle (tree_fcn_handle& fh) |
741 { | |
742 indent (); | |
743 | |
744 print_parens (fh, "("); | |
745 | |
746 fh.print_raw (os, true, print_original_text); | |
747 | |
748 print_parens (fh, ")"); | |
749 } | |
750 | |
751 void | |
2123 | 752 tree_print_code::visit_parameter_list (tree_parameter_list& lst) |
753 { | |
4219 | 754 tree_parameter_list::iterator p = lst.begin (); |
2123 | 755 |
4219 | 756 while (p != lst.end ()) |
2123 | 757 { |
6215 | 758 tree_decl_elt *elt = *p++; |
2123 | 759 |
760 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
762 elt->accept (*this); |
2123 | 763 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
765 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
766 } |
2123 | 767 } |
768 } | |
769 | |
770 void | |
771 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) | |
772 { | |
773 indent (); | |
774 | |
2961 | 775 print_parens (expr, "("); |
2123 | 776 |
2960 | 777 tree_expression *e = expr.operand (); |
2123 | 778 |
2960 | 779 if (e) |
780 e->accept (*this); | |
2123 | 781 |
782 os << expr.oper (); | |
783 | |
2961 | 784 print_parens (expr, ")"); |
2123 | 785 } |
786 | |
787 void | |
788 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) | |
789 { | |
790 indent (); | |
791 | |
2961 | 792 print_parens (expr, "("); |
2123 | 793 |
794 os << expr.oper (); | |
795 | |
2960 | 796 tree_expression *e = expr.operand (); |
2123 | 797 |
2960 | 798 if (e) |
799 e->accept (*this); | |
2123 | 800 |
2961 | 801 print_parens (expr, ")"); |
2123 | 802 } |
803 | |
804 void | |
4207 | 805 tree_print_code::visit_return_command (tree_return_command&) |
2123 | 806 { |
807 indent (); | |
808 | |
809 os << "return"; | |
810 } | |
811 | |
812 void | |
813 tree_print_code::visit_return_list (tree_return_list& lst) | |
814 { | |
4219 | 815 tree_return_list::iterator p = lst.begin (); |
2123 | 816 |
4219 | 817 while (p != lst.end ()) |
2123 | 818 { |
4219 | 819 tree_index_expression *elt = *p++; |
2123 | 820 |
821 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
822 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
823 elt->accept (*this); |
2123 | 824 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
825 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
826 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
827 } |
2123 | 828 } |
829 } | |
830 | |
831 void | |
2969 | 832 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
2123 | 833 { |
834 indent (); | |
835 | |
2961 | 836 print_parens (expr, "("); |
2123 | 837 |
2969 | 838 tree_expression *lhs = expr.left_hand_side (); |
2123 | 839 |
2969 | 840 if (lhs) |
841 lhs->accept (*this); | |
2123 | 842 |
2969 | 843 os << " " << expr.oper () << " "; |
2123 | 844 |
845 tree_expression *rhs = expr.right_hand_side (); | |
846 | |
847 if (rhs) | |
848 rhs->accept (*this); | |
849 | |
2961 | 850 print_parens (expr, ")"); |
2123 | 851 } |
852 | |
853 void | |
854 tree_print_code::visit_statement (tree_statement& stmt) | |
855 { | |
3665 | 856 print_comment_list (stmt.comment_text ()); |
857 | |
2123 | 858 tree_command *cmd = stmt.command (); |
859 | |
860 if (cmd) | |
861 { | |
862 cmd->accept (*this); | |
863 | |
864 if (! stmt.print_result ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
865 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
866 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
867 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
868 } |
4980 | 869 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 newline (); |
2123 | 871 } |
872 else | |
873 { | |
874 tree_expression *expr = stmt.expression (); | |
875 | |
876 if (expr) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 expr->accept (*this); |
2123 | 879 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 if (! stmt.print_result ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
884 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
885 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 } |
2123 | 888 } |
889 } | |
890 | |
891 void | |
892 tree_print_code::visit_statement_list (tree_statement_list& lst) | |
893 { | |
4219 | 894 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
2123 | 895 { |
4219 | 896 tree_statement *elt = *p; |
2123 | 897 |
898 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 elt->accept (*this); |
2123 | 900 } |
901 } | |
902 | |
903 void | |
2846 | 904 tree_print_code::visit_switch_case (tree_switch_case& cs) |
905 { | |
3665 | 906 print_comment_list (cs.leading_comment ()); |
907 | |
2846 | 908 indent (); |
909 | |
910 if (cs.is_default_case ()) | |
911 os << "otherwise"; | |
912 else | |
913 os << "case "; | |
914 | |
915 tree_expression *label = cs.case_label (); | |
916 | |
917 if (label) | |
918 label->accept (*this); | |
919 | |
920 newline (); | |
921 | |
922 tree_statement_list *list = cs.commands (); | |
923 | |
924 if (list) | |
925 { | |
3665 | 926 increment_indent_level (); |
927 | |
2846 | 928 list->accept (*this); |
929 | |
3665 | 930 newline (); |
931 | |
2846 | 932 decrement_indent_level (); |
933 } | |
934 } | |
935 | |
936 void | |
937 tree_print_code::visit_switch_case_list (tree_switch_case_list& lst) | |
938 { | |
4219 | 939 tree_switch_case_list::iterator p = lst.begin (); |
2846 | 940 |
4219 | 941 while (p != lst.end ()) |
2846 | 942 { |
4219 | 943 tree_switch_case *elt = *p++; |
2846 | 944 |
945 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
946 elt->accept (*this); |
2846 | 947 } |
948 } | |
949 | |
950 void | |
951 tree_print_code::visit_switch_command (tree_switch_command& cmd) | |
952 { | |
3665 | 953 print_comment_list (cmd.leading_comment ()); |
954 | |
2846 | 955 indent (); |
956 | |
957 os << "switch "; | |
958 | |
959 tree_expression *expr = cmd.switch_value (); | |
960 | |
961 if (expr) | |
962 expr->accept (*this); | |
963 | |
964 newline (); | |
965 | |
966 tree_switch_case_list *list = cmd.case_list (); | |
967 | |
968 if (list) | |
3665 | 969 { |
970 increment_indent_level (); | |
971 | |
972 list->accept (*this); | |
973 | |
974 decrement_indent_level (); | |
975 } | |
976 | |
977 print_indented_comment (cmd.leading_comment ()); | |
2846 | 978 |
979 indent (); | |
980 | |
981 os << "endswitch"; | |
982 } | |
983 | |
984 void | |
2123 | 985 tree_print_code::visit_try_catch_command (tree_try_catch_command& cmd) |
986 { | |
3665 | 987 print_comment_list (cmd.leading_comment ()); |
988 | |
2123 | 989 indent (); |
990 | |
3665 | 991 os << "try"; |
2123 | 992 |
993 newline (); | |
994 | |
995 tree_statement_list *try_code = cmd.body (); | |
17257
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
996 tree_identifier *expr_id = cmd.identifier (); |
2123 | 997 |
998 if (try_code) | |
999 { | |
1000 increment_indent_level (); | |
3665 | 1001 |
2123 | 1002 try_code->accept (*this); |
3665 | 1003 |
2123 | 1004 decrement_indent_level (); |
1005 } | |
1006 | |
3665 | 1007 print_indented_comment (cmd.middle_comment ()); |
1008 | |
2123 | 1009 indent (); |
1010 | |
1011 os << "catch"; | |
1012 | |
17257
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1013 if (expr_id) |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1014 { |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1015 os << " "; |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1016 expr_id->accept (*this); |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1017 } |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1018 |
2123 | 1019 newline (); |
1020 | |
1021 tree_statement_list *catch_code = cmd.cleanup (); | |
1022 | |
1023 if (catch_code) | |
1024 { | |
1025 increment_indent_level (); | |
3665 | 1026 |
2123 | 1027 catch_code->accept (*this); |
3665 | 1028 |
2123 | 1029 decrement_indent_level (); |
1030 } | |
1031 | |
3665 | 1032 print_indented_comment (cmd.trailing_comment ()); |
1033 | |
2123 | 1034 indent (); |
1035 | |
1036 os << "end_try_catch"; | |
1037 } | |
1038 | |
1039 void | |
1040 tree_print_code::visit_unwind_protect_command | |
1041 (tree_unwind_protect_command& cmd) | |
1042 { | |
3665 | 1043 print_comment_list (cmd.leading_comment ()); |
1044 | |
2123 | 1045 indent (); |
1046 | |
1047 os << "unwind_protect"; | |
1048 | |
1049 newline (); | |
1050 | |
1051 tree_statement_list *unwind_protect_code = cmd.body (); | |
1052 | |
1053 if (unwind_protect_code) | |
1054 { | |
1055 increment_indent_level (); | |
3665 | 1056 |
2123 | 1057 unwind_protect_code->accept (*this); |
3665 | 1058 |
2123 | 1059 decrement_indent_level (); |
1060 } | |
1061 | |
3665 | 1062 print_indented_comment (cmd.middle_comment ()); |
1063 | |
2123 | 1064 indent (); |
1065 | |
3478 | 1066 os << "unwind_protect_cleanup"; |
2123 | 1067 |
1068 newline (); | |
1069 | |
1070 tree_statement_list *cleanup_code = cmd.cleanup (); | |
1071 | |
1072 if (cleanup_code) | |
1073 { | |
1074 increment_indent_level (); | |
3665 | 1075 |
2123 | 1076 cleanup_code->accept (*this); |
3665 | 1077 |
2123 | 1078 decrement_indent_level (); |
1079 } | |
1080 | |
3665 | 1081 print_indented_comment (cmd.trailing_comment ()); |
1082 | |
2123 | 1083 indent (); |
1084 | |
1085 os << "end_unwind_protect"; | |
1086 } | |
1087 | |
1088 void | |
1089 tree_print_code::visit_while_command (tree_while_command& cmd) | |
1090 { | |
3665 | 1091 print_comment_list (cmd.leading_comment ()); |
1092 | |
2123 | 1093 indent (); |
1094 | |
1095 os << "while "; | |
1096 | |
1097 tree_expression *expr = cmd.condition (); | |
1098 | |
1099 if (expr) | |
1100 expr->accept (*this); | |
1101 | |
1102 newline (); | |
1103 | |
1104 tree_statement_list *list = cmd.body (); | |
1105 | |
1106 if (list) | |
1107 { | |
1108 increment_indent_level (); | |
3665 | 1109 |
2123 | 1110 list->accept (*this); |
3665 | 1111 |
2123 | 1112 decrement_indent_level (); |
1113 } | |
1114 | |
3665 | 1115 print_indented_comment (cmd.trailing_comment ()); |
1116 | |
2123 | 1117 indent (); |
1118 | |
1119 os << "endwhile"; | |
1120 } | |
1121 | |
3484 | 1122 void |
1123 tree_print_code::visit_do_until_command (tree_do_until_command& cmd) | |
1124 { | |
3665 | 1125 print_comment_list (cmd.leading_comment ()); |
1126 | |
3484 | 1127 indent (); |
1128 | |
1129 os << "do"; | |
1130 | |
1131 newline (); | |
1132 | |
1133 tree_statement_list *list = cmd.body (); | |
1134 | |
1135 if (list) | |
1136 { | |
1137 increment_indent_level (); | |
3665 | 1138 |
3484 | 1139 list->accept (*this); |
3665 | 1140 |
3484 | 1141 decrement_indent_level (); |
1142 } | |
1143 | |
3665 | 1144 print_indented_comment (cmd.trailing_comment ()); |
1145 | |
3484 | 1146 indent (); |
1147 | |
1148 os << "until"; | |
1149 | |
1150 tree_expression *expr = cmd.condition (); | |
1151 | |
1152 if (expr) | |
1153 expr->accept (*this); | |
1154 | |
1155 newline (); | |
1156 } | |
1157 | |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1158 void |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1159 tree_print_code::print_fcn_handle_body (tree_statement_list *b) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1160 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1161 if (b) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1162 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1163 assert (b->length () == 1); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1164 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1165 tree_statement *s = b->front (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1166 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1167 if (s) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1168 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1169 if (s->is_expression ()) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1170 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1171 tree_expression *e = s->expression (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1172 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1173 if (e) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1174 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1175 suppress_newlines++; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1176 e->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1177 suppress_newlines--; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1178 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1179 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1180 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1181 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1182 tree_command *c = s->command (); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1183 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1184 suppress_newlines++; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1185 c->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1186 suppress_newlines--; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1187 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1188 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1189 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1190 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1191 |
2123 | 1192 // Each print_code() function should call this before printing |
1193 // anything. | |
1194 // | |
1195 // This doesn't need to be fast, but isn't there a better way? | |
1196 | |
1197 void | |
1198 tree_print_code::indent (void) | |
1199 { | |
1200 assert (curr_print_indent_level >= 0); | |
2900 | 1201 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1202 if (beginning_of_line) |
4980 | 1203 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1204 os << prefix; |
2900 | 1205 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1206 for (int i = 0; i < curr_print_indent_level; i++) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1207 os << " "; |
4980 | 1208 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1209 beginning_of_line = false; |
2123 | 1210 } |
1211 } | |
1212 | |
1213 // All print_code() functions should use this to print new lines. | |
1214 | |
1215 void | |
4980 | 1216 tree_print_code::newline (const char *alt_txt) |
2123 | 1217 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1218 if (suppress_newlines) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1219 os << alt_txt; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1220 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1221 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1222 os << "\n"; |
2123 | 1223 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1224 beginning_of_line = true; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1225 } |
2123 | 1226 } |
1227 | |
1228 // For ressetting print_code state. | |
1229 | |
1230 void | |
1231 tree_print_code::reset (void) | |
1232 { | |
1233 beginning_of_line = true; | |
1234 curr_print_indent_level = 0; | |
4676 | 1235 while (nesting.top () != 'n') |
1236 nesting.pop (); | |
2123 | 1237 } |
1238 | |
2961 | 1239 void |
1240 tree_print_code::print_parens (const tree_expression& expr, const char *txt) | |
1241 { | |
1242 int n = expr.paren_count (); | |
1243 | |
1244 for (int i = 0; i < n; i++) | |
1245 os << txt; | |
1246 } | |
1247 | |
3665 | 1248 void |
1249 tree_print_code::print_comment_elt (const octave_comment_elt& elt) | |
1250 { | |
1251 bool printed_something = false; | |
1252 | |
1253 bool prev_char_was_newline = false; | |
1254 | |
3769 | 1255 std::string comment = elt.text (); |
3665 | 1256 |
1257 size_t len = comment.length (); | |
1258 | |
1259 size_t i = 0; | |
1260 | |
1261 while (i < len && comment[i++] == '\n') | |
1262 ; /* Skip leading new lines. */ | |
1263 i--; | |
1264 | |
1265 while (i < len) | |
1266 { | |
1267 char c = comment[i++]; | |
1268 | |
1269 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1270 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1271 if (prev_char_was_newline) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1272 os << "##"; |
3665 | 1273 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1274 newline (); |
3665 | 1275 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1276 prev_char_was_newline = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1277 } |
3665 | 1278 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1279 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1280 if (beginning_of_line) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1281 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1282 printed_something = true; |
3665 | 1283 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1284 indent (); |
3665 | 1285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1286 os << "##"; |
3665 | 1287 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1288 if (! (isspace (c) || c == '!')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1289 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1290 } |
3665 | 1291 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1292 os << static_cast<char> (c); |
3665 | 1293 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1294 prev_char_was_newline = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1295 } |
3665 | 1296 } |
1297 | |
1298 if (printed_something && ! beginning_of_line) | |
1299 newline (); | |
1300 } | |
1301 | |
1302 void | |
1303 tree_print_code::print_comment_list (octave_comment_list *comment_list) | |
1304 { | |
1305 if (comment_list) | |
1306 { | |
4219 | 1307 octave_comment_list::iterator p = comment_list->begin (); |
3665 | 1308 |
4219 | 1309 while (p != comment_list->end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1311 octave_comment_elt elt = *p++; |
3665 | 1312 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1313 print_comment_elt (elt); |
3665 | 1314 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1315 if (p != comment_list->end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1316 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1317 } |
3665 | 1318 } |
1319 } | |
1320 | |
1321 void | |
1322 tree_print_code::print_indented_comment (octave_comment_list *comment_list) | |
1323 { | |
1324 increment_indent_level (); | |
1325 | |
1326 print_comment_list (comment_list); | |
1327 | |
1328 decrement_indent_level (); | |
1329 } |