Tue Mar 9 19:23:08 2021 UTC ()
indent: rename a few more token types

The previous names were either too short or ambiguous.

No functional change.


(rillig)
diff -r1.38 -r1.39 src/usr.bin/indent/indent.c
diff -r1.10 -r1.11 src/usr.bin/indent/indent_codes.h
diff -r1.30 -r1.31 src/usr.bin/indent/lexi.c

cvs diff -r1.38 -r1.39 src/usr.bin/indent/indent.c (expand / switch to unified diff)

--- src/usr.bin/indent/indent.c 2021/03/09 19:14:39 1.38
+++ src/usr.bin/indent/indent.c 2021/03/09 19:23:08 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $ */ 1/* $NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 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
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
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#if 0 40#if 0
41#ifndef lint 41#ifndef lint
42static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; 42static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
43#endif /* not lint */ 43#endif /* not lint */
44#endif 44#endif
45 45
46#include <sys/cdefs.h> 46#include <sys/cdefs.h>
47#ifndef lint 47#ifndef lint
48#if defined(__NetBSD__) 48#if defined(__NetBSD__)
49__RCSID("$NetBSD: indent.c,v 1.38 2021/03/09 19:14:39 rillig Exp $"); 49__RCSID("$NetBSD: indent.c,v 1.39 2021/03/09 19:23:08 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
52#endif 52#endif
53#endif 53#endif
54 54
55#include <sys/param.h> 55#include <sys/param.h>
56#if HAVE_CAPSICUM 56#if HAVE_CAPSICUM
57#include <sys/capsicum.h> 57#include <sys/capsicum.h>
58#include <capsicum_helpers.h> 58#include <capsicum_helpers.h>
59#endif 59#endif
60#include <err.h> 60#include <err.h>
61#include <errno.h> 61#include <errno.h>
62#include <fcntl.h> 62#include <fcntl.h>
@@ -585,27 +585,27 @@ check_type: @@ -585,27 +585,27 @@ check_type:
585 585
586 if (opt.verbose) { 586 if (opt.verbose) {
587 printf("There were %d output lines and %d comments\n", 587 printf("There were %d output lines and %d comments\n",
588 ps.out_lines, ps.out_coms); 588 ps.out_lines, ps.out_coms);
589 printf("(Lines with comments)/(Lines with code): %6.3f\n", 589 printf("(Lines with comments)/(Lines with code): %6.3f\n",
590 (1.0 * ps.com_lines) / code_lines); 590 (1.0 * ps.com_lines) / code_lines);
591 } 591 }
592 fflush(output); 592 fflush(output);
593 exit(found_err); 593 exit(found_err);
594 } 594 }
595 if ( 595 if (
596 (type_code != comment) && 596 (type_code != comment) &&
597 (type_code != newline) && 597 (type_code != newline) &&
598 (type_code != preesc) && 598 (type_code != preprocessing) &&
599 (type_code != form_feed)) { 599 (type_code != form_feed)) {
600 if (force_nl && 600 if (force_nl &&
601 (type_code != semicolon) && 601 (type_code != semicolon) &&
602 (type_code != lbrace || !opt.btype_2)) { 602 (type_code != lbrace || !opt.btype_2)) {
603 /* we should force a broken line here */ 603 /* we should force a broken line here */
604 if (opt.verbose) 604 if (opt.verbose)
605 diag(0, "Line broken"); 605 diag(0, "Line broken");
606 dump_line(); 606 dump_line();
607 ps.want_blank = false; /* dont insert blank at line start */ 607 ps.want_blank = false; /* dont insert blank at line start */
608 force_nl = false; 608 force_nl = false;
609 } 609 }
610 ps.in_stmt = true; /* turn on flag which causes an extra level of 610 ps.in_stmt = true; /* turn on flag which causes an extra level of
611 * indentation. this is turned off by a ; or 611 * indentation. this is turned off by a ; or
@@ -760,27 +760,27 @@ check_type: @@ -760,27 +760,27 @@ check_type:
760 case binary_op: /* any binary operation */ 760 case binary_op: /* any binary operation */
761 { 761 {
762 int len = e_token - s_token; 762 int len = e_token - s_token;
763 763
764 check_size_code(len + 1); 764 check_size_code(len + 1);
765 if (ps.want_blank) 765 if (ps.want_blank)
766 *e_code++ = ' '; 766 *e_code++ = ' ';
767 memcpy(e_code, token, len); 767 memcpy(e_code, token, len);
768 e_code += len; 768 e_code += len;
769 } 769 }
770 ps.want_blank = true; 770 ps.want_blank = true;
771 break; 771 break;
772 772
773 case postop: /* got a trailing ++ or -- */ 773 case postfix_op: /* got a trailing ++ or -- */
774 *e_code++ = token[0]; 774 *e_code++ = token[0];
775 *e_code++ = token[1]; 775 *e_code++ = token[1];
776 ps.want_blank = true; 776 ps.want_blank = true;
777 break; 777 break;
778 778
779 case question: /* got a ? */ 779 case question: /* got a ? */
780 squest++; /* this will be used when a later colon 780 squest++; /* this will be used when a later colon
781 * appears so we can distinguish the 781 * appears so we can distinguish the
782 * <c>?<n>:<n> construct */ 782 * <c>?<n>:<n> construct */
783 if (ps.want_blank) 783 if (ps.want_blank)
784 *e_code++ = ' '; 784 *e_code++ = ' ';
785 *e_code++ = '?'; 785 *e_code++ = '?';
786 ps.want_blank = true; 786 ps.want_blank = true;
@@ -1022,31 +1022,31 @@ check_type: @@ -1022,31 +1022,31 @@ check_type:
1022 if (e_code != s_code) { /* make sure this starts a line */ 1022 if (e_code != s_code) { /* make sure this starts a line */
1023 if (opt.verbose) 1023 if (opt.verbose)
1024 diag(0, "Line broken"); 1024 diag(0, "Line broken");
1025 dump_line(); 1025 dump_line();
1026 ps.want_blank = false; 1026 ps.want_blank = false;
1027 } 1027 }
1028 force_nl = true;/* also, following stuff must go onto new line */ 1028 force_nl = true;/* also, following stuff must go onto new line */
1029 last_else = 0; 1029 last_else = 0;
1030 parse(keyword_do); 1030 parse(keyword_do);
1031 } 1031 }
1032 goto copy_id; /* move the token into line */ 1032 goto copy_id; /* move the token into line */
1033 1033
1034 case type_def: 1034 case type_def:
1035 case storage: 1035 case storage_class:
1036 prefix_blankline_requested = 0; 1036 prefix_blankline_requested = 0;
1037 goto copy_id; 1037 goto copy_id;
1038 1038
1039 case structure: 1039 case keyword_struct_union_enum:
1040 if (ps.p_l_follow > 0) 1040 if (ps.p_l_follow > 0)
1041 goto copy_id; 1041 goto copy_id;
1042 /* FALLTHROUGH */ 1042 /* FALLTHROUGH */
1043 case decl: /* we have a declaration type (int, etc.) */ 1043 case decl: /* we have a declaration type (int, etc.) */
1044 parse(decl); /* let parser worry about indentation */ 1044 parse(decl); /* let parser worry about indentation */
1045 if (ps.last_token == rparen && ps.tos <= 1) { 1045 if (ps.last_token == rparen && ps.tos <= 1) {
1046 if (s_code != e_code) { 1046 if (s_code != e_code) {
1047 dump_line(); 1047 dump_line();
1048 ps.want_blank = 0; 1048 ps.want_blank = 0;
1049 } 1049 }
1050 } 1050 }
1051 if (ps.in_parameter_declaration && opt.indent_parameters && ps.dec_nest == 0) { 1051 if (ps.in_parameter_declaration && opt.indent_parameters && ps.dec_nest == 0) {
1052 ps.ind_level = ps.i_l_follow = 1; 1052 ps.ind_level = ps.i_l_follow = 1;
@@ -1104,27 +1104,27 @@ check_type: @@ -1104,27 +1104,27 @@ check_type:
1104 { 1104 {
1105 int len = e_token - s_token; 1105 int len = e_token - s_token;
1106 1106
1107 check_size_code(len + 1); 1107 check_size_code(len + 1);
1108 if (ps.want_blank) 1108 if (ps.want_blank)
1109 *e_code++ = ' '; 1109 *e_code++ = ' ';
1110 memcpy(e_code, s_token, len); 1110 memcpy(e_code, s_token, len);
1111 e_code += len; 1111 e_code += len;
1112 } 1112 }
1113 if (type_code != funcname) 1113 if (type_code != funcname)
1114 ps.want_blank = true; 1114 ps.want_blank = true;
1115 break; 1115 break;
1116 1116
1117 case strpfx: 1117 case string_prefix:
1118 { 1118 {
1119 int len = e_token - s_token; 1119 int len = e_token - s_token;
1120 1120
1121 check_size_code(len + 1); 1121 check_size_code(len + 1);
1122 if (ps.want_blank) 1122 if (ps.want_blank)
1123 *e_code++ = ' '; 1123 *e_code++ = ' ';
1124 memcpy(e_code, token, len); 1124 memcpy(e_code, token, len);
1125 e_code += len; 1125 e_code += len;
1126 } 1126 }
1127 ps.want_blank = false; 1127 ps.want_blank = false;
1128 break; 1128 break;
1129 1129
1130 case period: /* treat a period kind of like a binary 1130 case period: /* treat a period kind of like a binary
@@ -1144,27 +1144,27 @@ check_type: @@ -1144,27 +1144,27 @@ check_type:
1144 ps.dumped_decl_indent = true; 1144 ps.dumped_decl_indent = true;
1145 } 1145 }
1146 *e_code++ = ','; 1146 *e_code++ = ',';
1147 if (ps.p_l_follow == 0) { 1147 if (ps.p_l_follow == 0) {
1148 if (ps.block_init_level <= 0) 1148 if (ps.block_init_level <= 0)
1149 ps.block_init = 0; 1149 ps.block_init = 0;
1150 if (break_comma && (!opt.leave_comma || 1150 if (break_comma && (!opt.leave_comma ||
1151 count_spaces_until(compute_code_target(), s_code, e_code) > 1151 count_spaces_until(compute_code_target(), s_code, e_code) >
1152 opt.max_col - opt.tabsize)) 1152 opt.max_col - opt.tabsize))
1153 force_nl = true; 1153 force_nl = true;
1154 } 1154 }
1155 break; 1155 break;
1156 1156
1157 case preesc: /* got the character '#' */ 1157 case preprocessing: /* '#' */
1158 if ((s_com != e_com) || 1158 if ((s_com != e_com) ||
1159 (s_lab != e_lab) || 1159 (s_lab != e_lab) ||
1160 (s_code != e_code)) 1160 (s_code != e_code))
1161 dump_line(); 1161 dump_line();
1162 check_size_label(1); 1162 check_size_label(1);
1163 *e_lab++ = '#'; /* move whole line to 'label' buffer */ 1163 *e_lab++ = '#'; /* move whole line to 'label' buffer */
1164 { 1164 {
1165 int in_comment = 0; 1165 int in_comment = 0;
1166 int com_start = 0; 1166 int com_start = 0;
1167 char quote = 0; 1167 char quote = 0;
1168 int com_end = 0; 1168 int com_end = 0;
1169 1169
1170 while (*buf_ptr == ' ' || *buf_ptr == '\t') { 1170 while (*buf_ptr == ' ' || *buf_ptr == '\t') {
@@ -1298,27 +1298,29 @@ check_type: @@ -1298,27 +1298,29 @@ check_type:
1298 } 1298 }
1299 break; /* subsequent processing of the newline 1299 break; /* subsequent processing of the newline
1300 * character will cause the line to be printed */ 1300 * character will cause the line to be printed */
1301 1301
1302 case comment: /* we have gotten a / followed by * this is a biggie */ 1302 case comment: /* we have gotten a / followed by * this is a biggie */
1303 pr_comment(); 1303 pr_comment();
1304 break; 1304 break;
1305 1305
1306 default: 1306 default:
1307 break; 1307 break;
1308 } /* end of big switch stmt */ 1308 } /* end of big switch stmt */
1309 1309
1310 *e_code = '\0'; /* make sure code section is null terminated */ 1310 *e_code = '\0'; /* make sure code section is null terminated */
1311 if (type_code != comment && type_code != newline && type_code != preesc) 1311 if (type_code != comment &&
 1312 type_code != newline &&
 1313 type_code != preprocessing)
1312 ps.last_token = type_code; 1314 ps.last_token = type_code;
1313 } /* end of main while (1) loop */ 1315 } /* end of main while (1) loop */
1314} 1316}
1315 1317
1316/* 1318/*
1317 * copy input file to backup file if in_name is /blah/blah/blah/file, then 1319 * copy input file to backup file if in_name is /blah/blah/blah/file, then
1318 * backup file will be ".Bfile" then make the backup file the input and 1320 * backup file will be ".Bfile" then make the backup file the input and
1319 * original input file the output 1321 * original input file the output
1320 */ 1322 */
1321static void 1323static void
1322bakcopy(void) 1324bakcopy(void)
1323{ 1325{
1324 int n, 1326 int n,

cvs diff -r1.10 -r1.11 src/usr.bin/indent/Attic/indent_codes.h (expand / switch to unified diff)

--- src/usr.bin/indent/Attic/indent_codes.h 2021/03/09 19:14:39 1.10
+++ src/usr.bin/indent/Attic/indent_codes.h 2021/03/09 19:23:08 1.11
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent_codes.h,v 1.10 2021/03/09 19:14:39 rillig Exp $ */ 1/* $NetBSD: indent_codes.h,v 1.11 2021/03/09 19:23:08 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) 1980, 1993 7 * Copyright (c) 1980, 1993
8 * The Regents of the University of California. All rights reserved. 8 * The Regents of the University of California. All rights reserved.
9 * All rights reserved. 9 * 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
@@ -37,46 +37,46 @@ @@ -37,46 +37,46 @@
37 * SUCH DAMAGE. 37 * SUCH DAMAGE.
38 * 38 *
39 * @(#)indent_codes.h 8.1 (Berkeley) 6/6/93 39 * @(#)indent_codes.h 8.1 (Berkeley) 6/6/93
40 * $FreeBSD: head/usr.bin/indent/indent_codes.h 334564 2018-06-03 16:21:15Z pstef $ 40 * $FreeBSD: head/usr.bin/indent/indent_codes.h 334564 2018-06-03 16:21:15Z pstef $
41 */ 41 */
42 42
43typedef enum token_type { 43typedef enum token_type {
44 end_of_file, 44 end_of_file,
45 newline, 45 newline,
46 lparen, /* '(' or '[' */ 46 lparen, /* '(' or '[' */
47 rparen, /* ')' or ']' */ 47 rparen, /* ')' or ']' */
48 unary_op, /* e.g. '+' or '&' */ 48 unary_op, /* e.g. '+' or '&' */
49 binary_op, /* e.g. '<<' or '+' or '&&' or '/=' */ 49 binary_op, /* e.g. '<<' or '+' or '&&' or '/=' */
50 postop, /* trailing '++' or '--' */ 50 postfix_op, /* trailing '++' or '--' */
51 question, /* the '?' from a '?:' expression */ 51 question, /* the '?' from a '?:' expression */
52 case_label, 52 case_label,
53 colon, 53 colon,
54 semicolon, 54 semicolon,
55 lbrace, 55 lbrace,
56 rbrace, 56 rbrace,
57 ident, 57 ident,
58 comma, 58 comma,
59 comment, 59 comment,
60 switch_expr, /* 'switch' '(' <expr> ')' */ 60 switch_expr, /* 'switch' '(' <expr> ')' */
61 preesc, 61 preprocessing, /* '#' */
62 form_feed, 62 form_feed,
63 decl, 63 decl,
64 keyword_for_if_while, /* 'for', 'if' or 'while' */ 64 keyword_for_if_while, /* 'for', 'if' or 'while' */
65 keyword_do_else, /* 'do' or 'else' */ 65 keyword_do_else, /* 'do' or 'else' */
66 if_expr, /* 'if' '(' <expr> ')' */ 66 if_expr, /* 'if' '(' <expr> ')' */
67 while_expr, /* 'while' '(' <expr> ')' */ 67 while_expr, /* 'while' '(' <expr> ')' */
68 for_exprs, /* 'for' '(' ... ')' */ 68 for_exprs, /* 'for' '(' ... ')' */
69 stmt, 69 stmt,
70 stmt_list, 70 stmt_list,
71 keyword_else, /* 'else' */ 71 keyword_else, /* 'else' */
72 keyword_do, /* 'do' */ 72 keyword_do, /* 'do' */
73 do_stmt, /* 'do' <stmt> */ 73 do_stmt, /* 'do' <stmt> */
74 if_expr_stmt, /* 'if' '(' <expr> ')' <stmt> */ 74 if_expr_stmt, /* 'if' '(' <expr> ')' <stmt> */
75 if_expr_stmt_else, /* 'if' '(' <expr> ')' <stmt> 'else' */ 75 if_expr_stmt_else, /* 'if' '(' <expr> ')' <stmt> 'else' */
76 period, 76 period,
77 strpfx, 77 string_prefix, /* 'L' */
78 storage, 78 storage_class,
79 funcname, 79 funcname,
80 type_def, 80 type_def,
81 structure 81 keyword_struct_union_enum
82} token_type; 82} token_type;

cvs diff -r1.30 -r1.31 src/usr.bin/indent/lexi.c (expand / switch to unified diff)

--- src/usr.bin/indent/lexi.c 2021/03/09 19:14:39 1.30
+++ src/usr.bin/indent/lexi.c 2021/03/09 19:23:08 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lexi.c,v 1.30 2021/03/09 19:14:39 rillig Exp $ */ 1/* $NetBSD: lexi.c,v 1.31 2021/03/09 19:23:08 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) 1980, 1993 7 * Copyright (c) 1980, 1993
8 * The Regents of the University of California. All rights reserved. 8 * The Regents of the University of California. All rights reserved.
9 * All rights reserved. 9 * 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
@@ -36,27 +36,27 @@ @@ -36,27 +36,27 @@
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#if 0 40#if 0
41#ifndef lint 41#ifndef lint
42static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; 42static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";
43#endif /* not lint */ 43#endif /* not lint */
44#endif 44#endif
45 45
46#include <sys/cdefs.h> 46#include <sys/cdefs.h>
47#ifndef lint 47#ifndef lint
48#if defined(__NetBSD__) 48#if defined(__NetBSD__)
49__RCSID("$NetBSD: lexi.c,v 1.30 2021/03/09 19:14:39 rillig Exp $"); 49__RCSID("$NetBSD: lexi.c,v 1.31 2021/03/09 19:23:08 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
52#endif 52#endif
53#endif 53#endif
54 54
55/* 55/*
56 * Here we have the token scanner for indent. It scans off one token and puts 56 * Here we have the token scanner for indent. It scans off one token and puts
57 * it in the global variable "token". It returns a code, indicating the type 57 * it in the global variable "token". It returns a code, indicating the type
58 * of token scanned. 58 * of token scanned.
59 */ 59 */
60 60
61#include <assert.h> 61#include <assert.h>
62#include <err.h> 62#include <err.h>
@@ -194,34 +194,34 @@ compare_templ_array(const void *key, con @@ -194,34 +194,34 @@ compare_templ_array(const void *key, con
194 194
195static int 195static int
196compare_string_array(const void *key, const void *elem) 196compare_string_array(const void *key, const void *elem)
197{ 197{
198 return strcmp(key, *((const char *const *)elem)); 198 return strcmp(key, *((const char *const *)elem));
199} 199}
200 200
201#ifdef debug 201#ifdef debug
202const char * 202const char *
203token_type_name(token_type tk) 203token_type_name(token_type tk)
204{ 204{
205 static const char *const name[] = { 205 static const char *const name[] = {
206 "end_of_file", "newline", "lparen", "rparen", "unary_op", 206 "end_of_file", "newline", "lparen", "rparen", "unary_op",
207 "binary_op", "postop", "question", "case_label", "colon", 207 "binary_op", "postfix_op", "question", "case_label", "colon",
208 "semicolon", "lbrace", "rbrace", "ident", "comma", 208 "semicolon", "lbrace", "rbrace", "ident", "comma",
209 "comment", "switch_expr", "preesc", "form_feed", "decl", 209 "comment", "switch_expr", "preprocessing", "form_feed", "decl",
210 "keyword_for_if_while", "keyword_do_else", 210 "keyword_for_if_while", "keyword_do_else",
211 "if_expr", "while_expr", "for_exprs", 211 "if_expr", "while_expr", "for_exprs",
212 "stmt", "stmt_list", "keyword_else", "keyword_do", "do_stmt", 212 "stmt", "stmt_list", "keyword_else", "keyword_do", "do_stmt",
213 "if_expr_stmt", "if_expr_stmt_else", "period", "strpfx", "storage", 213 "if_expr_stmt", "if_expr_stmt_else", "period", "string_prefix",
214 "funcname", "type_def", "structure" 214 "storage_class", "funcname", "type_def", "keyword_struct_union_enum"
215 }; 215 };
216 216
217 assert(0 <= tk && tk < sizeof name / sizeof name[0]); 217 assert(0 <= tk && tk < sizeof name / sizeof name[0]);
218 218
219 return name[tk]; 219 return name[tk];
220} 220}
221 221
222static void 222static void
223print_buf(const char *name, const char *s, const char *e) 223print_buf(const char *name, const char *s, const char *e)
224{ 224{
225 if (s == e) 225 if (s == e)
226 return; 226 return;
227 227
@@ -319,44 +319,44 @@ lexi(struct parser_state *state) @@ -319,44 +319,44 @@ lexi(struct parser_state *state)
319 } else 319 } else
320 break; 320 break;
321 } 321 }
322 check_size_token(1); 322 check_size_token(1);
323 /* copy it over */ 323 /* copy it over */
324 *e_token++ = *buf_ptr++; 324 *e_token++ = *buf_ptr++;
325 if (buf_ptr >= buf_end) 325 if (buf_ptr >= buf_end)
326 fill_buffer(); 326 fill_buffer();
327 } 327 }
328 *e_token = '\0'; 328 *e_token = '\0';
329 329
330 if (s_token[0] == 'L' && s_token[1] == '\0' && 330 if (s_token[0] == 'L' && s_token[1] == '\0' &&
331 (*buf_ptr == '"' || *buf_ptr == '\'')) 331 (*buf_ptr == '"' || *buf_ptr == '\''))
332 return lexi_end(strpfx); 332 return lexi_end(string_prefix);
333 333
334 while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */ 334 while (*buf_ptr == ' ' || *buf_ptr == '\t') { /* get rid of blanks */
335 if (++buf_ptr >= buf_end) 335 if (++buf_ptr >= buf_end)
336 fill_buffer(); 336 fill_buffer();
337 } 337 }
338 state->keyword = rw_0; 338 state->keyword = rw_0;
339 if (state->last_token == structure && !state->p_l_follow) { 339 if (state->last_token == keyword_struct_union_enum &&
340 /* if last token was 'struct' and we're not 340 !state->p_l_follow) {
341 * in parentheses, then this token 341 /* if last token was 'struct' and we're not in parentheses, then
342 * should be treated as a declaration */ 342 * this token should be treated as a declaration */
343 state->last_u_d = true; 343 state->last_u_d = true;
344 return lexi_end(decl); 344 return lexi_end(decl);
345 } 345 }
346 /* 346 /*
347 * Operator after identifier is binary unless last token was 'struct' 347 * Operator after identifier is binary unless last token was 'struct'
348 */ 348 */
349 state->last_u_d = (state->last_token == structure); 349 state->last_u_d = (state->last_token == keyword_struct_union_enum);
350 350
351 p = bsearch(s_token, specials, sizeof specials / sizeof specials[0], 351 p = bsearch(s_token, specials, sizeof specials / sizeof specials[0],
352 sizeof specials[0], compare_templ_array); 352 sizeof specials[0], compare_templ_array);
353 if (p == NULL) { /* not a special keyword... */ 353 if (p == NULL) { /* not a special keyword... */
354 char *u; 354 char *u;
355 355
356 /* ... so maybe a type_t or a typedef */ 356 /* ... so maybe a type_t or a typedef */
357 if ((opt.auto_typedefs && ((u = strrchr(s_token, '_')) != NULL) && 357 if ((opt.auto_typedefs && ((u = strrchr(s_token, '_')) != NULL) &&
358 strcmp(u, "_t") == 0) || (typename_top >= 0 && 358 strcmp(u, "_t") == 0) || (typename_top >= 0 &&
359 bsearch(s_token, typenames, typename_top + 1, 359 bsearch(s_token, typenames, typename_top + 1,
360 sizeof typenames[0], compare_string_array))) { 360 sizeof typenames[0], compare_string_array))) {
361 state->keyword = rw_type; 361 state->keyword = rw_type;
362 state->last_u_d = true; 362 state->last_u_d = true;
@@ -372,39 +372,39 @@ lexi(struct parser_state *state) @@ -372,39 +372,39 @@ lexi(struct parser_state *state)
372 return lexi_end(case_label); 372 return lexi_end(case_label);
373 case rw_struct_or_union_or_enum: 373 case rw_struct_or_union_or_enum:
374 case rw_type: 374 case rw_type:
375 found_typename: 375 found_typename:
376 if (state->p_l_follow) { 376 if (state->p_l_follow) {
377 /* inside parens: cast, param list, offsetof or sizeof */ 377 /* inside parens: cast, param list, offsetof or sizeof */
378 state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask; 378 state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask;
379 } 379 }
380 if (state->last_token == period || state->last_token == unary_op) { 380 if (state->last_token == period || state->last_token == unary_op) {
381 state->keyword = rw_0; 381 state->keyword = rw_0;
382 break; 382 break;
383 } 383 }
384 if (p != NULL && p->rwcode == rw_struct_or_union_or_enum) 384 if (p != NULL && p->rwcode == rw_struct_or_union_or_enum)
385 return lexi_end(structure); 385 return lexi_end(keyword_struct_union_enum);
386 if (state->p_l_follow) 386 if (state->p_l_follow)
387 break; 387 break;
388 return lexi_end(decl); 388 return lexi_end(decl);
389 389
390 case rw_for_or_if_or_while: 390 case rw_for_or_if_or_while:
391 return lexi_end(keyword_for_if_while); 391 return lexi_end(keyword_for_if_while);
392 392
393 case rw_do_or_else: 393 case rw_do_or_else:
394 return lexi_end(keyword_do_else); 394 return lexi_end(keyword_do_else);
395 395
396 case rw_storage_class: 396 case rw_storage_class:
397 return lexi_end(storage); 397 return lexi_end(storage_class);
398 398
399 case rw_typedef: 399 case rw_typedef:
400 return lexi_end(type_def); 400 return lexi_end(type_def);
401 401
402 default: /* all others are treated like any other 402 default: /* all others are treated like any other
403 * identifier */ 403 * identifier */
404 return lexi_end(ident); 404 return lexi_end(ident);
405 } /* end of switch */ 405 } /* end of switch */
406 } /* end of if (found_it) */ 406 } /* end of if (found_it) */
407 if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 && 407 if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 &&
408 state->in_parameter_declaration == 0 && state->block_init == 0) { 408 state->in_parameter_declaration == 0 && state->block_init == 0) {
409 char *tp = buf_ptr; 409 char *tp = buf_ptr;
410 while (tp < buf_end) 410 while (tp < buf_end)
@@ -491,27 +491,27 @@ stop_lit: @@ -491,27 +491,27 @@ stop_lit:
491 case ('('): 491 case ('('):
492 case ('['): 492 case ('['):
493 unary_delim = true; 493 unary_delim = true;
494 code = lparen; 494 code = lparen;
495 break; 495 break;
496 496
497 case (')'): 497 case (')'):
498 case (']'): 498 case (']'):
499 code = rparen; 499 code = rparen;
500 break; 500 break;
501 501
502 case '#': 502 case '#':
503 unary_delim = state->last_u_d; 503 unary_delim = state->last_u_d;
504 code = preesc; 504 code = preprocessing;
505 break; 505 break;
506 506
507 case '?': 507 case '?':
508 unary_delim = true; 508 unary_delim = true;
509 code = question; 509 code = question;
510 break; 510 break;
511 511
512 case (':'): 512 case (':'):
513 code = colon; 513 code = colon;
514 unary_delim = true; 514 unary_delim = true;
515 break; 515 break;
516 516
517 case (';'): 517 case (';'):
@@ -552,27 +552,27 @@ stop_lit: @@ -552,27 +552,27 @@ stop_lit:
552 code = period; 552 code = period;
553 break; 553 break;
554 554
555 case '-': 555 case '-':
556 case '+': /* check for -, +, --, ++ */ 556 case '+': /* check for -, +, --, ++ */
557 code = (state->last_u_d ? unary_op : binary_op); 557 code = (state->last_u_d ? unary_op : binary_op);
558 unary_delim = true; 558 unary_delim = true;
559 559
560 if (*buf_ptr == token[0]) { 560 if (*buf_ptr == token[0]) {
561 /* check for doubled character */ 561 /* check for doubled character */
562 *e_token++ = *buf_ptr++; 562 *e_token++ = *buf_ptr++;
563 /* buffer overflow will be checked at end of loop */ 563 /* buffer overflow will be checked at end of loop */
564 if (state->last_token == ident || state->last_token == rparen) { 564 if (state->last_token == ident || state->last_token == rparen) {
565 code = (state->last_u_d ? unary_op : postop); 565 code = (state->last_u_d ? unary_op : postfix_op);
566 /* check for following ++ or -- */ 566 /* check for following ++ or -- */
567 unary_delim = false; 567 unary_delim = false;
568 } 568 }
569 } 569 }
570 else if (*buf_ptr == '=') 570 else if (*buf_ptr == '=')
571 /* check for operator += */ 571 /* check for operator += */
572 *e_token++ = *buf_ptr++; 572 *e_token++ = *buf_ptr++;
573 else if (*buf_ptr == '>') { 573 else if (*buf_ptr == '>') {
574 /* check for operator -> */ 574 /* check for operator -> */
575 *e_token++ = *buf_ptr++; 575 *e_token++ = *buf_ptr++;
576 unary_delim = false; 576 unary_delim = false;
577 code = unary_op; 577 code = unary_op;
578 state->want_blank = false; 578 state->want_blank = false;