diff --git a/alib2algo/src/regexp/simplify/RegExpOptimize.cpp b/alib2algo/src/regexp/simplify/RegExpOptimize.cpp index cf53f9c55edc99aeaee1bc479c3bb2a82d5b75c0..c7843470d6d708e97a55cab9ff05d2f6631d5748 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimize.cpp +++ b/alib2algo/src/regexp/simplify/RegExpOptimize.cpp @@ -31,7 +31,7 @@ FormalRegExp RegExpOptimize::optimize( FormalRegExp const & regexp ) { auto RegExpOptimizeFormalRegEpx = RegExpOptimize::RegistratorWrapper<FormalRegExp, FormalRegExp>(RegExpOptimize::optimize); UnboundedRegExp RegExpOptimize::optimize( UnboundedRegExp const & regexp ) { - UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & regexp.getRegExp( ) ); + UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & regexp.getRegExp( ) ); return UnboundedRegExp ( std::manage_move ( optimized ) ); } diff --git a/alib2algo/src/regexp/simplify/RegExpOptimize.h b/alib2algo/src/regexp/simplify/RegExpOptimize.h index 81dab1c699a4841d3dd57110359f7becac35442b..3f56fc47d63cbb872c4194bce10a61926cda1dfe 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimize.h +++ b/alib2algo/src/regexp/simplify/RegExpOptimize.h @@ -54,7 +54,7 @@ namespace simplify { * - V4 : <- : ( x + y )* = (x*y*)* * - V5 : <- : x*y = y + x*xy * - V6 : <- : x*y = y + xx*y - * - V7 : : bleh + * - V7 : : bleh * - V8 : -> : if \e in h(x) => xx* = x* * - V9 : -> : (xy)*x = x(yx)* * - V10: <- : ( x + y )* = ( x* + y* )* @@ -75,13 +75,13 @@ public: private: regexp::FormalRegExpElement * optimize( regexp::FormalRegExpElement const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpElement const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpAlternation const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpConcatenation const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpIteration const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpSymbol const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpEpsilon const * const & node ) const; - regexp::UnboundedRegExpElement * optimize( regexp::UnboundedRegExpEmpty const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpElement const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpAlternation const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpConcatenation const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpIteration const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpSymbol const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpEpsilon const * const & node ) const; + regexp::UnboundedRegExpElement * optimizeInner( regexp::UnboundedRegExpEmpty const * const & node ) const; private: static bool A1( regexp::UnboundedRegExpAlternation & node ); diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx index 91e93f04f34e7f325199c2615fc55c6d00e3a3f3..7d561ed2e7395da1a874bb68b786e690e4a7037d 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx @@ -10,7 +10,7 @@ namespace regexp { namespace simplify { void RegExpOptimize::optimize( UnboundedRegExpElement & element ) { - UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & element ); + UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & element ); UnboundedRegExpAlternation * alternation = dynamic_cast<UnboundedRegExpAlternation *>( & element ); if( alternation ) { @@ -54,39 +54,39 @@ void RegExpOptimize::optimize( UnboundedRegExpElement & element ) { return; } -UnboundedRegExpElement* RegExpOptimize::optimize( UnboundedRegExpElement const * const & node ) const { +UnboundedRegExpElement* RegExpOptimize::optimizeInner( UnboundedRegExpElement const * const & node ) const { const UnboundedRegExpAlternation * alternation = dynamic_cast<const UnboundedRegExpAlternation*>( node ); if( alternation ) - return optimize( alternation ); + return optimizeInner( alternation ); const UnboundedRegExpConcatenation * concatenation = dynamic_cast<const UnboundedRegExpConcatenation*>( node ); if( concatenation ) - return optimize( concatenation ); + return optimizeInner( concatenation ); const UnboundedRegExpIteration * iteration = dynamic_cast<const UnboundedRegExpIteration*>( node ); if( iteration ) - return optimize( iteration ); + return optimizeInner( iteration ); const UnboundedRegExpSymbol * symbol = dynamic_cast<const UnboundedRegExpSymbol*>( node ); if( symbol ) - return optimize( symbol ); + return optimizeInner( symbol ); const UnboundedRegExpEmpty * empty = dynamic_cast<const UnboundedRegExpEmpty*>( node ); if( empty ) - return optimize( empty ); + return optimizeInner( empty ); const UnboundedRegExpEpsilon * eps = dynamic_cast<const UnboundedRegExpEpsilon*>( node ); if( eps ) - return optimize( eps ); + return optimizeInner( eps ); throw exception::CommonException( "RegExpOptimize::optimize - unknown UnboundedRegExpElement node" ); } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpAlternation const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpAlternation const * const & node ) const { UnboundedRegExpAlternation* alt = new UnboundedRegExpAlternation( ); for( const auto & child : node->getElements ( ) ) - alt->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimize( child.get() ) ) ); + alt->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( child.get() ) ) ); // optimize while you can while( A1( * alt ) || A2( * alt ) || A3( * alt ) || A4( * alt ) || A10( * alt ) || V2( * alt ) || V5( * alt ) || V6( * alt ) || X1( * alt ) ); @@ -105,11 +105,11 @@ UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpAlternation co return alt; } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpConcatenation const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpConcatenation const * const & node ) const { UnboundedRegExpConcatenation* concat = new UnboundedRegExpConcatenation( ); for( const auto & child : node->getElements ( ) ) - concat->pushBackChild ( std::smart_ptr < UnboundedRegExpElement > ( optimize( child.get() ) ) ); + concat->pushBackChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( child.get() ) ) ); while( A5( * concat ) || A6( * concat ) || A7( * concat ) || A8( * concat ) || A9( * concat ) || V8( * concat ) );//|| V9( * concat ) ); @@ -127,9 +127,9 @@ UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpConcatenation return concat; } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpIteration const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpIteration const * const & node ) const { UnboundedRegExpIteration* iter = new UnboundedRegExpIteration( UnboundedRegExpEmpty {} ); - iter->setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimize ( node->getChild ( ).get() ) ) ); + iter->setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( node->getChild ( ).get() ) ) ); do { // V1 is implemented right here @@ -147,15 +147,15 @@ UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpIteration cons return iter; } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpSymbol const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpSymbol const * const & node ) const { return node->clone( ); } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpEmpty const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpEmpty const * const & node ) const { return node->clone( ); } -UnboundedRegExpElement * RegExpOptimize::optimize( UnboundedRegExpEpsilon const * const & node ) const { +UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpEpsilon const * const & node ) const { return node->clone( ); } @@ -435,7 +435,7 @@ bool RegExpOptimize::A10( UnboundedRegExpAlternation & node ) { // concatenation without the iteration node UnboundedRegExpConcatenation tmpConcat ( * childConcat ); tmpConcat.getChildren ( ).erase( tmpConcat.getChildren ( ).begin( ) ); - UnboundedRegExpElement * tmpConcatOpt = RegExpOptimize::REG_EXP_OPTIMIZE.optimize ( & tmpConcat ); + UnboundedRegExpElement * tmpConcatOpt = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner ( & tmpConcat ); // check if the iteration element is the same as the rest of the concatenation if( iter->getElement() == * tmpConcatOpt ) { @@ -563,7 +563,7 @@ bool RegExpOptimize::V4( UnboundedRegExpIteration & node ) { for( const auto & n : cont->getChildren ( ) ) newAlt.pushBackChild ( std::move ( static_cast < UnboundedRegExpIteration * > ( n.get ( ) )->getChild ( ) ) ); - node.setChild ( std::smart_ptr < UnboundedRegExpElement > ( RegExpOptimize::REG_EXP_OPTIMIZE.optimize ( & newAlt ) ) ); + node.setChild ( std::smart_ptr < UnboundedRegExpElement > ( RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner ( & newAlt ) ) ); return true; } @@ -785,7 +785,7 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { } else { UnboundedRegExpConcatenation tmpA; tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itStartX ); - regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpA ); + regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & tmpA ); } // store everything behind iteration's followup element as "y" @@ -795,14 +795,14 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { } else { UnboundedRegExpConcatenation tmpY; tmpY.insert( tmpY.getChildren().end( ), std::next( itC ), concat->getChildren ( ).end( ) ); - regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpY ); + regexpY = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & tmpY ); } // concatenate "a" and "y" and see if they exist somewhere in parent alternation ( node->getElements() ) UnboundedRegExpConcatenation tmpAY; tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); tmpAY.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); - UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAY ); + UnboundedRegExpElement * regexpAY = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & tmpAY ); regexpA = tmpAY.getChildren()[0].release(); regexpY = tmpAY.getChildren()[1].release(); @@ -828,7 +828,7 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) { tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpA ) ); tmpAltered.pushBackChild( * itC ); tmpAltered.pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( regexpY ) ); - UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & tmpAltered ); + UnboundedRegExpElement * regexpAltered = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & tmpAltered ); node.setChild( std::smart_ptr < UnboundedRegExpElement > ( regexpAltered ), itA ); optimized = true;