Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:37:07

0001 //== APSIntPtr.h - Wrapper for APSInt objects owned separately -*- C++ -*--==//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H
0010 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H
0011 
0012 #include "llvm/ADT/APSInt.h"
0013 #include "llvm/Support/Compiler.h"
0014 
0015 namespace clang::ento {
0016 
0017 /// A safe wrapper around APSInt objects allocated and owned by
0018 /// \c BasicValueFactory. This just wraps a common llvm::APSInt.
0019 class APSIntPtr {
0020   using APSInt = llvm::APSInt;
0021 
0022 public:
0023   APSIntPtr() = delete;
0024   APSIntPtr(const APSIntPtr &) = default;
0025   APSIntPtr &operator=(const APSIntPtr &) & = default;
0026   ~APSIntPtr() = default;
0027 
0028   /// You should not use this API.
0029   /// If do, ensure that the \p Ptr not going to dangle.
0030   /// Prefer using \c BasicValueFactory::getValue() to get an APSIntPtr object.
0031   static APSIntPtr unsafeConstructor(const APSInt *Ptr) {
0032     return APSIntPtr(Ptr);
0033   }
0034 
0035   LLVM_ATTRIBUTE_RETURNS_NONNULL
0036   const APSInt *get() const { return Ptr; }
0037   /*implicit*/ operator const APSInt &() const { return *get(); }
0038 
0039   APSInt operator-() const { return -*Ptr; }
0040   APSInt operator~() const { return ~*Ptr; }
0041 
0042 #define DEFINE_OPERATOR(OP)                                                    \
0043   bool operator OP(APSIntPtr Other) const { return (*Ptr)OP(*Other.Ptr); }
0044   DEFINE_OPERATOR(>)
0045   DEFINE_OPERATOR(>=)
0046   DEFINE_OPERATOR(<)
0047   DEFINE_OPERATOR(<=)
0048   DEFINE_OPERATOR(==)
0049   DEFINE_OPERATOR(!=)
0050 #undef DEFINE_OPERATOR
0051 
0052   const APSInt &operator*() const { return *Ptr; }
0053   const APSInt *operator->() const { return Ptr; }
0054 
0055 private:
0056   explicit APSIntPtr(const APSInt *Ptr) : Ptr(Ptr) {}
0057 
0058   /// Owned by \c BasicValueFactory.
0059   const APSInt *Ptr;
0060 };
0061 
0062 } // namespace clang::ento
0063 
0064 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APSIntPtr_H