#include "flang/Common/enum-set.h"
#include "flang/Semantics/semantics.h"
#include "flang/Semantics/tools.h"
-
#include <unordered_map>
namespace Fortran::semantics {
template <typename T> bool Pre(const parser::Statement<T> &statement) {
currentStatementSourcePosition_ = statement.source;
+ if (statement.label.has_value()) {
+ labels_.insert(*statement.label);
+ }
return true;
}
}
void Post(const parser::StopStmt &) { EmitBranchOutError("STOP"); }
+ std::set<parser::Label> labels() { return labels_; }
+
private:
parser::MessageFormattedText GetEnclosingMsg() const {
return {"Enclosing %s construct"_en_US, upperCaseDirName_};
parser::CharBlock sourcePosition_;
std::string upperCaseDirName_;
D currentDirective_;
+ std::set<parser::Label> labels_;
};
// Generic structure checker for directives/clauses language such as OpenMP
SayNotMatching(beginDir.source, endDir.source);
}
}
+ // Check illegal branching out of `Parser::Block` for `Parser::Name` based
+ // nodes (examples `Parser::ExitStmt`) along with `Parser::Label`
+ // based nodes (example `Parser::GotoStmt`).
void CheckNoBranching(const parser::Block &block, D directive,
const parser::CharBlock &directiveSource);
NoBranchingEnforce<D> noBranchingEnforce{
context_, directiveSource, directive, ContextDirectiveAsFortran()};
parser::Walk(block, noBranchingEnforce);
+
+ LabelEnforce directiveLabelEnforce{context_, noBranchingEnforce.labels(),
+ directiveSource,
+ parser::ToUpperCaseLetters(getDirectiveName(directive).str()).c_str()};
+ parser::Walk(block, directiveLabelEnforce);
}
// Check that only clauses included in the given set are present after the given
CheckMatching<parser::OmpBlockDirective>(beginDir, endDir);
PushContextAndClauseSets(beginDir.source, beginDir.v);
-
- switch (beginDir.v) {
- case llvm::omp::OMPD_parallel:
- CheckNoBranching(block, llvm::omp::OMPD_parallel, beginDir.source);
- break;
- default:
- break;
- }
+ CheckNoBranching(block, beginDir.v, beginDir.source);
}
void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {