[clang] [OpenACC] Implement 'default' clause parsing. (PR #77002)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 5 06:05:41 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;
+ }
----------------
erichkeane wrote:
Im not sure I get what you mean? The point here is to error if it isn't an identifier OR isn't a 'keyword'.
The point here is simply to make `default(auto)` kind of things look sane (that is, not do an 'expected identifier', do a 'expected none or present`).
https://github.com/llvm/llvm-project/pull/77002
More information about the cfe-commits
mailing list