basic_token.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___basic_token_hh___included
00029 #define lestes__lang__cplus__lex___basic_token_hh___included
00030 
00031 /*! \file
00032   \brief Token template.
00033 
00034   Definition of basic_token class template.
00035   \author pt
00036 */
00037 #include <lestes/common.hh>
00038 #include <lestes/equality.hh>
00039 #include <lestes/pointer_helpers.hh>
00040 
00041 package(lestes);
00042 package(lang);
00043 package(cplus);
00044 package(lex);
00045 
00046 /*!
00047   \brief Token template.
00048 
00049   General token template representing an entity with specific occurence within file.
00050   \param Type  Type of the kind of the token.
00051   \param Location  Type of the location of the token.
00052   \param Value Type of the value of the token.
00053 */
00054 template <typename Type, typename Location, typename Value>
00055 class basic_token: public ::lestes::std::object {
00056 public:
00057         //! Type of token type.
00058         typedef typename convert<Type>::to_ptr type_type;
00059         //! Type of token value.
00060         typedef typename convert<Value>::to_ptr value_type;
00061         //! Type of token location.
00062         typedef typename convert<Location>::to_ptr location_type;
00063         //! Returns type of token.
00064         Type type_get(void) const;
00065         //! Returns value of token.
00066         Value value_get(void) const;
00067         //! Returns location of token.
00068         Location location_get(void) const;
00069         //! Tests equality.
00070         bool equals(const ptr< basic_token<Type,Location,Value> > &rhs) const;
00071 protected:
00072         //! Initializes with location, token type and value.
00073         basic_token(const Location &a_location, const Type &a_type, const Value &a_value);
00074         //! Marks the object.
00075         virtual void gc_mark(void);
00076 private:
00077         //! Type of token.
00078         typename convert<Type>::to_srp type;
00079         //! Token value itself.
00080         typename convert<Value>::to_srp value;
00081         //! Where the token is located.
00082         typename convert<Location>::to_srp location;
00083         //! Hides copy constructor.
00084         basic_token(const basic_token<Type,Location,Value> &copy);
00085         //! Hides assignment operator.
00086         basic_token<Type,Location,Value> &operator=
00087                 (const basic_token<Type,Location,Value> &rhs);
00088 };
00089 
00090 /*!
00091   Creates initialized object.
00092   \param a_location  The location of the token.
00093   \param a_type  The type of the token.
00094   \param a_value  The value of the token.
00095 */
00096 template <typename Type, typename Location, typename Value>
00097 basic_token<Type,Location,Value>::basic_token(const Location &a_location,
00098                 const Type &a_type, const Value &a_value):
00099         type(a_type),
00100         value(a_value),
00101         location(a_location)
00102 {
00103 }
00104 
00105 /*!
00106   Returns token type.
00107   \return  The token type.
00108 */
00109 template <typename Type, typename Location, typename Value>
00110 inline Type basic_token<Type,Location,Value>::type_get(void) const
00111 {
00112         return type;
00113 }
00114 
00115 /*!
00116   Returns token value.
00117   \return  The token value.
00118 */
00119 template <typename Type, typename Location, typename Value>
00120 inline Value basic_token<Type,Location,Value>::value_get(void) const
00121 {
00122         return value;
00123 }
00124 
00125 /*!
00126   Returns token location.
00127   \return  The token location.
00128 */
00129 template <typename Type, typename Location, typename Value>
00130 inline Location basic_token<Type,Location,Value>::location_get(void) const
00131 {
00132         return location;
00133 }
00134 
00135 /*!
00136   Marks the object.
00137 */
00138 template <typename Type, typename Location, typename Value>
00139 inline void basic_token<Type,Location,Value>::gc_mark(void)
00140 {
00141         gc_mark_srp(type);
00142         gc_mark_srp(location);
00143         gc_mark_srp(value);
00144 	
00145 	::lestes::std::object::gc_mark();
00146 }
00147 
00148 /*!
00149   Tests equality of tokens. Checks equality of type, value and location.
00150   \param rhs  The token to compare with.
00151   \return true  If both tokens are is_equal.
00152 */
00153 template <typename Type, typename Location, typename Value>
00154 bool basic_token<Type,Location,Value>::equals(
00155                 const ptr< basic_token<Type,Location,Value> > &rhs) const
00156 {
00157         return
00158                 is_equal(type,rhs->type_get()) &&
00159                 is_equal(value,rhs->value_get()) &&
00160                 is_equal(location,rhs->location_get());
00161 }
00162 
00163 end_package(lex);
00164 end_package(cplus);
00165 end_package(lang);
00166 end_package(lestes);
00167 #endif
00168 /* vim: set ft=lestes : */

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