| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: indent.c,v 1.338 2023/06/07 15:46:11 rillig Exp $ */ | | 1 | /* $NetBSD: indent.c,v 1.339 2023/06/08 06:47:13 rillig Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * SPDX-License-Identifier: BSD-4-Clause | | 4 | * SPDX-License-Identifier: BSD-4-Clause |
5 | * | | 5 | * |
6 | * Copyright (c) 1985 Sun Microsystems, Inc. | | 6 | * Copyright (c) 1985 Sun Microsystems, Inc. |
7 | * Copyright (c) 1976 Board of Trustees of the University of Illinois. | | 7 | * Copyright (c) 1976 Board of Trustees of the University of Illinois. |
8 | * Copyright (c) 1980, 1993 | | 8 | * Copyright (c) 1980, 1993 |
9 | * The Regents of the University of California. All rights reserved. | | 9 | * The Regents of the University of California. All rights reserved. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -28,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
37 | * SUCH DAMAGE. | | 37 | * SUCH DAMAGE. |
38 | */ | | 38 | */ |
39 | | | 39 | |
40 | #include <sys/cdefs.h> | | 40 | #include <sys/cdefs.h> |
41 | __RCSID("$NetBSD: indent.c,v 1.338 2023/06/07 15:46:11 rillig Exp $"); | | 41 | __RCSID("$NetBSD: indent.c,v 1.339 2023/06/08 06:47:13 rillig Exp $"); |
42 | | | 42 | |
43 | #include <sys/param.h> | | 43 | #include <sys/param.h> |
44 | #include <err.h> | | 44 | #include <err.h> |
45 | #include <fcntl.h> | | 45 | #include <fcntl.h> |
46 | #include <stdarg.h> | | 46 | #include <stdarg.h> |
47 | #include <stdio.h> | | 47 | #include <stdio.h> |
48 | #include <stdlib.h> | | 48 | #include <stdlib.h> |
49 | #include <string.h> | | 49 | #include <string.h> |
50 | #include <unistd.h> | | 50 | #include <unistd.h> |
51 | | | 51 | |
52 | #include "indent.h" | | 52 | #include "indent.h" |
53 | | | 53 | |
54 | struct options opt = { | | 54 | struct options opt = { |
| @@ -302,67 +302,68 @@ set_initial_indentation(void) | | | @@ -302,67 +302,68 @@ set_initial_indentation(void) |
302 | for (const char *p = inp_p;; p++) { | | 302 | for (const char *p = inp_p;; p++) { |
303 | if (*p == ' ') | | 303 | if (*p == ' ') |
304 | ind++; | | 304 | ind++; |
305 | else if (*p == '\t') | | 305 | else if (*p == '\t') |
306 | ind = next_tab(ind); | | 306 | ind = next_tab(ind); |
307 | else | | 307 | else |
308 | break; | | 308 | break; |
309 | } | | 309 | } |
310 | | | 310 | |
311 | ps.ind_level = ps.ind_level_follow = ind / opt.indent_size; | | 311 | ps.ind_level = ps.ind_level_follow = ind / opt.indent_size; |
312 | } | | 312 | } |
313 | | | 313 | |
314 | static void | | 314 | static void |
315 | code_add_decl_indent(int decl_ind, bool tabs_to_var) | | 315 | indent_declarator(int decl_ind, bool tabs_to_var) |
316 | { | | 316 | { |
317 | int base = ps.ind_level * opt.indent_size; | | 317 | int base = ps.ind_level * opt.indent_size; |
318 | int ind = base + (int)code.len; | | 318 | int ind = base + (int)code.len; |
319 | int target = base + decl_ind; | | 319 | int target = base + decl_ind; |
320 | size_t orig_code_len = code.len; | | 320 | size_t orig_code_len = code.len; |
321 | | | 321 | |
322 | if (tabs_to_var) | | 322 | if (tabs_to_var) |
323 | for (int next; (next = next_tab(ind)) <= target; ind = next) | | 323 | for (int next; (next = next_tab(ind)) <= target; ind = next) |
324 | buf_add_char(&code, '\t'); | | 324 | buf_add_char(&code, '\t'); |
325 | | | 325 | |
326 | for (; ind < target; ind++) | | 326 | for (; ind < target; ind++) |
327 | buf_add_char(&code, ' '); | | 327 | buf_add_char(&code, ' '); |
328 | | | 328 | |
329 | if (code.len == orig_code_len && ps.want_blank) { | | 329 | if (code.len == orig_code_len && ps.want_blank) { |
330 | buf_add_char(&code, ' '); | | 330 | buf_add_char(&code, ' '); |
331 | ps.want_blank = false; | | 331 | ps.want_blank = false; |
332 | } | | 332 | } |
| | | 333 | ps.decl_indent_done = true; |
333 | } | | 334 | } |
334 | | | 335 | |
335 | static void | | 336 | static void |
336 | update_ps_decl_ptr(lexer_symbol lsym) | | 337 | update_ps_decl_ptr(lexer_symbol lsym) |
337 | { | | 338 | { |
338 | if (lsym == lsym_semicolon | | 339 | if (lsym == lsym_semicolon |
339 | || lsym == lsym_lbrace | | 340 | || lsym == lsym_lbrace |
340 | || lsym == lsym_rbrace | | 341 | || lsym == lsym_rbrace |
341 | || (lsym == lsym_lparen && ps.prev_lsym != lsym_sizeof) | | 342 | || (lsym == lsym_lparen && ps.prev_lsym != lsym_sizeof) |
342 | || (lsym == lsym_comma && ps.in_decl) | | 343 | || (lsym == lsym_comma && ps.in_decl) |
343 | || lsym == lsym_modifier) | | 344 | || lsym == lsym_modifier) |
344 | ps.decl_ptr = dp_start; | | 345 | ps.decl_ptr = dp_start; |
345 | else if (ps.decl_ptr == dp_start && lsym == lsym_word) | | 346 | else if (ps.decl_ptr == dp_start && lsym == lsym_word) |
346 | ps.decl_ptr = dp_word; | | 347 | ps.decl_ptr = dp_word; |
347 | else if ((ps.decl_ptr == dp_word || ps.decl_ptr == dp_word_asterisk) | | 348 | else if ((ps.decl_ptr == dp_word || ps.decl_ptr == dp_word_asterisk) |
348 | && (lsym == lsym_unary_op && token.s[0] == '*')) | | 349 | && (lsym == lsym_unary_op && token.s[0] == '*')) |
349 | ps.decl_ptr = dp_word_asterisk; | | 350 | ps.decl_ptr = dp_word_asterisk; |
350 | else | | 351 | else |
351 | ps.decl_ptr = dp_other; | | 352 | ps.decl_ptr = dp_other; |
352 | } | | 353 | } |
353 | | | 354 | |
354 | static void | | 355 | static void |
355 | update_ps_prev_tag(lexer_symbol lsym) | | 356 | update_ps_lbrace_kind(lexer_symbol lsym) |
356 | { | | 357 | { |
357 | if (lsym == lsym_tag) { | | 358 | if (lsym == lsym_tag) { |
358 | ps.lbrace_kind = token.s[0] == 's' ? psym_lbrace_struct : | | 359 | ps.lbrace_kind = token.s[0] == 's' ? psym_lbrace_struct : |
359 | token.s[0] == 'u' ? psym_lbrace_union : | | 360 | token.s[0] == 'u' ? psym_lbrace_union : |
360 | psym_lbrace_enum; | | 361 | psym_lbrace_enum; |
361 | } else if (lsym != lsym_type_outside_parentheses | | 362 | } else if (lsym != lsym_type_outside_parentheses |
362 | && lsym != lsym_word | | 363 | && lsym != lsym_word |
363 | && lsym != lsym_lbrace) | | 364 | && lsym != lsym_lbrace) |
364 | ps.lbrace_kind = psym_lbrace_block; | | 365 | ps.lbrace_kind = psym_lbrace_block; |
365 | } | | 366 | } |
366 | | | 367 | |
367 | static int | | 368 | static int |
368 | process_eof(void) | | 369 | process_eof(void) |
| @@ -454,30 +455,29 @@ want_blank_before_lparen(void) | | | @@ -454,30 +455,29 @@ want_blank_before_lparen(void) |
454 | return false; | | 455 | return false; |
455 | return true; | | 456 | return true; |
456 | } | | 457 | } |
457 | | | 458 | |
458 | static void | | 459 | static void |
459 | process_lparen(void) | | 460 | process_lparen(void) |
460 | { | | 461 | { |
461 | if (++ps.nparen == array_length(ps.paren)) { | | 462 | if (++ps.nparen == array_length(ps.paren)) { |
462 | diag(0, "Reached internal limit of %zu unclosed parentheses", | | 463 | diag(0, "Reached internal limit of %zu unclosed parentheses", |
463 | array_length(ps.paren)); | | 464 | array_length(ps.paren)); |
464 | ps.nparen--; | | 465 | ps.nparen--; |
465 | } | | 466 | } |
466 | | | 467 | |
467 | if (is_function_pointer_declaration()) { | | 468 | if (is_function_pointer_declaration()) |
468 | code_add_decl_indent(ps.decl_ind, ps.tabs_to_var); | | 469 | indent_declarator(ps.decl_ind, ps.tabs_to_var); |
469 | ps.decl_indent_done = true; | | 470 | else if (want_blank_before_lparen()) |
470 | } else if (want_blank_before_lparen()) | | | |
471 | buf_add_char(&code, ' '); | | 471 | buf_add_char(&code, ' '); |
472 | ps.want_blank = false; | | 472 | ps.want_blank = false; |
473 | buf_add_char(&code, token.s[0]); | | 473 | buf_add_char(&code, token.s[0]); |
474 | | | 474 | |
475 | if (opt.extra_expr_indent && !opt.lineup_to_parens | | 475 | if (opt.extra_expr_indent && !opt.lineup_to_parens |
476 | && ps.spaced_expr_psym != psym_0 && ps.nparen == 1 | | 476 | && ps.spaced_expr_psym != psym_0 && ps.nparen == 1 |
477 | && opt.continuation_indent == opt.indent_size) | | 477 | && opt.continuation_indent == opt.indent_size) |
478 | ps.extra_expr_indent = eei_yes; | | 478 | ps.extra_expr_indent = eei_yes; |
479 | | | 479 | |
480 | if (ps.init_or_struct && ps.psyms.top <= 2) { | | 480 | if (ps.init_or_struct && ps.psyms.top <= 2) { |
481 | /* A kludge to correctly align function definitions. */ | | 481 | /* A kludge to correctly align function definitions. */ |
482 | parse(psym_stmt); | | 482 | parse(psym_stmt); |
483 | ps.init_or_struct = false; | | 483 | ps.init_or_struct = false; |
| @@ -494,48 +494,36 @@ process_lparen(void) | | | @@ -494,48 +494,36 @@ process_lparen(void) |
494 | || ps.prev_lsym == lsym_for | | 494 | || ps.prev_lsym == lsym_for |
495 | || ps.prev_lsym == lsym_if | | 495 | || ps.prev_lsym == lsym_if |
496 | || ps.prev_lsym == lsym_switch | | 496 | || ps.prev_lsym == lsym_switch |
497 | || ps.prev_lsym == lsym_while | | 497 | || ps.prev_lsym == lsym_while |
498 | || ps.is_function_definition) | | 498 | || ps.is_function_definition) |
499 | cast = cast_no; | | 499 | cast = cast_no; |
500 | | | 500 | |
501 | ps.paren[ps.nparen - 1].indent = indent; | | 501 | ps.paren[ps.nparen - 1].indent = indent; |
502 | ps.paren[ps.nparen - 1].cast = cast; | | 502 | ps.paren[ps.nparen - 1].cast = cast; |
503 | debug_println("paren_indents[%d] is now %s%d", | | 503 | debug_println("paren_indents[%d] is now %s%d", |
504 | ps.nparen - 1, paren_level_cast_name[cast], indent); | | 504 | ps.nparen - 1, paren_level_cast_name[cast], indent); |
505 | } | | 505 | } |
506 | | | 506 | |
507 | static bool | | | |
508 | want_blank_before_lbracket(void) | | | |
509 | { | | | |
510 | if (code.len == 0) | | | |
511 | return false; | | | |
512 | if (ps.prev_lsym == lsym_comma) | | | |
513 | return true; | | | |
514 | if (ps.prev_lsym == lsym_binary_op) | | | |
515 | return true; | | | |
516 | return false; | | | |
517 | } | | | |
518 | | | | |
519 | static void | | 507 | static void |
520 | process_lbracket(void) | | 508 | process_lbracket(void) |
521 | { | | 509 | { |
522 | if (++ps.nparen == array_length(ps.paren)) { | | 510 | if (++ps.nparen == array_length(ps.paren)) { |
523 | diag(0, "Reached internal limit of %zu unclosed parentheses", | | 511 | diag(0, "Reached internal limit of %zu unclosed parentheses", |
524 | array_length(ps.paren)); | | 512 | array_length(ps.paren)); |
525 | ps.nparen--; | | 513 | ps.nparen--; |
526 | } | | 514 | } |
527 | | | 515 | |
528 | if (want_blank_before_lbracket()) | | 516 | if (ps.prev_lsym == lsym_comma || ps.prev_lsym == lsym_binary_op) |
529 | buf_add_char(&code, ' '); | | 517 | buf_add_char(&code, ' '); |
530 | ps.want_blank = false; | | 518 | ps.want_blank = false; |
531 | buf_add_char(&code, token.s[0]); | | 519 | buf_add_char(&code, token.s[0]); |
532 | | | 520 | |
533 | int indent = ind_add(0, code.s, code.len); | | 521 | int indent = ind_add(0, code.s, code.len); |
534 | | | 522 | |
535 | ps.paren[ps.nparen - 1].indent = indent; | | 523 | ps.paren[ps.nparen - 1].indent = indent; |
536 | ps.paren[ps.nparen - 1].cast = cast_no; | | 524 | ps.paren[ps.nparen - 1].cast = cast_no; |
537 | debug_println("paren_indents[%d] is now %d", ps.nparen - 1, indent); | | 525 | debug_println("paren_indents[%d] is now %d", ps.nparen - 1, indent); |
538 | } | | 526 | } |
539 | | | 527 | |
540 | static void | | 528 | static void |
541 | process_rparen(void) | | 529 | process_rparen(void) |
| @@ -581,95 +569,69 @@ process_rbracket(void) | | | @@ -581,95 +569,69 @@ process_rbracket(void) |
581 | diag(0, "Extra '%c'", *token.s); | | 569 | diag(0, "Extra '%c'", *token.s); |
582 | goto unbalanced; | | 570 | goto unbalanced; |
583 | } | | 571 | } |
584 | --ps.nparen; | | 572 | --ps.nparen; |
585 | | | 573 | |
586 | ps.want_blank = true; | | 574 | ps.want_blank = true; |
587 | if (code.len == 0) | | 575 | if (code.len == 0) |
588 | ps.line_start_nparen = ps.nparen; | | 576 | ps.line_start_nparen = ps.nparen; |
589 | | | 577 | |
590 | unbalanced: | | 578 | unbalanced: |
591 | buf_add_char(&code, token.s[0]); | | 579 | buf_add_char(&code, token.s[0]); |
592 | } | | 580 | } |
593 | | | 581 | |
594 | static bool | | | |
595 | want_blank_before_unary_op(void) | | | |
596 | { | | | |
597 | if (ps.want_blank) | | | |
598 | return true; | | | |
599 | if (token.s[0] == '+' || token.s[0] == '-') | | | |
600 | return code.len > 0 && code.s[code.len - 1] == token.s[0]; | | | |
601 | return false; | | | |
602 | } | | | |
603 | | | | |
604 | static void | | 582 | static void |
605 | process_unary_op(void) | | 583 | process_unary_op(void) |
606 | { | | 584 | { |
607 | if (!ps.decl_indent_done && ps.in_decl && !ps.block_init && | | 585 | if (is_function_pointer_declaration()) { |
608 | !ps.is_function_definition && ps.line_start_nparen == 0) { | | 586 | int ind = ps.decl_ind - (int)token.len; |
609 | /* pointer declarations */ | | 587 | indent_declarator(ind, ps.tabs_to_var); |
610 | code_add_decl_indent(ps.decl_ind - (int)token.len, | | 588 | ps.want_blank = false; |
611 | ps.tabs_to_var); | | 589 | } else if ((token.s[0] == '+' || token.s[0] == '-') |
612 | ps.decl_indent_done = true; | | 590 | && code.len > 0 && code.s[code.len - 1] == token.s[0]) |
613 | } else if (want_blank_before_unary_op()) | | 591 | ps.want_blank = true; |
614 | buf_add_char(&code, ' '); | | | |
615 | | | | |
616 | buf_add_buf(&code, &token); | | | |
617 | ps.want_blank = false; | | | |
618 | } | | | |
619 | | | 592 | |
620 | static void | | 593 | if (ps.want_blank) |
621 | process_binary_op(void) | | | |
622 | { | | | |
623 | if (code.len > 0 && ps.want_blank) | | | |
624 | buf_add_char(&code, ' '); | | 594 | buf_add_char(&code, ' '); |
625 | buf_add_buf(&code, &token); | | 595 | buf_add_buf(&code, &token); |
626 | ps.want_blank = true; | | 596 | ps.want_blank = false; |
627 | } | | 597 | } |
628 | | | 598 | |
629 | static void | | 599 | static void |
630 | process_postfix_op(void) | | 600 | process_postfix_op(void) |
631 | { | | 601 | { |
632 | buf_add_buf(&code, &token); | | 602 | buf_add_buf(&code, &token); |
633 | ps.want_blank = true; | | 603 | ps.want_blank = true; |
634 | } | | 604 | } |
635 | | | 605 | |
636 | static void | | 606 | static void |
637 | process_question(void) | | 607 | process_question(void) |
638 | { | | 608 | { |
639 | ps.quest_level++; | | 609 | ps.quest_level++; |
640 | if (code.len == 0) { | | 610 | if (code.len == 0) { |
641 | ps.in_stmt_cont = true; | | 611 | ps.in_stmt_cont = true; |
642 | ps.in_stmt_or_decl = true; | | 612 | ps.in_stmt_or_decl = true; |
643 | ps.in_decl = false; | | 613 | ps.in_decl = false; |
644 | } | | 614 | } |
645 | if (ps.want_blank) | | | |
646 | buf_add_char(&code, ' '); | | | |
647 | buf_add_char(&code, '?'); | | | |
648 | ps.want_blank = true; | | | |
649 | } | | 615 | } |
650 | | | 616 | |
651 | static void | | 617 | static void |
652 | process_colon_question(void) | | 618 | process_colon_question(void) |
653 | { | | 619 | { |
654 | if (code.len == 0) { | | 620 | if (code.len == 0) { |
655 | ps.in_stmt_cont = true; | | 621 | ps.in_stmt_cont = true; |
656 | ps.in_stmt_or_decl = true; | | 622 | ps.in_stmt_or_decl = true; |
657 | ps.in_decl = false; | | 623 | ps.in_decl = false; |
658 | } | | 624 | } |
659 | if (ps.want_blank) | | | |
660 | buf_add_char(&code, ' '); | | | |
661 | buf_add_char(&code, ':'); | | | |
662 | ps.want_blank = true; | | | |
663 | } | | 625 | } |
664 | | | 626 | |
665 | static void | | 627 | static void |
666 | process_colon_label(void) | | 628 | process_colon_label(void) |
667 | { | | 629 | { |
668 | buf_add_buf(&lab, &code); | | 630 | buf_add_buf(&lab, &code); |
669 | buf_add_char(&lab, ':'); | | 631 | buf_add_char(&lab, ':'); |
670 | code.len = 0; | | 632 | code.len = 0; |
671 | | | 633 | |
672 | if (ps.seen_case) | | 634 | if (ps.seen_case) |
673 | out.line_kind = lk_case_or_default; | | 635 | out.line_kind = lk_case_or_default; |
674 | ps.in_stmt_or_decl = false; | | 636 | ps.in_stmt_or_decl = false; |
675 | ps.force_nl = ps.seen_case; | | 637 | ps.force_nl = ps.seen_case; |
| @@ -692,28 +654,27 @@ process_semicolon(void) | | | @@ -692,28 +654,27 @@ process_semicolon(void) |
692 | if (ps.decl_level == 0) | | 654 | if (ps.decl_level == 0) |
693 | ps.init_or_struct = false; | | 655 | ps.init_or_struct = false; |
694 | ps.seen_case = false; /* only needs to be reset on error */ | | 656 | ps.seen_case = false; /* only needs to be reset on error */ |
695 | ps.quest_level = 0; /* only needs to be reset on error */ | | 657 | ps.quest_level = 0; /* only needs to be reset on error */ |
696 | if (ps.prev_lsym == lsym_rparen) | | 658 | if (ps.prev_lsym == lsym_rparen) |
697 | ps.in_func_def_params = false; | | 659 | ps.in_func_def_params = false; |
698 | ps.block_init = false; | | 660 | ps.block_init = false; |
699 | ps.block_init_level = 0; | | 661 | ps.block_init_level = 0; |
700 | ps.declaration = ps.declaration == decl_begin ? decl_end : decl_no; | | 662 | ps.declaration = ps.declaration == decl_begin ? decl_end : decl_no; |
701 | | | 663 | |
702 | if (ps.in_decl && code.len == 0 && !ps.block_init && | | 664 | if (ps.in_decl && code.len == 0 && !ps.block_init && |
703 | !ps.decl_indent_done && ps.line_start_nparen == 0) { | | 665 | !ps.decl_indent_done && ps.line_start_nparen == 0) { |
704 | /* indent stray semicolons in declarations */ | | 666 | /* indent stray semicolons in declarations */ |
705 | code_add_decl_indent(ps.decl_ind - 1, ps.tabs_to_var); | | 667 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); |
706 | ps.decl_indent_done = true; | | | |
707 | } | | 668 | } |
708 | | | 669 | |
709 | ps.in_decl = ps.decl_level > 0; /* if we were in a first level | | 670 | ps.in_decl = ps.decl_level > 0; /* if we were in a first level |
710 | * structure declaration before, we | | 671 | * structure declaration before, we |
711 | * aren't anymore */ | | 672 | * aren't anymore */ |
712 | | | 673 | |
713 | if (ps.nparen > 0 && ps.spaced_expr_psym != psym_for_exprs) { | | 674 | if (ps.nparen > 0 && ps.spaced_expr_psym != psym_for_exprs) { |
714 | /* There were unbalanced parentheses in the statement. It is a | | 675 | /* There were unbalanced parentheses in the statement. It is a |
715 | * bit complicated, because the semicolon might be in a for | | 676 | * bit complicated, because the semicolon might be in a for |
716 | * statement. */ | | 677 | * statement. */ |
717 | diag(1, "Unbalanced parentheses"); | | 678 | diag(1, "Unbalanced parentheses"); |
718 | ps.nparen = 0; | | 679 | ps.nparen = 0; |
719 | if (ps.spaced_expr_psym != psym_0) { | | 680 | if (ps.spaced_expr_psym != psym_0) { |
| @@ -813,27 +774,27 @@ process_rbrace(void) | | | @@ -813,27 +774,27 @@ process_rbrace(void) |
813 | ps.nparen = 0; | | 774 | ps.nparen = 0; |
814 | ps.spaced_expr_psym = psym_0; | | 775 | ps.spaced_expr_psym = psym_0; |
815 | } | | 776 | } |
816 | | | 777 | |
817 | ps.declaration = decl_no; | | 778 | ps.declaration = decl_no; |
818 | if (ps.block_init_level > 0) | | 779 | if (ps.block_init_level > 0) |
819 | ps.block_init_level--; | | 780 | ps.block_init_level--; |
820 | | | 781 | |
821 | if (code.len > 0 && !ps.block_init) | | 782 | if (code.len > 0 && !ps.block_init) |
822 | output_line(); | | 783 | output_line(); |
823 | | | 784 | |
824 | buf_add_char(&code, '}'); | | 785 | buf_add_char(&code, '}'); |
825 | ps.want_blank = true; | | 786 | ps.want_blank = true; |
826 | ps.in_stmt_or_decl = false; | | 787 | ps.in_stmt_or_decl = false; // XXX: Initializers don't end a stmt |
827 | ps.in_stmt_cont = false; | | 788 | ps.in_stmt_cont = false; |
828 | | | 789 | |
829 | if (ps.decl_level > 0) { /* multi-level structure declaration */ | | 790 | if (ps.decl_level > 0) { /* multi-level structure declaration */ |
830 | ps.decl_ind = ps.di_stack[--ps.decl_level]; | | 791 | ps.decl_ind = ps.di_stack[--ps.decl_level]; |
831 | if (ps.decl_level == 0 && !ps.in_func_def_params) { | | 792 | if (ps.decl_level == 0 && !ps.in_func_def_params) { |
832 | ps.declaration = decl_begin; | | 793 | ps.declaration = decl_begin; |
833 | ps.decl_ind = ps.ind_level == 0 | | 794 | ps.decl_ind = ps.ind_level == 0 |
834 | ? opt.decl_indent : opt.local_decl_indent; | | 795 | ? opt.decl_indent : opt.local_decl_indent; |
835 | } | | 796 | } |
836 | ps.in_decl = true; | | 797 | ps.in_decl = true; |
837 | } | | 798 | } |
838 | | | 799 | |
839 | if (ps.psyms.top == 2) | | 800 | if (ps.psyms.top == 2) |
| @@ -868,30 +829,28 @@ process_else(void) | | | @@ -868,30 +829,28 @@ process_else(void) |
868 | if (code.len > 0 | | 829 | if (code.len > 0 |
869 | && !(opt.cuddle_else && code.s[code.len - 1] == '}')) | | 830 | && !(opt.cuddle_else && code.s[code.len - 1] == '}')) |
870 | output_line(); | | 831 | output_line(); |
871 | | | 832 | |
872 | ps.force_nl = true; | | 833 | ps.force_nl = true; |
873 | parse(psym_else); | | 834 | parse(psym_else); |
874 | } | | 835 | } |
875 | | | 836 | |
876 | static void | | 837 | static void |
877 | process_type(void) | | 838 | process_type(void) |
878 | { | | 839 | { |
879 | parse(psym_decl); /* let the parser worry about indentation */ | | 840 | parse(psym_decl); /* let the parser worry about indentation */ |
880 | | | 841 | |
881 | if (ps.prev_lsym == lsym_rparen && ps.psyms.top <= 1) { | | 842 | if (ps.prev_lsym == lsym_rparen && ps.psyms.top <= 1 && code.len > 0) |
882 | if (code.len > 0) | | 843 | output_line(); |
883 | output_line(); | | | |
884 | } | | | |
885 | | | 844 | |
886 | if (ps.in_func_def_params && opt.indent_parameters && | | 845 | if (ps.in_func_def_params && opt.indent_parameters && |
887 | ps.decl_level == 0) { | | 846 | ps.decl_level == 0) { |
888 | ps.ind_level = ps.ind_level_follow = 1; | | 847 | ps.ind_level = ps.ind_level_follow = 1; |
889 | ps.in_stmt_cont = false; | | 848 | ps.in_stmt_cont = false; |
890 | } | | 849 | } |
891 | | | 850 | |
892 | ps.init_or_struct = /* maybe */ true; | | 851 | ps.init_or_struct = /* maybe */ true; |
893 | ps.in_decl = ps.decl_on_line = ps.prev_lsym != lsym_typedef; | | 852 | ps.in_decl = ps.decl_on_line = ps.prev_lsym != lsym_typedef; |
894 | if (ps.decl_level <= 0) | | 853 | if (ps.decl_level <= 0) |
895 | ps.declaration = decl_begin; | | 854 | ps.declaration = decl_begin; |
896 | | | 855 | |
897 | int len = (int)token.len + 1; | | 856 | int len = (int)token.len + 1; |
| @@ -908,30 +867,28 @@ process_ident(lexer_symbol lsym) | | | @@ -908,30 +867,28 @@ process_ident(lexer_symbol lsym) |
908 | if (ps.in_decl) { | | 867 | if (ps.in_decl) { |
909 | if (lsym == lsym_funcname) { | | 868 | if (lsym == lsym_funcname) { |
910 | ps.in_decl = false; | | 869 | ps.in_decl = false; |
911 | if (opt.procnames_start_line && code.len > 0) | | 870 | if (opt.procnames_start_line && code.len > 0) |
912 | output_line(); | | 871 | output_line(); |
913 | else if (ps.want_blank) | | 872 | else if (ps.want_blank) |
914 | buf_add_char(&code, ' '); | | 873 | buf_add_char(&code, ' '); |
915 | ps.want_blank = false; | | 874 | ps.want_blank = false; |
916 | | | 875 | |
917 | } else if (!ps.block_init && !ps.decl_indent_done && | | 876 | } else if (!ps.block_init && !ps.decl_indent_done && |
918 | ps.line_start_nparen == 0) { | | 877 | ps.line_start_nparen == 0) { |
919 | if (opt.decl_indent == 0 | | 878 | if (opt.decl_indent == 0 |
920 | && code.len > 0 && code.s[code.len - 1] == '}') | | 879 | && code.len > 0 && code.s[code.len - 1] == '}') |
921 | ps.decl_ind = | | 880 | ps.decl_ind = ind_add(0, code.s, code.len) + 1; |
922 | ind_add(0, code.s, code.len) + 1; | | 881 | indent_declarator(ps.decl_ind, ps.tabs_to_var); |
923 | code_add_decl_indent(ps.decl_ind, ps.tabs_to_var); | | | |
924 | ps.decl_indent_done = true; | | | |
925 | ps.want_blank = false; | | 882 | ps.want_blank = false; |
926 | } | | 883 | } |
927 | | | 884 | |
928 | } else if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { | | 885 | } else if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { |
929 | ps.force_nl = true; | | 886 | ps.force_nl = true; |
930 | ps.next_unary = true; | | 887 | ps.next_unary = true; |
931 | ps.in_stmt_or_decl = false; | | 888 | ps.in_stmt_or_decl = false; |
932 | parse(ps.spaced_expr_psym); | | 889 | parse(ps.spaced_expr_psym); |
933 | ps.spaced_expr_psym = psym_0; | | 890 | ps.spaced_expr_psym = psym_0; |
934 | } | | 891 | } |
935 | } | | 892 | } |
936 | | | 893 | |
937 | static void | | 894 | static void |
| @@ -942,28 +899,27 @@ process_period(void) | | | @@ -942,28 +899,27 @@ process_period(void) |
942 | buf_add_char(&code, '.'); | | 899 | buf_add_char(&code, '.'); |
943 | ps.want_blank = false; | | 900 | ps.want_blank = false; |
944 | } | | 901 | } |
945 | | | 902 | |
946 | static void | | 903 | static void |
947 | process_comma(void) | | 904 | process_comma(void) |
948 | { | | 905 | { |
949 | ps.want_blank = code.len > 0; /* only put blank after comma if comma | | 906 | ps.want_blank = code.len > 0; /* only put blank after comma if comma |
950 | * does not start the line */ | | 907 | * does not start the line */ |
951 | | | 908 | |
952 | if (ps.in_decl && !ps.is_function_definition && !ps.block_init && | | 909 | if (ps.in_decl && !ps.is_function_definition && !ps.block_init && |
953 | !ps.decl_indent_done && ps.line_start_nparen == 0) { | | 910 | !ps.decl_indent_done && ps.line_start_nparen == 0) { |
954 | /* indent leading commas and not the actual identifiers */ | | 911 | /* indent leading commas and not the actual identifiers */ |
955 | code_add_decl_indent(ps.decl_ind - 1, ps.tabs_to_var); | | 912 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); |
956 | ps.decl_indent_done = true; | | | |
957 | } | | 913 | } |
958 | | | 914 | |
959 | buf_add_char(&code, ','); | | 915 | buf_add_char(&code, ','); |
960 | | | 916 | |
961 | if (ps.nparen == 0) { | | 917 | if (ps.nparen == 0) { |
962 | if (ps.block_init_level == 0) | | 918 | if (ps.block_init_level == 0) |
963 | ps.block_init = false; | | 919 | ps.block_init = false; |
964 | int typical_varname_length = 8; | | 920 | int typical_varname_length = 8; |
965 | if (ps.break_after_comma && (opt.break_after_comma || | | 921 | if (ps.break_after_comma && (opt.break_after_comma || |
966 | ind_add(compute_code_indent(), code.s, code.len) | | 922 | ind_add(compute_code_indent(), code.s, code.len) |
967 | >= opt.max_line_length - typical_varname_length)) | | 923 | >= opt.max_line_length - typical_varname_length)) |
968 | ps.force_nl = true; | | 924 | ps.force_nl = true; |
969 | } | | 925 | } |
| @@ -1015,197 +971,115 @@ read_preprocessing_line(void) | | | @@ -1015,197 +971,115 @@ read_preprocessing_line(void) |
1015 | | | 971 | |
1016 | while (lab.len > 0 && ch_isblank(lab.s[lab.len - 1])) | | 972 | while (lab.len > 0 && ch_isblank(lab.s[lab.len - 1])) |
1017 | lab.len--; | | 973 | lab.len--; |
1018 | } | | 974 | } |
1019 | | | 975 | |
1020 | static void | | 976 | static void |
1021 | process_preprocessing(void) | | 977 | process_preprocessing(void) |
1022 | { | | 978 | { |
1023 | if (lab.len > 0 || code.len > 0 || com.len > 0) | | 979 | if (lab.len > 0 || code.len > 0 || com.len > 0) |
1024 | output_line(); | | 980 | output_line(); |
1025 | | | 981 | |
1026 | read_preprocessing_line(); | | 982 | read_preprocessing_line(); |
1027 | | | 983 | |
1028 | const char *end = lab.s + lab.len; | | 984 | const char *dir = lab.s + 1, *line_end = lab.s + lab.len; |
1029 | const char *dir = lab.s + 1; | | 985 | while (dir < line_end && ch_isblank(*dir)) |
1030 | while (dir < end && ch_isblank(*dir)) | | | |
1031 | dir++; | | 986 | dir++; |
1032 | size_t dir_len = 0; | | 987 | size_t dir_len = 0; |
1033 | while (dir + dir_len < end && ch_isalpha(dir[dir_len])) | | 988 | while (dir + dir_len < line_end && ch_isalpha(dir[dir_len])) |
1034 | dir_len++; | | 989 | dir_len++; |
1035 | | | 990 | |
1036 | if (dir_len >= 2 && memcmp(dir, "if", 2) == 0) { | | 991 | if (dir_len >= 2 && memcmp(dir, "if", 2) == 0) { |
1037 | if ((size_t)ifdef_level < array_length(state_stack)) | | 992 | if ((size_t)ifdef_level < array_length(state_stack)) |
1038 | state_stack[ifdef_level++] = ps; | | 993 | state_stack[ifdef_level++] = ps; |
1039 | else | | 994 | else |
1040 | diag(1, "#if stack overflow"); | | 995 | diag(1, "#if stack overflow"); |
1041 | out.line_kind = lk_if; | | 996 | out.line_kind = lk_if; |
1042 | | | 997 | |
1043 | } else if (dir_len >= 2 && memcmp(dir, "el", 2) == 0) { | | 998 | } else if (dir_len >= 2 && memcmp(dir, "el", 2) == 0) { |
1044 | if (ifdef_level <= 0) | | 999 | if (ifdef_level <= 0) |
1045 | diag(1, dir[2] == 'i' | | 1000 | diag(1, dir[2] == 'i' |
1046 | ? "Unmatched #elif" : "Unmatched #else"); | | 1001 | ? "Unmatched #elif" : "Unmatched #else"); |
1047 | else | | 1002 | else |
1048 | ps = state_stack[ifdef_level - 1]; | | 1003 | ps = state_stack[ifdef_level - 1]; |
1049 | | | 1004 | |
1050 | } else if (dir_len == 5 && memcmp(dir, "endif", 5) == 0) { | | 1005 | } else if (dir_len == 5 && memcmp(dir, "endif", 5) == 0) { |
1051 | if (ifdef_level <= 0) | | 1006 | if (ifdef_level <= 0) |
1052 | diag(1, "Unmatched #endif"); | | 1007 | diag(1, "Unmatched #endif"); |
1053 | else | | 1008 | else |
1054 | ifdef_level--; | | 1009 | ifdef_level--; |
1055 | out.line_kind = lk_endif; | | 1010 | out.line_kind = lk_endif; |
1056 | } | | 1011 | } |
1057 | | | | |
1058 | /* subsequent processing of the newline character will cause the line | | | |
1059 | * to be printed */ | | | |
1060 | } | | 1012 | } |
1061 | | | 1013 | |
1062 | static void | | 1014 | static void |
1063 | process_lsym(lexer_symbol lsym) | | 1015 | process_lsym(lexer_symbol lsym) |
1064 | { | | 1016 | { |
1065 | switch (lsym) { | | 1017 | switch (lsym) { |
1066 | | | 1018 | /* INDENT OFF */ |
1067 | case lsym_newline: | | 1019 | case lsym_preprocessing: process_preprocessing(); break; |
1068 | process_newline(); | | 1020 | case lsym_newline: process_newline(); break; |
1069 | break; | | 1021 | case lsym_comment: process_comment(); break; |
1070 | | | 1022 | case lsym_lparen: process_lparen(); break; |
1071 | case lsym_lparen: | | 1023 | case lsym_lbracket: process_lbracket(); break; |
1072 | process_lparen(); | | 1024 | case lsym_rparen: process_rparen(); break; |
1073 | break; | | 1025 | case lsym_rbracket: process_rbracket(); break; |
1074 | | | 1026 | case lsym_lbrace: process_lbrace(); break; |
1075 | case lsym_lbracket: | | 1027 | case lsym_rbrace: process_rbrace(); break; |
1076 | process_lbracket(); | | 1028 | case lsym_period: process_period(); break; |
1077 | break; | | 1029 | case lsym_unary_op: process_unary_op(); break; |
1078 | | | 1030 | case lsym_postfix_op: process_postfix_op(); break; |
1079 | case lsym_rparen: | | 1031 | case lsym_binary_op: goto copy_token; |
1080 | process_rparen(); | | 1032 | case lsym_question: process_question(); goto copy_token; |
1081 | break; | | 1033 | case lsym_colon_question: process_colon_question(); goto copy_token; |
1082 | | | 1034 | case lsym_colon_label: process_colon_label(); break; |
1083 | case lsym_rbracket: | | 1035 | case lsym_colon_other: process_colon_other(); break; |
1084 | process_rbracket(); | | 1036 | case lsym_comma: process_comma(); break; |
1085 | break; | | 1037 | case lsym_semicolon: process_semicolon(); break; |
1086 | | | 1038 | case lsym_typedef: goto copy_token; |
1087 | case lsym_unary_op: | | 1039 | case lsym_modifier: goto copy_token; |
1088 | process_unary_op(); | | 1040 | case lsym_case: ps.seen_case = true; goto copy_token; |
1089 | break; | | 1041 | case lsym_default: ps.seen_case = true; goto copy_token; |
1090 | | | 1042 | case lsym_do: process_do(); goto copy_token; |
1091 | case lsym_binary_op: | | 1043 | case lsym_else: process_else(); goto copy_token; |
1092 | process_binary_op(); | | 1044 | case lsym_for: ps.spaced_expr_psym = psym_for_exprs; goto copy_token; |
1093 | break; | | 1045 | case lsym_if: ps.spaced_expr_psym = psym_if_expr; goto copy_token; |
1094 | | | 1046 | case lsym_switch: ps.spaced_expr_psym = psym_switch_expr; goto copy_token; |
1095 | case lsym_postfix_op: | | 1047 | case lsym_while: ps.spaced_expr_psym = psym_while_expr; goto copy_token; |
1096 | process_postfix_op(); | | 1048 | /* INDENT ON */ |
1097 | break; | | | |
1098 | | | | |
1099 | case lsym_question: | | | |
1100 | process_question(); | | | |
1101 | break; | | | |
1102 | | | | |
1103 | case lsym_case: | | | |
1104 | case lsym_default: | | | |
1105 | ps.seen_case = true; | | | |
1106 | goto copy_token; | | | |
1107 | | | | |
1108 | case lsym_colon_question: | | | |
1109 | process_colon_question(); | | | |
1110 | break; | | | |
1111 | | | | |
1112 | case lsym_colon_label: | | | |
1113 | process_colon_label(); | | | |
1114 | break; | | | |
1115 | | | | |
1116 | case lsym_colon_other: | | | |
1117 | process_colon_other(); | | | |
1118 | break; | | | |
1119 | | | | |
1120 | case lsym_semicolon: | | | |
1121 | process_semicolon(); | | | |
1122 | break; | | | |
1123 | | | | |
1124 | case lsym_lbrace: | | | |
1125 | process_lbrace(); | | | |
1126 | break; | | | |
1127 | | | | |
1128 | case lsym_rbrace: | | | |
1129 | process_rbrace(); | | | |
1130 | break; | | | |
1131 | | | | |
1132 | case lsym_switch: | | | |
1133 | ps.spaced_expr_psym = psym_switch_expr; | | | |
1134 | goto copy_token; | | | |
1135 | | | | |
1136 | case lsym_for: | | | |
1137 | ps.spaced_expr_psym = psym_for_exprs; | | | |
1138 | goto copy_token; | | | |
1139 | | | | |
1140 | case lsym_if: | | | |
1141 | ps.spaced_expr_psym = psym_if_expr; | | | |
1142 | goto copy_token; | | | |
1143 | | | | |
1144 | case lsym_while: | | | |
1145 | ps.spaced_expr_psym = psym_while_expr; | | | |
1146 | goto copy_token; | | | |
1147 | | | | |
1148 | case lsym_do: | | | |
1149 | process_do(); | | | |
1150 | goto copy_token; | | | |
1151 | | | | |
1152 | case lsym_else: | | | |
1153 | process_else(); | | | |
1154 | goto copy_token; | | | |
1155 | | | | |
1156 | case lsym_typedef: | | | |
1157 | case lsym_modifier: | | | |
1158 | goto copy_token; | | | |
1159 | | | 1049 | |
1160 | case lsym_tag: | | 1050 | case lsym_tag: |
1161 | if (ps.nparen > 0) | | 1051 | if (ps.nparen > 0) |
1162 | goto copy_token; | | 1052 | goto copy_token; |
1163 | /* FALLTHROUGH */ | | 1053 | /* FALLTHROUGH */ |
1164 | case lsym_type_outside_parentheses: | | 1054 | case lsym_type_outside_parentheses: |
1165 | process_type(); | | 1055 | process_type(); |
1166 | goto copy_token; | | 1056 | goto copy_token; |
1167 | | | 1057 | |
1168 | case lsym_type_in_parentheses: | | 1058 | case lsym_type_in_parentheses: |
1169 | case lsym_offsetof: | | | |
1170 | case lsym_sizeof: | | 1059 | case lsym_sizeof: |
| | | 1060 | case lsym_offsetof: |
1171 | case lsym_word: | | 1061 | case lsym_word: |
1172 | case lsym_funcname: | | 1062 | case lsym_funcname: |
1173 | case lsym_return: | | 1063 | case lsym_return: |
1174 | process_ident(lsym); | | 1064 | process_ident(lsym); |
1175 | copy_token: | | 1065 | copy_token: |
1176 | if (ps.want_blank) | | 1066 | if (ps.want_blank) |
1177 | buf_add_char(&code, ' '); | | 1067 | buf_add_char(&code, ' '); |
1178 | buf_add_buf(&code, &token); | | 1068 | buf_add_buf(&code, &token); |
1179 | if (lsym != lsym_funcname) | | 1069 | if (lsym != lsym_funcname) |
1180 | ps.want_blank = true; | | 1070 | ps.want_blank = true; |
1181 | break; | | 1071 | break; |
1182 | | | 1072 | |
1183 | case lsym_period: | | | |
1184 | process_period(); | | | |
1185 | break; | | | |
1186 | | | | |
1187 | case lsym_comma: | | | |
1188 | process_comma(); | | | |
1189 | break; | | | |
1190 | | | | |
1191 | case lsym_preprocessing: | | | |
1192 | process_preprocessing(); | | | |
1193 | break; | | | |
1194 | | | | |
1195 | case lsym_comment: | | | |
1196 | process_comment(); | | | |
1197 | break; | | | |
1198 | | | | |
1199 | default: | | 1073 | default: |
1200 | break; | | 1074 | break; |
1201 | } | | 1075 | } |
1202 | } | | 1076 | } |
1203 | | | 1077 | |
1204 | static int | | 1078 | static int |
1205 | indent(void) | | 1079 | indent(void) |
1206 | { | | 1080 | { |
1207 | debug_parser_state(); | | 1081 | debug_parser_state(); |
1208 | | | 1082 | |
1209 | for (;;) { /* loop until we reach eof */ | | 1083 | for (;;) { /* loop until we reach eof */ |
1210 | lexer_symbol lsym = lexi(); | | 1084 | lexer_symbol lsym = lexi(); |
1211 | | | 1085 | |
| @@ -1218,35 +1092,31 @@ indent(void) | | | @@ -1218,35 +1092,31 @@ indent(void) |
1218 | if (lsym == lsym_eof) | | 1092 | if (lsym == lsym_eof) |
1219 | return process_eof(); | | 1093 | return process_eof(); |
1220 | | | 1094 | |
1221 | if (lsym == lsym_if && ps.prev_lsym == lsym_else | | 1095 | if (lsym == lsym_if && ps.prev_lsym == lsym_else |
1222 | && opt.else_if_in_same_line) | | 1096 | && opt.else_if_in_same_line) |
1223 | ps.force_nl = false; | | 1097 | ps.force_nl = false; |
1224 | | | 1098 | |
1225 | if (lsym == lsym_newline || lsym == lsym_preprocessing) | | 1099 | if (lsym == lsym_newline || lsym == lsym_preprocessing) |
1226 | ps.force_nl = false; | | 1100 | ps.force_nl = false; |
1227 | else if (lsym == lsym_comment) { | | 1101 | else if (lsym == lsym_comment) { |
1228 | /* no special processing */ | | 1102 | /* no special processing */ |
1229 | } else { | | 1103 | } else { |
1230 | maybe_break_line(lsym); | | 1104 | maybe_break_line(lsym); |
1231 | /* | | | |
1232 | * Add an extra level of indentation; turned off again | | | |
1233 | * by a ';' or '}'. | | | |
1234 | */ | | | |
1235 | ps.in_stmt_or_decl = true; | | 1105 | ps.in_stmt_or_decl = true; |
1236 | if (com.len > 0) | | 1106 | if (com.len > 0) |
1237 | move_com_to_code(lsym); | | 1107 | move_com_to_code(lsym); |
1238 | update_ps_decl_ptr(lsym); | | 1108 | update_ps_decl_ptr(lsym); |
1239 | update_ps_prev_tag(lsym); | | 1109 | update_ps_lbrace_kind(lsym); |
1240 | } | | 1110 | } |
1241 | | | 1111 | |
1242 | process_lsym(lsym); | | 1112 | process_lsym(lsym); |
1243 | | | 1113 | |
1244 | debug_parser_state(); | | 1114 | debug_parser_state(); |
1245 | | | 1115 | |
1246 | if (lsym != lsym_comment && lsym != lsym_newline && | | 1116 | if (lsym != lsym_comment && lsym != lsym_newline && |
1247 | lsym != lsym_preprocessing) | | 1117 | lsym != lsym_preprocessing) |
1248 | ps.prev_lsym = lsym; | | 1118 | ps.prev_lsym = lsym; |
1249 | } | | 1119 | } |
1250 | } | | 1120 | } |
1251 | | | 1121 | |
1252 | int | | 1122 | int |