//ProgramStateTrait.h - Partial implementations of ProgramStateTrait -*- C++ -*- // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines partial implementations of template specializations of // the class ProgramStateTrait<>. ProgramStateTrait<> is used by ProgramState // to implement set/get methods for manipulating a ProgramState's // generic data map. // //===----------------------------------------------------------------------===// #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 <cstdint> #include <type_traits> namespace clang { namespace ento { template <typename T, typename Enable = void> struct ProgramStatePartialTrait; /// Declares a program state trait for type \p Type called \p Name, and /// introduce a type named \c NameTy. /// The macro should not be used inside namespaces. #define REGISTER_TRAIT_WITH_PROGRAMSTATE(Name, Type) … /// Declares a factory for objects of type \p Type in the program state /// manager. The type must provide a ::Factory sub-class. Commonly used for /// ImmutableMap, ImmutableSet, ImmutableList. The macro should not be used /// inside namespaces. #define REGISTER_FACTORY_WITH_PROGRAMSTATE(Type) … /// Helper for registering a map trait. /// /// If the map type were written directly in the invocation of /// REGISTER_TRAIT_WITH_PROGRAMSTATE, the comma in the template arguments /// would be treated as a macro argument separator, which is wrong. /// This allows the user to specify a map type in a way that the preprocessor /// can deal with. #define CLANG_ENTO_PROGRAMSTATE_MAP(Key, Value) … /// Declares an immutable map of type \p NameTy, suitable for placement into /// the ProgramState. This is implementing using llvm::ImmutableMap. /// /// \code /// State = State->set<Name>(K, V); /// const Value *V = State->get<Name>(K); // Returns NULL if not in the map. /// State = State->remove<Name>(K); /// NameTy Map = State->get<Name>(); /// \endcode /// /// The macro should not be used inside namespaces, or for traits that must /// be accessible from more than one translation unit. #define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value) … /// Declares an immutable map type \p Name and registers the factory /// for such maps in the program state, but does not add the map itself /// to the program state. Useful for managing lifetime of maps that are used /// as elements of other program state data structures. #define REGISTER_MAP_FACTORY_WITH_PROGRAMSTATE(Name, Key, Value) … /// Declares an immutable set of type \p NameTy, suitable for placement into /// the ProgramState. This is implementing using llvm::ImmutableSet. /// /// \code /// State = State->add<Name>(E); /// State = State->remove<Name>(E); /// bool Present = State->contains<Name>(E); /// NameTy Set = State->get<Name>(); /// \endcode /// /// The macro should not be used inside namespaces, or for traits that must /// be accessible from more than one translation unit. #define REGISTER_SET_WITH_PROGRAMSTATE(Name, Elem) … /// Declares an immutable set type \p Name and registers the factory /// for such sets in the program state, but does not add the set itself /// to the program state. Useful for managing lifetime of sets that are used /// as elements of other program state data structures. #define REGISTER_SET_FACTORY_WITH_PROGRAMSTATE(Name, Elem) … /// Declares an immutable list type \p NameTy, suitable for placement into /// the ProgramState. This is implementing using llvm::ImmutableList. /// /// \code /// State = State->add<Name>(E); // Adds to the /end/ of the list. /// bool Present = State->contains<Name>(E); /// NameTy List = State->get<Name>(); /// \endcode /// /// The macro should not be used inside namespaces, or for traits that must /// be accessible from more than one translation unit. #define REGISTER_LIST_WITH_PROGRAMSTATE(Name, Elem) … /// Declares an immutable list of type \p Name and registers the factory /// for such lists in the program state, but does not add the list itself /// to the program state. Useful for managing lifetime of lists that are used /// as elements of other program state data structures. #define REGISTER_LIST_FACTORY_WITH_PROGRAMSTATE(Name, Elem) … // Partial-specialization for ImmutableMap. ProgramStatePartialTrait<llvm::ImmutableMap<Key, Data, Info>>; // Partial-specialization for ImmutableSet. ProgramStatePartialTrait<llvm::ImmutableSet<Key, Info>>; // Partial-specialization for ImmutableList. ProgramStatePartialTrait<llvm::ImmutableList<T>>; template <typename T> struct DefaultProgramStatePartialTraitImpl { … }; // Partial specialization for integral types. ProgramStatePartialTrait<T, std::enable_if_t<std::is_integral<T>::value>>; // Partial specialization for enums. ProgramStatePartialTrait<T, std::enable_if_t<std::is_enum<T>::value>>; // Partial specialization for pointers. ProgramStatePartialTrait<T *, void>; } // namespace ento } // namespace clang #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_PROGRAMSTATETRAIT_H