#include <hinter.hh>
Public Types | |
| enum | mode_type { HINTER_NORMAL, HINTER_CHECK, HINTER_USER, HINTER_OFF } |
Static Public Member Functions | |
| static ptr< bison_token > | hint (const ptr< bison_token > &t, const ptr< bison_token > &lookahead) |
| static void | init (mode_type) |
| Initializes the hinter; manager must be already initialized when calling this function. | |
| static mode_type | mode_get () |
| static void | qual_scope_set (const ptr< ::lestes::lang::cplus::sem::ss_decl_seq > &) |
| static void | elab_spec_set (const ptr< elab_spec_key > &) |
| static void | namespace_mode_set (bool) |
| static void | qual_scope_set_root () |
Static Protected Member Functions | |
| static ptr< ::lestes::lang::cplus::sem::ss_decl_seq > | qual_scope_get () |
| static ptr< elab_spec_key > | elab_spec_get () |
| static bool | namespace_mode_get () |
| static ptr< bison_token > | use_user_hint (const ptr< bison_token > &t) |
| static ptr< bison_token > | compute_hint (const ptr< bison_token > &t, const ptr< bison_token > &lookahead) |
Protected Attributes | |
| static::std::map< bison_token::hint_type, bison_token::yytokentype > | id_hint2tok_type_map |
| maps identifier type hints to token types; note that not all hints are covered! | |
Private Member Functions | |
| hinter () | |
| Do not allow instantiating this class. | |
| hinter (const hinter &) | |
| Hide copy-constructor. | |
Static Private Attributes | |
| static mode_type | mode = HINTER_NORMAL |
Definition at line 47 of file hinter.hh.
Definition at line 50 of file hinter.hh.
00050 { 00051 HINTER_NORMAL, // hinter works full-time, ignores user hints 00052 HINTER_CHECK, // compares its hints with user's ones (if available) 00053 // it is fatal when they don't agree 00054 HINTER_USER, // trusts user hints, only hints itself when no user hint is available 00055 HINTER_OFF // hinter off; every identifier must be user-hinted 00056 };
| lestes::lang::cplus::syn::hinter::hinter | ( | ) | [private] |
Do not allow instantiating this class.
| lestes::lang::cplus::syn::hinter::hinter | ( | const hinter & | ) | [private] |
Hide copy-constructor.
| ptr< bison_token > lestes::lang::cplus::syn::hinter::hint | ( | const ptr< bison_token > & | t, | |
| const ptr< bison_token > & | lookahead | |||
| ) | [static] |
Definition at line 563 of file hinter.cc.
References checked, compute_hint(), lestes::lang::cplus::syn::bison_token::HINT_NONE, HINTER_CHECK, HINTER_NORMAL, HINTER_OFF, HINTER_USER, lassert, lassert2, llog, mode, TOK_IDENT, and use_user_hint().
Referenced by lestes::lang::cplus::syn::one_manager::yylex().
00564 { 00565 lassert( t && lookahead ); 00566 00567 llog(hl) << "hinter::hint( " << t << " ; la: " << lookahead << " ) called\n"; 00568 00569 lassert2( t->type_get() == bison_token::TOK_IDENT, 00570 "Hinter called on non-identifier token." ); 00571 00572 bool is_user_hinted = t->user_hint_get() != bison_token::HINT_NONE; 00573 00574 ptr<bison_token> result; 00575 00576 switch (mode) { 00577 case HINTER_OFF: 00578 lassert2( is_user_hinted, "Got unhinted identifier." ); 00579 result = use_user_hint(t); 00580 break; 00581 case HINTER_USER: 00582 if (is_user_hinted) 00583 result = use_user_hint(t); 00584 else 00585 result = compute_hint( t, lookahead ); 00586 break; 00587 case HINTER_CHECK: 00588 result = compute_hint( t, lookahead ); 00589 if (is_user_hinted) { 00590 ptr<bison_token> by_user = use_user_hint(t); 00591 lassert2( by_user->type_get() == result->type_get(), 00592 "User and computed hint do not agree." ); 00593 } 00594 break; 00595 case HINTER_NORMAL: 00596 result = compute_hint( t, lookahead ); 00597 break; 00598 } 00599 00600 return checked(result); 00601 }
| void lestes::lang::cplus::syn::hinter::init | ( | mode_type | a_mode | ) | [static] |
Initializes the hinter; manager must be already initialized when calling this function.
Definition at line 253 of file hinter.cc.
References _CLASS_NAME_ID, _ENUM_NAME_ID, _NMSPC_NAME, _NONTYPE, _TEMPL_NONTYPE, _TEMPL_TYPE, _TYPEDEF_NAME_ID, _UNKNOWN_ID, lestes::lang::cplus::syn::manager::close_event, lestes::lang::cplus::syn::manager::commit_event, lestes::lang::cplus::syn::one_hinter::create(), lestes::lang::cplus::syn::bison_token::HINT_CLASS, lestes::lang::cplus::syn::bison_token::HINT_ENUM, lestes::lang::cplus::syn::bison_token::HINT_NAMESPACE, lestes::lang::cplus::syn::bison_token::HINT_NONTYPE, lestes::lang::cplus::syn::bison_token::HINT_TEMPL_NONTYPE, lestes::lang::cplus::syn::bison_token::HINT_TEMPL_TYPE, lestes::lang::cplus::syn::bison_token::HINT_TYPEDEF, lestes::lang::cplus::syn::bison_token::HINT_UNKNOWN, lestes::lang::cplus::syn::hinter_stack, id_hint2tok_type_map, lestes::lang::cplus::syn::pop_state_action::instance(), lestes::lang::cplus::syn::push_state_action::instance(), lestes::lang::cplus::syn::close_hinter_action::instance(), lestes::lang::cplus::syn::spawn_hinter_action::instance(), lassert2, mode, lestes::lang::cplus::syn::manager::rollback_event, lestes::lang::cplus::syn::manager::spawn_event, and lestes::lang::cplus::syn::manager::start_event.
00254 { 00255 lassert2( id_hint2tok_type_map.empty(), 00256 "Trying to initialize hinter for the second time." ); 00257 00258 mode = a_mode; 00259 00260 hinter_stack = hinter_stack_type::create(); 00261 hinter_stack->push_back( one_hinter::create() ); 00262 00263 id_hint2tok_type_map[ bison_token::HINT_TEMPL_NONTYPE ] 00264 = bison_token::_TEMPL_NONTYPE; 00265 id_hint2tok_type_map[ bison_token::HINT_TEMPL_TYPE ] 00266 = bison_token::_TEMPL_TYPE; 00267 id_hint2tok_type_map[ bison_token::HINT_NONTYPE ] 00268 = bison_token::_NONTYPE; 00269 id_hint2tok_type_map[ bison_token::HINT_CLASS ] 00270 = bison_token::_CLASS_NAME_ID; 00271 id_hint2tok_type_map[ bison_token::HINT_ENUM ] 00272 = bison_token::_ENUM_NAME_ID; 00273 id_hint2tok_type_map[ bison_token::HINT_TYPEDEF ] 00274 = bison_token::_TYPEDEF_NAME_ID; 00275 id_hint2tok_type_map[ bison_token::HINT_NAMESPACE ] 00276 = bison_token::_NMSPC_NAME; 00277 id_hint2tok_type_map[ bison_token::HINT_UNKNOWN ] 00278 = bison_token::_UNKNOWN_ID; 00279 00280 manager::spawn_event->attach( spawn_hinter_action::instance() ); 00281 manager::close_event->attach( close_hinter_action::instance() ); 00282 00283 manager::start_event->attach( push_state_action::instance() ); 00284 manager::commit_event->attach( pop_state_action::instance() ); 00285 manager::rollback_event->attach( pop_state_action::instance() ); 00286 }
| hinter::mode_type lestes::lang::cplus::syn::hinter::mode_get | ( | ) | [static] |
| static void lestes::lang::cplus::syn::hinter::qual_scope_set | ( | const ptr< ::lestes::lang::cplus::sem::ss_decl_seq > & | ) | [static] |
Referenced by compute_hint(), and qual_scope_set_root().
| void lestes::lang::cplus::syn::hinter::elab_spec_set | ( | const ptr< elab_spec_key > & | ) | [static] |
Definition at line 639 of file hinter.cc.
References lestes::lang::cplus::syn::hinter_stack, and lassert.
Referenced by compute_hint().
00640 { 00641 lassert( !hinter_stack->empty() ); 00642 hinter_stack->back()->elab_spec_set(es); 00643 }
| void lestes::lang::cplus::syn::hinter::namespace_mode_set | ( | bool | ) | [static] |
Definition at line 645 of file hinter.cc.
References lestes::lang::cplus::syn::hinter_stack, and lassert.
Referenced by compute_hint().
00646 { 00647 lassert( !hinter_stack->empty() ); 00648 hinter_stack->back()->namespace_mode_set( b ); 00649 }
| void lestes::lang::cplus::syn::hinter::qual_scope_set_root | ( | ) | [static] |
Definition at line 651 of file hinter.cc.
References qual_scope_set().
00652 { 00653 qual_scope_set( ss_decl_seq::root_instance() ); 00654 }
| ptr< ss_decl_seq > lestes::lang::cplus::syn::hinter::qual_scope_get | ( | ) | [static, protected] |
Definition at line 609 of file hinter.cc.
References lestes::lang::cplus::syn::hinter_stack, and lassert.
Referenced by compute_hint().
00610 { 00611 lassert( !hinter_stack->empty() ); 00612 return hinter_stack->back()->qual_scope_get(); 00613 }
| ptr< elab_spec_key > lestes::lang::cplus::syn::hinter::elab_spec_get | ( | ) | [static, protected] |
Definition at line 615 of file hinter.cc.
References lestes::lang::cplus::syn::hinter_stack, and lassert.
Referenced by compute_hint().
00616 { 00617 lassert( !hinter_stack->empty() ); 00618 return hinter_stack->back()->elab_spec_get(); 00619 }
| bool lestes::lang::cplus::syn::hinter::namespace_mode_get | ( | ) | [static, protected] |
Definition at line 621 of file hinter.cc.
References lestes::lang::cplus::syn::hinter_stack, and lassert.
Referenced by compute_hint().
00622 { 00623 lassert( !hinter_stack->empty() ); 00624 return hinter_stack->back()->namespace_mode_get(); 00625 }
| ptr< bison_token > lestes::lang::cplus::syn::hinter::use_user_hint | ( | const ptr< bison_token > & | t | ) | [static, protected] |
Definition at line 293 of file hinter.cc.
References lestes::lang::cplus::syn::bison_id_token::BY_USER, lestes::intercode::intercode::create(), lestes::lang::cplus::syn::bison_token::HINT_NONE, id_hint2tok_type_map, lassert, and lassert2.
Referenced by hint().
00294 { 00295 lassert( t->user_hint_get() != bison_token::HINT_NONE ); 00296 int result_type = id_hint2tok_type_map[ t->user_hint_get() ]; 00297 lassert2( result_type != 0, 00298 "Either got invalid hint, or the map is corrupted." ); 00299 00300 return bison_id_token::create( result_type, t->wrapped_token_get(), 00301 bison_id_token::BY_USER, 00302 declaration_set_type::create() ); 00303 }
| ptr< bison_token > lestes::lang::cplus::syn::hinter::compute_hint | ( | const ptr< bison_token > & | t, | |
| const ptr< bison_token > & | lookahead | |||
| ) | [static, protected] |
Definition at line 479 of file hinter.cc.
References _CLASS_NAME_ID, _NMSPC_NAME, _TYPEDEF_NAME_ID, _UNKNOWN_ID, lestes::lang::cplus::syn::bison_id_token::BY_HINTER, lestes::intercode::intercode::create(), elab_spec_get(), elab_spec_set(), lestes::lang::cplus::syn::typedef_class_resolver::instance(), lestes::lang::cplus::syn::hint_from_declaration_set::instance(), lassert, lassert2, llog, lestes::lang::cplus::syn::look_first(), lestes::lang::cplus::syn::look_last(), lestes::lang::cplus::syn::look_last_elab(), lestes::lang::cplus::syn::middle(), namespace_mode_get(), namespace_mode_set(), lestes::lang::cplus::syn::nmspace(), qual_scope_get(), qual_scope_set(), lestes::report, TOK_COLON_COLON, lestes::lang::cplus::syn::unknown_before_coloncolon, lestes::lang::cplus::syn::unqualified(), lestes::lang::cplus::syn::unqualified_elab(), and lestes::lang::cplus::syn::wrong_before_coloncolon.
Referenced by hint().
00481 { 00482 lassert( t && lookahead ); 00483 00484 ptr<ss_decl_seq> qual_scope = qual_scope_get(); 00485 ptr<elab_spec_key> elab_spec = elab_spec_get(); 00486 00487 bool first = !qual_scope; // first -- there was no qualification 00488 bool last = lookahead->type_get() != bison_token::TOK_COLON_COLON; 00489 bool ns_mode = namespace_mode_get(); 00490 00491 ptr<ss_ordinary_name> name = ss_ordinary_name::create( t->location_get(), t->value_get() ); 00492 00493 ptr<ss_decl_seq> seq; 00494 if (qual_scope) 00495 seq = qual_scope; 00496 else 00497 seq = sa_context_manager::instance()->current()->ss_get()->scope_get(); 00498 // was: 00499 //seq = forced_scope_get(); 00500 00501 // first && last -> unqualified identifier 00502 // first && !last -> first part of qualification 00503 // !first && last -> last part in qualified name 00504 // !first && !last -> middle part in qualification 00505 00506 // elab_spec is considered only when last == true 00507 00508 llog(hl) << "first: " << first << " last: " << last << " elab_spec: " << bool(elab_spec) << "\n"; 00509 00510 ptr<declaration_set_type> lookup_result; 00511 00512 if (ns_mode && !qual_scope) 00513 lookup_result = nmspace( name, seq ); 00514 else if (ns_mode && qual_scope) 00515 lassert2( false, "Not implemented yet." ); 00516 else if (first && last && !elab_spec) 00517 lookup_result = unqualified( name, seq ); 00518 else if (first && last && elab_spec) 00519 lookup_result = unqualified_elab( name, seq ); 00520 else if (first && !last) 00521 lookup_result = look_first( name, seq ); 00522 else if (!first && last && !elab_spec) 00523 lookup_result = look_last( name, seq ); 00524 else if (!first && last && elab_spec) 00525 lookup_result = look_last_elab( name, seq ); 00526 else if (!first && !last) 00527 lookup_result = middle( name, seq ); 00528 lassert(lookup_result); 00529 00530 llog(hl) << "lookup_result->size(): " << lookup_result->size() << "\n"; 00531 00532 int result_token_type = hint_from_declaration_set::instance()->process( lookup_result ); 00533 00534 // [3.4.3/1] class or namespacename must be found before "non-global" :: operator 00535 if (!last && result_token_type != bison_token::_CLASS_NAME_ID 00536 && result_token_type != bison_token::_NMSPC_NAME) { 00537 if (result_token_type == bison_token::_UNKNOWN_ID) 00538 report << unknown_before_coloncolon << t->location_get(); 00539 else 00540 report << wrong_before_coloncolon << t->location_get(); 00541 } 00542 00543 /* when we got typedef name *not* prefixed by class-key/enum, see if it is a class name */ 00544 if (result_token_type == bison_token::_TYPEDEF_NAME_ID && !elab_spec) { 00545 lookup_result = typedef_class_resolver::instance()->process( lookup_result ); 00546 result_token_type = 00547 hint_from_declaration_set::instance()->process( lookup_result ); 00548 } 00549 00550 namespace_mode_set(false); 00551 qual_scope_set(NULL); 00552 if (last) 00553 elab_spec_set(NULL); 00554 00555 ptr<bison_token> result = bison_id_token::create( result_token_type, 00556 t->wrapped_token_get(), bison_id_token::BY_HINTER, lookup_result ); 00557 00558 llog(hl) << "computed " << result << "\n"; 00559 00560 return result; 00561 }
std::map< bison_token::hint_type, bison_token::yytokentype > lestes::lang::cplus::syn::hinter::id_hint2tok_type_map [protected] |
maps identifier type hints to token types; note that not all hints are covered!
Definition at line 76 of file hinter.hh.
Referenced by init(), and use_user_hint().
hinter::mode_type lestes::lang::cplus::syn::hinter::mode = HINTER_NORMAL [static, private] |
1.5.1-20070107