Regex.hpp

Go to the documentation of this file.
00001 #ifndef wali_regex_RE_GUARD
00002 #define wali_regex_RE_GUARD 1
00003 
00004 /*!
00005  * @author Nicholas Kidd
00006  */
00007 
00008 #include "wali/Markable.hpp"
00009 #include "wali/SemElem.hpp"
00010 
00011 namespace wali 
00012 {
00013   namespace regex 
00014   {
00015     class Regex;
00016 
00017     typedef wali::ref_ptr<Regex> regex_t;
00018 
00019     class Regex :
00020       public wali::Markable,
00021       public wali::SemElem
00022     {
00023 
00024       public:
00025         static const std::string lblID;
00026         static const std::string lblNIL;
00027 
00028         /*! @return regex_t == Root(lblID) */
00029         static regex_t ID();
00030 
00031         /*! @return regex_t == Root(lblNIL) */
00032         static regex_t NIL();
00033         static regex_t COMBINE( regex_t lhs, regex_t rhs );
00034         static regex_t EXTEND( regex_t lhs, regex_t rhs );
00035         static regex_t STAR( regex_t r );
00036       public:
00037         Regex();
00038 
00039         Regex(wali::sem_elem_t se);
00040 
00041         virtual ~Regex();
00042 
00043         // These three methods wrap calls to recursive method and the
00044         // calls reset_marks
00045         void toMona(std::ostream& o, const std::string& prefix ) const;
00046         std::ostream& write_dot( std::ostream& o ) const;
00047         wali::sem_elem_t solve();
00048         virtual void reset_marks() const;
00049 
00050 
00051         // Helper methods used in Spec::basicRegex
00052         bool isOne() const;
00053         bool isZero() const;
00054         virtual bool isConstant() const;
00055 
00056         // wali::SemElem methods
00057         virtual wali::sem_elem_t one() const;
00058         virtual wali::sem_elem_t zero() const;
00059         virtual bool equal( wali::SemElem * se ) const;
00060         virtual wali::sem_elem_t combine( wali::SemElem* se );
00061         virtual wali::sem_elem_t extend( wali::SemElem* se );
00062         virtual std::ostream& print( std::ostream& o ) const;
00063 
00064 
00065         // Recursive worker interfaces
00066         virtual std::ostream& print_recurse( std::ostream& o ) const = 0;
00067         virtual std::ostream& write_dot_recurse( std::ostream& o ) const = 0;
00068         virtual void to_mona_recurse( std::ostream& o, const std::string& prefix ) const = 0;
00069         virtual wali::sem_elem_t solve_recurse() = 0;
00070 
00071 
00072         virtual size_t hash() const;
00073 
00074         std::ostream& monaHeader(std::ostream& o, const std::string& prefix) const;
00075         std::ostream& monaName( std::ostream& o, const std::string& prefix) const;
00076       protected: // dot helper methods
00077         std::ostream& write_dot_state( std::ostream& o, const std::string& lbl, const std::string& color ) const;
00078         std::ostream& write_dot_edge( std::ostream& o, regex_t that ) const;
00079 
00080       public:
00081         const int id;
00082 
00083       protected:
00084         wali::sem_elem_t value;
00085 
00086     };
00087 
00088   } // namespace regex
00089 
00090 } // namespace wali
00091 
00092 #endif  // wali_regex_Regex_GUARD
00093