Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/UnresolvedSet.h
Line
Count
Source (jump to first uncovered line)
1
//===- UnresolvedSet.h - Unresolved sets of declarations --------*- 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 the UnresolvedSet class, which is used to store
11
//  collections of declarations in the AST.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_AST_UNRESOLVEDSET_H
16
#define LLVM_CLANG_AST_UNRESOLVEDSET_H
17
18
#include "clang/AST/DeclAccessPair.h"
19
#include "clang/Basic/LLVM.h"
20
#include "clang/Basic/Specifiers.h"
21
#include "llvm/ADT/SmallVector.h"
22
#include "llvm/ADT/iterator.h"
23
#include <cstddef>
24
#include <iterator>
25
26
namespace clang {
27
28
class NamedDecl;
29
30
/// The iterator over UnresolvedSets.  Serves as both the const and
31
/// non-const iterator.
32
0
class UnresolvedSetIterator : public llvm::iterator_adaptor_base<
33
                                  UnresolvedSetIterator, DeclAccessPair *,
34
                                  std::random_access_iterator_tag, NamedDecl *,
35
                                  std::ptrdiff_t, NamedDecl *, NamedDecl *> {
36
  friend class ASTUnresolvedSet;
37
  friend class OverloadExpr;
38
  friend class UnresolvedSetImpl;
39
40
  explicit UnresolvedSetIterator(DeclAccessPair *Iter)
41
68.6M
      : iterator_adaptor_base(Iter) {}
42
  explicit UnresolvedSetIterator(const DeclAccessPair *Iter)
43
219M
      : iterator_adaptor_base(const_cast<DeclAccessPair *>(Iter)) {}
44
45
public:
46
  // Work around a bug in MSVC 2013 where explicitly default constructed
47
  // temporaries with defaulted ctors are not zero initialized.
48
94
  UnresolvedSetIterator() : iterator_adaptor_base(nullptr) {}
49
50
245M
  NamedDecl *getDecl() const { return I->getDecl(); }
51
45
  void setDecl(NamedDecl *ND) const { return I->setDecl(ND); }
52
6.74M
  AccessSpecifier getAccess() const { return I->getAccess(); }
53
47.5k
  void setAccess(AccessSpecifier AS) { I->setAccess(AS); }
54
8.82M
  const DeclAccessPair &getPair() const { return *I; }
55
56
244M
  NamedDecl *operator*() const { return getDecl(); }
57
17.8k
  NamedDecl *operator->() const { return **this; }
58
};
59
60
/// A set of unresolved declarations.
61
class UnresolvedSetImpl {
62
  using DeclsTy = SmallVectorImpl<DeclAccessPair>;
63
64
  // Don't allow direct construction, and only permit subclassing by
65
  // UnresolvedSet.
66
private:
67
  template <unsigned N> friend class UnresolvedSet;
68
69
  UnresolvedSetImpl() = default;
70
  UnresolvedSetImpl(const UnresolvedSetImpl &) = default;
71
  UnresolvedSetImpl &operator=(const UnresolvedSetImpl &) = default;
72
73
  // FIXME: Switch these to "= default" once MSVC supports generating move ops
74
7.57k
  UnresolvedSetImpl(UnresolvedSetImpl &&) {}
75
0
  UnresolvedSetImpl &operator=(UnresolvedSetImpl &&) { return *this; }
76
77
public:
78
  // We don't currently support assignment through this iterator, so we might
79
  // as well use the same implementation twice.
80
  using iterator = UnresolvedSetIterator;
81
  using const_iterator = UnresolvedSetIterator;
82
83
51.3M
  iterator begin() { return iterator(decls().begin()); }
84
96.4k
  iterator end() { return iterator(decls().end()); }
85
86
164M
  const_iterator begin() const { return const_iterator(decls().begin()); }
87
54.3M
  const_iterator end() const { return const_iterator(decls().end()); }
88
89
763
  void addDecl(NamedDecl *D) {
90
763
    addDecl(D, AS_none);
91
763
  }
92
93
88.7M
  void addDecl(NamedDecl *D, AccessSpecifier AS) {
94
88.7M
    decls().push_back(DeclAccessPair::make(D, AS));
95
88.7M
  }
96
97
  /// Replaces the given declaration with the new one, once.
98
  ///
99
  /// \return true if the set changed
100
0
  bool replace(const NamedDecl* Old, NamedDecl *New) {
101
0
    for (DeclsTy::iterator I = decls().begin(), E = decls().end(); I != E; ++I)
102
0
      if (I->getDecl() == Old)
103
0
        return (I->setDecl(New), true);
104
0
    return false;
105
0
  }
106
107
  /// Replaces the declaration at the given iterator with the new one,
108
  /// preserving the original access bits.
109
0
  void replace(iterator I, NamedDecl *New) { I.I->setDecl(New); }
110
111
82.2k
  void replace(iterator I, NamedDecl *New, AccessSpecifier AS) {
112
82.2k
    I.I->set(New, AS);
113
82.2k
  }
114
115
0
  void erase(unsigned I) { decls()[I] = decls().pop_back_val(); }
116
117
1.23M
  void erase(iterator I) { *I.I = decls().pop_back_val(); }
118
119
0
  void setAccess(iterator I, AccessSpecifier AS) { I.I->setAccess(AS); }
120
121
777k
  void clear() { decls().clear(); }
122
12.0M
  void set_size(unsigned N) { decls().set_size(N); }
123
124
124M
  bool empty() const { return decls().empty(); }
125
83.3M
  unsigned size() const { return decls().size(); }
126
127
2.40M
  void append(iterator I, iterator E) { decls().append(I.I, E.I); }
128
129
106M
  DeclAccessPair &operator[](unsigned I) { return decls()[I]; }
130
11.5k
  const DeclAccessPair &operator[](unsigned I) const { return decls()[I]; }
131
132
private:
133
  // These work because the only permitted subclass is UnresolvedSetImpl
134
135
262M
  DeclsTy &decls() {
136
262M
    return *reinterpret_cast<DeclsTy*>(this);
137
262M
  }
138
426M
  const DeclsTy &decls() const {
139
426M
    return *reinterpret_cast<const DeclsTy*>(this);
140
426M
  }
141
};
142
143
/// A set of unresolved declarations.
144
template <unsigned InlineCapacity> class UnresolvedSet :
145
    public UnresolvedSetImpl {
146
  SmallVector<DeclAccessPair, InlineCapacity> Decls;
147
};
148
149
150
} // namespace clang
151
152
#endif // LLVM_CLANG_AST_UNRESOLVEDSET_H