From 7400a287a16ba99e911b0153d2797946e2faffcf Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Tue, 17 Jul 2018 07:02:30 -0700 Subject: [PATCH] [flang] Use brace initialization in lib/semantics Syntax only, no functional changes. Original-commit: flang-compiler/f18@8cc9743c9cddbda0d93cb171d623277715c3c7e2 Reviewed-on: https://github.com/flang-compiler/f18/pull/127 Tree-same-pre-rewrite: false --- flang/lib/semantics/mod-file.cc | 3 +- flang/lib/semantics/resolve-names.cc | 245 +++++++++++----------- flang/lib/semantics/rewrite-parse-tree.cc | 16 +- flang/lib/semantics/scope.cc | 11 +- flang/lib/semantics/symbol.cc | 14 +- flang/lib/semantics/symbol.h | 2 +- flang/lib/semantics/type.cc | 6 +- flang/lib/semantics/type.h | 2 +- 8 files changed, 149 insertions(+), 150 deletions(-) diff --git a/flang/lib/semantics/mod-file.cc b/flang/lib/semantics/mod-file.cc index 0b2c848c7193..b0ef08a12245 100644 --- a/flang/lib/semantics/mod-file.cc +++ b/flang/lib/semantics/mod-file.cc @@ -268,7 +268,8 @@ void ModFileWriter::PutUse(const Symbol &symbol) { // We have "USE local => use" in this module. If attr was added locally // (i.e. on local but not on use), also write it out in the mod file. -void ModFileWriter::PutUseExtraAttr(Attr attr, const Symbol &local, const Symbol &use) { +void ModFileWriter::PutUseExtraAttr( + Attr attr, const Symbol &local, const Symbol &use) { if (local.attrs().test(attr) && !use.attrs().test(attr)) { PutLower(useExtraAttrs_, AttrToString(attr)) << "::"; PutLower(useExtraAttrs_, local) << '\n'; diff --git a/flang/lib/semantics/resolve-names.cc b/flang/lib/semantics/resolve-names.cc index c08bf2e6c654..446d8b6e6e72 100644 --- a/flang/lib/semantics/resolve-names.cc +++ b/flang/lib/semantics/resolve-names.cc @@ -308,18 +308,18 @@ public: Symbol &MakeSymbol(const SourceName &name, const Attrs &attrs, D &&details) { // Note: don't use FindSymbol here. If this is a derived type scope, // we want to detect if the name is already declared as a component. - const auto &it = CurrScope().find(name); + const auto &it{CurrScope().find(name)}; if (it == CurrScope().end()) { - const auto pair = CurrScope().try_emplace(name, attrs, details); + const auto pair{CurrScope().try_emplace(name, attrs, details)}; CHECK(pair.second); // name was not found, so must be able to add return *pair.first->second; } - auto &symbol = *it->second; + auto &symbol{*it->second}; symbol.add_occurrence(name); if (std::is_same::value) { - if (auto *d = symbol.detailsIf()) { + if (auto *d{symbol.detailsIf()}) { // derived type with same name as a generic - auto *derivedType = d->derivedType(); + auto *derivedType{d->derivedType()}; if (!derivedType) { derivedType = &CurrScope().MakeSymbol(name, attrs, details); d->set_derivedType(*derivedType); @@ -549,7 +549,7 @@ private: Symbol &symbol{MakeSymbol(name.source, attrs)}; if (symbol.has()) { symbol.set_details(T{}); - } else if (auto *details = symbol.detailsIf()) { + } else if (auto *details{symbol.detailsIf()}) { if (!std::is_same::value) { symbol.set_details(T(*details)); } @@ -564,7 +564,7 @@ private: Say(name.source, "'%s' is use-associated from module '%s' and cannot be re-declared"_err_en_US, name.source, details->module().name()); - } else if (auto *details = symbol.detailsIf()) { + } else if (auto *details{symbol.detailsIf()}) { if (details->kind() == SubprogramKind::Module) { Say2(name.source, "Declaration of '%s' conflicts with its use as module procedure"_err_en_US, @@ -646,7 +646,7 @@ private: ImplicitRules::ImplicitRules(MessageHandler &messages) : messages_{messages} {} std::optional ImplicitRules::GetType(char ch) const { - auto it = map_.find(ch); + auto it{map_.find(ch)}; if (it != map_.end()) { return it->second; } else if (ch >= 'i' && ch <= 'n') { @@ -663,7 +663,7 @@ std::optional ImplicitRules::GetType(char ch) const { void ImplicitRules::SetType(const DeclTypeSpec &type, parser::Location lo, parser::Location hi, bool isDefault) { for (char ch = *lo; ch; ch = ImplicitRules::Incr(ch)) { - auto res = map_.emplace(ch, type); + auto res{map_.emplace(ch, type)}; if (!res.second && !isDefault) { messages_.Say(lo, "More than one implicit type specified for '%s'"_err_en_US, @@ -676,21 +676,21 @@ void ImplicitRules::SetType(const DeclTypeSpec &type, parser::Location lo, } const Symbol *DeclarationVisitor::ResolveDerivedType(const SourceName &name) { - auto *symbol = FindSymbol(name); + auto *symbol{FindSymbol(name)}; if (!symbol) { Say(name, "Derived type '%s' not found"_err_en_US); return nullptr; } - if (auto *details = symbol->detailsIf()) { + if (auto *details{symbol->detailsIf()}) { const Symbol &useSymbol = details->symbol(); - if (const auto *details = useSymbol.detailsIf()) { + if (const auto *details{useSymbol.detailsIf()}) { if (details->derivedType()) { return details->derivedType(); } } return &useSymbol; } - if (auto *details = symbol->detailsIf()) { + if (auto *details{symbol->detailsIf()}) { if (details->derivedType()) { symbol->remove_occurrence(name); symbol = details->derivedType(); @@ -728,7 +728,7 @@ std::ostream &operator<<(std::ostream &o, const ImplicitRules &implicitRules) { } void ShowImplicitRule( std::ostream &o, const ImplicitRules &implicitRules, char ch) { - auto it = implicitRules.map_.find(ch); + auto it{implicitRules.map_.find(ch)}; if (it != implicitRules.map_.end()) { o << " " << ch << ": " << it->second << '\n'; } @@ -888,10 +888,10 @@ void DeclTypeSpecVisitor::SetDeclTypeSpec(const DeclTypeSpec &declTypeSpec) { KindParamValue DeclTypeSpecVisitor::GetKindParamValue( const std::optional &kind) { if (kind) { - if (auto *intExpr = std::get_if(&kind->u)) { + if (auto *intExpr{std::get_if(&kind->u)}) { const parser::Expr &expr{*intExpr->thing.thing.thing}; - if (auto *lit = std::get_if(&expr.u)) { - if (auto *intLit = std::get_if(&lit->u)) { + if (auto *lit{std::get_if(&expr.u)}) { + if (auto *intLit{std::get_if(&lit->u)}) { return KindParamValue{ IntConst::Make(std::get(intLit->t))}; } @@ -969,9 +969,9 @@ bool ImplicitRulesVisitor::Pre(const parser::ImplicitStmt &x) { } bool ImplicitRulesVisitor::Pre(const parser::LetterSpec &x) { - auto loLoc = std::get(x.t); - auto hiLoc = loLoc; - if (auto hiLocOpt = std::get>(x.t)) { + auto loLoc{std::get(x.t)}; + auto hiLoc{loLoc}; + if (auto hiLocOpt{std::get>(x.t)}) { hiLoc = *hiLocOpt; if (*hiLoc < *loLoc) { Say(hiLoc, "'%s' does not follow '%s' alphabetically"_err_en_US, @@ -1074,22 +1074,22 @@ bool ArraySpecVisitor::Pre(const parser::DeferredShapeSpecList &x) { } bool ArraySpecVisitor::Pre(const parser::AssumedShapeSpec &x) { - const auto &lb = x.v; + const auto &lb{x.v}; arraySpec_.push_back( lb ? ShapeSpec::MakeAssumed(GetBound(*lb)) : ShapeSpec::MakeAssumed()); return false; } bool ArraySpecVisitor::Pre(const parser::ExplicitShapeSpec &x) { - const auto &lb = std::get>(x.t); - const auto &ub = GetBound(std::get(x.t)); + const auto &lb{std::get>(x.t)}; + const auto &ub{GetBound(std::get(x.t))}; arraySpec_.push_back(lb ? ShapeSpec::MakeExplicit(GetBound(*lb), ub) : ShapeSpec::MakeExplicit(ub)); return false; } bool ArraySpecVisitor::Pre(const parser::AssumedImpliedSpec &x) { - const auto &lb = x.v; + const auto &lb{x.v}; arraySpec_.push_back( lb ? ShapeSpec::MakeImplied(GetBound(*lb)) : ShapeSpec::MakeImplied()); return false; @@ -1128,7 +1128,7 @@ Bound ArraySpecVisitor::GetBound(const parser::SpecificationExpr &x) { // ScopeHandler implementation Scope &ScopeHandler::CurrNonTypeScope() { - auto &scope = CurrScope(); + auto &scope{CurrScope()}; return scope.kind() == Scope::Kind::DerivedType ? scope.parent() : scope; } Scope &ScopeHandler::PushScope(Scope::Kind kind, Symbol *symbol) { @@ -1147,7 +1147,7 @@ void ScopeHandler::PopScope() { Symbol *ScopeHandler::FindSymbol(const SourceName &name) { Scope &scope{CurrNonTypeScope()}; - const auto &it = scope.find(name); + const auto &it{scope.find(name)}; if (it == scope.end()) { return nullptr; } else { @@ -1164,9 +1164,9 @@ void ScopeHandler::ApplyImplicitRules(const SourceName &name, Symbol &symbol) { } else if (symbol.has()) { symbol.set_details(ObjectEntityDetails(symbol.get())); } - if (auto *details = symbol.detailsIf()) { + if (auto *details{symbol.detailsIf()}) { if (!details->type()) { - if (const auto type = GetImplicitType(symbol)) { + if (const auto type{GetImplicitType(symbol)}) { details->set_type(*type); } } @@ -1174,8 +1174,8 @@ void ScopeHandler::ApplyImplicitRules(const SourceName &name, Symbol &symbol) { } std::optional ScopeHandler::GetImplicitType( Symbol &symbol) { - auto &name = symbol.name(); - const auto type = implicitRules().GetType(name.begin()[0]); + auto &name{symbol.name()}; + const auto type{implicitRules().GetType(name.begin()[0])}; if (type) { symbol.set(Symbol::Flag::Implicit); } else { @@ -1221,12 +1221,12 @@ bool ModuleVisitor::Pre(const parser::Rename::Names &x) { // Set useModuleScope_ to the Scope of the module being used. bool ModuleVisitor::Pre(const parser::UseStmt &x) { // x.nature = UseStmt::ModuleNature::Intrinsic or Non_Intrinsic - const auto it = Scope::globalScope.find(x.moduleName.source); + const auto it{Scope::globalScope.find(x.moduleName.source)}; if (it == Scope::globalScope.end()) { Say(x.moduleName, "Module '%s' not found"_err_en_US); return false; } - const auto *details = it->second->detailsIf(); + const auto *details{it->second->detailsIf()}; if (!details) { Say(x.moduleName, "'%s' is not a module"_err_en_US); return false; @@ -1236,7 +1236,7 @@ bool ModuleVisitor::Pre(const parser::UseStmt &x) { return true; } void ModuleVisitor::Post(const parser::UseStmt &x) { - if (const auto *list = std::get_if>(&x.u)) { + if (const auto *list{std::get_if>(&x.u)}) { // Not a use-only: collect the names that were used in renames, // then add a use for each public name that was not renamed. std::set useNames; @@ -1280,7 +1280,7 @@ void ModuleVisitor::AddUse(const SourceName &location, if (!useModuleScope_) { return; // error occurred finding module } - const auto it = useModuleScope_->find(useName); + const auto it{useModuleScope_->find(useName)}; if (it == useModuleScope_->end()) { Say(useName, "'%s' not found in module '%s'"_err_en_US, useName, useModuleScope_->name()); @@ -1295,13 +1295,13 @@ void ModuleVisitor::AddUse(const SourceName &location, Symbol &localSymbol{MakeSymbol(localName, useSymbol.attrs())}; localSymbol.attrs() &= ~Attrs{Attr::PUBLIC, Attr::PRIVATE}; localSymbol.flags() |= useSymbol.flags(); - if (auto *details = localSymbol.detailsIf()) { + if (auto *details{localSymbol.detailsIf()}) { // check for importing the same symbol again: if (localSymbol.GetUltimate() != useSymbol.GetUltimate()) { localSymbol.set_details( UseErrorDetails{details->location(), *useModuleScope_}); } - } else if (auto *details = localSymbol.detailsIf()) { + } else if (auto *details{localSymbol.detailsIf()}) { details->add_occurrence(location, *useModuleScope_); } else if (localSymbol.has()) { localSymbol.set_details(UseDetails{location, useSymbol}); @@ -1313,16 +1313,16 @@ void ModuleVisitor::AddUse(const SourceName &location, bool ModuleVisitor::Pre(const parser::Module &x) { // Make a symbol and push a scope for this module - const auto &name = - std::get>(x.t).statement.v; - auto &symbol = MakeSymbol(name, ModuleDetails{}); + const auto &name{ + std::get>(x.t).statement.v}; + auto &symbol{MakeSymbol(name, ModuleDetails{})}; ModuleDetails &details{symbol.get()}; Scope &modScope{PushScope(Scope::Kind::Module, &symbol)}; details.set_scope(&modScope); MakeSymbol(name, ModuleDetails{details}); // collect module subprogram names - if (const auto &subpPart = - std::get>(x.t)) { + if (const auto &subpPart{ + std::get>(x.t)}) { subpNamesOnly_ = SubprogramKind::Module; parser::Walk(*subpPart, *static_cast(this)); subpNamesOnly_ = std::nullopt; @@ -1356,8 +1356,8 @@ void InterfaceVisitor::Post(const parser::InterfaceStmt &) {} void InterfaceVisitor::Post(const parser::EndInterfaceStmt &) { if (genericSymbol_) { - if (const auto *proc = - genericSymbol_->get().CheckSpecific()) { + if (const auto *proc{ + genericSymbol_->get().CheckSpecific()}) { SayAlreadyDeclared(genericSymbol_->name(), *proc); } genericSymbol_ = nullptr; @@ -1399,10 +1399,9 @@ bool InterfaceVisitor::Pre(const parser::GenericSpec &x) { const Symbol &ultimate{genericSymbol_->GetUltimate()}; EraseSymbol(*genericName); genericSymbol_ = &MakeSymbol(ultimate.name(), ultimate.attrs()); - if (const auto *details = ultimate.detailsIf()) { + if (const auto *details{ultimate.detailsIf()}) { genericSymbol_->set_details(GenericDetails{details->specificProcs()}); - } else if (const auto *details = - ultimate.detailsIf()) { + } else if (const auto *details{ultimate.detailsIf()}) { genericSymbol_->set_details(SubprogramDetails{*details}); } else { CHECK(!"can't happen"); @@ -1418,9 +1417,9 @@ bool InterfaceVisitor::Pre(const parser::GenericSpec &x) { } else if (genericSymbol_->has() || genericSymbol_->has()) { Details details; - if (auto *d = genericSymbol_->detailsIf()) { + if (auto *d{genericSymbol_->detailsIf()}) { details = *d; - } else if (auto *d = genericSymbol_->detailsIf()) { + } else if (auto *d{genericSymbol_->detailsIf()}) { details = *d; } else { CHECK(!"can't happen"); @@ -1455,7 +1454,7 @@ bool InterfaceVisitor::Pre(const parser::ProcedureStmt &x) { } void InterfaceVisitor::Post(const parser::GenericStmt &x) { - if (auto &accessSpec = std::get>(x.t)) { + if (auto &accessSpec{std::get>(x.t)}) { genericSymbol_->attrs().set(AccessSpecToAttr(*accessSpec)); } for (const auto &name : std::get>(x.t)) { @@ -1465,13 +1464,13 @@ void InterfaceVisitor::Post(const parser::GenericStmt &x) { void InterfaceVisitor::AddToGeneric( const parser::Name &name, bool expectModuleProc) { - const auto *symbol = FindSymbol(name.source); + const auto *symbol{FindSymbol(name.source)}; if (!symbol) { Say(name, "Procedure '%s' not found"_err_en_US); return; } if (symbol == genericSymbol_) { - if (auto *specific = genericSymbol_->get().specific()) { + if (auto *specific{genericSymbol_->get().specific()}) { symbol = specific; } } @@ -1481,7 +1480,7 @@ void InterfaceVisitor::AddToGeneric( return; } if (expectModuleProc) { - const auto *details = symbol->detailsIf(); + const auto *details{symbol->detailsIf()}; if (!details || details->kind() != SubprogramKind::Module) { Say(name, "'%s' is not a module procedure"_en_US); } @@ -1534,12 +1533,12 @@ void InterfaceVisitor::CheckGenericProcedures(Symbol &generic) { // SubprogramVisitor implementation bool SubprogramVisitor::Pre(const parser::StmtFunctionStmt &x) { - const auto &name = std::get(x.t); + const auto &name{std::get(x.t)}; std::optional occurrence; std::optional resultType; // Look up name: provides return type or tells us if it's an array - if (auto *symbol = FindSymbol(name.source)) { - if (auto *details = symbol->detailsIf()) { + if (auto *symbol{FindSymbol(name.source)}) { + if (auto *details{symbol->detailsIf()}) { // TODO: check that attrs are compatible with stmt func resultType = details->type(); occurrence = symbol->name(); @@ -1555,17 +1554,17 @@ bool SubprogramVisitor::Pre(const parser::StmtFunctionStmt &x) { Say(name, "'%s' has not been declared as an array"_err_en_US); return true; } - auto &symbol = PushSubprogramScope(name, Symbol::Flag::Function); + auto &symbol{PushSubprogramScope(name, Symbol::Flag::Function)}; CopyImplicitRules(); if (occurrence) { symbol.add_occurrence(*occurrence); } - auto &details = symbol.get(); + auto &details{symbol.get()}; for (const auto &dummyName : std::get>(x.t)) { EntityDetails dummyDetails{true}; - auto it = CurrScope().parent().find(dummyName.source); + auto it{CurrScope().parent().find(dummyName.source)}; if (it != CurrScope().parent().end()) { - if (auto *d = it->second->detailsIf()) { + if (auto *d{it->second->detailsIf()}) { if (d->type()) { dummyDetails.set_type(*d->type()); } @@ -1597,10 +1596,10 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) { } bool SubprogramVisitor::Pre(const parser::SubroutineSubprogram &x) { - const auto &name = std::get( - std::get>(x.t).statement.t); - const auto &subpPart = - std::get>(x.t); + const auto &name{std::get( + std::get>(x.t).statement.t)}; + const auto &subpPart{ + std::get>(x.t)}; return BeginSubprogram(name, Symbol::Flag::Subroutine, subpPart); } void SubprogramVisitor::Post(const parser::SubroutineSubprogram &) { @@ -1608,10 +1607,10 @@ void SubprogramVisitor::Post(const parser::SubroutineSubprogram &) { } bool SubprogramVisitor::Pre(const parser::FunctionSubprogram &x) { - const auto &name = std::get( - std::get>(x.t).statement.t); - const auto &subpPart = - std::get>(x.t); + const auto &name{std::get( + std::get>(x.t).statement.t)}; + const auto &subpPart{ + std::get>(x.t)}; return BeginSubprogram(name, Symbol::Flag::Function, subpPart); } void SubprogramVisitor::Post(const parser::FunctionSubprogram &) { @@ -1619,16 +1618,16 @@ void SubprogramVisitor::Post(const parser::FunctionSubprogram &) { } bool SubprogramVisitor::Pre(const parser::InterfaceBody::Subroutine &x) { - const auto &name = std::get( - std::get>(x.t).statement.t); + const auto &name{std::get( + std::get>(x.t).statement.t)}; return BeginSubprogram(name, Symbol::Flag::Subroutine, std::nullopt); } void SubprogramVisitor::Post(const parser::InterfaceBody::Subroutine &) { EndSubprogram(); } bool SubprogramVisitor::Pre(const parser::InterfaceBody::Function &x) { - const auto &name = std::get( - std::get>(x.t).statement.t); + const auto &name{std::get( + std::get>(x.t).statement.t)}; return BeginSubprogram(name, Symbol::Flag::Function, std::nullopt); } void SubprogramVisitor::Post(const parser::InterfaceBody::Function &) { @@ -1649,11 +1648,11 @@ bool SubprogramVisitor::Pre(const parser::FunctionStmt &stmt) { } void SubprogramVisitor::Post(const parser::SubroutineStmt &stmt) { - const auto &name = std::get(stmt.t); + const auto &name{std::get(stmt.t)}; Symbol &symbol{*CurrScope().symbol()}; CHECK(name.source == symbol.name()); symbol.attrs() |= EndAttrs(); - auto &details = symbol.get(); + auto &details{symbol.get()}; for (const auto &dummyArg : std::get>(stmt.t)) { const parser::Name *dummyName = std::get_if(&dummyArg.u); CHECK(dummyName != nullptr && "TODO: alternate return indicator"); @@ -1663,18 +1662,18 @@ void SubprogramVisitor::Post(const parser::SubroutineStmt &stmt) { } void SubprogramVisitor::Post(const parser::FunctionStmt &stmt) { - const auto &name = std::get(stmt.t); + const auto &name{std::get(stmt.t)}; Symbol &symbol{*CurrScope().symbol()}; CHECK(name.source == symbol.name()); symbol.attrs() |= EndAttrs(); - auto &details = symbol.get(); + auto &details{symbol.get()}; for (const auto &dummyName : std::get>(stmt.t)) { Symbol &dummy{MakeSymbol(dummyName, EntityDetails(true))}; details.add_dummyArg(dummy); } // add function result to function scope EntityDetails funcResultDetails; - if (auto &type = GetDeclTypeSpec()) { + if (auto &type{GetDeclTypeSpec()}) { funcResultDetails.set_type(*type); } EndDeclTypeSpec(); @@ -1694,7 +1693,7 @@ bool SubprogramVisitor::BeginSubprogram(const parser::Name &name, Symbol::Flag subpFlag, const std::optional &subpPart) { if (subpNamesOnly_) { - auto &symbol = MakeSymbol(name, SubprogramNameDetails{*subpNamesOnly_}); + auto &symbol{MakeSymbol(name, SubprogramNameDetails{*subpNamesOnly_})}; symbol.set(subpFlag); return false; } @@ -1719,7 +1718,7 @@ Symbol &SubprogramVisitor::PushSubprogramScope( symbol = &MakeSymbol(name, SubprogramDetails{}); symbol->set(subpFlag); } - auto &details = symbol->get(); + auto &details{symbol->get()}; if (inInterfaceBlock()) { details.set_isInterface(); if (!isAbstract()) { @@ -1738,9 +1737,9 @@ Symbol &SubprogramVisitor::PushSubprogramScope( // If name is a generic, return specific subprogram with the same name. Symbol *SubprogramVisitor::GetSpecificFromGeneric(const SourceName &name) { if (Symbol *symbol = FindSymbol(name)) { - if (auto *details = symbol->detailsIf()) { + if (auto *details{symbol->detailsIf()}) { // found generic, want subprogram - auto *specific = details->specific(); + auto *specific{details->specific()}; if (isGeneric()) { if (specific) { SayAlreadyDeclared(name, *specific); @@ -1777,7 +1776,7 @@ void DeclarationVisitor::EndDecl() { } void DeclarationVisitor::Post(const parser::DimensionStmt::Declaration &x) { - const auto &name = std::get(x.t); + const auto &name{std::get(x.t)}; DeclareObjectEntity(name, Attrs{}); } @@ -1790,7 +1789,7 @@ void DeclarationVisitor::Post(const parser::EntityDecl &x) { DeclareObjectEntity(name, attrs); } else { Symbol &symbol{DeclareEntity(name, attrs)}; - if (auto &type = GetDeclTypeSpec()) { + if (auto &type{GetDeclTypeSpec()}) { SetType(name.source, symbol, *type); } } @@ -1805,12 +1804,12 @@ bool DeclarationVisitor::Pre(const parser::ContiguousStmt &x) { bool DeclarationVisitor::Pre(const parser::ExternalStmt &x) { HandleAttributeStmt(Attr::EXTERNAL, x.v); for (const auto &name : x.v) { - auto *symbol = FindSymbol(name.source); + auto *symbol{FindSymbol(name.source)}; if (symbol->has()) { // nothing to do } else if (symbol->has()) { symbol->set_details(ProcEntityDetails{}); - } else if (auto *details = symbol->detailsIf()) { + } else if (auto *details{symbol->detailsIf()}) { symbol->set_details(ProcEntityDetails(*details)); symbol->set(Symbol::Flag::Function); } else { @@ -1843,7 +1842,7 @@ bool DeclarationVisitor::Pre(const parser::VolatileStmt &x) { bool DeclarationVisitor::HandleAttributeStmt( Attr attr, const std::list &names) { for (const auto &name : names) { - const auto pair = CurrScope().try_emplace(name.source, Attrs{attr}); + const auto pair{CurrScope().try_emplace(name.source, Attrs{attr})}; if (!pair.second) { // symbol was already there: set attribute on it Symbol &symbol{*pair.first->second}; @@ -1862,14 +1861,14 @@ bool DeclarationVisitor::HandleAttributeStmt( void DeclarationVisitor::Post(const parser::ObjectDecl &x) { CHECK(objectDeclAttr_.has_value()); - const auto &name = std::get(x.t); + const auto &name{std::get(x.t)}; DeclareObjectEntity(name, Attrs{*objectDeclAttr_}); } void DeclarationVisitor::DeclareProcEntity( const parser::Name &name, Attrs attrs, ProcInterface &&interface) { Symbol &symbol{DeclareEntity(name, attrs)}; - if (auto *details = symbol.detailsIf()) { + if (auto *details{symbol.detailsIf()}) { if (interface.type()) { symbol.set(Symbol::Flag::Function); } else if (interface.symbol()) { @@ -1885,8 +1884,8 @@ void DeclarationVisitor::DeclareProcEntity( void DeclarationVisitor::DeclareObjectEntity( const parser::Name &name, Attrs attrs) { Symbol &symbol{DeclareEntity(name, attrs)}; - if (auto *details = symbol.detailsIf()) { - if (auto &type = GetDeclTypeSpec()) { + if (auto *details{symbol.detailsIf()}) { + if (auto &type{GetDeclTypeSpec()}) { if (details->type()) { Say(name, "The type of '%s' has already been declared"_err_en_US); } else { @@ -1908,7 +1907,7 @@ void DeclarationVisitor::DeclareObjectEntity( void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &x) { SetDerivedDeclTypeSpec(DeclTypeSpec::TypeDerived); DerivedTypeSpec &type{GetDeclTypeSpec()->derivedTypeSpec()}; - if (const auto *symbol = ResolveDerivedType(type.name())) { + if (const auto *symbol{ResolveDerivedType(type.name())}) { if (!symbol->has()) { Say(type.name(), "'%s' is not a derived type"_err_en_US); return; @@ -1917,8 +1916,8 @@ void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &x) { } } bool DeclarationVisitor::Pre(const parser::DerivedTypeSpec &x) { - auto &name = std::get(x.t).source; - auto &derivedTypeSpec = CurrScope().MakeDerivedTypeSpec(name); + auto &name{std::get(x.t).source}; + auto &derivedTypeSpec{CurrScope().MakeDerivedTypeSpec(name)}; BeginDerivedTypeSpec(derivedTypeSpec); return true; } @@ -1935,8 +1934,8 @@ bool DeclarationVisitor::Pre(const parser::DerivedTypeStmt &x) { return true; } void DeclarationVisitor::Post(const parser::DerivedTypeStmt &x) { - auto &name = std::get(x.t).source; - auto &symbol = MakeSymbol(name, GetAttrs(), DerivedTypeDetails{}); + auto &name{std::get(x.t).source}; + auto &symbol{MakeSymbol(name, GetAttrs(), DerivedTypeDetails{})}; PushScope(Scope::Kind::DerivedType, &symbol); EndAttrs(); } @@ -1957,7 +1956,7 @@ bool DeclarationVisitor::Pre(const parser::SequenceStmt &x) { return false; } void DeclarationVisitor::Post(const parser::ComponentDecl &x) { - const auto &name = std::get(x.t); + const auto &name{std::get(x.t)}; DeclareObjectEntity(name, GetAttrs()); ClearArraySpec(); } @@ -1977,16 +1976,16 @@ void DeclarationVisitor::Post(const parser::ProcComponentDefStmt &) { interfaceName_ = nullptr; } void DeclarationVisitor::Post(const parser::ProcInterface &x) { - if (auto *name = std::get_if(&x.u)) { + if (auto *name{std::get_if(&x.u)}) { interfaceName_ = &name->source; } } void DeclarationVisitor::Post(const parser::ProcDecl &x) { - const auto &name = std::get(x.t); + const auto &name{std::get(x.t)}; ProcInterface interface; if (interfaceName_) { - auto *symbol = FindSymbol(*interfaceName_); + auto *symbol{FindSymbol(*interfaceName_)}; if (!symbol) { Say(*interfaceName_, "Explicit interface '%s' not found"_err_en_US); } else if (!symbol->HasExplicitInterface()) { @@ -1996,7 +1995,7 @@ void DeclarationVisitor::Post(const parser::ProcDecl &x) { } else { interface.set_symbol(*symbol); } - } else if (auto &type = GetDeclTypeSpec()) { + } else if (auto &type{GetDeclTypeSpec()}) { interface.set_type(*type); } if (derivedTypeData_) { @@ -2064,7 +2063,7 @@ void ResolveNamesVisitor::Post(const parser::CallStmt &) { bool ResolveNamesVisitor::CheckUseError( const SourceName &name, const Symbol &symbol) { - const auto *details = symbol.detailsIf(); + const auto *details{symbol.detailsIf()}; if (!details) { return false; } @@ -2094,7 +2093,7 @@ const Symbol *ResolveNamesVisitor::ResolveDataRef(const parser::DataRef &x) { return std::visit( common::visitors{ [=](const parser::Name &y) { - auto *symbol = FindSymbol(y.source); + auto *symbol{FindSymbol(y.source)}; if (!symbol) { if (isImplicitNoneType()) { Say(y.source, "No explicit type declared for '%s'"_err_en_US); @@ -2119,9 +2118,9 @@ const Symbol *ResolveNamesVisitor::ResolveDataRef(const parser::DataRef &x) { const Symbol *ResolveNamesVisitor::FindComponent( const Symbol &base, const SourceName &component) { std::optional type; - if (auto *details = base.detailsIf()) { + if (auto *details{base.detailsIf()}) { type = details->type(); - } else if (auto *details = base.detailsIf()) { + } else if (auto *details{base.detailsIf()}) { type = details->type(); } else { Say2(base.occurrences().back(), @@ -2148,9 +2147,9 @@ const Symbol *ResolveNamesVisitor::FindComponent( if (!scope) { return nullptr; // previously failed to resolve type } - auto it = scope->find(component); + auto it{scope->find(component)}; if (it == scope->end()) { - auto &typeName = scope->symbol()->name(); + auto &typeName{scope->symbol()->name()}; Say(component, "Component '%s' not found in derived type '%s'"_err_en_US, component, typeName) .Attach(typeName, @@ -2164,7 +2163,7 @@ const Symbol *ResolveNamesVisitor::FindComponent( } void ResolveNamesVisitor::Post(const parser::ProcedureDesignator &x) { - if (const auto *name = std::get_if(&x.u)) { + if (const auto *name{std::get_if(&x.u)}) { auto *symbol{FindSymbol(name->source)}; if (symbol == nullptr) { symbol = &MakeSymbol(name->source); @@ -2175,7 +2174,7 @@ void ResolveNamesVisitor::Post(const parser::ProcedureDesignator &x) { } symbol->attrs().set(Attr::EXTERNAL); symbol->set_details(ProcEntityDetails{}); - if (const auto type = GetImplicitType(*symbol)) { + if (const auto type{GetImplicitType(*symbol)}) { symbol->get().interface().set_type(*type); } CHECK(expectedProcFlag_); @@ -2185,7 +2184,7 @@ void ResolveNamesVisitor::Post(const parser::ProcedureDesignator &x) { } else if (CheckUseError(name->source, *symbol)) { // error was reported } else { - if (auto *details = symbol->detailsIf()) { + if (auto *details{symbol->detailsIf()}) { symbol->set_details(ProcEntityDetails(*details)); symbol->set(Symbol::Flag::Function); } @@ -2222,7 +2221,7 @@ bool ModuleVisitor::Pre(const parser::AccessStmt &x) { EnumToString(accessAttr)); return false; } - const auto &accessIds = std::get>(x.t); + const auto &accessIds{std::get>(x.t)}; if (accessIds.empty()) { if (prevAccessStmt_) { Say("The default accessibility of this module has already been declared"_err_en_US) @@ -2272,11 +2271,11 @@ void ModuleVisitor::SetAccess(const parser::Name &name, Attr attr) { static bool NeedsExplicitType(const Symbol &symbol) { if (symbol.has()) { return true; - } else if (const auto *details = symbol.detailsIf()) { + } else if (const auto *details{symbol.detailsIf()}) { return !details->type(); - } else if (const auto *details = symbol.detailsIf()) { + } else if (const auto *details{symbol.detailsIf()}) { return !details->type(); - } else if (const auto *details = symbol.detailsIf()) { + } else if (const auto *details{symbol.detailsIf()}) { return details->interface().symbol() == nullptr && details->interface().type() == nullptr; } else { @@ -2335,8 +2334,8 @@ const parser::Name *ResolveNamesVisitor::GetVariableName( } const parser::Name *ResolveNamesVisitor::GetVariableName( const parser::Expr &x) { - if (const auto *designator = - std::get_if>(&x.u)) { + if (const auto *designator{ + std::get_if>(&x.u)}) { return GetVariableName(**designator); } else { return nullptr; @@ -2344,8 +2343,8 @@ const parser::Name *ResolveNamesVisitor::GetVariableName( } const parser::Name *ResolveNamesVisitor::GetVariableName( const parser::Variable &x) { - if (const auto *designator = - std::get_if>(&x.u)) { + if (const auto *designator{ + std::get_if>(&x.u)}) { return GetVariableName(**designator); } else { return nullptr; @@ -2359,7 +2358,7 @@ const Symbol *ResolveNamesVisitor::CheckImplicitSymbol( if (!name) { return nullptr; } - if (const auto *symbol = FindSymbol(name->source)) { + if (const auto *symbol{FindSymbol(name->source)}) { if (CheckUseError(name->source, *symbol) || !symbol->has()) { return nullptr; // reported an error or symbol is declared @@ -2372,9 +2371,9 @@ const Symbol *ResolveNamesVisitor::CheckImplicitSymbol( } // If we are in a derived type and need to create an implicit symbol // (e.g. an implied-do variable), it belongs in the enclosing scope. - auto pair = CurrNonTypeScope().try_emplace(name->source); + auto pair{CurrNonTypeScope().try_emplace(name->source)}; CHECK(pair.second); // name was not found, so must be able to add it - auto *symbol = pair.first->second; + auto *symbol{pair.first->second}; ApplyImplicitRules(name->source, *symbol); return symbol; } @@ -2487,17 +2486,17 @@ static void PutIndent(std::ostream &os, int indent) { static void DumpSymbols(std::ostream &os, const Scope &scope, int indent = 0) { PutIndent(os, indent); os << Scope::EnumToString(scope.kind()) << " scope:"; - if (const auto *symbol = scope.symbol()) { + if (const auto *symbol{scope.symbol()}) { os << ' ' << symbol->name().ToString(); } os << '\n'; ++indent; for (const auto &pair : scope) { - const auto &symbol = *pair.second; + const auto &symbol{*pair.second}; PutIndent(os, indent); os << symbol << '\n'; - if (const auto *details = symbol.detailsIf()) { - if (const auto &type = details->derivedType()) { + if (const auto *details{symbol.detailsIf()}) { + if (const auto &type{details->derivedType()}) { PutIndent(os, indent); os << *type << '\n'; } diff --git a/flang/lib/semantics/rewrite-parse-tree.cc b/flang/lib/semantics/rewrite-parse-tree.cc index 82fe17cb9b8c..5e9ee200882d 100644 --- a/flang/lib/semantics/rewrite-parse-tree.cc +++ b/flang/lib/semantics/rewrite-parse-tree.cc @@ -37,7 +37,7 @@ public: // Fill in name.symbol if there is a corresponding symbol void Post(parser::Name &name) { - const auto it = symbols_.find(name.source.begin()); + const auto it{symbols_.find(name.source.begin())}; if (it != symbols_.end()) { name.symbol = it->second; } @@ -48,9 +48,9 @@ public: // Find mis-parsed statement functions and move to stmtFuncsToConvert list. void Post(parser::SpecificationPart &x) { - auto &list = std::get>(x.t); - for (auto it = list.begin(); it != list.end();) { - if (auto stmt = std::get_if(&it->u)) { + auto &list{std::get>(x.t)}; + for (auto it{list.begin()}; it != list.end();) { + if (auto stmt{std::get_if(&it->u)}) { Symbol *symbol{std::get(stmt->statement->t).symbol}; if (symbol && symbol->has()) { // not a stmt func: remove it here and add to ones to convert @@ -65,7 +65,7 @@ public: // Insert converted assignments at start of ExecutionPart. bool Pre(parser::ExecutionPart &x) { - auto origFirst = x.v.begin(); // insert each elem before origFirst + auto origFirst{x.v.begin()}; // insert each elem before origFirst for (stmtFuncType &sf : stmtFuncsToConvert) { auto &&stmt = sf.statement->ConvertToAssignment(); stmt.source = sf.source; @@ -88,8 +88,8 @@ private: // should be an array element reference (i.e. the name occurs in an // entity declaration, convert it. template void ConvertFunctionRef(T &x) { - auto *funcRef = - std::get_if>(&x.u); + auto *funcRef{ + std::get_if>(&x.u)}; if (!funcRef) { return; } @@ -112,7 +112,7 @@ static void CollectSymbols(Scope &scope, symbolMap &symbols) { for (auto &pair : scope) { Symbol *symbol{pair.second}; CollectSymbol(*symbol, symbols); - if (auto *details = symbol->detailsIf()) { + if (auto *details{symbol->detailsIf()}) { if (details->derivedType()) { CollectSymbol(*details->derivedType(), symbols); } diff --git a/flang/lib/semantics/scope.cc b/flang/lib/semantics/scope.cc index 6f420226245f..22bea6952593 100644 --- a/flang/lib/semantics/scope.cc +++ b/flang/lib/semantics/scope.cc @@ -18,8 +18,7 @@ namespace Fortran::semantics { -Scope Scope::systemScope{ - Scope::systemScope, Scope::Kind::System, nullptr}; +Scope Scope::systemScope{Scope::systemScope, Scope::Kind::System, nullptr}; Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global, nullptr}; Symbols<1024> Scope::allSymbols; @@ -30,7 +29,7 @@ Scope &Scope::MakeScope(Kind kind, Symbol *symbol) { } Scope::iterator Scope::find(const SourceName &name) { - auto it = symbols_.find(name); + auto it{symbols_.find(name)}; if (it != end()) { it->second->add_occurrence(name); } @@ -40,7 +39,7 @@ Scope::const_iterator Scope::find(const SourceName &name) const { return symbols_.find(name); } Scope::size_type Scope::erase(const SourceName &name) { - auto it = symbols_.find(name); + auto it{symbols_.find(name)}; if (it != end()) { it->second->remove_occurrence(name); symbols_.erase(it); @@ -56,12 +55,12 @@ DerivedTypeSpec &Scope::MakeDerivedTypeSpec(const SourceName &name) { std::ostream &operator<<(std::ostream &os, const Scope &scope) { os << Scope::EnumToString(scope.kind()) << " scope: "; - if (auto *symbol = scope.symbol()) { + if (auto *symbol{scope.symbol()}) { os << *symbol << ' '; } os << scope.children_.size() << " children\n"; for (const auto &pair : scope.symbols_) { - const auto &symbol = pair.second; + const auto &symbol{pair.second}; os << " " << symbol << '\n'; } return os; diff --git a/flang/lib/semantics/symbol.cc b/flang/lib/semantics/symbol.cc index f0ee337088be..97968145f657 100644 --- a/flang/lib/semantics/symbol.cc +++ b/flang/lib/semantics/symbol.cc @@ -44,7 +44,7 @@ void ObjectEntityDetails::set_shape(const ArraySpec &shape) { } ProcEntityDetails::ProcEntityDetails(const EntityDetails &d) { - if (auto type = d.type()) { + if (auto type{d.type()}) { interface_.set_type(*type); } } @@ -137,8 +137,8 @@ void Symbol::add_occurrence(const SourceName &name) { } } void Symbol::remove_occurrence(const SourceName &name) { - auto end = occurrences_.end(); - for (auto it = occurrences_.begin(); it != end; ++it) { + auto end{occurrences_.end()}; + for (auto it{occurrences_.begin()}; it != end; ++it) { if (it->begin() == name.begin()) { occurrences_.erase(it); return; @@ -149,7 +149,7 @@ Symbol &Symbol::GetUltimate() { return const_cast(static_cast(this)->GetUltimate()); } const Symbol &Symbol::GetUltimate() const { - if (const auto *details = detailsIf()) { + if (const auto *details{detailsIf()}) { return details->symbol().GetUltimate(); } else { return *this; @@ -232,16 +232,16 @@ std::ostream &operator<<(std::ostream &os, const ObjectEntityDetails &x) { } bool ProcEntityDetails::HasExplicitInterface() const { - if (auto *symbol = interface_.symbol()) { + if (auto *symbol{interface_.symbol()}) { return symbol->HasExplicitInterface(); } return false; } std::ostream &operator<<(std::ostream &os, const ProcEntityDetails &x) { - if (auto *symbol = x.interface_.symbol()) { + if (auto *symbol{x.interface_.symbol()}) { os << ' ' << symbol->name().ToString(); - } else if (auto *type = x.interface_.type()) { + } else if (auto *type{x.interface_.type()}) { os << ' ' << *type; } return os; diff --git a/flang/lib/semantics/symbol.h b/flang/lib/semantics/symbol.h index 5c00fb4e26b8..d811aa10f603 100644 --- a/flang/lib/semantics/symbol.h +++ b/flang/lib/semantics/symbol.h @@ -254,7 +254,7 @@ public: return const_cast(static_cast(this)->get()); } template const D &get() const { - if (const auto p = detailsIf()) { + if (const auto p{detailsIf()}) { return *p; } else { common::die("unexpected %s details at %s(%d)", GetDetailsName().c_str(), diff --git a/flang/lib/semantics/type.cc b/flang/lib/semantics/type.cc index 12ec3aa6dc8c..c4999b6a3676 100644 --- a/flang/lib/semantics/type.cc +++ b/flang/lib/semantics/type.cc @@ -36,7 +36,7 @@ std::ostream &operator<<(std::ostream &o, const KindParamValue &x) { } const IntConst &IntConst::Make(std::uint64_t value) { - auto it = cache.find(value); + auto it{cache.find(value)}; if (it == cache.end()) { it = cache.insert({value, IntConst{value}}).first; } @@ -303,9 +303,9 @@ ProcComponentDef::ProcComponentDef( } std::ostream &operator<<(std::ostream &o, const ProcComponentDef &x) { o << "PROCEDURE("; - if (auto *symbol = x.interface_.symbol()) { + if (auto *symbol{x.interface_.symbol()}) { o << symbol->name().ToString(); - } else if (auto *type = x.interface_.type()) { + } else if (auto *type{x.interface_.type()}) { o << *type; } o << "), " << x.attrs_ << " :: " << x.decl_; diff --git a/flang/lib/semantics/type.h b/flang/lib/semantics/type.h index e901d0e690f7..5957f850f9e4 100644 --- a/flang/lib/semantics/type.h +++ b/flang/lib/semantics/type.h @@ -183,7 +183,7 @@ public: : name_{name}, defaultValue_{defaultValue} {} const T &Make() { return Make(defaultValue_); } const T &Make(KindParamValue kind) { - auto it = cache.find(kind); + auto it{cache.find(kind)}; if (it == cache.end()) { it = cache.insert(std::make_pair(kind, T{kind})).first; }