@@ -90,6 +90,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
9090 return llvm::StringSwitch<OpenACCClauseKind>(
9191 Tok.getIdentifierInfo ()->getName ())
9292 .Case (" auto" , OpenACCClauseKind::Auto)
93+ .Case (" copy" , OpenACCClauseKind::Copy)
9394 .Case (" default" , OpenACCClauseKind::Default)
9495 .Case (" finalize" , OpenACCClauseKind::Finalize)
9596 .Case (" if" , OpenACCClauseKind::If)
@@ -334,7 +335,8 @@ bool ClauseHasOptionalParens(OpenACCClauseKind Kind) {
334335}
335336
336337bool ClauseHasRequiredParens (OpenACCClauseKind Kind) {
337- return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If;
338+ return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If ||
339+ Kind == OpenACCClauseKind::Copy;
338340}
339341
340342ExprResult ParseOpenACCConditionalExpr (Parser &P) {
@@ -345,43 +347,124 @@ ExprResult ParseOpenACCConditionalExpr(Parser &P) {
345347 return P.getActions ().CorrectDelayedTyposInExpr (P.ParseExpression ());
346348}
347349
348- bool ParseOpenACCClauseParams (Parser &P, OpenACCClauseKind Kind) {
349- BalancedDelimiterTracker Parens (P, tok::l_paren,
350+ // Skip until we see the end of pragma token, but don't consume it. This is us
351+ // just giving up on the rest of the pragma so we can continue executing. We
352+ // have to do this because 'SkipUntil' considers paren balancing, which isn't
353+ // what we want.
354+ void SkipUntilEndOfDirective (Parser &P) {
355+ while (P.getCurToken ().isNot (tok::annot_pragma_openacc_end))
356+ P.ConsumeAnyToken ();
357+ }
358+
359+ } // namespace
360+
361+ // OpenACC 3.3, section 1.7:
362+ // To simplify the specification and convey appropriate constraint information,
363+ // a pqr-list is a comma-separated list of pdr items. The one exception is a
364+ // clause-list, which is a list of one or more clauses optionally separated by
365+ // commas.
366+ void Parser::ParseOpenACCClauseList () {
367+ bool FirstClause = true ;
368+ while (getCurToken ().isNot (tok::annot_pragma_openacc_end)) {
369+ // Comma is optional in a clause-list.
370+ if (!FirstClause && getCurToken ().is (tok::comma))
371+ ConsumeToken ();
372+ FirstClause = false ;
373+
374+ // Recovering from a bad clause is really difficult, so we just give up on
375+ // error.
376+ if (ParseOpenACCClause ()) {
377+ SkipUntilEndOfDirective (*this );
378+ return ;
379+ }
380+ }
381+ }
382+
383+ bool Parser::ParseOpenACCClauseVarList (OpenACCClauseKind Kind) {
384+ // FIXME: Future clauses will require 'special word' parsing, check for one,
385+ // then parse it based on whether it is a clause that requires a 'special
386+ // word'.
387+ (void )Kind;
388+
389+ // If the var parsing fails, skip until the end of the directive as this is
390+ // an expression and gets messy if we try to continue otherwise.
391+ if (ParseOpenACCVar ())
392+ return true ;
393+
394+ while (!getCurToken ().isOneOf (tok::r_paren, tok::annot_pragma_openacc_end)) {
395+ ExpectAndConsume (tok::comma);
396+
397+ // If the var parsing fails, skip until the end of the directive as this is
398+ // an expression and gets messy if we try to continue otherwise.
399+ if (ParseOpenACCVar ())
400+ return true ;
401+ }
402+ return false ;
403+ }
404+ // The OpenACC Clause List is a comma or space-delimited list of clauses (see
405+ // the comment on ParseOpenACCClauseList). The concept of a 'clause' doesn't
406+ // really have its owner grammar and each individual one has its own definition.
407+ // However, they all are named with a single-identifier (or auto/default!)
408+ // token, followed in some cases by either braces or parens.
409+ bool Parser::ParseOpenACCClause () {
410+ // A number of clause names are actually keywords, so accept a keyword that
411+ // can be converted to a name.
412+ if (expectIdentifierOrKeyword (*this ))
413+ return true ;
414+
415+ OpenACCClauseKind Kind = getOpenACCClauseKind (getCurToken ());
416+
417+ if (Kind == OpenACCClauseKind::Invalid)
418+ return Diag (getCurToken (), diag::err_acc_invalid_clause)
419+ << getCurToken ().getIdentifierInfo ();
420+
421+ // Consume the clause name.
422+ ConsumeToken ();
423+
424+ return ParseOpenACCClauseParams (Kind);
425+ }
426+
427+ bool Parser::ParseOpenACCClauseParams (OpenACCClauseKind Kind) {
428+ BalancedDelimiterTracker Parens (*this , tok::l_paren,
350429 tok::annot_pragma_openacc_end);
351430
352431 if (ClauseHasRequiredParens (Kind)) {
353432 if (Parens.expectAndConsume ()) {
354433 // We are missing a paren, so assume that the person just forgot the
355434 // parameter. Return 'false' so we try to continue on and parse the next
356435 // clause.
357- P. SkipUntil (tok::comma, tok::r_paren, tok::annot_pragma_openacc_end,
358- Parser::StopBeforeMatch);
436+ SkipUntil (tok::comma, tok::r_paren, tok::annot_pragma_openacc_end,
437+ Parser::StopBeforeMatch);
359438 return false ;
360439 }
361440
362441 switch (Kind) {
363442 case OpenACCClauseKind::Default: {
364- Token DefKindTok = P. getCurToken ();
443+ Token DefKindTok = getCurToken ();
365444
366- if (expectIdentifierOrKeyword (P ))
445+ if (expectIdentifierOrKeyword (* this ))
367446 break ;
368447
369- P. ConsumeToken ();
448+ ConsumeToken ();
370449
371450 if (getOpenACCDefaultClauseKind (DefKindTok) ==
372451 OpenACCDefaultClauseKind::Invalid)
373- P. Diag (DefKindTok, diag::err_acc_invalid_default_clause_kind);
452+ Diag (DefKindTok, diag::err_acc_invalid_default_clause_kind);
374453
375454 break ;
376455 }
377456 case OpenACCClauseKind::If: {
378- ExprResult CondExpr = ParseOpenACCConditionalExpr (P );
457+ ExprResult CondExpr = ParseOpenACCConditionalExpr (* this );
379458 // An invalid expression can be just about anything, so just give up on
380459 // this clause list.
381460 if (CondExpr.isInvalid ())
382461 return true ;
383462 break ;
384463 }
464+ case OpenACCClauseKind::Copy:
465+ if (ParseOpenACCClauseVarList (Kind))
466+ return true ;
467+ break ;
385468 default :
386469 llvm_unreachable (" Not a required parens type?" );
387470 }
@@ -391,7 +474,7 @@ bool ParseOpenACCClauseParams(Parser &P, OpenACCClauseKind Kind) {
391474 if (!Parens.consumeOpen ()) {
392475 switch (Kind) {
393476 case OpenACCClauseKind::Self: {
394- ExprResult CondExpr = ParseOpenACCConditionalExpr (P );
477+ ExprResult CondExpr = ParseOpenACCConditionalExpr (* this );
395478 // An invalid expression can be just about anything, so just give up on
396479 // this clause list.
397480 if (CondExpr.isInvalid ())
@@ -407,62 +490,6 @@ bool ParseOpenACCClauseParams(Parser &P, OpenACCClauseKind Kind) {
407490 return false ;
408491}
409492
410- // The OpenACC Clause List is a comma or space-delimited list of clauses (see
411- // the comment on ParseOpenACCClauseList). The concept of a 'clause' doesn't
412- // really have its owner grammar and each individual one has its own definition.
413- // However, they all are named with a single-identifier (or auto/default!)
414- // token, followed in some cases by either braces or parens.
415- bool ParseOpenACCClause (Parser &P) {
416- // A number of clause names are actually keywords, so accept a keyword that
417- // can be converted to a name.
418- if (expectIdentifierOrKeyword (P))
419- return true ;
420-
421- OpenACCClauseKind Kind = getOpenACCClauseKind (P.getCurToken ());
422-
423- if (Kind == OpenACCClauseKind::Invalid)
424- return P.Diag (P.getCurToken (), diag::err_acc_invalid_clause)
425- << P.getCurToken ().getIdentifierInfo ();
426-
427- // Consume the clause name.
428- P.ConsumeToken ();
429-
430- return ParseOpenACCClauseParams (P, Kind);
431- }
432-
433- // Skip until we see the end of pragma token, but don't consume it. This is us
434- // just giving up on the rest of the pragma so we can continue executing. We
435- // have to do this because 'SkipUntil' considers paren balancing, which isn't
436- // what we want.
437- void SkipUntilEndOfDirective (Parser &P) {
438- while (P.getCurToken ().isNot (tok::annot_pragma_openacc_end))
439- P.ConsumeAnyToken ();
440- }
441-
442- // OpenACC 3.3, section 1.7:
443- // To simplify the specification and convey appropriate constraint information,
444- // a pqr-list is a comma-separated list of pdr items. The one exception is a
445- // clause-list, which is a list of one or more clauses optionally separated by
446- // commas.
447- void ParseOpenACCClauseList (Parser &P) {
448- bool FirstClause = true ;
449- while (P.getCurToken ().isNot (tok::annot_pragma_openacc_end)) {
450- // Comma is optional in a clause-list.
451- if (!FirstClause && P.getCurToken ().is (tok::comma))
452- P.ConsumeToken ();
453- FirstClause = false ;
454-
455- // Recovering from a bad clause is really difficult, so we just give up on
456- // error.
457- if (ParseOpenACCClause (P)) {
458- SkipUntilEndOfDirective (P);
459- return ;
460- }
461- }
462- }
463-
464- } // namespace
465-
466493// / OpenACC 3.3, section 2.16:
467494// / In this section and throughout the specification, the term wait-argument
468495// / means:
@@ -664,7 +691,7 @@ void Parser::ParseOpenACCDirective() {
664691 }
665692
666693 // Parses the list of clauses, if present.
667- ParseOpenACCClauseList (* this );
694+ ParseOpenACCClauseList ();
668695
669696 Diag (getCurToken (), diag::warn_pragma_acc_unimplemented);
670697 assert (Tok.is (tok::annot_pragma_openacc_end) &&
0 commit comments