Skip to content

Commit e7611be

Browse files
Three more namespace cleanups for multilanguage.
Replace YY_FLUSH_BUFFER with yy_flush_current_buffer() Replace YY_CURRENT_BUFFER with yy_current_buffer(). Replace YY_BUFFER_STATE with yybuffer. The following are the all-caps definitions still exposed: YY_FLEX_MAJOR_VERSION YY_FLEX_MINOR_VERSION YY_FLEX_SUBMINOR_VERSION YY_NULL YY_END_OF_BUFFER_CHAR YY_BUF_SIZE YYLMAX It is not idea for this list to be nonempty, but at least these are all actual comple-time constants rather than function calls or type names.
1 parent 8d0162b commit e7611be

File tree

4 files changed

+130
-104
lines changed

4 files changed

+130
-104
lines changed

doc/flex.texi

+63-42
Original file line numberDiff line numberDiff line change
@@ -1471,12 +1471,12 @@ example, the following is one way to eat up C comments:
14711471
@end example
14721472

14731473
@cindex flushing the internal buffer
1474-
@cindex YY_FLUSH_BUFFER
1475-
@code{YY_FLUSH_BUFFER;} flushes the scanner's internal buffer so that
1474+
@cindex yy_flush_current_buffer()
1475+
@code{yy_flush_current_buffer()} flushes the scanner's internal buffer so that
14761476
the next time the scanner attempts to match a token, it will first
14771477
refill the buffer using @code{yyread()} (@pxref{Generated Scanner}).
14781478
This action is a special case of the more general
1479-
@code{yy_flush_buffer;} function, described below (@pxref{Multiple
1479+
@code{yy_flush_buffer()} function, described below (@pxref{Multiple
14801480
Input Buffers})
14811481

14821482
@cindex yyterminate()
@@ -1562,7 +1562,7 @@ the latter is available for compatibility with previous versions of
15621562
@code{flex}, and because it can be used to switch input files in the
15631563
middle of scanning. It can also be used to throw away the current input
15641564
buffer, by calling it with an argument of @file{yyin}; but it would be
1565-
better to use @code{YY_FLUSH_BUFFER} (@pxref{Actions}). Note that
1565+
better to use @code{yy_flush_current_buffer()} (@pxref{Actions}). Note that
15661566
@code{yyrestart()} does @emph{not} reset the start condition to
15671567
@code{INITIAL} (@pxref{Start Conditions}).
15681568

@@ -2056,13 +2056,13 @@ for creating and switching between multiple input buffers. An input
20562056
buffer is created by using:
20572057

20582058
@cindex memory, allocating input buffers
2059-
@deftypefun YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size )
2059+
@deftypefun yybuffer yy_create_buffer ( FILE *file, int size )
20602060
@end deftypefun
20612061

20622062
which takes a @code{FILE} pointer and a size and creates a buffer
20632063
associated with the given file and large enough to hold @code{size}
20642064
characters (when in doubt, use @code{YY_BUF_SIZE} for the size). It
2065-
returns a @code{YY_BUFFER_STATE} handle, which may then be passed to
2065+
returns a @code{yybuffer} handle, which may then be passed to
20662066
other routines (see below).
20672067

20682068
In target languages other than C/C++, this prototype will look
@@ -2071,11 +2071,11 @@ not have ``struct'' as part of its name. The input-stream type won't
20712071
be @code{FILE *}. But expect the same semamntics wxpressed in native
20722072
tytypes.
20732073

2074-
@tindex YY_BUFFER_STATE
2075-
The @code{YY_BUFFER_STATE} type is a
2076-
pointer to an opaque @code{struct yy_buffer_state} structure, so you may
2077-
safely initialize @code{YY_BUFFER_STATE} variables to @code{((YY_BUFFER_STATE)
2078-
0)} if you wish, and also refer to the opaque structure in order to
2074+
@tindex yybuffer
2075+
The @code{yybuffer} type is a
2076+
reference to an opaque buffer state structure, so you may
2077+
safely initialize @code{yybuffer} variables to @code{((yybuffer)
2078+
NULL)} if you wish, and also refer to the opaque structure in order to
20792079
correctly declare input buffers in source files other than that of your
20802080
scanner. Note that the @code{FILE} pointer in the call to
20812081
@code{yy_create_buffer} is only used as the value of @file{yyin} seen by
@@ -2084,7 +2084,7 @@ scanner. Note that the @code{FILE} pointer in the call to
20842084
@code{yy_create_buffer}. You select a particular buffer to scan from
20852085
using:
20862086

2087-
@deftypefun void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer )
2087+
@deftypefun void yy_switch_to_buffer ( yybuffer new_buffer )
20882088
@end deftypefun
20892089

