macro.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___macro_hh___included
00029 #define lestes__lang__cplus__lex___macro_hh___included
00030 
00031 /*! \file
00032   \brief Preprocessor macro.
00033 
00034         Declaration of macro class representing preprocessor macro.
00035         \author pt
00036 */
00037 
00038 #include <lestes/common.hh>
00039 
00040 package(lestes);
00041 
00042 package(std);
00043 // forward declarations to avoid cycle
00044 class source_location;
00045 end_package(std);
00046 
00047 package(lang);
00048 package(cplus);
00049 package(lex);
00050 
00051 // forward declaration to avoid cycle
00052 class pp_token;
00053 class token_value;
00054 class token_input;
00055 class token_sequence;
00056 class macro_item;
00057 class macro_head;
00058 class macro_storage;
00059 class macro_body;
00060 
00061 /*!
00062   \brief Preprocessor macro.
00063 
00064   Represents stored preprocessor macro.
00065 */
00066 class macro: public ::lestes::std::object {
00067 public:
00068         //! Returns definition location.
00069         ptr<source_location> location_get(void) const;
00070         //! Returns macro name.
00071         ptr<token_value> name_get(void) const;
00072         //! Returns function-like flag.
00073         bool funlike_get(void) const;
00074         //! Returns predefined flag.
00075         bool predefined_get(void) const;
00076         //! Expands macro.
00077         ptr<token_sequence> expand(
00078                         // TODO pt rename
00079                         const ptr<pp_token> &name, 
00080                         const ptr<token_input> &input,
00081                 const ptr<macro_storage> &macros);
00082         //! Parses the macro definition.
00083         bool parse(const ptr<token_input> &ts);
00084         //! Tests equality.
00085         bool equals(const ptr<macro> &other) const;
00086         //! Creates empty object.
00087         static ptr<macro> create(void);
00088         //! Creates predefined macro.
00089         static ptr<macro> create_predefined(void);
00090 protected:
00091         //! Constructs empty object.
00092         macro(void);
00093         //! Marks the object.
00094         virtual void gc_mark(void);
00095 private:
00096         //! Type of internal state.
00097         typedef enum { BEGIN, PARSED, DEAD } state_type;
00098         //! Parses name.
00099         bool parse_name(const ptr<token_input> &input);
00100         //! Parses parameter list.
00101         bool parse_head(const ptr<token_input> &input);
00102         //! Parses expansion list.
00103         bool parse_body(const ptr<token_input> &input);
00104         //! Internal state of the object.
00105         state_type state;
00106         //! Location of definition.
00107         srp<source_location> location;
00108         //! Name of the macro.
00109         srp<token_value> name;
00110         //! Flag designating function-like macro.
00111         bool funlike;
00112         //! Flag designating predefined macro.
00113         bool predefined;
00114         //! Parameter list of the macro.
00115         srp<macro_head> head;
00116         //! Expansion list of the macro.
00117         srp<macro_body> body;
00118 };
00119 
00120 end_package(lex);
00121 end_package(cplus);
00122 end_package(lang);
00123 end_package(lestes);
00124 #endif
00125 /* vim: set ft=lestes : */

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