@@ -418,42 +418,40 @@ static bool isTrivialSingleTokenExpansion(const MacroInfo *MI,
418418 return !llvm::is_contained (MI->params (), II);
419419}
420420
421- // / isNextPPTokenLParen - Determine whether the next preprocessor token to be
422- // / lexed is a '('. If so, consume the token and return true, if not, this
423- // / method should have no observable side-effect on the lexed tokens.
424- bool Preprocessor::isNextPPTokenLParen () {
421+ // / isNextPPTokenLParen - Peek the next token. If so, return the token, if not,
422+ // / this method should have no observable side-effect on the lexed tokens.
423+ std::optional<Token> Preprocessor::peekNextPPToken () {
425424 // Do some quick tests for rejection cases.
426- unsigned Val;
425+ std::optional<Token> Val;
427426 if (CurLexer)
428- Val = CurLexer->isNextPPTokenLParen ();
427+ Val = CurLexer->peekNextPPToken ();
429428 else
430- Val = CurTokenLexer->isNextTokenLParen ();
429+ Val = CurTokenLexer->peekNextPPToken ();
431430
432- if (Val == 2 ) {
431+ if (! Val) {
433432 // We have run off the end. If it's a source file we don't
434433 // examine enclosing ones (C99 5.1.1.2p4). Otherwise walk up the
435434 // macro stack.
436435 if (CurPPLexer)
437- return false ;
436+ return std:: nullopt ;
438437 for (const IncludeStackInfo &Entry : llvm::reverse (IncludeMacroStack)) {
439438 if (Entry.TheLexer )
440- Val = Entry.TheLexer ->isNextPPTokenLParen ();
439+ Val = Entry.TheLexer ->peekNextPPToken ();
441440 else
442- Val = Entry.TheTokenLexer ->isNextTokenLParen ();
441+ Val = Entry.TheTokenLexer ->peekNextPPToken ();
443442
444- if (Val != 2 )
443+ if (Val)
445444 break ;
446445
447446 // Ran off the end of a source file?
448447 if (Entry.ThePPLexer )
449- return false ;
448+ return std:: nullopt ;
450449 }
451450 }
452451
453- // Okay, if we know that the token is a '(', lex it and return. Otherwise we
454- // have found something that isn't a '(' or we found the end of the
455- // translation unit. In either case, return false.
456- return Val == 1 ;
452+ // Okay, we found the token and return. Otherwise we found the end of the
453+ // translation unit.
454+ return Val;
457455}
458456
459457// / HandleMacroExpandedIdentifier - If an identifier token is read that is to be
0 commit comments