Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58885 - in branches/release: boost/regex/pending boost/regex/v4 libs/regex/example/timer libs/regex/src libs/regex/test/regress
From: john_at_[hidden]
Date: 2010-01-11 04:55:42


Author: johnmaddock
Date: 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
New Revision: 58885
URL: http://svn.boost.org/trac/boost/changeset/58885

Log:
Merge changes in Trunk:
  Simplify regex_timer to eliminate regression failure.
  Rename extern "C" function to have a "boost_" prefix.
  Fix recursive-expression related bug, and update tests to match.
Text files modified:
   branches/release/boost/regex/pending/static_mutex.hpp | 2 +-
   branches/release/boost/regex/v4/basic_regex_creator.hpp | 35 +++++++++++++++++++++++++++++++++++
   branches/release/boost/regex/v4/basic_regex_parser.hpp | 4 +++-
   branches/release/boost/regex/v4/perl_matcher.hpp | 11 ++++++++---
   branches/release/boost/regex/v4/perl_matcher_non_recursive.hpp | 5 +++++
   branches/release/boost/regex/v4/states.hpp | 8 ++++++++
   branches/release/libs/regex/example/timer/regex_timer.cpp | 20 ++++++++------------
   branches/release/libs/regex/src/static_mutex.cpp | 4 ++--
   branches/release/libs/regex/test/regress/test_perl_ex.cpp | 4 ++++
   9 files changed, 74 insertions(+), 19 deletions(-)

Modified: branches/release/boost/regex/pending/static_mutex.hpp
==============================================================================
--- branches/release/boost/regex/pending/static_mutex.hpp (original)
+++ branches/release/boost/regex/pending/static_mutex.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -140,7 +140,7 @@
 namespace boost{
 
 class BOOST_REGEX_DECL scoped_static_mutex_lock;
-extern "C" BOOST_REGEX_DECL void free_static_mutex();
+extern "C" BOOST_REGEX_DECL void boost_regex_free_static_mutex();
 
 class BOOST_REGEX_DECL static_mutex
 {

Modified: branches/release/boost/regex/v4/basic_regex_creator.hpp
==============================================================================
--- branches/release/boost/regex/v4/basic_regex_creator.hpp (original)
+++ branches/release/boost/regex/v4/basic_regex_creator.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -811,8 +811,43 @@
             {
                if((p->type == syntax_element_startmark) && (static_cast<re_brace*>(p)->index == id))
                {
+ //
+ // We've found the target of the recursion, set the jump target:
+ //
                   static_cast<re_jump*>(state)->alt.p = p;
                   ok = true;
+ //
+ // Now scan the target for nested repeats:
+ //
+ p = p->next.p;
+ int next_rep_id = 0;
+ while(p)
+ {
+ switch(p->type)
+ {
+ case syntax_element_rep:
+ case syntax_element_dot_rep:
+ case syntax_element_char_rep:
+ case syntax_element_short_set_rep:
+ case syntax_element_long_set_rep:
+ next_rep_id = static_cast<re_repeat*>(p)->state_id;
+ break;
+ case syntax_element_endmark:
+ if(static_cast<const re_brace*>(p)->index == id)
+ next_rep_id = -1;
+ break;
+ default:
+ break;
+ }
+ if(next_rep_id)
+ break;
+ p = p->next.p;
+ }
+ if(next_rep_id > 0)
+ {
+ static_cast<re_recurse*>(state)->state_id = next_rep_id - 1;
+ }
+
                   break;
                }
                p = p->next.p;

Modified: branches/release/boost/regex/v4/basic_regex_parser.hpp
==============================================================================
--- branches/release/boost/regex/v4/basic_regex_parser.hpp (original)
+++ branches/release/boost/regex/v4/basic_regex_parser.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -1939,7 +1939,9 @@
       }
 insert_recursion:
       pb->index = markid = 0;
- static_cast<re_jump*>(this->append_state(syntax_element_recurse, sizeof(re_jump)))->alt.i = v;
+ re_recurse* pr = static_cast<re_recurse*>(this->append_state(syntax_element_recurse, sizeof(re_recurse)));
+ pr->alt.i = v;
+ pr->state_id = 0;
       static_cast<re_case*>(
             this->append_state(syntax_element_toggle_case, sizeof(re_case))
             )->icase = this->flags() & regbase::icase;

Modified: branches/release/boost/regex/v4/perl_matcher.hpp
==============================================================================
--- branches/release/boost/regex/v4/perl_matcher.hpp (original)
+++ branches/release/boost/regex/v4/perl_matcher.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -277,10 +277,15 @@
       else
       {
          repeater_count* p = next;
- while(p->state_id != state_id)
+ while(p && (p->state_id != state_id))
             p = p->next;
- count = p->count;
- start_pos = p->start_pos;
+ if(p)
+ {
+ count = p->count;
+ start_pos = p->start_pos;
+ }
+ else
+ count = 0;
       }
    }
    ~repeater_count()

Modified: branches/release/boost/regex/v4/perl_matcher_non_recursive.hpp
==============================================================================
--- branches/release/boost/regex/v4/perl_matcher_non_recursive.hpp (original)
+++ branches/release/boost/regex/v4/perl_matcher_non_recursive.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -904,10 +904,15 @@
    }
    recursion_stack[recursion_stack_position].preturn_address = pstate->next.p;
    recursion_stack[recursion_stack_position].results = *m_presult;
+ if(static_cast<const re_recurse*>(pstate)->state_id > 0)
+ {
+ push_repeater_count(static_cast<const re_recurse*>(pstate)->state_id, &next_count);
+ }
    pstate = static_cast<const re_jump*>(pstate)->alt.p;
    recursion_stack[recursion_stack_position].id = static_cast<const re_brace*>(pstate)->index;
    ++recursion_stack_position;
    //BOOST_ASSERT(recursion_stack[recursion_stack_position-1].id);
