[clang-tools-extra] r305434 - Update Append Argument to more efficiently traverse tokens

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 14 17:27:23 PDT 2017


Author: erichkeane
Date: Wed Jun 14 19:27:23 2017
New Revision: 305434

URL: http://llvm.org/viewvc/llvm-project?rev=305434&view=rev
Log:
Update Append Argument to more efficiently traverse tokens

This function was previously making (correct) assumptions
without complete knowledge of MacroArgs guarantees for
Arguments.  After going through Macro Args a bunch, I'd
corrected the getNumArguments (and changed its name), 
however didn't realize this was depending on the behavior.

This patch has version that depends on the corrected 
getNumMacroArguments's behavior, with the rest checked against
my knowledge of the MacroArgs' token list.  Commiting no-wait
since the test is broken.

Modified:
    clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp

Modified: clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp?rev=305434&r1=305433&r2=305434&view=diff
==============================================================================
--- clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp (original)
+++ clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.cpp Wed Jun 14 19:27:23 2017
@@ -588,19 +588,16 @@ void PPCallbacksTracker::appendArgument(
   std::string Str;
   llvm::raw_string_ostream SS(Str);
   SS << "[";
-  // The argument tokens might include end tokens, so we reflect how
-  // how getUnexpArgument provides the arguments.
-  for (int I = 0, E = Value->getNumMacroArguments(); I < E; ++I) {
+
+  // Each argument is is a series of contiguous Tokens, terminated by a eof.
+  // Go through each argument printing tokens until we reach eof.
+  for (unsigned I = 0; I < Value->getNumMacroArguments(); ++I) {
     const clang::Token *Current = Value->getUnexpArgument(I);
-    int TokenCount = Value->getArgLength(Current) + 1; // include EOF
-    E -= TokenCount;
     if (I)
       SS << ", ";
-    // We're assuming tokens are contiguous, as otherwise we have no
-    // other way to get at them.
-    --TokenCount;
-    for (int TokenIndex = 0; TokenIndex < TokenCount; ++TokenIndex, ++Current) {
-      if (TokenIndex)
+    bool First = true;
+    while (Current->isNot(clang::tok::eof)) {
+      if (!First)
         SS << " ";
       // We need to be careful here because the arguments might not be legal in
       // YAML, so we use the token name for anything but identifiers and
@@ -611,6 +608,8 @@ void PPCallbacksTracker::appendArgument(
       } else {
         SS << "<" << Current->getName() << ">";
       }
+      ++Current;
+      First = false;
     }
   }
   SS << "]";




More information about the cfe-commits mailing list