diff options
| author | Jonas Hahnfeld <jonas.hahnfeld@cern.ch> | 2023-08-21 12:41:56 +0200 |
|---|---|---|
| committer | Jonas Hahnfeld <jonas.hahnfeld@cern.ch> | 2023-10-05 11:04:07 +0200 |
| commit | 3116d60494f219bfcb284d05d9ebed5b6c196ca5 (patch) | |
| tree | 4098e5aead4239f84f7930b67822c2f90a37e9a1 /clang/lib/Lex/Preprocessor.cpp | |
| parent | 7fa33773e355aaef03197e19698303748238d91a (diff) | |
[Lex] Introduce Preprocessor::LexTokensUntilEOF()
This new method repeatedly calls Lex() until end of file is reached
and optionally fills a std::vector of Tokens. Use it in Clang's unit
tests to avoid quite some code duplication.
Differential Revision: https://reviews.llvm.org/D158413
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
| -rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 73c37bc5161c..b82dd1fe49c7 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -998,6 +998,17 @@ void Preprocessor::Lex(Token &Result) { } } +void Preprocessor::LexTokensUntilEOF(std::vector<Token> *Tokens) { + while (1) { + Token Tok; + Lex(Tok); + if (Tok.isOneOf(tok::unknown, tok::eof, tok::eod)) + break; + if (Tokens != nullptr) + Tokens->push_back(Tok); + } +} + /// Lex a header-name token (including one formed from header-name-tokens if /// \p AllowConcatenation is \c true). /// |
