gnulib: update
[bison.git] / src / flex-scanner.h
blob238ca88117002eabb69bc68ea671eecc758744f3
1 /* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
3 Copyright (C) 2006, 2009-2015, 2018-2021 Free Software Foundation,
4 Inc.
6 This file is part of Bison, the GNU Compiler Compiler.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <https://www.gnu.org/licenses/>. */
21 #ifndef FLEX_PREFIX
22 # error "FLEX_PREFIX not defined"
23 #endif
25 /* Flex full version as a number. */
26 #define FLEX_VERSION \
27 ((YY_FLEX_MAJOR_VERSION) * 1000000 \
28 + (YY_FLEX_MINOR_VERSION) * 1000 \
29 + (YY_FLEX_SUBMINOR_VERSION))
31 // Pacify warnings in yy_init_buffer (observed with Flex 2.6.4 and GCC
32 // 6.4.0 and 7.3.0).
34 // ./src/scan-skel.c: In function 'skel_restart':
35 // ./src/scan-skel.c:2035:20: error: potential null pointer dereference [-Werror=null-dereference]
36 // b->yy_fill_buffer = 1;
37 // ~~~~~~~~~~~~~~~~~~^~~
38 // ./src/scan-skel.c:2031:19: error: potential null pointer dereference [-Werror=null-dereference]
39 // b->yy_input_file = file;
40 // ~~~~~~~~~~~~~~~~~^~~~~~
41 #if defined __GNUC__ && ! defined __clang__ && 6 <= __GNUC__
42 # pragma GCC diagnostic ignored "-Wnull-dereference"
43 #endif
45 // Old versions of Flex (2.5.35) generate an incomplete documentation comment.
47 // In file included from src/scan-code-c.c:3:
48 // src/scan-code.c:2198:21: error: empty paragraph passed to '@param' command
49 // [-Werror,-Wdocumentation]
50 // * @param line_number
51 // ~~~~~~~~~~~~~~~~~^
52 // 1 error generated.
53 #if FLEX_VERSION <= 20060000 && defined __clang__
54 # pragma clang diagnostic ignored "-Wdocumentation"
55 #endif
57 /* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
58 #if FLEX_VERSION <= 2005031
59 int FLEX_PREFIX (get_lineno) (void);
60 FILE *FLEX_PREFIX (get_in) (void);
61 FILE *FLEX_PREFIX (get_out) (void);
62 int FLEX_PREFIX (get_leng) (void);
63 char *FLEX_PREFIX (get_text) (void);
64 void FLEX_PREFIX (set_lineno) (int);
65 void FLEX_PREFIX (set_in) (FILE *);
66 void FLEX_PREFIX (set_out) (FILE *);
67 int FLEX_PREFIX (get_debug) (void);
68 void FLEX_PREFIX (set_debug) (int);
69 int FLEX_PREFIX (lex_destroy) (void);
70 #endif
72 #define last_string FLEX_PREFIX (last_string)
74 /* It seems to be a nice "feature" of Flex that one cannot use yytext,
75 yyleng etc. when a prefix is given, since there is no longer a
76 #define, but rather the token is actually changed in the output.
77 However, this is not true for Flex 2.5.4. */
78 #ifndef yyleng
79 # define yyleng FLEX_PREFIX (leng)
80 #endif
81 #ifndef yytext
82 # define yytext FLEX_PREFIX (text)
83 #endif
85 /* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
86 versions according to the Flex manual) leak memory if yylex_destroy is not
87 invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
88 an implementation here that at least appears to work with Flex 2.5.4. */
89 #if FLEX_VERSION <= 2005009
90 # define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
91 #endif
93 /* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
94 keep (to construct ID, STRINGS etc.). Use the following macros to
95 use it.
97 Use STRING_GROW () to append what has just been matched, and
98 STRING_FINISH () to end the string (it puts the ending 0).
99 STRING_FINISH () also stores this string in LAST_STRING, which can be
100 used, and which is used by STRING_FREE () to free the last string. */
102 #ifndef FLEX_NO_OBSTACK
104 static struct obstack obstack_for_string;
106 # define STRING_GROW() \
107 obstack_grow (&obstack_for_string, yytext, yyleng)
109 # define STRING_FINISH() \
110 (last_string = obstack_finish0 (&obstack_for_string))
112 # define STRING_1GROW(Char) \
113 obstack_1grow (&obstack_for_string, Char)
115 # ifdef NDEBUG
116 # define STRING_FREE() \
117 obstack_free (&obstack_for_string, last_string)
118 # else
119 # define STRING_FREE() \
120 do { \
121 obstack_free (&obstack_for_string, last_string); \
122 last_string = NULL; \
123 } while (0)
124 # endif
126 #endif