From 89a1e97e7dd8a9af5a5fe2c5530cf4217c79f43b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 13 Jul 2017 01:07:23 +0100 Subject: Avoid cyclic imports in referencedSourceUnits --- libsolidity/ast/AST.cpp | 15 ++++++++++----- libsolidity/ast/AST.h | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'libsolidity') 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(*m_annotation); } -set SourceUnit::referencedSourceUnits(bool _recurse) const +set SourceUnit::referencedSourceUnits(bool _recurse, set _skipList) const { set sourceUnits; for (ImportDirective const* importDirective: filteredNodes(nodes())) { - sourceUnits.insert(importDirective->annotation().sourceUnit); - if (_recurse) + auto const& sourceUnit = importDirective->annotation().sourceUnit; + if (!_skipList.count(sourceUnit)) { - set referencedSourceUnits = importDirective->annotation().sourceUnit->referencedSourceUnits(true); - sourceUnits.insert(referencedSourceUnits.begin(), referencedSourceUnits.end()); + _skipList.insert(sourceUnit); + sourceUnits.insert(sourceUnit); + if (_recurse) + { + set 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> nodes() const { return m_nodes; } /// @returns a set of referenced SourceUnits. Recursively if @a _recurse is true. - std::set referencedSourceUnits(bool _recurse = false) const; + std::set referencedSourceUnits(bool _recurse = false, std::set _skipList = std::set()) const; private: std::vector> m_nodes; -- cgit v1.2.3