Home | History | Annotate | Download | only in Script
      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 
     62 extern "C++" {
     63 
     64 struct yy_buffer_state;
     65 typedef int yy_state_type;
     66 
     67 class FlexLexer
     68 {
     69 public:
     70   virtual ~FlexLexer()        { }
     71 
     72   const char* YYText() const  { return yytext; }
     73   int YYLeng()        const   { return yyleng; }
     74 
     75   virtual void
     76   yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0;
     77   virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0;
     78   virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0;
     79   virtual void yy_delete_buffer( yy_buffer_state* b ) = 0;
     80   virtual void yyrestart( std::istream* s ) = 0;
     81   virtual void yyrestart( std::istream& s ) = 0;
     82 
     83   virtual int yylex() = 0;
     84 
     85   // Call yylex with new input/output sources.
     86   int yylex( std::istream& new_in, std::ostream& new_out )
     87   {
     88     switch_streams( new_in, new_out );
     89     return yylex();
     90   }
     91 
     92   int yylex( std::istream* new_in, std::ostream* new_out = 0)
     93   {
     94     switch_streams( new_in, new_out );
     95     return yylex();
     96   }
     97 
     98   // Switch to new input/output streams.  A nil stream pointer
     99   // indicates "keep the current one".
    100   virtual void switch_streams( std::istream* new_in,
    101                                std::ostream* new_out ) = 0;
    102   virtual void switch_streams( std::istream& new_in,
    103                                std::ostream& new_out ) = 0;
    104 
    105   int lineno() const          { return yylineno; }
    106 
    107   int debug() const           { return yy_flex_debug; }
    108   void set_debug( int flag )  { yy_flex_debug = flag; }
    109 
    110 protected:
    111   char* yytext;
    112   int yyleng;
    113   int yylineno;       // only maintained if you use %option yylineno
    114   int yy_flex_debug;  // only has effect with -d or "%option debug"
    115 };
    116 
    117 }
    118 #endif // FLEXLEXER_H
    119 
    120 #if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce)
    121 // Either this is the first time through (yyFlexLexerOnce not defined),
    122 // or this is a repeated include to define a different flavor of
    123 // yyFlexLexer, as discussed in the flex manual.
    124 # define yyFlexLexerOnce
    125 
    126 extern "C++" {
    127 
    128 class yyFlexLexer : public FlexLexer {
    129 public:
    130   // arg_yyin and arg_yyout default to the cin and cout, but we
    131   // only make that assignment when initializing in yylex().
    132   yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout );
    133   yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 );
    134 private:
    135   void ctor_common();
    136 
    137 public:
    138 
    139   virtual ~yyFlexLexer();
    140 
    141   void yy_switch_to_buffer( yy_buffer_state* new_buffer );
    142   yy_buffer_state* yy_create_buffer( std::istream* s, int size );
    143   yy_buffer_state* yy_create_buffer( std::istream& s, int size );
    144   void yy_delete_buffer( yy_buffer_state* b );
    145   void yyrestart( std::istream* s );
    146   void yyrestart( std::istream& s );
    147 
    148   void yypush_buffer_state( yy_buffer_state* new_buffer );
    149   void yypop_buffer_state();
    150 
    151   virtual int yylex();
    152   virtual void switch_streams( std::istream& new_in, std::ostream& new_out );
    153   virtual void switch_streams( std::istream* new_in = 0, std::ostream* new_out = 0 );
    154   virtual int yywrap();
    155 
    156 protected:
    157   virtual int LexerInput( char* buf, int max_size );
    158   virtual void LexerOutput( const char* buf, int size );
    159   virtual void LexerError( const char* msg );
    160 
    161   void yyunput( int c, char* buf_ptr );
    162   int yyinput();
    163 
    164   void yy_load_buffer_state();
    165   void yy_init_buffer( yy_buffer_state* b, std::istream& s );
    166   void yy_flush_buffer( yy_buffer_state* b );
    167 
    168   int yy_start_stack_ptr;
    169   int yy_start_stack_depth;
    170   int* yy_start_stack;
    171 
    172   void yy_push_state( int new_state );
    173   void yy_pop_state();
    174   int yy_top_state();
    175 
    176   yy_state_type yy_get_previous_state();
    177   yy_state_type yy_try_NUL_trans( yy_state_type current_state );
    178   int yy_get_next_buffer();
    179 
    180   std::istream yyin;  // input source for default LexerInput
    181   std::ostream yyout; // output sink for default LexerOutput
    182 
    183   // yy_hold_char holds the character lost when yytext is formed.
    184   char yy_hold_char;
    185 
    186   // Number of characters read into yy_ch_buf.
    187   int yy_n_chars;
    188 
    189   // Points to current character in buffer.
    190   char* yy_c_buf_p;
    191 
    192   int yy_init;                // whether we need to initialize
    193   int yy_start;               // start state number
    194 
    195   // Flag which is used to allow yywrap()'s to do buffer switches
    196   // instead of setting up a fresh yyin.  A bit of a hack ...
    197   int yy_did_buffer_switch_on_eof;
    198 
    199 
    200   size_t yy_buffer_stack_top; /**< index of top of stack. */
    201   size_t yy_buffer_stack_max; /**< capacity of stack. */
    202   yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
    203   void yyensure_buffer_stack(void);
    204 
    205   // The following are not always needed, but may be depending
    206   // on use of certain flex features (like REJECT or yymore()).
    207 
    208   yy_state_type yy_last_accepting_state;
    209   char* yy_last_accepting_cpos;
    210 
    211   yy_state_type* yy_state_buf;
    212   yy_state_type* yy_state_ptr;
    213 
    214   char* yy_full_match;
    215   int* yy_full_state;
    216   int yy_full_lp;
    217 
    218   int yy_lp;
    219   int yy_looking_for_trail_begin;
    220 
    221   int yy_more_flag;
    222   int yy_more_len;
    223   int yy_more_offset;
    224   int yy_prev_more_offset;
    225 };
    226 
    227 }
    228 
    229 #endif  // yyFlexLexer || ! yyFlexLexerOnce
    230