Coverage Report

Created: 2019-02-21 13: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
// 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
230
  all_lookups_iterator() = default;
39
  all_lookups_iterator(StoredDeclsMap::iterator It,
40
                       StoredDeclsMap::iterator End)
41
2.81k
      : It(It), End(End) {}
42
43
131
  DeclarationName getLookupName() const { return It->first; }
44
45
9.07k
  reference operator*() const { return It->second.getLookupResult(); }
46
  pointer operator->() const { return It->second.getLookupResult(); }
47
48
9.07k
  all_lookups_iterator& operator++() {
49
9.07k
    // Filter out using directives. They don't belong as results from name
50
9.07k
    // lookup anyways, except as an implementation detail. Users of the API
51
9.07k
    // should not expect to get them (or worse, rely on it).
52
9.12k
    do {
53
9.12k
      ++It;
54
9.12k
    } while (It != End &&
55
9.12k
             
It->first == DeclarationName::getUsingDirectiveName()7.72k
);
56
9.07k
57
9.07k
    return *this;
58
9.07k
  }
59
60
0
  all_lookups_iterator operator++(int) {
61
0
    all_lookups_iterator tmp(*this);
62
0
    ++(*this);
63
0
    return tmp;
64
0
  }
65
66
0
  friend bool operator==(all_lookups_iterator x, all_lookups_iterator y) {
67
0
    return x.It == y.It;
68
0
  }
69
70
10.5k
  friend bool operator!=(all_lookups_iterator x, all_lookups_iterator y) {
71
10.5k
    return x.It != y.It;
72
10.5k
  }
73
};
74
75
1.51k
inline DeclContext::lookups_range DeclContext::lookups() const {
76
1.51k
  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
77
1.51k
  if (Primary->hasExternalVisibleStorage())
78
66
    getParentASTContext().getExternalSource()->completeVisibleDeclsMap(Primary);
79
1.51k
  if (StoredDeclsMap *Map = Primary->buildLookup())
80
1.39k
    return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
81
1.39k
                         all_lookups_iterator(Map->end(), Map->end()));
82
114
83
114
  // Synthesize an empty range. This requires that two default constructed
84
114
  // versions of these iterators form a valid empty range.
85
114
  return lookups_range(all_lookups_iterator(), all_lookups_iterator());
86
114
}
87
88
inline DeclContext::lookups_range
89
12
DeclContext::noload_lookups(bool PreserveInternalState) const {
90
12
  DeclContext *Primary = const_cast<DeclContext*>(this)->getPrimaryContext();
91
12
  if (!PreserveInternalState)
92
5
    Primary->loadLazyLocalLexicalLookups();
93
12
  if (StoredDeclsMap *Map = Primary->getLookupPtr())
94
11
    return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
95
11
                         all_lookups_iterator(Map->end(), Map->end()));
96
1
97
1
  // Synthesize an empty range. This requires that two default constructed
98
1
  // versions of these iterators form a valid empty range.
99
1
  return lookups_range(all_lookups_iterator(), all_lookups_iterator());
100
1
}
101
102
} // namespace clang
103
104
#endif // LLVM_CLANG_AST_DECLLOOKUPS_H