aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-07-27 20:20:18 +0800
committerGitHub <noreply@github.com>2017-07-27 20:20:18 +0800
commit517a36640469ccf2501f85f763776b04268276c8 (patch)
treee09534264628a5477470c38dd62572a1b645803b /libsolidity
parent1caa14b0717533dc415d76aa92061235c7aaebfd (diff)
parent7c7c2baa82ec2fa0535381c2ea3418b8623a9062 (diff)
downloaddexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar.gz
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar.bz2
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar.lz
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar.xz
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.tar.zst
dexon-solidity-517a36640469ccf2501f85f763776b04268276c8.zip
Merge pull request #2652 from ethereum/fixMultiModifier
Re-allow multiple modifiers per function.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
-rw-r--r--libsolidity/codegen/CompilerContext.cpp12
-rw-r--r--libsolidity/codegen/CompilerContext.h5
3 files changed, 11 insertions, 8 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 23f01752..0d04c26d 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -510,8 +510,6 @@ bool TypeChecker::visit(FunctionDefinition const& _function)
{
if (dynamic_cast<ContractDefinition const*>(decl))
m_errorReporter.declarationError(modifier->location(), "Base constructor already provided.");
- else
- m_errorReporter.declarationError(modifier->location(), "Modifier already used for this function.");
}
else
modifiers.insert(decl);
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp
index e52d14de..bc4de3ee 100644
--- a/libsolidity/codegen/CompilerContext.cpp
+++ b/libsolidity/codegen/CompilerContext.cpp
@@ -124,14 +124,15 @@ void CompilerContext::addVariable(VariableDeclaration const& _declaration,
unsigned _offsetToCurrent)
{
solAssert(m_asm->deposit() >= 0 && unsigned(m_asm->deposit()) >= _offsetToCurrent, "");
- solAssert(m_localVariables.count(&_declaration) == 0, "Variable already present");
- m_localVariables[&_declaration] = unsigned(m_asm->deposit()) - _offsetToCurrent;
+ m_localVariables[&_declaration].push_back(unsigned(m_asm->deposit()) - _offsetToCurrent);
}
void CompilerContext::removeVariable(VariableDeclaration const& _declaration)
{
- solAssert(!!m_localVariables.count(&_declaration), "");
- m_localVariables.erase(&_declaration);
+ solAssert(m_localVariables.count(&_declaration) && !m_localVariables[&_declaration].empty(), "");
+ m_localVariables[&_declaration].pop_back();
+ if (m_localVariables[&_declaration].empty())
+ m_localVariables.erase(&_declaration);
}
eth::Assembly const& CompilerContext::compiledContract(const ContractDefinition& _contract) const
@@ -203,7 +204,8 @@ unsigned CompilerContext::baseStackOffsetOfVariable(Declaration const& _declarat
{
auto res = m_localVariables.find(&_declaration);
solAssert(res != m_localVariables.end(), "Variable not found on stack.");
- return res->second;
+ solAssert(!res->second.empty(), "");
+ return res->second.back();
}
unsigned CompilerContext::baseToCurrentStackOffset(unsigned _baseOffset) const
diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h
index 1968c1e1..13821f67 100644
--- a/libsolidity/codegen/CompilerContext.h
+++ b/libsolidity/codegen/CompilerContext.h
@@ -272,7 +272,10 @@ private:
/// Storage offsets of state variables
std::map<Declaration const*, std::pair<u256, unsigned>> m_stateVariables;
/// Offsets of local variables on the stack (relative to stack base).
- std::map<Declaration const*, unsigned> m_localVariables;
+ /// This needs to be a stack because if a modifier contains a local variable and this
+ /// modifier is applied twice, the position of the variable needs to be restored
+ /// after the nested modifier is left.
+ std::map<Declaration const*, std::vector<unsigned>> m_localVariables;
/// List of current inheritance hierarchy from derived to base.
std::vector<ContractDefinition const*> m_inheritanceHierarchy;
/// Stack of current visited AST nodes, used for location attachment