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