FlexLexer.h revision 8ff673e0a04af20135485dc422bcba264e4c0510
1//===- FlexLexer.h --------------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// -*-C++-*-
11// FlexLexer.h -- define interfaces for lexical analyzer classes generated
12// by flex
13
14// Copyright (c) 1993 The Regents of the University of California.
15// All rights reserved.
16//
17// This code is derived from software contributed to Berkeley by
18// Kent Williams and Tom Epperly.
19//
20//  Redistribution and use in source and binary forms, with or without
21//  modification, are permitted provided that the following conditions
22//  are met:
23
24//  1. Redistributions of source code must retain the above copyright
25//  notice, this list of conditions and the following disclaimer.
26//  2. Redistributions in binary form must reproduce the above copyright
27//  notice, this list of conditions and the following disclaimer in the
28//  documentation and/or other materials provided with the distribution.
29
30//  Neither the name of the University nor the names of its contributors
31//  may be used to endorse or promote products derived from this software
32//  without specific prior written permission.
33
34//  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
35//  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
36//  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
37//  PURPOSE.
38
39// This file defines FlexLexer, an abstract class which specifies the
40// external interface provided to flex C++ lexer objects, and yyFlexLexer,
41// which defines a particular lexer class.
42//
43// If you want to create multiple lexer classes, you use the -P flag
44// to rename each yyFlexLexer to some other xxFlexLexer.  You then
45// include <FlexLexer.h> in your other sources once per lexer class:
46//
47//	#undef yyFlexLexer
48//	#define yyFlexLexer xxFlexLexer
49//	#include <FlexLexer.h>
50//
51//	#undef yyFlexLexer
52//	#define yyFlexLexer zzFlexLexer
53//	#include <FlexLexer.h>
54//	...
55
56#ifndef __FLEX_LEXER_H
57// Never included before - need to define base class.
58#define __FLEX_LEXER_H
59
60#include <iostream>
61#  ifndef FLEX_STD
62#    define FLEX_STD std::
63#  endif
64
65extern "C++" {
66
67struct yy_buffer_state;
68typedef int yy_state_type;
69
70class FlexLexer {
71public:
72	virtual ~FlexLexer()	{ }
73
74	const char* YYText() const	{ return yytext; }
75	int YYLeng()	const	{ return yyleng; }
76
77	virtual void
78		yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
79	virtual struct yy_buffer_state*
80		yy_create_buffer( FLEX_STD istream* s, int size ) = 0;
81	virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
82	virtual void yyrestart( FLEX_STD istream* s ) = 0;
83
84	virtual int yylex() = 0;
85
86	// Call yylex with new input/output sources.
87	int yylex( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 )
88		{
89		switch_streams( new_in, new_out );
90		return yylex();
91		}
92
93	// Switch to new input/output streams.  A nil stream pointer
94	// indicates "keep the current one".
95	virtual void switch_streams( FLEX_STD istream* new_in = 0,
96					FLEX_STD ostream* new_out = 0 ) = 0;
97
98	int lineno() const		{ return yylineno; }
99
100	int debug() const		{ return yy_flex_debug; }
101	void set_debug( int flag )	{ yy_flex_debug = flag; }
102
103protected:
104	char* yytext;
105	int yyleng;
106	int yylineno;		// only maintained if you use %option yylineno
107	int yy_flex_debug;	// only has effect with -d or "%option debug"
108};
109
110}
111#endif // FLEXLEXER_H
112
113#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
114// Either this is the first time through (yyFlexLexerOnce not defined),
115// or this is a repeated include to define a different flavor of
116// yyFlexLexer, as discussed in the flex manual.
117#define yyFlexLexerOnce
118
119extern "C++" {
120
121class yyFlexLexer : public FlexLexer {
122public:
123	// arg_yyin and arg_yyout default to the cin and cout, but we
124	// only make that assignment when initializing in yylex().
125	yyFlexLexer( FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0 );
126
127	virtual ~yyFlexLexer();
128
129	void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
130	struct yy_buffer_state* yy_create_buffer( FLEX_STD istream* s, int size );
131	void yy_delete_buffer( struct yy_buffer_state* b );
132	void yyrestart( FLEX_STD istream* s );
133
134	void yypush_buffer_state( struct yy_buffer_state* new_buffer );
135	void yypop_buffer_state();
136
137	virtual int yylex();
138	virtual void switch_streams( FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0 );
139	virtual int yywrap();
140
141protected:
142	virtual int LexerInput( char* buf, int max_size );
143	virtual void LexerOutput( const char* buf, int size );
144	/* BEGIN ANDROID WAR - Mac builds use size_t until we switch to prebuilts */
145	virtual size_t LexerInput( char* buf, size_t max_size );
146	virtual void LexerOutput( const char* buf, size_t size );
147	/* END ANDROID WAR */
148	virtual void LexerError( const char* msg );
149
150	void yyunput( int c, char* buf_ptr );
151	int yyinput();
152
153	void yy_load_buffer_state();
154	void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
155	void yy_flush_buffer( struct yy_buffer_state* b );
156
157	int yy_start_stack_ptr;
158	int yy_start_stack_depth;
159	int* yy_start_stack;
160
161	void yy_push_state( int new_state );
162	void yy_pop_state();
163	int yy_top_state();
164
165	yy_state_type yy_get_previous_state();
166	yy_state_type yy_try_NUL_trans( yy_state_type current_state );
167	int yy_get_next_buffer();
168
169	FLEX_STD istream* yyin;	// input source for default LexerInput
170	FLEX_STD ostream* yyout;	// output sink for default LexerOutput
171
172	// yy_hold_char holds the character lost when yytext is formed.
173	char yy_hold_char;
174
175	// Number of characters read into yy_ch_buf.
176	int yy_n_chars;
177
178	// Points to current character in buffer.
179	char* yy_c_buf_p;
180
181	int yy_init;		// whether we need to initialize
182	int yy_start;		// start state number
183
184	// Flag which is used to allow yywrap()'s to do buffer switches
185	// instead of setting up a fresh yyin.  A bit of a hack ...
186	int yy_did_buffer_switch_on_eof;
187
188
189	size_t yy_buffer_stack_top; /**< index of top of stack. */
190	size_t yy_buffer_stack_max; /**< capacity of stack. */
191	struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
192	void yyensure_buffer_stack(void);
193
194	// The following are not always needed, but may be depending
195	// on use of certain flex features (like REJECT or yymore()).
196
197	yy_state_type yy_last_accepting_state;
198	char* yy_last_accepting_cpos;
199
200	yy_state_type* yy_state_buf;
201	yy_state_type* yy_state_ptr;
202
203	char* yy_full_match;
204	int* yy_full_state;
205	int yy_full_lp;
206
207	int yy_lp;
208	int yy_looking_for_trail_begin;
209
210	int yy_more_flag;
211	int yy_more_len;
212	int yy_more_offset;
213	int yy_prev_more_offset;
214};
215
216}
217
218#endif // yyFlexLexer || ! yyFlexLexerOnce
219
220