aboutsummaryrefslogtreecommitdiffstats
path: root/CompilerContext.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-01-27 21:32:59 +0800
committerChristian <c@ethdev.com>2015-01-29 07:29:43 +0800
commitae5a6a235c9d0996a712903e0cfd0560b326bbad (patch)
tree51e9e64e0a4f59172d4de9345e15100d3fd96268 /CompilerContext.cpp
parentb5a786dda19e54fa587b1b693e7a139818d65b9e (diff)
downloaddexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar.gz
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar.bz2
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar.lz
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar.xz
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.tar.zst
dexon-solidity-ae5a6a235c9d0996a712903e0cfd0560b326bbad.zip
Super keyword.
Diffstat (limited to 'CompilerContext.cpp')
-rw-r--r--CompilerContext.cpp77
1 files changed, 55 insertions, 22 deletions
diff --git a/CompilerContext.cpp b/CompilerContext.cpp
index ea349c0d..52910a55 100644
--- a/CompilerContext.cpp
+++ b/CompilerContext.cpp
@@ -43,6 +43,14 @@ void CompilerContext::addStateVariable(VariableDeclaration const& _declaration)
m_stateVariablesSize += _declaration.getType()->getStorageSize();
}
+void CompilerContext::startFunction(Declaration const& _function)
+{
+ m_functionsWithCode.insert(&_function);
+ m_localVariables.clear();
+ m_asm.setDeposit(0);
+ *this << getFunctionEntryLabel(_function);
+}
+
void CompilerContext::addVariable(VariableDeclaration const& _declaration,
unsigned _offsetToCurrent)
{
@@ -59,18 +67,6 @@ void CompilerContext::addAndInitializeVariable(VariableDeclaration const& _decla
*this << u256(0);
}
-void CompilerContext::addFunction(Declaration const& _decl)
-{
- eth::AssemblyItem tag(m_asm.newTag());
- m_functionEntryLabels.insert(make_pair(&_decl, tag));
- m_virtualFunctionEntryLabels.insert(make_pair(_decl.getName(), tag));
-}
-
-void CompilerContext::addModifier(ModifierDefinition const& _modifier)
-{
- m_functionModifiers.insert(make_pair(_modifier.getName(), &_modifier));
-}
-
bytes const& CompilerContext::getCompiledContract(const ContractDefinition& _contract) const
{
auto ret = m_compiledContracts.find(&_contract);
@@ -83,25 +79,62 @@ bool CompilerContext::isLocalVariable(Declaration const* _declaration) const
return m_localVariables.count(_declaration);
}
-eth::AssemblyItem CompilerContext::getFunctionEntryLabel(Declaration const& _declaration) const
+eth::AssemblyItem CompilerContext::getFunctionEntryLabel(Declaration const& _declaration)
{
auto res = m_functionEntryLabels.find(&_declaration);
- solAssert(res != m_functionEntryLabels.end(), "Function entry label not found.");
- return res->second.tag();
+ if (res == m_functionEntryLabels.end())
+ {
+ eth::AssemblyItem tag(m_asm.newTag());
+ m_functionEntryLabels.insert(make_pair(&_declaration, tag));
+ return tag.tag();
+ }
+ else
+ return res->second.tag();
+}
+
+eth::AssemblyItem CompilerContext::getVirtualFunctionEntryLabel(FunctionDefinition const& _function)
+{
+ solAssert(!m_inheritanceHierarchy.empty(), "No inheritance hierarchy set.");
+ for (ContractDefinition const* contract: m_inheritanceHierarchy)
+ for (ASTPointer<FunctionDefinition> const& function: contract->getDefinedFunctions())
+ if (!function->isConstructor() && function->getName() == _function.getName())
+ return getFunctionEntryLabel(*function);
+ solAssert(false, "Virtual function " + _function.getName() + " not found.");
+ return m_asm.newTag(); // not reached
+}
+
+eth::AssemblyItem CompilerContext::getSuperFunctionEntryLabel(string const& _name, ContractDefinition const& _base)
+{
+ // search for first contract after _base
+ solAssert(!m_inheritanceHierarchy.empty(), "No inheritance hierarchy set.");
+ auto it = find(m_inheritanceHierarchy.begin(), m_inheritanceHierarchy.end(), &_base);
+ solAssert(it != m_inheritanceHierarchy.end(), "Base not found in inheritance hierarchy.");
+ for (++it; it != m_inheritanceHierarchy.end(); ++it)
+ for (ASTPointer<FunctionDefinition> const& function: (*it)->getDefinedFunctions())
+ if (!function->isConstructor() && function->getName() == _name)
+ return getFunctionEntryLabel(*function);
+ solAssert(false, "Super function " + _name + " not found.");
+ return m_asm.newTag(); // not reached
}
-eth::AssemblyItem CompilerContext::getVirtualFunctionEntryLabel(FunctionDefinition const& _function) const
+set<Declaration const*> CompilerContext::getFunctionsWithoutCode()
{
- auto res = m_virtualFunctionEntryLabels.find(_function.getName());
- solAssert(res != m_virtualFunctionEntryLabels.end(), "Function entry label not found.");
- return res->second.tag();
+ set<Declaration const*> functions;
+ for (auto const& it: m_functionEntryLabels)
+ if (m_functionsWithCode.count(it.first) == 0)
+ functions.insert(it.first);
+ return move(functions);
}
ModifierDefinition const& CompilerContext::getFunctionModifier(string const& _name) const
{
- auto res = m_functionModifiers.find(_name);
- solAssert(res != m_functionModifiers.end(), "Function modifier override not found.");
- return *res->second;
+ solAssert(!m_inheritanceHierarchy.empty(), "No inheritance hierarchy set.");
+ for (ContractDefinition const* contract: m_inheritanceHierarchy)
+ for (ASTPointer<ModifierDefinition> const& modifier: contract->getFunctionModifiers())
+ if (modifier->getName() == _name)
+ return *modifier.get();
+ BOOST_THROW_EXCEPTION(InternalCompilerError()
+ << errinfo_comment("Function modifier " + _name + " not found."));
}
unsigned CompilerContext::getBaseStackOffsetOfVariable(Declaration const& _declaration) const