token_sequence.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_sequence_hh___included
00029 #define lestes__lang__cplus__lex___token_sequence_hh___included
00030 
00031 /*! \file
00032         Declaration of token_sequence class representing sequence of tokens.
00033         \author pt
00034 */
00035 
00036 #include <lestes/common.hh>
00037 #include <lestes/std/list.hh>
00038 #include <lestes/lang/cplus/lex/token_input.hh>
00039 #include <iosfwd>
00040 
00041 package(lestes);
00042 
00043 package(std);
00044 // forward declarations to avoid cycle
00045 class source_location;
00046 end_package(std);
00047 
00048 package(lang);
00049 package(cplus);
00050 package(lex);
00051 
00052 // forward declaration to break cycle
00053 class pp_token;
00054 class macro;
00055 class macro_storage;
00056 class taboo_macros;
00057 
00058 /*!
00059   Represents sequence of tokens, with access at both ends.
00060 */
00061 class token_sequence: public token_input {
00062 private:
00063         //! The type of sequence container.
00064         typedef ::lestes::std::list< srp<pp_token> > sequence_type;
00065 public:
00066         /*!
00067           \brief The type for size of the sequence.
00068           \author TMA
00069          */
00070         typedef sequence_type::size_type size_type;
00071         //! Reads first token.
00072         ptr<pp_token> read(void);
00073         //! Returns front token.
00074         ptr<pp_token> peek_front(void);
00075         //! Returns back token.
00076         ptr<pp_token> peek_back(void);
00077         //! Reads front token, squeezing whitespace.
00078         ptr<pp_token> read_front(void);
00079         //! Reads front token, skipping front whitespace, but not newline.
00080         ptr<pp_token> read_front_skip_ws(void);
00081         //! Reads back token, squeezing whitespace.
00082         ptr<pp_token> read_back(void);
00083         //! Reads back token, skipping back whitespace, but not newline.
00084         ptr<pp_token> read_back_skip_ws(void);
00085         //! skips back whitespace
00086         bool skip_front_ws(void);
00087         //! skips back whitespace
00088         bool skip_back_ws(void);
00089         //! Adds token to back.
00090         void add_back(const ptr<pp_token> &t);
00091         //! Prepends another sequence.
00092         void prepend(const ptr<token_sequence> &ts);
00093         //! Appends another sequence.
00094         void append(const ptr<token_sequence> &inserted);
00095         //! Extends taboo set for tokens in sequence.
00096         void taboo_extend(
00097         const ptr<taboo_macros> &tm, const ptr<macro_storage> &macros);
00098         //! completely expands all macros within sequence
00099         ptr<token_sequence> expand_all(const ptr<macro_storage> &macros);
00100         //! Clones the sequence.
00101         ptr<token_sequence> clone(void) const;
00102         //! clones the sequence with new location.
00103         ptr<token_sequence> clone(const ptr<source_location> &a_location) const;
00104         //! Returns length of the sequence.
00105         size_type length(void) const;
00106         //! Tests equality.
00107         bool equals(const ptr<token_sequence> &other) const;
00108         //! Tests congruence.
00109         bool congruent(const ptr<token_sequence> &other) const;
00110         //! TODO prints debug dump
00111         void debug_print(::std::ostream &o) const;
00112         //! Returns empty sequence.
00113         static ptr<token_sequence> create(void);
00114 protected:   
00115         //! Creates empty sequence.
00116         token_sequence(void);
00117         //! Marks the object.
00118         virtual void gc_mark(void);
00119 private:
00120         //! For direct acces to sequence in prepend().
00121         friend class token_stream;
00122         //! The sequence container.
00123         srp<sequence_type> sequence;
00124 };
00125 
00126 //! prints debug dump of token sequence
00127 ::std::ostream &operator<<(::std::ostream &o, const ptr<token_sequence> &ts);
00128 
00129 end_package(lex);
00130 end_package(cplus);
00131 end_package(lang);
00132 end_package(lestes);
00133 #endif
00134 /* vim: set ft=lestes : */

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