@@ -90,6 +90,7 @@ OpenACCClauseKind getOpenACCClauseKind(Token Tok) {
90
90
return llvm::StringSwitch<OpenACCClauseKind>(
91
91
Tok.getIdentifierInfo ()->getName ())
92
92
.Case (" auto" , OpenACCClauseKind::Auto)
93
+ .Case (" copy" , OpenACCClauseKind::Copy)
93
94
.Case (" default" , OpenACCClauseKind::Default)
94
95
.Case (" finalize" , OpenACCClauseKind::Finalize)
95
96
.Case (" if" , OpenACCClauseKind::If)
@@ -334,7 +335,8 @@ bool ClauseHasOptionalParens(OpenACCClauseKind Kind) {
334
335
}
335
336
336
337
bool ClauseHasRequiredParens (OpenACCClauseKind Kind) {
337
- return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If;
338
+ return Kind == OpenACCClauseKind::Default || Kind == OpenACCClauseKind::If ||
339
+ Kind == OpenACCClauseKind::Copy;
338
340
}
339
341
340
342
ExprResult ParseOpenACCConditionalExpr (Parser &P) {
@@ -345,43 +347,124 @@ ExprResult ParseOpenACCConditionalExpr(Parser &P) {
345
347
return P.getActions ().CorrectDelayedTyposInExpr (P.ParseExpression ());
346
348
}
347
349
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,
350
429
tok::annot_pragma_openacc_end);
351
430
352
431
if (ClauseHasRequiredParens (Kind)) {
353
432
if (Parens.expectAndConsume ()) {
354
433
// We are missing a paren, so assume that the person just forgot the
355
434
// parameter. Return 'false' so we try to continue on and parse the next
356
435
// 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);
359
438
return false ;
360
439
}
361
440
362
441
switch (Kind) {
363
442
case OpenACCClauseKind::Default: {
364
- Token DefKindTok = P. getCurToken ();
443
+ Token DefKindTok = getCurToken ();
365
444
366
- if (expectIdentifierOrKeyword (P ))
445
+ if (expectIdentifierOrKeyword (* this ))
367
446
break ;
368
447
369
- P. ConsumeToken ();
448
+ ConsumeToken ();
370
449
371
450
if (getOpenACCDefaultClauseKind (DefKindTok) ==
372
451
OpenACCDefaultClauseKind::Invalid)
373
- P. Diag (DefKindTok, diag::err_acc_invalid_default_clause_kind);
452
+ Diag (DefKindTok, diag::err_acc_invalid_default_clause_kind);
374
453
375
454
break ;
376
455
}
377
456
case OpenACCClauseKind::If: {
378
- ExprResult CondExpr = ParseOpenACCConditionalExpr (P );
457
+ ExprResult CondExpr = ParseOpenACCConditionalExpr (* this );
379
458
// An invalid expression can be just about anything, so just give up on
380
459
// this clause list.
381
460
if (CondExpr.isInvalid ())
382
461
return true ;
383
462
break ;
384
463
}
464
+ case OpenACCClauseKind::Copy:
465
+ if (ParseOpenACCClauseVarList (Kind))
466
+ return true ;
467
+ break ;
385
468
default :
386
469
llvm_unreachable (" Not a required parens type?" );
387
470
}
@@ -391,7 +474,7 @@ bool ParseOpenACCClauseParams(Parser &P, OpenACCClauseKind Kind) {
391
474
if (!Parens.consumeOpen ()) {
392
475
switch (Kind) {
393
476
case OpenACCClauseKind::Self: {
394
- ExprResult CondExpr = ParseOpenACCConditionalExpr (P );
477
+ ExprResult CondExpr = ParseOpenACCConditionalExpr (* this );
395
478
// An invalid expression can be just about anything, so just give up on
396
479
// this clause list.
397
480
if (CondExpr.isInvalid ())
@@ -407,62 +490,6 @@ bool ParseOpenACCClauseParams(Parser &P, OpenACCClauseKind Kind) {
407
490
return false ;
408
491
}
409
492
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
-
466
493
// / OpenACC 3.3, section 2.16:
467
494
// / In this section and throughout the specification, the term wait-argument
468
495
// / means:
@@ -664,7 +691,7 @@ void Parser::ParseOpenACCDirective() {
664
691
}
665
692
666
693
// Parses the list of clauses, if present.
667
- ParseOpenACCClauseList (* this );
694
+ ParseOpenACCClauseList ();
668
695
669
696
Diag (getCurToken (), diag::warn_pragma_acc_unimplemented);
670
697
assert (Tok.is (tok::annot_pragma_openacc_end) &&
0 commit comments