clang 8.0.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"
19 #include "clang/AST/DeclContextInternals.h"
20 #include "clang/AST/DeclarationName.h"
21 #include "clang/AST/ExternalASTSource.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.
29 class DeclContext::all_lookups_iterator {
30 StoredDeclsMap::iterator It, End;
31
32 public:
33 using value_type = lookup_result;
34 using reference = lookup_result;
35 using pointer = lookup_result;
36 using iterator_category = std::forward_iterator_tag;
37 using difference_type = std::ptrdiff_t;
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
49 all_lookups_iterator& operator++() {
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 &&
56 It->first == DeclarationName::getUsingDirectiveName());
57
58 return *this;
59 }
60
61 all_lookups_iterator operator++(int) {
62 all_lookups_iterator tmp(*this);
63 ++(*this);
64 return tmp;
65 }
66
67 friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
68 return x.It == y.It;
69 }
70
71 friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
72 return x.It != y.It;
73 }
74 };
75
76 inline DeclContext::lookups_range DeclContext::lookups() const {
77 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
78 if (Primary->hasExternalVisibleStorage())
79 getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
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.
86 return lookups_range(all_lookups_iterator(), all_lookups_iterator());
87 }
88
89 inline DeclContext::lookups_range
90 DeclContext::noload_lookups(bool PreserveInternalState) const {
91 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
92 if (!PreserveInternalState)
93 Primary->loadLazyLocalLexicalLookups();
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.
100 return lookups_range(all_lookups_iterator(), all_lookups_iterator());
101 }
102
103 } // namespace clang
104
105 #endif // LLVM_CLANG_AST_DECLLOOKUPS_H
ASTContext.h
Defines the clang::ASTContext interface.
clang::DeclContext::all_lookups_iterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: DeclLookups.h:36
clang::DeclContext::all_lookups_iterator::operator!=
friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:71
clang::DeclContext::hasExternalVisibleStorage
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2324
clang::DeclContext::all_lookups_iterator::operator==
friend bool operator==(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:67
clang::DeclContext::noload_lookups
lookups_range noload_lookups(bool PreserveInternalState) const
Definition: DeclLookups.h:90
clang::DeclContext::all_lookups_iterator::difference_type
std::ptrdiff_t difference_type
Definition: DeclLookups.h:37
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1187
clang::DeclContext::all_lookups_iterator::getLookupName
DeclarationName getLookupName() const
Definition: DeclLookups.h:44
clang::DeclContext::buildLookup
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1530
clang::DeclContext::lookups
lookups_range lookups() const
Definition: DeclLookups.h:76
clang::DeclContext::all_lookups_iterator::all_lookups_iterator
all_lookups_iterator()=default
clang::DeclContext::all_lookups_iterator::operator++
all_lookups_iterator & operator++()
Definition: DeclLookups.h:49
ExternalASTSource.h
clang::ExternalASTSource::completeVisibleDeclsMap
virtual void completeVisibleDeclsMap(const DeclContext *DC)
Ensures that the table of all visible declarations inside this context is up to date.
Definition: ExternalASTSource.cpp:115
clang::DeclContext::lookups_range
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:2248
clang::DeclContext::getLookupPtr
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2305
DeclBase.h
clang::DeclContext::all_lookups_iterator::operator->
pointer operator->() const
Definition: DeclLookups.h:47
clang::DeclContext::all_lookups_iterator
all_lookups_iterator - An iterator that provides a view over the results of looking up every possible...
Definition: DeclLookups.h:29
DeclarationName.h
ptrdiff_t
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Definition: opencl-c.h:76
clang::StoredDeclsMap
Definition: DeclContextInternals.h:240
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1262
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:146
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1083
clang::DeclContext::all_lookups_iterator::operator++
all_lookups_iterator operator++(int)
Definition: DeclLookups.h:61
DeclContextInternals.h
clang::DeclContext::all_lookups_iterator::all_lookups_iterator
all_lookups_iterator(StoredDeclsMap::iterator It, StoredDeclsMap::iterator End)
Definition: DeclLookups.h:40
clang::DeclContext::lookup_result
DeclContextLookupResult lookup_result
Definition: DeclBase.h:2201
clang::DeclContext::getParentASTContext
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1781
clang::DeclContext::getPrimaryContext
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1158
clang::DeclarationName::getUsingDirectiveName
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
Definition: DeclarationName.h:360
clang::DeclContext::all_lookups_iterator::operator*
reference operator*() const
Definition: DeclLookups.h:46