]> git.saurik.com Git - bison.git/blob - src/flex-scanner.h
Fix portability problem on OpenBSD 4.7.
[bison.git] / src / flex-scanner.h
1 /* Common parts between scan-code.l, scan-gram.l, and scan-skel.l.
2
3 Copyright (C) 2006, 2009, 2010 Free Software Foundation, Inc.
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef FLEX_PREFIX
21 # error "FLEX_PREFIX not defined"
22 #endif
23
24 /* Pacify "gcc -Wmissing-prototypes" when flex 2.5.31 is used. */
25 int FLEX_PREFIX (get_lineno) (void);
26 FILE *FLEX_PREFIX (get_in) (void);
27 FILE *FLEX_PREFIX (get_out) (void);
28 int FLEX_PREFIX (get_leng) (void);
29 char *FLEX_PREFIX (get_text) (void);
30 void FLEX_PREFIX (set_lineno) (int);
31 void FLEX_PREFIX (set_in) (FILE *);
32 void FLEX_PREFIX (set_out) (FILE *);
33 int FLEX_PREFIX (get_debug) (void);
34 void FLEX_PREFIX (set_debug) (int);
35 int FLEX_PREFIX (lex_destroy) (void);
36
37 #define last_string FLEX_PREFIX (last_string)
38
39 /* It seems to be a nice "feature" of Flex that one cannot use yytext,
40 yyleng etc. when a prefix is given, since there is no longer a
41 #define, but rather the token is actually changed in the output.
42 However, this is not true for Flex 2.5.4. */
43 #ifndef yyleng
44 # define yyleng FLEX_PREFIX (leng)
45 #endif
46 #ifndef yytext
47 # define yytext FLEX_PREFIX (text)
48 #endif
49
50 /* Non-reentrant scanners generated by Flex 2.5.9 and later (and some earlier
51 versions according to the Flex manual) leak memory if yylex_destroy is not
52 invoked. However, yylex_destroy is not defined before Flex 2.5.9, so give
53 an implementation here that at least appears to work with Flex 2.5.4. */
54 #if !defined(YY_FLEX_MAJOR_VERSION) || YY_FLEX_MAJOR_VERSION < 2 \
55 || (YY_FLEX_MAJOR_VERSION == 2 \
56 && (!defined(YY_FLEX_MINOR_VERSION) || YY_FLEX_MINOR_VERSION < 5 \
57 || (YY_FLEX_MINOR_VERSION == 5 \
58 && (!defined(YY_FLEX_SUBMINOR_VERSION) \
59 || YY_FLEX_SUBMINOR_VERSION < 9))))
60 # define yylex_destroy() yy_delete_buffer (YY_CURRENT_BUFFER)
61 #endif
62
63 /* OBSTACK_FOR_STRING -- Used to store all the characters that we need to
64 keep (to construct ID, STRINGS etc.). Use the following macros to
65 use it.
66
67 Use STRING_GROW to append what has just been matched, and
68 STRING_FINISH to end the string (it puts the ending 0).
69 STRING_FINISH also stores this string in LAST_STRING, which can be
70 used, and which is used by STRING_FREE to free the last string. */
71
72 #ifndef FLEX_NO_OBSTACK
73
74 static struct obstack obstack_for_string;
75
76 #define STRING_GROW \
77 obstack_grow (&obstack_for_string, yytext, yyleng)
78
79 #define STRING_FINISH \
80 do { \
81 obstack_1grow (&obstack_for_string, '\0'); \
82 last_string = obstack_finish (&obstack_for_string); \
83 } while (0)
84
85 #define STRING_FREE \
86 obstack_free (&obstack_for_string, last_string)
87
88 #endif