diff options
Diffstat (limited to 'include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h')
-rw-r--r-- | include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h | 142 |
1 files changed, 68 insertions, 74 deletions
diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h index a04fa9005955..5555b292534c 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h @@ -14,33 +14,28 @@ // //===----------------------------------------------------------------------===// - #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H +#include "llvm/ADT/ImmutableList.h" +#include "llvm/ADT/ImmutableMap.h" +#include "llvm/ADT/ImmutableSet.h" #include "llvm/Support/Allocator.h" -#include "llvm/Support/DataTypes.h" - -namespace llvm { - template <typename K, typename D, typename I> class ImmutableMap; - template <typename K, typename I> class ImmutableSet; - template <typename T> class ImmutableList; - template <typename T> class ImmutableListImpl; -} +#include <cstdint> namespace clang { - namespace ento { + template <typename T> struct ProgramStatePartialTrait; /// Declares a program state trait for type \p Type called \p Name, and - /// introduce a typedef named \c NameTy. + /// introduce a type named \c NameTy. /// The macro should not be used inside namespaces, or for traits that must /// be accessible from more than one translation unit. #define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type) \ namespace { \ class Name {}; \ - typedef Type Name ## Ty; \ + using Name ## Ty = Type; \ } \ namespace clang { \ namespace ento { \ @@ -52,28 +47,30 @@ namespace ento { } \ } - // Partial-specialization for ImmutableMap. - template <typename Key, typename Data, typename Info> - struct ProgramStatePartialTrait< llvm::ImmutableMap<Key,Data,Info> > { - typedef llvm::ImmutableMap<Key,Data,Info> data_type; - typedef typename data_type::Factory& context_type; - typedef Key key_type; - typedef Data value_type; - typedef const value_type* lookup_type; - - static inline data_type MakeData(void *const* p) { - return p ? data_type((typename data_type::TreeTy*) *p) + struct ProgramStatePartialTrait<llvm::ImmutableMap<Key, Data, Info>> { + using data_type = llvm::ImmutableMap<Key, Data, Info>; + using context_type = typename data_type::Factory &; + using key_type = Key; + using value_type = Data; + using lookup_type = const value_type *; + + static data_type MakeData(void *const *p) { + return p ? data_type((typename data_type::TreeTy *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type B) { + + static void *MakeVoidPtr(data_type B) { return B.getRoot(); } + static lookup_type Lookup(data_type B, key_type K) { return B.lookup(K); } - static data_type Set(data_type B, key_type K, value_type E,context_type F){ + + static data_type Set(data_type B, key_type K, value_type E, + context_type F) { return F.add(B, K, E); } @@ -85,8 +82,8 @@ namespace ento { return B.contains(K); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { @@ -94,7 +91,7 @@ namespace ento { } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; @@ -107,21 +104,19 @@ namespace ento { /// can deal with. #define CLANG_ENTO_PROGRAMSTATE_MAP(Key, Value) llvm::ImmutableMap<Key, Value> - // Partial-specialization for ImmutableSet. - template <typename Key, typename Info> - struct ProgramStatePartialTrait< llvm::ImmutableSet<Key,Info> > { - typedef llvm::ImmutableSet<Key,Info> data_type; - typedef typename data_type::Factory& context_type; - typedef Key key_type; + struct ProgramStatePartialTrait<llvm::ImmutableSet<Key, Info>> { + using data_type = llvm::ImmutableSet<Key, Info>; + using context_type = typename data_type::Factory &; + using key_type = Key; - static inline data_type MakeData(void *const* p) { - return p ? data_type((typename data_type::TreeTy*) *p) + static data_type MakeData(void *const *p) { + return p ? data_type((typename data_type::TreeTy *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type B) { + static void *MakeVoidPtr(data_type B) { return B.getRoot(); } @@ -137,27 +132,25 @@ namespace ento { return B.contains(K); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } - static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { + static void *CreateContext(llvm::BumpPtrAllocator &Alloc) { return new typename data_type::Factory(Alloc); } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; - // Partial-specialization for ImmutableList. - template <typename T> - struct ProgramStatePartialTrait< llvm::ImmutableList<T> > { - typedef llvm::ImmutableList<T> data_type; - typedef T key_type; - typedef typename data_type::Factory& context_type; + struct ProgramStatePartialTrait<llvm::ImmutableList<T>> { + using data_type = llvm::ImmutableList<T>; + using key_type = T; + using context_type = typename data_type::Factory &; static data_type Add(data_type L, key_type K, context_type F) { return F.add(K, L); @@ -167,83 +160,84 @@ namespace ento { return L.contains(K); } - static inline data_type MakeData(void *const* p) { - return p ? data_type((const llvm::ImmutableListImpl<T>*) *p) + static data_type MakeData(void *const *p) { + return p ? data_type((const llvm::ImmutableListImpl<T> *) *p) : data_type(nullptr); } - static inline void *MakeVoidPtr(data_type D) { + static void *MakeVoidPtr(data_type D) { return const_cast<llvm::ImmutableListImpl<T> *>(D.getInternalPointer()); } - static inline context_type MakeContext(void *p) { - return *((typename data_type::Factory*) p); + static context_type MakeContext(void *p) { + return *((typename data_type::Factory *) p); } - static void *CreateContext(llvm::BumpPtrAllocator& Alloc) { + static void *CreateContext(llvm::BumpPtrAllocator &Alloc) { return new typename data_type::Factory(Alloc); } static void DeleteContext(void *Ctx) { - delete (typename data_type::Factory*) Ctx; + delete (typename data_type::Factory *) Ctx; } }; - // Partial specialization for bool. template <> struct ProgramStatePartialTrait<bool> { - typedef bool data_type; + using data_type = bool; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? (data_type) (uintptr_t) *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { - return (void*) (uintptr_t) d; + + static void *MakeVoidPtr(data_type d) { + return (void *) (uintptr_t) d; } }; // Partial specialization for unsigned. template <> struct ProgramStatePartialTrait<unsigned> { - typedef unsigned data_type; + using data_type = unsigned; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? (data_type) (uintptr_t) *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { - return (void*) (uintptr_t) d; + + static void *MakeVoidPtr(data_type d) { + return (void *) (uintptr_t) d; } }; // Partial specialization for void*. - template <> struct ProgramStatePartialTrait<void*> { - typedef void *data_type; + template <> struct ProgramStatePartialTrait<void *> { + using data_type = void *; - static inline data_type MakeData(void *const* p) { + static data_type MakeData(void *const *p) { return p ? *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { + + static void *MakeVoidPtr(data_type d) { return d; } }; // Partial specialization for const void *. template <> struct ProgramStatePartialTrait<const void *> { - typedef const void *data_type; + using data_type = const void *; - static inline data_type MakeData(void * const *p) { + static data_type MakeData(void *const *p) { return p ? *p : data_type(); } - static inline void *MakeVoidPtr(data_type d) { + static void *MakeVoidPtr(data_type d) { return const_cast<void *>(d); } }; -} // end ento namespace - -} // end clang namespace +} // namespace ento +} // namespace clang -#endif +#endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H |