[flang] Change two member functions of DerivedTypeDetails to non-member
authorTim Keith <tkeith@nvidia.com>
Thu, 11 Jul 2019 13:29:31 +0000 (06:29 -0700)
committerTim Keith <tkeith@nvidia.com>
Thu, 11 Jul 2019 15:51:40 +0000 (08:51 -0700)
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@81710d4e6ec9e316d95b955a1efd253d9c485fef
Reviewed-on: https://github.com/flang-compiler/f18/pull/559

flang/lib/semantics/check-allocate.cc
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/symbol.cc
flang/lib/semantics/symbol.h
flang/lib/semantics/tools.cc
flang/lib/semantics/tools.h

index ffc6304..fa9d7d4 100644 (file)
@@ -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.
index 9758a38..6e5ff7e 100644 (file)
@@ -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 :
index 603d60d..4c55c64 100644 (file)
@@ -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_) {
index dc85345..447a891 100644 (file)
@@ -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
index de6e8ec..8be6317 100644 (file)
@@ -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 &paramNames{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 &paramDecls{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
index 6420ac5..f78d061 100644 (file)
@@ -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 &);