Skip to content

Commit 9747be7

Browse files
committed
[flang][NFC] Clean up code in two new functions
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 f20423f commit 9747be7

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
@@ -753,29 +753,7 @@ std::string GetCommonBlockObjectName(const Symbol &, bool underscoring);
753753
// Check for ambiguous USE associations
754754
bool HadUseError(SemanticsContext &, SourceName at, const Symbol *);
755755

756-
/// Checks if the assignment statement has a single variable on the RHS.
757-
inline bool checkForSingleVariableOnRHS(
758-
const Fortran::parser::AssignmentStmt &assignmentStmt) {
759-
const Fortran::parser::Expr &expr{
760-
std::get<Fortran::parser::Expr>(assignmentStmt.t)};
761-
const Fortran::common::Indirection<Fortran::parser::Designator> *designator =
762-
std::get_if<Fortran::common::Indirection<Fortran::parser::Designator>>(
763-
&expr.u);
764-
return designator != nullptr;
765-
}
766-
767-
/// Checks if the symbol on the LHS is present in the RHS expression.
768-
inline bool checkForSymbolMatch(const Fortran::semantics::SomeExpr *lhs,
769-
const Fortran::semantics::SomeExpr *rhs) {
770-
auto lhsSyms{Fortran::evaluate::GetSymbolVector(*lhs)};
771-
const Fortran::semantics::Symbol &lhsSymbol{*lhsSyms.front()};
772-
for (const Fortran::semantics::Symbol &symbol :
773-
Fortran::evaluate::GetSymbolVector(*rhs)) {
774-
if (lhsSymbol == symbol) {
775-
return true;
776-
}
777-
}
778-
return false;
779-
}
756+
// Checks whether the symbol on the LHS is present in the RHS expression.
757+
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs);
780758
} // namespace Fortran::semantics
781759
#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
@@ -3199,8 +3199,8 @@ static void genAtomicCapture(lower::AbstractConverter &converter,
31993199
firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0)));
32003200
mlir::Block &block = atomicCaptureOp->getRegion(0).back();
32013201
firOpBuilder.setInsertionPointToStart(&block);
3202-
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
3203-
if (semantics::checkForSymbolMatch(semantics::GetExpr(stmt2Var),
3202+
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
3203+
if (semantics::CheckForSymbolMatch(semantics::GetExpr(stmt2Var),
32043204
semantics::GetExpr(stmt2Expr))) {
32053205
// Atomic capture construct is of the form [capture-stmt, update-stmt]
32063206
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
@@ -2922,9 +2922,9 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
29222922
const auto *e2 = GetExpr(context_, stmt2Expr);
29232923

29242924
if (e1 && v1 && e2 && v2) {
2925-
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
2925+
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
29262926
CheckAtomicCaptureStmt(stmt1);
2927-
if (semantics::checkForSymbolMatch(v2, e2)) {
2927+
if (CheckForSymbolMatch(v2, e2)) {
29282928
// ATOMIC CAPTURE construct is of the form [capture-stmt, update-stmt]
29292929
CheckAtomicUpdateStmt(stmt2);
29302930
} else {
@@ -2936,8 +2936,8 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
29362936
"Captured variable/array element/derived-type component %s expected to be assigned in the second statement of ATOMIC CAPTURE construct"_err_en_US,
29372937
stmt1Expr.source);
29382938
}
2939-
} else if (semantics::checkForSymbolMatch(v1, e1) &&
2940-
semantics::checkForSingleVariableOnRHS(stmt2)) {
2939+
} else if (CheckForSymbolMatch(v1, e1) &&
2940+
parser::CheckForSingleVariableOnRHS(stmt2)) {
29412941
// ATOMIC CAPTURE construct is of the form [update-stmt, capture-stmt]
29422942
CheckAtomicUpdateStmt(stmt1);
29432943
CheckAtomicCaptureStmt(stmt2);

flang/lib/Semantics/tools.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,4 +1756,18 @@ bool HadUseError(
17561756
}
17571757
}
17581758

1759+
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs) {
1760+
if (lhs && rhs) {
1761+
if (SymbolVector lhsSymbols{evaluate::GetSymbolVector(*lhs)};
1762+
!lhsSymbols.empty()) {
1763+
const Symbol &first{*lhsSymbols.front()};
1764+
for (const Symbol &symbol : evaluate::GetSymbolVector(*rhs)) {
1765+
if (first == symbol) {
1766+
return true;
1767+
}
1768+
}
1769+
}
1770+
}
1771+
return false;
1772+
}
17591773
} // namespace Fortran::semantics

0 commit comments

Comments
 (0)