//=== BasicValueFactory.h - Basic values for Path Sens analysis --*- C++ -*---// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This file defines BasicValueFactory, a class that manages the lifetime // of APSInt objects and symbolic constraints used by GRExprEngine // and related classes. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_ANALYSIS_BASICVALUEFACTORY_H #define LLVM_CLANG_ANALYSIS_BASICVALUEFACTORY_H #include "clang/Analysis/PathSensitive/SymbolManager.h" #include "clang/Analysis/PathSensitive/SVals.h" #include "clang/AST/ASTContext.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/ImmutableList.h" namespace clang { class CompoundValData : public llvm::FoldingSetNode { QualType T; llvm::ImmutableList L; public: CompoundValData(QualType t, llvm::ImmutableList l) : T(t), L(l) {} typedef llvm::ImmutableList::iterator iterator; iterator begin() const { return L.begin(); } iterator end() const { return L.end(); } static void Profile(llvm::FoldingSetNodeID& ID, QualType T, llvm::ImmutableList L); void Profile(llvm::FoldingSetNodeID& ID) { Profile(ID, T, L); } }; class BasicValueFactory { typedef llvm::FoldingSet > APSIntSetTy; typedef llvm::FoldingSet SymIntCSetTy; ASTContext& Ctx; llvm::BumpPtrAllocator& BPAlloc; APSIntSetTy APSIntSet; SymIntCSetTy SymIntCSet; void* PersistentSVals; void* PersistentSValPairs; llvm::ImmutableList::Factory SValListFactory; llvm::FoldingSet CompoundValDataSet; public: BasicValueFactory(ASTContext& ctx, llvm::BumpPtrAllocator& Alloc) : Ctx(ctx), BPAlloc(Alloc), PersistentSVals(0), PersistentSValPairs(0), SValListFactory(Alloc) {} ~BasicValueFactory(); ASTContext& getContext() const { return Ctx; } const llvm::APSInt& getValue(const llvm::APSInt& X); const llvm::APSInt& getValue(const llvm::APInt& X, bool isUnsigned); const llvm::APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned); const llvm::APSInt& getValue(uint64_t X, QualType T); inline const llvm::APSInt& getZeroWithPtrWidth(bool isUnsigned = true) { return getValue(0, Ctx.getTypeSize(Ctx.VoidPtrTy), isUnsigned); } inline const llvm::APSInt& getTruthValue(bool b) { return getValue(b ? 1 : 0, Ctx.getTypeSize(Ctx.IntTy), false); } const SymIntConstraint& getConstraint(SymbolRef sym, BinaryOperator::Opcode Op, const llvm::APSInt& V); const CompoundValData* getCompoundValData(QualType T, llvm::ImmutableList Vals); llvm::ImmutableList getEmptySValList() { return SValListFactory.GetEmptyList(); } llvm::ImmutableList consVals(SVal X, llvm::ImmutableList L) { return SValListFactory.Add(X, L); } const llvm::APSInt* EvaluateAPSInt(BinaryOperator::Opcode Op, const llvm::APSInt& V1, const llvm::APSInt& V2); const std::pair& getPersistentSValWithData(const SVal& V, uintptr_t Data); const std::pair& getPersistentSValPair(const SVal& V1, const SVal& V2); const SVal* getPersistentSVal(SVal X); }; } // end clang namespace #endif