clang API Documentation
00001 //===--- Handlers.h - Interfaces for receiving information ------*- 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 // Abstract interfaces for receiving information. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_INDEX_HANDLERS_H 00015 #define LLVM_CLANG_INDEX_HANDLERS_H 00016 00017 #include "clang/Basic/LLVM.h" 00018 #include "llvm/ADT/SmallVector.h" 00019 00020 namespace clang { 00021 00022 namespace idx { 00023 class Entity; 00024 class TranslationUnit; 00025 class TULocation; 00026 00027 /// \brief Abstract interface for receiving Entities. 00028 class EntityHandler { 00029 public: 00030 typedef Entity receiving_type; 00031 00032 virtual ~EntityHandler(); 00033 virtual void Handle(Entity Ent) = 0; 00034 }; 00035 00036 /// \brief Abstract interface for receiving TranslationUnits. 00037 class TranslationUnitHandler { 00038 public: 00039 typedef TranslationUnit* receiving_type; 00040 00041 virtual ~TranslationUnitHandler(); 00042 virtual void Handle(TranslationUnit *TU) = 0; 00043 }; 00044 00045 /// \brief Abstract interface for receiving TULocations. 00046 class TULocationHandler { 00047 public: 00048 typedef TULocation receiving_type; 00049 00050 virtual ~TULocationHandler(); 00051 virtual void Handle(TULocation TULoc) = 0; 00052 }; 00053 00054 /// \brief Helper for the Handler classes. Stores the objects into a vector. 00055 /// example: 00056 /// @code 00057 /// Storing<TranslationUnitHandler> TURes; 00058 /// IndexProvider.GetTranslationUnitsFor(Entity, TURes); 00059 /// for (Storing<TranslationUnitHandler>::iterator 00060 /// I = TURes.begin(), E = TURes.end(); I != E; ++I) { .... 00061 /// @endcode 00062 template <typename handler_type> 00063 class Storing : public handler_type { 00064 typedef typename handler_type::receiving_type receiving_type; 00065 typedef SmallVector<receiving_type, 8> StoreTy; 00066 StoreTy Store; 00067 00068 public: 00069 virtual void Handle(receiving_type Obj) { 00070 Store.push_back(Obj); 00071 } 00072 00073 typedef typename StoreTy::const_iterator iterator; 00074 iterator begin() const { return Store.begin(); } 00075 iterator end() const { return Store.end(); } 00076 }; 00077 00078 } // namespace idx 00079 00080 } // namespace clang 00081 00082 #endif