evaluator.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___evaluator_hh___included
00029 #define lestes__lang__cplus__lex___evaluator_hh___included
00030 
00031 /*! \file
00032   \brief Directives evaluator.
00033 
00034   Declaration of evaluator class representing evaluator of preprocessing directives.
00035   \author pt
00036 */
00037 #include <lestes/common.hh>
00038 #include <lestes/std/vector.hh>
00039 #include <lestes/lang/cplus/lex/pp_filter.hh>
00040 package(lestes);
00041 package(lang);
00042 package(cplus);
00043 package(lex);
00044 
00045 // forward declaration to break cycle
00046 class expander;
00047 class unit_part;
00048 class pp_token;
00049 class token_sequence;
00050 class macro_storage;
00051 class named_istream;
00052 class file_system;
00053 
00054 /*!
00055   \brief Directives evaluator.
00056 
00057   Represents evaluator of preprocessing directives.
00058   Manages include stack.
00059 */
00060 class evaluator: public pp_filter {
00061 public:
00062         //! Returns pragma flag.
00063         bool pragma_flag_get(void) const;
00064         //! Reads single token.
00065         ptr<pp_token> read(void);
00066         //! Returns new instance.
00067         static ptr<evaluator> create(const ptr<file_system> &a_fs, const lstring &file_name);
00068 protected:
00069         //! Creates new object.
00070         evaluator(const ptr<file_system> &a_fs, const lstring &file_name);
00071         //! Marks the object.
00072         virtual void gc_mark(void);
00073 private:
00074         //! States of the evaluator.
00075         typedef enum {
00076                 EMPTY,
00077                 START,
00078                 BUFFER,
00079                 END,
00080         } state_type;
00081         enum {
00082                 //! Nesting limit of include files.
00083                 NESTING_LIMIT = 16
00084         };
00085         //! Type of include stack.
00086         typedef ::lestes::std::vector< srp<unit_part> > includes_type;
00087         //! Processes directive in buffer.
00088         ptr<pp_token> process_directive(void);
00089         //! Parses include directive in buffer.
00090         ptr<pp_token> parse_include(void);
00091         //! Checks extra tokens in directive.
00092         void check_extra_tokens(const lstring &name);
00093         //! Pushes stream to process.
00094         void push_stream(const ptr<named_istream> &ns, const ptr<source_location> &loc);
00095         //! Pops the processed stream.
00096         void pop_stream(void);
00097         //! File system binding.
00098         srp<file_system> fs;
00099         //! State of the evaluator.
00100         state_type state;
00101         //! Output active flag.
00102         bool active;
00103         //! Storage of defined macros.
00104         srp<macro_storage> macros;
00105         //! Include stack.
00106         srp<includes_type> includes;
00107         //! Input into evaluator.
00108         srp<expander> input;
00109         //! Current unit part.
00110         srp<unit_part> part;
00111         //! Buffer with pending tokens.
00112         srp<token_sequence> buffer;
00113         //! Flag of encountered pragma.
00114         bool pragma_flag;
00115         //! Nesting depth of includes.
00116         ulint nesting;
00117         //! Hides copy constructor.
00118         evaluator(const evaluator &copy);
00119         //! Hides assignment operator.
00120         evaluator &operator=(const evaluator &rhs);
00121 };
00122 
00123 end_package(lex);
00124 end_package(cplus);
00125 end_package(lang);
00126 end_package(lestes);
00127 
00128 #endif
00129 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:33 2007 for lestes by doxygen 1.5.1-20070107