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__syn__token_hh__included
00029 #define lestes__lang__cplus__syn__token_hh__included
00030 
00031 #include <lestes/common.hh>
00032 #include <lestes/intercode/intercode.g.hh>
00033 #include <lestes/lang/cplus/lex/cpp_token.hh>
00034 #include <lestes/lang/cplus/lex/token_value.hh>
00035 #include <lestes/lang/cplus/sem/lu_typedef.hh>
00036 #include <lestes/std/list.hh>
00037 #include <lestes/std/set.hh>
00038 #include <lestes/std/source_location.hh>
00039 
00040 #include <iosfwd>
00041 
00042 package(lestes);
00043 package(lang);
00044 package(cplus);
00045 package(syn);
00046 
00047 class bison_token : public ::lestes::intercode::as_base {
00048 public:
00049         // enum yytokentype:
00050 #include <lestes/lang/cplus/syn/cpp_token_type_enum.s.hh> 
00051         typedef ::lestes::lang::cplus::lex::cpp_token wrapped_token_type;
00052         enum hint_type {
00053                 HINT_NONE,
00054 
00055                 HINT_TEMPL_NONTYPE,
00056                 HINT_TEMPL_TYPE,
00057                 HINT_NONTYPE,
00058                 HINT_CLASS,
00059                 HINT_ENUM,
00060                 HINT_TYPEDEF,
00061                 HINT_NAMESPACE,
00062                 HINT_UNKNOWN,
00063                 
00064                 HINT_CTOR,
00065                 HINT_NO_CTOR,
00066 
00067                 HINT_BITFIELD,
00068                 HINT_NO_BITFIELD,
00069         };
00070 private:
00071         //! type of the token; this is what bison cares about
00072         const int type;
00073 protected:
00074         //! pointer to token read from lex
00075         /*!
00076          * Must not be NULL when the real type is bison_token.
00077          * In other words, derived classes are allowed to set it to NULL.
00078          * All the methods that use the value are virtual and the implementations in
00079          * this class (bison_token, that is) always check the value.
00080          */
00081         const srp<wrapped_token_type> wrapped_token;
00082 private:
00083         hint_type user_hint;
00084 protected:
00085         bison_token( const ptr<source_location> & a_location, int a_type,
00086                         const ptr<wrapped_token_type> & a_token_to_wrap ) :
00087                 as_base(a_location), type(a_type),
00088                 wrapped_token(a_token_to_wrap), user_hint(HINT_NONE)
00089         {}
00090         void gc_mark();
00091 public:
00092         static ptr<bison_token> create( ptr<wrapped_token_type> a_token_to_wrap )
00093         {
00094                 // we check the value here, not in the constructor
00095                 // this allows derived classes to set wrapped_token to NULL
00096                 return new bison_token( a_token_to_wrap->location_get(),
00097                                 a_token_to_wrap->type_get(),
00098                                 checked(a_token_to_wrap) );
00099         }
00100         int type_get() const
00101         {
00102                 return type;
00103         }
00104         virtual ucn_string value_get() const
00105         {
00106                 return checked(wrapped_token)->value_get()->content_get();
00107         }
00108         virtual ptr<wrapped_token_type> wrapped_token_get() const
00109         {
00110                 return checked(wrapped_token);
00111         }
00112         void user_hint_set( hint_type hint )
00113         {
00114                 lassert2( hint != HINT_NONE, "Trying to set user hint to NONE." );
00115                 lassert2( user_hint == HINT_NONE, "User hint already set." );
00116                 user_hint = hint;
00117         }
00118         hint_type user_hint_get() const
00119         {
00120                 return user_hint;
00121         }
00122         virtual void print( ::std::ostream & ) const;
00123 /* the dump part: */
00124 private:
00125         static ptr<reflection_list> reflection;
00126 public:
00127         virtual ptr<reflection_list> reflection_get() const;
00128         virtual ptr<field_list_list> field_values_get() const;
00129 };
00130 
00131 class bison_madeup_token : public bison_token {
00132 protected:
00133         bison_madeup_token( const ptr<source_location> & a_location, int a_type ) :
00134                 bison_token( a_location, a_type, NULL )
00135         {}
00136 public:
00137         static ptr<bison_madeup_token> create( const ptr<source_location> & a_location, int a_type )
00138         {
00139                 return new bison_madeup_token( a_location, a_type );
00140         }
00141         virtual ucn_string value_get() const
00142         {
00143                 lassert2( false, "value_get() called on a made up token." );
00144         }
00145         virtual ptr<wrapped_token_type> wrapped_token_get() const
00146         {
00147                 lassert2( false, "wrapped_token_get() called on a made up token." );
00148         }
00149         virtual void print( ::std::ostream & ) const;
00150 /* the dump part: */
00151 private:
00152         static ptr<reflection_list> reflection;
00153 public:
00154         virtual ptr<reflection_list> reflection_get() const;
00155         virtual ptr<field_list_list> field_values_get() const;
00156 };
00157 
00158 class bison_id_token : public bison_token {
00159 public:
00160         enum hinted_by_type {
00161                 BY_HINTER,
00162 //              BY_BOTH,
00163                 BY_USER,
00164         };
00165         ptr< ::lestes::lang::cplus::sem::declaration_set_type > found_decls_get() const;
00166 private:
00167         const hinted_by_type hinted_by;
00168         srp< ::lestes::lang::cplus::sem::declaration_set_type > found_decls;
00169 protected:
00170         bison_id_token( const ptr<source_location> & a_location, int a_value,
00171                         const ptr<wrapped_token_type> & a_token_to_wrap,
00172                         hinted_by_type a_hinted_by,
00173                         const ptr< ::lestes::lang::cplus::sem::declaration_set_type > & a_found_decls )
00174                 : bison_token( a_location, a_value, a_token_to_wrap ),
00175                 hinted_by(a_hinted_by), found_decls(a_found_decls)
00176         {}
00177         void gc_mark();
00178 public:
00179         static ptr<bison_id_token> create( int a_type,
00180                         const ptr<wrapped_token_type> & a_token_to_wrap,
00181                         hinted_by_type a_hinted_by,
00182                         const ptr< ::lestes::lang::cplus::sem::declaration_set_type > & a_found_decls )
00183         {
00184                 return new bison_id_token( a_token_to_wrap->location_get(),
00185                                 a_type, a_token_to_wrap, a_hinted_by,
00186                                 a_found_decls );
00187         }
00188         virtual void print( ::std::ostream & ) const;
00189 /* the dump part: */
00190 private:
00191         static ptr<reflection_list> reflection;
00192 public:
00193         virtual ptr<reflection_list> reflection_get() const;
00194         virtual ptr<field_list_list> field_values_get() const;
00195 };
00196 
00197 class bison_pack_token : public bison_madeup_token {
00198 private:
00199         typedef list< srp<bison_token> > token_list_type;
00200         const srp<token_list_type> pack;
00201         const srp<source_location> end_location;
00202 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00203         //! when this pack_token is used in error recovery, errors contains tokens at which sytax error(s) occured
00204         const srp<token_list_type> errors;
00205 #endif
00206 protected:
00207         bison_pack_token( const ptr<source_location> & a_location, int a_type,
00208                         ptr<token_list_type> a_pack,
00209                         const ptr<source_location> & a_end_location
00210 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00211                         ,ptr<token_list_type> a_errors
00212 #endif
00213                         ) :
00214                 bison_madeup_token( a_location, a_type ),
00215                 pack(a_pack), end_location(a_end_location)
00216 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00217                 ,errors(a_errors)
00218 #endif
00219         {}
00220         void gc_mark();
00221 public:
00222         static ptr<bison_pack_token> create( const ptr<source_location> & a_location,
00223                         int a_type, const ptr<source_location> a_end_location )
00224         {
00225                 lassert( a_type > bison_token::_PACK_FIRST && a_type < bison_token::_PACK_LAST );
00226                 return new bison_pack_token( a_location, a_type,
00227                                 token_list_type::create(), a_end_location
00228 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00229                                 ,token_list_type::create()
00230 #endif
00231                                 );
00232         }
00233         ptr<token_list_type> pack_get() const
00234         {
00235                 return pack;
00236         }
00237         ptr<source_location> end_location_get() const
00238         {
00239                 return end_location;
00240         }
00241 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00242         ptr<token_list_type> errors_get() const
00243         {
00244                 return errors;
00245         }
00246 #endif
00247         virtual void print( ::std::ostream & ) const;
00248 /* the dump part: */
00249 private:
00250         static ptr<reflection_list> reflection;
00251 public:
00252         virtual ptr<reflection_list> reflection_get() const;
00253         virtual ptr<field_list_list> field_values_get() const;
00254 };
00255 
00256 ::std::ostream & operator << ( ::std::ostream &, const ptr<bison_token> & );
00257 
00258 end_package(syn);
00259 end_package(cplus);
00260 end_package(lang);
00261 end_package(lestes);
00262 
00263 #endif  // lestes__lang__cplus__syn__token_hh__included

Generated on Mon Feb 12 18:27:09 2007 for lestes by doxygen 1.5.1-20070107