[PATCH] D158414: [LexerTest] Use LexTokensUntilEOF() in StringifyArgs

Jonas Hahnfeld via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 15 05:33:06 PDT 2023


Hahnfeld updated this revision to Diff 556848.
Hahnfeld retitled this revision from "[LexerTest] Use LexAll() in StringifyArgs" to "[LexerTest] Use LexTokensUntilEOF() in StringifyArgs".
Hahnfeld edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158414/new/

https://reviews.llvm.org/D158414

Files:
  clang/unittests/Lex/LexerTest.cpp


Index: clang/unittests/Lex/LexerTest.cpp
===================================================================
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -451,18 +451,15 @@
   Token Eof;
   Eof.setKind(tok::eof);
   std::vector<Token> ArgTokens;
-  while (1) {
-    Token tok;
-    PP->Lex(tok);
-    if (tok.is(tok::eof)) {
-      ArgTokens.push_back(Eof);
-      break;
+  PP->LexTokensUntilEOF(&ArgTokens);
+  // Replace all tok::comma with tok::eof for stringification.
+  for (auto &tok : ArgTokens) {
+    if (tok.is(tok::comma)) {
+      tok = Eof;
     }
-    if (tok.is(tok::comma))
-      ArgTokens.push_back(Eof);
-    else
-      ArgTokens.push_back(tok);
   }
+  // Push a tok::eof as the last element.
+  ArgTokens.push_back(Eof);
 
   auto MacroArgsDeleter = [&PP](MacroArgs *M) { M->destroy(*PP); };
   std::unique_ptr<MacroArgs, decltype(MacroArgsDeleter)> MA(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158414.556848.patch
Type: text/x-patch
Size: 912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230915/137f8403/attachment.bin>


More information about the cfe-commits mailing list