[cfe-commits] r77545 - in /cfe/trunk/include/clang/Index: DeclReferenceMap.h STLExtras.h SelectorMap.h

Argiris Kirtzidis akyrtzi at gmail.com
Wed Jul 29 16:41:34 PDT 2009


Author: akirtzidis
Date: Wed Jul 29 18:41:33 2009
New Revision: 77545

URL: http://llvm.org/viewvc/llvm-project?rev=77545&view=rev
Log:
Use a STL helper template 'pair_value_iterator', by both DeclReferenceMap and SelectorMap.

Added:
    cfe/trunk/include/clang/Index/STLExtras.h
Modified:
    cfe/trunk/include/clang/Index/DeclReferenceMap.h
    cfe/trunk/include/clang/Index/SelectorMap.h

Modified: cfe/trunk/include/clang/Index/DeclReferenceMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/DeclReferenceMap.h?rev=77545&r1=77544&r2=77545&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/DeclReferenceMap.h (original)
+++ cfe/trunk/include/clang/Index/DeclReferenceMap.h Wed Jul 29 18:41:33 2009
@@ -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 @@
   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;

Added: cfe/trunk/include/clang/Index/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/STLExtras.h?rev=77545&view=auto

==============================================================================
--- cfe/trunk/include/clang/Index/STLExtras.h (added)
+++ cfe/trunk/include/clang/Index/STLExtras.h Wed Jul 29 18:41:33 2009
@@ -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

Modified: cfe/trunk/include/clang/Index/SelectorMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/SelectorMap.h?rev=77545&r1=77544&r2=77545&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/SelectorMap.h (original)
+++ cfe/trunk/include/clang/Index/SelectorMap.h Wed Jul 29 18:41:33 2009
@@ -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 @@
 ///
 /// 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;





More information about the cfe-commits mailing list