[clang] [OpenACC] Implement compound construct parsing (PR #72692)

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 17 13:09:34 PST 2023


================
@@ -50,6 +52,35 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   if (DirKind == OpenACCDirectiveKind::Invalid)
     P.Diag(FirstTok, diag::err_acc_invalid_directive) << FirstTokSpelling;
 
+  // Combined Constructs allows parallel loop, serial loop, or kernels loop. Any
+  // other attempt at a combined construct will be diagnosed as an invalid
+  // clause.
+  Token SecondTok = P.getCurToken();
+  switch (DirKind) {
+  default:
+    // Nothing to do except in the below cases, as they should be diagnosed as
+    // a clause.
+    break;
+  case OpenACCDirectiveKind::Parallel:
+    if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+      P.ConsumeToken();
+      return OpenACCDirectiveKind::ParallelLoop;
+    }
+    break;
+  case OpenACCDirectiveKind::Serial:
+    if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+      P.ConsumeToken();
+      return OpenACCDirectiveKind::SerialLoop;
+    }
+    break;
+  case OpenACCDirectiveKind::Kernels:
+    if (P.getPreprocessor().getSpelling(SecondTok) == "loop") {
+      P.ConsumeToken();
+      return OpenACCDirectiveKind::KernelsLoop;
+    }
+    break;
+  }
----------------
alexey-bataev wrote:

```suggestion
if (GetOpenACCDirectiveKind(P.getPreprocessor().getSpelling(SecondTok)) == OpenACCDirectiveKind::Loop) {
  P.ConsumeToken();
  switch (DirKind) {
  default:
    // error??
    break;
  case OpenACCDirectiveKind::Parallel:
    return OpenACCDirectiveKind::ParallelLoop;
  case OpenACCDirectiveKind::Serial:
    return OpenACCDirectiveKind::SerialLoop;
  case OpenACCDirectiveKind::Kernels:
    return OpenACCDirectiveKind::KernelsLoop;
  }
}

```

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


More information about the cfe-commits mailing list