[clang] [OpenACC] Implement 'default' clause parsing. (PR #77002)

via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 23:57:56 PST 2024


================
@@ -291,13 +307,63 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
   return DirKind;
 }
 
+bool ClauseHasRequiredParens(OpenACCClauseKind Kind) {
+  return Kind == OpenACCClauseKind::Default;
+}
+
+bool ParseOpenACCClauseParams(Parser &P, OpenACCClauseKind Kind) {
+  BalancedDelimiterTracker Parens(P, tok::l_paren,
+                                  tok::annot_pragma_openacc_end);
+
+  if (ClauseHasRequiredParens(Kind)) {
+    if (Parens.expectAndConsume()) {
+      // We are missing a paren, so assume that the person just forgot the
+      // parameter.  Return 'false' so we try to continue on and parse the next
+      // clause.
+      P.SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openacc_end,
+                  Parser::StopBeforeMatch);
+      return false;
+    }
+
+    switch (Kind) {
+    case OpenACCClauseKind::Default: {
+      Token DefKindTok = P.getCurToken();
+      // 'default' accepts 'present' or 'none'. Be a little liberal here to
+      // allow things like 'auto' or 'default'.
+      // TODO ERICH: Make 'keyword like tokens' via tok::getKeywordSpelling'
+      // or 'getIdentifierInfo' isKeyword
+      if (!DefKindTok.is(tok::identifier) &&
+          (DefKindTok.isAnnotation() || !DefKindTok.getIdentifierInfo() ||
+           !DefKindTok.getIdentifierInfo()->isKeyword(P.getLangOpts()))) {
+        P.Diag(P.getCurToken(), diag::err_expected) << tok::identifier;
+        break;
+      }
----------------
cor3ntin wrote:

I think `!DefKindTok.is(tok::identifier)` is sufficient here.
A keyword isn't an identifier (even if the both return getIdentifierInfo)  

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


More information about the cfe-commits mailing list