diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-13 08:07:23 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-07-19 21:56:40 +0800 |
commit | 89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b (patch) | |
tree | 6abc7f120db94cba42bb052f08899043d3b0f9ad /libsolidity | |
parent | c617336587b976afc3dbe388ebaa8605c3d6fe54 (diff) | |
download | dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar.gz dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar.bz2 dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar.lz dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar.xz dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.tar.zst dexon-solidity-89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b.zip |
Avoid cyclic imports in referencedSourceUnits
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/ast/AST.cpp | 15 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 2 |
2 files changed, 11 insertions, 6 deletions
diff --git a/libsolidity/ast/AST.cpp b/libsolidity/ast/AST.cpp index a126e6ed..f4ab6491 100644 --- a/libsolidity/ast/AST.cpp +++ b/libsolidity/ast/AST.cpp @@ -84,16 +84,21 @@ SourceUnitAnnotation& SourceUnit::annotation() const return dynamic_cast<SourceUnitAnnotation&>(*m_annotation); } -set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse) const +set<SourceUnit const*> SourceUnit::referencedSourceUnits(bool _recurse, set<SourceUnit const*> _skipList) const { set<SourceUnit const*> sourceUnits; for (ImportDirective const* importDirective: filteredNodes<ImportDirective>(nodes())) { - sourceUnits.insert(importDirective->annotation().sourceUnit); - if (_recurse) + auto const& sourceUnit = importDirective->annotation().sourceUnit; + if (!_skipList.count(sourceUnit)) { - set<SourceUnit const*> referencedSourceUnits = importDirective->annotation().sourceUnit->referencedSourceUnits(true); - sourceUnits.insert(referencedSourceUnits.begin(), referencedSourceUnits.end()); + _skipList.insert(sourceUnit); + sourceUnits.insert(sourceUnit); + if (_recurse) + { + set<SourceUnit const*> referencedSourceUnits = sourceUnit->referencedSourceUnits(true, _skipList); + sourceUnits.insert(referencedSourceUnits.begin(), referencedSourceUnits.end()); + } } } return sourceUnits; diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 2522867b..8012bcb4 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -137,7 +137,7 @@ public: std::vector<ASTPointer<ASTNode>> nodes() const { return m_nodes; } /// @returns a set of referenced SourceUnits. Recursively if @a _recurse is true. - std::set<SourceUnit const*> referencedSourceUnits(bool _recurse = false) const; + std::set<SourceUnit const*> referencedSourceUnits(bool _recurse = false, std::set<SourceUnit const*> _skipList = std::set<SourceUnit const*>()) const; private: std::vector<ASTPointer<ASTNode>> m_nodes; |