From cc8e1e9e9f1dd8f90becbc58e7a6d56724c2df02 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Thu, 11 Jul 2019 06:29:31 -0700 Subject: [PATCH] [flang] Change two member functions of DerivedTypeDetails to non-member In `OrderParameterNames` and `OrderParameterDeclarations` it was always true that `this == &type.get()` 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@81710d4e6ec9e316d95b955a1efd253d9c485fef Reviewed-on: https://github.com/flang-compiler/f18/pull/559 --- flang/lib/semantics/check-allocate.cc | 4 +--- flang/lib/semantics/resolve-names.cc | 5 ++--- flang/lib/semantics/symbol.cc | 26 -------------------------- flang/lib/semantics/symbol.h | 9 --------- flang/lib/semantics/tools.cc | 28 ++++++++++++++++++++++------ flang/lib/semantics/tools.h | 8 ++++++++ 6 files changed, 33 insertions(+), 47 deletions(-) diff --git a/flang/lib/semantics/check-allocate.cc b/flang/lib/semantics/check-allocate.cc index ffc6304..fa9d7d4 100644 --- a/flang/lib/semantics/check-allocate.cc +++ b/flang/lib/semantics/check-allocate.cc @@ -353,10 +353,8 @@ static std::optional GetTypeParameterInt64Value( // type2 (except for kind type parameters) static bool HaveCompatibleKindParameters( const DerivedTypeSpec &derivedType1, const DerivedTypeSpec &derivedType2) { - const DerivedTypeDetails &typeDetails{ - derivedType1.typeSymbol().get()}; for (const Symbol *symbol : - typeDetails.OrderParameterDeclarations(derivedType1.typeSymbol())) { + OrderParameterDeclarations(derivedType1.typeSymbol())) { if (symbol->get().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. diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index 9758a38..6e5ff7e 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -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()}; - 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 : diff --git a/flang/lib/semantics/symbol.cc b/flang/lib/semantics/symbol.cc index 603d60d..4c55c64 100644 --- a/flang/lib/semantics/symbol.cc +++ b/flang/lib/semantics/symbol.cc @@ -552,32 +552,6 @@ void DerivedTypeDetails::add_component(const Symbol &symbol) { componentNames_.push_back(symbol.name()); } -std::list DerivedTypeDetails::OrderParameterNames( - const Symbol &type) const { - std::list result; - if (const DerivedTypeSpec * spec{type.GetParentTypeSpec()}) { - const DerivedTypeDetails &details{ - spec->typeSymbol().get()}; - 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()}; - 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_) { diff --git a/flang/lib/semantics/symbol.h b/flang/lib/semantics/symbol.h index dc85345..447a891 100644 --- a/flang/lib/semantics/symbol.h +++ b/flang/lib/semantics/symbol.h @@ -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 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 diff --git a/flang/lib/semantics/tools.cc b/flang/lib/semantics/tools.cc index de6e8ec..8be6317 100644 --- a/flang/lib/semantics/tools.cc +++ b/flang/lib/semantics/tools.cc @@ -459,6 +459,26 @@ static const DeclTypeSpec *FindInstantiatedDerivedType(const Scope &scope, static Symbol &InstantiateSymbol(const Symbol &, Scope &, SemanticsContext &); +std::list OrderParameterNames(const Symbol &typeSymbol) { + std::list result; + if (const DerivedTypeSpec * spec{typeSymbol.GetParentTypeSpec()}) { + result = OrderParameterNames(spec->typeSymbol()); + } + const auto ¶mNames{typeSymbol.get().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().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()}; - 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()}; - 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 diff --git a/flang/lib/semantics/tools.h b/flang/lib/semantics/tools.h index 6420ac5..f78d061 100644 --- a/flang/lib/semantics/tools.h +++ b/flang/lib/semantics/tools.h @@ -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 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 &); -- 2.7.4