[cfe-commits] r77524 - in /cfe/trunk: include/clang/Index/EntityHandler.h include/clang/Index/Handlers.h include/clang/Index/IndexProvider.h include/clang/Index/Indexer.h lib/Index/Handlers.cpp lib/Index/IndexProvider.cpp lib/Index/Indexer.cpp lib/Index/Program.cpp tools/index-test/index-test.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 29 16:38:21 PDT 2009


Author: akirtzidis
Date: Wed Jul 29 18:38:21 2009
New Revision: 77524

URL: http://llvm.org/viewvc/llvm-project?rev=77524&view=rev
Log:
-Make IndexProvider an abstract interface for getting indexing information.
-Introduce Indexer as an IndexProvider implementation.

Added:
    cfe/trunk/include/clang/Index/Handlers.h
      - copied, changed from r77518, cfe/trunk/include/clang/Index/EntityHandler.h
    cfe/trunk/include/clang/Index/Indexer.h
      - copied, changed from r77518, cfe/trunk/include/clang/Index/IndexProvider.h
    cfe/trunk/lib/Index/Handlers.cpp
    cfe/trunk/lib/Index/Indexer.cpp
Removed:
    cfe/trunk/include/clang/Index/EntityHandler.h
Modified:
    cfe/trunk/include/clang/Index/IndexProvider.h
    cfe/trunk/lib/Index/IndexProvider.cpp
    cfe/trunk/lib/Index/Program.cpp
    cfe/trunk/tools/index-test/index-test.cpp

Removed: cfe/trunk/include/clang/Index/EntityHandler.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/EntityHandler.h?rev=77523&view=auto

==============================================================================
--- cfe/trunk/include/clang/Index/EntityHandler.h (original)
+++ cfe/trunk/include/clang/Index/EntityHandler.h (removed)
@@ -1,33 +0,0 @@
-//===--- EntityHandler.h - Interface for receiving entities -----*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-//  Abstract interface for receiving Entities.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_INDEX_ENTITYHANDLER_H
-#define LLVM_CLANG_INDEX_ENTITYHANDLER_H
-
-namespace clang {
-
-namespace idx {
-  class Entity;
-
-/// \brief Abstract interface for receiving Entities.
-class EntityHandler {
-public:
-  virtual ~EntityHandler();
-  virtual void HandleEntity(Entity Ent);
-};
-  
-} // namespace idx
-
-} // namespace clang
-
-#endif

