pp_lex.hh

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 #ifndef lestes__lang__cplus__lex___pp_lex_hh___included
00029 #define lestes__lang__cplus__lex___pp_lex_hh___included
00030 
00031 /*! \file
00032   \brief Integration with flexer.
00033   
00034   Declaration of pp_lex class wrapping pp_lex_guts flexer.
00035   Enables sharing flexer by concurrent instances of pp_lex via
00036   switching flexer contexts.
00037   \author pt
00038 */
00039 #include <lestes/common.hh>
00040 #include <lestes/lang/cplus/lex/ucn_token.hh>
00041 
00042 package(lestes);
00043 
00044 package(std);
00045 // forward declaration to avoid cycle
00046 class file_info;
00047 class source_location;
00048 end_package(std);
00049 
00050 package(lang);
00051 package(cplus);
00052 package(lex);
00053 
00054 // forward declaration to avoid cycle
00055 class pp_token;
00056 class pre_lex;
00057 class simple_location;
00058 class ucn_token_buffer;
00059 class line_control;
00060 
00061 package(pp_lex_guts);
00062 //! Forward declaration of flex buffer type.
00063 struct yy_buffer_state;
00064 end_package(pp_lex_guts);
00065 
00066 /*!
00067   \brief Integration with flexer.
00068   
00069   Handles integration with pp_lex_guts flexer. Passes special character classes to flexer,
00070   storing actual characters in own buffer. Each instance is connected to
00071   flexer by calling activate() prior to reading tokens (after file change etc.).
00072 */
00073 class pp_lex: public ::lestes::std::object {
00074 public:
00075         //! Type of character in lex.
00076         typedef char char_type;
00077         //! Type of size in lex.
00078         typedef int size_type;
00079         //! Finalizes object.
00080         virtual ~pp_lex(void);
00081         //! Prepares pp_lex_guts to communicate with this object.
00082         void activate(void);
00083         //! Stores next characters for YY_INPUT.
00084         size_type yy_input(char_type *cbuf, size_type max);
00085         //! Saves location of current input token.
00086         void location_save(void);
00087         //! Creates location for current token.
00088         ptr<source_location> location_create(void) const;
00089         //! Returns the line control.
00090         ptr<line_control> lines_get(void) const;
00091         //! Reads token from flex.
00092         ptr<pp_token> read(bool read_include);
00093         //! Sets interactive flag.
00094         void interactive_set(bool a_interactive);
00095         //! Returns interactive flag.
00096         bool interactive_get(void) const;
00097         //! Returns new instance.
00098         static ptr<pp_lex> create(const ptr<pre_lex> &a_input, const ptr<line_control> &a_lines);
00099 protected:
00100         //! Creates the object.
00101         pp_lex(const ptr<pre_lex> &a_input, const ptr<line_control> &a_lines);
00102         //! Marks the object.
00103         virtual void gc_mark(void);
00104 private:
00105         //! Type of flex buffer.
00106         typedef struct pp_lex_guts::yy_buffer_state *yy_buffer_type;
00107         //! Reads next character from input.
00108         char_type read_char(void);
00109         //! Flag for interactiveness.
00110         bool interactive;
00111         //! Input stream of tokens.
00112         srp<pre_lex> input;
00113         //! Physical location of currently processed token.
00114         srp<simple_location> physical;
00115         //! Line control for transforming locations.
00116         srp<line_control> lines;
00117         //! Buffer with ucn tokens.
00118         srp<ucn_token_buffer> buffer;
00119         //! Error token buffer.
00120         srp<ucn_token_buffer> errors;
00121         //! Flex buffer.
00122         yy_buffer_type yy_buffer;
00123         //! Hides copy constructor.
00124         pp_lex(const pp_lex &copy);
00125         //! Hides assignment operator.
00126         pp_lex &operator=(const pp_lex &rhs);
00127 };
00128 
00129 end_package(lex);
00130 end_package(cplus);
00131 end_package(lang);
00132 end_package(lestes);
00133 
00134 #endif
00135 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:23:10 2007 for lestes by doxygen 1.5.1-20070107