]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Index/Handlers.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Index / Handlers.h
1 //===--- Handlers.h - Interfaces for receiving information ------*- 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 //  Abstract interfaces for receiving information.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_INDEX_HANDLERS_H
15 #define LLVM_CLANG_INDEX_HANDLERS_H
16
17 #include "llvm/ADT/SmallVector.h"
18
19 namespace clang {
20
21 namespace idx {
22   class Entity;
23   class TranslationUnit;
24   class TULocation;
25
26 /// \brief Abstract interface for receiving Entities.
27 class EntityHandler {
28 public:
29   typedef Entity receiving_type;
30
31   virtual ~EntityHandler();
32   virtual void Handle(Entity Ent) = 0;
33 };
34
35 /// \brief Abstract interface for receiving TranslationUnits.
36 class TranslationUnitHandler {
37 public:
38   typedef TranslationUnit* receiving_type;
39
40   virtual ~TranslationUnitHandler();
41   virtual void Handle(TranslationUnit *TU) = 0;
42 };
43
44 /// \brief Abstract interface for receiving TULocations.
45 class TULocationHandler {
46 public:
47   typedef TULocation receiving_type;
48
49   virtual ~TULocationHandler();
50   virtual void Handle(TULocation TULoc) = 0;
51 };
52
53 /// \brief Helper for the Handler classes. Stores the objects into a vector.
54 /// example:
55 /// @code
56 /// Storing<TranslationUnitHandler> TURes;
57 /// IndexProvider.GetTranslationUnitsFor(Entity, TURes);
58 /// for (Storing<TranslationUnitHandler>::iterator
59 ///   I = TURes.begin(), E = TURes.end(); I != E; ++I) { ....
60 /// @endcode
61 template <typename handler_type>
62 class Storing : public handler_type {
63   typedef typename handler_type::receiving_type receiving_type;
64   typedef llvm::SmallVector<receiving_type, 8> StoreTy;
65   StoreTy Store;
66
67 public:
68   virtual void Handle(receiving_type Obj) {
69     Store.push_back(Obj);
70   }
71
72   typedef typename StoreTy::const_iterator iterator;
73   iterator begin() const { return Store.begin(); }
74   iterator end() const { return Store.end(); }
75 };
76
77 } // namespace idx
78
79 } // namespace clang
80
81 #endif