[clang] [Clang][Preprocessor] Unify header-name lookahead for import and include (PR #191004)
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 10:53:21 PDT 2026
================
@@ -1356,32 +1356,32 @@ bool Preprocessor::HandleModuleContextualKeyword(Token &Result) {
llvm::SaveAndRestore<bool> SavedParsingPreprocessorDirective(
CurPPLexer->ParsingPreprocessorDirective, true);
- // The next token may be an angled string literal after import keyword.
- llvm::SaveAndRestore<bool> SavedParsingFilemame(
- CurPPLexer->ParsingFilename,
- Result.getIdentifierInfo()->isImportKeyword());
-
- std::optional<Token> NextTok = peekNextPPToken();
- if (!NextTok)
- return false;
-
- if (NextTok->is(tok::raw_identifier))
- LookUpIdentifierInfo(*NextTok);
-
- if (Result.getIdentifierInfo()->isImportKeyword()) {
- if (NextTok->isOneOf(tok::identifier, tok::less, tok::colon,
- tok::header_name)) {
- Result.setKind(tok::kw_import);
- ModuleImportLoc = Result.getLocation();
- return true;
+ if (II->isModuleKeyword()) {
+ if (auto NextTok = peekNextPPToken()) {
----------------
zygoloid wrote:
I don't think we need peek for that, because we don't need to try lexing one way, then roll back and try again a different way if it fails. I think it would suffice to lex a token, then use `EnterToken` to push it back onto the token stream for processing after the `import` token.
https://github.com/llvm/llvm-project/pull/191004
More information about the cfe-commits
mailing list