aboutsummaryrefslogtreecommitdiffstats
path: root/AST.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2015-01-30 05:50:20 +0800
committerChristian <c@ethdev.com>2015-01-30 05:50:20 +0800
commitcfb55901cc963523ca1defe232728f195a818228 (patch)
tree69110bff671995fb49805678d05d0687b4105429 /AST.cpp
parent3701543ae8dd8ffbfd58e5648d45699468f10a55 (diff)
downloaddexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar.gz
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar.bz2
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar.lz
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar.xz
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.tar.zst
dexon-solidity-cfb55901cc963523ca1defe232728f195a818228.zip
Fallback functions.
Diffstat (limited to 'AST.cpp')
-rw-r--r--AST.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/AST.cpp b/AST.cpp
index bc6be600..20c117c0 100644
--- a/AST.cpp
+++ b/AST.cpp
@@ -56,7 +56,12 @@ void ContractDefinition::checkTypeRequirements()
FunctionDefinition const* constructor = getConstructor();
if (constructor && !constructor->getReturnParameters().empty())
BOOST_THROW_EXCEPTION(constructor->getReturnParameterList()->createTypeError(
- "Non-empty \"returns\" directive for constructor."));
+ "Non-empty \"returns\" directive for constructor."));
+
+ FunctionDefinition const* fallbackFunction = getFallbackFunction();
+ if (fallbackFunction && fallbackFunction->getScope() == this && !fallbackFunction->getParameters().empty())
+ BOOST_THROW_EXCEPTION(fallbackFunction->getParameterList().createTypeError(
+ "Fallback function cannot take parameters."));
for (ASTPointer<ModifierDefinition> const& modifier: getFunctionModifiers())
modifier->checkTypeRequirements();
@@ -99,6 +104,15 @@ FunctionDefinition const* ContractDefinition::getConstructor() const
return nullptr;
}
+FunctionDefinition const* ContractDefinition::getFallbackFunction() const
+{
+ for (ContractDefinition const* contract: getLinearizedBaseContracts())
+ for (ASTPointer<FunctionDefinition> const& f: contract->getDefinedFunctions())
+ if (f->getName().empty())
+ return f.get();
+ return nullptr;
+}
+
void ContractDefinition::checkIllegalOverrides() const
{
// TODO unify this at a later point. for this we need to put the constness and the access specifier
@@ -147,7 +161,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getIn
for (ContractDefinition const* contract: getLinearizedBaseContracts())
{
for (ASTPointer<FunctionDefinition> const& f: contract->getDefinedFunctions())
- if (f->isPublic() && !f->isConstructor() && functionsSeen.count(f->getName()) == 0)
+ if (f->isPublic() && !f->isConstructor() && !f->getName().empty() && functionsSeen.count(f->getName()) == 0)
{
functionsSeen.insert(f->getName());
FixedHash<4> hash(dev::sha3(f->getCanonicalSignature()));