aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/clang/Index/Entity.h70
-rw-r--r--include/clang/Index/EntityHandler.h33
-rw-r--r--include/clang/Index/IndexProvider.h56
-rw-r--r--include/clang/Index/Program.h43
-rw-r--r--include/clang/Index/TranslationUnit.h33
5 files changed, 235 insertions, 0 deletions
diff --git a/include/clang/Index/Entity.h b/include/clang/Index/Entity.h
new file mode 100644
index 0000000000..8caaeb870f
--- /dev/null
+++ b/include/clang/Index/Entity.h
@@ -0,0 +1,70 @@
+//===--- 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 "llvm/ADT/FoldingSet.h"
+
+namespace clang {
+ class ASTContext;
+ class Decl;
+
+namespace idx {
+ class Program;
+
+/// \brief A ASTContext-independent way to refer to declarations that are
+/// visible across translation units.
+///
+/// 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.
+///
+/// An Entity may only refer to declarations that can be visible by multiple
+/// translation units, e.g. a static function cannot have an Entity associated
+/// with it.
+///
+/// Entities are uniqued so pointer equality can be used (note that the same
+/// Program object should be used when getting Entities).
+///
+class Entity : public llvm::FoldingSetNode {
+public:
+ /// \brief Find the Decl that can be referred to by this entity.
+ Decl *getDecl(ASTContext &AST);
+
+ /// \brief Get an Entity associated with the given Decl.
+ /// \returns Null if an Entity cannot refer to this Decl.
+ static Entity *get(Decl *D, Program &Prog);
+
+ void Profile(llvm::FoldingSetNodeID &ID) const {
+ Profile(ID, Parent, Id);
+ }
+ static void Profile(llvm::FoldingSetNodeID &ID, Entity *Parent, void *Id) {
+ ID.AddPointer(Parent);
+ ID.AddPointer(Id);
+ }
+
+private:
+ Entity *Parent;
+ void *Id;
+
+ Entity(Entity *parent, void *id) : Parent(parent), Id(id) { }
+ friend class EntityGetter;
+};
+
+} // namespace idx
+
+} // namespace clang
+
+#endif
diff --git a/include/clang/Index/EntityHandler.h b/include/clang/Index/EntityHandler.h
new file mode 100644
index 0000000000..b5c2cee881
--- /dev/null
+++ b/include/clang/Index/EntityHandler.h
@@ -0,0 +1,33 @@
+//===--- EntityHandler.h - Interface for receiving entities -----*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Abstract interface for receiving Entities.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_INDEX_ENTITYHANDLER_H
+#define LLVM_CLANG_INDEX_ENTITYHANDLER_H
+
+namespace clang {
+
+namespace idx {
+ class Entity;
+
+/// \brief Abstract interface for receiving Entities.
+class EntityHandler {
+public:
+ virtual ~EntityHandler();
+ virtual void HandleEntity(Entity *Ent) { }
+};
+
+} // namespace idx
+
+} // namespace clang
+
+#endif
diff --git a/include/clang/Index/IndexProvider.h b/include/clang/Index/IndexProvider.h
new file mode 100644
index 0000000000..abd436cc82
--- /dev/null
+++ b/include/clang/Index/IndexProvider.h
@@ -0,0 +1,56 @@
+//===--- IndexProvider.h - Map of entities to translation units -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSaE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Maps Entities to TranslationUnits
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_INDEX_INDEXPROVIDER_H
+#define LLVM_CLANG_INDEX_INDEXPROVIDER_H
+
+#include "llvm/ADT/SmallPtrSet.h"
+#include <map>
+
+namespace clang {
+
+namespace idx {
+ class Program;
+ class Entity;
+ class TranslationUnit;
+
+/// \brief Maps Entities to TranslationUnits.
+class IndexProvider {
+ typedef llvm::SmallPtrSet<TranslationUnit *, 4> TUSetTy;
+ typedef std::map<Entity *, TUSetTy> MapTy;
+ class Indexer;
+
+public:
+ explicit IndexProvider(Program &prog) : Prog(prog) { }
+
+ Program &getProgram() const { return Prog; }
+
+ /// \brief Find all Entities and map them to the given translation unit.
+ void IndexAST(TranslationUnit *TU);
+
+ typedef TUSetTy::iterator translation_unit_iterator;
+
+ translation_unit_iterator translation_units_begin(Entity *Ent) const;
+ translation_unit_iterator translation_units_end(Entity *Ent) const;
+ bool translation_units_empty(Entity *Ent) const;
+
+private:
+ Program &Prog;
+ mutable MapTy Map;
+};
+
+} // namespace idx
+
+} // namespace clang
+
+#endif
diff --git a/include/clang/Index/Program.h b/include/clang/Index/Program.h
new file mode 100644
index 0000000000..30afa0be46
--- /dev/null
+++ b/include/clang/Index/Program.h
@@ -0,0 +1,43 @@
+//===--- Program.h - Entity originator and misc -----------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Storage for Entities and utility functions
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_INDEX_PROGRAM_H
+#define LLVM_CLANG_INDEX_PROGRAM_H
+
+namespace clang {
+ class ASTContext;
+
+namespace idx {
+ class EntityHandler;
+
+/// \brief Repository for Entities.
+class Program {
+ void *Impl;
+
+ Program(const Program&); // do not implement
+ Program &operator=(const Program &); // do not implement
+ friend class Entity;
+
+public:
+ Program();
+ ~Program();
+
+ /// \brief Traverses the AST and passes all the entities to the Handler.
+ void FindEntities(ASTContext &Ctx, EntityHandler *Handler);
+};
+
+} // namespace idx
+
+} // namespace clang
+
+#endif
diff --git a/include/clang/Index/TranslationUnit.h b/include/clang/Index/TranslationUnit.h
new file mode 100644
index 0000000000..d0171422de
--- /dev/null
+++ b/include/clang/Index/TranslationUnit.h
@@ -0,0 +1,33 @@
+//===--- TranslationUnit.h - Interface for a translation unit ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSaE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Abstract interface for a translation unit
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_INDEX_TRANSLATIONUNIT_H
+#define LLVM_CLANG_INDEX_TRANSLATIONUNIT_H
+
+namespace clang {
+ class ASTContext;
+
+namespace idx {
+
+/// \brief Abstract interface for a translation unit.
+class TranslationUnit {
+public:
+ virtual ~TranslationUnit();
+ virtual ASTContext &getASTContext() = 0;
+};
+
+} // namespace idx
+
+} // namespace clang
+
+#endif