Commit dcdf2b3c authored by Akim Demaille's avatar Akim Demaille
Browse files

build: adjust to Flex 2.6

The new version of Flex made incompatible changes with the previous
version.  Deal with it.

* configure.ac (config.hh): Define the version of Flex.
* vcsn/misc/flex-lexer.hh: Depend on the Flex version.
Add support for references.
(putback): New.
* lib/vcsn/rat/parse.yy: Adjust.
parent 038381a8
Loading
Loading
Loading
Loading
+12 −0
Changes for configure.ac: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -287,6 +287,18 @@ AC_CHECK_PROGS([FLEX], [flex], [no])
LEX=$FLEX
AM_PROG_LEX
AC_CONFIG_FILES([build-aux/bin/flex++], [chmod +x build-aux/bin/flex++])
FLEX_MAJOR_VERSION=$(flex --version |
                      perl -ne 'm/(\d+)\.(\d+)(?:\.(\d+))?/ && print($1)')
FLEX_MINOR_VERSION=$(flex --version |
                      perl -ne 'm/(\d+)\.(\d+)(?:\.(\d+))?/ && print($2)')
FLEX_SUBMINOR_VERSION=$(flex --version |
                      perl -ne 'm/(\d+)\.(\d+)(?:\.(\d+))?/ && print($3)')
AC_DEFINE_UNQUOTED([FLEX_MAJOR_VERSION], [$FLEX_MAJOR_VERSION],
                   [Define to the Flex major version.])
AC_DEFINE_UNQUOTED([FLEX_MINOR_VERSION], [$FLEX_MINOR_VERSION],
                   [Define to the Flex minor version.])
AC_DEFINE_UNQUOTED([FLEX_SUBMINOR_VERSION], [$FLEX_SUBMINOR_VERSION],
                   [Define to the Flex subminor version.])

AC_ARG_VAR([BISON], [Bison parser generator])
AC_CHECK_PROGS([BISON], [bison])
+2 −2
Changes for lib/vcsn/rat/parse.yy: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -219,8 +219,8 @@ input:

terminator.opt:
  %empty     {}
| ","        { driver_.scanner_->yyin->putback(','); }
| ")"        { driver_.scanner_->yyin->putback(')'); }
| ","        { driver_.scanner_->putback(','); }
| ")"        { driver_.scanner_->putback(')'); }
;

sum:
+43 −12
Changes for vcsn/misc/flex-lexer.hh: 43 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -47,6 +47,12 @@
#ifndef VCSN_MISC_FLEX_LEXER_HH
# define VCSN_MISC_FLEX_LEXER_HH

# include <vcsn/config.hh>

# ifndef FLEX_STD
#  define FLEX_STD std::
# endif

struct yy_buffer_state;
typedef int yy_state_type;

@@ -58,13 +64,17 @@ public:
  const char* YYText() const    { return yytext; }
  int YYLeng()  const   { return yyleng; }

  virtual void
  yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0;
  virtual struct yy_buffer_state*
  yy_create_buffer( std::istream* s, int size ) = 0;
  virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0;
  virtual void yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0;
  virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0;
  virtual void yy_delete_buffer( yy_buffer_state* b ) = 0;
  virtual void yyrestart( std::istream* s ) = 0;

#if 2 <= VCSN_FLEX_MAJOR_VERSION && 6 <= VCSN_FLEX_MINOR_VERSION
  virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0;
  virtual void switch_streams(std::istream& new_in, std::ostream& new_out ) = 0;
  virtual void yyrestart( std::istream& s ) = 0;
#endif

  // Switch to new input/output streams.  A nil stream pointer
  // indicates "keep the current one".
  virtual void switch_streams( std::istream* new_in = nullptr,
@@ -92,16 +102,22 @@ class yyFlexLexer : public FlexLexer
public:
  // arg_yyin and arg_yyout default to the cin and cout, but we
  // only make that assignment when initializing in yylex().
  yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout );
  yyFlexLexer( std::istream* arg_yyin = nullptr, std::ostream* arg_yyout = nullptr );

private:
  void ctor_common();

public:

  virtual ~yyFlexLexer();

  void yy_switch_to_buffer( struct yy_buffer_state* new_buffer );
  struct yy_buffer_state* yy_create_buffer( std::istream* s, int size );
  void yy_delete_buffer( struct yy_buffer_state* b );
  void yy_switch_to_buffer( yy_buffer_state* new_buffer );
  yy_buffer_state* yy_create_buffer( std::istream* s, int size );
  void yy_delete_buffer( yy_buffer_state* b );
  void yyrestart( std::istream* s );

  void yypush_buffer_state( struct yy_buffer_state* new_buffer );
  void yypush_buffer_state( yy_buffer_state* new_buffer );
  void yypop_buffer_state();

  // The signature of yylex.
@@ -117,7 +133,18 @@ public:
                              std::ostream* new_out = nullptr );
  virtual int yywrap();

#if 2 <= VCSN_FLEX_MAJOR_VERSION && 6 <= VCSN_FLEX_MINOR_VERSION
  virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size );
  void yy_init_buffer( yy_buffer_state* b, std::istream& s );
  virtual void switch_streams(std::istream& new_in, std::ostream& new_out );
  virtual void yyrestart( std::istream& s );

  std::istream yyin;   // input source for default LexerInput
  void putback(char c) { yyin.putback(c); }
#else
  std::istream * yyin;   // input source for default LexerInput
  void putback(char c) { yyin->putback(c); }
#endif

protected:
  virtual int LexerInput( char* buf, int max_size );
@@ -128,8 +155,8 @@ protected:
  int yyinput();

  void yy_load_buffer_state();
  void yy_init_buffer( struct yy_buffer_state* b, std::istream* s );
  void yy_flush_buffer( struct yy_buffer_state* b );
  void yy_init_buffer( yy_buffer_state* b, std::istream* s );
  void yy_flush_buffer( yy_buffer_state* b );

  int yy_start_stack_ptr;
  int yy_start_stack_depth;
@@ -143,7 +170,11 @@ protected:
  yy_state_type yy_try_NUL_trans( yy_state_type current_state );
  int yy_get_next_buffer();

#if 2 <= VCSN_FLEX_MAJOR_VERSION && 6 <= VCSN_FLEX_MINOR_VERSION
  std::ostream yyout;  // output sink for default LexerOutput
#else
  std::ostream * yyout;  // output sink for default LexerOutput
#endif

  // yy_hold_char holds the character lost when yytext is formed.
  char yy_hold_char;
@@ -164,7 +195,7 @@ protected:

  size_t yy_buffer_stack_top; /**< index of top of stack. */
  size_t yy_buffer_stack_max; /**< capacity of stack. */
  struct yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
  yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */
  void yyensure_buffer_stack(void);

  // The following are not always needed, but may be depending