================ @@ -268,6 +270,71 @@ ExprResult Parser::ParseOpenACCRoutineName() { return getActions().CorrectDelayedTyposInExpr(Res); } +void Parser::ParseOpenACCCacheVar() { + ExprResult ArrayName = ParseOpenACCIDExpression(); + // FIXME: Pass this to Sema. + (void)ArrayName; + + // If the expression is invalid, just continue parsing the brackets, there + // is likely other useful diagnostics we can emit inside of those. + + BalancedDelimiterTracker SquareBrackets(*this, tok::l_square, + tok::annot_pragma_openacc_end); + + // Square brackets are required, so error here, and try to recover by moving + // until the next comma, or the close paren/end of pragma. + if (SquareBrackets.expectAndConsume()) { + SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openacc_end, + Parser::StopBeforeMatch); + return; + } + + ExprResult Lower = getActions().CorrectDelayedTyposInExpr(ParseExpression()); + // FIXME: Pass this to Sema. + (void)Lower; + + // The 'length' expression is optional, as this could be a single array + // element. If there is no colon, we can treat it as that. + if (getCurToken().is(tok::colon)) { + ConsumeToken(); + ExprResult Length = + getActions().CorrectDelayedTyposInExpr(ParseExpression()); + // FIXME: Pass this to Sema. + (void)Length; + } + + // Diagnose the square bracket being in the wrong place and continue. + SquareBrackets.consumeClose(); +} + +void Parser::ParseOpenACCCacheVarList() { + // If this is the end of the line, just return 'false' and count on the close + // paren diagnostic to catch the issue. + if (getCurToken().isAnnotation()) + return; + + // The VarList is an optional `readonly:` followed by a list of a variable + // specifications. First, see if we have `readonly:`, else we back-out and + // treat it like the beginning of a reference to a potentially-existing + // `readonly` variable. + if (getPreprocessor().getSpelling(getCurToken()) == "readonly" && + NextToken().is(tok::colon)) { + // Consume both tokens. + ConsumeToken(); + ConsumeToken(); + // FIXME: Record that this is a 'readonly' so that we can use that during + // Sema/AST generation. + } + + bool FirstArray = true; + while (!getCurToken().isOneOf(tok::r_paren, tok::annot_pragma_openacc_end)) { + if (!FirstArray) + ExpectAndConsume(tok::comma); + FirstArray = false; + ParseOpenACCCacheVar(); ---------------- erichkeane wrote:
At the moment, that function doesn't "fail", it attempts to consume the entirety of what could be a var (that is, name, then brackets), thus letting this diagnose the missing ','. Though I see from your other comment you're encouraging diagnosing a 'failed' expression parse rather than try to continue on. https://github.com/llvm/llvm-project/pull/74324 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits