Home | History | Annotate | Download | only in PathSensitive
      1 //== ConstraintManager.h - Constraints on symbolic values.-------*- C++ -*--==//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  This file defined the interface to manage constraints on symbolic values.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef LLVM_CLANG_GR_CONSTRAINT_MANAGER_H
     15 #define LLVM_CLANG_GR_CONSTRAINT_MANAGER_H
     16 
     17 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
     18 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
     19 
     20 namespace llvm {
     21 class APSInt;
     22 }
     23 
     24 namespace clang {
     25 namespace ento {
     26 
     27 class SubEngine;
     28 
     29 class ConstraintManager {
     30 public:
     31   virtual ~ConstraintManager();
     32   virtual ProgramStateRef assume(ProgramStateRef state,
     33                                      DefinedSVal Cond,
     34                                      bool Assumption) = 0;
     35 
     36   std::pair<ProgramStateRef, ProgramStateRef >
     37     assumeDual(ProgramStateRef state, DefinedSVal Cond)
     38   {
     39     std::pair<ProgramStateRef, ProgramStateRef > res =
     40       std::make_pair(assume(state, Cond, true), assume(state, Cond, false));
     41 
     42     assert(!(!res.first && !res.second) && "System is over constrained.");
     43     return res;
     44   }
     45 
     46   virtual const llvm::APSInt* getSymVal(ProgramStateRef state,
     47                                         SymbolRef sym) const = 0;
     48 
     49   virtual bool isEqual(ProgramStateRef state,
     50                        SymbolRef sym,
     51                        const llvm::APSInt& V) const = 0;
     52 
     53   virtual ProgramStateRef removeDeadBindings(ProgramStateRef state,
     54                                                  SymbolReaper& SymReaper) = 0;
     55 
     56   virtual void print(ProgramStateRef state,
     57                      raw_ostream &Out,
     58                      const char* nl,
     59                      const char *sep) = 0;
     60 
     61   virtual void EndPath(ProgramStateRef state) {}
     62 
     63 protected:
     64   /// canReasonAbout - Not all ConstraintManagers can accurately reason about
     65   ///  all SVal values.  This method returns true if the ConstraintManager can
     66   ///  reasonably handle a given SVal value.  This is typically queried by
     67   ///  ExprEngine to determine if the value should be replaced with a
     68   ///  conjured symbolic value in order to recover some precision.
     69   virtual bool canReasonAbout(SVal X) const = 0;
     70 };
     71 
     72 ConstraintManager* CreateBasicConstraintManager(ProgramStateManager& statemgr,
     73                                                 SubEngine &subengine);
     74 ConstraintManager* CreateRangeConstraintManager(ProgramStateManager& statemgr,
     75                                                 SubEngine &subengine);
     76 
     77 } // end GR namespace
     78 
     79 } // end clang namespace
     80 
     81 #endif
     82