clang API Documentation

DeclLookups.h
Go to the documentation of this file.
00001 //===-- DeclLookups.h - Low-level interface to all names in a DC-*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines DeclContext::all_lookups_iterator.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CLANG_AST_DECLLOOKUPS_H
00015 #define LLVM_CLANG_AST_DECLLOOKUPS_H
00016 
00017 #include "clang/AST/ASTContext.h"
00018 #include "clang/AST/DeclBase.h"
00019 #include "clang/AST/DeclContextInternals.h"
00020 #include "clang/AST/DeclarationName.h"
00021 
00022 namespace clang {
00023 
00024 /// all_lookups_iterator - An iterator that provides a view over the results
00025 /// of looking up every possible name.
00026 class DeclContext::all_lookups_iterator {
00027   StoredDeclsMap::iterator It, End;
00028 public:
00029   typedef lookup_result             value_type;
00030   typedef lookup_result             reference;
00031   typedef lookup_result             pointer;
00032   typedef std::forward_iterator_tag iterator_category;
00033   typedef std::ptrdiff_t            difference_type;
00034 
00035   all_lookups_iterator() {}
00036   all_lookups_iterator(StoredDeclsMap::iterator It,
00037                        StoredDeclsMap::iterator End)
00038       : It(It), End(End) {}
00039 
00040   DeclarationName getLookupName() const { return It->first; }
00041 
00042   reference operator*() const { return It->second.getLookupResult(); }
00043   pointer operator->() const { return It->second.getLookupResult(); }
00044 
00045   all_lookups_iterator& operator++() {
00046     // Filter out using directives. They don't belong as results from name
00047     // lookup anyways, except as an implementation detail. Users of the API
00048     // should not expect to get them (or worse, rely on it).
00049     do {
00050       ++It;
00051     } while (It != End &&
00052              It->first == DeclarationName::getUsingDirectiveName());
00053              
00054     return *this;
00055   }
00056 
00057   all_lookups_iterator operator++(int) {
00058     all_lookups_iterator tmp(*this);
00059     ++(*this);
00060     return tmp;
00061   }
00062 
00063   friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
00064     return x.It == y.It;
00065   }
00066   friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
00067     return x.It != y.It;
00068   }
00069 };
00070 
00071 inline DeclContext::lookups_range DeclContext::lookups() const {
00072   DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
00073   if (Primary->hasExternalVisibleStorage())
00074     getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
00075   if (StoredDeclsMap *Map = Primary->buildLookup())
00076     return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
00077                          all_lookups_iterator(Map->end(), Map->end()));
00078   return lookups_range();
00079 }
00080 
00081 inline DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
00082   return lookups().begin();
00083 }
00084 
00085 inline DeclContext::all_lookups_iterator DeclContext::lookups_end() const {
00086   return lookups().end();
00087 }
00088 
00089 inline DeclContext::lookups_range DeclContext::noload_lookups() const {
00090   DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
00091   if (StoredDeclsMap *Map = Primary->getLookupPtr())
00092     return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
00093                          all_lookups_iterator(Map->end(), Map->end()));
00094   return lookups_range();
00095 }
00096 
00097 inline
00098 DeclContext::all_lookups_iterator DeclContext::noload_lookups_begin() const {
00099   return noload_lookups().begin();
00100 }
00101 
00102 inline
00103 DeclContext::all_lookups_iterator DeclContext::noload_lookups_end() const {
00104   return noload_lookups().end();
00105 }
00106 
00107 } // end namespace clang
00108 
00109 #endif