[clang] [OpenACC] Add 'clause' parsing infrastructure plus a few clauses (PR #75052)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 07:16:12 PST 2023


================
@@ -69,6 +69,29 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(Token Tok) {
       .Default(OpenACCDirectiveKindEx::Invalid);
 }
 
+// Translate single-token string representations to the OpenCC Clause Kind.
+OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
+  // auto is a keyword in some language modes, so make sure we parse it
+  // correctly.
+  if (Tok.is(tok::kw_auto))
+    return OpenACCClauseKind::Auto;
+
+  if (!Tok.is(tok::identifier))
+    return OpenACCClauseKind::Invalid;
+
+  return llvm::StringSwitch<OpenACCClauseKind>(
+             Tok.getIdentifierInfo()->getName())
+      .Case("finalize", OpenACCClauseKind::Finalize)
+      .Case("if_present", OpenACCClauseKind::IfPresent)
+      .Case("seq", OpenACCClauseKind::Seq)
+      .Case("independent", OpenACCClauseKind::Independent)
+      .Case("auto", OpenACCClauseKind::Auto)
+      .Case("worker", OpenACCClauseKind::Worker)
+      .Case("vector", OpenACCClauseKind::Vector)
+      .Case("nohost", OpenACCClauseKind::NoHost)
+      .Default(OpenACCClauseKind::Invalid);
+}
----------------
erichkeane wrote:

Sure! Done.

https://github.com/llvm/llvm-project/pull/75052


More information about the cfe-commits mailing list