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 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00029 #include <lestes/lang/cplus/syn/parser.hh>
00030 #include <lestes/lang/cplus/syn/token.hh>
00031 #include <lestes/std/list.hh>
00032 #include <lestes/std/pair.hh>
00033 #include <lestes/std/reflect.hh>
00034 
00035 #include <ostream>
00036 
00037 package(lestes);
00038 package(lang);
00039 package(cplus);
00040 package(syn);
00041 
00042 static lstring hint2str( bison_token::hint_type hint )
00043 {
00044         lstring str = "BUG!";
00045         switch (hint) {
00046         case bison_token::HINT_NONE:
00047                 str = "HINT_NONE";
00048                 break;
00049 
00050         case bison_token::HINT_TEMPL_NONTYPE:
00051                 str = "HINT_TEMPL_NONTYPE";
00052                 break;
00053         case bison_token::HINT_TEMPL_TYPE:
00054                 str = "HINT_TEMPL_TYPE";
00055                 break;
00056         case bison_token::HINT_NONTYPE:
00057                 str = "HINT_NONTYPE";
00058                 break;
00059         case bison_token::HINT_CLASS:
00060                 str = "HINT_CLASS";
00061                 break;
00062         case bison_token::HINT_ENUM:
00063                 str = "HINT_ENUM";
00064                 break;
00065         case bison_token::HINT_TYPEDEF:
00066                 str = "HINT_TYPEDEF";
00067                 break;
00068         case bison_token::HINT_NAMESPACE:
00069                 str = "HINT_NAMESPACE";
00070                 break;
00071         case bison_token::HINT_UNKNOWN:
00072                 str = "HINT_UNKNOWN";
00073                 break;
00074 
00075         case bison_token::HINT_CTOR:
00076                 str = "HINT_CTOR";
00077                 break;
00078         case bison_token::HINT_NO_CTOR:
00079                 str = "HINT_NO_CTOR";
00080                 break;
00081 
00082         case bison_token::HINT_BITFIELD:
00083                 str = "HINT_BITFIELD";
00084                 break;
00085         case bison_token::HINT_NO_BITFIELD:
00086                 str = "HINT_NO_BITFIELD";
00087                 break;
00088         }
00089         return str;
00090 }
00091 
00092 static lstring hinted_by2str( bison_id_token::hinted_by_type hb )
00093 {
00094         lstring str = "BUG!";
00095         switch (hb) {
00096         case bison_id_token::BY_HINTER:
00097                 str = "BY_HINTER";
00098                 break;
00099 //      case bison_id_token::BY_BOTH:
00100 //              str = "BY_BOTH";
00101 //              break;
00102         case bison_id_token::BY_USER:
00103                 str = "BY_USER";
00104                 break;
00105         }
00106         return str;
00107 }
00108 
00109 ::std::ostream & operator << ( ::std::ostream & os, const ptr<bison_token> & bt )
00110 {
00111         bt->print( os );
00112         return os;
00113 }
00114 
00115 void bison_token::gc_mark()
00116 {
00117         wrapped_token.gc_mark();
00118         as_base::gc_mark();
00119 }
00120 
00121 ptr< object::reflection_list > bison_token::reflection = reflection;
00122 
00123 ptr< object::reflection_list > bison_token::reflection_get() const
00124 {
00125         if (!reflection) {
00126                 typedef class_reflection::field_metadata md;
00127                 typedef class_reflection::field_metadata_list mdlist;
00128                 ptr<mdlist> mdl = mdlist::create();
00129                 mdl->push_back( md::create( "type", "lstring" ) );
00130                 mdl->push_back( md::create( "wrapped_token", "cpp_token" ) );
00131                 mdl->push_back( md::create( "user_hint", "lstring" ) );
00132                 // append our one to a copy of the base class's list
00133                 reflection = reflection_list::create( as_base::reflection_get() );
00134                 reflection->push_back( class_reflection::create( "bison_token", mdl ) );
00135         }
00136         return reflection;
00137 }
00138 
00139 ptr< object::field_list_list > bison_token::field_values_get() const
00140 {
00141         ptr<field_list_list> result = as_base::field_values_get();
00142         result->push_back( value_list::create() );
00143         result->back()->push_back( objectize<lstring>::create( parser::token_type2name(type) ) );
00144         result->push_back( value_list::create() );
00145         result->back()->push_back( wrapped_token );
00146         result->push_back( value_list::create() );
00147         result->back()->push_back( objectize<lstring>::create( hint2str(user_hint) ) );
00148         return result;
00149 }
00150 
00151 void bison_token::print( ::std::ostream & os ) const
00152 {
00153         os << "bison_token " << parser::token_type2name(type);
00154         if (type == TOK_IDENT || type == TOK_LITERAL)
00155                 os << " (\"" << value_get() << "\")";
00156         if (user_hint != HINT_NONE)
00157                 os << ", user " << hint2str(user_hint);
00158 }
00159 
00160 ptr< object::reflection_list > bison_madeup_token::reflection = reflection;
00161 
00162 ptr< object::reflection_list > bison_madeup_token::reflection_get() const
00163 {
00164         if (!reflection) {
00165                 typedef class_reflection::field_metadata md;
00166                 typedef class_reflection::field_metadata_list mdlist;
00167                 ptr<mdlist> mdl = mdlist::create();
00168                 // append our one to a copy of the base class's list
00169                 reflection = reflection_list::create( bison_token::reflection_get() );
00170                 reflection->push_back( class_reflection::create( "bison_madeup_token", mdl ) );
00171         }
00172         return reflection;
00173 }
00174 
00175 ptr< object::field_list_list > bison_madeup_token::field_values_get() const
00176 {
00177         return bison_token::field_values_get();
00178 }
00179 
00180 void bison_madeup_token::print( ::std::ostream & os ) const
00181 {
00182         os << "bison_madeup_token " << parser::token_type2name(type_get());
00183         lassert2( user_hint_get() == HINT_NONE, "Made up tokens cannot have hints!" );
00184 }
00185 
00186 void bison_id_token::gc_mark()
00187 {
00188         found_decls.gc_mark();
00189         bison_token::gc_mark();
00190 }
00191 
00192 ptr< ::lestes::lang::cplus::sem::declaration_set_type > bison_id_token::found_decls_get() const
00193 {
00194         return found_decls;
00195 }
00196 
00197 ptr< object::reflection_list > bison_id_token::reflection = reflection;
00198 
00199 ptr< object::reflection_list > bison_id_token::reflection_get() const
00200 {
00201         if (!reflection) {
00202                 typedef class_reflection::field_metadata md;
00203                 typedef class_reflection::field_metadata_list mdlist;
00204                 ptr<mdlist> mdl = mdlist::create();
00205                 mdl->push_back( md::create( "hinted_by", "lstring" ) );
00206                 // append our one to a copy of the base class's list
00207                 reflection = reflection_list::create( bison_token::reflection_get() );
00208                 reflection->push_back( class_reflection::create( "bison_id_token", mdl ) );
00209         }
00210         return reflection;
00211 }
00212 
00213 ptr< object::field_list_list > bison_id_token::field_values_get() const
00214 {
00215         ptr<field_list_list> result = bison_token::field_values_get();
00216         result->push_back( value_list::create() );
00217         result->back()->push_back( objectize<lstring>::create( hinted_by2str(hinted_by) ) );
00218         return result;
00219 }
00220 
00221 void bison_id_token::print( ::std::ostream & os ) const
00222 {
00223         os << "bison_id_token " << parser::token_type2name(type_get()) <<
00224                 " (\"" << value_get() << "\"),"
00225                 " hinted " << hinted_by2str(hinted_by);
00226         lassert2( user_hint_get() == HINT_NONE, "Id tokens must not have hints!" );
00227 }
00228 
00229 void bison_pack_token::gc_mark()
00230 {
00231         pack.gc_mark();
00232         end_location.gc_mark();
00233 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00234         errors.gc_mark();
00235 #endif
00236         bison_madeup_token::gc_mark();
00237 }
00238 
00239 ptr< object::reflection_list > bison_pack_token::reflection = reflection;
00240 
00241 ptr< object::reflection_list > bison_pack_token::reflection_get() const
00242 {
00243         if (!reflection) {
00244                 typedef class_reflection::field_metadata md;
00245                 typedef class_reflection::field_metadata_list mdlist;
00246                 ptr<mdlist> mdl = mdlist::create();
00247                 mdl->push_back( md::create( "pack", "list&lt; srp&lt; bison_token &gt; &gt;" ) );
00248                 mdl->push_back( md::create( "end_location", "source_location" ) );
00249 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00250                 mdl->push_back( md::create( "errors", "list&lt; srp&lt; bison_token &gt; &gt;" ) );
00251 #endif
00252                 // append our one to a copy of the base class's list
00253                 reflection = reflection_list::create( bison_madeup_token::reflection_get() );
00254                 reflection->push_back( class_reflection::create( "bison_pack_token", mdl ) );
00255         }
00256         return reflection;
00257 }
00258 
00259 ptr< object::field_list_list > bison_pack_token::field_values_get() const
00260 {
00261         ptr<field_list_list> result = bison_madeup_token::field_values_get();
00262         result->push_back( value_list::create() );
00263         result->back()->push_back( pack );
00264         result->push_back( value_list::create() );
00265         result->back()->push_back( end_location );
00266 #if 0 || BISON_PACK_TOKEN_ERRORS_WANTED
00267         result->push_back( value_list::create() );
00268         result->back()->push_back( errors );
00269 #endif
00270         return result;
00271 }
00272 
00273 void bison_pack_token::print( ::std::ostream & os ) const
00274 {
00275         os << "bison_pack_token " << parser::token_type2name(type_get()) <<
00276                 ", size " << pack->size();
00277         lassert2( user_hint_get() == HINT_NONE, "Pack tokens must not have hints!" );
00278 }
00279 
00280 end_package(syn);
00281 end_package(cplus);
00282 end_package(lang);
00283 end_package(lestes);

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