@@ -285,13 +285,9 @@ void OmpStructureChecker::Enter(const parser::OpenMPLoopConstruct &x) {
285285 }
286286 SetLoopInfo (x);
287287
288- auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t );
289- if (optLoopCons.has_value ()) {
290- if (const auto &doConstruct{
291- std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
292- const auto &doBlock{std::get<parser::Block>(doConstruct->t )};
293- CheckNoBranching (doBlock, beginName.v , beginName.source );
294- }
288+ if (const auto *doConstruct{x.GetNestedLoop ()}) {
289+ const auto &doBlock{std::get<parser::Block>(doConstruct->t )};
290+ CheckNoBranching (doBlock, beginName.v , beginName.source );
295291 }
296292 CheckLoopItrVariableIsInt (x);
297293 CheckAssociatedLoopConstraints (x);
@@ -314,46 +310,34 @@ const parser::Name OmpStructureChecker::GetLoopIndex(
314310}
315311
316312void OmpStructureChecker::SetLoopInfo (const parser::OpenMPLoopConstruct &x) {
317- auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t );
318- if (optLoopCons.has_value ()) {
319- if (const auto &loopConstruct{
320- std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
321- const parser::DoConstruct *loop{&*loopConstruct};
322- if (loop && loop->IsDoNormal ()) {
323- const parser::Name &itrVal{GetLoopIndex (loop)};
324- SetLoopIv (itrVal.symbol );
325- }
313+ if (const auto *loop{x.GetNestedLoop ()}) {
314+ if (loop->IsDoNormal ()) {
315+ const parser::Name &itrVal{GetLoopIndex (loop)};
316+ SetLoopIv (itrVal.symbol );
326317 }
327318 }
328319}
329320
330321void OmpStructureChecker::CheckLoopItrVariableIsInt (
331322 const parser::OpenMPLoopConstruct &x) {
332- auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t );
333- if (optLoopCons.has_value ()) {
334- if (const auto &loopConstruct{
335- std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
336-
337- for (const parser::DoConstruct *loop{&*loopConstruct}; loop;) {
338- if (loop->IsDoNormal ()) {
339- const parser::Name &itrVal{GetLoopIndex (loop)};
340- if (itrVal.symbol ) {
341- const auto *type{itrVal.symbol ->GetType ()};
342- if (!type->IsNumeric (TypeCategory::Integer)) {
343- context_.Say (itrVal.source ,
344- " The DO loop iteration"
345- " variable must be of the type integer." _err_en_US,
346- itrVal.ToString ());
347- }
348- }
323+ for (const parser::DoConstruct *loop{x.GetNestedLoop ()}; loop;) {
324+ if (loop->IsDoNormal ()) {
325+ const parser::Name &itrVal{GetLoopIndex (loop)};
326+ if (itrVal.symbol ) {
327+ const auto *type{itrVal.symbol ->GetType ()};
328+ if (!type->IsNumeric (TypeCategory::Integer)) {
329+ context_.Say (itrVal.source ,
330+ " The DO loop iteration"
331+ " variable must be of the type integer." _err_en_US,
332+ itrVal.ToString ());
349333 }
350- // Get the next DoConstruct if block is not empty.
351- const auto &block{std::get<parser::Block>(loop->t )};
352- const auto it{block.begin ()};
353- loop = it != block.end () ? parser::Unwrap<parser::DoConstruct>(*it)
354- : nullptr ;
355334 }
356335 }
336+ // Get the next DoConstruct if block is not empty.
337+ const auto &block{std::get<parser::Block>(loop->t )};
338+ const auto it{block.begin ()};
339+ loop =
340+ it != block.end () ? parser::Unwrap<parser::DoConstruct>(*it) : nullptr ;
357341 }
358342}
359343
@@ -417,29 +401,23 @@ void OmpStructureChecker::CheckDistLinear(
417401
418402 // Match the loop index variables with the collected symbols from linear
419403 // clauses.
420- auto &optLoopCons = std::get<std::optional<parser::NestedConstruct>>(x.t );
421- if (optLoopCons.has_value ()) {
422- if (const auto &loopConstruct{
423- std::get_if<parser::DoConstruct>(&*optLoopCons)}) {
424- for (const parser::DoConstruct *loop{&*loopConstruct}; loop;) {
425- if (loop->IsDoNormal ()) {
426- const parser::Name &itrVal{GetLoopIndex (loop)};
427- if (itrVal.symbol ) {
428- // Remove the symbol from the collected set
429- indexVars.erase (&itrVal.symbol ->GetUltimate ());
430- }
431- collapseVal--;
432- if (collapseVal == 0 ) {
433- break ;
434- }
435- }
436- // Get the next DoConstruct if block is not empty.
437- const auto &block{std::get<parser::Block>(loop->t )};
438- const auto it{block.begin ()};
439- loop = it != block.end () ? parser::Unwrap<parser::DoConstruct>(*it)
440- : nullptr ;
404+ for (const parser::DoConstruct *loop{x.GetNestedLoop ()}; loop;) {
405+ if (loop->IsDoNormal ()) {
406+ const parser::Name &itrVal{GetLoopIndex (loop)};
407+ if (itrVal.symbol ) {
408+ // Remove the symbol from the collected set
409+ indexVars.erase (&itrVal.symbol ->GetUltimate ());
410+ }
411+ collapseVal--;
412+ if (collapseVal == 0 ) {
413+ break ;
441414 }
442415 }
416+ // Get the next DoConstruct if block is not empty.
417+ const auto &block{std::get<parser::Block>(loop->t )};
418+ const auto it{block.begin ()};
419+ loop = it != block.end () ? parser::Unwrap<parser::DoConstruct>(*it)
420+ : nullptr ;
443421 }
444422
445423 // Show error for the remaining variables
0 commit comments