aboutsummaryrefslogtreecommitdiff
path: root/flang/lib/Semantics/scope.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Semantics/scope.cpp')
-rw-r--r--flang/lib/Semantics/scope.cpp52
1 files changed, 46 insertions, 6 deletions
diff --git a/flang/lib/Semantics/scope.cpp b/flang/lib/Semantics/scope.cpp
index 4af371f..ab75d4c 100644
--- a/flang/lib/Semantics/scope.cpp
+++ b/flang/lib/Semantics/scope.cpp
@@ -144,9 +144,8 @@ void Scope::add_crayPointer(const SourceName &name, Symbol &pointer) {
}
Symbol &Scope::MakeCommonBlock(SourceName name, SourceName location) {
- const auto it{commonBlocks_.find(name)};
- if (it != commonBlocks_.end()) {
- return *it->second;
+ if (auto *cb{FindCommonBlock(name)}) {
+ return *cb;
} else {
Symbol &symbol{MakeSymbol(
name, Attrs{}, CommonBlockDetails{name.empty() ? location : name})};
@@ -154,9 +153,25 @@ Symbol &Scope::MakeCommonBlock(SourceName name, SourceName location) {
return symbol;
}
}
-Symbol *Scope::FindCommonBlock(const SourceName &name) const {
- const auto it{commonBlocks_.find(name)};
- return it != commonBlocks_.end() ? &*it->second : nullptr;
+
+Symbol *Scope::FindCommonBlockInVisibleScopes(const SourceName &name) const {
+ if (Symbol * cb{FindCommonBlock(name)}) {
+ return cb;
+ } else if (Symbol * cb{FindCommonBlockUse(name)}) {
+ return &cb->GetUltimate();
+ } else if (IsSubmodule()) {
+ if (const Scope *parent{
+ symbol_ ? symbol_->get<ModuleDetails>().parent() : nullptr}) {
+ if (auto *cb{parent->FindCommonBlockInVisibleScopes(name)}) {
+ return cb;
+ }
+ }
+ } else if (!IsTopLevel() && parent_) {
+ if (auto *cb{parent_->FindCommonBlockInVisibleScopes(name)}) {
+ return cb;
+ }
+ }
+ return nullptr;
}
Scope *Scope::FindSubmodule(const SourceName &name) const {
@@ -167,6 +182,31 @@ Scope *Scope::FindSubmodule(const SourceName &name) const {
return &*it->second;
}
}
+
+bool Scope::AddCommonBlockUse(
+ const SourceName &name, Attrs attrs, Symbol &cbUltimate) {
+ CHECK(cbUltimate.has<CommonBlockDetails>());
+ // Make a symbol, but don't add it to the Scope, since it needs to
+ // be added to the USE-associated COMMON blocks
+ Symbol &useCB{MakeSymbol(name, attrs, UseDetails{name, cbUltimate})};
+ return commonBlockUses_.emplace(name, useCB).second;
+}
+
+Symbol *Scope::FindCommonBlock(const SourceName &name) const {
+ if (const auto it{commonBlocks_.find(name)}; it != commonBlocks_.end()) {
+ return &*it->second;
+ }
+ return nullptr;
+}
+
+Symbol *Scope::FindCommonBlockUse(const SourceName &name) const {
+ if (const auto it{commonBlockUses_.find(name)};
+ it != commonBlockUses_.end()) {
+ return &*it->second;
+ }
+ return nullptr;
+}
+
bool Scope::AddSubmodule(const SourceName &name, Scope &submodule) {
return submodules_.emplace(name, submodule).second;
}