Skip to content
Snippets Groups Projects
Commit f21625ad authored by Jan Trávníček's avatar Jan Trávníček
Browse files

rename inner optimize functions

parent b681639b
No related branches found
No related tags found
No related merge requests found
......@@ -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 ) );
}
......
......@@ -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 );
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment