187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//===- FlexLexer.h --------------------------------------------------------===//
287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//                     The MCLinker Project
487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// This file is distributed under the University of Illinois Open Source
687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// License. See LICENSE.TXT for details.
787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//===----------------------------------------------------------------------===//
987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
1087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// -*-C++-*-
1187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// FlexLexer.h -- define interfaces for lexical analyzer classes generated
1287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// by flex
1387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
1487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// Copyright (c) 1993 The Regents of the University of California.
1587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// All rights reserved.
1687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
1787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// This code is derived from software contributed to Berkeley by
1887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// Kent Williams and Tom Epperly.
1987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
2087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  Redistribution and use in source and binary forms, with or without
2187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  modification, are permitted provided that the following conditions
2287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  are met:
2387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
2487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  1. Redistributions of source code must retain the above copyright
2587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  notice, this list of conditions and the following disclaimer.
2687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  2. Redistributions in binary form must reproduce the above copyright
2787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  notice, this list of conditions and the following disclaimer in the
2887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  documentation and/or other materials provided with the distribution.
2987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  Neither the name of the University nor the names of its contributors
3187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  may be used to endorse or promote products derived from this software
3287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  without specific prior written permission.
3387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
3587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
3687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//  PURPOSE.
3887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
3987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// This file defines FlexLexer, an abstract class which specifies the
4087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// external interface provided to flex C++ lexer objects, and yyFlexLexer,
4187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// which defines a particular lexer class.
4287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
4387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// If you want to create multiple lexer classes, you use the -P flag
4487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// to rename each yyFlexLexer to some other xxFlexLexer.  You then
4587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// include <FlexLexer.h> in your other sources once per lexer class:
4687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
4787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#undef yyFlexLexer
4887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#define yyFlexLexer xxFlexLexer
4987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#include <FlexLexer.h>
5087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//
5187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#undef yyFlexLexer
5287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#define yyFlexLexer zzFlexLexer
5387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	#include <FlexLexer.h>
5487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines//	...
5587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
5687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#ifndef __FLEX_LEXER_H
5787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// Never included before - need to define base class.
5887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#define __FLEX_LEXER_H
5987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
6087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#include <iostream>
6137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef FLEX_STD
6237b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define FLEX_STD std::
6337b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif
6487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
6587f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesextern "C++" {
6687f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesstruct yy_buffer_state;
6787f34658dec9097d987d254a990ea7f311bfc95fStephen Hinestypedef int yy_state_type;
6887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
6987f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass FlexLexer {
7037b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
7137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual ~FlexLexer() {}
7237b74a387bb3993387029859c2d9d051c41c724eStephen Hines
7337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  const char* YYText() const { return yytext; }
7437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int YYLeng() const { return yyleng; }
7537b74a387bb3993387029859c2d9d051c41c724eStephen Hines
7637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void yy_switch_to_buffer(struct yy_buffer_state* new_buffer) = 0;
7737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s,
7837b74a387bb3993387029859c2d9d051c41c724eStephen Hines                                                   int size) = 0;
7937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void yy_delete_buffer(struct yy_buffer_state* b) = 0;
8037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void yyrestart(FLEX_STD istream* s) = 0;
8137b74a387bb3993387029859c2d9d051c41c724eStephen Hines
8237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual int yylex() = 0;
8337b74a387bb3993387029859c2d9d051c41c724eStephen Hines
8437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // Call yylex with new input/output sources.
8537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yylex(FLEX_STD istream* new_in, FLEX_STD ostream* new_out = 0) {
8637b74a387bb3993387029859c2d9d051c41c724eStephen Hines    switch_streams(new_in, new_out);
8737b74a387bb3993387029859c2d9d051c41c724eStephen Hines    return yylex();
8837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  }
8937b74a387bb3993387029859c2d9d051c41c724eStephen Hines
9037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // Switch to new input/output streams.  A nil stream pointer
9137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // indicates "keep the current one".
9237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void switch_streams(FLEX_STD istream* new_in = 0,
9337b74a387bb3993387029859c2d9d051c41c724eStephen Hines                              FLEX_STD ostream* new_out = 0) = 0;
9487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
9537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int lineno() const { return yylineno; }
9637b74a387bb3993387029859c2d9d051c41c724eStephen Hines
9737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int debug() const { return yy_flex_debug; }
9837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void set_debug(int flag) { yy_flex_debug = flag; }
9937b74a387bb3993387029859c2d9d051c41c724eStephen Hines
10037b74a387bb3993387029859c2d9d051c41c724eStephen Hines protected:
10137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  char* yytext;
10237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yyleng;
10337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yylineno;       // only maintained if you use %option yylineno
10437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_flex_debug;  // only has effect with -d or "%option debug"
10537b74a387bb3993387029859c2d9d051c41c724eStephen Hines};
10687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines}
10737b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // FLEXLEXER_H
10887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
10937b74a387bb3993387029859c2d9d051c41c724eStephen Hines#if defined(yyFlexLexer) || !defined(yyFlexLexerOnce)
11087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// Either this is the first time through (yyFlexLexerOnce not defined),
11187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// or this is a repeated include to define a different flavor of
11287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines// yyFlexLexer, as discussed in the flex manual.
11387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines#define yyFlexLexerOnce
11487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
11587f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesextern "C++" {
11687f34658dec9097d987d254a990ea7f311bfc95fStephen Hinesclass yyFlexLexer : public FlexLexer {
11737b74a387bb3993387029859c2d9d051c41c724eStephen Hines public:
11837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // arg_yyin and arg_yyout default to the cin and cout, but we
11937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // only make that assignment when initializing in yylex().
12037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yyFlexLexer(FLEX_STD istream* arg_yyin = 0, FLEX_STD ostream* arg_yyout = 0);
12187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
12237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual ~yyFlexLexer();
12387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
12437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_switch_to_buffer(struct yy_buffer_state* new_buffer);
12537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  struct yy_buffer_state* yy_create_buffer(FLEX_STD istream* s, int size);
12637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_delete_buffer(struct yy_buffer_state* b);
12737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yyrestart(FLEX_STD istream* s);
12887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
12937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yypush_buffer_state(struct yy_buffer_state* new_buffer);
13037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yypop_buffer_state();
13187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
13237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual int yylex();
13337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void switch_streams(FLEX_STD istream* new_in,
13437b74a387bb3993387029859c2d9d051c41c724eStephen Hines                              FLEX_STD ostream* new_out = 0);
13537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual int yywrap();
13687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
13737b74a387bb3993387029859c2d9d051c41c724eStephen Hines protected:
13837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual int LexerInput(char* buf, int max_size);
13937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void LexerOutput(const char* buf, int size);
14037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  virtual void LexerError(const char* msg);
14187f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
14237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yyunput(int c, char* buf_ptr);
14337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yyinput();
14487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
14537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_load_buffer_state();
14637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_init_buffer(struct yy_buffer_state* b, FLEX_STD istream* s);
14737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_flush_buffer(struct yy_buffer_state* b);
14887f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
14937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_start_stack_ptr;
15037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_start_stack_depth;
15137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int* yy_start_stack;
15287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
15337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_push_state(int new_state);
15437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yy_pop_state();
15537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_top_state();
15687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
15737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yy_state_type yy_get_previous_state();
15837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yy_state_type yy_try_NUL_trans(yy_state_type current_state);
15937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_get_next_buffer();
16087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
16137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  FLEX_STD istream* yyin;   // input source for default LexerInput
16237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  FLEX_STD ostream* yyout;  // output sink for default LexerOutput
16387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
16437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // yy_hold_char holds the character lost when yytext is formed.
16537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  char yy_hold_char;
16687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
16737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // Number of characters read into yy_ch_buf.
16837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_n_chars;
16987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
17037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // Points to current character in buffer.
17137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  char* yy_c_buf_p;
17287f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
17337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_init;   // whether we need to initialize
17437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_start;  // start state number
17587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
17637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // Flag which is used to allow yywrap()'s to do buffer switches
17737b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // instead of setting up a fresh yyin.  A bit of a hack ...
17837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_did_buffer_switch_on_eof;
17987f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
18037b74a387bb3993387029859c2d9d051c41c724eStephen Hines  size_t yy_buffer_stack_top;               /**< index of top of stack. */
18137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  size_t yy_buffer_stack_max;               /**< capacity of stack. */
18237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  struct yy_buffer_state** yy_buffer_stack; /**< Stack as an array. */
18337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  void yyensure_buffer_stack(void);
18487f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
18537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // The following are not always needed, but may be depending
18637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  // on use of certain flex features (like REJECT or yymore()).
18787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
18837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yy_state_type yy_last_accepting_state;
18937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  char* yy_last_accepting_cpos;
19087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
19137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yy_state_type* yy_state_buf;
19237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  yy_state_type* yy_state_ptr;
19387f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
19437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  char* yy_full_match;
19537b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int* yy_full_state;
19637b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_full_lp;
19787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
19837b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_lp;
19937b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_looking_for_trail_begin;
20087f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
20137b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_more_flag;
20237b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_more_len;
20337b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_more_offset;
20437b74a387bb3993387029859c2d9d051c41c724eStephen Hines  int yy_prev_more_offset;
20587f34658dec9097d987d254a990ea7f311bfc95fStephen Hines};
20687f34658dec9097d987d254a990ea7f311bfc95fStephen Hines}
20787f34658dec9097d987d254a990ea7f311bfc95fStephen Hines
20837b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif  // yyFlexLexer || ! yyFlexLexerOnce
209