Skip to content

Commit a8f1613

Browse files
committed
code cleanup
1 parent 80194f3 commit a8f1613

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
@@ -1824,8 +1824,7 @@ bool OmpVisitor::Pre(const parser::OmpMapClause &x) {
18241824
// TODO: Do we need a specific flag or type here, to distinghuish against
18251825
// other ConstructName things? Leaving this for the full implementation
18261826
// of mapper lowering.
1827-
const Symbol &ultimate{symbol->GetUltimate()};
1828-
auto *misc{const_cast<Symbol &>(ultimate).detailsIf<MiscDetails>()};
1827+
auto *misc{symbol->GetUltimate().detailsIf<MiscDetails>()};
18291828
if (!misc || misc->kind() != MiscDetails::Kind::ConstructName)
18301829
context().Say(mapper->v.source,
18311830
"Name '%s' should be a mapper name"_err_en_US, mapper->v.source);
@@ -2376,7 +2375,7 @@ void AttrsVisitor::SetBindNameOn(Symbol &symbol) {
23762375
}
23772376
symbol.SetBindName(std::move(*label));
23782377
if (!oldBindName.empty()) {
2379-
if (const std::string * newBindName{symbol.GetBindName()}) {
2378+
if (const std::string *newBindName{symbol.GetBindName()}) {
23802379
if (oldBindName != *newBindName) {
23812380
Say(symbol.name(),
23822381
"The entity '%s' has multiple BIND names ('%s' and '%s')"_err_en_US,
@@ -2502,15 +2501,15 @@ void DeclTypeSpecVisitor::Post(const parser::TypeSpec &typeSpec) {
25022501
// expression semantics if the DeclTypeSpec is a valid TypeSpec.
25032502
// The grammar ensures that it's an intrinsic or derived type spec,
25042503
// not TYPE(*) or CLASS(*) or CLASS(T).
2505-
if (const DeclTypeSpec * spec{state_.declTypeSpec}) {
2504+
if (const DeclTypeSpec *spec{state_.declTypeSpec}) {
25062505
switch (spec->category()) {
25072506
case DeclTypeSpec::Numeric:
25082507
case DeclTypeSpec::Logical:
25092508
case DeclTypeSpec::Character:
25102509
typeSpec.declTypeSpec = spec;
25112510
break;
25122511
case DeclTypeSpec::TypeDerived:
2513-
if (const DerivedTypeSpec * derived{spec->AsDerived()}) {
2512+
if (const DerivedTypeSpec *derived{spec->AsDerived()}) {
25142513
CheckForAbstractType(derived->typeSymbol()); // C703
25152514
typeSpec.declTypeSpec = spec;
25162515
}
@@ -3101,8 +3100,8 @@ Symbol &ScopeHandler::MakeSymbol(const parser::Name &name, Attrs attrs) {
31013100
Symbol &ScopeHandler::MakeHostAssocSymbol(
31023101
const parser::Name &name, const Symbol &hostSymbol) {
31033102
Symbol &symbol{*NonDerivedTypeScope()
3104-
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3105-
.first->second};
3103+
.try_emplace(name.source, HostAssocDetails{hostSymbol})
3104+
.first->second};
31063105
name.symbol = &symbol;
31073106
symbol.attrs() = hostSymbol.attrs(); // TODO: except PRIVATE, PUBLIC?
31083107
// These attributes can be redundantly reapplied without error
@@ -3190,7 +3189,7 @@ void ScopeHandler::ApplyImplicitRules(
31903189
if (context().HasError(symbol) || !NeedsType(symbol)) {
31913190
return;
31923191
}
3193-
if (const DeclTypeSpec * type{GetImplicitType(symbol)}) {
3192+
if (const DeclTypeSpec *type{GetImplicitType(symbol)}) {
31943193
if (!skipImplicitTyping_) {
31953194
symbol.set(Symbol::Flag::Implicit);
31963195
symbol.SetType(*type);
@@ -3290,7 +3289,7 @@ const DeclTypeSpec *ScopeHandler::GetImplicitType(
32903289
const auto *type{implicitRulesMap_->at(scope).GetType(
32913290
symbol.name(), respectImplicitNoneType)};
32923291
if (type) {
3293-
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
3292+
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
32943293
// Resolve any forward-referenced derived type; a quick no-op else.
32953294
auto &instantiatable{*const_cast<DerivedTypeSpec *>(derived)};
32963295
instantiatable.Instantiate(currScope());
@@ -4299,7 +4298,7 @@ Scope *ModuleVisitor::FindModule(const parser::Name &name,
42994298
if (scope) {
43004299
if (DoesScopeContain(scope, currScope())) { // 14.2.2(1)
43014300
std::optional<SourceName> submoduleName;
4302-
if (const Scope * container{FindModuleOrSubmoduleContaining(currScope())};
4301+
if (const Scope *container{FindModuleOrSubmoduleContaining(currScope())};
43034302
container && container->IsSubmodule()) {
43044303
submoduleName = container->GetName();
43054304
}
@@ -4404,7 +4403,7 @@ bool InterfaceVisitor::isAbstract() const {
44044403

44054404
void InterfaceVisitor::AddSpecificProcs(
44064405
const std::list<parser::Name> &names, ProcedureKind kind) {
4407-
if (Symbol * symbol{GetGenericInfo().symbol};
4406+
if (Symbol *symbol{GetGenericInfo().symbol};
44084407
symbol && symbol->has<GenericDetails>()) {
44094408
for (const auto &name : names) {
44104409
specificsForGenericProcs_.emplace(symbol, std::make_pair(&name, kind));
@@ -4504,7 +4503,7 @@ void GenericHandler::DeclaredPossibleSpecificProc(Symbol &proc) {
45044503
}
45054504

45064505
void InterfaceVisitor::ResolveNewSpecifics() {
4507-
if (Symbol * generic{genericInfo_.top().symbol};
4506+
if (Symbol *generic{genericInfo_.top().symbol};
45084507
generic && generic->has<GenericDetails>()) {
45094508
ResolveSpecificsInGeneric(*generic, false);
45104509
}
@@ -4589,7 +4588,7 @@ bool SubprogramVisitor::HandleStmtFunction(const parser::StmtFunctionStmt &x) {
45894588
name.source);
45904589
MakeSymbol(name, Attrs{}, UnknownDetails{});
45914590
} else if (auto *entity{ultimate.detailsIf<EntityDetails>()};
4592-
entity && !ultimate.has<ProcEntityDetails>()) {
4591+
entity && !ultimate.has<ProcEntityDetails>()) {
45934592
resultType = entity->type();
45944593
ultimate.details() = UnknownDetails{}; // will be replaced below
45954594
} else {
@@ -4648,7 +4647,7 @@ bool SubprogramVisitor::Pre(const parser::Suffix &suffix) {
46484647
} else {
46494648
Message &msg{Say(*suffix.resultName,
46504649
"RESULT(%s) may appear only in a function"_err_en_US)};
4651-
if (const Symbol * subprogram{InclusiveScope().symbol()}) {
4650+
if (const Symbol *subprogram{InclusiveScope().symbol()}) {
46524651
msg.Attach(subprogram->name(), "Containing subprogram"_en_US);
46534652
}
46544653
}
@@ -5164,7 +5163,7 @@ Symbol *ScopeHandler::FindSeparateModuleProcedureInterface(
51645163
symbol = generic->specific();
51655164
}
51665165
}
5167-
if (const Symbol * defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
5166+
if (const Symbol *defnIface{FindSeparateModuleSubprogramInterface(symbol)}) {
51685167
// Error recovery in case of multiple definitions
51695168
symbol = const_cast<Symbol *>(defnIface);
51705169
}
@@ -5303,8 +5302,8 @@ bool SubprogramVisitor::HandlePreviousCalls(
53035302
return generic->specific() &&
53045303
HandlePreviousCalls(name, *generic->specific(), subpFlag);
53055304
} else if (const auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
5306-
!proc->isDummy() &&
5307-
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
5305+
!proc->isDummy() &&
5306+
!symbol.attrs().HasAny(Attrs{Attr::INTRINSIC, Attr::POINTER})) {
53085307
// There's a symbol created for previous calls to this subprogram or
53095308
// ENTRY's name. We have to replace that symbol in situ to avoid the
53105309
// obligation to rewrite symbol pointers in the parse tree.
@@ -5346,7 +5345,7 @@ const Symbol *SubprogramVisitor::CheckExtantProc(
53465345
if (prev) {
53475346
if (IsDummy(*prev)) {
53485347
} else if (auto *entity{prev->detailsIf<EntityDetails>()};
5349-
IsPointer(*prev) && entity && !entity->type()) {
5348+
IsPointer(*prev) && entity && !entity->type()) {
53505349
// POINTER attribute set before interface
53515350
} else if (inInterfaceBlock() && currScope() != prev->owner()) {
53525351
// Procedures in an INTERFACE block do not resolve to symbols
@@ -5418,7 +5417,7 @@ Symbol *SubprogramVisitor::PushSubprogramScope(const parser::Name &name,
54185417
}
54195418
set_inheritFromParent(false); // interfaces don't inherit, even if MODULE
54205419
}
5421-
if (Symbol * found{FindSymbol(name)};
5420+
if (Symbol *found{FindSymbol(name)};
54225421
found && found->has<HostAssocDetails>()) {
54235422
found->set(subpFlag); // PushScope() created symbol
54245423
}
@@ -6266,9 +6265,9 @@ void DeclarationVisitor::Post(const parser::VectorTypeSpec &x) {
62666265
vectorDerivedType.CookParameters(GetFoldingContext());
62676266
}
62686267

6269-
if (const DeclTypeSpec *
6270-
extant{ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6271-
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
6268+
if (const DeclTypeSpec *extant{
6269+
ppcBuiltinTypesScope->FindInstantiatedDerivedType(
6270+
vectorDerivedType, DeclTypeSpec::Category::TypeDerived)}) {
62726271
// This derived type and parameter expressions (if any) are already present
62736272
// in the __ppc_intrinsics scope.
62746273
SetDeclTypeSpec(*extant);
@@ -6290,7 +6289,7 @@ bool DeclarationVisitor::Pre(const parser::DeclarationTypeSpec::Type &) {
62906289

62916290
void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Type &type) {
62926291
const parser::Name &derivedName{std::get<parser::Name>(type.derived.t)};
6293-
if (const Symbol * derivedSymbol{derivedName.symbol}) {
6292+
if (const Symbol *derivedSymbol{derivedName.symbol}) {
62946293
CheckForAbstractType(*derivedSymbol); // C706
62956294
}
62966295
}
@@ -6359,8 +6358,8 @@ void DeclarationVisitor::Post(const parser::DerivedTypeSpec &x) {
63596358
if (!spec->MightBeParameterized()) {
63606359
spec->EvaluateParameters(context());
63616360
}
6362-
if (const DeclTypeSpec *
6363-
extant{currScope().FindInstantiatedDerivedType(*spec, category)}) {
6361+
if (const DeclTypeSpec *extant{
6362+
currScope().FindInstantiatedDerivedType(*spec, category)}) {
63646363
// This derived type and parameter expressions (if any) are already present
63656364
// in this scope.
63666365
SetDeclTypeSpec(*extant);
@@ -6391,8 +6390,7 @@ void DeclarationVisitor::Post(const parser::DeclarationTypeSpec::Record &rec) {
63916390
if (auto spec{ResolveDerivedType(typeName)}) {
63926391
spec->CookParameters(GetFoldingContext());
63936392
spec->EvaluateParameters(context());
6394-
if (const DeclTypeSpec *
6395-
extant{currScope().FindInstantiatedDerivedType(
6393+
if (const DeclTypeSpec *extant{currScope().FindInstantiatedDerivedType(
63966394
*spec, DeclTypeSpec::TypeDerived)}) {
63976395
SetDeclTypeSpec(*extant);
63986396
} else {
@@ -7403,7 +7401,7 @@ bool DeclarationVisitor::PassesLocalityChecks(
74037401
"Coarray '%s' not allowed in a %s locality-spec"_err_en_US, specName);
74047402
return false;
74057403
}
7406-
if (const DeclTypeSpec * type{symbol.GetType()}) {
7404+
if (const DeclTypeSpec *type{symbol.GetType()}) {
74077405
if (type->IsPolymorphic() && IsDummy(symbol) && !IsPointer(symbol) &&
74087406
!isReduce) { // F'2023 C1130
74097407
SayWithDecl(name, symbol,
@@ -7630,7 +7628,7 @@ Symbol *DeclarationVisitor::NoteInterfaceName(const parser::Name &name) {
76307628
}
76317629

76327630
void DeclarationVisitor::CheckExplicitInterface(const parser::Name &name) {
7633-
if (const Symbol * symbol{name.symbol}) {
7631+
if (const Symbol *symbol{name.symbol}) {
76347632
const Symbol &ultimate{symbol->GetUltimate()};
76357633
if (!context().HasError(*symbol) && !context().HasError(ultimate) &&
76367634
!BypassGeneric(ultimate).HasExplicitInterface()) {
@@ -7948,7 +7946,7 @@ bool ConstructVisitor::Pre(const parser::DataStmtValue &x) {
79487946
auto &mutableData{const_cast<parser::DataStmtConstant &>(data)};
79497947
if (auto *elem{parser::Unwrap<parser::ArrayElement>(mutableData)}) {
79507948
if (const auto *name{std::get_if<parser::Name>(&elem->base.u)}) {
7951-
if (const Symbol * symbol{FindSymbol(*name)};
7949+
if (const Symbol *symbol{FindSymbol(*name)};
79527950
symbol && symbol->GetUltimate().has<DerivedTypeDetails>()) {
79537951
mutableData.u = elem->ConvertToStructureConstructor(
79547952
DerivedTypeSpec{name->source, *symbol});
@@ -8094,15 +8092,15 @@ void ConstructVisitor::Post(const parser::SelectTypeStmt &x) {
80948092
}
80958093
}
80968094
} else {
8097-
if (const Symbol *
8098-
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8095+
if (const Symbol *whole{
8096+
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
80998097
ConvertToObjectEntity(const_cast<Symbol &>(*whole));
81008098
if (!IsVariableName(*whole)) {
81018099
Say(association.selector.source, // C901
81028100
"Selector is not a variable"_err_en_US);
81038101
association = {};
81048102
}
8105-
if (const DeclTypeSpec * type{whole->GetType()}) {
8103+
if (const DeclTypeSpec *type{whole->GetType()}) {
81068104
if (!type->IsPolymorphic()) { // C1159
81078105
Say(association.selector.source,
81088106
"Selector '%s' in SELECT TYPE statement must be "
@@ -8242,8 +8240,8 @@ Symbol *ConstructVisitor::MakeAssocEntity() {
82428240
"The associate name '%s' is already used in this associate statement"_err_en_US);
82438241
return nullptr;
82448242
}
8245-
} else if (const Symbol *
8246-
whole{UnwrapWholeSymbolDataRef(association.selector.expr)}) {
8243+
} else if (const Symbol *whole{
8244+
UnwrapWholeSymbolDataRef(association.selector.expr)}) {
82478245
symbol = &MakeSymbol(whole->name());
82488246
} else {
82498247
return nullptr;
@@ -8864,7 +8862,7 @@ bool DeclarationVisitor::CheckForHostAssociatedImplicit(
88648862
if (name.symbol) {
88658863
ApplyImplicitRules(*name.symbol, true);
88668864
}
8867-
if (Scope * host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
8865+
if (Scope *host{GetHostProcedure()}; host && !isImplicitNoneType(*host)) {
88688866
Symbol *hostSymbol{nullptr};
88698867
if (!name.symbol) {
88708868
if (currScope().CanImport(name.source)) {
@@ -8935,7 +8933,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89358933
if (!type) {
89368934
return nullptr; // should have already reported error
89378935
}
8938-
if (const IntrinsicTypeSpec * intrinsic{type->AsIntrinsic()}) {
8936+
if (const IntrinsicTypeSpec *intrinsic{type->AsIntrinsic()}) {
89398937
auto category{intrinsic->category()};
89408938
MiscDetails::Kind miscKind{MiscDetails::Kind::None};
89418939
if (component.source == "kind") {
@@ -8957,7 +8955,7 @@ const parser::Name *DeclarationVisitor::FindComponent(
89578955
}
89588956
} else if (DerivedTypeSpec * derived{type->AsDerived()}) {
89598957
derived->Instantiate(currScope()); // in case of forward referenced type
8960-
if (const Scope * scope{derived->scope()}) {
8958+
if (const Scope *scope{derived->scope()}) {
89618959
if (Resolve(component, scope->FindComponent(component.source))) {
89628960
if (auto msg{CheckAccessibleSymbol(currScope(), *component.symbol)}) {
89638961
context().Say(component.source, *msg);
@@ -9108,8 +9106,8 @@ void DeclarationVisitor::PointerInitialization(
91089106
if (evaluate::IsNullProcedurePointer(&*expr)) {
91099107
CHECK(!details->init());
91109108
details->set_init(nullptr);
9111-
} else if (const Symbol *
9112-
targetSymbol{evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
9109+
} else if (const Symbol *targetSymbol{
9110+
evaluate::UnwrapWholeSymbolDataRef(*expr)}) {
91139111
CHECK(!details->init());
91149112
details->set_init(*targetSymbol);
91159113
} else {
@@ -9677,7 +9675,7 @@ void ResolveNamesVisitor::EarlyDummyTypeDeclaration(
96779675
for (const auto &ent : entities) {
96789676
const auto &objName{std::get<parser::ObjectName>(ent.t)};
96799677
Resolve(objName, FindInScope(currScope(), objName));
9680-
if (Symbol * symbol{objName.symbol};
9678+
if (Symbol *symbol{objName.symbol};
96819679
symbol && IsDummy(*symbol) && NeedsType(*symbol)) {
96829680
if (!type) {
96839681
type = ProcessTypeSpec(declTypeSpec);
@@ -9816,7 +9814,7 @@ void ResolveNamesVisitor::FinishSpecificationPart(
98169814
if (auto *proc{symbol.detailsIf<ProcEntityDetails>()}; proc &&
98179815
!proc->isDummy() && !IsPointer(symbol) &&
98189816
!symbol.attrs().test(Attr::BIND_C)) {
9819-
if (const Symbol * iface{proc->procInterface()};
9817+
if (const Symbol *iface{proc->procInterface()};
98209818
iface && IsBindCProcedure(*iface)) {
98219819
SetImplicitAttr(symbol, Attr::BIND_C);
98229820
SetBindNameOn(symbol);
@@ -9949,7 +9947,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
99499947
Symbol *ptrSymbol{parser::GetLastName(dataRef).symbol};
99509948
Walk(bounds);
99519949
// Resolve unrestricted specific intrinsic procedures as in "p => cos".
9952-
if (const parser::Name * name{parser::Unwrap<parser::Name>(expr)}) {
9950+
if (const parser::Name *name{parser::Unwrap<parser::Name>(expr)}) {
99539951
if (NameIsKnownOrIntrinsic(*name)) {
99549952
if (Symbol * symbol{name->symbol}) {
99559953
if (IsProcedurePointer(ptrSymbol) &&
@@ -10390,8 +10388,8 @@ void ResolveNamesVisitor::ResolveSpecificationParts(ProgramTree &node) {
1039010388
// implied SAVE so that evaluate::IsSaved() will return true.
1039110389
if (node.scope()->kind() == Scope::Kind::MainProgram) {
1039210390
if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()}) {
10393-
if (const DeclTypeSpec * type{object->type()}) {
10394-
if (const DerivedTypeSpec * derived{type->AsDerived()}) {
10391+
if (const DeclTypeSpec *type{object->type()}) {
10392+
if (const DerivedTypeSpec *derived{type->AsDerived()}) {
1039510393
if (!IsSaved(symbol) && FindCoarrayPotentialComponent(*derived)) {
1039610394
SetImplicitAttr(symbol, Attr::SAVE);
1039710395
}
@@ -10648,7 +10646,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1064810646
if (DerivedTypeSpec * spec{scope.derivedTypeSpec()}) {
1064910647
spec->Instantiate(currScope());
1065010648
const Symbol &origTypeSymbol{spec->typeSymbol()};
10651-
if (const Scope * origTypeScope{origTypeSymbol.scope()}) {
10649+
if (const Scope *origTypeScope{origTypeSymbol.scope()}) {
1065210650
CHECK(origTypeScope->IsDerivedType() &&
1065310651
origTypeScope->symbol() == &origTypeSymbol);
1065410652
auto &foldingContext{GetFoldingContext()};
@@ -10659,7 +10657,7 @@ void ResolveNamesVisitor::FinishDerivedTypeInstantiation(Scope &scope) {
1065910657
if (IsPointer(comp)) {
1066010658
if (auto *details{comp.detailsIf<ObjectEntityDetails>()}) {
1066110659
auto origDetails{origComp.get<ObjectEntityDetails>()};
10662-
if (const MaybeExpr & init{origDetails.init()}) {
10660+
if (const MaybeExpr &init{origDetails.init()}) {
1066310661
SomeExpr newInit{*init};
1066410662
MaybeExpr folded{FoldExpr(std::move(newInit))};
1066510663
details->set_init(std::move(folded));

0 commit comments

Comments
 (0)