From ad6eb395db25cf46c84eebf2a8c4b138df6dd2a7 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 19 Jul 2016 09:59:56 +0200
Subject: [PATCH] simplify internal regexp optimize api

---
 .../src/regexp/simplify/RegExpOptimize.cpp    |  2 +-
 .../src/regexp/simplify/RegExpOptimize.h      | 14 ++--
 .../simplify/RegExpOptimizeUnboundedPart.cxx  | 72 +++++++++----------
 3 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/alib2algo/src/regexp/simplify/RegExpOptimize.cpp b/alib2algo/src/regexp/simplify/RegExpOptimize.cpp
index c7843470d6..b3b390c235 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.optimizeInner( & regexp.getRegExp( ) );
+	UnboundedRegExpElement* optimized = 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 b1335d17ba..76d1ce2512 100644
--- a/alib2algo/src/regexp/simplify/RegExpOptimize.h
+++ b/alib2algo/src/regexp/simplify/RegExpOptimize.h
@@ -77,13 +77,13 @@ public:
 private:
 	regexp::FormalRegExpElement * optimize( regexp::FormalRegExpElement 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;
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpElement & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpAlternation & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpConcatenation & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpIteration & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpSymbol & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpEpsilon & node );
+	static regexp::UnboundedRegExpElement * optimizeInner( const regexp::UnboundedRegExpEmpty & node );
 
 private:
 	static bool A1( regexp::UnboundedRegExpAlternation & node );
diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
index 50ae9dbe0e..d14bbddfaa 100644
--- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
+++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
@@ -11,7 +11,7 @@ namespace simplify {
 
 void RegExpOptimize::optimize( UnboundedRegExpAlternation & alt ) {
 	//while( A1( alt ) || A2( alt ) || A3( alt ) || A4( alt ) || A10( alt ) || V2( alt ) || V5( alt ) || V6( alt ) || X1( alt ) );
-	UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & alt );
+	UnboundedRegExpElement* optimized = optimizeInner( alt );
 
 	UnboundedRegExpAlternation * alternationOptimized = dynamic_cast<UnboundedRegExpAlternation *>( optimized );
 	if( alternationOptimized ) {
@@ -25,7 +25,7 @@ void RegExpOptimize::optimize( UnboundedRegExpAlternation & alt ) {
 
 void RegExpOptimize::optimize( UnboundedRegExpConcatenation & concat ) {
 	//while( A5( concat ) || A6( concat ) || A7( concat ) || A8( concat ) || A9( concat ) || V8( concat ) );//|| V9( concat ) );
-	UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & concat );
+	UnboundedRegExpElement* optimized = optimizeInner( concat );
 
 	UnboundedRegExpConcatenation * concatenationOptimized = dynamic_cast<UnboundedRegExpConcatenation *>( optimized );
 	if( concatenationOptimized ) {
@@ -48,7 +48,7 @@ void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) {
 			return;
 		}
 	} while( A11( iter ) || V1( iter ) || V3( iter ) || V4( iter ) || V10( iter ) );*/
-	UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & iter );
+	UnboundedRegExpElement* optimized = optimizeInner( iter );
 
 	UnboundedRegExpIteration * iterationOptimized = dynamic_cast<UnboundedRegExpIteration *>( optimized );
 	if( iterationOptimized ) {
@@ -59,39 +59,39 @@ void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) {
 	}
 }
 
-UnboundedRegExpElement* RegExpOptimize::optimizeInner( UnboundedRegExpElement const * const & node ) const {
-	const UnboundedRegExpAlternation * alternation = dynamic_cast<const UnboundedRegExpAlternation*>( node );
+UnboundedRegExpElement* RegExpOptimize::optimizeInner( const UnboundedRegExpElement & node ) {
+	const UnboundedRegExpAlternation * alternation = dynamic_cast<const UnboundedRegExpAlternation*>( & node );
 	if( alternation )
-		return optimizeInner( alternation );
+		return optimizeInner( * alternation );
 
-	const UnboundedRegExpConcatenation * concatenation = dynamic_cast<const UnboundedRegExpConcatenation*>( node );
+	const UnboundedRegExpConcatenation * concatenation = dynamic_cast<const UnboundedRegExpConcatenation*>( & node );
 	if( concatenation )
-		return optimizeInner( concatenation );
+		return optimizeInner( * concatenation );
 
-	const UnboundedRegExpIteration * iteration = dynamic_cast<const UnboundedRegExpIteration*>( node );
+	const UnboundedRegExpIteration * iteration = dynamic_cast<const UnboundedRegExpIteration*>( & node );
 	if( iteration )
-		return optimizeInner( iteration );
+		return optimizeInner( * iteration );
 
-	const UnboundedRegExpSymbol * symbol = dynamic_cast<const UnboundedRegExpSymbol*>( node );
+	const UnboundedRegExpSymbol * symbol = dynamic_cast<const UnboundedRegExpSymbol*>( & node );
 	if( symbol )
-		return optimizeInner( symbol );
+		return optimizeInner( * symbol );
 
-	const UnboundedRegExpEmpty * empty = dynamic_cast<const UnboundedRegExpEmpty*>( node );
+	const UnboundedRegExpEmpty * empty = dynamic_cast<const UnboundedRegExpEmpty*>( & node );
 	if( empty )
-		return optimizeInner( empty );
+		return optimizeInner( * empty );
 
-	const UnboundedRegExpEpsilon * eps = dynamic_cast<const UnboundedRegExpEpsilon*>( node );
+	const UnboundedRegExpEpsilon * eps = dynamic_cast<const UnboundedRegExpEpsilon*>( & node );
 	if( eps )
-		return optimizeInner( eps );
+		return optimizeInner( * eps );
 
 	throw exception::CommonException( "RegExpOptimize::optimize - unknown UnboundedRegExpElement node" );
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpAlternation const * const & node ) const {
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpAlternation & node ) {
 	UnboundedRegExpAlternation* alt = new UnboundedRegExpAlternation( );
 
-	for( const auto & child : node->getElements ( ) )
-		alt->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( child.get() ) ) );
+	for( const auto & child : node.getElements ( ) )
+		alt->pushBackChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * child ) ) );
 
 	// optimize while you can
 	while( A1( * alt ) || A2( * alt ) || A3( * alt ) || A4( * alt ) || A10( * alt ) || V2( * alt ) || V5( * alt ) || V6( * alt ) || X1( * alt ) );
