diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:41:33 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:41:33 +0000 |
commit | b325146ac7f8e197b6d12aa5c11a3f0a7244e870 (patch) | |
tree | b93b84085c2ad67cc28d701d922a25858500763b | |
parent | 66570b230941651245accbc5680b60e904eb993c (diff) |
Use a STL helper template 'pair_value_iterator', by both DeclReferenceMap and SelectorMap.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77545 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Index/DeclReferenceMap.h | 39 | ||||
-rw-r--r-- | include/clang/Index/STLExtras.h | 63 | ||||
-rw-r--r-- | include/clang/Index/SelectorMap.h | 44 |
3 files changed, 68 insertions, 78 deletions
diff --git a/include/clang/Index/DeclReferenceMap.h b/include/clang/Index/DeclReferenceMap.h index d1e2c09e98..1ed64369fc 100644 --- a/include/clang/Index/DeclReferenceMap.h +++ b/include/clang/Index/DeclReferenceMap.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_INDEX_DECLREFERENCEMAP_H #include "clang/Index/ASTLocation.h" +#include "clang/Index/STLExtras.h" #include <map> namespace clang { @@ -32,43 +33,7 @@ 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; - } - }; + typedef pair_value_iterator<MapTy::iterator> astlocation_iterator; astlocation_iterator refs_begin(NamedDecl *D) const; astlocation_iterator refs_end(NamedDecl *D) const; diff --git a/include/clang/Index/STLExtras.h b/include/clang/Index/STLExtras.h new file mode 100644 index 0000000000..a9707204c5 --- /dev/null +++ b/include/clang/Index/STLExtras.h @@ -0,0 +1,63 @@ +//===--- STLExtras.h - Helper STL related templates -------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Helper templates for using with the STL. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_INDEX_STLEXTRAS_H +#define LLVM_CLANG_INDEX_STLEXTRAS_H + +namespace clang { + +namespace idx { + +/// \brief Wraps an iterator whose value_type is a pair, and provides +/// pair's second object as the value. +template <typename iter_type> +class pair_value_iterator { + iter_type I; + +public: + typedef typename iter_type::value_type::second_type value_type; + typedef value_type& reference; + typedef value_type* pointer; + typedef typename iter_type::iterator_category iterator_category; + typedef typename iter_type::difference_type difference_type; + + pair_value_iterator() { } + pair_value_iterator(iter_type i) : I(i) { } + + reference operator*() const { return I->second; } + pointer operator->() const { return &I->second; } + + pair_value_iterator& operator++() { + ++I; + return *this; + } + + pair_value_iterator operator++(int) { + pair_value_iterator tmp(*this); + ++(*this); + return tmp; + } + + friend bool operator==(pair_value_iterator L, pair_value_iterator R) { + return L.I == R.I; + } + friend bool operator!=(pair_value_iterator L, pair_value_iterator R) { + return L.I != R.I; + } +}; + +} // end idx namespace + +} // end clang namespace + +#endif diff --git a/include/clang/Index/SelectorMap.h b/include/clang/Index/SelectorMap.h index 4cd10cc4f6..0fb6afb741 100644 --- a/include/clang/Index/SelectorMap.h +++ b/include/clang/Index/SelectorMap.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_INDEX_SELECTORMAP_H #include "clang/Index/ASTLocation.h" +#include "clang/Index/STLExtras.h" #include "clang/Basic/IdentifierTable.h" #include <map> @@ -29,53 +30,14 @@ namespace idx { /// /// References are mapped and retrieved using the canonical decls. class SelectorMap { - - template <typename iter_type> - class wrap_pair_iterator { - iter_type I; - - wrap_pair_iterator(iter_type i) : I(i) { } - friend class SelectorMap; - - public: - typedef typename iter_type::value_type::second_type value_type; - typedef value_type& reference; - typedef value_type* pointer; - typedef typename iter_type::iterator_category iterator_category; - typedef typename iter_type::difference_type difference_type; - - wrap_pair_iterator() { } - - reference operator*() const { return I->second; } - pointer operator->() const { return &I->second; } - - wrap_pair_iterator& operator++() { - ++I; - return *this; - } - - wrap_pair_iterator operator++(int) { - wrap_pair_iterator tmp(*this); - ++(*this); - return tmp; - } - - friend bool operator==(wrap_pair_iterator L, wrap_pair_iterator R) { - return L.I == R.I; - } - friend bool operator!=(wrap_pair_iterator L, wrap_pair_iterator R) { - return L.I != R.I; - } - }; - public: explicit SelectorMap(ASTContext &Ctx); typedef std::multimap<Selector, ObjCMethodDecl *> SelMethMapTy; typedef std::multimap<Selector, ASTLocation> SelRefMapTy; - typedef wrap_pair_iterator<SelMethMapTy::iterator> method_iterator; - typedef wrap_pair_iterator<SelRefMapTy::iterator> astlocation_iterator; + typedef pair_value_iterator<SelMethMapTy::iterator> method_iterator; + typedef pair_value_iterator<SelRefMapTy::iterator> astlocation_iterator; method_iterator methods_begin(Selector Sel) const; method_iterator methods_end(Selector Sel) const; |