forked from OSchip/llvm-project
[flang] Change Scope::name() to Scope::GetName()
Address comments. Not all scopes are related to a name. This change makes this more visible to compiler programers by changing `scope:name()` into `Scope::GetName()` that returns an optional `SourceName` instead of always returning a `SourceName` and dying when it cannot. Original-commit: flang-compiler/f18@0addb79919 Reviewed-on: https://github.com/flang-compiler/f18/pull/634 Tree-same-pre-rewrite: false
This commit is contained in:
parent
281d41cc10
commit
52e72abb67
|
@ -206,7 +206,8 @@ private:
|
|||
bool EndTDeallocatesCoarray() { return false; } // FIXME placeholder
|
||||
bool fromScope(const Symbol &symbol, const std::string &moduleName) {
|
||||
if (symbol.GetUltimate().owner().IsModule() &&
|
||||
symbol.GetUltimate().owner().name().ToString() == moduleName) {
|
||||
symbol.GetUltimate().owner().GetName().value().ToString() ==
|
||||
moduleName) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -126,7 +126,7 @@ void ModFileWriter::WriteOne(const Scope &scope) {
|
|||
// Write the module file for symbol, which must be a module or submodule.
|
||||
void ModFileWriter::Write(const Symbol &symbol) {
|
||||
auto *ancestor{symbol.get<ModuleDetails>().ancestor()};
|
||||
auto ancestorName{ancestor ? ancestor->name().ToString() : ""s};
|
||||
auto ancestorName{ancestor ? ancestor->GetName().value().ToString() : ""s};
|
||||
auto path{ModFilePath(context_.moduleDirectory(), symbol.name(), ancestorName,
|
||||
context_.moduleFileSuffix())};
|
||||
PutSymbols(*symbol.scope());
|
||||
|
@ -680,7 +680,7 @@ Scope *ModFileReader::Read(const SourceName &name, Scope *ancestor) {
|
|||
if (auto *scope{ancestor->FindSubmodule(name)}) {
|
||||
return scope;
|
||||
}
|
||||
ancestorName = ancestor->name().ToString();
|
||||
ancestorName = ancestor->GetName().value().ToString();
|
||||
} else {
|
||||
auto it{context_.globalScope().find(name)};
|
||||
if (it != context_.globalScope().end()) {
|
||||
|
|
|
@ -1968,7 +1968,7 @@ ModuleVisitor::SymbolRename ModuleVisitor::AddUse(
|
|||
IsDefinedOperator(useName)
|
||||
? "Operator '%s' not found in module '%s'"_err_en_US
|
||||
: "'%s' not found in module '%s'"_err_en_US,
|
||||
useName, useModuleScope_->name());
|
||||
useName, useModuleScope_->GetName().value());
|
||||
return {};
|
||||
}
|
||||
if (useSymbol->attrs().test(Attr::PRIVATE)) {
|
||||
|
@ -1976,7 +1976,7 @@ ModuleVisitor::SymbolRename ModuleVisitor::AddUse(
|
|||
IsDefinedOperator(useName)
|
||||
? "Operator '%s' is PRIVATE in '%s'"_err_en_US
|
||||
: "'%s' is PRIVATE in '%s'"_err_en_US,
|
||||
useName, useModuleScope_->name());
|
||||
useName, useModuleScope_->GetName().value());
|
||||
return {};
|
||||
}
|
||||
auto &localSymbol{MakeSymbol(localName)};
|
||||
|
@ -2583,7 +2583,7 @@ bool DeclarationVisitor::CheckUseError(const parser::Name &name) {
|
|||
Message &msg{Say(name, "Reference to '%s' is ambiguous"_err_en_US)};
|
||||
for (const auto &[location, module] : details->occurrences()) {
|
||||
msg.Attach(location, "'%s' was use-associated from module '%s'"_en_US,
|
||||
name.source, module->name());
|
||||
name.source, module->GetName().value());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2620,7 +2620,7 @@ bool DeclarationVisitor::CheckAccessibleComponent(
|
|||
}
|
||||
Say(name,
|
||||
"PRIVATE component '%s' is only accessible within module '%s'"_err_en_US,
|
||||
name.ToString(), moduleScope->name());
|
||||
name.ToString(), moduleScope->GetName().value());
|
||||
} else {
|
||||
Say(name,
|
||||
"PRIVATE component '%s' is only accessible within its module"_err_en_US,
|
||||
|
@ -5303,7 +5303,8 @@ void ResolveNamesVisitor::CheckImports() {
|
|||
// C8102: all entities in host must not be hidden
|
||||
for (const auto &pair : scope.parent()) {
|
||||
auto &name{pair.first};
|
||||
if (!scope.GetSymbol() || name != scope.name()) {
|
||||
std::optional<SourceName> scopeName{scope.GetName()};
|
||||
if (!scopeName.has_value() || name != *scopeName) {
|
||||
CheckImport(prevImportStmt_.value(), name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,9 +89,13 @@ public:
|
|||
const Symbol *GetSymbol() const;
|
||||
const Scope *GetDerivedTypeParent() const;
|
||||
|
||||
// It is only safe to call name() for kind of scopes for which GetSymbol
|
||||
// will return a symbol (e.g, it will die if the scope is a Block).
|
||||
const SourceName &name() const { return DEREF(GetSymbol()).name(); }
|
||||
std::optional<SourceName> GetName() const {
|
||||
if (const auto *sym{GetSymbol()}) {
|
||||
return sym->name();
|
||||
} else {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
/// Make a scope nested in this one
|
||||
Scope &MakeScope(Kind kind, Symbol *symbol = nullptr);
|
||||
|
|
|
@ -392,10 +392,10 @@ std::ostream &operator<<(std::ostream &os, const Details &details) {
|
|||
if (x.isSubmodule()) {
|
||||
os << " (";
|
||||
if (x.ancestor()) {
|
||||
auto &ancestor{x.ancestor()->name()};
|
||||
auto ancestor{x.ancestor()->GetName().value()};
|
||||
os << ancestor;
|
||||
if (x.parent()) {
|
||||
auto &parent{x.parent()->name()};
|
||||
auto parent{x.parent()->GetName().value()};
|
||||
if (ancestor != parent) {
|
||||
os << ':' << parent;
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ std::ostream &operator<<(std::ostream &os, const Details &details) {
|
|||
[&](const UseErrorDetails &x) {
|
||||
os << " uses:";
|
||||
for (const auto &[location, module] : x.occurrences()) {
|
||||
os << " from " << module->name() << " at " << location;
|
||||
os << " from " << module->GetName().value() << " at " << location;
|
||||
}
|
||||
},
|
||||
[](const HostAssocDetails &) {},
|
||||
|
|
|
@ -367,7 +367,7 @@ bool IsDerivedTypeFromModule(
|
|||
} else {
|
||||
const auto &symbol{derived->typeSymbol()};
|
||||
return symbol.name() == name && symbol.owner().IsModule() &&
|
||||
symbol.owner().name() == module;
|
||||
symbol.owner().GetName().value() == module;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue