Coverage Report

Created: 2019-02-23 12:57

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