aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/AST.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-09-12 01:35:31 +0800
committerchriseth <c@ethdev.com>2015-09-12 01:35:31 +0800
commit4360e0459622e7843ca9f8d7fb5113da0b8a044e (patch)
treee8f5fe5f139517c000c57fa271617621420ccb5d /libsolidity/AST.cpp
parent3c25420b8476f1516ac8cb10f5c1552609a08675 (diff)
parentd89832fa898d18f1962eff14acf3f2f7b1c4e3bc (diff)
downloaddexon-solidity-4360e0459622e7843ca9f8d7fb5113da0b8a044e.tar.gz
dexon-solidity-4360e0459622e7843ca9f8d7fb5113da0b8a044e.tar.zst
dexon-solidity-4360e0459622e7843ca9f8d7fb5113da0b8a044e.zip
Merge pull request #66 from chriseth/sol_libraries
Calling libraries.
Diffstat (limited to 'libsolidity/AST.cpp')
-rw-r--r--libsolidity/AST.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp
index 1ad34cfe..674f33b7 100644
--- a/libsolidity/AST.cpp
+++ b/libsolidity/AST.cpp
@@ -106,6 +106,9 @@ void ContractDefinition::checkTypeRequirements()
));
hashes.insert(hash);
}
+
+ if (isLibrary())
+ checkLibraryRequirements();
}
map<FixedHash<4>, FunctionTypePointer> ContractDefinition::interfaceFunctions() const
@@ -335,6 +338,17 @@ void ContractDefinition::checkExternalTypeClashes() const
));
}
+void ContractDefinition::checkLibraryRequirements() const
+{
+ solAssert(m_isLibrary, "");
+ if (!m_baseContracts.empty())
+ BOOST_THROW_EXCEPTION(createTypeError("Library is not allowed to inherit."));
+
+ for (auto const& var: m_stateVariables)
+ if (!var->isConstant())
+ BOOST_THROW_EXCEPTION(var->createTypeError("Library cannot have non-constant state variables"));
+}
+
vector<ASTPointer<EventDefinition>> const& ContractDefinition::interfaceEvents() const
{
if (!m_interfaceEvents)
@@ -452,6 +466,10 @@ void InheritanceSpecifier::checkTypeRequirements()
ContractDefinition const* base = dynamic_cast<ContractDefinition const*>(&m_baseName->referencedDeclaration());
solAssert(base, "Base contract not available.");
+
+ if (base->isLibrary())
+ BOOST_THROW_EXCEPTION(createTypeError("Libraries cannot be inherited from."));
+
TypePointers parameterTypes = ContractType(*base).constructorType()->parameterTypes();
if (!m_arguments.empty() && parameterTypes.size() != m_arguments.size())
BOOST_THROW_EXCEPTION(createTypeError(