Skip to content

Commit e27e9ca

Browse files
authored
[flang] Attempt to work around MSVC build problem (#161426)
Move a function that seems to be running into an MSVC problem from the source file where I created it to another one (tools.cpp) that is already known to be able to access the semantics::Scope type.
1 parent 8425004 commit e27e9ca

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,9 @@ bool IsVarSubexpressionOf(
15211521
// it returns std::nullopt.
15221522
std::optional<Expr<SomeType>> GetConvertInput(const Expr<SomeType> &x);
15231523

1524+
// How many ancestors does have a derived type have?
1525+
std::optional<int> DerivedTypeDepth(const semantics::Scope &);
1526+
15241527
} // namespace Fortran::evaluate
15251528

15261529
namespace Fortran::semantics {

flang/lib/Evaluate/constant.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "flang/Evaluate/expression.h"
1111
#include "flang/Evaluate/shape.h"
1212
#include "flang/Evaluate/type.h"
13-
#include "flang/Semantics/scope.h"
1413
#include <string>
1514

1615
namespace Fortran::evaluate {
@@ -390,33 +389,6 @@ std::size_t Constant<SomeDerived>::CopyFrom(const Constant<SomeDerived> &source,
390389
return Base::CopyFrom(source, count, resultSubscripts, dimOrder);
391390
}
392391

393-
static std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
394-
if (scope.IsDerivedType()) {
395-
for (auto iter{scope.cbegin()}; iter != scope.cend(); ++iter) {
396-
const Symbol &symbol{*iter->second};
397-
if (symbol.test(Symbol::Flag::ParentComp)) {
398-
if (const semantics::DeclTypeSpec *type{symbol.GetType()}) {
399-
if (const semantics::DerivedTypeSpec *derived{type->AsDerived()}) {
400-
const semantics::Scope *parent{derived->scope()};
401-
if (!parent) {
402-
parent = derived->typeSymbol().scope();
403-
}
404-
if (parent) {
405-
if (auto parentDepth{DerivedTypeDepth(*parent)}) {
406-
return 1 + *parentDepth;
407-
}
408-
}
409-
}
410-
}
411-
return std::nullopt; // error recovery
412-
}
413-
}
414-
return 0;
415-
} else {
416-
return std::nullopt; // error recovery
417-
}
418-
}
419-
420392
bool ComponentCompare::operator()(SymbolRef x, SymbolRef y) const {
421393
if (&x->owner() != &y->owner()) {
422394
// Not components of the same derived type; put ancestors' components first.

flang/lib/Evaluate/tools.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,6 +1950,33 @@ bool IsVarSubexpressionOf(
19501950
return VariableFinder{sub}(super);
19511951
}
19521952

1953+
std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
1954+
if (scope.IsDerivedType()) {
1955+
for (auto iter{scope.cbegin()}; iter != scope.cend(); ++iter) {
1956+
const Symbol &symbol{*iter->second};
1957+
if (symbol.test(Symbol::Flag::ParentComp)) {
1958+
if (const semantics::DeclTypeSpec *type{symbol.GetType()}) {
1959+
if (const semantics::DerivedTypeSpec *derived{type->AsDerived()}) {
1960+
const semantics::Scope *parent{derived->scope()};
1961+
if (!parent) {
1962+
parent = derived->typeSymbol().scope();
1963+
}
1964+
if (parent) {
1965+
if (auto parentDepth{DerivedTypeDepth(*parent)}) {
1966+
return 1 + *parentDepth;
1967+
}
1968+
}
1969+
}
1970+
}
1971+
return std::nullopt; // error recovery
1972+
}
1973+
}
1974+
return 0;
1975+
} else {
1976+
return std::nullopt; // error recovery
1977+
}
1978+
}
1979+
19531980
} // namespace Fortran::evaluate
19541981

19551982
namespace Fortran::semantics {

0 commit comments

Comments
 (0)