@@ -110,11 +110,11 @@ UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpAlternati
 	return alt;
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpConcatenation const * const & node ) const {
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpConcatenation & node ) {
 	UnboundedRegExpConcatenation* concat = new UnboundedRegExpConcatenation( );
 
-	for( const auto & child : node->getElements ( ) )
-		concat->pushBackChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( child.get() ) ) );
+	for( const auto & child : node.getElements ( ) )
+		concat->pushBackChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * child ) ) );
 
 	while( A5( * concat ) || A6( * concat ) || A7( * concat ) || A8( * concat ) || A9( * concat ) || V8( * concat ) );//|| V9( * concat ) );
 
@@ -132,9 +132,9 @@ UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpConcatena
 	return concat;
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpIteration const * const & node ) const {
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpIteration & node ) {
 	UnboundedRegExpIteration* iter = new UnboundedRegExpIteration( UnboundedRegExpEmpty {} );
-	iter->setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( node->getChild ( ).get() ) ) );
+	iter->setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( * node.getChild ( ) ) ) );
 
 	do {
 		// V1 is implemented right here
@@ -152,16 +152,16 @@ UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpIteration
 	return iter;
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpSymbol const * const & node ) const {
-	return node->clone( );
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpSymbol & node ) {
+	return node.clone( );
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpEmpty const * const & node ) const {
-	return node->clone( );
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpEmpty & node ) {
+	return node.clone( );
 }
 
-UnboundedRegExpElement * RegExpOptimize::optimizeInner( UnboundedRegExpEpsilon const * const & node ) const {
-	return node->clone( );
+UnboundedRegExpElement * RegExpOptimize::optimizeInner( const UnboundedRegExpEpsilon & node ) {
+	return node.clone( );
 }
 
 /**
@@ -440,7 +440,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.optimizeInner ( & tmpConcat );
+		UnboundedRegExpElement * tmpConcatOpt = optimizeInner ( tmpConcat );
 
 		// check if the iteration element is the same as the rest of the concatenation
 		if( iter->getElement() == * tmpConcatOpt ) {
@@ -568,7 +568,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.optimizeInner ( & newAlt ) ) );
+	node.setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( newAlt ) ) );
 
 	return true;
 }
@@ -790,7 +790,7 @@ bool RegExpOptimize::V6( UnboundedRegExpAlternation & node ) {
 			} else {
 				UnboundedRegExpConcatenation tmpA;
 				tmpA.insert( tmpA.getChildren().end( ), concat->getChildren().begin( ), itStartX );
-				regexpA = RegExpOptimize::REG_EXP_OPTIMIZE.optimizeInner( & tmpA );
+				regexpA = optimizeInner( tmpA );
 			}
 
 			// store everything behind iteration's followup element as "y"
@@ -800,14 +800,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.optimizeInner( & tmpY );
+				regexpY = 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.optimizeInner( & tmpAY );
+			UnboundedRegExpElement * regexpAY = optimizeInner( tmpAY );
 			regexpA = tmpAY.getChildren()[0].release();
 			regexpY = tmpAY.getChildren()[1].release();
 
@@ -833,7 +833,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.optimizeInner( & tmpAltered );
+			UnboundedRegExpElement * regexpAltered = optimizeInner( tmpAltered );
 
 			node.setChild( std::smart_ptr < UnboundedRegExpElement > ( regexpAltered ), itA );
 			optimized = true;
-- 
GitLab