1 //===--- Handlers.h - Interfaces for receiving information ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Abstract interfaces for receiving information.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_INDEX_HANDLERS_H
15 #define LLVM_CLANG_INDEX_HANDLERS_H
17 #include "clang/Basic/LLVM.h"
18 #include "llvm/ADT/SmallVector.h"
24 class TranslationUnit;
27 /// \brief Abstract interface for receiving Entities.
30 typedef Entity receiving_type;
32 virtual ~EntityHandler();
33 virtual void Handle(Entity Ent) = 0;
36 /// \brief Abstract interface for receiving TranslationUnits.
37 class TranslationUnitHandler {
39 typedef TranslationUnit* receiving_type;
41 virtual ~TranslationUnitHandler();
42 virtual void Handle(TranslationUnit *TU) = 0;
45 /// \brief Abstract interface for receiving TULocations.
46 class TULocationHandler {
48 typedef TULocation receiving_type;
50 virtual ~TULocationHandler();
51 virtual void Handle(TULocation TULoc) = 0;
54 /// \brief Helper for the Handler classes. Stores the objects into a vector.
57 /// Storing<TranslationUnitHandler> TURes;
58 /// IndexProvider.GetTranslationUnitsFor(Entity, TURes);
59 /// for (Storing<TranslationUnitHandler>::iterator
60 /// I = TURes.begin(), E = TURes.end(); I != E; ++I) { ....
62 template <typename handler_type>
63 class Storing : public handler_type {
64 typedef typename handler_type::receiving_type receiving_type;
65 typedef SmallVector<receiving_type, 8> StoreTy;
69 virtual void Handle(receiving_type Obj) {
73 typedef typename StoreTy::const_iterator iterator;
74 iterator begin() const { return Store.begin(); }
75 iterator end() const { return Store.end(); }