20902090
The above function switches the scanner's input buffer so subsequent tokens
@@ -2097,7 +2097,7 @@ instead of this function. Note also that switching input sources via either
20972097
start condition.
20982098

20992099
@cindex memory, deleting input buffers
2100-
@deftypefun void yy_delete_buffer ( YY_BUFFER_STATE buffer )
2100+
@deftypefun void yy_delete_buffer ( yybuffer buffer )
21012101
@end deftypefun
21022102

21032103
is used to reclaim the storage associated with a buffer. (@code{buffer}
@@ -2106,7 +2106,7 @@ the current contents of a buffer using:
21062106

21072107
@cindex pushing an input buffer
21082108
@cindex stack, input buffer push
2109-
@deftypefun void yypush_buffer_state ( YY_BUFFER_STATE buffer )
2109+
@deftypefun void yypush_buffer_state ( yybuffer buffer )
21102110
@end deftypefun
21112111

21122112
This function pushes the new buffer state onto an internal stack. The pushed
@@ -2126,25 +2126,26 @@ becomes the new current state.
21262126

21272127
@cindex clearing an input buffer
21282128
@cindex flushing an input buffer
2129-
@deftypefun void yy_flush_buffer ( YY_BUFFER_STATE buffer )
2129+
@deftypefun void yy_flush_buffer ( yybuffer buffer )
21302130
@end deftypefun
21312131

21322132
This function discards the buffer's contents,
21332133
so the next time the scanner attempts to match a token from the
21342134
buffer, it will first fill the buffer anew using
21352135
@code{yyread()}.
21362136

2137-
@deftypefun YY_BUFFER_STATE yy_new_buffer ( FILE *file, int size )
2137+
@deftypefun yybuffer yy_new_buffer ( FILE *file, int size )
21382138
@end deftypefun
21392139

21402140
is an alias for @code{yy_create_buffer()},
21412141
provided for compatibility with the C++ use of @code{new} and
21422142
@code{delete} for creating and destroying dynamic objects.
21432143

2144-
@cindex YY_CURRENT_BUFFER, and multiple buffers
2145-
Finally, the macro @code{YY_CURRENT_BUFFER} macro returns a
2146-
@code{YY_BUFFER_STATE} handle to the current buffer. It should not be
2147-
used as an lvalue.
2144+
@cindex yy_current_buffer(), and multiple buffers
2145+
Finally, @code{yy_current_buffer()} returns a
2146+
@code{yybuffer} handle to the current buffer. It should not be
2147+
used as an lvalue, because it can return NULL to indicate no buffer is
2148+
current.
21482149

21492150
@cindex EOF, example using multiple input buffers
21502151
Here are two examples of using these features for writing a scanner
@@ -2183,7 +2184,7 @@ maintains the stack internally.
21832184
<<EOF>> {
21842185
yypop_buffer_state();
21852186
2186-
if ( !YY_CURRENT_BUFFER )
2187+
if ( !yy_current_buffer() )
21872188
{
21882189
yyterminate();
21892190
}
@@ -2204,7 +2205,7 @@ manages its own input buffer stack manually (instead of letting flex do it).
22042205
22052206
%{
22062207
#define MAX_INCLUDE_DEPTH 10
2207-
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
2208+
yybuffer include_stack[MAX_INCLUDE_DEPTH];
22082209
int include_stack_ptr = 0;
22092210
%}
22102211
@@ -2223,7 +2224,7 @@ manages its own input buffer stack manually (instead of letting flex do it).
22232224
}
22242225
22252226
include_stack[include_stack_ptr++] =
2226-
YY_CURRENT_BUFFER;
2227+
yy_current_buffer();
22272228
22282229
yyin = fopen( yytext, "r" );
22292230
@@ -2244,7 +2245,7 @@ manages its own input buffer stack manually (instead of letting flex do it).
22442245
22452246
else
22462247
{
2247-
yy_delete_buffer( YY_CURRENT_BUFFER );
2248+
yy_delete_buffer( yy_current_buffer() );
22482249
yy_switch_to_buffer(
22492250
include_stack[include_stack_ptr] );
22502251
}
@@ -2257,16 +2258,16 @@ manages its own input buffer stack manually (instead of letting flex do it).
22572258
The following routines are available for setting up input buffers for
22582259
scanning in-memory strings instead of files. All of them create a new
22592260
input buffer for scanning the string, and return a corresponding
2260-
@code{YY_BUFFER_STATE} handle (which you should delete with
2261+
@code{yybuffer} handle (which you should delete with
22612262
@code{yy_delete_buffer()} when done with it). They also switch to the
22622263
new buffer using @code{yy_switch_to_buffer()}, so the next call to
22632264
@code{yylex()} will start scanning the string.
22642265

2265-
@deftypefun YY_BUFFER_STATE yy_scan_string ( const char *str )
2266+
@deftypefun yybuffer yy_scan_string ( const char *str )
22662267
scans a NUL-terminated string.
22672268
@end deftypefun
22682269

2269-
@deftypefun YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len )
2270+
@deftypefun yybuffer yy_scan_bytes ( const char *bytes, int len )
22702271
scans @code{len} bytes (including possibly @code{NUL}s) starting at location
22712272
@code{bytes}.
22722273
@end deftypefun
@@ -2277,7 +2278,7 @@ the contents of the buffer it is scanning.) You can avoid the copy by
22772278
using:
22782279

