diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h --- a/flang/include/flang/Semantics/tools.h +++ b/flang/include/flang/Semantics/tools.h @@ -620,5 +620,7 @@ std::forward_list GetAllNames( const SemanticsContext &, const SourceName &); +std::vector CollectBindings(const Scope &dtScope); + } // namespace Fortran::semantics #endif // FORTRAN_SEMANTICS_TOOLS_H_ diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp --- a/flang/lib/Semantics/runtime-type-info.cpp +++ b/flang/lib/Semantics/runtime-type-info.cpp @@ -65,7 +65,6 @@ evaluate::StructureConstructor PackageIntValue( const SomeExpr &genre, std::int64_t = 0) const; SomeExpr PackageIntValueExpr(const SomeExpr &genre, std::int64_t = 0) const; - std::vector CollectBindings(const Scope &dtScope) const; std::vector DescribeBindings( const Scope &dtScope, Scope &); void DescribeGeneric( @@ -941,36 +940,6 @@ return StructureExpr(PackageIntValue(genre, n)); } -std::vector RuntimeTableBuilder::CollectBindings( - const Scope &dtScope) const { - std::vector result; - std::map localBindings; - // Collect local bindings - for (auto pair : dtScope) { - const Symbol &symbol{*pair.second}; - if (symbol.has()) { - localBindings.emplace(symbol.name(), &symbol); - } - } - if (const Scope * parentScope{dtScope.GetDerivedTypeParent()}) { - result = CollectBindings(*parentScope); - // Apply overrides from the local bindings of the extended type - for (auto iter{result.begin()}; iter != result.end(); ++iter) { - const Symbol &symbol{**iter}; - auto overridden{localBindings.find(symbol.name())}; - if (overridden != localBindings.end()) { - *iter = overridden->second; - localBindings.erase(overridden); - } - } - } - // Add remaining (non-overriding) local bindings in name order to the result - for (auto pair : localBindings) { - result.push_back(pair.second); - } - return result; -} - std::vector RuntimeTableBuilder::DescribeBindings(const Scope &dtScope, Scope &scope) { std::vector result; diff --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp --- a/flang/lib/Semantics/tools.cpp +++ b/flang/lib/Semantics/tools.cpp @@ -1511,4 +1511,33 @@ return nullptr; } +std::vector CollectBindings(const Scope &dtScope) { + std::vector result; + std::map localBindings; + // Collect local bindings + for (auto pair : dtScope) { + const Symbol &symbol{*pair.second}; + if (symbol.has()) { + localBindings.emplace(symbol.name(), &symbol); + } + } + if (const Scope * parentScope{dtScope.GetDerivedTypeParent()}) { + result = CollectBindings(*parentScope); + // Apply overrides from the local bindings of the extended type + for (auto iter{result.begin()}; iter != result.end(); ++iter) { + const Symbol &symbol{**iter}; + auto overridden{localBindings.find(symbol.name())}; + if (overridden != localBindings.end()) { + *iter = overridden->second; + localBindings.erase(overridden); + } + } + } + // Add remaining (non-overriding) local bindings in name order to the result + for (auto pair : localBindings) { + result.push_back(pair.second); + } + return result; +} + } // namespace Fortran::semantics