Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:32

0001 //===- DeclLookups.h - Low-level interface to all names in a DC -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 //  This file defines DeclContext::all_lookups_iterator.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CLANG_AST_DECLLOOKUPS_H
0014 #define LLVM_CLANG_AST_DECLLOOKUPS_H
0015 
0016 #include "clang/AST/ASTContext.h"
0017 #include "clang/AST/DeclBase.h"
0018 #include "clang/AST/DeclContextInternals.h"
0019 #include "clang/AST/DeclarationName.h"
0020 #include "clang/AST/ExternalASTSource.h"
0021 #include <cstddef>
0022 #include <iterator>
0023 
0024 namespace clang {
0025 
0026 /// all_lookups_iterator - An iterator that provides a view over the results
0027 /// of looking up every possible name.
0028 class DeclContext::all_lookups_iterator {
0029   StoredDeclsMap::iterator It, End;
0030 
0031 public:
0032   using value_type = lookup_result;
0033   using reference = lookup_result;
0034   using pointer = lookup_result;
0035   using iterator_category = std::forward_iterator_tag;
0036   using difference_type = std::ptrdiff_t;
0037 
0038   all_lookups_iterator() = default;
0039   all_lookups_iterator(StoredDeclsMap::iterator It,
0040                        StoredDeclsMap::iterator End)
0041       : It(It), End(End) {}
0042 
0043   DeclarationName getLookupName() const { return It->first; }
0044 
0045   reference operator*() const { return It->second.getLookupResult(); }
0046   pointer operator->() const { return It->second.getLookupResult(); }
0047 
0048   all_lookups_iterator& operator++() {
0049     // Filter out using directives. They don't belong as results from name
0050     // lookup anyways, except as an implementation detail. Users of the API
0051     // should not expect to get them (or worse, rely on it).
0052     do {
0053       ++It;
0054     } while (It != End &&
0055              It->first == DeclarationName::getUsingDirectiveName());
0056 
0057     return *this;
0058   }
0059 
0060   all_lookups_iterator operator++(int) {
0061     all_lookups_iterator tmp(*this);
0062     ++(*this);
0063     return tmp;
0064   }
0065 
0066   friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
0067     return x.It == y.It;
0068   }
0069 
0070   friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
0071     return x.It != y.It;
0072   }
0073 };
0074 
0075 inline DeclContext::lookups_range DeclContext::lookups() const {
0076   DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
0077   if (Primary->hasExternalVisibleStorage())
0078     getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
0079   if (StoredDeclsMap *Map = Primary->buildLookup())
0080     return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
0081                          all_lookups_iterator(Map->end(), Map->end()));
0082 
0083   // Synthesize an empty range. This requires that two default constructed
0084   // versions of these iterators form a valid empty range.
0085   return lookups_range(all_lookups_iterator(), all_lookups_iterator());
0086 }
0087 
0088 inline DeclContext::lookups_range
0089 DeclContext::noload_lookups(bool PreserveInternalState) const {
0090   DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
0091   if (!PreserveInternalState)
0092     Primary->loadLazyLocalLexicalLookups();
0093   if (StoredDeclsMap *Map = Primary->getLookupPtr())
0094     return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
0095                          all_lookups_iterator(Map->end(), Map->end()));
0096 
0097   // Synthesize an empty range. This requires that two default constructed
0098   // versions of these iterators form a valid empty range.
0099   return lookups_range(all_lookups_iterator(), all_lookups_iterator());
0100 }
0101 
0102 } // namespace clang
0103 
0104 #endif // LLVM_CLANG_AST_DECLLOOKUPS_H