clang API Documentation
00001 //== ConstraintManager.h - Constraints on symbolic values.-------*- C++ -*--==// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defined the interface to manage constraints on symbolic values. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_CLANG_GR_CONSTRAINT_MANAGER_H 00015 #define LLVM_CLANG_GR_CONSTRAINT_MANAGER_H 00016 00017 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" 00018 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h" 00019 00020 namespace llvm { 00021 class APSInt; 00022 } 00023 00024 namespace clang { 00025 namespace ento { 00026 00027 class SubEngine; 00028 00029 class ConstraintManager { 00030 public: 00031 virtual ~ConstraintManager(); 00032 virtual ProgramStateRef assume(ProgramStateRef state, 00033 DefinedSVal Cond, 00034 bool Assumption) = 0; 00035 00036 std::pair<ProgramStateRef, ProgramStateRef > 00037 assumeDual(ProgramStateRef state, DefinedSVal Cond) 00038 { 00039 std::pair<ProgramStateRef, ProgramStateRef > res = 00040 std::make_pair(assume(state, Cond, true), assume(state, Cond, false)); 00041 00042 assert(!(!res.first && !res.second) && "System is over constrained."); 00043 return res; 00044 } 00045 00046 virtual const llvm::APSInt* getSymVal(ProgramStateRef state, 00047 SymbolRef sym) const = 0; 00048 00049 virtual bool isEqual(ProgramStateRef state, 00050 SymbolRef sym, 00051 const llvm::APSInt& V) const = 0; 00052 00053 virtual ProgramStateRef removeDeadBindings(ProgramStateRef state, 00054 SymbolReaper& SymReaper) = 0; 00055 00056 virtual void print(ProgramStateRef state, 00057 raw_ostream &Out, 00058 const char* nl, 00059 const char *sep) = 0; 00060 00061 virtual void EndPath(ProgramStateRef state) {} 00062 00063 protected: 00064 /// canReasonAbout - Not all ConstraintManagers can accurately reason about 00065 /// all SVal values. This method returns true if the ConstraintManager can 00066 /// reasonably handle a given SVal value. This is typically queried by 00067 /// ExprEngine to determine if the value should be replaced with a 00068 /// conjured symbolic value in order to recover some precision. 00069 virtual bool canReasonAbout(SVal X) const = 0; 00070 }; 00071 00072 ConstraintManager* CreateBasicConstraintManager(ProgramStateManager& statemgr, 00073 SubEngine &subengine); 00074 ConstraintManager* CreateRangeConstraintManager(ProgramStateManager& statemgr, 00075 SubEngine &subengine); 00076 00077 } // end GR namespace 00078 00079 } // end clang namespace 00080 00081 #endif