clang  6.0.0svn
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"
22 #include <cstddef>
23 #include <iterator>
24 
25 namespace clang {
26 
27 /// all_lookups_iterator - An iterator that provides a view over the results
28 /// of looking up every possible name.
30  StoredDeclsMap::iterator It, End;
31 
32 public:
36  using iterator_category = std::forward_iterator_tag;
38 
39  all_lookups_iterator() = default;
40  all_lookups_iterator(StoredDeclsMap::iterator It,
41  StoredDeclsMap::iterator End)
42  : It(It), End(End) {}
43 
44  DeclarationName getLookupName() const { return It->first; }
45 
46  reference operator*() const { return It->second.getLookupResult(); }
47  pointer operator->() const { return It->second.getLookupResult(); }
48 
50  // Filter out using directives. They don't belong as results from name
51  // lookup anyways, except as an implementation detail. Users of the API
52  // should not expect to get them (or worse, rely on it).
53  do {
54  ++It;
55  } while (It != End &&
57 
58  return *this;
59  }
60 
62  all_lookups_iterator tmp(*this);
63  ++(*this);
64  return tmp;
65  }
66 
68  return x.It == y.It;
69  }
70 
72  return x.It != y.It;
73  }
74 };
75 
77  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
78  if (Primary->hasExternalVisibleStorage())
80  if (StoredDeclsMap *Map = Primary->buildLookup())
81  return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
82  all_lookups_iterator(Map->end(), Map->end()));
83 
84  // Synthesize an empty range. This requires that two default constructed
85  // versions of these iterators form a valid empty range.
87 }
88 
90  return lookups().begin();
91 }
92 
94  return lookups().end();
95 }
96 
98  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
99  if (StoredDeclsMap *Map = Primary->getLookupPtr())
100  return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
101  all_lookups_iterator(Map->end(), Map->end()));
102 
103  // Synthesize an empty range. This requires that two default constructed
104  // versions of these iterators form a valid empty range.
106 }
107 
108 inline
110  return noload_lookups().begin();
111 }
112 
113 inline
115  return noload_lookups().end();
116 }
117 
118 } // namespace clang
119 
120 #endif // LLVM_CLANG_AST_DECLLOOKUPS_H
Defines the clang::ASTContext interface.
std::forward_iterator_tag iterator_category
Definition: DeclLookups.h:36
friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:71
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:1895
friend bool operator==(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:67
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1178
all_lookups_iterator lookups_begin() const
Iterators over all possible lookups within this context.
Definition: DeclLookups.h:89
DeclarationName getLookupName() const
Definition: DeclLookups.h:44
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1459
lookups_range lookups() const
Definition: DeclLookups.h:76
all_lookups_iterator & operator++()
Definition: DeclLookups.h:49
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:1823
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:1878
lookups_range noload_lookups() const
Definition: DeclLookups.h:97
all_lookups_iterator lookups_end() const
Definition: DeclLookups.h:93
all_lookups_iterator - An iterator that provides a view over the results of looking up every possible...
Definition: DeclLookups.h:29
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Definition: opencl-c.h:68
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1252
DeclarationName - The name of a declaration.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1048
all_lookups_iterator operator++(int)
Definition: DeclLookups.h:61
all_lookups_iterator noload_lookups_end() const
Definition: DeclLookups.h:114
all_lookups_iterator(StoredDeclsMap::iterator It, StoredDeclsMap::iterator End)
Definition: DeclLookups.h:40
DeclContextLookupResult lookup_result
Definition: DeclBase.h:1776
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1360
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1106
static DeclarationName getUsingDirectiveName()
getUsingDirectiveName - Return name for all using-directives.
all_lookups_iterator noload_lookups_begin() const
Iterators over all possible lookups within this context that are currently loaded; don&#39;t attempt to r...
Definition: DeclLookups.h:109