| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: lex.c,v 1.105 2022/02/27 22:46:04 rillig Exp $ */ | | 1 | /* $NetBSD: lex.c,v 1.106 2022/02/28 22:41:07 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. | | 4 | * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
5 | * Copyright (c) 1994, 1995 Jochen Pohl | | 5 | * Copyright (c) 1994, 1995 Jochen Pohl |
6 | * All Rights Reserved. | | 6 | * All Rights Reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -28,27 +28,27 @@ | | | @@ -28,27 +28,27 @@ |
28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #if HAVE_NBTOOL_CONFIG_H | | 35 | #if HAVE_NBTOOL_CONFIG_H |
36 | #include "nbtool_config.h" | | 36 | #include "nbtool_config.h" |
37 | #endif | | 37 | #endif |
38 | | | 38 | |
39 | #include <sys/cdefs.h> | | 39 | #include <sys/cdefs.h> |
40 | #if defined(__RCSID) && !defined(lint) | | 40 | #if defined(__RCSID) && !defined(lint) |
41 | __RCSID("$NetBSD: lex.c,v 1.105 2022/02/27 22:46:04 rillig Exp $"); | | 41 | __RCSID("$NetBSD: lex.c,v 1.106 2022/02/28 22:41:07 rillig Exp $"); |
42 | #endif | | 42 | #endif |
43 | | | 43 | |
44 | #include <ctype.h> | | 44 | #include <ctype.h> |
45 | #include <errno.h> | | 45 | #include <errno.h> |
46 | #include <float.h> | | 46 | #include <float.h> |
47 | #include <limits.h> | | 47 | #include <limits.h> |
48 | #include <math.h> | | 48 | #include <math.h> |
49 | #include <stdlib.h> | | 49 | #include <stdlib.h> |
50 | #include <string.h> | | 50 | #include <string.h> |
51 | | | 51 | |
52 | #include "lint1.h" | | 52 | #include "lint1.h" |
53 | #include "cgram.h" | | 53 | #include "cgram.h" |
54 | | | 54 | |
| @@ -77,27 +77,27 @@ bool in_system_header; | | | @@ -77,27 +77,27 @@ bool in_system_header; |
77 | kwdef(name, token, 0, 0, 0, c90, c99, gcc, attr, deco) | | 77 | kwdef(name, token, 0, 0, 0, c90, c99, gcc, attr, deco) |
78 | #define kwdef_sclass(name, sclass, c90, c99, gcc, attr, deco) \ | | 78 | #define kwdef_sclass(name, sclass, c90, c99, gcc, attr, deco) \ |
79 | kwdef(name, T_SCLASS, sclass, 0, 0, c90, c99, gcc, attr, deco) | | 79 | kwdef(name, T_SCLASS, sclass, 0, 0, c90, c99, gcc, attr, deco) |
80 | #define kwdef_type(name, tspec, c90, c99, gcc, attr, deco) \ | | 80 | #define kwdef_type(name, tspec, c90, c99, gcc, attr, deco) \ |
81 | kwdef(name, T_TYPE, 0, tspec, 0, c90, c99, gcc, attr, deco) | | 81 | kwdef(name, T_TYPE, 0, tspec, 0, c90, c99, gcc, attr, deco) |
82 | #define kwdef_tqual(name, tqual, c90, c99, gcc, attr, deco) \ | | 82 | #define kwdef_tqual(name, tqual, c90, c99, gcc, attr, deco) \ |
83 | kwdef(name, T_QUAL, 0, 0, tqual, c90, c99, gcc, attr, deco) | | 83 | kwdef(name, T_QUAL, 0, 0, tqual, c90, c99, gcc, attr, deco) |
84 | #define kwdef_keyword(name, token) \ | | 84 | #define kwdef_keyword(name, token) \ |
85 | kwdef(name, token, 0, 0, 0, 0, 0, 0, 0, 1) | | 85 | kwdef(name, token, 0, 0, 0, 0, 0, 0, 0, 1) |
86 | #define kwdef_gcc_attr(name, token) \ | | 86 | #define kwdef_gcc_attr(name, token) \ |
87 | kwdef(name, token, 0, 0, 0, 0, 0, 1, 1, 5) | | 87 | kwdef(name, token, 0, 0, 0, 0, 0, 1, 1, 5) |
88 | | | 88 | |
89 | /* During initialization, these keywords are written to the symbol table. */ | | 89 | /* During initialization, these keywords are written to the symbol table. */ |
90 | static struct keyword { | | 90 | static const struct keyword { |
91 | const char *kw_name; /* keyword */ | | 91 | const char *kw_name; /* keyword */ |
92 | int kw_token; /* token returned by yylex() */ | | 92 | int kw_token; /* token returned by yylex() */ |
93 | scl_t kw_scl; /* storage class if kw_token T_SCLASS */ | | 93 | scl_t kw_scl; /* storage class if kw_token T_SCLASS */ |
94 | tspec_t kw_tspec; /* type spec. if kw_token | | 94 | tspec_t kw_tspec; /* type spec. if kw_token |
95 | * T_TYPE or T_STRUCT_OR_UNION */ | | 95 | * T_TYPE or T_STRUCT_OR_UNION */ |
96 | tqual_t kw_tqual; /* type qual. if kw_token T_QUAL */ | | 96 | tqual_t kw_tqual; /* type qual. if kw_token T_QUAL */ |
97 | bool kw_c90:1; /* C90 keyword */ | | 97 | bool kw_c90:1; /* C90 keyword */ |
98 | bool kw_c99:1; /* C99 keyword */ | | 98 | bool kw_c99:1; /* C99 keyword */ |
99 | bool kw_gcc:1; /* GCC keyword */ | | 99 | bool kw_gcc:1; /* GCC keyword */ |
100 | bool kw_attr:1; /* GCC attribute, keyword */ | | 100 | bool kw_attr:1; /* GCC attribute, keyword */ |
101 | bool kw_plain:1; /* 'name' */ | | 101 | bool kw_plain:1; /* 'name' */ |
102 | bool kw_leading:1; /* '__name' */ | | 102 | bool kw_leading:1; /* '__name' */ |
103 | bool kw_both:1; /* '__name__' */ | | 103 | bool kw_both:1; /* '__name__' */ |
| @@ -334,27 +334,27 @@ add_keyword(const struct keyword *kw, bo | | | @@ -334,27 +334,27 @@ add_keyword(const struct keyword *kw, bo |
334 | sym->s_tqual = kw->kw_tqual; | | 334 | sym->s_tqual = kw->kw_tqual; |
335 | } | | 335 | } |
336 | | | 336 | |
337 | symtab_add(sym); | | 337 | symtab_add(sym); |
338 | } | | 338 | } |
339 | | | 339 | |
340 | /* | | 340 | /* |
341 | * All keywords are written to the symbol table. This saves us looking | | 341 | * All keywords are written to the symbol table. This saves us looking |
342 | * in an extra table for each name we found. | | 342 | * in an extra table for each name we found. |
343 | */ | | 343 | */ |
344 | void | | 344 | void |
345 | initscan(void) | | 345 | initscan(void) |
346 | { | | 346 | { |
347 | struct keyword *kw; | | 347 | const struct keyword *kw; |
348 | | | 348 | |
349 | for (kw = keywords; kw->kw_name != NULL; kw++) { | | 349 | for (kw = keywords; kw->kw_name != NULL; kw++) { |
350 | if ((kw->kw_c90 || kw->kw_c99) && tflag) | | 350 | if ((kw->kw_c90 || kw->kw_c99) && tflag) |
351 | continue; | | 351 | continue; |
352 | if (kw->kw_c99 && !(Sflag || gflag)) | | 352 | if (kw->kw_c99 && !(Sflag || gflag)) |
353 | continue; | | 353 | continue; |
354 | if (kw->kw_gcc && !gflag) | | 354 | if (kw->kw_gcc && !gflag) |
355 | continue; | | 355 | continue; |
356 | if (kw->kw_plain) | | 356 | if (kw->kw_plain) |
357 | add_keyword(kw, false, false); | | 357 | add_keyword(kw, false, false); |
358 | if (kw->kw_leading) | | 358 | if (kw->kw_leading) |
359 | add_keyword(kw, true, false); | | 359 | add_keyword(kw, true, false); |
360 | if (kw->kw_both) | | 360 | if (kw->kw_both) |