22792280
@vindex YY_END_OF_BUFFER_CHAR
2280-
@deftypefun YY_BUFFER_STATE yy_scan_buffer (char *base, yy_size_t size)
2281+
@deftypefun yybuffer yy_scan_buffer (char *base, yy_size_t size)
22812282
which scans in place the buffer starting at @code{base}, consisting of
22822283
@code{size} bytes, the last two bytes of which @emph{must} be
22832284
@code{YY_END_OF_BUFFER_CHAR} (ASCII NUL). These last two bytes are not
@@ -2429,7 +2430,7 @@ Setting a post-action allows, for example, C++ users to suppress the
24292430
trailing break (while being very careful that every rule ends with a
24302431
@code{break} or a @code{return}!) to avoid suffering from unreachable
24312432
statement warnings where because a rule's action ends with
2432-
@code{return}, the @code{YY_BREAK} is inaccessible.
2433+
@code{return}, the break is inaccessible.
24332434

24342435
@node User Values, Yacc, Misc Controls, Top
24352436
@chapter Values Available To the User
@@ -2493,9 +2494,9 @@ by the user.
24932494
In target languages other than C/C++, expect it to have
24942495
whatever tyoe is associated with I/O streams.
24952496

2496-
@vindex YY_CURRENT_BUFFER
2497-
@item YY_CURRENT_BUFFER
2498-
returns a @code{YY_BUFFER_STATE} handle to the current buffer.
2497+
@vindex yy_current_buffer()
2498+
@item yy_current_buffer()
2499+
returns a @code{yybuffer} handle to the current buffer.
24992500

25002501
@vindex yystart()
25012502
@item yystart()
@@ -3860,7 +3861,7 @@ returns the current setting of the debugging flag.
38603861
Also provided are member functions equivalent to
38613862
@code{yy_switch_to_buffer()}, @code{yy_create_buffer()} (though the
38623863
first argument is an @code{istream&} object reference and not a
3863-
@code{FILE*)}, @code{yy_flush_buffer()}, @code{yy_delete_buffer()}, and
3864+
@code{FILE*)}, @code{yy_flush_current_buffer()}, @code{yy_delete_buffer()}, and
38643865
@code{yyrestart()} (again, the first argument is a @code{istream&}
38653866
object reference).
38663867

@@ -4105,7 +4106,7 @@ another instance of itself.
41054106
%%
41064107
"eval(".+")" {
41074108
yyscan_t scanner;
4108-
YY_BUFFER_STATE buf;
4109+
yybuffer buf;
41094110
41104111
yylex_init( &scanner );
41114112
yytext[yyleng-1] = ' ';
@@ -4917,8 +4918,8 @@ specified. You will rarely need to tune this buffer. The ideal size for this
49174918
stack is the maximum depth expected. The memory for this stack is
49184919
automatically destroyed when you call yylex_destroy(). @xref{option-stack}.
49194920

4920-
@item 40 bytes for each YY_BUFFER_STATE.
4921-
Flex allocates memory for each YY_BUFFER_STATE. The buffer state itself
4921+
@item 40 bytes for each yybuffer.
4922+
Flex allocates memory for each yybuffer. The buffer state itself
49224923
is about 40 bytes, plus an additional large character buffer (described above.)
49234924
The initial buffer state is created during initialization, and with each call
49244925
to yy_create_buffer(). You can't tune the size of this, but you can tune the
@@ -6075,7 +6076,7 @@ However, you can do this using multiple input buffers.
60756076
%%
60766077
macro/[a-z]+ {
60776078
/* Saw the macro "macro" followed by extra stuff. */
6078-
main_buffer = YY_CURRENT_BUFFER;
6079+
main_buffer = yy_current_buffer();
60796080
expansion_buffer = yy_scan_string(expand(yytext));
60806081
yy_switch_to_buffer(expansion_buffer);
60816082
}
@@ -6212,7 +6213,7 @@ you might try this:
62126213
@example
62136214
@verbatim
62146215
/* For non-reentrant C scanner only. */
6215-
yy_delete_buffer(YY_CURRENT_BUFFER);
6216+
yy_delete_buffer(yy_current_buffer());
62166217
yy_init = 1;
62176218
@end verbatim
62186219
@end example
@@ -6228,7 +6229,7 @@ situation. It is possible that some other globals may need resetting as well.
62286229
> We thought that it would be possible to have this number through the
62296230
> evaluation of the following expression:
62306231
>
6231-
> seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf
6232+
> seek_position = (no_buffers)*YY_READ_BUF_SIZE + yy_c_buf_p - yy_current_buffer()->yy_ch_buf
62326233
@end verbatim
62336234
@end example
62346235

@@ -6239,7 +6240,7 @@ even though @code{YY_READ_BUF_SIZE} bytes were requested). The second problem
62396240
is that when refilling its internal buffer, @code{flex} keeps some characters
62406241
from the previous buffer (because usually it's in the middle of a match,
62416242
and needs those characters to construct @code{yytext} for the match once it's
6242-
done). Because of this, @code{yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf} won't
6243+
done). Because of this, @code{yy_c_buf_p - yy_current_buffer()->yy_ch_buf} won't
62436244
be exactly the number of characters already read from the current buffer.
62446245

