Coverage Report

Created: 2019-03-22 08:08

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