aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-01-11 20:55:58 +0800
committerchriseth <c@ethdev.com>2016-01-11 20:56:02 +0800
commitf20a604c5a941ed5117d3e472b5ad93bed02fd97 (patch)
tree0e08a74d3432787f135fbd471b5cdf3fa1251321 /libsolidity
parentaa645d11927dce715ed3507e4b2ae89cf984a488 (diff)
downloaddexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar.gz
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar.bz2
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar.lz
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar.xz
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.tar.zst
dexon-solidity-f20a604c5a941ed5117d3e472b5ad93bed02fd97.zip
Allow aliases during import.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/DeclarationContainer.cpp11
-rw-r--r--libsolidity/analysis/NameAndTypeResolver.cpp57
-rw-r--r--libsolidity/ast/AST.h4
3 files changed, 56 insertions, 16 deletions
diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp
index ac56562e..042b7a6a 100644
--- a/libsolidity/analysis/DeclarationContainer.cpp
+++ b/libsolidity/analysis/DeclarationContainer.cpp
@@ -49,6 +49,8 @@ Declaration const* DeclarationContainer::conflictingDeclaration(
if (!dynamic_cast<FunctionDefinition const*>(declaration))
return declaration;
}
+ else if (declarations.size() == 1 && declarations.front() == &_declaration)
+ return nullptr;
else if (!declarations.empty())
return declarations.front();
@@ -73,13 +75,12 @@ bool DeclarationContainer::registerDeclaration(
m_declarations.erase(*_name);
m_invisibleDeclarations.erase(*_name);
}
- else if (conflictingDeclaration(_declaration))
+ else if (conflictingDeclaration(_declaration, _name))
return false;
- if (_invisible)
- m_invisibleDeclarations[*_name].push_back(&_declaration);
- else
- m_declarations[*_name].push_back(&_declaration);
+ vector<Declaration const*>& decls = _invisible ? m_invisibleDeclarations[*_name] : m_declarations[*_name];
+ if (!contains(decls, &_declaration))
+ decls.push_back(&_declaration);
return true;
}
diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp
index 96ffdd6e..5e407383 100644
--- a/libsolidity/analysis/NameAndTypeResolver.cpp
+++ b/libsolidity/analysis/NameAndTypeResolver.cpp
@@ -76,23 +76,58 @@ bool NameAndTypeResolver::performImports(SourceUnit& _sourceUnit, map<string, So
string const& path = imp->annotation().absolutePath;
if (!_sourceUnits.count(path))
{
- reportDeclarationError( node->location(),
- "Import \"" +
- path +
- "\" (referenced as \"" +
- imp->path() +
- "\") not found."
+ reportDeclarationError(
+ imp->location(),
+ "Import \"" + path + "\" (referenced as \"" + imp->path() + "\") not found."
);
error = true;
+ continue;
}
+ auto scope = m_scopes.find(_sourceUnits.at(path));
+ solAssert(scope != end(m_scopes), "");
+ if (!imp->symbolAliases().empty())
+ for (auto const& alias: imp->symbolAliases())
+ {
+ auto declarations = scope->second->resolveName(alias.first->name(), false);
+ if (declarations.empty())
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Declaration \"" +
+ alias.first->name() +
+ "\" not found in \"" +
+ path +
+ "\" (referenced as \"" +
+ imp->path() +
+ "\")."
+ );
+ error = true;
+ }
+ else
+ for (Declaration const* declaration: declarations)
+ {
+ ASTString const* name = alias.second ? alias.second.get() : &declaration->name();
+ if (!target.registerDeclaration(*declaration, name))
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Identifier \"" + *name + "\" already declared."
+ );
+ error = true;
+ }
+ }
+ }
else if (imp->name().empty())
- {
- auto scope = m_scopes.find(_sourceUnits.at(path));
- solAssert(scope != end(m_scopes), "");
for (auto const& nameAndDeclaration: scope->second->declarations())
for (auto const& declaration: nameAndDeclaration.second)
- target.registerDeclaration(*declaration, &nameAndDeclaration.first);
- }
+ if (!target.registerDeclaration(*declaration, &nameAndDeclaration.first))
+ {
+ reportDeclarationError(
+ imp->location(),
+ "Identifier \"" + nameAndDeclaration.first + "\" already declared."
+ );
+ error = true;
+ }
}
return !error;
}
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index 604a12a0..4baf95d3 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -201,6 +201,10 @@ public:
virtual void accept(ASTConstVisitor& _visitor) const override;
ASTString const& path() const { return *m_path; }
+ std::vector<std::pair<ASTPointer<Identifier>, ASTPointer<ASTString>>> const& symbolAliases() const
+ {
+ return m_symbolAliases;
+ }
virtual ImportAnnotation& annotation() const override;
virtual TypePointer type() const override;