62456246
An alternative solution is to count the number of characters you've matched
@@ -6597,7 +6598,7 @@ Date: Wed, 13 Nov 1996 19:51:54 PST
65976598
From: Vern Paxson <vern>
65986599
65996600
> "yyunput()" them to input flow, question occurs. If I do this after I scan
6600-
> a carriage, the variable "YY_CURRENT_BUFFER->yy_at_bol" is changed. That
6601+
> a carriage, the variable "yy_current_buffer()->yy_at_bol" is changed. That
66016602
> means the carriage flag has gone.
66026603
66036604
You can control this by calling yy_set_bol(). It's described in the manual.
@@ -7026,7 +7027,7 @@ In-reply-to: Your message of Mon, 08 Dec 1997 15:54:15 PST.
70267027
Date: Mon, 15 Dec 1997 13:21:35 PST
70277028
From: Vern Paxson <vern>
70287029
7029-
> stdin_handle = YY_CURRENT_BUFFER;
7030+
> stdin_handle = yy_current_buffer();
70307031
> ifstream fin( "aFile" );
70317032
> yy_switch_to_buffer( yy_create_buffer( fin, YY_BUF_SIZE ) );
70327033
>
@@ -8848,6 +8849,15 @@ yunput(): Replaced by yyunput().
88488849
YYSTATE: is accepted as an alias for @code{yystart()}
88498850
(since that is what's used by AT&T @code{lex}).
88508851

8852+
@item
8853+
YY_FLUSH_BUFFER: replaced by yy_flush_current_buffer().
8854+
8855+
@item
8856+
YY_CURRENT_BUFFER: replaced by yy_current_buffer().
8857+
8858+
@item
8859+
YY_BUFFER_STATE: replaced by yybuffer.
8860+
88518861
@item
88528862
YY_NEW_FILE: In previous versions of @code{flex}, ehen assigning
88538863
@file{yyin} to a new input file, after doing the assignment you had to
@@ -8916,4 +8926,15 @@ to specific locations in the generated scanner, and may be used to insert arbitr
89168926
@c endf
89178927
@c nnoremap <F5> 1G/@node\s\+unnamed-faq-\d\+<cr>mfww"wy5ezt:call Faq2()<cr>
89188928

8929+
@c Remaining problem points for the multilangage interface
8930+
@c YY_NUM_RULES
8931+
@c YY_FLEX_MAJOR_VERSION
8932+
@c YY_FLEX_MINOR_VERSION
8933+
@c YY_FLEX_SUBMINOR_VERSION
8934+
@c YY_NULL
8935+
@c YY_END_OF_BUFFER_CHAR
8936+
@c YY_BUF_SIZE
8937+
@c YYLMAX
8938+
8939+
89198940
@bye

examples/manual/eof_rules.lex

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int include_count = -1;
2525
exit( 1 );
2626
}
2727

28-
include_stack[++include_count] = YY_CURRENT_BUFFER;
28+
include_stack[++include_count] = yy_current_buffer();
2929

3030
yyin = fopen( yytext, "r" );
3131
if ( ! yyin ){

examples/manual/pas_include.lex

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int include_count = -1;
3333
exit( 1 );
3434
}
3535

36-
include_stack[++include_count] = YY_CURRENT_BUFFER;
36+
include_stack[++include_count] = yy_current_buffer();
3737

3838
yyin = fopen( yytext, "r" );
3939
if ( ! yyin ){

0 commit comments

Comments
 (0)