ucn_token.cc

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 /*! \file
00029   \brief Single character token.
00030 
00031   Declaration of ucn_token class representing single source character token.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/lex/ucn_token.hh>
00036 
00037 package(lestes);
00038 package(lang);
00039 package(cplus);
00040 package(lex);
00041 
00042 /*!
00043   Creates the object, initializes with location, type and value.
00044   \pre a_type != TOK_ERROR
00045   \post a_error == NULL
00046   \param a_location  The initial location of the token.
00047   \param a_type  The initial type of the token.
00048   \param a_value  The initial value of the token.
00049 */
00050 ucn_token::ucn_token(const location_type &a_location, const type_type &a_type,
00051                 const value_type &a_value):
00052         basic_ucn_token(a_location,(lassert(a_type != TOK_ERROR),a_type),a_value),
00053         error()
00054 {
00055 }
00056 
00057 /*!
00058   Creates the object, initializes with location and error message.
00059   \pre a_error != NULL
00060   \param a_location  The location of the token.
00061   \param a_error  The error message.
00062 */
00063 ucn_token::ucn_token(const location_type &a_location, const error_type &a_error):
00064         basic_ucn_token(a_location,TOK_ERROR,0),
00065         error(checked(a_error))
00066 {
00067 }
00068 
00069 /*!
00070   Marks the object
00071 */
00072 void ucn_token::gc_mark(void)
00073 {
00074         error.gc_mark();
00075         basic_ucn_token::gc_mark();
00076 }
00077 
00078 /*!
00079   Returns error for an error token.
00080   \pre type_get() == TOK_ERROR
00081   \return The error assigned to the token.
00082 */
00083 ucn_token::error_type ucn_token::error_get(void) const
00084 {
00085         lassert(type_get() == TOK_ERROR);
00086         lassert(error);
00087         return error;
00088 }
00089 
00090 /* TODO remove !
00091   Sets error for an error token.
00092   \pre type_get() == TOK_ERROR
00093   \pre a_error != NULL
00094   \param a_error  The error to set.
00095 void ucn_token::error_set(const error_type &a_error)
00096 {
00097         lassert(type_get() == TOK_ERROR);
00098         error = a_error;
00099 }
00100 */
00101 
00102 /*!
00103   Returns copy of this token.
00104   \post is_equal(returned,this)
00105   \return  New token which holds the same values.
00106 ptr<ucn_token> ucn_token::clone(void)
00107 {
00108         return new ucn_token(location_get(),type_get(),value_get());
00109 }
00110 */
00111 
00112 /*!
00113   Returns copy of this token with new type.
00114   \pre type_get() != TOK_ERROR
00115   \return  The token with new value.
00116 */
00117 ptr<ucn_token> ucn_token::clone_type(const type_type &a_type) const
00118 {
00119         lassert(type_get() != TOK_ERROR);
00120         return new ucn_token(location_get(),a_type,value_get());
00121 }
00122 
00123 /*!
00124   Returns copy of this token with new value.
00125   \pre type_get() != TOK_ERROR
00126   \return  The token with new value.
00127 */
00128 ptr<ucn_token> ucn_token::clone_value(const value_type &a_value) const
00129 {
00130         lassert(type_get() != TOK_ERROR);
00131         return new ucn_token(location_get(),type_get(),a_value);
00132 }
00133 
00134 /*!
00135   Returns copy of this token with new location.
00136   \return  The token with new value.
00137 */
00138 ptr<ucn_token> ucn_token::clone_location(const location_type &a_location) const
00139 {
00140         if (type_get() == TOK_ERROR)
00141                 return new ucn_token(a_location,error_get());
00142         return new ucn_token(a_location,type_get(),value_get());
00143 }
00144 
00145 /*!
00146   Returns new token, initializes with token type.
00147   \post is_equal(type_get(),a_type)
00148   \param a_type  The initial token type.
00149   \return New token initialized with token type.
00150 */
00151 ptr<ucn_token> ucn_token::create(const type_type &a_type)
00152 {
00153         return new ucn_token(location_type(),a_type,value_type());
00154 }
00155 
00156 /*!
00157   Returns new token, initializes with token type and token value.
00158   \post is_equal(type_get(),a_type)
00159   \post is_equal(value_get(),a_value)
00160   \param a_type  The initial token type.
00161   \param a_value  The initial value.
00162   \return  A new token initialized with token type and value.
00163 */
00164 ptr<ucn_token> ucn_token::create(const type_type &a_type, const value_type &a_value)
00165 {
00166         return new ucn_token(location_type(),a_type,a_value);
00167 }
00168 
00169 /*!
00170   Returns new token, initializes with location, token type and token value.
00171   \post is_equal(type_get(),a_type)
00172   \post is_equal(value_get(),a_value)
00173   \post is_equal(location_get(),a_location)
00174   \param a_type  The initial token type.
00175   \param a_value  The initial token value.
00176   \param a_location  The initial location.
00177   \return  A new token initialized with location, token type and token value.
00178 */
00179 ptr<ucn_token> ucn_token::create(const type_type &a_type, const value_type &a_value,
00180                 const location_type &a_location)
00181 {
00182         return new ucn_token(a_location,a_type,a_value);
00183 }
00184 
00185 /*!
00186   Returns new token, initializes with error and location.
00187   \post is_equal(error_get(),a_error)
00188   \post is_equal(location_get(),a_location)
00189   \param a_error  The error message.
00190   \param a_location  The location.
00191   \return  A new token initialized with location and error message.
00192 */
00193 ptr<ucn_token> ucn_token::create_error(const error_type &a_error, const location_type &a_location)
00194 {
00195         return new ucn_token(a_location,a_error);
00196 }
00197 
00198 /*!
00199   Returns new token, initializes with error.
00200   \post is_equal(error_get(),a_error)
00201   \param a_error  The error message.
00202   \param a_location  The location.
00203   \return  A new token initialized with location and error message.
00204 */
00205 ptr<ucn_token> ucn_token::create_error(const error_type &a_error)
00206 {
00207         return new ucn_token(NULL,a_error);
00208 }
00209 
00210 /*!
00211   Tests equality of the token.
00212   \param rhs  The token to compare with.
00213   \return true  If both tokens are equal.
00214 */
00215 bool ucn_token::equals(const ptr<ucn_token> &rhs) const
00216 {
00217         return basic_ucn_token::equals(rhs.dncast<basic_ucn_token>());
00218 }
00219 
00220 end_package(lex);
00221 end_package(cplus);
00222 end_package(lang);
00223 end_package(lestes);
00224 
00225 /* vim: set ft=lestes : */

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