Home | History | Annotate | Download | only in Index
      1 //===--- Indexer.h - IndexProvider implementation ---------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  IndexProvider implementation.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_INDEX_INDEXER_H
     15 #define LLVM_CLANG_INDEX_INDEXER_H
     16 
     17 #include "clang/Index/IndexProvider.h"
     18 #include "clang/Index/Entity.h"
     19 #include "clang/Index/GlobalSelector.h"
     20 #include "llvm/ADT/SmallPtrSet.h"
     21 #include "llvm/ADT/DenseMap.h"
     22 #include <map>
     23 
     24 namespace clang {
     25   class ASTContext;
     26   class FunctionDecl;
     27 
     28 namespace idx {
     29   class Program;
     30   class TranslationUnit;
     31 
     32 /// \brief Maps information to TranslationUnits.
     33 class Indexer : public IndexProvider {
     34 public:
     35   typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
     36   typedef llvm::DenseMap<ASTContext *, TranslationUnit *> CtxTUMapTy;
     37   typedef std::map<Entity, TUSetTy> MapTy;
     38   typedef std::map<GlobalSelector, TUSetTy> SelMapTy;
     39   typedef std::map<Entity, std::pair<FunctionDecl*,TranslationUnit*> > DefMapTy;
     40 
     41   explicit Indexer(Program &prog) :
     42     Prog(prog) { }
     43 
     44   Program &getProgram() const { return Prog; }
     45 
     46   /// \brief Find all Entities and map them to the given translation unit.
     47   void IndexAST(TranslationUnit *TU);
     48 
     49   virtual void GetTranslationUnitsFor(Entity Ent,
     50                                       TranslationUnitHandler &Handler);
     51   virtual void GetTranslationUnitsFor(GlobalSelector Sel,
     52                                       TranslationUnitHandler &Handler);
     53 
     54   std::pair<FunctionDecl*, TranslationUnit*> getDefinitionFor(Entity Ent);
     55 
     56 private:
     57   Program &Prog;
     58 
     59   MapTy Map;
     60   // Map a function Entity to the its definition.
     61   DefMapTy DefMap;
     62 
     63   CtxTUMapTy CtxTUMap;
     64   SelMapTy SelMap;
     65 };
     66 
     67 } // namespace idx
     68 
     69 } // namespace clang
     70 
     71 #endif
     72