clang 20.0.0git
APSIntPtr.h
Go to the documentation of this file.
1//== APSIntPtr.h - Wrapper for APSInt objects owned separately -*- 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#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H
10#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H
11
12#include "llvm/ADT/APSInt.h"
13#include "llvm/Support/Compiler.h"
14
15namespace clang::ento {
16
17/// A safe wrapper around APSInt objects allocated and owned by
18/// \c BasicValueFactory. This just wraps a common llvm::APSInt.
19class APSIntPtr {
20 using APSInt = llvm::APSInt;
21
22public:
23 APSIntPtr() = delete;
24 APSIntPtr(const APSIntPtr &) = default;
25 APSIntPtr &operator=(const APSIntPtr &) & = default;
26 ~APSIntPtr() = default;
27
28 /// You should not use this API.
29 /// If do, ensure that the \p Ptr not going to dangle.
30 /// Prefer using \c BasicValueFactory::getValue() to get an APSIntPtr object.
31 static APSIntPtr unsafeConstructor(const APSInt *Ptr) {
32 return APSIntPtr(Ptr);
33 }
34
35 LLVM_ATTRIBUTE_RETURNS_NONNULL
36 const APSInt *get() const { return Ptr; }
37 /*implicit*/ operator const APSInt &() const { return *get(); }
38
39 APSInt operator-() const { return -*Ptr; }
40 APSInt operator~() const { return ~*Ptr; }
41
42#define DEFINE_OPERATOR(OP) \
43 bool operator OP(APSIntPtr Other) const { return (*Ptr)OP(*Other.Ptr); }
50#undef DEFINE_OPERATOR
51
52 const APSInt &operator*() const { return *Ptr; }
53 const APSInt *operator->() const { return Ptr; }
54
55private:
56 explicit APSIntPtr(const APSInt *Ptr) : Ptr(Ptr) {}
57
58 /// Owned by \c BasicValueFactory.
59 const APSInt *Ptr;
60};
61
62} // namespace clang::ento
63
64#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H
#define DEFINE_OPERATOR(OP)
Definition: APSIntPtr.h:42
llvm::APSInt APSInt
Definition: Compiler.cpp:23
A safe wrapper around APSInt objects allocated and owned by BasicValueFactory.
Definition: APSIntPtr.h:19
APSIntPtr & operator=(const APSIntPtr &) &=default
const APSInt * operator->() const
Definition: APSIntPtr.h:53
static APSIntPtr unsafeConstructor(const APSInt *Ptr)
You should not use this API.
Definition: APSIntPtr.h:31
const APSInt & operator*() const
Definition: APSIntPtr.h:52
APSIntPtr(const APSIntPtr &)=default
LLVM_ATTRIBUTE_RETURNS_NONNULL const APSInt * get() const
Definition: APSIntPtr.h:36
APSInt operator-() const
Definition: APSIntPtr.h:39
APSInt operator~() const
Definition: APSIntPtr.h:40