aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Index/DeclReferenceMap.h
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-06 21:34:47 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2009-07-06 21:34:47 +0000
commitccbcb70ee96cb67ed6c8b4142d050f3a6764edd7 (patch)
treed4803b36db97d778f1fedd25c0e1f0e55f8f660d /include/clang/Index/DeclReferenceMap.h
parent874012b1fb80dff2ec227c726a0c63d55e3db63f (diff)
Move ASTLocation and DeclReferenceMap from the AST library to the Index library.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74859 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Index/DeclReferenceMap.h')
-rw-r--r--include/clang/Index/DeclReferenceMap.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/include/clang/Index/DeclReferenceMap.h b/include/clang/Index/DeclReferenceMap.h
new file mode 100644
index 0000000000..130ca387d5
--- /dev/null
+++ b/include/clang/Index/DeclReferenceMap.h
@@ -0,0 +1,86 @@
+//===--- 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 <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 primary decls
+/// (see Decl::getPrimaryDecl()).
+class DeclReferenceMap {
+public:
+ explicit DeclReferenceMap(ASTContext &Ctx);
+
+ typedef std::multimap<NamedDecl*, ASTLocation> MapTy;
+
+ class astlocation_iterator {
+ MapTy::iterator I;
+
+ astlocation_iterator(MapTy::iterator i) : I(i) { }
+ friend class DeclReferenceMap;
+
+ public:
+ typedef ASTLocation value_type;
+ typedef ASTLocation& reference;
+ typedef ASTLocation* pointer;
+ typedef MapTy::iterator::iterator_category iterator_category;
+ typedef MapTy::iterator::difference_type difference_type;
+
+ astlocation_iterator() { }
+
+ reference operator*() const { return I->second; }
+ pointer operator->() const { return &I->second; }
+
+ astlocation_iterator& operator++() {
+ ++I;
+ return *this;
+ }
+
+ astlocation_iterator operator++(int) {
+ astlocation_iterator tmp(*this);
+ ++(*this);
+ return tmp;
+ }
+
+ friend bool operator==(astlocation_iterator L, astlocation_iterator R) {
+ return L.I == R.I;
+ }
+ friend bool operator!=(astlocation_iterator L, astlocation_iterator R) {
+ return L.I != R.I;
+ }
+ };
+
+ 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