00001 #ifndef wali_wfa_TRANS_GUARD 00002 #define wali_wfa_TRANS_GUARD 1 00003 00004 00005 /*! 00006 * @author Nicholas Kidd 00007 */ 00008 00009 #include <iostream> 00010 #include "wali/Common.hpp" 00011 #include "wali/Printable.hpp" 00012 #include "wali/Countable.hpp" 00013 #include "wali/Markable.hpp" 00014 #include "wali/SemElem.hpp" 00015 #include "wali/KeyContainer.hpp" 00016 #include "wali/wfa/ITrans.hpp" 00017 00018 00019 // Disable 00020 // warning C4250: 'wali::wfa::Trans' : inherits 'wali::Markable::wali::Markable::mark' via dominance 00021 // for MSVC 00022 #if defined(_MSC_VER) 00023 # pragma warning(push) 00024 # pragma warning(disable: 4250) 00025 #endif 00026 00027 00028 namespace wali 00029 { 00030 namespace wpds { 00031 class Config; 00032 } 00033 00034 namespace wfa 00035 { 00036 00037 class WFA; 00038 class Trans; 00039 00040 /*! 00041 * @class Trans 00042 * 00043 * A Trans is a 4-tuple of from state, stack, to state, and Weight. It 00044 * represents a transition in the WFA. 00045 * 00046 * Markable is to make a Trans able to be placed in a Worklist. 00047 * Countable is for reference counting. 00048 * 00049 * @see Printable 00050 * @see Countable 00051 * @see Markable 00052 * @see Worklist 00053 * @see WFA 00054 * @see sem_elem_t 00055 * @see ref_ptr 00056 */ 00057 00058 class Trans : public ITrans, public Markable 00059 { 00060 // 00061 // Types 00062 // 00063 public: 00064 friend class WFA; 00065 static int numTrans; 00066 00067 00068 // 00069 // Methods 00070 // 00071 public: 00072 /*! 00073 * Construct an empty Trans 00074 */ 00075 Trans(); 00076 00077 /*! 00078 * @brief constructor 00079 * 00080 * This is used by WFA when addTrans is called. 00081 */ 00082 Trans( Key from, 00083 Key stack, 00084 Key to, 00085 sem_elem_t se ); 00086 00087 Trans( const Trans & t ); 00088 00089 Trans( const ITrans & t ); 00090 00091 Trans &operator =(const Trans &t); 00092 00093 Trans &operator =(const ITrans &t); 00094 00095 virtual ~Trans(); 00096 00097 virtual Trans* copy() const; 00098 virtual Trans* copy(Key f, Key s, Key t) const; 00099 00100 // 00101 // getters (const) 00102 // 00103 /*! @return const Key of from state */ 00104 Key from() const throw() { 00105 return kp.first; 00106 } 00107 00108 /*! @return const Key of from state */ 00109 Key from_state() const throw() { 00110 return kp.first; 00111 } 00112 00113 /*! @return const Key of stack symbol */ 00114 Key stack() const throw() { 00115 return kp.second; 00116 } 00117 00118 /*! @return const Key of to state */ 00119 Key to() const throw() { 00120 return toStateKey; 00121 } 00122 00123 /*! @return const Key of to state */ 00124 Key to_state() const throw() { 00125 return toStateKey; 00126 } 00127 00128 /*! @return const sem_elem_t of Trans */ 00129 virtual const sem_elem_t weight() const throw() { 00130 return se; 00131 } 00132 00133 /*! 00134 * @return const sem_elem_t delta of Trans 00135 * 00136 * delta is used in computing fixpoints 00137 */ 00138 const sem_elem_t getDelta() const throw() { 00139 return delta; 00140 } 00141 00142 // 00143 // getters (non const) 00144 // 00145 /*! @return Key of from state */ 00146 Key from() throw() { 00147 return kp.first; 00148 } 00149 00150 /*! @return Key of from state */ 00151 Key from_state()throw() { 00152 return kp.first; 00153 } 00154 00155 /*! @return Key of stack symbol */ 00156 Key stack() throw() { 00157 return kp.second; 00158 } 00159 00160 /*! @return Key of to state */ 00161 Key to() throw() { 00162 return toStateKey; 00163 } 00164 00165 /*! @return Key of to state */ 00166 Key to_state() throw() { 00167 return toStateKey; 00168 } 00169 00170 /*! @return sem_elem_t of Trans */ 00171 virtual sem_elem_t weight() throw() { 00172 return se; 00173 } 00174 00175 /*! 00176 * @return sem_elem_t delta of Trans 00177 * 00178 * delta is used in computing fixpoints 00179 */ 00180 sem_elem_t getDelta() throw() { 00181 return delta; 00182 } 00183 00184 // 00185 // setters 00186 // 00187 /*! 00188 * Set weight and delta of this Trans 00189 * to be param [w]. 00190 * 00191 * @param sem_elem_t for new weight and delta 00192 * 00193 * @return void 00194 */ 00195 virtual void setWeight( sem_elem_t w ) { 00196 se = w; 00197 delta = w; 00198 } 00199 00200 /*! 00201 * Set the delta value for the Trans. 00202 */ 00203 void setDelta( const sem_elem_t w ) { 00204 delta = w; 00205 } 00206 00207 /*! 00208 * Sets the weight of the Trans to be param w. 00209 * The Trans's status will be set to MODIFIED if 00210 * param w != this->weight(). Delta is set accordingly. 00211 * 00212 * @param w the sem_elem_t for the new weight 00213 */ 00214 virtual void combineTrans( ITrans* tp ); 00215 00216 /*! 00217 * Return const referenct to this transitions KeyPair 00218 * 00219 * The KeyPair holds the from state and stack symbol. 00220 * 00221 * @see KeyPair 00222 * @return const KeyPair reference 00223 */ 00224 const KeyPair & keypair() const throw() 00225 { 00226 return kp; 00227 } 00228 00229 /*! 00230 * @brief return true if the transition has been modified 00231 * 00232 * A Trans is considered modified if when its weight changes. This 00233 * includes the initial creation of a Trans object. This follows 00234 * from the fact that all Trans can be considered (abstractly) 00235 * created with a weight of ZERO 00236 * 00237 * @return true if this transition has been modified 00238 */ 00239 bool modified() const throw() 00240 { 00241 return (status == MODIFIED); 00242 } 00243 00244 /*! 00245 * @return A null pointer. 00246 */ 00247 wpds::Config* getConfig() const; 00248 00249 /*! 00250 * Set this Trans's Config to c. 00251 * @return void 00252 */ 00253 void setConfig( wpds::Config* c ); 00254 00255 /*! 00256 * This is used by (E)WPDS::poststar 00257 * during epsilon-transistion contraction. 00258 * The base case is: 00259 * this->weight()->extend(se) 00260 */ 00261 virtual sem_elem_t poststar_eps_closure( sem_elem_t se ); 00262 00263 virtual TaggedWeight apply_post( TaggedWeight tw) const; 00264 virtual TaggedWeight apply_pre( TaggedWeight tw) const; 00265 virtual void applyWeightChanger( util::WeightChanger &wc); 00266 00267 protected: 00268 KeyPair kp; 00269 Key toStateKey; 00270 mutable sem_elem_t se; 00271 sem_elem_t delta; 00272 00273 protected: // vars used in Process and not relevant to Trans 00274 status_t status; 00275 /*! 00276 * Used by *WPDS during pre and poststar. This is guaranteed 00277 * to be NULL when not performing a reachability query. 00278 */ 00279 mutable wpds::Config *config; 00280 }; 00281 00282 } // namespace wfa 00283 00284 } // namespace wali 00285 00286 00287 // Restore the warning state 00288 #if defined(_MSC_VER) 00289 # pragma warning(pop) 00290 #endif 00291 00292 #endif // wali_wfa_TRANS_GUARD 00293