[clang] [clang][Preprocessor] Handle the first pp-token in EnterMainSourceFile (PR #145244)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 24 04:03:45 PDT 2025


================
@@ -2302,10 +2295,41 @@ class Preprocessor {
     }
   }
 
-  /// Determine whether the next preprocessor token to be
-  /// lexed is a '('.  If so, consume the token and return true, if not, this
+  /// Check whether the next pp-token is one of the specificed token kind. this
   /// method should have no observable side-effect on the lexed tokens.
-  bool isNextPPTokenLParen();
+  template <tok::TokenKind K, tok::TokenKind... Ks> bool isNextPPTokenOneOf() {
----------------
yronglin wrote:

Yes, more details in https://github.com/llvm/llvm-project/pull/143898, we need an mechanism that look ahead next pp-token, and check whether the next pp-token kind is one of `tok::A, tok::B`...:
Eg.
```cpp
  auto NextTok = peekNextPPToken().value_or(Token{});
  if (Result.getIdentifierInfo()->isModulesImport() &&
      isNextPPTokenOneOf<tok::raw_identifier, tok::less, tok::string_literal,
                      tok::colon>()) {
     // Handle C++ import directive.
  }
  if (Result.getIdentifierInfo()->isModulesDeclaration() &&
      isNextPPTokenOneOf<tok::raw_identifier, tok::colon, tok::semi>()) {
     // Handle C++ module directive.
  }

  // Ok, it's an identifier.
  return false;
```

https://github.com/llvm/llvm-project/pull/145244


More information about the cfe-commits mailing list