DeclLookups.h revision 173a37a57b79bd8f94b85c2273039e760b159922
1//===-- DeclLookups.h - Low-level interface to all names in a DC-*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines DeclContext::all_lookups_iterator. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_DECLLOOKUPS_H 15#define LLVM_CLANG_AST_DECLLOOKUPS_H 16 17#include "clang/AST/DeclBase.h" 18#include "clang/AST/DeclContextInternals.h" 19#include "clang/AST/DeclarationName.h" 20 21namespace clang { 22 23/// all_lookups_iterator - An iterator that provides a view over the results 24/// of looking up every possible name. 25class DeclContext::all_lookups_iterator { 26 StoredDeclsMap::iterator It, End; 27public: 28 typedef lookup_result value_type; 29 typedef lookup_result reference; 30 typedef lookup_result pointer; 31 typedef std::forward_iterator_tag iterator_category; 32 typedef std::ptrdiff_t difference_type; 33 34 all_lookups_iterator() {} 35 all_lookups_iterator(StoredDeclsMap::iterator It, 36 StoredDeclsMap::iterator End) 37 : It(It), End(End) {} 38 39 reference operator*() const { return It->second.getLookupResult(); } 40 pointer operator->() const { return It->second.getLookupResult(); } 41 42 all_lookups_iterator& operator++() { 43 // Filter out using directives. They don't belong as results from name 44 // lookup anyways, except as an implementation detail. Users of the API 45 // should not expect to get them (or worse, rely on it). 46 do { 47 ++It; 48 } while (It != End && 49 It->first == DeclarationName::getUsingDirectiveName()); 50 51 return *this; 52 } 53 54 all_lookups_iterator operator++(int) { 55 all_lookups_iterator tmp(*this); 56 ++(*this); 57 return tmp; 58 } 59 60 friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) { 61 return x.It == y.It; 62 } 63 friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) { 64 return x.It != y.It; 65 } 66}; 67 68DeclContext::all_lookups_iterator DeclContext::lookups_begin() const { 69 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext(); 70 if (StoredDeclsMap *Map = Primary->buildLookup()) 71 return all_lookups_iterator(Map->begin(), Map->end()); 72 return all_lookups_iterator(); 73} 74 75DeclContext::all_lookups_iterator DeclContext::lookups_end() const { 76 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext(); 77 if (StoredDeclsMap *Map = Primary->buildLookup()) 78 return all_lookups_iterator(Map->end(), Map->end()); 79 return all_lookups_iterator(); 80} 81 82} // end namespace clang 83 84#endif 85