]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/AST/DeclLookups.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / AST / DeclLookups.h
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