Ignore:
Timestamp:
Jun 8, 2023, 3:19:43 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT
Parents:
044ae62
Message:

Finish Adt POC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/SymbolTable.cpp

    r044ae62 rfa2c005  
    218218}
    219219
     220const AdtDecl * SymbolTable::lookupAdt( const std::string &id ) const {
     221        ++*stats().lookup_calls;
     222        if ( ! adtTable ) return nullptr;
     223        auto it = adtTable->find( id );
     224        return it == adtTable->end() ? nullptr : it->second.decl;
     225}
     226
    220227const EnumDecl * SymbolTable::lookupEnum( const std::string &id ) const {
    221228        ++*stats().lookup_calls;
     
    339346}
    340347
    341 void SymbolTable::addEnum( const EnumDecl *decl ) {
    342         ++*stats().add_calls;
    343         const std::string &id = decl->name;
    344 
    345         if ( ! enumTable ) {
    346                 enumTable = EnumTable::new_ptr();
    347         } else {
    348                 ++*stats().map_lookups;
    349                 auto existing = enumTable->find( id );
    350                 if ( existing != enumTable->end()
    351                         && existing->second.scope == scope
    352                         && addedDeclConflicts( existing->second.decl, decl ) ) return;
    353         }
    354 
    355         lazyInitScope();
    356         ++*stats().map_mutations;
    357         enumTable = enumTable->set( id, scoped<EnumDecl>{ decl, scope } );
     348void SymbolTable::addAdt( const std::string &id ) {
     349        addAdt( new AdtDecl( CodeLocation(), id ) );
    358350}
    359351
     
    377369        adtTable = adtTable->set( id, scoped<AdtDecl>{ decl, scope });
    378370}
     371
     372void SymbolTable::addEnum( const EnumDecl *decl ) {
     373        ++*stats().add_calls;
     374        const std::string &id = decl->name;
     375
     376        if ( ! enumTable ) {
     377                enumTable = EnumTable::new_ptr();
     378        } else {
     379                ++*stats().map_lookups;
     380                auto existing = enumTable->find( id );
     381                if ( existing != enumTable->end()
     382                        && existing->second.scope == scope
     383                        && addedDeclConflicts( existing->second.decl, decl ) ) return;
     384        }
     385
     386        lazyInitScope();
     387        ++*stats().map_mutations;
     388        enumTable = enumTable->set( id, scoped<EnumDecl>{ decl, scope } );
     389}
     390
    379391
    380392void SymbolTable::addUnion( const std::string &id ) {
Note: See TracChangeset for help on using the changeset viewer.