+
    return true;
 }
 

Modified: branches/release/boost/regex/v4/states.hpp
==============================================================================
--- branches/release/boost/regex/v4/states.hpp (original)
+++ branches/release/boost/regex/v4/states.hpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -248,6 +248,14 @@
    bool greedy; // True if this is a greedy repeat
 };
 
+/*** struct re_recurse ************************************************
+Recurse to a particular subexpression.
+**********************************************************************/
+struct re_recurse : public re_jump
+{
+ int state_id; // identifier of first nested repeat within the recursion.
+};
+
 /*** enum re_jump_size_type *******************************************
 Provides compiled size of re_jump structure (allowing for trailing alignment).
 We provide this so we know how manybytes to insert when constructing the machine

Modified: branches/release/libs/regex/example/timer/regex_timer.cpp
==============================================================================
--- branches/release/libs/regex/example/timer/regex_timer.cpp (original)
+++ branches/release/libs/regex/example/timer/regex_timer.cpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -103,6 +103,7 @@
    char c = static_cast<char>(is.get());
    while(c != '\n')
    {
+ BOOST_ASSERT(is.good());
       s.append(1, c);
       c = static_cast<char>(is.get());
    }
@@ -123,16 +124,17 @@
 int main(int argc, char**argv)
 {
    ifstream ifs;
- streambuf* pbuf = 0;
+ std::istream* p_in = &std::cin;
    if(argc == 2)
    {
       ifs.open(argv[1]);
- if(ifs.bad())
+ ifs.peek();
+ if(!ifs.good())
       {
          cout << "Bad filename: " << argv[1] << endl;
          return -1;
       }
- pbuf = cin.rdbuf(ifs.rdbuf());
+ p_in = &ifs;
    }
    
    boost::regex ex;
@@ -152,12 +154,12 @@
    double tim;
    int result = 0;
    unsigned iters = 100;
- double wait_time = (std::min)(t.elapsed_min() * 1000, 1.0);
+ double wait_time = (std::min)(t.elapsed_min() * 1000, 0.5);
 
    while(true)
    {
       cout << "Enter expression (or \"quit\" to exit): ";
- boost::getline(cin, s1);
+ boost::getline(*p_in, s1);
       if(argc == 2)
          cout << endl << s1 << endl;
       if(s1 == "quit")
@@ -191,7 +193,7 @@
       while(true)
       {
          cout << "Enter string to search (or \"quit\" to exit): ";
- boost::getline(cin, s2);
+ boost::getline(*p_in, s2);
          if(argc == 2)
             cout << endl << s2 << endl;
          if(s2 == "quit")
@@ -365,12 +367,6 @@
       regfreeA(&r);
    }
 
- if(pbuf)
- {
- cin.rdbuf(pbuf);
- ifs.close();
- }
-
    return 0;
 }
 

Modified: branches/release/libs/regex/src/static_mutex.cpp
==============================================================================
--- branches/release/libs/regex/src/static_mutex.cpp (original)
+++ branches/release/libs/regex/src/static_mutex.cpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -124,7 +124,7 @@
 boost::recursive_mutex* static_mutex::m_pmutex = 0;
 boost::once_flag static_mutex::m_once = BOOST_ONCE_INIT;
 
-extern "C" BOOST_REGEX_DECL void free_static_mutex()
+extern "C" BOOST_REGEX_DECL void boost_regex_free_static_mutex()
 {
    delete static_mutex::m_pmutex;
    static_mutex::m_pmutex = 0;
@@ -133,7 +133,7 @@
 void static_mutex::init()
 {
    m_pmutex = new boost::recursive_mutex();
- int r = atexit(free_static_mutex);
+ int r = atexit(boost_regex_free_static_mutex);
    BOOST_ASSERT(0 == r);
 }
 

Modified: branches/release/libs/regex/test/regress/test_perl_ex.cpp
==============================================================================
--- branches/release/libs/regex/test/regress/test_perl_ex.cpp (original)
+++ branches/release/libs/regex/test/regress/test_perl_ex.cpp 2010-01-11 04:55:40 EST (Mon, 11 Jan 2010)
@@ -892,5 +892,9 @@
    TEST_REGEX_SEARCH("\\b(?&byte)(\\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\\d|25[0-5]|1\\d\\d|[1-9]?\\d))", perl|mod_x, "10.0.0.0", match_default, make_array(0, 8, 6, 8, -1, -1, -2, -2));
    TEST_REGEX_SEARCH("\\b(?&byte)(\\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\\d|25[0-5]|1\\d\\d|[1-9]?\\d))", perl|mod_x, "10.6", match_default, make_array(-2, -2));
    TEST_REGEX_SEARCH("\\b(?&byte)(\\.(?&byte)){3}(?(DEFINE)(?<byte>2[0-4]\\d|25[0-5]|1\\d\\d|[1-9]?\\d))", perl|mod_x, "455.3.4.5", match_default, make_array(-2, -2));
+
+ // Bugs:
+ TEST_REGEX_SEARCH("namespace\\s+(\\w+)\\s+(\\{(?:[^{}]*(?:(?2)[^{}]*)*)?\\})", perl, "namespace one { namespace two { int foo(); } }", match_default, make_array(0, 46, 10, 13, 14, 46, -2, -2));
+ TEST_REGEX_SEARCH("namespace\\s+(\\w+)\\s+(\\{(?:[^{}]*(?:(?2)[^{}]*)*)?\\})", perl, "namespace one { namespace two { int foo(){} } { {{{ } } } } {}}", match_default, make_array(0, 64, 10, 13, 14, 64, -2, -2));
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk