[cfe-commits] r103062 - /cfe/trunk/tools/libclang/CIndex.cpp

Ted Kremenek kremenek at apple.com
Tue May 4 17:55:18 PDT 2010


Author: kremenek
Date: Tue May  4 19:55:17 2010
New Revision: 103062

URL: http://llvm.org/viewvc/llvm-project?rev=103062&view=rev
Log:
Move post-processing of token annotations to method in AnnotateTokensWorker.

Modified:
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=103062&r1=103061&r2=103062&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue May  4 19:55:17 2010
@@ -2324,13 +2324,32 @@
 namespace {
 class AnnotateTokensWorker {
   AnnotateTokensData &Annotated;
+  CXToken *Tokens;
+  CXCursor *Cursors;
+  unsigned NumTokens;
 public:
-  AnnotateTokensWorker(AnnotateTokensData &annotated)
-    : Annotated(annotated) {}
+  AnnotateTokensWorker(AnnotateTokensData &annotated,
+                       CXToken *tokens, CXCursor *cursors, unsigned numTokens)
+    : Annotated(annotated), Tokens(tokens), Cursors(cursors),
+      NumTokens(numTokens) {}
+
+  void CompleteAnnotations();
+
   enum CXChildVisitResult Visit(CXCursor cursor, CXCursor parent);
 };
 }
 
+void AnnotateTokensWorker::CompleteAnnotations() {
+  for (unsigned I = 0; I != NumTokens; ++I) {
+    // Determine whether we saw a cursor at this token's location.
+    AnnotateTokensData::iterator Pos = Annotated.find(Tokens[I].int_data[1]);
+    if (Pos == Annotated.end())
+      continue;
+
+    Cursors[I] = Pos->second;
+  }
+}
+
 enum CXChildVisitResult
 AnnotateTokensWorker::Visit(CXCursor cursor, CXCursor parent) {
   // We only annotate the locations of declarations, simple
@@ -2462,19 +2481,11 @@
   // Annotate all of the source locations in the region of interest that map to
   // a specific cursor.  
   CXCursor Parent = clang_getTranslationUnitCursor(CXXUnit);
-  AnnotateTokensWorker W(Annotated);
+  AnnotateTokensWorker W(Annotated, Tokens, Cursors, NumTokens);
   CursorVisitor AnnotateVis(CXXUnit, AnnotateTokensVisitor, &W,
                             Decl::MaxPCHLevel, RegionOfInterest);
   AnnotateVis.VisitChildren(Parent);
-  
-  for (unsigned I = 0; I != NumTokens; ++I) {
-    // Determine whether we saw a cursor at this token's location.
-    AnnotateTokensData::iterator Pos = Annotated.find(Tokens[I].int_data[1]);
-    if (Pos == Annotated.end())
-      continue;
-    
-    Cursors[I] = Pos->second;
-  }  
+  W.CompleteAnnotations();
 }
 } // end: extern "C"
 





More information about the cfe-commits mailing list