Skip to content

Commit 117d77e

Browse files
committed
code cleanup
1 parent f56f6c2 commit 117d77e

File tree

1 file changed

+45
-47
lines changed

1 file changed

+45
-47
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,8 +1852,7 @@ bool OmpVisitor::Pre(const parser::OmpMapClause &x) {
18521852
// TODO: Do we need a specific flag or type here, to distinghuish against
18531853
// other ConstructName things? Leaving this for the full implementation
18541854
// of mapper lowering.
1855-
const Symbol &ultimate{symbol->GetUltimate()};
1856-
auto *misc{const_cast<Symbol &>(ultimate).detailsIf<MiscDetails>()};
1855+
auto *misc{symbol->GetUltimate().detailsIf<MiscDetails>()};
18571856
if (!misc || misc->kind() != MiscDetails::Kind::ConstructName)
18581857
context().Say(mapper->v.source,
18591858
"Name '%s' should be a mapper name"_err_en_US, mapper->v.source);
@@ -2373,7 +2372,7 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
23732372
}
23742373
symbol.SetBindName(std::move(*label));
23752374
if (!oldBindName.empty()) {
2376-
if (const std::string * newBindName{symbol.GetBindName()}) {
2375+
if (const std::string *newBindName{symbol.GetBindName()}) {
23772376
if (oldBindName != *newBindName) {
23782377
Say(symbol.name(),
23792378
"The entity '%s' has multiple BIND names ('%s' and '%s')"_err_en_US,
@@ -2499,15 +2498,15 @@ void DeclTypeSpecVisitor::Post(const parser::TypeSpec &typeSpec) {
24992498
// expression semantics if the DeclTypeSpec is a valid TypeSpec.
25002499
// The grammar ensures that it's an intrinsic or derived type spec,
25012500
// not TYPE(*) or CLASS(*) or CLASS(T).
2502-
if (const DeclTypeSpec * spec{state_.declTypeSpec}) {
2501+
if (const DeclTypeSpec *spec{state_.declTypeSpec}) {
25032502
switch (spec->category()) {
25042503
case DeclTypeSpec::Numeric:
25052504
case DeclTypeSpec::Logical:
25062505
case DeclTypeSpec::Character:
25072506
typeSpec.declTypeSpec = spec;
25082507
break;
25092508
case DeclTypeSpec::TypeDerived:
2510-
if (const DerivedTypeSpec * derived{spec->AsDerived()}) {
2509+
if (const DerivedTypeSpec *derived{spec->AsDerived()}) {
25112510
CheckForAbstractType(derived->typeSymbol()); // C703
25122511
typeSpec.declTypeSpec = spec;
25132512
}
@@ -3098,8 +3097,8 @@ Symbol &ScopeHandler::MakeSymbol(const parser::Name &name, Attrs attrs) {
30983097
Symbol &ScopeHandler::MakeHostAssocSymbol(
30993098
const parser::Name &name, const Symbol &hostSymbol) {
31003099
Symbol &symbol{*NonDerivedTypeScope()
3101-
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3102-
.first->second};
3100+
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3101+
.first->second};
31033102
name.symbol = &symbol;
31043103
symbol.attrs() = hostSymbol.attrs(); // TODO: except PRIVATE, PUBLIC?
31053104
// These attributes can be redundantly reapplied without error
@@ -3187,7 +3186,7 @@ void ScopeHandler::ApplyImplicitRules(
31873186
if (context().HasError(symbol) || !NeedsType(symbol)) {
31883187
return;
31893188
}
3190-
if (const DeclTypeSpec * type{GetImplicitType(symbol)}) {
3189+
if (const DeclTypeSpec *type{GetImplicitType(symbol)}) {
31913190
if (!skipImplicitTyping_) {
31923191
symbol.set(Symbol::Flag::Implicit);
31933192
symbol.SetType(*type);
@@ -3287,7 +3286,7 @@ const DeclTypeSpec *ScopeHandler::GetImplicitType(
32873286
const auto *type{implicitRulesMap_->at(scope).GetType(
32883287
symbol.name(), respectImplicitNoneType)};
32893288
if (type) {
3290-
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
3289+
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
32913290
// Resolve any forward-referenced derived type; a quick no-op else.
32923291
auto &instantiatable{*const_cast<DerivedTypeSpec *>(derived)};
32933292
instantiatable.Instantiate(currScope());
@@ -4310,7 +4309,7 @@ Scope *ModuleVisitor::FindModule(const parser::Name &name,
43104309
if (scope) {
43114310
if (DoesScopeContain(scope, currScope())) { // 14.2.2(1)
43124311
std::optional<SourceName> submoduleName;
4313-
if (const Scope * container{FindModuleOrSubmoduleContaining(currScope())};
4312+
if (const Scope *container{FindModuleOrSubmoduleContaining(currScope())};
43144313
container && container->IsSubmodule()) {
43154314
submoduleName = container->GetName();
43164315
}
@@ -4415,7 +4414,7 @@ bool InterfaceVisitor::isAbstract() const {
44154414

44164415
void InterfaceVisitor::AddSpecificProcs(
44174416
const std::list<parser::Name> &names, ProcedureKind kind) {
4418-
if (Symbol * symbol{GetGenericInfo().symbol};
4417+
if (Symbol *symbol{GetGenericInfo().symbol};
44194418
symbol && symbol->has<GenericDetails>()) {
44204419
for (const auto &name : names) {
44214420
specificsForGenericProcs_.emplace(symbol, std::make_pair(&name, kind));
@@ -4515,7 +4514,7 @@ void GenericHandler::DeclaredPossibleSpecificProc(Symbol &proc) {
45154514
}
45164515

45174516
void InterfaceVisitor::ResolveNewSpecifics() {
4518-
if (Symbol * generic{genericInfo_.top().symbol};
4517+
if (Symbol *generic{genericInfo_.top().symbol};
45194518
generic && generic->has<GenericDetails>()) {
45204519
ResolveSpecificsInGeneric(*generic, false);
45214520
}
@@ -4600,7 +4599,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
46004599
name.source);
46014600
MakeSymbol(name, Attrs{}, UnknownDetails{});
46024601
} else if (auto *entity{ultimate.detailsIf<EntityDetails>()};
4603-
entity && !ultimate.has<ProcEntityDetails>()) {
4602+
entity && !ultimate.has<ProcEntityDetails>()) {
46044603
resultType = entity->type();
46054604
ultimate.details() = UnknownDetails{}; // will be replaced below
46064605
} else {
@@ -4659,7 +4658,7 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
46594658
} else {
46604659
Message &msg{Say(*suffix.resultName,
46614660
"RESULT(%s) may appear only in a function"_err_en_US)};
4662-
if (const Symbol * subprogram{InclusiveScope().symbol()}) {
4661+
if (const Symbol *subprogram{InclusiveScope().symbol()}) {
46634662
msg.Attach(subprogram->name(), "Containing subprogram"_en_US);
46644663
}
46654664
}
@@ -5175,7 +5174,7 @@ Symbol *ScopeHandler::FindSeparateModuleProcedureInterface(
51755174
symbol = generic->specific();
51765175
}
51775176
}
5178-
if (const Symbol * defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
5177+
if (const Symbol *defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
51795178
// Error recovery in case of multiple definitions
51805179
symbol = const_cast<Symbol *>(defnIface);
51815180
}
@@ -5314,8 +5313,8 @@ bool SubprogramVisitor::HandlePreviousCalls(
53145313
return generic->specific() &&
53155314
HandlePreviousCalls(name, *generic->specific(), subpFlag);
53165315
} else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
5317-
!proc->isDummy() &&
5318-
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
5316+
!proc->isDummy() &&
5317+
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
53195318
// There's a symbol created for previous calls to this subprogram or
53205319
// ENTRY's name. We have to replace that symbol in situ to avoid the
53215320
// obligation to rewrite symbol pointers in the parse tree.
@@ -5357,7 +5356,7 @@ const Symbol *SubprogramVisitor::CheckExtantProc(
53575356
if (prev) {
53585357
if (IsDummy(*prev)) {
53595358
} else if (auto *entity{prev->detailsIf<EntityDetails>()};
5360-
IsPointer(*prev) && entity && !entity->type()) {
5359+
IsPointer(*prev) && entity && !entity->type()) {
53615360
// POINTER attribute set before interface
53625361
} else if (inInterfaceBlock() && currScope() != prev->owner()) {
53635362
// Procedures in an INTERFACE block do not resolve to symbols
@@ -5429,7 +5428,7 @@ Symbol *SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
54295428
}
54305429
set_inheritFromParent(false); // interfaces don't inherit, even if MODULE
54315430
}
5432-
if (Symbol * found{FindSymbol(name)};
5431+
if (Symbol *found{FindSymbol(name)};
54335432
found && found->has<HostAssocDetails>()) {
54345433
found->set(subpFlag); // PushScope() created symbol
54355434
}
@@ -6280,9 +6279,9 @@ void DeclarationVisitor::Post(const parser::VectorTypeSpec &x) {
62806279
vectorDerivedType.CookParameters(GetFoldingContext());
62816280
}
62826281

6283-
if (const DeclTypeSpec *
6284-
extant{ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6285-
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
6282+
if (const DeclTypeSpec *extant{
6283+
ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6284+
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
62866285
// This derived type and parameter expressions (if any) are already present
62876286
// in the __ppc_intrinsics scope.
62886287
SetDeclTypeSpec(*extant);
@@ -6304,7 +6303,7 @@ bool DeclarationVisitor::Pre(const parser::DeclarationTypeSpec::Type &) {
63046303

63056304
void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &type) {
63066305
const parser::Name &derivedName{std::get<parser::Name>(type.derived.t)};
6307-
if (const Symbol * derivedSymbol{derivedName.symbol}) {
6306+
if (const Symbol *derivedSymbol{derivedName.symbol}) {
63086307
CheckForAbstractType(*derivedSymbol); // C706
63096308
}
63106309
}
@@ -6373,8 +6372,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeSpec &x) {
63736372
if (!spec->MightBeParameterized()) {
63746373
spec->EvaluateParameters(context());
63756374
}
6376-
if (const DeclTypeSpec *
6377-
extant{currScope().FindInstantiatedDerivedType(*spec, category)}) {
6375+
if (const DeclTypeSpec *extant{
6376+
currScope().FindInstantiatedDerivedType(*spec, category)}) {
63786377
// This derived type and parameter expressions (if any) are already present
63796378
// in this scope.
63806379
SetDeclTypeSpec(*extant);
@@ -6405,8 +6404,7 @@ void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Record &rec) {
64056404
if (auto spec{ResolveDerivedType(typeName)}) {
64066405
spec->CookParameters(GetFoldingContext());
64076406
spec->EvaluateParameters(context());
6408-
if (const DeclTypeSpec *
6409-
extant{currScope().FindInstantiatedDerivedType(
6407+
if (const DeclTypeSpec *extant{currScope().FindInstantiatedDerivedType(
64106408
*spec, DeclTypeSpec::TypeDerived)}) {
64116409
SetDeclTypeSpec(*extant);
64126410
} else {
@@ -7417,7 +7415,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
74177415
"Coarray '%s' not allowed in a %s locality-spec"_err_en_US, specName);
74187416
return false;
74197417
}
7420-
if (const DeclTypeSpec * type{symbol.GetType()}) {
7418+
if (const DeclTypeSpec *type{symbol.GetType()}) {
74217419
if (type->IsPolymorphic() && IsDummy(symbol) && !IsPointer(symbol) &&
74227420
!isReduce) { // F'2023 C1130
74237421
SayWithDecl(name, symbol,
@@ -7644,7 +7642,7 @@ Symbol *DeclarationVisitor::NoteInterfaceName(const parser::Name &name) {
76447642
}
76457643

76467644
void DeclarationVisitor::CheckExplicitInterface(const parser::Name &name) {
7647-
if (const Symbol * symbol{name.symbol}) {
7645+
if (const Symbol *symbol{name.symbol}) {
76487646
const Symbol &ultimate{symbol->GetUltimate()};
76497647
if (!context().HasError(*symbol) && !context().HasError(ultimate) &&
76507648
!BypassGeneric(ultimate).HasExplicitInterface()) {
@@ -7963,7 +7961,7 @@ bool ConstructVisitor::Pre(const parser::DataStmtValue &x) {
79637961
auto &mutableData{const_cast<parser::DataStmtConstant &>(data)};
79647962
if (auto *elem{parser::Unwrap<parser::ArrayElement>(mutableData)}) {
79657963
if (const auto *name{std::get_if<parser::Name>(&elem->base.u)}) {
7966-
if (const Symbol * symbol{FindSymbol(*name)};
7964+
if (const Symbol *symbol{FindSymbol(*name)};
79677965
symbol && symbol->GetUltimate().has<DerivedTypeDetails>()) {
79687966
mutableData.u = elem->ConvertToStructureConstructor(
79697967
DerivedTypeSpec{name->source, *symbol});
@@ -8109,15 +8107,15 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
81098107
}
81108108
}
81118109
} else {
8112-
if (const Symbol *
8113-
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8110+
if (const Symbol *whole{
8111+
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
81148112
ConvertToObjectEntity(const_cast<Symbol &>(*whole));
81158113
if (!IsVariableName(*whole)) {
81168114
Say(association.selector.source, // C901
81178115
"Selector is not a variable"_err_en_US);
81188116
association = {};
81198117
}
8120-
if (const DeclTypeSpec * type{whole->GetType()}) {
8118+
if (const DeclTypeSpec *type{whole->GetType()}) {
81218119
if (!type->IsPolymorphic()) { // C1159
81228120
Say(association.selector.source,
81238121
"Selector '%s' in SELECT TYPE statement must be "
@@ -8257,8 +8255,8 @@ Symbol *ConstructVisitor::MakeAssocEntity() {
82578255
"The associate name '%s' is already used in this associate statement"_err_en_US);
82588256
return nullptr;
82598257
}
8260-
} else if (const Symbol *
8261-
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8258+
} else if (const Symbol *whole{
8259+
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
82628260
symbol = &MakeSymbol(whole->name());
82638261
} else {
82648262
return nullptr;
@@ -8878,7 +8876,7 @@ bool DeclarationVisitor::CheckForHostAssociatedImplicit(
88788876
if (name.symbol) {
88798877
ApplyImplicitRules(*name.symbol, true);
88808878
}
8881-
if (Scope * host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
8879+
if (Scope *host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
88828880
Symbol *hostSymbol{nullptr};
88838881
if (!name.symbol) {
88848882
if (currScope().CanImport(name.source)) {
@@ -8949,7 +8947,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89498947
if (!type) {
89508948
return nullptr; // should have already reported error
89518949
}
8952-
if (const IntrinsicTypeSpec * intrinsic{type->AsIntrinsic()}) {
8950+
if (const IntrinsicTypeSpec *intrinsic{type->AsIntrinsic()}) {
89538951
auto category{intrinsic->category()};
89548952
MiscDetails::Kind miscKind{MiscDetails::Kind::None};
89558953
if (component.source == "kind") {
@@ -8971,7 +8969,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89718969
}
89728970
} else if (DerivedTypeSpec * derived{type->AsDerived()}) {
89738971
derived->Instantiate(currScope()); // in case of forward referenced type
8974-
if (const Scope * scope{derived->scope()}) {
8972+
if (const Scope *scope{derived->scope()}) {
89758973
if (Resolve(component, scope->FindComponent(component.source))) {
89768974
if (auto msg{CheckAccessibleSymbol(currScope(), *component.symbol)}) {
89778975
context().Say(component.source, *msg);
@@ -9122,8 +9120,8 @@ void DeclarationVisitor::PointerInitialization(
91229120
if (evaluate::IsNullProcedurePointer(&*expr)) {
91239121
CHECK(!details->init());
91249122
details->set_init(nullptr);
9125-
} else if (const Symbol *
9126-
targetSymbol{evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
9123+
} else if (const Symbol *targetSymbol{
9124+
evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
91279125
CHECK(!details->init());
91289126
details->set_init(*targetSymbol);
91299127
} else {
@@ -9692,7 +9690,7 @@ void ResolveNamesVisitor::EarlyDummyTypeDeclaration(
96929690
for (const auto &ent : entities) {
96939691
const auto &objName{std::get<parser::ObjectName>(ent.t)};
96949692
Resolve(objName, FindInScope(currScope(), objName));
9695-
if (Symbol * symbol{objName.symbol};
9693+
if (Symbol *symbol{objName.symbol};
96969694
symbol && IsDummy(*symbol) && NeedsType(*symbol)) {
96979695
if (!type) {
96989696
type = ProcessTypeSpec(declTypeSpec);
@@ -9831,7 +9829,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
98319829
if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
98329830
!proc->isDummy() && !IsPointer(symbol) &&
98339831
!symbol.attrs().test(Attr::BIND_C)) {
9834-
if (const Symbol * iface{proc->procInterface()};
9832+
if (const Symbol *iface{proc->procInterface()};
98359833
iface && IsBindCProcedure(*iface)) {
98369834
SetImplicitAttr(symbol, Attr::BIND_C);
98379835
SetBindNameOn(symbol);
@@ -9964,7 +9962,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
99649962
Symbol *ptrSymbol{parser::GetLastName(dataRef).symbol};
99659963
Walk(bounds);
99669964
// Resolve unrestricted specific intrinsic procedures as in "p => cos".
9967-
if (const parser::Name * name{parser::Unwrap<parser::Name>(expr)}) {
9965+
if (const parser::Name *name{parser::Unwrap<parser::Name>(expr)}) {
99689966
if (NameIsKnownOrIntrinsic(*name)) {
99699967
if (Symbol * symbol{name->symbol}) {
99709968
if (IsProcedurePointer(ptrSymbol) &&
@@ -10411,8 +10409,8 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
1041110409
// implied SAVE so that evaluate::IsSaved() will return true.
1041210410
if (node.scope()->kind() == Scope::Kind::MainProgram) {
1041310411
if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
10414-
if (const DeclTypeSpec * type{object->type()}) {
10415-
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
10412+
if (const DeclTypeSpec *type{object->type()}) {
10413+
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
1041610414
if (!IsSaved(symbol) && FindCoarrayPotentialComponent(*derived)) {
1041710415
SetImplicitAttr(symbol, Attr::SAVE);
1041810416
}
@@ -10669,7 +10667,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1066910667
if (DerivedTypeSpec * spec{scope.derivedTypeSpec()}) {
1067010668
spec->Instantiate(currScope());
1067110669
const Symbol &origTypeSymbol{spec->typeSymbol()};
10672-
if (const Scope * origTypeScope{origTypeSymbol.scope()}) {
10670+
if (const Scope *origTypeScope{origTypeSymbol.scope()}) {
1067310671
CHECK(origTypeScope->IsDerivedType() &&
1067410672
origTypeScope->symbol() == &origTypeSymbol);
1067510673
auto &foldingContext{GetFoldingContext()};
@@ -10680,7 +10678,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1068010678
if (IsPointer(comp)) {
1068110679
if (auto *details{comp.detailsIf<ObjectEntityDetails>()}) {
1068210680
auto origDetails{origComp.get<ObjectEntityDetails>()};
10683-
if (const MaybeExpr & init{origDetails.init()}) {
10681+
if (const MaybeExpr &init{origDetails.init()}) {
1068410682
SomeExpr newInit{*init};
1068510683
MaybeExpr folded{FoldExpr(std::move(newInit))};
1068610684
details->set_init(std::move(folded));

0 commit comments

Comments
 (0)