forked from OSchip/llvm-project
[flang] Change two member functions of DerivedTypeDetails to non-member
In `OrderParameterNames` and `OrderParameterDeclarations` it was always true that `this == &type.get<DerivedTypeDetails>()` which meant that `this` was redundant. So convert them to non-member functions in `tools.h` that get the details from the symbol passed in. This makes life simpler for the callers. Original-commit: flang-compiler/f18@81710d4e6e Reviewed-on: https://github.com/flang-compiler/f18/pull/559
This commit is contained in:
parent
c37707a5b1
commit
cc8e1e9e9f
|
@ -353,10 +353,8 @@ static std::optional<std::int64_t> GetTypeParameterInt64Value(
|
|||
// type2 (except for kind type parameters)
|
||||
static bool HaveCompatibleKindParameters(
|
||||
const DerivedTypeSpec &derivedType1, const DerivedTypeSpec &derivedType2) {
|
||||
const DerivedTypeDetails &typeDetails{
|
||||
derivedType1.typeSymbol().get<DerivedTypeDetails>()};
|
||||
for (const Symbol *symbol :
|
||||
typeDetails.OrderParameterDeclarations(derivedType1.typeSymbol())) {
|
||||
OrderParameterDeclarations(derivedType1.typeSymbol())) {
|
||||
if (symbol->get<TypeParamDetails>().attr() == common::TypeParamAttr::Kind) {
|
||||
// At this point, it should have been ensured that these contain integer
|
||||
// constants, so die if this is not the case.
|
||||
|
|
|
@ -2891,9 +2891,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeSpec &x) {
|
|||
// order as "type parameter order" (7.5.3.2).
|
||||
// Parameters of the most deeply nested "base class" come first when the
|
||||
// derived type is an extension.
|
||||
const DerivedTypeDetails &typeDetails{typeSymbol->get<DerivedTypeDetails>()};
|
||||
auto parameterNames{typeDetails.OrderParameterNames(*typeSymbol)};
|
||||
auto parameterDecls{typeDetails.OrderParameterDeclarations(*typeSymbol)};
|
||||
auto parameterNames{OrderParameterNames(*typeSymbol)};
|
||||
auto parameterDecls{OrderParameterDeclarations(*typeSymbol)};
|
||||
auto nextNameIter{parameterNames.begin()};
|
||||
bool seenAnyName{false};
|
||||
for (const auto &typeParamSpec :
|
||||
|
|
|
@ -552,32 +552,6 @@ void DerivedTypeDetails::add_component(const Symbol &symbol) {
|
|||
componentNames_.push_back(symbol.name());
|
||||
}
|
||||
|
||||
std::list<SourceName> DerivedTypeDetails::OrderParameterNames(
|
||||
const Symbol &type) const {
|
||||
std::list<SourceName> result;
|
||||
if (const DerivedTypeSpec * spec{type.GetParentTypeSpec()}) {
|
||||
const DerivedTypeDetails &details{
|
||||
spec->typeSymbol().get<DerivedTypeDetails>()};
|
||||
result = details.OrderParameterNames(spec->typeSymbol());
|
||||
}
|
||||
for (const auto &name : paramNames_) {
|
||||
result.push_back(name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SymbolVector DerivedTypeDetails::OrderParameterDeclarations(
|
||||
const Symbol &type) const {
|
||||
SymbolVector result;
|
||||
if (const DerivedTypeSpec * spec{type.GetParentTypeSpec()}) {
|
||||
const DerivedTypeDetails &details{
|
||||
spec->typeSymbol().get<DerivedTypeDetails>()};
|
||||
result = details.OrderParameterDeclarations(spec->typeSymbol());
|
||||
}
|
||||
result.insert(result.end(), paramDecls_.begin(), paramDecls_.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
SymbolVector DerivedTypeDetails::OrderComponents(const Scope &scope) const {
|
||||
SymbolVector result;
|
||||
for (SourceName name : componentNames_) {
|
||||
|
|
|
@ -233,15 +233,6 @@ public:
|
|||
void add_component(const Symbol &);
|
||||
void set_sequence(bool x = true) { sequence_ = x; }
|
||||
|
||||
// Returns the complete list of derived type parameter names in the
|
||||
// order defined by 7.5.3.2.
|
||||
std::list<SourceName> OrderParameterNames(const Symbol &) const;
|
||||
|
||||
// Returns the complete list of derived type parameter symbols in
|
||||
// the order in which their declarations appear in the derived type
|
||||
// definitions (parents first).
|
||||
SymbolVector OrderParameterDeclarations(const Symbol &) const;
|
||||
|
||||
// Returns the complete list of derived type components in the order
|
||||
// in which their declarations appear in the derived type definitions
|
||||
// (parents first). Parent components appear in the list immediately
|
||||
|
|
|
@ -459,6 +459,26 @@ static const DeclTypeSpec *FindInstantiatedDerivedType(const Scope &scope,
|
|||
|
||||
static Symbol &InstantiateSymbol(const Symbol &, Scope &, SemanticsContext &);
|
||||
|
||||
std::list<SourceName> OrderParameterNames(const Symbol &typeSymbol) {
|
||||
std::list<SourceName> result;
|
||||
if (const DerivedTypeSpec * spec{typeSymbol.GetParentTypeSpec()}) {
|
||||
result = OrderParameterNames(spec->typeSymbol());
|
||||
}
|
||||
const auto ¶mNames{typeSymbol.get<DerivedTypeDetails>().paramNames()};
|
||||
result.insert(result.end(), paramNames.begin(), paramNames.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
SymbolVector OrderParameterDeclarations(const Symbol &typeSymbol) {
|
||||
SymbolVector result;
|
||||
if (const DerivedTypeSpec * spec{typeSymbol.GetParentTypeSpec()}) {
|
||||
result = OrderParameterDeclarations(spec->typeSymbol());
|
||||
}
|
||||
const auto ¶mDecls{typeSymbol.get<DerivedTypeDetails>().paramDecls()};
|
||||
result.insert(result.end(), paramDecls.begin(), paramDecls.end());
|
||||
return result;
|
||||
}
|
||||
|
||||
void InstantiateDerivedType(DerivedTypeSpec &spec, Scope &containingScope,
|
||||
SemanticsContext &semanticsContext) {
|
||||
Scope &newScope{containingScope.MakeScope(Scope::Kind::DerivedType)};
|
||||
|
@ -467,9 +487,7 @@ void InstantiateDerivedType(DerivedTypeSpec &spec, Scope &containingScope,
|
|||
const Symbol &typeSymbol{spec.typeSymbol()};
|
||||
const Scope *typeScope{typeSymbol.scope()};
|
||||
CHECK(typeScope != nullptr);
|
||||
const auto &typeDetails{typeSymbol.get<DerivedTypeDetails>()};
|
||||
for (const Symbol *symbol :
|
||||
typeDetails.OrderParameterDeclarations(typeSymbol)) {
|
||||
for (const Symbol *symbol : OrderParameterDeclarations(typeSymbol)) {
|
||||
const SourceName &name{symbol->name()};
|
||||
if (typeScope->find(symbol->name()) != typeScope->end()) {
|
||||
// This type parameter belongs to the derived type itself, not to
|
||||
|
@ -526,9 +544,7 @@ void InstantiateDerivedType(DerivedTypeSpec &spec, Scope &containingScope,
|
|||
|
||||
void ProcessParameterExpressions(
|
||||
DerivedTypeSpec &spec, evaluate::FoldingContext &foldingContext) {
|
||||
const Symbol &typeSymbol{spec.typeSymbol()};
|
||||
const DerivedTypeDetails &typeDetails{typeSymbol.get<DerivedTypeDetails>()};
|
||||
auto paramDecls{typeDetails.OrderParameterDeclarations(typeSymbol)};
|
||||
auto paramDecls{OrderParameterDeclarations(spec.typeSymbol())};
|
||||
// Fold the explicit type parameter value expressions first. Do not
|
||||
// fold them within the scope of the derived type being instantiated;
|
||||
// these expressions cannot use its type parameters. Convert the values
|
||||
|
|
|
@ -103,6 +103,14 @@ bool IsFinalizable(const Symbol &symbol);
|
|||
bool IsCoarray(const Symbol &symbol);
|
||||
bool IsAssumedSizeArray(const Symbol &symbol);
|
||||
|
||||
// Returns the complete list of derived type parameter symbols in
|
||||
// the order in which their declarations appear in the derived type
|
||||
// definitions (parents first).
|
||||
SymbolVector OrderParameterDeclarations(const Symbol &);
|
||||
// Returns the complete list of derived type parameter names in the
|
||||
// order defined by 7.5.3.2.
|
||||
std::list<SourceName> OrderParameterNames(const Symbol &);
|
||||
|
||||
// Create a new instantiation of this parameterized derived type
|
||||
// for this particular distinct set of actual parameter values.
|
||||
void InstantiateDerivedType(DerivedTypeSpec &, Scope &, SemanticsContext &);
|
||||
|
|
Loading…
Reference in New Issue