Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ bool IsVarSubexpressionOf(
std::optional<Expr<SomeType>> GetConvertInput(const Expr<SomeType> &x);

// How many ancestors does have a derived type have?
std::optional<int> DerivedTypeDepth(const semantics::Scope &);
std::optional<int> CountDerivedTypeAncestors(const semantics::Scope &);

} // namespace Fortran::evaluate

Expand Down
5 changes: 3 additions & 2 deletions flang/lib/Evaluate/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flang/Evaluate/constant.h"
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/shape.h"
#include "flang/Evaluate/tools.h"
#include "flang/Evaluate/type.h"
#include <string>

Expand Down Expand Up @@ -392,8 +393,8 @@ std::size_t Constant<SomeDerived>::CopyFrom(const Constant<SomeDerived> &source,
bool ComponentCompare::operator()(SymbolRef x, SymbolRef y) const {
if (&x->owner() != &y->owner()) {
// Not components of the same derived type; put ancestors' components first.
if (auto xDepth{DerivedTypeDepth(x->owner())}) {
if (auto yDepth{DerivedTypeDepth(y->owner())}) {
if (auto xDepth{CountDerivedTypeAncestors(x->owner())}) {
if (auto yDepth{CountDerivedTypeAncestors(y->owner())}) {
if (*xDepth != *yDepth) {
return *xDepth < *yDepth;
}
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Evaluate/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,7 @@ bool IsVarSubexpressionOf(
return VariableFinder{sub}(super);
}

std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
std::optional<int> CountDerivedTypeAncestors(const semantics::Scope &scope) {
if (scope.IsDerivedType()) {
for (auto iter{scope.cbegin()}; iter != scope.cend(); ++iter) {
const Symbol &symbol{*iter->second};
Expand All @@ -1962,7 +1962,7 @@ std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
parent = derived->typeSymbol().scope();
}
if (parent) {
if (auto parentDepth{DerivedTypeDepth(*parent)}) {
if (auto parentDepth{CountDerivedTypeAncestors(*parent)}) {
return 1 + *parentDepth;
}
}
Expand Down