diff options
author | chriseth <chris@ethereum.org> | 2018-02-06 01:02:32 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-02-06 19:38:32 +0800 |
commit | 88a5d152d028d597fd8cd90bd99ee5b7f1388191 (patch) | |
tree | dcb194994bd7fcc3c64132aafaf6330db8f3cedc | |
parent | 773be40c19a2c3b72a5cf743e86e150533e0f25f (diff) | |
download | dexon-solidity-88a5d152d028d597fd8cd90bd99ee5b7f1388191.tar.gz dexon-solidity-88a5d152d028d597fd8cd90bd99ee5b7f1388191.tar.zst dexon-solidity-88a5d152d028d597fd8cd90bd99ee5b7f1388191.zip |
Introduce struct for scopes.
-rw-r--r-- | libjulia/optimiser/DataFlowAnalyzer.cpp | 16 | ||||
-rw-r--r-- | libjulia/optimiser/DataFlowAnalyzer.h | 12 |
2 files changed, 17 insertions, 11 deletions
diff --git a/libjulia/optimiser/DataFlowAnalyzer.cpp b/libjulia/optimiser/DataFlowAnalyzer.cpp index 389f8715..9ee3215d 100644 --- a/libjulia/optimiser/DataFlowAnalyzer.cpp +++ b/libjulia/optimiser/DataFlowAnalyzer.cpp @@ -51,7 +51,7 @@ void DataFlowAnalyzer::operator()(VariableDeclaration& _varDecl) set<string> names; for (auto const& var: _varDecl.variables) names.insert(var.name); - m_variableScopes.back().first += names; + m_variableScopes.back().variables += names; if (_varDecl.value) visit(*_varDecl.value); handleAssignment(names, _varDecl.value.get()); @@ -84,11 +84,11 @@ void DataFlowAnalyzer::operator()(Switch& _switch) void DataFlowAnalyzer::operator()(FunctionDefinition& _fun) { - m_variableScopes.push_back(make_pair(set<string>(), true)); + m_variableScopes.emplace_back(true); for (auto const& parameter: _fun.parameters) - m_variableScopes.back().first.insert(parameter.name); + m_variableScopes.back().variables.insert(parameter.name); for (auto const& var: _fun.returnVariables) - m_variableScopes.back().first.insert(var.name); + m_variableScopes.back().variables.insert(var.name); ASTModifier::operator()(_fun); m_variableScopes.pop_back(); } @@ -96,7 +96,7 @@ void DataFlowAnalyzer::operator()(FunctionDefinition& _fun) void DataFlowAnalyzer::operator()(ForLoop& _for) { // Special scope handling of the pre block. - m_variableScopes.push_back(make_pair(set<string>(), false)); + m_variableScopes.emplace_back(false); for (auto& statement: _for.pre.statements) visit(statement); @@ -117,7 +117,7 @@ void DataFlowAnalyzer::operator()(ForLoop& _for) void DataFlowAnalyzer::operator()(Block& _block) { size_t numScopes = m_variableScopes.size(); - m_variableScopes.push_back(make_pair(set<string>(), false)); + m_variableScopes.emplace_back(false); ASTModifier::operator()(_block); m_variableScopes.pop_back(); solAssert(numScopes == m_variableScopes.size(), ""); @@ -186,9 +186,9 @@ bool DataFlowAnalyzer::inScope(string const& _variableName) const { for (auto const& scope: m_variableScopes | boost::adaptors::reversed) { - if (scope.first.count(_variableName)) + if (scope.variables.count(_variableName)) return true; - if (scope.second) + if (scope.isFunction) return false; } return false; diff --git a/libjulia/optimiser/DataFlowAnalyzer.h b/libjulia/optimiser/DataFlowAnalyzer.h index 16d6e72b..4cb3d4cd 100644 --- a/libjulia/optimiser/DataFlowAnalyzer.h +++ b/libjulia/optimiser/DataFlowAnalyzer.h @@ -69,9 +69,15 @@ protected: std::map<std::string, std::set<std::string>> m_references; /// m_referencedBy[b].contains(a) <=> the current expression assigned to a references b std::map<std::string, std::set<std::string>> m_referencedBy; - /// List of scopes, where each scope is a set of variables and a bool that tells - /// whether it is a function body (true) or not. - std::vector<std::pair<std::set<std::string>, bool>> m_variableScopes; + + struct Scope + { + explicit Scope(bool _isFunction): isFunction(_isFunction) {} + std::set<std::string> variables; + bool isFunction; + }; + /// List of scopes. + std::vector<Scope> m_variableScopes; }; } |