Skip to content

Commit 92bd6e5

Browse files
committed
[flang] clang-format Semantics sources, NFC
There a a bunch of relatively simple changes, mostly the position of the * or & in declarations, or line breaks in declarations (usually) within if-statements. Three manual changes: - remove tailing ; in the constructor of ArithmeticIfStmtChecker, - prevent re-indentation of visitor functions in check-case.cpp and resolve-directives.cpp
1 parent 30007a5 commit 92bd6e5

37 files changed

+396
-422
lines changed

flang/include/flang/Semantics/scope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class SemanticsContext;
3939
struct EquivalenceObject {
4040
EquivalenceObject(Symbol &symbol, std::vector<ConstantSubscript> subscripts,
4141
std::optional<ConstantSubscript> substringStart, parser::CharBlock source)
42-
: symbol{symbol}, subscripts{subscripts},
43-
substringStart{substringStart}, source{source} {}
42+
: symbol{symbol}, subscripts{subscripts}, substringStart{substringStart},
43+
source{source} {}
4444
explicit EquivalenceObject(Symbol &symbol)
4545
: symbol{symbol}, source{symbol.name()} {}
4646

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace Fortran::parser {
3232
struct Expr;
3333
struct OpenMPDeclareReductionConstruct;
3434
struct OmpMetadirectiveDirective;
35-
}
35+
} // namespace Fortran::parser
3636

