[flang-commits] [flang] 97e8eeb - [flang][NFC] Switch CollectBindings return to SymbolVector

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Nov 22 00:43:16 PST 2022


Author: Valentin Clement
Date: 2022-11-22T09:43:11+01:00
New Revision: 97e8eeb758fcae4f2afd9ac516ffc9509b4daaf0

URL: https://github.com/llvm/llvm-project/commit/97e8eeb758fcae4f2afd9ac516ffc9509b4daaf0
DIFF: https://github.com/llvm/llvm-project/commit/97e8eeb758fcae4f2afd9ac516ffc9509b4daaf0.diff

LOG: [flang][NFC] Switch CollectBindings return to SymbolVector

As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/runtime-type-info.h b/flang/include/flang/Semantics/runtime-type-info.h
index 4bb93c8e5069b..76560b98b1c20 100644
--- a/flang/include/flang/Semantics/runtime-type-info.h
+++ b/flang/include/flang/Semantics/runtime-type-info.h
@@ -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_

diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 5d8be0390ca87..f17f0f8bd1959 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -223,21 +223,21 @@ class DispatchTableConverter {
           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())

diff  --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index a3877e776bdc8..f0e2c8b1413a9 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -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;


        


More information about the flang-commits mailing list