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