3737
namespace Fortran::semantics {
3838

flang/include/flang/Semantics/tools.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool IsDeviceAllocatable(const Symbol &symbol);
203203

204204
inline bool IsCUDADeviceContext(const Scope *scope) {
205205
if (scope) {
206-
if (const Symbol * symbol{scope->symbol()}) {
206+
if (const Symbol *symbol{scope->symbol()}) {
207207
if (const auto *subp{symbol->detailsIf<SubprogramDetails>()}) {
208208
if (auto attrs{subp->cudaSubprogramAttrs()}) {
209209
return *attrs != common::CUDASubprogramAttrs::Host;
@@ -305,7 +305,7 @@ const Symbol *FindExternallyVisibleObject(const A &, const Scope &) {
305305
template <typename T>
306306
const Symbol *FindExternallyVisibleObject(
307307
const evaluate::Designator<T> &designator, const Scope &scope) {
308-
if (const Symbol * symbol{designator.GetBaseObject().symbol()}) {
308+
if (const Symbol *symbol{designator.GetBaseObject().symbol()}) {
309309
return FindExternallyVisibleObject(*symbol, scope, false);
310310
} else if (std::holds_alternative<evaluate::CoarrayRef>(designator.u)) {
311311
// Coindexed values are visible even if their image-local objects are not.
@@ -670,8 +670,8 @@ class LabelEnforce {
670670
LabelEnforce(SemanticsContext &context, std::set<parser::Label> &&labels,
671671
parser::CharBlock constructSourcePosition, const char *construct)
672672
: context_{context}, labels_{labels},
673-
constructSourcePosition_{constructSourcePosition}, construct_{
674-
construct} {}
673+
constructSourcePosition_{constructSourcePosition},
674+
construct_{construct} {}
675675
template <typename T> bool Pre(const T &) { return true; }
676676
template <typename T> bool Pre(const parser::Statement<T> &statement) {
677677
currentStatementSourcePosition_ = statement.source;

flang/include/flang/Semantics/unparse-with-symbols.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ void UnparseWithSymbols(llvm::raw_ostream &, const parser::Program &,
3232
void UnparseWithModules(llvm::raw_ostream &, SemanticsContext &,
3333
const parser::Program &,
3434
parser::Encoding encoding = parser::Encoding::UTF_8);
35-
}
35+
} // namespace Fortran::semantics
3636

3737
#endif // FORTRAN_SEMANTICS_UNPARSE_WITH_SYMBOLS_H_

flang/lib/Semantics/assignment.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AssignmentContext {
6262
};
6363

6464
void AssignmentContext::Analyze(const parser::AssignmentStmt &stmt) {
65-
if (const evaluate::Assignment * assignment{GetAssignment(stmt)}) {
65+
if (const evaluate::Assignment *assignment{GetAssignment(stmt)}) {
6666
const SomeExpr &lhs{assignment->lhs};
6767
const SomeExpr &rhs{assignment->rhs};
6868
auto lhsLoc{std::get<parser::Variable>(stmt.t).GetSource()};
@@ -72,8 +72,8 @@ void AssignmentContext::Analyze(const parser::AssignmentStmt &stmt) {
7272
std::holds_alternative<evaluate::ProcedureRef>(assignment->u)};
7373
if (isDefinedAssignment) {
7474
flags.set(DefinabilityFlag::AllowEventLockOrNotifyType);
75-
} else if (const Symbol *
76-
whole{evaluate::UnwrapWholeSymbolOrComponentDataRef(lhs)}) {
75+
} else if (const Symbol *whole{
76+
evaluate::UnwrapWholeSymbolOrComponentDataRef(lhs)}) {
7777
if (IsAllocatable(whole->GetUltimate())) {
7878
flags.set(DefinabilityFlag::PotentialDeallocation);
7979
}
@@ -101,7 +101,7 @@ void AssignmentContext::Analyze(const parser::AssignmentStmt &stmt) {
101101

102102
void AssignmentContext::Analyze(const parser::PointerAssignmentStmt &stmt) {
103103
CHECK(whereDepth_ == 0);
104-
if (const evaluate::Assignment * assignment{GetAssignment(stmt)}) {
104+
if (const evaluate::Assignment *assignment{GetAssignment(stmt)}) {
105105
parser::CharBlock at{context_.location().value()};
106106
auto restorer{foldingContext().messages().SetLocation(at)};
107107
CheckPointerAssignment(context_, *assignment, context_.FindScope(at));
@@ -125,7 +125,7 @@ static std::optional<std::string> GetPointerComponentDesignatorName(
125125
bool CheckCopyabilityInPureScope(parser::ContextualMessages &messages,
126126
const SomeExpr &expr, const Scope &scope) {
127127
if (auto pointer{GetPointerComponentDesignatorName(expr)}) {
128-
if (const Symbol * base{GetFirstSymbol(expr)}) {
128+
if (const Symbol *base{GetFirstSymbol(expr)}) {
129129
const char *why{WhyBaseObjectIsSuspicious(base->GetUltimate(), scope)};
130130
if (!why) {
131131
if (auto coarray{evaluate::ExtractCoarrayRef(expr)}) {

flang/lib/Semantics/canonicalize-acc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CanonicalizationOfAcc {
6868
return; // Tile is not allowed on DO CONCURRENT
6969
}
7070
for (const parser::DoConstruct *loop{&outer}; loop && tileArgNb > 0;
71-
--tileArgNb) {
71+
--tileArgNb) {
7272
const auto &block{std::get<parser::Block>(loop->t)};
7373
const auto it{block.begin()};
7474
loop = it != block.end() ? parser::Unwrap<parser::DoConstruct>(*it)

flang/lib/Semantics/check-acc-structure.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ void AccStructureChecker::Enter(const parser::OpenACCCacheConstruct &x) {
667667
PushContextAndClauseSets(verbatim.source, llvm::acc::Directive::ACCD_cache);
668668
SetContextDirectiveSource(verbatim.source);
669669
if (loopNestLevel == 0) {
670-
context_.Say(verbatim.source,
671-
"The CACHE directive must be inside a loop"_err_en_US);
670+
context_.Say(
671+
verbatim.source, "The CACHE directive must be inside a loop"_err_en_US);
672672
}
673673
}
674674
void AccStructureChecker::Leave(const parser::OpenACCCacheConstruct &x) {

flang/lib/Semantics/check-allocate.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class AllocationCheckerHelper {
7474
if (type_->category() == DeclTypeSpec::Category::Character) {
7575
hasDeferredTypeParameter_ =
7676
type_->characterTypeSpec().length().isDeferred();
77-
} else if (const DerivedTypeSpec * derivedTypeSpec{type_->AsDerived()}) {
77+
} else if (const DerivedTypeSpec *derivedTypeSpec{type_->AsDerived()}) {
7878
for (const auto &pair : derivedTypeSpec->parameters()) {
7979
hasDeferredTypeParameter_ |= pair.second.isDeferred();
8080
}
@@ -114,7 +114,7 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
114114
}
115115
info.gotTypeSpec = true;
116116
info.typeSpecLoc = parser::FindSourceLocation(*typeSpec);
117-
if (const DerivedTypeSpec * derived{info.typeSpec->AsDerived()}) {
117+
if (const DerivedTypeSpec *derived{info.typeSpec->AsDerived()}) {
118118
// C937
119119
if (auto it{FindCoarrayUltimateComponent(*derived)}) {
120120
context
@@ -224,8 +224,8 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
224224
}
225225
info.sourceExprRank = expr->Rank();
226226
info.sourceExprLoc = parserSourceExpr->source;
227-
if (const DerivedTypeSpec *
228-
derived{evaluate::GetDerivedTypeSpec(info.sourceExprType)}) {
227+
if (const DerivedTypeSpec *derived{
228+
evaluate::GetDerivedTypeSpec(info.sourceExprType)}) {
229229
// C949
230230
if (auto it{FindCoarrayUltimateComponent(*derived)}) {
231231
context
@@ -279,13 +279,13 @@ static std::optional<AllocateCheckerInfo> CheckAllocateOptions(
279279
// in this test.
280280
static bool IsTypeCompatible(
281281
const DeclTypeSpec &type1, const DerivedTypeSpec &derivedType2) {
282-
if (const DerivedTypeSpec * derivedType1{type1.AsDerived()}) {
282+
if (const DerivedTypeSpec *derivedType1{type1.AsDerived()}) {
283283
if (type1.category() == DeclTypeSpec::Category::TypeDerived) {
284284
return evaluate::AreSameDerivedTypeIgnoringTypeParameters(
285285
*derivedType1, derivedType2);
286286
} else if (type1.category() == DeclTypeSpec::Category::ClassDerived) {
287287
for (const DerivedTypeSpec *parent{&derivedType2}; parent;
288-
parent = parent->typeSymbol().GetParentTypeSpec()) {
288+
parent = parent->typeSymbol().GetParentTypeSpec()) {
289289
if (evaluate::AreSameDerivedTypeIgnoringTypeParameters(
290290
*derivedType1, *parent)) {
291291
return true;
@@ -303,13 +303,13 @@ static bool IsTypeCompatible(
303303
// cannot be allocatable (C709)
304304
return true;
305305
}
306-
if (const IntrinsicTypeSpec * intrinsicType2{type2.AsIntrinsic()}) {
307-
if (const IntrinsicTypeSpec * intrinsicType1{type1.AsIntrinsic()}) {
306+
if (const IntrinsicTypeSpec *intrinsicType2{type2.AsIntrinsic()}) {
307+
if (const IntrinsicTypeSpec *intrinsicType1{type1.AsIntrinsic()}) {
308308
return intrinsicType1->category() == intrinsicType2->category();
309309
} else {
310310
return false;
311311
}
312-
} else if (const DerivedTypeSpec * derivedType2{type2.AsDerived()}) {
312+
} else if (const DerivedTypeSpec *derivedType2{type2.AsDerived()}) {
313313
return IsTypeCompatible(type1, *derivedType2);
314314
}
315315
return false;
@@ -323,7 +323,7 @@ static bool IsTypeCompatible(
323323
return true;
324324
}
325325
if (type2.category() != evaluate::TypeCategory::Derived) {
326-
if (const IntrinsicTypeSpec * intrinsicType1{type1.AsIntrinsic()}) {
326+
if (const IntrinsicTypeSpec *intrinsicType1{type1.AsIntrinsic()}) {
327327
return intrinsicType1->category() == type2.category();
328328
} else {
329329
return false;
@@ -348,16 +348,16 @@ static bool HaveSameAssumedTypeParameters(
348348
}
349349
// It is possible to reach this if type1 is unlimited polymorphic
350350
return !type2LengthIsAssumed;
351-
} else if (const DerivedTypeSpec * derivedType2{type2.AsDerived()}) {
351+
} else if (const DerivedTypeSpec *derivedType2{type2.AsDerived()}) {
352352
int type2AssumedParametersCount{0};
353353
int type1AssumedParametersCount{0};
354354
for (const auto &pair : derivedType2->parameters()) {
355355
type2AssumedParametersCount += pair.second.isAssumed();
356356
}
357357
// type1 may be unlimited polymorphic
358-
if (const DerivedTypeSpec * derivedType1{type1.AsDerived()}) {
358+
if (const DerivedTypeSpec *derivedType1{type1.AsDerived()}) {
359359
for (auto it{derivedType1->parameters().begin()};
360-
it != derivedType1->parameters().end(); ++it) {
360+
it != derivedType1->parameters().end(); ++it) {
361361
if (it->second.isAssumed()) {
362362
++type1AssumedParametersCount;
363363
const ParamValue *param{derivedType2->FindParameter(it->first)};
@@ -378,8 +378,8 @@ static bool HaveSameAssumedTypeParameters(
378378

379379
static std::optional<std::int64_t> GetTypeParameterInt64Value(
380380
const Symbol &parameterSymbol, const DerivedTypeSpec &derivedType) {
381-
if (const ParamValue *
382-
paramValue{derivedType.FindParameter(parameterSymbol.name())}) {
381+
if (const ParamValue *paramValue{
382+
derivedType.FindParameter(parameterSymbol.name())}) {
383383
return evaluate::ToInt64(paramValue->GetExplicit());
384384
}
385385
return std::nullopt;
@@ -403,11 +403,11 @@ static bool HaveCompatibleTypeParameters(
403403
if (type1.category() == DeclTypeSpec::Category::ClassStar) {
404404
return true;
405405
}
406-
if (const IntrinsicTypeSpec * intrinsicType1{type1.AsIntrinsic()}) {
406+
if (const IntrinsicTypeSpec *intrinsicType1{type1.AsIntrinsic()}) {
407407
return evaluate::ToInt64(intrinsicType1->kind()).value() == type2.kind();
408408
} else if (type2.IsUnlimitedPolymorphic()) {
409409
return false;
410-
} else if (const DerivedTypeSpec * derivedType1{type1.AsDerived()}) {
410+
} else if (const DerivedTypeSpec *derivedType1{type1.AsDerived()}) {
411411
return HaveCompatibleTypeParameters(
412412
*derivedType1, type2.GetDerivedTypeSpec());
413413
} else {
@@ -419,10 +419,10 @@ static bool HaveCompatibleTypeParameters(
419419
const DeclTypeSpec &type1, const DeclTypeSpec &type2) {
420420
if (type1.category() == DeclTypeSpec::Category::ClassStar) {
421421
return true;
422-
} else if (const IntrinsicTypeSpec * intrinsicType1{type1.AsIntrinsic()}) {
422+
} else if (const IntrinsicTypeSpec *intrinsicType1{type1.AsIntrinsic()}) {
423423
const IntrinsicTypeSpec *intrinsicType2{type2.AsIntrinsic()};
424424
return !intrinsicType2 || intrinsicType1->kind() == intrinsicType2->kind();
425-
} else if (const DerivedTypeSpec * derivedType1{type1.AsDerived()}) {
425+
} else if (const DerivedTypeSpec *derivedType1{type1.AsDerived()}) {
426426
const DerivedTypeSpec *derivedType2{type2.AsDerived()};
427427
return !derivedType2 ||
428428
HaveCompatibleTypeParameters(*derivedType1, *derivedType2);
@@ -699,8 +699,7 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
699699
if (evaluate::IsCoarray(*ultimate_)) {
700700
if (allocateInfo_.gotTypeSpec) {
701701
// C938
702-
if (const DerivedTypeSpec *
703-
derived{allocateInfo_.typeSpec->AsDerived()}) {
702+
if (const DerivedTypeSpec *derived{allocateInfo_.typeSpec->AsDerived()}) {
704703
if (IsTeamType(derived)) {
705704
context
706705
.Say(allocateInfo_.typeSpecLoc.value(),
@@ -784,8 +783,8 @@ bool AllocationCheckerHelper::RunCoarrayRelatedChecks(
784783
return false;
785784
}
786785
}
787-
if (const parser::CoindexedNamedObject *
788-
coindexedObject{parser::GetCoindexedNamedObject(allocateObject_)}) {
786+
if (const parser::CoindexedNamedObject *coindexedObject{
787+
parser::GetCoindexedNamedObject(allocateObject_)}) {
789788
// C950
790789
context.Say(parser::FindSourceLocation(*coindexedObject),
791790
"Allocatable object must not be coindexed in ALLOCATE"_err_en_US);

flang/lib/Semantics/check-arithmeticif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct ArithmeticIfStmt;
1818
namespace Fortran::semantics {
1919
class ArithmeticIfStmtChecker : public virtual BaseChecker {
2020
public:
21-
ArithmeticIfStmtChecker(SemanticsContext &context) : context_(context){};
21+
ArithmeticIfStmtChecker(SemanticsContext &context) : context_(context) {}
2222
void Leave(const parser::ArithmeticIfStmt &);
2323

2424
private:

0 commit comments

Comments
 (0)