FlexLexer.h revision 2bb9d97b7dd35f78e67c3a774f2029c22b4fbb0b
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// BEGIN android-modified: work around flex differences on Darwin and Linux
143#if !defined(DARWIN_FLEX)
144        virtual int LexerInput( char* buf, int max_size );
145        virtual void LexerOutput( const char* buf, int size );
146#else
147        virtual size_t LexerInput( char* buf, size_t max_size );
148        virtual void LexerOutput( const char* buf, size_t size );
149#endif
150// END android-modified
151	virtual void LexerError( const char* msg );
152
153	void yyunput( int c, char* buf_ptr );
154	int yyinput();
155
156	void yy_load_buffer_state();
157	void yy_init_buffer( struct yy_buffer_state* b, FLEX_STD istream* s );
158	void yy_flush_buffer( struct yy_buffer_state* b );
159
160	int yy_start_stack_ptr;
161	int yy_start_stack_depth;
162	int* yy_start_stack;
163
164	void yy_push_state( int new_state );
165	void yy_pop_state();
166	int yy_top_state();
167
168	yy_state_type yy_get_previous_state();
169	yy_state_type yy_try_NUL_trans( yy_state_type current_state );
170	int yy_get_next_buffer();
171
172	FLEX_STD istream* yyin;	// input source for default LexerInput
173	FLEX_STD ostream* yyout;	// output sink for default LexerOutput
174
175	// yy_hold_char holds the character lost when yytext is formed.
176	char yy_hold_char;
177
178	// Number of characters read into yy_ch_buf.
179	int yy_n_chars;
180
181	// Points to current character in buffer.
182	char* yy_c_buf_p;
183
184	int yy_init;		// whether we need to initialize
185	int yy_start;		// start state number
186
187	// Flag which is used to allow yywrap()'s to do buffer switches
188	// instead of setting up a fresh yyin.  A bit of a hack ...
189	int yy_did_buffer_switch_on_eof;
190
191
192	size_t yy_buffer_stack_top; /**< index of top of stack. */
193	size_t yy_buffer_stack_max; /**< capacity of stack. */
194	struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
195	void yyensure_buffer_stack(void);
196
197	// The following are not always needed, but may be depending
198	// on use of certain flex features (like REJECT or yymore()).
199
200	yy_state_type yy_last_accepting_state;
201	char* yy_last_accepting_cpos;
202
203	yy_state_type* yy_state_buf;
204	yy_state_type* yy_state_ptr;
205
206	char* yy_full_match;
207	int* yy_full_state;
208	int yy_full_lp;
209
210	int yy_lp;
211	int yy_looking_for_trail_begin;
212
213	int yy_more_flag;
214	int yy_more_len;
215	int yy_more_offset;
216	int yy_prev_more_offset;
217};
218
219}
220
221#endif // yyFlexLexer || ! yyFlexLexerOnce
222
223