Changeset 3943 in CLRX


Ignore:
Timestamp:
Mar 27, 2018, 6:10:30 PM (6 months ago)
Author:
matszpk
Message:

CLRadeonExtender: Asm: Use STL stack to delete recursively the symbols from the scope and to delete same scopes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/amdasm/Assembler.cpp

    r3823 r3943  
    638638}
    639639
     640struct CLRX_INTERNAL ScopeStackElem0
     641{
     642    AsmScope* scope;
     643    AsmScopeMap::iterator it;
     644};
     645
     646
    640647AsmScope::~AsmScope()
    641648{
    642     for (const auto& entry: scopeMap)
    643         delete entry.second;
    644     /// remove expressions before symbol map deletion
    645     for (auto& entry: symbolMap)
    646         entry.second.clearOccurrencesInExpr();
     649    std::stack<ScopeStackElem0> scopeStack;
     650    scopeStack.push({ this, this->scopeMap.begin() });
     651   
     652    while (!scopeStack.empty())
     653    {
     654        ScopeStackElem0& entry = scopeStack.top();
     655        if (entry.it != entry.scope->scopeMap.end())
     656        {
     657            // next nested level
     658            if (entry.it->second != nullptr)
     659                scopeStack.push({ entry.it->second, entry.it->second->scopeMap.begin() });
     660            entry.it->second = nullptr;
     661            ++entry.it;
     662        }
     663        else
     664        {
     665            entry.scope->scopeMap.clear();
     666            /// remove expressions before symbol map deletion
     667            for (auto& symEntry: entry.scope->symbolMap)
     668                symEntry.second.clearOccurrencesInExpr();
     669            entry.scope->symbolMap.clear();
     670            if (scopeStack.size() > 1)
     671                delete entry.scope;
     672            scopeStack.pop();
     673        }
     674    }
    647675}
    648676
     
    650678void AsmScope::deleteSymbolsRecursively()
    651679{
    652     symbolMap.clear();
    653     for (auto& entry: scopeMap)
    654         entry.second->deleteSymbolsRecursively();
     680    std::stack<ScopeStackElem0> scopeStack;
     681    scopeStack.push({ this, this->scopeMap.begin() });
     682   
     683    while (!scopeStack.empty())
     684    {
     685        ScopeStackElem0& entry = scopeStack.top();
     686        if (entry.it == entry.scope->scopeMap.begin())
     687            // first touch - clear symbol map
     688            entry.scope->symbolMap.clear();
     689       
     690        if (entry.it != entry.scope->scopeMap.end())
     691        {
     692            // next nested level
     693            scopeStack.push({ entry.it->second, entry.it->second->scopeMap.begin() });
     694            ++entry.it;
     695        }
     696        else
     697            scopeStack.pop();
     698    }
    655699}
    656700
Note: See TracChangeset for help on using the changeset viewer.