clang API Documentation
00001 //===--- Indexer.h - IndexProvider implementation ---------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // IndexProvider implementation. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_INDEX_INDEXER_H 00015 #define LLVM_CLANG_INDEX_INDEXER_H 00016 00017 #include "clang/Index/IndexProvider.h" 00018 #include "clang/Index/Entity.h" 00019 #include "clang/Index/GlobalSelector.h" 00020 #include "llvm/ADT/SmallPtrSet.h" 00021 #include "llvm/ADT/DenseMap.h" 00022 #include <map> 00023 00024 namespace clang { 00025 class ASTContext; 00026 class FunctionDecl; 00027 00028 namespace idx { 00029 class Program; 00030 class TranslationUnit; 00031 00032 /// \brief Maps information to TranslationUnits. 00033 class Indexer : public IndexProvider { 00034 public: 00035 typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy; 00036 typedef llvm::DenseMap<ASTContext *, TranslationUnit *> CtxTUMapTy; 00037 typedef std::map<Entity, TUSetTy> MapTy; 00038 typedef std::map<GlobalSelector, TUSetTy> SelMapTy; 00039 typedef std::map<Entity, std::pair<FunctionDecl*,TranslationUnit*> > DefMapTy; 00040 00041 explicit Indexer(Program &prog) : 00042 Prog(prog) { } 00043 00044 Program &getProgram() const { return Prog; } 00045 00046 /// \brief Find all Entities and map them to the given translation unit. 00047 void IndexAST(TranslationUnit *TU); 00048 00049 virtual void GetTranslationUnitsFor(Entity Ent, 00050 TranslationUnitHandler &Handler); 00051 virtual void GetTranslationUnitsFor(GlobalSelector Sel, 00052 TranslationUnitHandler &Handler); 00053 00054 std::pair<FunctionDecl*, TranslationUnit*> getDefinitionFor(Entity Ent); 00055 00056 private: 00057 Program &Prog; 00058 00059 MapTy Map; 00060 // Map a function Entity to the its definition. 00061 DefMapTy DefMap; 00062 00063 CtxTUMapTy CtxTUMap; 00064 SelMapTy SelMap; 00065 }; 00066 00067 } // namespace idx 00068 00069 } // namespace clang 00070 00071 #endif