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(


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(
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to