00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
00072 const int type;
00073 protected:
00074
00075
00076
00077
00078
00079
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
00095
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
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
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
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
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
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
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