[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.
This commit is contained in:
Peter Klausler
2025-06-10 14:44:41 -07:00
committed by GitHub
parent 163c67ad3d
commit b994a4c04f
7 changed files with 32 additions and 32 deletions

View File

@@ -250,5 +250,8 @@ template <typename A> std::optional<CharBlock> GetLastSource(A &x) {
return GetSourceHelper<false>::GetSource(const_cast<const A &>(x));
}
// Checks whether the assignment statement has a single variable on the RHS.
bool CheckForSingleVariableOnRHS(const AssignmentStmt &);
} // namespace Fortran::parser
#endif // FORTRAN_PARSER_TOOLS_H_

View File

@@ -756,29 +756,7 @@ std::string GetCommonBlockObjectName(const Symbol &, bool underscoring);
// Check for ambiguous USE associations
bool HadUseError(SemanticsContext &, SourceName at, const Symbol *);
/// Checks if the assignment statement has a single variable on the RHS.
inline bool checkForSingleVariableOnRHS(
const Fortran::parser::AssignmentStmt &assignmentStmt) {
const Fortran::parser::Expr &expr{
std::get<Fortran::parser::Expr>(assignmentStmt.t)};
const Fortran::common::Indirection<Fortran::parser::Designator> *designator =
std::get_if<Fortran::common::Indirection<Fortran::parser::Designator>>(
&expr.u);
return designator != nullptr;
}
/// Checks if the symbol on the LHS is present in the RHS expression.
inline bool checkForSymbolMatch(const Fortran::semantics::SomeExpr *lhs,
const Fortran::semantics::SomeExpr *rhs) {
auto lhsSyms{Fortran::evaluate::GetSymbolVector(*lhs)};
const Fortran::semantics::Symbol &lhsSymbol{*lhsSyms.front()};
for (const Fortran::semantics::Symbol &symbol :
Fortran::evaluate::GetSymbolVector(*rhs)) {
if (lhsSymbol == symbol) {
return true;
}
}
return false;
}
// Checks whether the symbol on the LHS is present in the RHS expression.
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs);
} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_TOOLS_H_

View File

@@ -653,8 +653,8 @@ void genAtomicCapture(Fortran::lower::AbstractConverter &converter,
firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0)));
mlir::Block &block = atomicCaptureOp->getRegion(0).back();
firOpBuilder.setInsertionPointToStart(&block);
if (Fortran::semantics::checkForSingleVariableOnRHS(stmt1)) {
if (Fortran::semantics::checkForSymbolMatch(
if (Fortran::parser::CheckForSingleVariableOnRHS(stmt1)) {
if (Fortran::semantics::CheckForSymbolMatch(
Fortran::semantics::GetExpr(stmt2Var),
Fortran::semantics::GetExpr(stmt2Expr))) {
// Atomic capture construct is of the form [capture-stmt, update-stmt]

View File

@@ -3200,8 +3200,8 @@ static void genAtomicCapture(lower::AbstractConverter &converter,
firOpBuilder.createBlock(&(atomicCaptureOp->getRegion(0)));
mlir::Block &block = atomicCaptureOp->getRegion(0).back();
firOpBuilder.setInsertionPointToStart(&block);
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
if (semantics::checkForSymbolMatch(semantics::GetExpr(stmt2Var),
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
if (semantics::CheckForSymbolMatch(semantics::GetExpr(stmt2Var),
semantics::GetExpr(stmt2Expr))) {
// Atomic capture construct is of the form [capture-stmt, update-stmt]
const semantics::SomeExpr &fromExpr = *semantics::GetExpr(stmt1Expr);

View File

@@ -174,4 +174,9 @@ const CoindexedNamedObject *GetCoindexedNamedObject(
},
allocateObject.u);
}
bool CheckForSingleVariableOnRHS(const AssignmentStmt &assignmentStmt) {
return Unwrap<Designator>(std::get<Expr>(assignmentStmt.t)) != nullptr;
}
} // namespace Fortran::parser

View File

@@ -2933,9 +2933,9 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
const auto *e2 = GetExpr(context_, stmt2Expr);
if (e1 && v1 && e2 && v2) {
if (semantics::checkForSingleVariableOnRHS(stmt1)) {
if (parser::CheckForSingleVariableOnRHS(stmt1)) {
CheckAtomicCaptureStmt(stmt1);
if (semantics::checkForSymbolMatch(v2, e2)) {
if (CheckForSymbolMatch(v2, e2)) {
// ATOMIC CAPTURE construct is of the form [capture-stmt, update-stmt]
CheckAtomicUpdateStmt(stmt2);
} else {
@@ -2947,8 +2947,8 @@ void OmpStructureChecker::CheckAtomicCaptureConstruct(
"Captured variable/array element/derived-type component %s expected to be assigned in the second statement of ATOMIC CAPTURE construct"_err_en_US,
stmt1Expr.source);
}
} else if (semantics::checkForSymbolMatch(v1, e1) &&
semantics::checkForSingleVariableOnRHS(stmt2)) {
} else if (CheckForSymbolMatch(v1, e1) &&
parser::CheckForSingleVariableOnRHS(stmt2)) {
// ATOMIC CAPTURE construct is of the form [update-stmt, capture-stmt]
CheckAtomicUpdateStmt(stmt1);
CheckAtomicCaptureStmt(stmt2);

View File

@@ -1788,4 +1788,18 @@ bool HadUseError(
}
}
bool CheckForSymbolMatch(const SomeExpr *lhs, const SomeExpr *rhs) {
if (lhs && rhs) {
if (SymbolVector lhsSymbols{evaluate::GetSymbolVector(*lhs)};
!lhsSymbols.empty()) {
const Symbol &first{*lhsSymbols.front()};
for (const Symbol &symbol : evaluate::GetSymbolVector(*rhs)) {
if (first == symbol) {
return true;
}
}
}
}
return false;
}
} // namespace Fortran::semantics