Hahnfeld created this revision.
Hahnfeld added a reviewer: erichkeane.
Herald added a project: All.
Hahnfeld requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rely on `Preprocessor::LexAll()` and just replace `tok::comma` by `tok::eof` 
and push a `tok::eof` as the last element.


Repository:
  rG LLVM Github Monorepo

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
@@ -447,19 +447,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;
+  std::vector<Token> ArgTokens = PP->LexAll();
+  // 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
@@ -447,19 +447,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;
+  std::vector<Token> ArgTokens = PP->LexAll();
+  // 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
  • [PATCH] D158414: [LexerTest... Jonas Hahnfeld via Phabricator via cfe-commits

Reply via email to