Coverage Report

Created: 2018-09-25 23:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Sema/Ownership.h
Line
Count
Source
1
//===- Ownership.h - Parser ownership helpers -------------------*- 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 contains classes for managing ownership of Stmt and Expr nodes.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_SEMA_OWNERSHIP_H
15
#define LLVM_CLANG_SEMA_OWNERSHIP_H
16
17
#include "clang/AST/Expr.h"
18
#include "clang/Basic/LLVM.h"
19
#include "llvm/ADT/ArrayRef.h"
20
#include "llvm/Support/PointerLikeTypeTraits.h"
21
#include "llvm/Support/type_traits.h"
22
#include <cassert>
23
#include <cstddef>
24
#include <cstdint>
25
26
//===----------------------------------------------------------------------===//
27
// OpaquePtr
28
//===----------------------------------------------------------------------===//
29
30
namespace clang {
31
32
class CXXBaseSpecifier;
33
class CXXCtorInitializer;
34
class Decl;
35
class Expr;
36
class ParsedTemplateArgument;
37
class QualType;
38
class Stmt;
39
class TemplateName;
40
class TemplateParameterList;
41
42
  /// Wrapper for void* pointer.
43
  /// \tparam PtrTy Either a pointer type like 'T*' or a type that behaves like
44
  ///               a pointer.
45
  ///
46
  /// This is a very simple POD type that wraps a pointer that the Parser
47
  /// doesn't know about but that Sema or another client does.  The PtrTy
48
  /// template argument is used to make sure that "Decl" pointers are not
49
  /// compatible with "Type" pointers for example.
50
  template <class PtrTy>
51
  class OpaquePtr {
52
    void *Ptr = nullptr;
53
54
38.5M
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
clang::OpaquePtr<clang::QualType>::OpaquePtr(void*)
Line
Count
Source
54
38.5M
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
clang::OpaquePtr<clang::TemplateName>::OpaquePtr(void*)
Line
Count
Source
54
2.79k
    explicit OpaquePtr(void *Ptr) : Ptr(Ptr) {}
55
56
    using Traits = llvm::PointerLikeTypeTraits<PtrTy>;
57
58
  public:
59
189M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::DeclGroupRef>::OpaquePtr(std::nullptr_t)
Line
Count
Source
59
16.4M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::QualType>::OpaquePtr(std::nullptr_t)
Line
Count
Source
59
137M
    OpaquePtr(std::nullptr_t = nullptr) {}
clang::OpaquePtr<clang::TemplateName>::OpaquePtr(std::nullptr_t)
Line
Count
Source
59
36.2M
    OpaquePtr(std::nullptr_t = nullptr) {}
60
61
44.4M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::DeclGroupRef>::make(clang::DeclGroupRef)
Line
Count
Source
61
12.4M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::QualType>::make(clang::QualType)
Line
Count
Source
61
29.2M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
clang::OpaquePtr<clang::TemplateName>::make(clang::TemplateName)
Line
Count
Source
61
2.69M
    static OpaquePtr make(PtrTy P) { OpaquePtr OP; OP.set(P); return OP; }
62
63
    /// Returns plain pointer to the entity pointed by this wrapper.
64
    /// \tparam PointeeT Type of pointed entity.
65
    ///
66
    /// It is identical to getPtrAs<PointeeT*>.
67
    template <typename PointeeT> PointeeT* getPtrTo() const {
68
      return get();
69
    }
70
71
    /// Returns pointer converted to the specified type.
72
    /// \tparam PtrT Result pointer type.  There must be implicit conversion
73
    ///              from PtrTy to PtrT.
74
    ///
75
    /// In contrast to getPtrTo, this method allows the return type to be
76
    /// a smart pointer.
77
    template <typename PtrT> PtrT getPtrAs() const {
78
      return get();
79
    }
80
81
50.2M
    PtrTy get() const {
82
50.2M
      return Traits::getFromVoidPointer(Ptr);
83
50.2M
    }
clang::OpaquePtr<clang::DeclGroupRef>::get() const
Line
Count
Source
81
5.50M
    PtrTy get() const {
82
5.50M
      return Traits::getFromVoidPointer(Ptr);
83
5.50M
    }
clang::OpaquePtr<clang::QualType>::get() const
Line
Count
Source
81
38.6M
    PtrTy get() const {
82
38.6M
      return Traits::getFromVoidPointer(Ptr);
83
38.6M
    }
clang::OpaquePtr<clang::TemplateName>::get() const
Line
Count
Source
81
6.07M
    PtrTy get() const {
82
6.07M
      return Traits::getFromVoidPointer(Ptr);
83
6.07M
    }
84
85
44.4M
    void set(PtrTy P) {
86
44.4M
      Ptr = Traits::getAsVoidPointer(P);
87
44.4M
    }
clang::OpaquePtr<clang::DeclGroupRef>::set(clang::DeclGroupRef)
Line
Count
Source
85
12.4M
    void set(PtrTy P) {
86
12.4M
      Ptr = Traits::getAsVoidPointer(P);
87
12.4M
    }
clang::OpaquePtr<clang::QualType>::set(clang::QualType)
Line
Count
Source
85
29.2M
    void set(PtrTy P) {
86
29.2M
      Ptr = Traits::getAsVoidPointer(P);
87
29.2M
    }
clang::OpaquePtr<clang::TemplateName>::set(clang::TemplateName)
Line
Count
Source
85
2.69M
    void set(PtrTy P) {
86
2.69M
      Ptr = Traits::getAsVoidPointer(P);
87
2.69M
    }
88
89
53.0M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::DeclGroupRef>::operator bool() const
Line
Count
Source
89
3.57M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::QualType>::operator bool() const
Line
Count
Source
89
49.4M
    explicit operator bool() const { return Ptr != nullptr; }
clang::OpaquePtr<clang::TemplateName>::operator bool() const
Line
Count
Source
89
73
    explicit operator bool() const { return Ptr != nullptr; }
90
91
39.2M
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::QualType>::getAsOpaquePtr() const
Line
Count
Source
91
39.2M
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::TemplateName>::getAsOpaquePtr() const
Line
Count
Source
91
2.31k
    void *getAsOpaquePtr() const { return Ptr; }
clang::OpaquePtr<clang::DeclGroupRef>::getAsOpaquePtr() const
Line
Count
Source
91
2
    void *getAsOpaquePtr() const { return Ptr; }
92
38.5M
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
clang::OpaquePtr<clang::QualType>::getFromOpaquePtr(void*)
Line
Count
Source
92
38.5M
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
clang::OpaquePtr<clang::TemplateName>::getFromOpaquePtr(void*)
Line
Count
Source
92
2.79k
    static OpaquePtr getFromOpaquePtr(void *P) { return OpaquePtr(P); }
93
  };
94
95
  /// UnionOpaquePtr - A version of OpaquePtr suitable for membership
96
  /// in a union.
97
  template <class T> struct UnionOpaquePtr {
98
    void *Ptr;
99
100
    static UnionOpaquePtr make(OpaquePtr<T> P) {
101
      UnionOpaquePtr OP = { P.getAsOpaquePtr() };
102
      return OP;
103
    }
104
105
24.2M
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
clang::UnionOpaquePtr<clang::QualType>::get() const
Line
Count
Source
105
24.2M
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
clang::UnionOpaquePtr<clang::TemplateName>::get() const
Line
Count
Source
105
605
    OpaquePtr<T> get() const { return OpaquePtr<T>::getFromOpaquePtr(Ptr); }
106
24.2M
    operator OpaquePtr<T>() const { return get(); }
107
108
25.3M
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
109
25.3M
      Ptr = P.getAsOpaquePtr();
110
25.3M
      return *this;
111
25.3M
    }
clang::UnionOpaquePtr<clang::QualType>::operator=(clang::OpaquePtr<clang::QualType>)
Line
Count
Source
108
25.3M
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
109
25.3M
      Ptr = P.getAsOpaquePtr();
110
25.3M
      return *this;
111
25.3M
    }
