@@ -282,7 +282,7 @@ class ParseTreeAnalyzer {
282
282
constructNames_.emplace_back (optionalName->ToString ());
283
283
}
284
284
// Allow FORTRAN '66 extended DO ranges
285
- PushScope (). isExteriorGotoFatal = false ;
285
+ PushScope (false ) ;
286
286
// Process labels of the DO and END DO statements, but not the
287
287
// statements themselves, so that a non-construct END DO
288
288
// can be distinguished (below).
@@ -302,7 +302,7 @@ class ParseTreeAnalyzer {
302
302
bool Pre (const parser::IfConstruct &ifConstruct) {
303
303
return PushConstructName (ifConstruct);
304
304
}
305
- void Post (const parser::IfThenStmt &) { PushScope (); }
305
+ void Post (const parser::IfThenStmt &) { PushScope (false ); }
306
306
bool Pre (const parser::IfConstruct::ElseIfBlock &) {
307
307
return SwitchToNewScope ();
308
308
}
@@ -316,19 +316,19 @@ class ParseTreeAnalyzer {
316
316
bool Pre (const parser::CaseConstruct &caseConstruct) {
317
317
return PushConstructName (caseConstruct);
318
318
}
319
- void Post (const parser::SelectCaseStmt &) { PushScope (); }
319
+ void Post (const parser::SelectCaseStmt &) { PushScope (false ); }
320
320
bool Pre (const parser::CaseConstruct::Case &) { return SwitchToNewScope (); }
321
321
bool Pre (const parser::SelectRankConstruct &selectRankConstruct) {
322
322
return PushConstructName (selectRankConstruct);
323
323
}
324
- void Post (const parser::SelectRankStmt &) { PushScope (); }
324
+ void Post (const parser::SelectRankStmt &) { PushScope (true ); }
325
325
bool Pre (const parser::SelectRankConstruct::RankCase &) {
326
326
return SwitchToNewScope ();
327
327
}
328
328
bool Pre (const parser::SelectTypeConstruct &selectTypeConstruct) {
329
329
return PushConstructName (selectTypeConstruct);
330
330
}
331
- void Post (const parser::SelectTypeStmt &) { PushScope (); }
331
+ void Post (const parser::SelectTypeStmt &) { PushScope (true ); }
332
332
bool Pre (const parser::SelectTypeConstruct::TypeCase &) {
333
333
return SwitchToNewScope ();
334
334
}
@@ -580,19 +580,20 @@ class ParseTreeAnalyzer {
580
580
SemanticsContext &ErrorHandler () { return context_; }
581
581
582
582
private:
583
- ScopeInfo &PushScope () {
583
+ ScopeInfo &PushScope (bool isExteriorGotoFatal ) {
584
584
auto &model{programUnits_.back ().scopeModel };
585
585
int newDepth{model.empty () ? 1 : model[currentScope_].depth + 1 };
586
586
ScopeInfo &result{model.emplace_back ()};
587
587
result.parent = currentScope_;
588
588
result.depth = newDepth;
589
+ result.isExteriorGotoFatal = isExteriorGotoFatal;
589
590
currentScope_ = model.size () - 1 ;
590
591
return result;
591
592
}
592
593
bool InitializeNewScopeContext () {
593
594
programUnits_.emplace_back (UnitAnalysis{});
594
595
currentScope_ = 0u ;
595
- PushScope ();
596
+ PushScope (false );
596
597
return true ;
597
598
}
598
599
ScopeInfo &PopScope () {
@@ -604,9 +605,7 @@ class ParseTreeAnalyzer {
604
605
return programUnits_.back ().scopeModel [currentScope_].parent ;
605
606
}
606
607
bool SwitchToNewScope () {
607
- ScopeInfo &oldScope{PopScope ()};
608
- bool isExteriorGotoFatal{oldScope.isExteriorGotoFatal };
609
- PushScope ().isExteriorGotoFatal = isExteriorGotoFatal;
608
+ PushScope (PopScope ().isExteriorGotoFatal );
610
609
return true ;
611
610
}
612
611
@@ -617,10 +616,9 @@ class ParseTreeAnalyzer {
617
616
}
618
617
// Gotos into this construct from outside it are diagnosed, and
619
618
// are fatal unless the construct is a DO, IF, or SELECT CASE.
620
- PushScope ().isExteriorGotoFatal =
621
- !(std::is_same_v<A, parser::DoConstruct> ||
622
- std::is_same_v<A, parser::IfConstruct> ||
623
- std::is_same_v<A, parser::CaseConstruct>);
619
+ PushScope (!(std::is_same_v<A, parser::DoConstruct> ||
620
+ std::is_same_v<A, parser::IfConstruct> ||
621
+ std::is_same_v<A, parser::CaseConstruct>));
624
622
return true ;
625
623
}
626
624
bool PushConstructName (const parser::BlockConstruct &blockConstruct) {
@@ -630,7 +628,7 @@ class ParseTreeAnalyzer {
630
628
if (optionalName) {
631
629
constructNames_.emplace_back (optionalName->ToString ());
632
630
}
633
- PushScope (). isExteriorGotoFatal = true ;
631
+ PushScope (true ) ;
634
632
return true ;
635
633
}
636
634
template <typename A> void PopConstructNameIfPresent (const A &a) {
0 commit comments