clang 10.0.0git

DeclLookups.h
Go to the documentation of this file.
1 //===- DeclLookups.h - Low-level interface to all names in a DC -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines DeclContext::all_lookups_iterator.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_AST_DECLLOOKUPS_H
14 #define LLVM_CLANG_AST_DECLLOOKUPS_H
15
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclBase.h"
18 #include "clang/AST/DeclContextInternals.h"
19 #include "clang/AST/DeclarationName.h"
20 #include "clang/AST/ExternalASTSource.h"
21 #include <cstddef>
22 #include <iterator>
23
24 namespace clang {
25
26 /// all_lookups_iterator - An iterator that provides a view over the results
27 /// of looking up every possible name.
28 class DeclContext::all_lookups_iterator {
29 StoredDeclsMap::iterator It, End;
30
31 public:
32 using value_type = lookup_result;
33 using reference = lookup_result;
34 using pointer = lookup_result;
35 using iterator_category = std::forward_iterator_tag;
36 using difference_type = std::ptrdiff_t;
37
38 all_lookups_iterator() = default;
39 all_lookups_iterator(StoredDeclsMap::iterator It,
40 StoredDeclsMap::iterator End)
41 : It(It), End(End) {}
42
43 DeclarationName getLookupName() const { return It->first; }
44
45 reference operator*() const { return It->second.getLookupResult(); }
46 pointer operator->() const { return It->second.getLookupResult(); }
47
48 all_lookups_iterator& operator++() {
49 // Filter out using directives. They don't belong as results from name
50 // lookup anyways, except as an implementation detail. Users of the API
51 // should not expect to get them (or worse, rely on it).
52 do {
53 ++It;
54 } while (It != End &&
55 It->first == DeclarationName::getUsingDirectiveName());
56
57 return *this;
58 }
59
60 all_lookups_iterator operator++(int) {
61 all_lookups_iterator tmp(*this);
62 ++(*this);
63 return tmp;
64 }
65
66 friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
67 return x.It == y.It;
68 }
69
70 friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
71 return x.It != y.It;
72 }
73 };
74
75 inline DeclContext::lookups_range DeclContext::lookups() const {
76 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
77 if (Primary->hasExternalVisibleStorage())
78 getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
79 if (StoredDeclsMap *Map = Primary->buildLookup())
80 return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
81 all_lookups_iterator(Map->end(), Map->end()));
82
83 // Synthesize an empty range. This requires that two default constructed
84 // versions of these iterators form a valid empty range.
85 return lookups_range(all_lookups_iterator(), all_lookups_iterator());
86 }
87
88 inline DeclContext::lookups_range
89 DeclContext::noload_lookups(bool PreserveInternalState) const {
90 DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
91 if (!PreserveInternalState)
92 Primary->loadLazyLocalLexicalLookups();
93 if (StoredDeclsMap *Map = Primary->getLookupPtr())
94 return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
95 all_lookups_iterator(Map->end(), Map->end()));
96
97 // Synthesize an empty range. This requires that two default constructed
98 // versions of these iterators form a valid empty range.
99 return lookups_range(all_lookups_iterator(), all_lookups_iterator());
100 }
101
102 } // namespace clang
103
104 #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:35
clang::DeclContext::all_lookups_iterator::operator!=
friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:70
clang::DeclContext::hasExternalVisibleStorage
bool hasExternalVisibleStorage() const
Whether this DeclContext has external storage containing additional declarations that are visible in ...
Definition: DeclBase.h:2360
clang::DeclContext::all_lookups_iterator::operator==
friend bool operator==(all_lookups_iterator x, all_lookups_iterator y)
Definition: DeclLookups.h:66
clang::DeclContext::noload_lookups
lookups_range noload_lookups(bool PreserveInternalState) const
Definition: DeclLookups.h:89
clang::DeclContext::all_lookups_iterator::difference_type
std::ptrdiff_t difference_type
Definition: DeclLookups.h:36
clang::DeclContextLookupResult
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1195
clang::DeclContext::all_lookups_iterator::getLookupName
DeclarationName getLookupName() const
Definition: DeclLookups.h:43
clang::DeclContext::buildLookup
StoredDeclsMap * buildLookup()
Ensure the lookup structure is fully-built and return it.
Definition: DeclBase.cpp:1547
clang::DeclContext::lookups
lookups_range lookups() const
Definition: DeclLookups.h:75
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:48
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:116
clang::DeclContext::lookups_range
llvm::iterator_range< all_lookups_iterator > lookups_range
Definition: DeclBase.h:2284
clang::DeclContext::getLookupPtr
StoredDeclsMap * getLookupPtr() const
Retrieve the internal representation of the lookup structure.
Definition: DeclBase.h:2341
DeclBase.h
clang::DeclContext::all_lookups_iterator::operator->
pointer operator->() const
Definition: DeclLookups.h:46
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:28
DeclarationName.h
clang::StoredDeclsMap
Definition: DeclContextInternals.h:238
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
clang::DeclContext
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1271
clang::DeclarationName
The name of a declaration.
Definition: DeclarationName.h:145
clang::ASTContext::getExternalSource
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
Definition: ASTContext.h:1086
clang::DeclContext::all_lookups_iterator::operator++
all_lookups_iterator operator++(int)
Definition: DeclLookups.h:60
DeclContextInternals.h
clang::DeclContext::all_lookups_iterator::all_lookups_iterator
all_lookups_iterator(StoredDeclsMap::iterator It, StoredDeclsMap::iterator End)
Definition: DeclLookups.h:39
ptrdiff_t
__PTRDIFF_TYPE__ ptrdiff_t
A signed integer type that is the result of subtracting two pointers.
Definition: opencl-c-base.h:48
clang::DeclContext::lookup_result
DeclContextLookupResult lookup_result
Definition: DeclBase.h:2237
clang::DeclContext::getParentASTContext
ASTContext & getParentASTContext() const
Definition: DeclBase.h:1813
clang::DeclContext::getPrimaryContext
DeclContext * getPrimaryContext()
getPrimaryContext - There may be many different declarations of the same entity (including forward de...
Definition: DeclBase.cpp:1171
clang::DeclarationName::getUsingDirectiveName
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
Definition: DeclarationName.h:359
clang::DeclContext::all_lookups_iterator::operator*
reference operator*() const
Definition: DeclLookups.h:45