Merge pull request #6848 from ethereum/invertibleRelation

Implement references using InvertibleRelation as data structure.
This commit is contained in:
chriseth
2019-05-29 13:34:10 +02:00
committed by GitHub
7 changed files with 86 additions and 23 deletions
+6 -17
View File
@@ -88,11 +88,9 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
// Save all information. We might rather reinstantiate this class,
// but this could be difficult if it is subclassed.
map<YulString, Expression const*> value;
map<YulString, set<YulString>> references;
map<YulString, set<YulString>> referencedBy;
InvertibleRelation<YulString> references;
m_value.swap(value);
m_references.swap(references);
m_referencedBy.swap(referencedBy);
swap(m_references, references);
pushScope(true);
for (auto const& parameter: _fun.parameters)
@@ -106,8 +104,7 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun)
popScope();
m_value.swap(value);
m_references.swap(references);
m_referencedBy.swap(referencedBy);
swap(m_references, references);
}
void DataFlowAnalyzer::operator()(ForLoop& _for)
@@ -162,11 +159,7 @@ void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expres
auto const& referencedVariables = movableChecker.referencedVariables();
for (auto const& name: _variables)
{
m_references[name] = referencedVariables;
for (auto const& ref: referencedVariables)
m_referencedBy[ref].emplace(name);
}
m_references.set(name, referencedVariables);
}
void DataFlowAnalyzer::pushScope(bool _functionScope)
@@ -197,18 +190,14 @@ void DataFlowAnalyzer::clearValues(set<YulString> _variables)
// Clear variables that reference variables to be cleared.
for (auto const& name: _variables)
for (auto const& ref: m_referencedBy[name])
for (auto const& ref: m_references.backward[name])
_variables.emplace(ref);
// Clear the value and update the reference relation.
for (auto const& name: _variables)
m_value.erase(name);
for (auto const& name: _variables)
{
for (auto const& ref: m_references[name])
m_referencedBy[ref].erase(name);
m_references[name].clear();
}
m_references.eraseKey(name);
}
bool DataFlowAnalyzer::inScope(YulString _variableName) const