Skip to content

Commit 25b1b4b

Browse files
committed
Address review comments
1 parent 2ea14e0 commit 25b1b4b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

flang/include/flang/Parser/parse-tree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,6 +3470,7 @@ struct OmpDirectiveName {
34703470
constexpr OmpDirectiveName(const OmpDirectiveName &) = default;
34713471
// Construct from an already parsed text. Use Verbatim for this because
34723472
// Verbatim's source corresponds to an actual source location.
3473+
// This allows "construct<OmpDirectiveName>(Verbatim("<name>"))".
34733474
OmpDirectiveName(const Verbatim &name);
34743475
using WrapperTrait = std::true_type;
34753476
CharBlock source;

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace Fortran::parser {
2727
constexpr auto startOmpLine = skipStuffBeforeStatement >> "!$OMP "_sptok;
2828
constexpr auto endOmpLine = space >> endOfLine;
2929

30+
// Given a parser P for a wrapper class, invoke P, and if it succeeds return
31+
// the wrapped object.
3032
template <typename Parser> struct UnwrapParser {
3133
static_assert(
3234
Parser::resultType::WrapperTrait::value && "Wrapper class required");

flang/lib/Parser/parse-tree.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,17 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Name &x) {
256256
OmpDirectiveName::OmpDirectiveName(const Verbatim &name) {
257257
std::string_view nameView{name.source.begin(), name.source.size()};
258258
std::string nameLower{ToLowerCaseLetters(nameView)};
259-
// If the name was actually "unknown" then accept it, otherwise flag
260-
// OMPD_unknown (the default return value from getOpenMPDirectiveKind)
261-
// as an error.
262-
if (nameLower != "unknown") {
263-
v = llvm::omp::getOpenMPDirectiveKind(nameLower);
264-
assert(v != llvm::omp::Directive::OMPD_unknown && "Unrecognized directive");
265-
} else {
266-
v = llvm::omp::Directive::OMPD_unknown;
267-
}
259+
// The function getOpenMPDirectiveKind will return OMPD_unknown in two cases:
260+
// (1) if the given string doesn't match any actual directive, or
261+
// (2) if the given string was "unknown".
262+
// The Verbatim(<token>) parser will succeed as long as the given token
263+
// matches the source.
264+
// Since using "construct<OmpDirectiveName>(verbatim(...))" will succeed
265+
// if the verbatim parser succeeds, in order to get OMPD_unknown the
266+
// token given to Verbatim must be invalid. Because it's an internal issue
267+
// asserting is ok.
268+
v = llvm::omp::getOpenMPDirectiveKind(nameLower);
269+
assert(v != llvm::omp::Directive::OMPD_unknown && "Invalid directive name");
268270
source = name.source;
269271
}
270272

0 commit comments

Comments
 (0)