clang  3.7.0
DeclLookups.h
Go to the documentation of this file.
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/ASTContext.h"
18 #include "clang/AST/DeclBase.h"
21 
22 namespace clang {
23 
24 /// all_lookups_iterator - An iterator that provides a view over the results
25 /// of looking up every possible name.
27  StoredDeclsMap::iterator It, End;
28 public:
32  typedef std::forward_iterator_tag iterator_category;
34 
36  all_lookups_iterator(StoredDeclsMap::iterator It,
37  StoredDeclsMap::iterator End)
38  : It(It), End(End) {}
39 
40  DeclarationName getLookupName() const { return It->first; }
41 
42  reference operator*() const { return It->second.getLookupResult(); }
43  pointer operator->() const { return It->second.getLookupResult(); }
44 
46  // Filter out using directives. They don't belong as results from name
47  // lookup anyways, except as an implementation detail. Users of the API
48  // should not expect to get them (or worse, rely on it).
49  do {
50  ++It;
51  } while (It != End &&
53 
54  return *this;
55  }
56 
58  all_lookups_iterator tmp(*this);
59  ++(*this);
60  return tmp;
61  }
62 
64  return x.It == y.It;
65  }
67  return x.It != y.It;
68  }
69 };
70 
72  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
73  if (Primary->hasExternalVisibleStorage())
75  if (StoredDeclsMap *Map = Primary->buildLookup())
76  return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
77  all_lookups_iterator(Map->end(), Map->end()));
78 
79  // Synthesize an empty range. This requires that two default constructed
80  // versions of these iterators form a valid empty range.
82 }
83 
85  return lookups().begin();
86 }
87 
89  return lookups().end();
90 }
91 
93  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
94  if (StoredDeclsMap *Map = Primary->getLookupPtr())
95  return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
96  all_lookups_iterator(Map->end(), Map->end()));
97 
98  // Synthesize an empty range. This requires that two default constructed
99  // versions of these iterators form a valid empty range.
101 }
102 
103 inline
105  return noload_lookups().begin();
106 }
107 
108 inline
110  return noload_lookups().end();
111 }
112 
113 } // end namespace clang
114 
115 #endif
Defines the clang::ASTContext interface.
friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:66
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure. This may omit some names if we are lazi...
Definition: DeclBase.h:1709
friend bool operator==(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:63
std::forward_iterator_tag iterator_category
Definition: DeclLookups.h:32
The results of name lookup within a DeclContext. This is either a single result (with no stable stora...
Definition: DeclBase.h:1034
all_lookups_iterator lookups_end() const
Definition: DeclLookups.h:88
lookups_range noload_lookups() const
Definition: DeclLookups.h:92
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1277
all_lookups_iterator & operator++()
Definition: DeclLookups.h:45
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
lookups_range lookups() const
Definition: DeclLookups.h:71
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1203
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:1657
all_lookups_iterator lookups_begin() const
Iterators over all possible lookups within this context.
Definition: DeclLookups.h:84
DeclarationName getLookupName() const
Definition: DeclLookups.h:40
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:864
all_lookups_iterator noload_lookups_end() const
Definition: DeclLookups.h:109
all_lookups_iterator noload_lookups_begin() const
Iterators over all possible lookups within this context that are currently loaded; don't attempt to r...
Definition: DeclLookups.h:104
unsigned Map[Count]
Definition: AddressSpaces.h:45
all_lookups_iterator operator++(int)
Definition: DeclLookups.h:57
static __inline__ uint32_t uint32_t y
Definition: arm_acle.h:113
all_lookups_iterator(StoredDeclsMap::iterator It, StoredDeclsMap::iterator End)
Definition: DeclLookups.h:36
__PTRDIFF_TYPE__ ptrdiff_t
Definition: stddef.h:51
DeclContext * getPrimaryContext()
Definition: DeclBase.cpp:920
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:1726