clang::UnionOpaquePtr<clang::TemplateName>::operator=(clang::OpaquePtr<clang::TemplateName>)
Line
Count
Source
108
153
    UnionOpaquePtr &operator=(OpaquePtr<T> P) {
109
153
      Ptr = P.getAsOpaquePtr();
110
153
      return *this;
111
153
    }
112
  };
113
114
} // namespace clang
115
116
namespace llvm {
117
118
  template <class T>
119
  struct PointerLikeTypeTraits<clang::OpaquePtr<T>> {
120
    enum { NumLowBitsAvailable = 0 };
121
122
    static inline void *getAsVoidPointer(clang::OpaquePtr<T> P) {
123
      // FIXME: Doesn't work? return P.getAs< void >();
124
      return P.getAsOpaquePtr();
125
    }
126
127
    static inline clang::OpaquePtr<T> getFromVoidPointer(void *P) {
128
      return clang::OpaquePtr<T>::getFromOpaquePtr(P);
129
    }
130
  };
131
132
  template <class T>
133
  struct isPodLike<clang::OpaquePtr<T>> { static const bool value = true; };
134
135
} // namespace llvm
136
137
namespace clang {
138
139
  // Basic
140
  class DiagnosticBuilder;
141
142
  // Determines whether the low bit of the result pointer for the
143
  // given UID is always zero. If so, ActionResult will use that bit
144
  // for it's "invalid" flag.
145
  template<class Ptr>
146
  struct IsResultPtrLowBitFree {
147
    static const bool value = false;
148
  };
149
150
  /// ActionResult - This structure is used while parsing/acting on
151
  /// expressions, stmts, etc.  It encapsulates both the object returned by
152
  /// the action, plus a sense of whether or not it is valid.
153
  /// When CompressInvalid is true, the "invalid" flag will be
154
  /// stored in the low bit of the Val pointer.
155
  template<class PtrTy,
156
           bool CompressInvalid = IsResultPtrLowBitFree<PtrTy>::value>
157
  class ActionResult {
158
    PtrTy Val;
159
    bool Invalid;
160
161
  public:
162
10.4M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::ActionResult(bool)
Line
Count
Source
162
9.09M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
clang::ActionResult<clang::Decl*, false>::ActionResult(bool)
Line
Count
Source
162
1.40M
    ActionResult(bool Invalid = false) : Val(PtrTy()), Invalid(Invalid) {}
163
6.90M
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::ActionResult(clang::OpaquePtr<clang::QualType>)
Line
Count
Source
163
6.38M
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
clang::ActionResult<clang::Decl*, false>::ActionResult(clang::Decl*)
Line
Count
Source
163
519k
    ActionResult(PtrTy val) : Val(val), Invalid(false) {}
164
6
    ActionResult(const DiagnosticBuilder &) : Val(PtrTy()), Invalid(true) {}
165
166
    // These two overloads prevent void* -> bool conversions.
167
    ActionResult(const void *) = delete;
168
    ActionResult(volatile void *) = delete;
169
170
12.1M
    bool isInvalid() const { return Invalid; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::isInvalid() const
Line
Count
Source
170
9.38M
    bool isInvalid() const { return Invalid; }
clang::ActionResult<clang::Decl*, false>::isInvalid() const
Line
Count
Source
170
2.81M
    bool isInvalid() const { return Invalid; }
171
5.79M
    bool isUsable() const { return !Invalid && 
Val5.79M
; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::isUsable() const
Line
Count
Source
171
5.79M
    bool isUsable() const { return !Invalid && 
Val5.79M
; }
clang::ActionResult<clang::Decl*, false>::isUsable() const
Line
Count
Source
171
2.77k
    bool isUsable() const { return !Invalid && Val; }
172
945k
    bool isUnset() const { return !Invalid && 
!Val945k
; }
173
174
19.8M
    PtrTy get() const { return Val; }
clang::ActionResult<clang::OpaquePtr<clang::QualType>, false>::get() const
Line
Count
Source
174
15.8M
    PtrTy get() const { return Val; }
clang::ActionResult<clang::Decl*, false>::get() const
Line
Count
Source
174
4.03M
    PtrTy get() const { return Val; }
175
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
176
177
    void set(PtrTy V) { Val = V; }
178
179
1.15M
    const ActionResult &operator=(PtrTy RHS) {
180
1.15M
      Val = RHS;
181
1.15M
      Invalid = false;
182
1.15M
      return *this;
183
1.15M
    }
184
  };
185
186
  // This ActionResult partial specialization places the "invalid"
187
  // flag into the low bit of the pointer.
188
  template<typename PtrTy>
189
  class ActionResult<PtrTy, true> {
190
    // A pointer whose low bit is 1 if this result is invalid, 0
191
    // otherwise.
192
    uintptr_t PtrWithInvalid;
193
194
    using PtrTraits = llvm::PointerLikeTypeTraits<PtrTy>;
195
196
  public:
197
    ActionResult(bool Invalid = false)
198
139M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::Expr*, true>::ActionResult(bool)
Line
Count
Source
198
115M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::CXXBaseSpecifier*, true>::ActionResult(bool)
Line
Count
Source
198
234
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(bool)
Line
Count
Source
198
41.2k
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
clang::ActionResult<clang::Stmt*, true>::ActionResult(bool)
Line
Count
Source
198
23.3M
        : PtrWithInvalid(static_cast<uintptr_t>(Invalid)) {}
199
200
321M
    ActionResult(PtrTy V) {
201
321M
      void *VP = PtrTraits::getAsVoidPointer(V);
202
321M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
203
321M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
204
321M
    }
clang::ActionResult<clang::Expr*, true>::ActionResult(clang::Expr*)
Line
Count
Source
200
306M
    ActionResult(PtrTy V) {
201
306M
      void *VP = PtrTraits::getAsVoidPointer(V);
202
306M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
203
306M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
204
306M
    }
clang::ActionResult<clang::Stmt*, true>::ActionResult(clang::Stmt*)
Line
Count
Source
200
14.4M
    ActionResult(PtrTy V) {
201
14.4M
      void *VP = PtrTraits::getAsVoidPointer(V);
202
14.4M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
203
14.4M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
204
14.4M
    }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::ActionResult(clang::CXXBaseSpecifier*)
Line
Count
Source
200
251k
    ActionResult(PtrTy V) {
201
251k
      void *VP = PtrTraits::getAsVoidPointer(V);
202
251k
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
203
251k
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
204
251k
    }
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(clang::CXXCtorInitializer*)
Line
Count
Source
200
303k
    ActionResult(PtrTy V) {
201
303k
      void *VP = PtrTraits::getAsVoidPointer(V);
202
303k
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
203
303k
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
204
303k
    }
205
206
246
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::CXXCtorInitializer*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
206
23
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::Expr*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
206
211
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
clang::ActionResult<clang::Stmt*, true>::ActionResult(clang::DiagnosticBuilder const&)
Line
Count
Source
206
12
    ActionResult(const DiagnosticBuilder &) : PtrWithInvalid(0x01) {}
207
208
    // These two overloads prevent void* -> bool conversions.
209
    ActionResult(const void *) = delete;
210
    ActionResult(volatile void *) = delete;
211
212
395M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::Expr*, true>::isInvalid() const
Line
Count
Source
212
382M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::isInvalid() const
Line
Count
Source
212
251k
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::CXXCtorInitializer*, true>::isInvalid() const
Line
Count
Source
212
303k
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
clang::ActionResult<clang::Stmt*, true>::isInvalid() const
Line
Count
Source
212
12.9M
    bool isInvalid() const { return PtrWithInvalid & 0x01; }
213
51.4M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
clang::ActionResult<clang::Expr*, true>::isUsable() const
Line
Count
Source
213
43.5M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
clang::ActionResult<clang::Stmt*, true>::isUsable() const
Line
Count
Source
213
7.92M
    bool isUsable() const { return PtrWithInvalid > 0x01; }
214
22.9M
    bool isUnset() const { return PtrWithInvalid == 0; }
215
216
606M
    PtrTy get() const {
217
606M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
218
606M
      return PtrTraits::getFromVoidPointer(VP);
219
606M
    }
clang::ActionResult<clang::Expr*, true>::get() const
Line
Count
Source
216
584M
    PtrTy get() const {
217
584M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
218
584M
      return PtrTraits::getFromVoidPointer(VP);
219
584M
    }
clang::ActionResult<clang::CXXBaseSpecifier*, true>::get() const
Line
Count
Source
216
251k
    PtrTy get() const {
217
251k
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
218
251k
      return PtrTraits::getFromVoidPointer(VP);
219
251k
    }
clang::ActionResult<clang::CXXCtorInitializer*, true>::get() const
Line
Count
Source
216
303k
    PtrTy get() const {
217
303k
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
218
303k
      return PtrTraits::getFromVoidPointer(VP);
219
303k
    }
clang::ActionResult<clang::Stmt*, true>::get() const
Line
Count
Source
216
22.0M
    PtrTy get() const {
217
22.0M
      void *VP = reinterpret_cast<void *>(PtrWithInvalid & ~0x01);
218
22.0M
      return PtrTraits::getFromVoidPointer(VP);
219
22.0M
    }
220
221
16.7M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Expr* clang::ActionResult<clang::Expr*, true>::getAs<clang::Expr>()
Line
Count
Source
221
12.7M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Stmt* clang::ActionResult<clang::Expr*, true>::getAs<clang::Stmt>()
Line
Count
Source
221
3.13M
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Expr* clang::ActionResult<clang::Stmt*, true>::getAs<clang::Expr>()
Line
Count
Source
221
599
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::Stmt* clang::ActionResult<clang::Stmt*, true>::getAs<clang::Stmt>()
Line
Count
Source
221
897k
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::CXXConstructExpr* clang::ActionResult<clang::Expr*, true>::getAs<clang::CXXConstructExpr>()
Line
Count
Source
221
73
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
clang::DeclRefExpr* clang::ActionResult<clang::Expr*, true>::getAs<clang::DeclRefExpr>()
Line
Count
Source
221
162
    template <typename T> T *getAs() { return static_cast<T*>(get()); }
222
223
    void set(PtrTy V) {
224
      void *VP = PtrTraits::getAsVoidPointer(V);
225
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
226
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
227
    }
228
229
15.3M
    const ActionResult &operator=(PtrTy RHS) {
230
15.3M
      void *VP = PtrTraits::getAsVoidPointer(RHS);
231
15.3M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
232
15.3M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
233
15.3M
      return *this;
234
15.3M
    }
clang::ActionResult<clang::Expr*, true>::operator=(clang::Expr*)
Line
Count
Source
229
15.3M
    const ActionResult &operator=(PtrTy RHS) {
230
15.3M
      void *VP = PtrTraits::getAsVoidPointer(RHS);
231
15.3M
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
232
15.3M
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
233
15.3M
      return *this;
234
15.3M
    }
clang::ActionResult<clang::Stmt*, true>::operator=(clang::Stmt*)
Line
Count
Source
229
24
    const ActionResult &operator=(PtrTy RHS) {
230
24
      void *VP = PtrTraits::getAsVoidPointer(RHS);
231
24
      PtrWithInvalid = reinterpret_cast<uintptr_t>(VP);
232
24
      assert((PtrWithInvalid & 0x01) == 0 && "Badly aligned pointer");
233
24
      return *this;
234
24
    }
235
236
    // For types where we can fit a flag in with the pointer, provide
237
    // conversions to/from pointer type.
238
4.13M
    static ActionResult getFromOpaquePointer(void *P) {
239
4.13M
      ActionResult Result;
240
4.13M
      Result.PtrWithInvalid = (uintptr_t)P;
241
4.13M
      return Result;
242
4.13M
    }
243
4.13M
    void *getAsOpaquePointer() const { return (void*)PtrWithInvalid; }
244
  };
245
246
  /// An opaque type for threading parsed type information through the
247
  /// parser.
248
  using ParsedType = OpaquePtr<QualType>;
249
  using UnionParsedType = UnionOpaquePtr<QualType>;
250
251
  // We can re-use the low bit of expression, statement, base, and
252
  // member-initializer pointers for the "invalid" flag of
253
  // ActionResult.
254
  template<> struct IsResultPtrLowBitFree<Expr*> {
255
    static const bool value = true;
256
  };
257
  template<> struct IsResultPtrLowBitFree<Stmt*> {
258
    static const bool value = true;
259
  };
260
  template<> struct IsResultPtrLowBitFree<CXXBaseSpecifier*> {
261
    static const bool value = true;
262
  };
263
  template<> struct IsResultPtrLowBitFree<CXXCtorInitializer*> {
264
    static const bool value = true;
265
  };
266
267
  using ExprResult = ActionResult<Expr *>;
268
  using StmtResult = ActionResult<Stmt *>;
269
  using TypeResult = ActionResult<ParsedType>;
270
  using BaseResult = ActionResult<CXXBaseSpecifier *>;
271
  using MemInitResult = ActionResult<CXXCtorInitializer *>;
272
273
  using DeclResult = ActionResult<Decl *>;
274
  using ParsedTemplateTy = OpaquePtr<TemplateName>;
275
  using UnionParsedTemplateTy = UnionOpaquePtr<TemplateName>;
276
277
  using MultiExprArg = MutableArrayRef<Expr *>;
278
  using MultiStmtArg = MutableArrayRef<Stmt *>;
279
  using ASTTemplateArgsPtr = MutableArrayRef<ParsedTemplateArgument>;
280
  using MultiTypeArg = MutableArrayRef<ParsedType>;
281
  using MultiTemplateParamsArg = MutableArrayRef<TemplateParameterList *>;
282
283
1.90M
  inline ExprResult ExprError() { return ExprResult(true); }
284
317k
  inline StmtResult StmtError() { return StmtResult(true); }
285
286
415
  inline ExprResult ExprError(const DiagnosticBuilder&) { return ExprError(); }
287
380
  inline StmtResult StmtError(const DiagnosticBuilder&) { return StmtError(); }
288
289
127k
  inline ExprResult ExprEmpty() { return ExprResult(false); }
290
52
  inline StmtResult StmtEmpty() { return StmtResult(false); }
291
292
  inline Expr *AssertSuccess(ExprResult R) {
293
    assert(!R.isInvalid() && "operation was asserted to never fail!");
294
    return R.get();
295
  }
296
297
  inline Stmt *AssertSuccess(StmtResult R) {
298
    assert(!R.isInvalid() && "operation was asserted to never fail!");
299
    return R.get();
300
  }
301
302
} // namespace clang
303
304
#endif // LLVM_CLANG_SEMA_OWNERSHIP_H