[flang][NFC] Switch CollectBindings return to SymbolVector
authorValentin Clement <clementval@gmail.com>
Tue, 22 Nov 2022 14:13:18 +0000 (15:13 +0100)
committerValentin Clement <clementval@gmail.com>
Tue, 22 Nov 2022 14:14:03 +0000 (15:14 +0100)
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138419

flang/include/flang/Semantics/runtime-type-info.h
flang/lib/Lower/Bridge.cpp
flang/lib/Semantics/runtime-type-info.cpp

index 4bb93c8..76560b9 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 #define FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
 
+#include "flang/Common/reference.h"
 #include <set>
 #include <string>
 #include <vector>
@@ -27,6 +28,9 @@ class Scope;
 class SemanticsContext;
 class Symbol;
 
+using SymbolRef = common::Reference<const Symbol>;
+using SymbolVector = std::vector<SymbolRef>;
+
 struct RuntimeDerivedTypeTables {
   Scope *schemata{nullptr};
   std::set<std::string> names;
@@ -38,7 +42,7 @@ RuntimeDerivedTypeTables BuildRuntimeDerivedTypeTables(SemanticsContext &);
 /// to describe other derived types at runtime in flang descriptor.
 constexpr char typeInfoBuiltinModule[]{"__fortran_type_info"};
 
-std::vector<const Symbol *> CollectBindings(const Scope &dtScope);
+SymbolVector CollectBindings(const Scope &dtScope);
 
 } // namespace Fortran::semantics
 #endif // FORTRAN_SEMANTICS_RUNTIME_TYPE_INFO_H_
index 5d8be03..bfd3041 100644 (file)
@@ -223,21 +223,21 @@ public:
           parent ? Fortran::lower::mangle::mangleName(*parent) : "");
       auto insertPt = builder.saveInsertionPoint();
 
-      std::vector<const Fortran::semantics::Symbol *> bindings =
+      Fortran::semantics::SymbolVector bindings =
           Fortran::semantics::CollectBindings(*info.typeSpec->scope());
 
       if (!bindings.empty())
         builder.createBlock(&dt.getRegion());
 
-      for (const Fortran::semantics::Symbol *binding : bindings) {
+      for (const Fortran::semantics::SymbolRef &binding : bindings) {
         const auto *details =
-            binding->detailsIf<Fortran::semantics::ProcBindingDetails>();
+            binding.get().detailsIf<Fortran::semantics::ProcBindingDetails>();
         std::string bindingName =
             Fortran::lower::mangle::mangleName(details->symbol());
         builder.create<fir::DTEntryOp>(
             info.loc,
             mlir::StringAttr::get(builder.getContext(),
-                                  binding->name().ToString()),
+                                  binding.get().name().ToString()),
             mlir::SymbolRefAttr::get(builder.getContext(), bindingName));
       }
       if (!bindings.empty())
index a3877e7..62cb264 100644 (file)
@@ -940,8 +940,8 @@ SomeExpr RuntimeTableBuilder::PackageIntValueExpr(
   return StructureExpr(PackageIntValue(genre, n));
 }
 
-std::vector<const Symbol *> CollectBindings(const Scope &dtScope) {
-  std::vector<const Symbol *> result;
+SymbolVector CollectBindings(const Scope &dtScope) {
+  SymbolVector result;
   std::map<SourceName, const Symbol *> localBindings;
   // Collect local bindings
   for (auto pair : dtScope) {
@@ -957,14 +957,14 @@ std::vector<const Symbol *> CollectBindings(const Scope &dtScope) {
       const Symbol &symbol{**iter};
       auto overridden{localBindings.find(symbol.name())};
       if (overridden != localBindings.end()) {
-        *iter = overridden->second;
+        *iter = *overridden->second;
         localBindings.erase(overridden);
       }
     }
   }
   // Add remaining (non-overriding) local bindings in name order to the result
   for (auto pair : localBindings) {
-    result.push_back(pair.second);
+    result.push_back(*pair.second);
   }
   return result;
 }
@@ -972,13 +972,13 @@ std::vector<const Symbol *> CollectBindings(const Scope &dtScope) {
 std::vector<evaluate::StructureConstructor>
 RuntimeTableBuilder::DescribeBindings(const Scope &dtScope, Scope &scope) {
   std::vector<evaluate::StructureConstructor> result;
-  for (const Symbol *symbol : CollectBindings(dtScope)) {
+  for (const SymbolRef &ref : CollectBindings(dtScope)) {
     evaluate::StructureConstructorValues values;
     AddValue(values, bindingSchema_, "proc"s,
         SomeExpr{evaluate::ProcedureDesignator{
-            symbol->get<ProcBindingDetails>().symbol()}});
+            ref.get().get<ProcBindingDetails>().symbol()}});
     AddValue(values, bindingSchema_, "name"s,
-        SaveNameAsPointerTarget(scope, symbol->name().ToString()));
+        SaveNameAsPointerTarget(scope, ref.get().name().ToString()));
     result.emplace_back(DEREF(bindingSchema_.AsDerived()), std::move(values));
   }
   return result;