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