Rule.hpp

Go to the documentation of this file.
00001 #ifndef wali_wpds_RULE_GUARD
00002 #define wali_wpds_RULE_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include "wali/Common.hpp"
00009 #include "wali/Printable.hpp"
00010 #include "wali/Countable.hpp"
00011 #include "wali/Markable.hpp"
00012 #include "wali/SemElem.hpp"
00013 #include "wali/ref_ptr.hpp"
00014 
00015 //
00016 // begin namespace wali
00017 //
00018 namespace wali
00019 {
00020 
00021   namespace wpds
00022   {
00023 
00024     class Config;
00025     class rule_t;
00026 
00027     namespace ewpds 
00028     {
00029       class EWPDS;
00030     }
00031     namespace fwpds
00032     {
00033       class FWPDS;
00034     }
00035 
00036     /*! @class Rule
00037      *
00038      * @see Config
00039      * @see sem_elem_t
00040      * @see wali_key_t
00041      * @see ref_ptr
00042      * @see rcmix
00043      */
00044 
00045     class Rule : public Printable, public Countable
00046     {
00047 
00048       public:
00049         friend class WPDS;
00050         friend class DebugWPDS;
00051         friend class ewpds::EWPDS;
00052         friend class fwpds::FWPDS;
00053         friend class RuleWitness;
00054 
00055         static const std::string XMLTag;
00056         static const std::string XMLFromTag;
00057         static const std::string XMLFromStackTag;
00058         static const std::string XMLToTag;
00059         static const std::string XMLToStack1Tag;
00060         static const std::string XMLToStack2Tag;
00061 
00062       public: // static methods
00063 
00064         /*!
00065          * Keep track of the number of Rule's that have
00066          * been allocated
00067          */
00068         static int numRules;
00069 
00070       public:
00071 
00072         /*!
00073          * @brief constructor
00074          */
00075         Rule( Config *f, Config *t, wali_key_t s2, sem_elem_t se  );
00076 
00077         /*!
00078          * @brief destructor
00079          */
00080         ~Rule();
00081 
00082         /*! @return Config Rule transitions from */
00083         const Config & from() const;// { return *f; }
00084 
00085         /*! @return from state key */
00086         wali_key_t from_state() const;// { return f->state(); }
00087 
00088         /*! @return from stack key */
00089         wali_key_t from_stack() const;// { return f->stack(); }
00090 
00091         /*! @return Config Rule transitions to */
00092         const Config & to() const;// { return *t; }
00093 
00094         /*! @return to state key */
00095         wali_key_t to_state() const;// { return to().state(); }
00096 
00097         /*! @return to stack key 1 */
00098         wali_key_t to_stack1() const;// { return to().stack(); }
00099 
00100         /*! @return to stack key 2 */
00101         wali_key_t to_stack2() const;// { return stack2(); }
00102 
00103         /*!
00104          * @return Rule rhs second stack symbol or WALI_EPSILON if no such
00105          * stack sym
00106          */
00107         wali_key_t stack2() const { return stk2; }
00108 
00109         /*! @return const reference to this's Weight */
00110         const sem_elem_t& weight() const;
00111 
00112         /*! @return the Rule's weight */
00113         sem_elem_t weight();
00114 
00115         /*!
00116          * Sets the weight on the Rule.
00117          *
00118          * @param wnew the new weight for the rule
00119          * @return void
00120          */
00121         void setWeight( sem_elem_t wnew );
00122 
00123         /*!
00124          * overrides (implements) Printable::print method
00125          *
00126          * @param o the std::ostream this is written to
00127          * @return std::ostream passed in
00128          *
00129          * @see Printable
00130          */
00131         virtual std::ostream & print( std::ostream &o ) const;
00132 
00133         /*!
00134          * marshall will write a Rule to a std::ostream. This writes
00135          * the rule in XML form.
00136          *
00137          * @return std::ostream the marshalled rule was written to.
00138          */
00139         std::ostream& marshall( std::ostream & o ) const;
00140 
00141         /*!
00142          * @return true if this rule has 2 rhs stack symbols
00143          */
00144         bool is_rule2() const { return (stack2() != WALI_EPSILON); }
00145 
00146         // @author Amanda Burton
00147         /**
00148          *  TODO: fix comments
00149          *  operator== is needed by std::set
00150          */
00151         bool operator==( Rule other ) const;
00152         
00153         /**
00154          *  TODO: fix comments
00155          *  operator< is needed by std::set
00156          */
00157         bool operator<( Rule other ) const;
00158 
00159         /*!
00160          * @brief Make a copy of the rule
00161          */
00162         virtual void copy(const rule_t r);
00163 
00164       protected:
00165 
00166         Config * from() { return f; }
00167         Config * to() { return t; }
00168 
00169       protected:
00170         Config *f;
00171         Config *t;
00172         wali_key_t stk2;
00173         sem_elem_t se;
00174 
00175     };
00176 
00177     /*! @class rule_t
00178      *
00179      * Wrapper class for ref_ptr that ensures type safety.
00180      */
00181     class rule_t {
00182 
00183       public:
00184 
00185         rule_t() : rc(0) {}
00186 
00187         rule_t( Rule * ptr ) : rc(ptr) {}
00188 
00189         rule_t( const rule_t & rhs ) : rc( rhs.rc ) {}
00190 
00191         Rule * operator->() {
00192           return get_ptr();
00193         }
00194 
00195         Rule & operator*() {
00196           return *get_ptr();
00197         }
00198 
00199         rule_t & operator=( const rule_t &rhs ) {
00200           rc = rhs.rc;
00201           return *this;
00202         }
00203 
00204         rule_t & operator=( Rule * r ) {
00205           rc = r;
00206           return *this;
00207         }
00208 
00209         Rule * get_ptr() {
00210           return (Rule *)rc.get_ptr();
00211         }
00212 
00213         //
00214         // const methods
00215         //
00216         const Rule * operator->() const {
00217           return get_ptr();
00218         }
00219 
00220         const Rule & operator*() const {
00221           return *get_ptr();
00222         }
00223 
00224         const Rule * get_ptr() const {
00225           return (const Rule *)rc.get_ptr();
00226         }
00227 
00228         bool is_empty() const {
00229           return rc.is_empty();
00230         }
00231 
00232         bool is_valid() const {
00233           return rc.is_valid();
00234         }
00235 
00236       private:
00237 
00238         ref_ptr< Rule > rc;
00239     };
00240 
00241   } // end namespace wpds
00242 
00243 } // end namespace wali
00244 
00245 #endif  // wali_wpds_RULE_GUARD
00246 
00247