00001 #ifndef wali_WITNESS_GUARD 00002 #define wali_WITNESS_GUARD 1 00003 00004 /*! 00005 * @author Nicholas Kidd 00006 */ 00007 00008 #include "wali/Common.hpp" 00009 #include "wali/Markable.hpp" 00010 #include "wali/ref_ptr.hpp" 00011 #include "wali/SemElem.hpp" 00012 #include "wali/witness/Visitable.hpp" 00013 00014 namespace wali 00015 { 00016 class Visitor; 00017 00018 namespace witness 00019 { 00020 class Witness; 00021 00022 struct witness_t : public wali::ref_ptr< Witness > 00023 { 00024 typedef wali::ref_ptr< Witness > Parent; 00025 witness_t(); 00026 witness_t( sem_elem_t ); 00027 witness_t( Witness* ); 00028 witness_t& operator=( sem_elem_t se ); 00029 witness_t& operator=( Witness* alpha ); 00030 Witness* getWitness( sem_elem_t se ); 00031 }; 00032 00033 /** 00034 * @class Witness 00035 */ 00036 class Witness : public SemElem, public Markable, public Visitable 00037 { 00038 public: 00039 static int COUNT; 00040 00041 public: 00042 Witness( sem_elem_t se ); 00043 00044 virtual ~Witness(); 00045 00046 /*! 00047 * Test if the Witness has user weight ZERO 00048 */ 00049 bool isZero(); 00050 00051 /*! 00052 * Test if the Witness has user weight ONE 00053 */ 00054 bool isOne(); 00055 00056 /*! 00057 * Returns a new Witness whose user_se is a sem_elem_t ONE 00058 * element of the user's weight domain. 00059 * 00060 * @see SemElem 00061 * @see sem_elem_t 00062 */ 00063 virtual sem_elem_t one() const; 00064 00065 /*! 00066 * Returns a new Witness whose user_se is a sem_elem_t ZERO 00067 * element of the user's weight domain. 00068 * 00069 * @see SemElem 00070 * @see sem_elem_t 00071 */ 00072 virtual sem_elem_t zero() const; 00073 00074 /*! 00075 * Extend the user supplied weight and create a new WitnessExtend. 00076 * 00077 * @see WitnessExtend 00078 */ 00079 virtual sem_elem_t extend( SemElem * se ); 00080 00081 /*! 00082 * Combines the user's weight and creates a WitnessCombine 00083 * if parameter "se" is not already a WitnessCombine. 00084 * 00085 * @see SemElem 00086 * @see sem_elem_t 00087 * @see WitnessCombine 00088 */ 00089 virtual sem_elem_t combine( SemElem * se ); 00090 00091 /*! 00092 * Test for equality of user supplied weight. The Witness is 00093 * simply along for the ride. 00094 */ 00095 virtual bool equal( SemElem * se ) const; 00096 00097 //! Print the Witness to the parameter o. 00098 virtual std::ostream& print( std::ostream& o ) const; 00099 00100 /*! 00101 * Accept method allows for different behaviors to be applied to 00102 * the Witness DAG. 00103 * 00104 * @see Visitor 00105 */ 00106 virtual void accept( Visitor& v, bool visitOnce=false ); 00107 00108 //! Pretty print in a DAG like structure to the ostream 00109 virtual std::ostream& prettyPrint( std::ostream& o, size_t depth ) const; 00110 00111 //! Prints " |" to parameter o for each level of depth 00112 std::ostream& formatDepth( std::ostream& o, size_t depth ) const; 00113 00114 /*! 00115 * Returns protected sem_elem_t se member variable that is the 00116 * user supplied weight or from a computation involving the 00117 * user defined semiring. 00118 * 00119 * @see sem_elem_t 00120 */ 00121 sem_elem_t weight() { return user_se; } 00122 00123 //! Reset all marks (recursively) 00124 virtual void reset_marks() const; 00125 00126 protected: 00127 sem_elem_t user_se; //!< The user SemElem value 00128 bool isEmpty; //!< True if type == Witness. Cheap reflection. 00129 00130 private: 00131 Witness( sem_elem_t se, bool ie ); 00132 00133 }; // class Witness 00134 00135 } // namespace witness 00136 00137 } // namespace wali 00138 00139 #endif // wali_WITNESS_GUARD 00140