token_stream.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___token_stream_hh___included
00029 #define lestes__lang__cplus__lex___token_stream_hh___included
00030 
00031 /*! \file
00032   \brief Stream of tokens.
00033 
00034         Declaration of token_stream class representing stream of tokens.
00035         \author pt
00036 */
00037 
00038 #include <lestes/common.hh>
00039 #include <lestes/lang/cplus/lex/token_input.hh>
00040 #include <lestes/std/list.hh>
00041 #include <iosfwd>
00042 
00043 package(lestes);
00044 
00045 package(std);
00046 // forward declarations to avoid cycle
00047 class source_location;
00048 end_package(std);
00049 
00050 package(lang);
00051 package(cplus);
00052 package(lex);
00053 
00054 // forward declaration to break cycle
00055 class pp_token;
00056 class pp_filter;
00057 class token_sequence;
00058 class macro;
00059 
00060 /*!
00061   \brief Stream of tokens.
00062 
00063   Represents input stream of tokens, with access at front.
00064   The stream is connected to pp_filter to read tokens from.
00065   Never reads beyond the next newline, if not asked for.
00066 */
00067 class token_stream: public token_input {
00068 public:
00069         //! Reads first token.
00070         ptr<pp_token> read(void);
00071         //! Returns front token.
00072         ptr<pp_token> peek_front(void);
00073         //! Reads front token, squeezing whitespace.
00074         ptr<pp_token> read_front(void);
00075         //! Reads front token, skipping front whitespace, but not newline.
00076         ptr<pp_token> read_front_skip_ws(void);
00077         //! Skips front whitespace.
00078         bool skip_front_ws(void);
00079         //! Reads next line in input.
00080         ptr<token_sequence> read_line(void);
00081         //! Expands next line in input.
00082         ptr<token_sequence> expand_line(const ptr<macro_storage> &macros);
00083         // TODO pt remove
00084         //! Prints debug dump.
00085         void debug_print(::std::ostream &o);
00086         //! Returns stream with input.
00087         static ptr<token_stream> create(const ptr<pp_filter> &a_input);
00088 protected:   
00089         //! Creates stream.
00090         token_stream(const ptr<pp_filter> &a_input);
00091         //! Prepends a sequence.
00092         void prepend(const ptr<token_sequence> &ts);
00093         //! Marks the object.
00094         virtual void gc_mark(void);
00095 private:
00096         //! The type of sequence container.
00097         typedef ::lestes::std::list< srp<pp_token> > sequence_type;
00098         //! Loads next line.
00099         bool load_input(void);
00100         
00101         // TODO pt remove //! State of the stream.
00102         //state_type state;
00103 
00104         //! The eof token.
00105         srp<pp_token> file_end;
00106         //! The sequence container.
00107         srp<sequence_type> sequence;
00108         //! Input into this sequence.
00109         // TODO pt remove srp<pp_filter> input;
00110 };
00111 
00112 //! Prints debug dump of token stream.
00113 ::std::ostream &operator<<(::std::ostream &o, const ptr<token_stream> &ts);
00114 
00115 end_package(lex);
00116 end_package(cplus);
00117 end_package(lang);
00118 end_package(lestes);
00119 #endif
00120 /* vim: set ft=lestes : */

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