EWPDS.hpp

Go to the documentation of this file.
00001 #ifndef wali_wpds_ewpds_EWPDS_GUARD
00002 #define wali_wpds_ewpds_EWPDS_GUARD 1
00003 
00004 /**
00005  * @author Akash Lal, Nicholas Kidd
00006  */
00007 
00008 #include "wali/Common.hpp"
00009 #include "wali/SemElemPair.hpp"
00010 #include "wali/IMergeFn.hpp"
00011 #include "wali/wpds/WPDS.hpp"
00012 #include <set>
00013 
00014 namespace wali
00015 {
00016   class SemElem;
00017   template< typename T > class Worklist;
00018 
00019   namespace wpds 
00020   {
00021     class Config;
00022     class rule_t;
00023     class RuleFunctor;
00024     class ConstRuleFunctor;
00025     class Wrapper;
00026 
00027     namespace ewpds
00028     {
00029 
00030       using ::wali::wfa::WFA;
00031       class ERule;
00032       typedef ref_ptr<ERule> erule_t;
00033 
00034 
00035       /**
00036        * @class EWPDS
00037        */
00038 
00039       class EWPDS : public WPDS
00040       {
00041         public:
00042           /**
00043            * For parsing XML EWPDSs.
00044            * @shadow wali::wpds::WPDS::XMLTag
00045            */
00046           static const std::string XMLTag;
00047 
00048         public:
00049           typedef HashMap< KeyTriple, rule_t > merge_rule_hash_t;
00050 
00051         public:
00052           //using WPDS::replace_rule;
00053           friend class TransCopyPairLinker;
00054 
00055         public:
00056 
00057           EWPDS(); 
00058           EWPDS( ref_ptr<Wrapper> wrapper );
00059           EWPDS( const EWPDS& e );
00060 
00061           virtual ~EWPDS();
00062 
00063           /** 
00064        * @brief create rule with no r.h.s. stack symbols
00065        * @return true if rule existed
00066        *
00067        * @see sem_elem_t
00068        * @see Key
00069        */
00070           virtual bool add_rule(
00071               Key from_state,
00072               Key from_stack,
00073               Key to_state,
00074               sem_elem_t se );
00075 
00076           /** @brief create rule with one r.h.s. stack symbol
00077            *
00078            * @return true if rule existed
00079        *
00080        * @see sem_elem_t
00081        * @see Key
00082        */
00083           virtual bool add_rule(
00084               Key from_state,
00085               Key from_stack,
00086               Key to_state,
00087               Key to_stack1,
00088               sem_elem_t se );
00089 
00090           /** 
00091            * @brief create rule with two r.h.s. stack symbols
00092            * @return true if rule existed
00093            *
00094            * @see sem_elem_t
00095            * @see wali::Key
00096            */
00097           virtual bool add_rule(
00098               wali::Key from_state,
00099               wali::Key from_stack,
00100               wali::Key to_state,
00101               wali::Key to_stack1,
00102               wali::Key to_stack2,
00103               sem_elem_t se);
00104 
00105           /** 
00106            * @brief create rule with two r.h.s. stack symbols
00107            * @return true if rule existed
00108            *
00109            * @see sem_elem_t
00110            * @see merge_fn_t
00111            * @see wali::Key
00112            */
00113           virtual bool add_rule(
00114               wali::Key from_state,
00115               wali::Key from_stack,
00116               wali::Key to_state,
00117               wali::Key to_stack1,
00118               wali::Key to_stack2,
00119               sem_elem_t se,
00120               merge_fn_t mf);
00121 
00122           /** 
00123            * @brief create rule with two r.h.s. stack symbols
00124            * @return true if rule existed
00125            *
00126            * @see sem_elem_t
00127            * @see wali::Key
00128            */
00129           virtual bool replace_rule(
00130               wali::Key from_state,
00131               wali::Key from_stack,
00132               wali::Key to_state,
00133               wali::Key to_stack1,
00134               wali::Key to_stack2,
00135               sem_elem_t se);
00136 
00137           /** 
00138            * @brief create rule with two r.h.s. stack symbols
00139            * @return true if rule existed
00140            *
00141            * @see sem_elem_t
00142            * @see merge_fn_t
00143            * @see wali::Key
00144            */
00145           virtual bool replace_rule(
00146               wali::Key from_state,
00147               wali::Key from_stack,
00148               wali::Key to_state,
00149               wali::Key to_stack1,
00150               wali::Key to_stack2,
00151               sem_elem_t se,
00152               merge_fn_t mf);
00153 
00154 
00155           // Both these versions are provided for EWPDS via WPDS
00156           // void poststar( WFA & input, WFA & output );
00157           // void poststar( WFA & input);
00158 
00159           /**
00160            * @brief Perform prestar reachability query
00161            *
00162            * @param input
00163            * @param output
00164            *
00165            * @see WFA
00166            */
00167           virtual void prestar( WFA const & input, WFA& output );
00168 
00169           virtual wfa::WFA prestar( wfa::WFA const & input ) {
00170             return this->WPDS::prestar(input);
00171           }
00172 
00173           /**
00174            * This method writes the EWPDS to the passed in 
00175            * std::ostream parameter. Implements Printable::print.
00176            *
00177            * @param o the std::ostream this is written to
00178            * @return std::ostream this was written to
00179            *
00180            * @see Printable
00181            */
00182           virtual std::ostream & print( std::ostream & o ) const;
00183 
00184           /**
00185            * This method marshalls the EWPDS into the passed
00186            * in std::ostream parameter.  Marshalling simply
00187            * writes the EWPDS in XML form.
00188            *
00189            * @return std::ostream the EWPDS was marshalled into
00190            */
00191           virtual std::ostream & marshall( std::ostream & o ) const;
00192 
00193           /**
00194            * Override WPDS::operator()(ITrans const *) for linking b/c
00195            * EWPDS uses paired weights
00196            */
00197           virtual void operator()( wfa::ITrans const * t );
00198 
00199           rule_t lookup_rule(wali::Key to_state, wali::Key to_stack1, wali::Key to_stack2) const;
00200 
00201         
00202           ///////////////////////////
00203           // These next two functions just forward to the base class. They are
00204           // here so we can compile under GCC with -Woverloaded-virtual. (See
00205           // another comment below for more discussion about a similar issue
00206           // with a couple add_rule functions.)
00207           virtual bool replace_rule(
00208             Key from_state,
00209             Key from_stack,
00210             Key to_state,
00211             sem_elem_t se )
00212           {
00213             return this->WPDS::replace_rule(from_state, from_stack,
00214                                             to_state, se);
00215           }
00216 
00217           virtual bool replace_rule(
00218             Key from_state,
00219             Key from_stack,
00220             Key to_state,
00221             Key to_stack1,
00222             sem_elem_t se )
00223           {
00224             return this->WPDS::replace_rule(from_state, from_stack,
00225                                             to_state, to_stack1, se);
00226           }
00227         
00228         
00229 
00230         protected:
00231 
00232           /**
00233            * @brief Actually adds the rule
00234        */
00235 
00236           virtual bool add_rule(
00237               wali::Key from_state,
00238               wali::Key from_stack,
00239               wali::Key to_state,
00240               wali::Key to_stack1,
00241               wali::Key to_stack2,
00242               sem_elem_t se,
00243               merge_fn_t mf,
00244           bool replace_weight);
00245 
00246           
00247           /**
00248            * @brief helper method for prestar
00249            */
00250           virtual void prestar_handle_call(
00251               wfa::ITrans *t1,
00252               wfa::ITrans *t2,
00253               rule_t &r,
00254               sem_elem_t delta
00255               );
00256 
00257           /**
00258            * @brief helper method for prestar
00259            */
00260           virtual void prestar_handle_trans(
00261               wfa::ITrans * t,
00262               WFA & ca  ,
00263               rule_t & r,
00264               sem_elem_t delta );
00265 
00266           /**
00267            * @brief helper method for poststar
00268            */
00269           virtual void poststar_handle_trans(
00270               wfa::ITrans * t ,
00271               WFA & ca   ,
00272               rule_t & r,
00273               sem_elem_t delta
00274               );
00275 
00276           virtual void update_etrans(
00277               Key from
00278               , Key stack
00279               , Key to
00280               , sem_elem_t se
00281               , Config * cfg
00282               );
00283 
00284           virtual void update(
00285               Key from
00286               , Key stack
00287               , Key to
00288               , sem_elem_t se
00289               , Config * cfg
00290               );
00291 
00292           virtual wfa::ITrans* update_prime(
00293               Key from, //<! Guaranteed to be a generated state
00294               wfa::ITrans* call, //<! The call transition
00295               rule_t r, //<! The push rule
00296               sem_elem_t delta, //<! Delta change on the call transition
00297               sem_elem_t wWithRule //<! delta \extends r->weight()
00298               );
00299 
00300 
00301         ///////////////////////////
00302         // These next two functions just forward to the base class. They are
00303         // here so we can compile under GCC with -Woverloaded-virtual. (An
00304         // alternate solution -- that used to be employed -- is the use of a
00305         // 'using' declaration to bring these into scope. However, this can
00306         // hide problems if a set of functions are brought into scope with
00307         // 'using' and then it is overloaded, when what was intended was only
00308         // some of the originals should be brought into scope and then a new
00309         // function is an override of one of the others. This means that the
00310         // critical bugs that -Woverloaded-virtual are intended to find won't
00311         // trigger a warning.
00312         virtual bool add_rule(
00313             Key from_state,
00314             Key from_stack,
00315             Key to_state,
00316             Key to_stack1,
00317             Key to_stack2,
00318             sem_elem_t se,
00319         bool replace_weight,
00320             rule_t& r )
00321         {
00322           return this->WPDS::add_rule(from_state, from_stack, to_state, to_stack1, to_stack2,
00323                                       se, replace_weight, r);
00324         }
00325 
00326         virtual bool add_rule(
00327             Key from_state,
00328             Key from_stack,
00329             Key to_state,
00330             Key to_stack1,
00331             Key to_stack2,
00332             sem_elem_t se,
00333             rule_t& r )
00334         {
00335           return this->WPDS::add_rule(from_state, from_stack, to_state,
00336                                       to_stack1, to_stack2, se, r);
00337         }
00338 
00339           
00340         private:
00341           merge_rule_hash_t merge_rule_hash; // FIXME: verify correct usage of HashMap
00342         protected:
00343           bool addEtrans; // Used during update()
00344 
00345       }; // class EWPDS
00346 
00347     } // namespace ewpds
00348 
00349   } // namespace wpds
00350 
00351 } // namespace wali
00352 
00353 #endif  // wali_wpds_ewpds_EWPDS_GUARD
00354