[clang] [Clang][Preprocessor] Unify header-name lookahead for import and include (PR #191004)
Yihan Wang via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 27 13:00:55 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()) {
----------------
yronglin wrote:
I recall the original PR used peek here because we wanted a lightweight approach, as peek only incurs one lex overhead, while using lex + `Enter Token` might incur additional mem alloc overhead. And after `HandleModuleContextualKeyword`, `HandleDirective` requires CurPPLexer is available, but `EnterToken` will change the current lexer to a TokenLexer.
https://github.com/llvm/llvm-project/pull/191004
More information about the cfe-commits
mailing list