Copied: cfe/trunk/include/clang/Index/Handlers.h (from r77518, cfe/trunk/include/clang/Index/EntityHandler.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/Handlers.h?p2=cfe/trunk/include/clang/Index/Handlers.h&p1=cfe/trunk/include/clang/Index/EntityHandler.h&r1=77518&r2=77524&rev=77524&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/EntityHandler.h (original)
+++ cfe/trunk/include/clang/Index/Handlers.h Wed Jul 29 18:38:21 2009
@@ -1,4 +1,4 @@
-//===--- EntityHandler.h - Interface for receiving entities -----*- C++ -*-===//
+//===--- Handlers.h - Interfaces for receiving information ------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,23 +7,31 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  Abstract interface for receiving Entities.
+//  Abstract interfaces for receiving information.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_INDEX_ENTITYHANDLER_H
-#define LLVM_CLANG_INDEX_ENTITYHANDLER_H
+#ifndef LLVM_CLANG_INDEX_HANDLERS_H
+#define LLVM_CLANG_INDEX_HANDLERS_H
 
 namespace clang {
 
 namespace idx {
   class Entity;
+  class TranslationUnit;
 
 /// \brief Abstract interface for receiving Entities.
 class EntityHandler {
 public:
   virtual ~EntityHandler();
-  virtual void HandleEntity(Entity Ent);
+  virtual void HandleEntity(Entity Ent) = 0;
+};
+
+/// \brief Abstract interface for receiving TranslationUnits.
+class TranslationUnitHandler {
+public:
+  virtual ~TranslationUnitHandler();
+  virtual void Handle(TranslationUnit *TU) = 0;
 };
   
 } // namespace idx

Modified: cfe/trunk/include/clang/Index/IndexProvider.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexProvider.h?rev=77524&r1=77523&r2=77524&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/IndexProvider.h (original)
+++ cfe/trunk/include/clang/Index/IndexProvider.h Wed Jul 29 18:38:21 2009
@@ -1,4 +1,4 @@
-//===--- IndexProvider.h - Map of entities to translation units -*- C++ -*-===//
+//===--- IndexProvider.h - Maps information to translation units -*- C++ -*-==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,46 +7,25 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  Maps Entities to TranslationUnits
+//  Maps information to TranslationUnits.
 //
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CLANG_INDEX_INDEXPROVIDER_H
 #define LLVM_CLANG_INDEX_INDEXPROVIDER_H
 
-#include "llvm/ADT/SmallPtrSet.h"
-#include <map>
-
 namespace clang {
 
 namespace idx {
-  class Program;
   class Entity;
-  class TranslationUnit;
+  class TranslationUnitHandler;
 
-/// \brief Maps Entities to TranslationUnits.
+/// \brief Maps information to TranslationUnits.
 class IndexProvider {
 public:
-  typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
-  typedef std::map<Entity, TUSetTy> MapTy;
-  class Indexer;
-
-  explicit IndexProvider(Program &prog) : Prog(prog) { }
-
-  Program &getProgram() const { return Prog; }
-
-  /// \brief Find all Entities and map them to the given translation unit.
-  void IndexAST(TranslationUnit *TU);
-
-  typedef TUSetTy::iterator translation_unit_iterator;
-
-  translation_unit_iterator translation_units_begin(Entity Ent) const;
-  translation_unit_iterator translation_units_end(Entity Ent) const;
-  bool translation_units_empty(Entity Ent) const;
-  
-private:
-  Program &Prog;
-  mutable MapTy Map;
+  virtual ~IndexProvider();
+  virtual void GetTranslationUnitsFor(Entity Ent,
+                                      TranslationUnitHandler *Handler) = 0;
 };
 
 } // namespace idx

Copied: cfe/trunk/include/clang/Index/Indexer.h (from r77518, cfe/trunk/include/clang/Index/IndexProvider.h)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/Indexer.h?p2=cfe/trunk/include/clang/Index/Indexer.h&p1=cfe/trunk/include/clang/Index/IndexProvider.h&r1=77518&r2=77524&rev=77524&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/IndexProvider.h (original)
+++ cfe/trunk/include/clang/Index/Indexer.h Wed Jul 29 18:38:21 2009
@@ -1,4 +1,4 @@
-//===--- IndexProvider.h - Map of entities to translation units -*- C++ -*-===//
+//===--- Indexer.h - IndexProvider implementation ---------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,13 +7,14 @@
 //
 //===----------------------------------------------------------------------===//
 //
-//  Maps Entities to TranslationUnits
+//  IndexProvider implementation.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_CLANG_INDEX_INDEXPROVIDER_H
-#define LLVM_CLANG_INDEX_INDEXPROVIDER_H
+#ifndef LLVM_CLANG_INDEX_INDEXER_H
+#define LLVM_CLANG_INDEX_INDEXER_H
 
+#include "clang/Index/IndexProvider.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include <map>
 
@@ -21,32 +22,34 @@
 
 namespace idx {
   class Program;
-  class Entity;
   class TranslationUnit;
 
-/// \brief Maps Entities to TranslationUnits.
-class IndexProvider {
+/// \brief Maps information to TranslationUnits.
+class Indexer : public IndexProvider {
 public:
   typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
   typedef std::map<Entity, TUSetTy> MapTy;
-  class Indexer;
 
-  explicit IndexProvider(Program &prog) : Prog(prog) { }
+  explicit Indexer(Program &prog) : Prog(prog) { }
 
   Program &getProgram() const { return Prog; }
 
   /// \brief Find all Entities and map them to the given translation unit.
   void IndexAST(TranslationUnit *TU);
 
+  virtual void GetTranslationUnitsFor(Entity Ent,
+                                      TranslationUnitHandler *Handler);
+
   typedef TUSetTy::iterator translation_unit_iterator;
 
   translation_unit_iterator translation_units_begin(Entity Ent) const;
   translation_unit_iterator translation_units_end(Entity Ent) const;
   bool translation_units_empty(Entity Ent) const;
-  
+
 private:
   Program &Prog;
-  mutable MapTy Map;
+  MapTy Map;
+  CtxTUMapTy CtxTUMap;
 };
 
 } // namespace idx

Added: cfe/trunk/lib/Index/Handlers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/Handlers.cpp?rev=77524&view=auto

==============================================================================
--- cfe/trunk/lib/Index/Handlers.cpp (added)
+++ cfe/trunk/lib/Index/Handlers.cpp Wed Jul 29 18:38:21 2009
@@ -0,0 +1,21 @@
+//===--- Handlers.cpp - Interfaces for receiving information ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  Abstract interfaces for receiving information.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Index/Handlers.h"
+#include "clang/Index/Entity.h"
+using namespace clang;
+using namespace idx;
+
+// Out-of-line to give the virtual tables a home.
+EntityHandler::~EntityHandler() { }
+TranslationUnitHandler::~TranslationUnitHandler() { }

Modified: cfe/trunk/lib/Index/IndexProvider.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexProvider.cpp?rev=77524&r1=77523&r2=77524&view=diff

==============================================================================
--- cfe/trunk/lib/Index/IndexProvider.cpp (original)
+++ cfe/trunk/lib/Index/IndexProvider.cpp Wed Jul 29 18:38:21 2009
@@ -1,74 +1,20 @@
-//===--- IndexProvider.cpp - Map of entities to translation units ---------===//
+//===- IndexProvider.cpp - Maps information to translation units -*- C++ -*-==//
 //
 //                     The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
-// License. See LICENSaE.TXT for details.
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
-//  Maps Entities to TranslationUnits
+//  Maps information to TranslationUnits.
 //
 //===----------------------------------------------------------------------===//
 
 #include "clang/Index/IndexProvider.h"
-#include "clang/Index/Program.h"
 #include "clang/Index/Entity.h"
-#include "clang/Index/EntityHandler.h"
-#include "clang/Index/TranslationUnit.h"
 using namespace clang;
 using namespace idx;
 
-class IndexProvider::Indexer : public EntityHandler {
-  TranslationUnit *TU;
-  MapTy ⤅
-  
-public:
-  Indexer(TranslationUnit *tu, MapTy &map) : TU(tu), Map(map) { }
-
-  virtual void HandleEntity(Entity Ent) {
-    if (Ent.isInternalToTU())
-      return;
-
-    MapTy::iterator I = Map.find(Ent);
-    if (I != Map.end()) {
-      I->second.insert(TU);
-      return;
-    }
-    
-    Map[Ent].insert(TU);
-  }
-};
-
-void IndexProvider::IndexAST(TranslationUnit *TU) {
-  Indexer Idx(TU, Map);
-  Prog.FindEntities(TU->getASTContext(), &Idx);
-}
-
-static IndexProvider::TUSetTy EmptySet;
-
-IndexProvider::translation_unit_iterator
-IndexProvider::translation_units_begin(Entity Ent) const {
-  MapTy::iterator I = Map.find(Ent);
-  if (I == Map.end())
-    return EmptySet.begin();
-  
-  return I->second.begin();
-}
-
-IndexProvider::translation_unit_iterator
-IndexProvider::translation_units_end(Entity Ent) const {
-  MapTy::iterator I = Map.find(Ent);
-  if (I == Map.end())
-    return EmptySet.end();
-  
-  return I->second.end();
-}
-
-bool IndexProvider::translation_units_empty(Entity Ent) const {
-  MapTy::iterator I = Map.find(Ent);
-  if (I == Map.end())
-    return true;
-
-  return I->second.begin() == I->second.end();
-}
+// Out-of-line to give the virtual table a home.
+IndexProvider::~IndexProvider() { }

Added: cfe/trunk/lib/Index/Indexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/Indexer.cpp?rev=77524&view=auto

==============================================================================
--- cfe/trunk/lib/Index/Indexer.cpp (added)
+++ cfe/trunk/lib/Index/Indexer.cpp Wed Jul 29 18:38:21 2009
@@ -0,0 +1,86 @@
+//===--- Indexer.cpp - IndexProvider implementation -------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  IndexProvider implementation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Index/Indexer.h"
+#include "clang/Index/Program.h"
+#include "clang/Index/Entity.h"
+#include "clang/Index/Handlers.h"
+#include "clang/Index/TranslationUnit.h"
+using namespace clang;
+using namespace idx;
+
+namespace {
+
+class EntityIndexer : public EntityHandler {
+  TranslationUnit *TU;
+  Indexer::MapTy ⤅
+  
+public:
+  EntityIndexer(TranslationUnit *tu, Indexer::MapTy &map) : TU(tu), Map(map) { }
+
+  virtual void HandleEntity(Entity Ent) {
+    if (Ent.isInternalToTU())
+      return;
+    Map[Ent].insert(TU);
+  }
+};
+
+} // anonymous namespace
+
+void Indexer::IndexAST(TranslationUnit *TU) {
+  EntityIndexer Idx(TU, Map);
+  Prog.FindEntities(TU->getASTContext(), &Idx);
+}
+
+void Indexer::GetTranslationUnitsFor(Entity Ent,
+                                     TranslationUnitHandler *Handler) {
+  assert(Ent.isValid() && "Expected valid Entity");
+  assert(!Ent.isInternalToTU() &&
+         "Expected an Entity visible outside of its translation unit");
+
+  MapTy::iterator I = Map.find(Ent);
+  if (I == Map.end())
+    return;
+  
+  TUSetTy &Set = I->second;
+  for (TUSetTy::iterator I = Set.begin(), E = Set.end(); I != E; ++I)
+    Handler->Handle(*I);
+}
+
+static Indexer::TUSetTy EmptySet;
+
+Indexer::translation_unit_iterator
+Indexer::translation_units_begin(Entity Ent) const {
+  MapTy::iterator I = Map.find(Ent);
+  if (I == Map.end())
+    return EmptySet.begin();
+  
+   return I->second.begin();
+}
+
+Indexer::translation_unit_iterator
+Indexer::translation_units_end(Entity Ent) const {
+  MapTy::iterator I = Map.find(Ent);
+  if (I == Map.end())
+    return EmptySet.end();
+
+  return I->second.end();
+}
+
+bool Indexer::translation_units_empty(Entity Ent) const {
+  MapTy::iterator I = Map.find(Ent);
+  if (I == Map.end())
+    return true;
+
+  return I->second.begin() == I->second.end();
+}

Modified: cfe/trunk/lib/Index/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/Program.cpp?rev=77524&r1=77523&r2=77524&view=diff

==============================================================================
--- cfe/trunk/lib/Index/Program.cpp (original)
+++ cfe/trunk/lib/Index/Program.cpp Wed Jul 29 18:38:21 2009
@@ -13,7 +13,7 @@
 
 #include "clang/Index/Program.h"
 #include "ProgramImpl.h"
-#include "clang/Index/EntityHandler.h"
+#include "clang/Index/Handlers.h"
 #include "clang/Index/TranslationUnit.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/ASTContext.h"
@@ -22,11 +22,8 @@
 using namespace idx;
 
 // Out-of-line to give the virtual tables a home.
-EntityHandler::~EntityHandler() { }
 TranslationUnit::~TranslationUnit() { }
 
-void EntityHandler::HandleEntity(Entity Ent) { }
-
 Program::Program() : Impl(new ProgramImpl()) { }
 
 Program::~Program() {

Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=77524&r1=77523&r2=77524&view=diff

==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Wed Jul 29 18:38:21 2009
@@ -33,7 +33,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Index/Program.h"
-#include "clang/Index/IndexProvider.h"
+#include "clang/Index/Indexer.h"
 #include "clang/Index/Entity.h"
 #include "clang/Index/TranslationUnit.h"
 #include "clang/Index/ASTLocation.h"
@@ -141,7 +141,7 @@
   }
 }
 
-static void ProcessASTLocation(ASTLocation ASTLoc, IndexProvider &IdxProvider) {
+static void ProcessASTLocation(ASTLocation ASTLoc, Indexer &Idxer) {
   assert(ASTLoc.isValid());
 
   Decl *D = ASTLoc.getReferencedDecl();
@@ -151,14 +151,14 @@
     return;
   }
 
-  Entity Ent = Entity::get(D, IdxProvider.getProgram());
+  Entity Ent = Entity::get(D, Idxer.getProgram());
   if (Ent.isInvalid() || Ent.isInternalToTU())
     return ProcessDecl(D);
 
   // Find the "same" Decl in other translation units and print information.
-  for (IndexProvider::translation_unit_iterator
-         I = IdxProvider.translation_units_begin(Ent),
-         E = IdxProvider.translation_units_end(Ent); I != E; ++I) {
+  for (Indexer::translation_unit_iterator
+         I = Idxer.translation_units_begin(Ent),
+         E = Idxer.translation_units_end(Ent); I != E; ++I) {
     TUnit *TU = static_cast<TUnit*>(*I);
     Decl *OtherD = Ent.getDecl(TU->getASTContext());
     assert(OtherD && "Couldn't resolve Entity");
@@ -178,7 +178,7 @@
   FileManager FileMgr;
 
   Program Prog;
-  IndexProvider IdxProvider(Prog);
+  Indexer Idxer(Prog);
   llvm::SmallVector<TUnit*, 4> TUnits;
   
   // If no input was specified, read from stdin.
@@ -200,7 +200,7 @@
     TUnit *TU = new TUnit(AST.take(), InFile);
     TUnits.push_back(TU);
     
-    IdxProvider.IndexAST(TU);
+    Idxer.IndexAST(TU);
   }
 
   ASTLocation ASTLoc;
@@ -253,7 +253,7 @@
             FirstAST->getASTContext().getCommentForDecl(ASTLoc.getDecl()))
         OS << "Comment associated with this declaration:\n" << Comment << "\n";
     } else {
-      ProcessASTLocation(ASTLoc, IdxProvider);
+      ProcessASTLocation(ASTLoc, Idxer);
     }
   }
   





More information about the cfe-commits mailing list