Skip to content

Commit b994a4c

Browse files
authored
[flang][NFC] Clean up code in two new functions (#142037)
Two recently-added functions in Semantics/tools.h need some cleaning up to conform to the coding style of the project. One of them should actually be in Parser/tools.{h,cpp}, the other doesn't need to be defined in the header.
1 parent 163c67a commit b994a4c

File tree

7 files changed

+32
-32
lines changed

7 files changed

+32
-32
lines changed

flang/include/flang/Parser/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,8 @@ template <typename A> std::optional<CharBlock> GetLastSource(A &x) {
250250
return GetSourceHelper<false>::GetSource(const_cast<const A &>(x));
251251
}
252252

253+
// Checks whether the assignment statement has a single variable on the RHS.
254+
bool CheckForSingleVariableOnRHS(const AssignmentStmt &);
255+
253256
} // namespace Fortran::parser
254257
#endif // FORTRAN_PARSER_TOOLS_H_

flang/include/flang/Semantics/tools.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -756,29 +756,7 @@ std::string GetCommonBlockObjectName(const Symbol &, bool underscoring);
756756
// Check for ambiguous USE associations
757757
bool HadUseError(SemanticsContext &, SourceName at, const Symbol *);
758758

759-
/// Checks if the assignment statement has a single variable on the RHS.
760-
inline bool checkForSingleVariableOnRHS(
761-
const Fortran::parser::AssignmentStmt &assignmentStmt) {
762-
const Fortran::parser::Expr &expr{
763-
std::get<Fortran::parser::Expr>(assignmentStmt.t)};
764-
const Fortran::common::Indirection<Fortran::parser::Designator> *designator =
765-
std::get_if<Fortran::common::Indirection<Fortran::parser::Designator>>(
766-
&expr.u);
767-
return designator != nullptr;
768-
}
769-
770-
/// Checks if the symbol on the LHS is present in the RHS expression.
771-
inline bool checkForSymbolMatch(const Fortran::semantics::SomeExpr *lhs,
772-
const Fortran::semantics::SomeExpr *rhs) {
773-
auto lhsSyms{Fortran::evaluate::GetSymbolVector(*lhs)};
774-
const Fortran::semantics::Symbol &lhsSymbol{*lhsSyms.front()};
775-
for (const Fortran::semantics::Symbol &symbol :
776-
Fortran::evaluate::GetSymbolVector(*rhs)) {
777-
if (lhsSymbol == symbol) {
778-
return true;
779-
}
780-
}
781-
return false;
782-
}
759+
// Checks whether the symbol on the LHS is present in the RHS expression.
760+
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs);
783761
} // namespace Fortran::semantics
784762
#endif // FORTRAN_SEMANTICS_TOOLS_H_

flang/lib/Lower/OpenACC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ void genAtomicCapture(Fortran::lower::AbstractConverter &converter,
653653
firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0)));
654654
mlir::Block &block = atomicCaptureOp->getRegion(0).back();
655655
firOpBuilder.setInsertionPointToStart(&block);
656-
if (Fortran::semantics::checkForSingleVariableOnRHS(stmt1)) {
657-
if (Fortran::semantics::checkForSymbolMatch(
656+
if (Fortran::parser::CheckForSingleVariableOnRHS(stmt1)) {
657+
if (Fortran::semantics::CheckForSymbolMatch(
658658
Fortran::semantics::GetExpr(stmt2Var),
659659
Fortran::semantics::GetExpr(stmt2Expr))) {
660660
// Atomic capture construct is of the form [capture-stmt, update-stmt]

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,8 +3200,8 @@ static void genAtomicCapture(lower::AbstractConverter &converter,
32003200
firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0)));
32013201
mlir::Block &block = atomicCaptureOp->getRegion(0).back();
32023202
firOpBuilder.setInsertionPointToStart(&block);
3203-
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
3204-
if (semantics::checkForSymbolMatch(semantics::GetExpr(stmt2Var),
3203+
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
3204+
if (semantics::CheckForSymbolMatch(semantics::GetExpr(stmt2Var),
32053205
semantics::GetExpr(stmt2Expr))) {
32063206
// Atomic capture construct is of the form [capture-stmt, update-stmt]
32073207
const semantics::SomeExpr &fromExpr = *semantics::GetExpr(stmt1Expr);

flang/lib/Parser/tools.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,9 @@ const CoindexedNamedObject *GetCoindexedNamedObject(
174174
},
175175
allocateObject.u);
176176
}
177+
178+
bool CheckForSingleVariableOnRHS(const AssignmentStmt &assignmentStmt) {
179+
return Unwrap<Designator>(std::get<Expr>(assignmentStmt.t)) != nullptr;
180+
}
181+
177182
} // namespace Fortran::parser

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,9 +2933,9 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
29332933
const auto *e2 = GetExpr(context_, stmt2Expr);
29342934

29352935
if (e1 && v1 && e2 && v2) {
2936-
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
2936+
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
29372937
CheckAtomicCaptureStmt(stmt1);
2938-
if (semantics::checkForSymbolMatch(v2, e2)) {
2938+
if (CheckForSymbolMatch(v2, e2)) {
29392939
// ATOMIC CAPTURE construct is of the form [capture-stmt, update-stmt]
29402940
CheckAtomicUpdateStmt(stmt2);
29412941
} else {
@@ -2947,8 +2947,8 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
29472947
"Captured variable/array element/derived-type component %s expected to be assigned in the second statement of ATOMIC CAPTURE construct"_err_en_US,
29482948
stmt1Expr.source);
29492949
}
2950-
} else if (semantics::checkForSymbolMatch(v1, e1) &&
2951-
semantics::checkForSingleVariableOnRHS(stmt2)) {
2950+
} else if (CheckForSymbolMatch(v1, e1) &&
2951+
parser::CheckForSingleVariableOnRHS(stmt2)) {
29522952
// ATOMIC CAPTURE construct is of the form [update-stmt, capture-stmt]
29532953
CheckAtomicUpdateStmt(stmt1);
29542954
CheckAtomicCaptureStmt(stmt2);

flang/lib/Semantics/tools.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,4 +1788,18 @@ bool HadUseError(
17881788
}
17891789
}
17901790

1791+
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs) {
1792+
if (lhs && rhs) {
1793+
if (SymbolVector lhsSymbols{evaluate::GetSymbolVector(*lhs)};
1794+
!lhsSymbols.empty()) {
1795+
const Symbol &first{*lhsSymbols.front()};
1796+
for (const Symbol &symbol : evaluate::GetSymbolVector(*rhs)) {
1797+
if (first == symbol) {
1798+
return true;
1799+
}
1800+
}
1801+
}
1802+
}
1803+
return false;
1804+
}
17911805
} // namespace Fortran::semantics

0 commit comments

Comments
 (0)