diff options
37 files changed, 3 insertions, 2899 deletions
diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 5e4ecadd69..041eabb5b9 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -14,7 +14,6 @@ #ifndef LLVM_CLANG_FRONTEND_ASTUNIT_H #define LLVM_CLANG_FRONTEND_ASTUNIT_H -#include "clang/Index/ASTLocation.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Sema/Sema.h" #include "clang/Sema/CodeCompleteConsumer.h" @@ -57,8 +56,6 @@ class SourceManager; class TargetInfo; class ASTFrontendAction; -using namespace idx; - /// \brief Utility class for loading a ASTContext from an AST file. /// class ASTUnit : public ModuleLoader { @@ -134,9 +131,6 @@ private: /// The name of the original source file used to generate this ASTUnit. std::string OriginalSourceFile; - // Critical optimization when using clang_getCursor(). - ASTLocation LastLoc; - /// \brief The set of diagnostics produced when creating the preamble. SmallVector<StoredDiagnostic, 4> PreambleDiagnostics; @@ -474,10 +468,6 @@ public: bool getOwnsRemappedFileBuffers() const { return OwnsRemappedFileBuffers; } void setOwnsRemappedFileBuffers(bool val) { OwnsRemappedFileBuffers = val; } - void setLastASTLocation(ASTLocation ALoc) { LastLoc = ALoc; } - ASTLocation getLastASTLocation() const { return LastLoc; } - - StringRef getMainFileName() const; typedef std::vector<Decl *>::iterator top_level_iterator; diff --git a/include/clang/Index/ASTLocation.h b/include/clang/Index/ASTLocation.h deleted file mode 100644 index 45097cc5c3..0000000000 --- a/include/clang/Index/ASTLocation.h +++ /dev/null @@ -1,173 +0,0 @@ -//===--- ASTLocation.h - A <Decl, Stmt> pair --------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// ASTLocation is Decl or a Stmt and its immediate Decl parent. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_ASTLOCATION_H -#define LLVM_CLANG_INDEX_ASTLOCATION_H - -#include "clang/AST/TypeLoc.h" -#include "llvm/ADT/PointerIntPair.h" -#include "llvm/Support/Compiler.h" - -namespace clang { - class Decl; - class Stmt; - class NamedDecl; - -namespace idx { - class TranslationUnit; - -/// \brief Represents a Decl or a Stmt and its immediate Decl parent. It's -/// immutable. -/// -/// ASTLocation is intended to be used as a "pointer" into the AST. It is either -/// just a Decl, or a Stmt and its Decl parent. Since a single Stmt is devoid -/// of context, its parent Decl provides all the additional missing information -/// like the declaration context, ASTContext, etc. -/// -class ASTLocation { -public: - enum NodeKind { - N_Decl, N_NamedRef, N_Stmt, N_Type - }; - - struct NamedRef { - NamedDecl *ND; - SourceLocation Loc; - - NamedRef() : ND(0) { } - NamedRef(NamedDecl *nd, SourceLocation loc) : ND(nd), Loc(loc) { } - }; - -private: - llvm::PointerIntPair<Decl *, 2, NodeKind> ParentDecl; - - union { - Decl *D; - Stmt *Stm; - struct { - NamedDecl *ND; - unsigned RawLoc; - } NDRef; - struct { - void *TyPtr; - void *Data; - } Ty; - }; - -public: - ASTLocation() { } - - explicit ASTLocation(const Decl *d) - : ParentDecl(const_cast<Decl*>(d), N_Decl), D(const_cast<Decl*>(d)) { } - - ASTLocation(const Decl *parentDecl, const Stmt *stm) - : ParentDecl(const_cast<Decl*>(parentDecl), N_Stmt), - Stm(const_cast<Stmt*>(stm)) { - if (!stm) ParentDecl.setPointer(0); - } - - ASTLocation(const Decl *parentDecl, NamedDecl *ndRef, SourceLocation loc) - : ParentDecl(const_cast<Decl*>(parentDecl), N_NamedRef) { - if (ndRef) { - NDRef.ND = ndRef; - NDRef.RawLoc = loc.getRawEncoding(); - } else - ParentDecl.setPointer(0); - } - - ASTLocation(const Decl *parentDecl, TypeLoc tyLoc) - : ParentDecl(const_cast<Decl*>(parentDecl), N_Type) { - if (tyLoc) { - Ty.TyPtr = tyLoc.getType().getAsOpaquePtr(); - Ty.Data = tyLoc.getOpaqueData(); - } else - ParentDecl.setPointer(0); - } - - bool isValid() const { return ParentDecl.getPointer() != 0; } - bool isInvalid() const { return !isValid(); } - - NodeKind getKind() const { - assert(isValid()); - return (NodeKind)ParentDecl.getInt(); - } - - Decl *getParentDecl() const { return ParentDecl.getPointer(); } - - Decl *AsDecl() const { - assert(getKind() == N_Decl); - return D; - } - Stmt *AsStmt() const { - assert(getKind() == N_Stmt); - return Stm; - } - NamedRef AsNamedRef() const { - assert(getKind() == N_NamedRef); - return NamedRef(NDRef.ND, SourceLocation::getFromRawEncoding(NDRef.RawLoc)); - } - TypeLoc AsTypeLoc() const { - assert(getKind() == N_Type); - return TypeLoc(QualType::getFromOpaquePtr(Ty.TyPtr), Ty.Data); - } - - Decl *dyn_AsDecl() const { return isValid() && getKind() == N_Decl ? D : 0; } - Stmt *dyn_AsStmt() const { - return isValid() && getKind() == N_Stmt ? Stm : 0; - } - NamedRef dyn_AsNamedRef() const { - return getKind() == N_Type ? AsNamedRef() : NamedRef(); - } - TypeLoc dyn_AsTypeLoc() const { - return getKind() == N_Type ? AsTypeLoc() : TypeLoc(); - } - - bool isDecl() const { return isValid() && getKind() == N_Decl; } - bool isStmt() const { return isValid() && getKind() == N_Stmt; } - bool isNamedRef() const { return isValid() && getKind() == N_NamedRef; } - bool isType() const { return isValid() && getKind() == N_Type; } - - /// \brief Returns the declaration that this ASTLocation references. - /// - /// If this points to a Decl, that Decl is returned. - /// If this points to an Expr that references a Decl, that Decl is returned, - /// otherwise it returns NULL. - Decl *getReferencedDecl(); - const Decl *getReferencedDecl() const { - return const_cast<ASTLocation*>(this)->getReferencedDecl(); - } - - SourceRange getSourceRange() const LLVM_READONLY; - - void print(raw_ostream &OS) const; -}; - -/// \brief Like ASTLocation but also contains the TranslationUnit that the -/// ASTLocation originated from. -class TULocation : public ASTLocation { - TranslationUnit *TU; - -public: - TULocation(TranslationUnit *tu, ASTLocation astLoc) - : ASTLocation(astLoc), TU(tu) { - assert(tu && "Passed null translation unit"); - } - - TranslationUnit *getTU() const { return TU; } -}; - -} // namespace idx - -} // namespace clang - -#endif diff --git a/include/clang/Index/Analyzer.h b/include/clang/Index/Analyzer.h deleted file mode 100644 index f6b5465148..0000000000 --- a/include/clang/Index/Analyzer.h +++ /dev/null @@ -1,56 +0,0 @@ -//===--- Analyzer.h - Analysis for indexing information ---------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file declares the Analyzer interface. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_ANALYZER_H -#define LLVM_CLANG_INDEX_ANALYZER_H - -namespace clang { - class Decl; - class ObjCMessageExpr; - -namespace idx { - class Program; - class IndexProvider; - class TULocationHandler; - -/// \brief Provides indexing information, like finding all references of an -/// Entity across translation units. -class Analyzer { - Program &Prog; - IndexProvider &Idxer; - - Analyzer(const Analyzer&); // do not implement - Analyzer &operator=(const Analyzer &); // do not implement - -public: - explicit Analyzer(Program &prog, IndexProvider &idxer) - : Prog(prog), Idxer(idxer) { } - - /// \brief Find all TULocations for declarations of the given Decl and pass - /// them to Handler. - void FindDeclarations(Decl *D, TULocationHandler &Handler); - - /// \brief Find all TULocations for references of the given Decl and pass - /// them to Handler. - void FindReferences(Decl *D, TULocationHandler &Handler); - - /// \brief Find methods that may respond to the given message and pass them - /// to Handler. - void FindObjCMethods(ObjCMessageExpr *MsgE, TULocationHandler &Handler); -}; - -} // namespace idx - -} // namespace clang - -#endif diff --git a/include/clang/Index/DeclReferenceMap.h b/include/clang/Index/DeclReferenceMap.h deleted file mode 100644 index 73f2fe50b3..0000000000 --- a/include/clang/Index/DeclReferenceMap.h +++ /dev/null @@ -1,50 +0,0 @@ -//===--- DeclReferenceMap.h - Map Decls to their references -----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// DeclReferenceMap creates a mapping from Decls to the ASTLocations that -// reference them. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_DECLREFERENCEMAP_H -#define LLVM_CLANG_INDEX_DECLREFERENCEMAP_H - -#include "clang/Index/ASTLocation.h" -#include "clang/Index/STLExtras.h" -#include <map> - -namespace clang { - class ASTContext; - class NamedDecl; - -namespace idx { - -/// \brief Maps NamedDecls with the ASTLocations that reference them. -/// -/// References are mapped and retrieved using the canonical decls. -class DeclReferenceMap { -public: - explicit DeclReferenceMap(ASTContext &Ctx); - - typedef std::multimap<NamedDecl*, ASTLocation> MapTy; - typedef pair_value_iterator<MapTy::iterator> astlocation_iterator; - - astlocation_iterator refs_begin(NamedDecl *D) const; - astlocation_iterator refs_end(NamedDecl *D) const; - bool refs_empty(NamedDecl *D) const; - -private: - mutable MapTy Map; -}; - -} // end idx namespace - -} // end clang namespace - -#endif diff --git a/include/clang/Index/Entity.h b/include/clang/Index/Entity.h deleted file mode 100644 index d104458ec2..0000000000 --- a/include/clang/Index/Entity.h +++ /dev/null @@ -1,149 +0,0 @@ -//===--- Entity.h - Cross-translation-unit "token" for decls ----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Entity is a ASTContext-independent way to refer to declarations that are -// visible across translation units. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_ENTITY_H -#define LLVM_CLANG_INDEX_ENTITY_H - -#include "clang/Basic/LLVM.h" -#include "llvm/ADT/PointerUnion.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/StringRef.h" -#include <string> - -namespace clang { - class ASTContext; - class Decl; - -namespace idx { - class Program; - class EntityImpl; - -/// \brief A ASTContext-independent way to refer to declarations. -/// -/// Entity is basically the link for declarations that are semantically the same -/// in multiple ASTContexts. A client will convert a Decl into an Entity and -/// later use that Entity to find the "same" Decl into another ASTContext. -/// Declarations that are semantically the same and visible across translation -/// units will be associated with the same Entity. -/// -/// An Entity may also refer to declarations that cannot be visible across -/// translation units, e.g. static functions with the same name in multiple -/// translation units will be associated with different Entities. -/// -/// Entities can be checked for equality but note that the same Program object -/// should be used when getting Entities. -/// -class Entity { - /// \brief Stores the Decl directly if it is not visible outside of its own - /// translation unit, otherwise it stores the associated EntityImpl. - llvm::PointerUnion<Decl *, EntityImpl *> Val; - - explicit Entity(Decl *D); - explicit Entity(EntityImpl *impl) : Val(impl) { } - friend class EntityGetter; - -public: - Entity() { } - - /// \brief Find the Decl that can be referred to by this entity. - Decl *getDecl(ASTContext &AST) const; - - /// \brief If this Entity represents a declaration that is internal to its - /// translation unit, getInternalDecl() returns it. - Decl *getInternalDecl() const { - assert(isInternalToTU() && "This Entity is not internal!"); - return Val.get<Decl *>(); - } - - /// \brief Get a printable name for debugging purpose. - std::string getPrintableName() const; - - /// \brief Get an Entity associated with the given Decl. - /// \returns invalid Entity if an Entity cannot refer to this Decl. - static Entity get(Decl *D, Program &Prog); - - /// \brief Get an Entity associated with a name in the global namespace. - static Entity get(StringRef Name, Program &Prog); - - /// \brief true if the Entity is not visible outside the trasnlation unit. - bool isInternalToTU() const { - assert(isValid() && "This Entity is not valid!"); - return Val.is<Decl *>(); - } - - bool isValid() const { return !Val.isNull(); } - bool isInvalid() const { return !isValid(); } - - void *getAsOpaquePtr() const { return Val.getOpaqueValue(); } - static Entity getFromOpaquePtr(void *Ptr) { - Entity Ent; - Ent.Val = llvm::PointerUnion<Decl *, EntityImpl *>::getFromOpaqueValue(Ptr); - return Ent; - } - - friend bool operator==(const Entity &LHS, const Entity &RHS) { - return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr(); - } - - // For use in a std::map. - friend bool operator < (const Entity &LHS, const Entity &RHS) { - return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr(); - } - - // For use in DenseMap/DenseSet. - static Entity getEmptyMarker() { - Entity Ent; - Ent.Val = - llvm::PointerUnion<Decl *, EntityImpl *>::getFromOpaqueValue((void*)-1); - return Ent; - } - static Entity getTombstoneMarker() { - Entity Ent; - Ent.Val = - llvm::PointerUnion<Decl *, EntityImpl *>::getFromOpaqueValue((void*)-2); - return Ent; - } -}; - -} // namespace idx - -} // namespace clang - -namespace llvm { -/// Define DenseMapInfo so that Entities can be used as keys in DenseMap and -/// DenseSets. -template<> -struct DenseMapInfo<clang::idx::Entity> { - static inline clang::idx::Entity getEmptyKey() { - return clang::idx::Entity::getEmptyMarker(); - } - - static inline clang::idx::Entity getTombstoneKey() { - return clang::idx::Entity::getTombstoneMarker(); - } - - static unsigned getHashValue(clang::idx::Entity); - - static inline bool - isEqual(clang::idx::Entity LHS, clang::idx::Entity RHS) { - return LHS == RHS; - } -}; - -template <> -struct isPodLike<clang::idx::Entity> { static const bool value = true; }; - -} // end namespace llvm - -#endif diff --git a/include/clang/Index/GlobalCallGraph.h b/include/clang/Index/GlobalCallGraph.h deleted file mode 100644 index 7ba1cceac1..0000000000 --- a/include/clang/Index/GlobalCallGraph.h +++ /dev/null @@ -1,149 +0,0 @@ -//== GlobalCallGraph.h - Call graph building --------------------*- C++ -*--==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defined the CallGraph and CallGraphNode classes. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_CALLGRAPH -#define LLVM_CLANG_INDEX_CALLGRAPH - -#include "clang/Index/ASTLocation.h" -#include "clang/Index/Entity.h" -#include "clang/Index/Program.h" -#include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/GraphTraits.h" -#include "llvm/ADT/STLExtras.h" -#include <vector> -#include <map> - -using namespace clang; - -namespace clang { -namespace idx { - -class CallGraphNode { - Entity F; - typedef std::pair<ASTLocation, CallGraphNode*> CallRecord; - std::vector<CallRecord> CalledFunctions; - -public: - CallGraphNode(Entity f) : F(f) {} - - typedef std::vector<CallRecord>::iterator iterator; - typedef std::vector<CallRecord>::const_iterator const_iterator; - - iterator begin() { return CalledFunctions.begin(); } - iterator end() { return CalledFunctions.end(); } - const_iterator begin() const { return CalledFunctions.begin(); } - const_iterator end() const { return CalledFunctions.end(); } - - void addCallee(ASTLocation L, CallGraphNode *Node) { - CalledFunctions.push_back(std::make_pair(L, Node)); - } - - bool hasCallee() const { return begin() != end(); } - - std::string getName() const { return F.getPrintableName(); } - - Decl *getDecl(ASTContext &Ctx) const { return F.getDecl(Ctx); } -}; - -class CallGraph { - /// Program manages all Entities. - Program &Prog; - - typedef std::map<Entity, CallGraphNode *> FunctionMapTy; - - /// FunctionMap owns all CallGraphNodes. - FunctionMapTy FunctionMap; - - /// CallerCtx maps a caller to its ASTContext. - llvm::DenseMap<CallGraphNode *, ASTContext *> CallerCtx; - - /// Root node is the 'main' function or 0. - CallGraphNode *Root; - - /// ExternalCallingNode has edges to all external functions. - CallGraphNode *ExternalCallingNode; - -public: - CallGraph(Program &P); - ~CallGraph(); - - typedef FunctionMapTy::iterator iterator; - typedef FunctionMapTy::const_iterator const_iterator; - - iterator begin() { return FunctionMap.begin(); } - iterator end() { return FunctionMap.end(); } - const_iterator begin() const { return FunctionMap.begin(); } - const_iterator end() const { return FunctionMap.end(); } - - CallGraphNode *getRoot() { return Root; } - - CallGraphNode *getExternalCallingNode() { return ExternalCallingNode; } - - void addTU(ASTContext &AST); - - Program &getProgram() { return Prog; } - - CallGraphNode *getOrInsertFunction(idx::Entity F); - - Decl *getDecl(CallGraphNode *Node); - - void print(raw_ostream &os); - void dump(); - - void ViewCallGraph() const; -}; - -}} // end clang idx namespace - -namespace llvm { - -template <> struct GraphTraits<clang::idx::CallGraph> { - typedef clang::idx::CallGraph GraphType; - typedef clang::idx::CallGraphNode NodeType; - - typedef std::pair<clang::idx::ASTLocation, NodeType*> CGNPairTy; - typedef std::pointer_to_unary_function<CGNPairTy, NodeType*> CGNDerefFun; - - typedef mapped_iterator<NodeType::iterator, CGNDerefFun> ChildIteratorType; - - static NodeType *getEntryNode(GraphType *CG) { - return CG->getExternalCallingNode(); - } - - static ChildIteratorType child_begin(NodeType *N) { - return map_iterator(N->begin(), CGNDerefFun(CGNDeref)); - } - static ChildIteratorType child_end(NodeType *N) { - return map_iterator(N->end(), CGNDerefFun(CGNDeref)); - } - - typedef std::pair<clang::idx::Entity, NodeType*> PairTy; - typedef std::pointer_to_unary_function<PairTy, NodeType*> DerefFun; - - typedef mapped_iterator<GraphType::const_iterator, DerefFun> nodes_iterator; - - static nodes_iterator nodes_begin(const GraphType &CG) { - return map_iterator(CG.begin(), DerefFun(CGDeref)); - } - static nodes_iterator nodes_end(const GraphType &CG) { - return map_iterator(CG.end(), DerefFun(CGDeref)); - } - - static NodeType *CGNDeref(CGNPairTy P) { return P.second; } - - static NodeType *CGDeref(PairTy P) { return P.second; } -}; - -} // end llvm namespace - -#endif diff --git a/include/clang/Index/GlobalSelector.h b/include/clang/Index/GlobalSelector.h deleted file mode 100644 index 9cd83a8595..0000000000 --- a/include/clang/Index/GlobalSelector.h +++ /dev/null @@ -1,100 +0,0 @@ -//===--- GlobalSelector.h - Cross-translation-unit "token" for selectors --===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// GlobalSelector is a ASTContext-independent way to refer to selectors. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_GLOBALSELECTOR_H -#define LLVM_CLANG_INDEX_GLOBALSELECTOR_H - -#include "llvm/ADT/DenseMap.h" -#include <string> - -namespace clang { - class ASTContext; - class Selector; - -namespace idx { - class Program; - -/// \brief A ASTContext-independent way to refer to selectors. -class GlobalSelector { - void *Val; - - explicit GlobalSelector(void *val) : Val(val) { } - -public: - GlobalSelector() : Val(0) { } - - /// \brief Get the ASTContext-specific selector. - Selector getSelector(ASTContext &AST) const; - - bool isValid() const { return Val != 0; } - bool isInvalid() const { return !isValid(); } - - /// \brief Get a printable name for debugging purpose. - std::string getPrintableName() const; - - /// \brief Get a GlobalSelector for the ASTContext-specific selector. - static GlobalSelector get(Selector Sel, Program &Prog); - - void *getAsOpaquePtr() const { return Val; } - - static GlobalSelector getFromOpaquePtr(void *Ptr) { - return GlobalSelector(Ptr); - } - - friend bool operator==(const GlobalSelector &LHS, const GlobalSelector &RHS) { - return LHS.getAsOpaquePtr() == RHS.getAsOpaquePtr(); - } - - // For use in a std::map. - friend bool operator< (const GlobalSelector &LHS, const GlobalSelector &RHS) { - return LHS.getAsOpaquePtr() < RHS.getAsOpaquePtr(); - } - - // For use in DenseMap/DenseSet. - static GlobalSelector getEmptyMarker() { return GlobalSelector((void*)-1); } - static GlobalSelector getTombstoneMarker() { - return GlobalSelector((void*)-2); - } -}; - -} // namespace idx - -} // namespace clang - -namespace llvm { -/// Define DenseMapInfo so that GlobalSelectors can be used as keys in DenseMap -/// and DenseSets. -template<> -struct DenseMapInfo<clang::idx::GlobalSelector> { - static inline clang::idx::GlobalSelector getEmptyKey() { - return clang::idx::GlobalSelector::getEmptyMarker(); - } - - static inline clang::idx::GlobalSelector getTombstoneKey() { - return clang::idx::GlobalSelector::getTombstoneMarker(); - } - - static unsigned getHashValue(clang::idx::GlobalSelector); - - static inline bool - isEqual(clang::idx::GlobalSelector LHS, clang::idx::GlobalSelector RHS) { - return LHS == RHS; - } -}; - -template <> -struct isPodLike<clang::idx::GlobalSelector> { static const bool value = true;}; - -} // end namespace llvm - -#endif diff --git a/include/clang/Index/Handlers.h b/include/clang/Index/Handlers.h deleted file mode 100644 index 1e017f8a7c..0000000000 --- a/include/clang/Index/Handlers.h +++ /dev/null @@ -1,82 +0,0 @@ -//===--- Handlers.h - Interfaces for receiving information ------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// Abstract interfaces for receiving information. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_INDEX_HANDLERS_H -#define LLVM_CLANG_INDEX_HANDLERS_H - -#include "clang/Basic/LLVM.h" -#include "llvm/ADT/SmallVector.h" - -namespace clang { - -namespace idx { - class Entity; - class TranslationUnit; - class TULocation; - -/// \brief Abstract interface for receiving Entities. -class EntityHandler { -public: - typedef Entity receiving_type; - - virtual ~EntityHandler(); - virtual void Handle(Entity Ent) = 0; -}; - -/// \brief Abstract interface for receiving TranslationUnits. -class TranslationUnitHandler { -public: - typedef TranslationUnit* receiving_type; - - virtual ~TranslationUnitHandler(); - virtual void Handle(TranslationUnit *TU) = 0; -}; - -/// \brief Abstract interface for receiving TULocations. -class TULocationHandler { -public: - typedef TULocation receiving_type; - - virtual ~TULocationHandler(); - virtual void Handle(TULocation TULoc) = 0; -}; - -/// \brief Helper for the Handler classes. Stores the objects into a vector. -/// example: -/// @code -/// Storing<TranslationUnitHandler> TURes; -/// IndexProvider.GetTranslationUnitsFor(Entity, TURes); -/// for (Storing<TranslationUnitHandler>::iterator -/// I = TURes.begin(), E = TURes.end(); I != E; ++I) { .... -/// @endcode -template <typename handler_type> -class Storing : public handler_type { - typedef typename handler_type::receiving_type receiving_type; - typedef SmallVector<receiving_type, 8> StoreTy; - StoreTy Store; - -public: - virtual void Handle(receiving_type Obj) { - Store.push_back(Obj); - } - - typedef typename StoreTy::const_iterator iterator; - iterator begin() const { return Store.begin(); } - iterator end() const { return Store.end(); } -}; - -} // namespace idx - -} // namespace clang - -#endif |