Coverage Report

Created: 2018-07-22 10:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/DeclLookups.h
Line
Count
Source (jump to first uncovered line)
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
220
  all_lookups_iterator() = default;
40
  all_lookups_iterator(StoredDeclsMap::iterator It,
41
                       StoredDeclsMap::iterator End)
42
2.38k
      : It(It), End(End) {}
43
44
131
  DeclarationName getLookupName() const { return It->first; }
45
46
7.76k
  reference operator*() const { return It->second.getLookupResult(); }
47
  pointer operator->() const { return It->second.getLookupResult(); }
48
49
7.76k
  all_lookups_iterator& operator++() {
50
7.76k
    // Filter out using directives. They don't belong as results from name
51
7.76k
    // lookup anyways, except as an implementation detail. Users of the API
52
7.76k
    // should not expect to get them (or worse, rely on it).
53
7.80k
    do {
54
7.80k
      ++It;
55
7.80k
    } while (It != End &&
56
7.80k
             
It->first == DeclarationName::getUsingDirectiveName()6.61k
);
57
7.76k
             
58
7.76k
    return *this;
59
7.76k
  }
60
61
0
  all_lookups_iterator operator++(int) {
62
0
    all_lookups_iterator tmp(*this);
63
0
    ++(*this);
64
0
    return tmp;
65
0
  }
66
67
0
  friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
68
0
    return x.It == y.It;
69
0
  }
70
71
9.06k
  friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
72
9.06k
    return x.It != y.It;
73
9.06k
  }
74
};
75
76
1.29k
inline DeclContext::lookups_range DeclContext::lookups() const {
77
1.29k
  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
78
1.29k
  if (Primary->hasExternalVisibleStorage())
79
65
    getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
80
1.29k
  if (StoredDeclsMap *Map = Primary->buildLookup())
81
1.18k
    return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
82
1.18k
                         all_lookups_iterator(Map->end(), Map->end()));
83
110
84
110
  // Synthesize an empty range. This requires that two default constructed
85
110
  // versions of these iterators form a valid empty range.
86
110
  return lookups_range(all_lookups_iterator(), all_lookups_iterator());
87
110
}
88
89
inline DeclContext::lookups_range
90
9
DeclContext::noload_lookups(bool PreserveInternalState) const {
91
9
  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
92
9
  if (!PreserveInternalState)
93
2
    Primary->loadLazyLocalLexicalLookups();
94
9
  if (StoredDeclsMap *Map = Primary->getLookupPtr())
95
9
    return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
96
9
                         all_lookups_iterator(Map->end(), Map->end()));
97
0
98
0
  // Synthesize an empty range. This requires that two default constructed
99
0
  // versions of these iterators form a valid empty range.
100
0
  return lookups_range(all_lookups_iterator(), all_lookups_iterator());
101
0
}
102
103
} // namespace clang
104
105
#endif // LLVM_CLANG_AST_DECLLOOKUPS_H