Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/DeclGroup.h
Line
Count
Source (jump to first uncovered line)
1
//===- DeclGroup.h - Classes for representing groups of Decls ---*- 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 DeclGroup, DeclGroupRef, and OwningDeclGroup classes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_DECLGROUP_H
15
#define LLVM_CLANG_AST_DECLGROUP_H
16
17
#include "llvm/Support/TrailingObjects.h"
18
#include <cassert>
19
#include <cstdint>
20
21
namespace clang {
22
23
class ASTContext;
24
class Decl;
25
26
class DeclGroup final : private llvm::TrailingObjects<DeclGroup, Decl *> {
27
  // FIXME: Include a TypeSpecifier object.
28
  unsigned NumDecls = 0;
29
30
private:
31
  DeclGroup() = default;
32
  DeclGroup(unsigned numdecls, Decl** decls);
33
34
public:
35
  friend TrailingObjects;
36
37
  static DeclGroup *Create(ASTContext &C, Decl **Decls, unsigned NumDecls);
38
39
179k
  unsigned size() const { return NumDecls; }
40
41
431k
  Decl*& operator[](unsigned i) {
42
431k
    assert (i < NumDecls && "Out-of-bounds access.");
43
431k
    return getTrailingObjects<Decl *>()[i];
44
431k
  }
45
46
56.7k
  Decl* const& operator[](unsigned i) const {
47
56.7k
    assert (i < NumDecls && "Out-of-bounds access.");
48
56.7k
    return getTrailingObjects<Decl *>()[i];
49
56.7k
  }
50
};
51
52
0
class DeclGroupRef {
53
  // Note this is not a PointerIntPair because we need the address of the
54
  // non-group case to be valid as a Decl** for iteration.
55
  enum Kind { SingleDeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };
56
57
  Decl* D = nullptr;
58
59
15.6M
  Kind getKind() const {
60
15.6M
    return (Kind) (reinterpret_cast<uintptr_t>(D) & Mask);
61
15.6M
  }
62
63
public:
64
5.52M
  DeclGroupRef() = default;
65
12.6M
  explicit DeclGroupRef(Decl* d) : D(d) {}
66
  explicit DeclGroupRef(DeclGroup* dg)
67
223k
    : D((Decl*) (reinterpret_cast<uintptr_t>(dg) | DeclGroupKind)) {}
68
69
8.08M
  static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
70
8.08M
    if (NumDecls == 0)
71
381
      return DeclGroupRef();
72
8.08M
    if (NumDecls == 1)
73
7.86M
      return DeclGroupRef(Decls[0]);
74
222k
    return DeclGroupRef(DeclGroup::Create(C, Decls, NumDecls));
75
222k
  }
76
77
  using iterator = Decl **;
78
  using const_iterator = Decl * const *;
79
80
1.99M
  bool isNull() const { return D == nullptr; }
81
15.6M
  bool isSingleDecl() const { return getKind() == SingleDeclKind; }
82
  bool isDeclGroup() const { return getKind() == DeclGroupKind; }
83
84
579k
  Decl *getSingleDecl() {
85
579k
    assert(isSingleDecl() && "Isn't a single decl");
86
579k
    return D;
87
579k
  }
88
45.9k
  const Decl *getSingleDecl() const {
89
45.9k
    return const_cast<DeclGroupRef*>(this)->getSingleDecl();
90
45.9k
  }
91
92
487k
  DeclGroup &getDeclGroup() {
93
487k
    assert(isDeclGroup() && "Isn't a declgroup");
94
487k
    return *((DeclGroup*)(reinterpret_cast<uintptr_t>(D) & ~Mask));
95
487k
  }
96
56.7k
  const DeclGroup &getDeclGroup() const {
97
56.7k
    return const_cast<DeclGroupRef*>(this)->getDeclGroup();
98
56.7k
  }
99
100
8.54M
  iterator begin() {
101
8.54M
    if (isSingleDecl())
102
8.26M
      return D ? 
&D8.26M
:
nullptr40
;
103
280k
    return &getDeclGroup()[0];
104
280k
  }
105
106
5.03M
  iterator end() {
107
5.03M
    if (isSingleDecl())
108
4.88M
      return D ? 
&D+14.88M
:
nullptr40
;
109
150k
    DeclGroup &G = getDeclGroup();
110
150k
    return &G[0] + G.size();
111
150k
  }
112
113
768k
  const_iterator begin() const {
114
768k
    if (isSingleDecl())
115
740k
      return D ? &D : 
nullptr0
;
116
28.3k
    return &getDeclGroup()[0];
117
28.3k
  }
118
119
745k
  const_iterator end() const {
120
745k
    if (isSingleDecl())
121
716k
      return D ? &D+1 : 
nullptr0
;
122
28.3k
    const DeclGroup &G = getDeclGroup();
123
28.3k
    return &G[0] + G.size();
124
28.3k
  }
125
126
12.4M
  void *getAsOpaquePtr() const { return D; }
127
5.50M
  static DeclGroupRef getFromOpaquePtr(void *Ptr) {
128
5.50M
    DeclGroupRef X;
129
5.50M
    X.D = static_cast<Decl*>(Ptr);
130
5.50M
    return X;
131
5.50M
  }
132
};
133
134
} // namespace clang
135
136
namespace llvm {
137
138
  // DeclGroupRef is "like a pointer", implement PointerLikeTypeTraits.
139
  template <typename T>
140
  struct PointerLikeTypeTraits;
141
  template <>
142
  struct PointerLikeTypeTraits<clang::DeclGroupRef> {
143
12.4M
    static inline void *getAsVoidPointer(clang::DeclGroupRef P) {
144
12.4M
      return P.getAsOpaquePtr();
145
12.4M
    }
146
147
5.50M
    static inline clang::DeclGroupRef getFromVoidPointer(void *P) {
148
5.50M
      return clang::DeclGroupRef::getFromOpaquePtr(P);
149
5.50M
    }
150
151
    enum { NumLowBitsAvailable = 0 };
152
  };
153
154
} // namespace llvm
155
156
#endif // LLVM_CLANG_AST_DECLGROUP_H