aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/interface/CompilerStack.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-01-12 02:40:15 +0800
committerchriseth <c@ethdev.com>2016-01-14 18:36:13 +0800
commit2364c55735f8e511dbed6e46f83975a867839e12 (patch)
treed2db787525bbf300d0e07cb6af15c0e4ea13e7cb /libsolidity/interface/CompilerStack.cpp
parent1cf6acca90b6876c83676b0dc04babd3efcbf092 (diff)
downloaddexon-solidity-2364c55735f8e511dbed6e46f83975a867839e12.tar.gz
dexon-solidity-2364c55735f8e511dbed6e46f83975a867839e12.tar.zst
dexon-solidity-2364c55735f8e511dbed6e46f83975a867839e12.zip
Detect library name clashes.
Diffstat (limited to 'libsolidity/interface/CompilerStack.cpp')
-rw-r--r--libsolidity/interface/CompilerStack.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index a6f6f224..9a7d6982 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -148,6 +148,9 @@ bool CompilerStack::parse()
m_contracts[contract->name()].contract = contract;
}
+ if (!checkLibraryNameClashes())
+ noErrors = false;
+
for (Source const* source: m_sourceOrder)
for (ASTPointer<ASTNode> const& node: source->ast->nodes())
if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
@@ -400,6 +403,36 @@ void CompilerStack::resolveImports()
swap(m_sourceOrder, sourceOrder);
}
+bool CompilerStack::checkLibraryNameClashes()
+{
+ bool clashFound = false;
+ map<string, SourceLocation> libraries;
+ for (Source const* source: m_sourceOrder)
+ for (ASTPointer<ASTNode> const& node: source->ast->nodes())
+ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get()))
+ if (contract->isLibrary())
+ {
+ if (libraries.count(contract->name()))
+ {
+ auto err = make_shared<Error>(Error::Type::DeclarationError);
+ *err <<
+ errinfo_sourceLocation(contract->location()) <<
+ errinfo_comment(
+ "Library \"" + contract->name() + "\" declared twice "
+ "(will create ambiguities during linking)."
+ ) <<
+ errinfo_secondarySourceLocation(SecondarySourceLocation().append(
+ "The other declaration is here:", libraries[contract->name()]
+ ));
+
+ m_errors.push_back(err);
+ }
+ else
+ libraries[contract->name()] = contract->location();
+ }
+ return !clashFound;
+}
+
string CompilerStack::absolutePath(string const& _path, string const& _reference) const
{
// Anything that does not start with `.` is an absolute path.