Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-pr-code.cc @ 20717:0fdba3fdf40e stable
mkoctfile: Apply default C++ compiler flags when linking oct-file (bug #45280)
* mkoctfile.in.cc: Include the value of "ALL_CXXFLAGS" in the oct-file link
command line.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Tue, 22 Sep 2015 23:12:22 +0200 |
parents | 4197fc428c7d |
children | abf85f8cbd6c |
rev | line source |
---|---|
2123 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18362
diff
changeset
|
3 Copyright (C) 1996-2015 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 | |
15035 | 752 tree_print_code::visit_funcall (tree_funcall& fc) |
753 { | |
754 indent (); | |
755 | |
756 print_parens (fc, "("); | |
757 | |
758 fc.print_raw (os, true, print_original_text); | |
759 | |
760 print_parens (fc, ")"); | |
761 } | |
762 | |
763 void | |
2123 | 764 tree_print_code::visit_parameter_list (tree_parameter_list& lst) |
765 { | |
4219 | 766 tree_parameter_list::iterator p = lst.begin (); |
2123 | 767 |
4219 | 768 while (p != lst.end ()) |
2123 | 769 { |
6215 | 770 tree_decl_elt *elt = *p++; |
2123 | 771 |
772 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
774 elt->accept (*this); |
2123 | 775 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
776 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 } |
2123 | 779 } |
780 } | |
781 | |
782 void | |
783 tree_print_code::visit_postfix_expression (tree_postfix_expression& expr) | |
784 { | |
785 indent (); | |
786 | |
2961 | 787 print_parens (expr, "("); |
2123 | 788 |
2960 | 789 tree_expression *e = expr.operand (); |
2123 | 790 |
2960 | 791 if (e) |
792 e->accept (*this); | |
2123 | 793 |
794 os << expr.oper (); | |
795 | |
2961 | 796 print_parens (expr, ")"); |
2123 | 797 } |
798 | |
799 void | |
800 tree_print_code::visit_prefix_expression (tree_prefix_expression& expr) | |
801 { | |
802 indent (); | |
803 | |
2961 | 804 print_parens (expr, "("); |
2123 | 805 |
806 os << expr.oper (); | |
807 | |
2960 | 808 tree_expression *e = expr.operand (); |
2123 | 809 |
2960 | 810 if (e) |
811 e->accept (*this); | |
2123 | 812 |
2961 | 813 print_parens (expr, ")"); |
2123 | 814 } |
815 | |
816 void | |
4207 | 817 tree_print_code::visit_return_command (tree_return_command&) |
2123 | 818 { |
819 indent (); | |
820 | |
821 os << "return"; | |
822 } | |
823 | |
824 void | |
825 tree_print_code::visit_return_list (tree_return_list& lst) | |
826 { | |
4219 | 827 tree_return_list::iterator p = lst.begin (); |
2123 | 828 |
4219 | 829 while (p != lst.end ()) |
2123 | 830 { |
4219 | 831 tree_index_expression *elt = *p++; |
2123 | 832 |
833 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
834 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
835 elt->accept (*this); |
2123 | 836 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
837 if (p != lst.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
838 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
839 } |
2123 | 840 } |
841 } | |
842 | |
843 void | |
2969 | 844 tree_print_code::visit_simple_assignment (tree_simple_assignment& expr) |
2123 | 845 { |
846 indent (); | |
847 | |
2961 | 848 print_parens (expr, "("); |
2123 | 849 |
2969 | 850 tree_expression *lhs = expr.left_hand_side (); |
2123 | 851 |
2969 | 852 if (lhs) |
853 lhs->accept (*this); | |
2123 | 854 |
2969 | 855 os << " " << expr.oper () << " "; |
2123 | 856 |
857 tree_expression *rhs = expr.right_hand_side (); | |
858 | |
859 if (rhs) | |
860 rhs->accept (*this); | |
861 | |
2961 | 862 print_parens (expr, ")"); |
2123 | 863 } |
864 | |
865 void | |
866 tree_print_code::visit_statement (tree_statement& stmt) | |
867 { | |
3665 | 868 print_comment_list (stmt.comment_text ()); |
869 | |
2123 | 870 tree_command *cmd = stmt.command (); |
871 | |
872 if (cmd) | |
873 { | |
874 cmd->accept (*this); | |
875 | |
876 if (! stmt.print_result ()) | |
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 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 } |
4980 | 881 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 newline (); |
2123 | 883 } |
884 else | |
885 { | |
886 tree_expression *expr = stmt.expression (); | |
887 | |
888 if (expr) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
890 expr->accept (*this); |
2123 | 891 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
892 if (! stmt.print_result ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 os << ";"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
895 newline (" "); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
898 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 } |
2123 | 900 } |
901 } | |
902 | |
903 void | |
904 tree_print_code::visit_statement_list (tree_statement_list& lst) | |
905 { | |
4219 | 906 for (tree_statement_list::iterator p = lst.begin (); p != lst.end (); p++) |
2123 | 907 { |
4219 | 908 tree_statement *elt = *p; |
2123 | 909 |
910 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 elt->accept (*this); |
2123 | 912 } |
913 } | |
914 | |
915 void | |
2846 | 916 tree_print_code::visit_switch_case (tree_switch_case& cs) |
917 { | |
3665 | 918 print_comment_list (cs.leading_comment ()); |
919 | |
2846 | 920 indent (); |
921 | |
922 if (cs.is_default_case ()) | |
923 os << "otherwise"; | |
924 else | |
925 os << "case "; | |
926 | |
927 tree_expression *label = cs.case_label (); | |
928 | |
929 if (label) | |
930 label->accept (*this); | |
931 | |
932 newline (); | |
933 | |
934 tree_statement_list *list = cs.commands (); | |
935 | |
936 if (list) | |
937 { | |
3665 | 938 increment_indent_level (); |
939 | |
2846 | 940 list->accept (*this); |
941 | |
3665 | 942 newline (); |
943 | |
2846 | 944 decrement_indent_level (); |
945 } | |
946 } | |
947 | |
948 void | |
949 tree_print_code::visit_switch_case_list (tree_switch_case_list& lst) | |
950 { | |
4219 | 951 tree_switch_case_list::iterator p = lst.begin (); |
2846 | 952 |
4219 | 953 while (p != lst.end ()) |
2846 | 954 { |
4219 | 955 tree_switch_case *elt = *p++; |
2846 | 956 |
957 if (elt) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
958 elt->accept (*this); |
2846 | 959 } |
960 } | |
961 | |
962 void | |
963 tree_print_code::visit_switch_command (tree_switch_command& cmd) | |
964 { | |
3665 | 965 print_comment_list (cmd.leading_comment ()); |
966 | |
2846 | 967 indent (); |
968 | |
969 os << "switch "; | |
970 | |
971 tree_expression *expr = cmd.switch_value (); | |
972 | |
973 if (expr) | |
974 expr->accept (*this); | |
975 | |
976 newline (); | |
977 | |
978 tree_switch_case_list *list = cmd.case_list (); | |
979 | |
980 if (list) | |
3665 | 981 { |
982 increment_indent_level (); | |
983 | |
984 list->accept (*this); | |
985 | |
986 decrement_indent_level (); | |
987 } | |
988 | |
989 print_indented_comment (cmd.leading_comment ()); | |
2846 | 990 |
991 indent (); | |
992 | |
993 os << "endswitch"; | |
994 } | |
995 | |
996 void | |
2123 | 997 tree_print_code::visit_try_catch_command (tree_try_catch_command& cmd) |
998 { | |
3665 | 999 print_comment_list (cmd.leading_comment ()); |
1000 | |
2123 | 1001 indent (); |
1002 | |
3665 | 1003 os << "try"; |
2123 | 1004 |
1005 newline (); | |
1006 | |
1007 tree_statement_list *try_code = cmd.body (); | |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1008 tree_identifier *expr_id = cmd.identifier (); |
2123 | 1009 |
1010 if (try_code) | |
1011 { | |
1012 increment_indent_level (); | |
3665 | 1013 |
2123 | 1014 try_code->accept (*this); |
3665 | 1015 |
2123 | 1016 decrement_indent_level (); |
1017 } | |
1018 | |
3665 | 1019 print_indented_comment (cmd.middle_comment ()); |
1020 | |
2123 | 1021 indent (); |
1022 | |
1023 os << "catch"; | |
1024 | |
17249
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1025 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
|
1026 { |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1027 os << " "; |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1028 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
|
1029 } |
923ce8b42db2
improve try-catch-statement to save exception to a variable (bug #33217)
Stefan Mahr <dac922@gmx.de>
parents:
15195
diff
changeset
|
1030 |
2123 | 1031 newline (); |
1032 | |
1033 tree_statement_list *catch_code = cmd.cleanup (); | |
1034 | |
1035 if (catch_code) | |
1036 { | |
1037 increment_indent_level (); | |
3665 | 1038 |
2123 | 1039 catch_code->accept (*this); |
3665 | 1040 |
2123 | 1041 decrement_indent_level (); |
1042 } | |
1043 | |
3665 | 1044 print_indented_comment (cmd.trailing_comment ()); |
1045 | |
2123 | 1046 indent (); |
1047 | |
1048 os << "end_try_catch"; | |
1049 } | |
1050 | |
1051 void | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1052 tree_print_code::visit_unwind_protect_command (tree_unwind_protect_command& cmd) |
2123 | 1053 { |
3665 | 1054 print_comment_list (cmd.leading_comment ()); |
1055 | |
2123 | 1056 indent (); |
1057 | |
1058 os << "unwind_protect"; | |
1059 | |
1060 newline (); | |
1061 | |
1062 tree_statement_list *unwind_protect_code = cmd.body (); | |
1063 | |
1064 if (unwind_protect_code) | |
1065 { | |
1066 increment_indent_level (); | |
3665 | 1067 |
2123 | 1068 unwind_protect_code->accept (*this); |
3665 | 1069 |
2123 | 1070 decrement_indent_level (); |
1071 } | |
1072 | |
3665 | 1073 print_indented_comment (cmd.middle_comment ()); |
1074 | |
2123 | 1075 indent (); |
1076 | |
3478 | 1077 os << "unwind_protect_cleanup"; |
2123 | 1078 |
1079 newline (); | |
1080 | |
1081 tree_statement_list *cleanup_code = cmd.cleanup (); | |
1082 | |
1083 if (cleanup_code) | |
1084 { | |
1085 increment_indent_level (); | |
3665 | 1086 |
2123 | 1087 cleanup_code->accept (*this); |
3665 | 1088 |
2123 | 1089 decrement_indent_level (); |
1090 } | |
1091 | |
3665 | 1092 print_indented_comment (cmd.trailing_comment ()); |
1093 | |
2123 | 1094 indent (); |
1095 | |
1096 os << "end_unwind_protect"; | |
1097 } | |
1098 | |
1099 void | |
1100 tree_print_code::visit_while_command (tree_while_command& cmd) | |
1101 { | |
3665 | 1102 print_comment_list (cmd.leading_comment ()); |
1103 | |
2123 | 1104 indent (); |
1105 | |
1106 os << "while "; | |
1107 | |
1108 tree_expression *expr = cmd.condition (); | |
1109 | |
1110 if (expr) | |
1111 expr->accept (*this); | |
1112 | |
1113 newline (); | |
1114 | |
1115 tree_statement_list *list = cmd.body (); | |
1116 | |
1117 if (list) | |
1118 { | |
1119 increment_indent_level (); | |
3665 | 1120 |
2123 | 1121 list->accept (*this); |
3665 | 1122 |
2123 | 1123 decrement_indent_level (); |
1124 } | |
1125 | |
3665 | 1126 print_indented_comment (cmd.trailing_comment ()); |
1127 | |
2123 | 1128 indent (); |
1129 | |
1130 os << "endwhile"; | |
1131 } | |
1132 | |
3484 | 1133 void |
1134 tree_print_code::visit_do_until_command (tree_do_until_command& cmd) | |
1135 { | |
3665 | 1136 print_comment_list (cmd.leading_comment ()); |
1137 | |
3484 | 1138 indent (); |
1139 | |
1140 os << "do"; | |
1141 | |
1142 newline (); | |
1143 | |
1144 tree_statement_list *list = cmd.body (); | |
1145 | |
1146 if (list) | |
1147 { | |
1148 increment_indent_level (); | |
3665 | 1149 |
3484 | 1150 list->accept (*this); |
3665 | 1151 |
3484 | 1152 decrement_indent_level (); |
1153 } | |
1154 | |
3665 | 1155 print_indented_comment (cmd.trailing_comment ()); |
1156 | |
3484 | 1157 indent (); |
1158 | |
18362 | 1159 os << "until "; |
3484 | 1160 |
1161 tree_expression *expr = cmd.condition (); | |
1162 | |
1163 if (expr) | |
1164 expr->accept (*this); | |
1165 | |
1166 newline (); | |
1167 } | |
1168 | |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1169 void |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1170 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
|
1171 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1172 if (b) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1173 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1174 assert (b->length () == 1); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1175 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1176 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
|
1177 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1178 if (s) |
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 if (s->is_expression ()) |
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_expression *e = s->expression (); |
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 if (e) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1185 { |
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 e->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1188 suppress_newlines--; |
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 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1192 { |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1193 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
|
1194 |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1195 suppress_newlines++; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1196 c->accept (*this); |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1197 suppress_newlines--; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1198 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1199 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1200 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1201 } |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1202 |
18284
c6858f725afe
Use std::string rather than for loop to generate blank string for indentation.
Rik <rik@octave.org>
parents:
17856
diff
changeset
|
1203 // Each print_code() function should call this before printing anything. |
2123 | 1204 |
1205 void | |
1206 tree_print_code::indent (void) | |
1207 { | |
1208 assert (curr_print_indent_level >= 0); | |
2900 | 1209 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1210 if (beginning_of_line) |
4980 | 1211 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1212 os << prefix; |
2900 | 1213 |
18284
c6858f725afe
Use std::string rather than for loop to generate blank string for indentation.
Rik <rik@octave.org>
parents:
17856
diff
changeset
|
1214 os << std::string (curr_print_indent_level, ' '); |
4980 | 1215 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1216 beginning_of_line = false; |
2123 | 1217 } |
1218 } | |
1219 | |
1220 // All print_code() functions should use this to print new lines. | |
1221 | |
1222 void | |
4980 | 1223 tree_print_code::newline (const char *alt_txt) |
2123 | 1224 { |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1225 if (suppress_newlines) |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1226 os << alt_txt; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1227 else |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1228 { |
18293
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1229 // Print prefix for blank lines. |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1230 indent (); |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1231 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1232 os << "\n"; |
2123 | 1233 |
11223
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1234 beginning_of_line = true; |
64e7538db12a
fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1235 } |
2123 | 1236 } |
1237 | |
1238 // For ressetting print_code state. | |
1239 | |
1240 void | |
1241 tree_print_code::reset (void) | |
1242 { | |
1243 beginning_of_line = true; | |
1244 curr_print_indent_level = 0; | |
4676 | 1245 while (nesting.top () != 'n') |
1246 nesting.pop (); | |
2123 | 1247 } |
1248 | |
2961 | 1249 void |
1250 tree_print_code::print_parens (const tree_expression& expr, const char *txt) | |
1251 { | |
1252 int n = expr.paren_count (); | |
1253 | |
1254 for (int i = 0; i < n; i++) | |
1255 os << txt; | |
1256 } | |
1257 | |
3665 | 1258 void |
1259 tree_print_code::print_comment_elt (const octave_comment_elt& elt) | |
1260 { | |
1261 bool printed_something = false; | |
1262 | |
1263 bool prev_char_was_newline = false; | |
1264 | |
3769 | 1265 std::string comment = elt.text (); |
3665 | 1266 |
1267 size_t len = comment.length (); | |
1268 | |
1269 size_t i = 0; | |
1270 | |
1271 while (i < len && comment[i++] == '\n') | |
1272 ; /* Skip leading new lines. */ | |
1273 i--; | |
1274 | |
1275 while (i < len) | |
1276 { | |
1277 char c = comment[i++]; | |
1278 | |
1279 if (c == '\n') | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1280 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1281 if (prev_char_was_newline) |
18293
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1282 { |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1283 printed_something = true; |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1284 |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1285 indent (); |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1286 |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1287 os << "##"; |
7e297c293e4c
Fix pretty printing with debug prompt (bug #41204).
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1288 } |
3665 | 1289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1290 newline (); |
3665 | 1291 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1292 prev_char_was_newline = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1293 } |
3665 | 1294 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1295 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1296 if (beginning_of_line) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1297 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1298 printed_something = true; |
3665 | 1299 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1300 indent (); |
3665 | 1301 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1302 os << "##"; |
3665 | 1303 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1304 if (! (isspace (c) || c == '!')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1305 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1306 } |
3665 | 1307 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1308 os << static_cast<char> (c); |
3665 | 1309 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 prev_char_was_newline = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1311 } |
3665 | 1312 } |
1313 | |
1314 if (printed_something && ! beginning_of_line) | |
1315 newline (); | |
1316 } | |
1317 | |
1318 void | |
1319 tree_print_code::print_comment_list (octave_comment_list *comment_list) | |
1320 { | |
1321 if (comment_list) | |
1322 { | |
4219 | 1323 octave_comment_list::iterator p = comment_list->begin (); |
3665 | 1324 |
4219 | 1325 while (p != comment_list->end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1326 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1327 octave_comment_elt elt = *p++; |
3665 | 1328 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1329 print_comment_elt (elt); |
3665 | 1330 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1331 if (p != comment_list->end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1332 newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1333 } |
3665 | 1334 } |
1335 } | |
1336 | |
1337 void | |
1338 tree_print_code::print_indented_comment (octave_comment_list *comment_list) | |
1339 { | |
1340 increment_indent_level (); | |
1341 | |
1342 print_comment_list (comment_list); | |
1343 | |
1344 decrement_indent_level (); | |
1345 } |