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

make optimize compile

parent f9369ac6
No related branches found
No related tags found
No related merge requests found
......@@ -27,11 +27,7 @@ FormalRegExp RegExpOptimize::optimize( FormalRegExp const & regexp )
{
FormalRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & regexp.getRegExp( ) );
 
FormalRegExp ret( std::move( * optimized ) );
delete optimized;
return ret;
return FormalRegExp ( std::manage_move ( optimized ) );
}
 
auto RegExpOptimizeFormalRegEpx = RegExpOptimize::RegistratorWrapper<FormalRegExp, FormalRegExp>(RegExpOptimize::optimize);
......@@ -47,8 +43,7 @@ void RegExpOptimize::optimize( FormalRegExpElement & element )
* alternation = std::move( * alternationOptimized );
delete alternationOptimized;
} else {
* alternation = FormalRegExpAlternation { std::move( * optimized ), FormalRegExpEmpty { } };
delete optimized;
* alternation = FormalRegExpAlternation { std::manage_move ( optimized ), FormalRegExpEmpty { } };
}
return;
}
......@@ -60,8 +55,7 @@ void RegExpOptimize::optimize( FormalRegExpElement & element )
* concatenation = std::move( * concatenationOptimized );
delete concatenationOptimized;
} else {
* concatenation = FormalRegExpConcatenation { std::move( * optimized ), FormalRegExpEpsilon { } };
delete optimized;
* concatenation = FormalRegExpConcatenation { std::manage_move ( optimized ), FormalRegExpEpsilon { } };
}
return;
}
......@@ -73,8 +67,7 @@ void RegExpOptimize::optimize( FormalRegExpElement & element )
* iteration = std::move( * iterationOptimized );
delete iterationOptimized;
} else {
* iteration = FormalRegExpIteration { std::move( * optimized ) };
delete optimized;
* iteration = FormalRegExpIteration { std::manage_move ( optimized ) };
}
return;
}
......@@ -87,11 +80,7 @@ UnboundedRegExp RegExpOptimize::optimize( UnboundedRegExp const & regexp )
{
UnboundedRegExpElement* optimized = RegExpOptimize::REG_EXP_OPTIMIZE.optimize( & regexp.getRegExp( ) );
 
UnboundedRegExp ret( std::move( * optimized ) );
delete optimized;
return ret;
return UnboundedRegExp ( std::manage_move ( optimized ) );
}
 
auto RegExpOptimizeUnboundedRegEpx = RegExpOptimize::RegistratorWrapper<UnboundedRegExp, UnboundedRegExp>(RegExpOptimize::optimize);
......@@ -107,8 +96,7 @@ void RegExpOptimize::optimize( UnboundedRegExpElement & element ) {
delete alternationOptimized;
} else {
* alternation = UnboundedRegExpAlternation { };
alternation->appendElement( std::move( * optimized ) );
delete optimized;
alternation->appendElement( std::manage_move ( optimized ) );
}
return;
}
......@@ -121,8 +109,7 @@ void RegExpOptimize::optimize( UnboundedRegExpElement & element ) {
delete concatenationOptimized;
} else {
* concatenation = UnboundedRegExpConcatenation { };
concatenation->appendElement( std::move( * optimized ) );
delete optimized;
concatenation->appendElement( std::manage_move ( optimized ) );
}
return;
}
......@@ -134,8 +121,7 @@ void RegExpOptimize::optimize( UnboundedRegExpElement & element ) {
* iteration = std::move( * iterationOptimized );
delete iterationOptimized;
} else {
* iteration = UnboundedRegExpIteration { std::move( * optimized ) };
delete optimized;
* iteration = UnboundedRegExpIteration { std::manage_move ( optimized ) };
}
return;
}
......
......@@ -26,35 +26,46 @@ bool RegExpOptimize::S( FormalRegExpElement * & node ) const
bool optimized = false;
FormalRegExpAlternation * alternation = dynamic_cast<FormalRegExpAlternation*>( node );
if( alternation ) {
auto tmp = alternation->left;
alternation->left = optimize(alternation->left);
if(tmp != alternation->left) optimized = true;
FormalRegExpElement * tmp = optimize ( alternation->left.get() );
if(tmp != alternation->left.get()) {
optimized = true;
alternation->left = std::smart_ptr < FormalRegExpElement > ( tmp );
}
 
tmp = alternation->right;
alternation->right = optimize(alternation->right);
if(tmp != alternation->right) optimized = true;
tmp = optimize ( alternation->right.get() );
if(tmp != alternation->right.get()) {
optimized = true;
alternation->right = std::smart_ptr < FormalRegExpElement > ( tmp );
}
 
return optimized;
}
 
FormalRegExpConcatenation * concatenation = dynamic_cast<FormalRegExpConcatenation*>( node );
if( concatenation ) {
auto tmp = concatenation->left;
concatenation->left = optimize(concatenation->left);
if(tmp != concatenation->left) optimized = true;
FormalRegExpElement* tmp = optimize ( concatenation->left.get() );
if(tmp != concatenation->left.get()) {
optimized = true;
concatenation->left = std::smart_ptr < FormalRegExpElement > ( tmp );
}
 
tmp = concatenation->right;
concatenation->right = optimize(concatenation->right);
if(tmp != concatenation->right) optimized = true;
tmp = optimize ( concatenation->right.get());
if(tmp != concatenation->right.get()) {
optimized = true;
concatenation->right = std::smart_ptr < FormalRegExpElement > ( tmp );
}
 
return optimized;
}
 
FormalRegExpIteration * iteration = dynamic_cast<FormalRegExpIteration*>( node );
if( iteration ) {
auto tmp = iteration->element;
iteration->element = optimize(iteration->element);
if(tmp != iteration->element) optimized = true;
FormalRegExpElement* tmp = optimize ( iteration->element.get() );
if(tmp != iteration->element.get()) {
optimized = true;
iteration->element = std::smart_ptr < FormalRegExpElement > ( tmp );
}
return iteration;
}
 
......@@ -72,17 +83,18 @@ bool RegExpOptimize::A1( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpAlternation * leftAlt = dynamic_cast<FormalRegExpAlternation *>( node->left );
FormalRegExpAlternation * leftAlt = dynamic_cast<FormalRegExpAlternation *>( node->left.get() );
 
if( leftAlt ) {
FormalRegExpElement * x = leftAlt->left;
FormalRegExpElement * y = leftAlt->right;
FormalRegExpElement * z = node->right;
leftAlt = static_cast<FormalRegExpAlternation *>( node->left.release() );
std::smart_ptr < FormalRegExpElement > x = std::move ( leftAlt->left );
std::smart_ptr < FormalRegExpElement > y = std::move ( leftAlt->right );
std::smart_ptr < FormalRegExpElement > z = std::move ( node->right );
 
node->left = x;
node->right = leftAlt;
leftAlt->left = y;
leftAlt->right = z;
leftAlt->left = std::move ( y );
leftAlt->right = std::move ( z );
node->left = std::move ( x );
node->right = std::smart_ptr < FormalRegExpElement > ( leftAlt );
 
return true;
}
......@@ -100,15 +112,14 @@ bool RegExpOptimize::A2( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpAlternation * rightAlt = dynamic_cast<FormalRegExpAlternation *>( node->right );
FormalRegExpAlternation * rightAlt = dynamic_cast<FormalRegExpAlternation *>( node->right.get() );
 
if( rightAlt ) {
FormalRegExpElement * x = node->left;
FormalRegExpElement * y = rightAlt->left;
FormalRegExpElement * x = node->left.get();
FormalRegExpElement * y = rightAlt->left.get();
 
if(*x > *y) {
node->left = y;
rightAlt->left = x;
std::swap ( node->left, rightAlt->left );
} else {
return false;
}
......@@ -129,20 +140,18 @@ bool RegExpOptimize::A3( FormalRegExpElement * & n ) const
 
// input can be \0 + \0, so at least one element must be preserved
 
FormalRegExpEmpty * rightEmp = dynamic_cast<FormalRegExpEmpty *>( node->right );
FormalRegExpEmpty * rightEmp = dynamic_cast<FormalRegExpEmpty *>( node->right.get() );
if( rightEmp ) {
delete rightEmp;
n = node->left;
node->left = NULL;
rightEmp = nullptr;
n = node->left.release();
delete node;
return true;
}
 
FormalRegExpEmpty * leftEmp = dynamic_cast<FormalRegExpEmpty *>( node->left );
FormalRegExpEmpty * leftEmp = dynamic_cast<FormalRegExpEmpty *>( node->left.release() );
if( leftEmp ) {
delete leftEmp;
n = node->right;
node->right = NULL;
leftEmp = nullptr;
n = node->right.release();
delete node;
return true;
}
......@@ -168,10 +177,9 @@ bool RegExpOptimize::A4( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
if( node->left == node->right ) {
delete node->left;
n = node->right;
node->right = NULL;
if( *node->left == *node->right ) {
delete node->left.release();
n = node->right.release();
delete node;
return true;
}
......@@ -189,17 +197,18 @@ bool RegExpOptimize::A5( FormalRegExpElement * & n ) const
FormalRegExpConcatenation * node = dynamic_cast<FormalRegExpConcatenation *>( n );
if( ! node ) return false;
 
FormalRegExpConcatenation * leftCon = dynamic_cast<FormalRegExpConcatenation *>( node->left );
FormalRegExpConcatenation * leftCon = dynamic_cast<FormalRegExpConcatenation *>( node->left.get() );
 
if( leftCon ) {
FormalRegExpElement * x = leftCon->left;
FormalRegExpElement * y = leftCon->right;
FormalRegExpElement * z = node->right;
leftCon = static_cast<FormalRegExpConcatenation *>( node->left.release() );
std::smart_ptr < FormalRegExpElement > x = std::move ( leftCon->left );
std::smart_ptr < FormalRegExpElement > y = std::move ( leftCon->right );
std::smart_ptr < FormalRegExpElement > z = std::move ( node->right );
 
node->left = x;
node->right = leftCon;
leftCon->left = y;
leftCon->right = z;
leftCon->left = std::move ( y );
leftCon->right = std::move ( z );
node->left = std::move ( x );
node->right = std::smart_ptr < FormalRegExpElement > ( leftCon );
 
return true;
}
......@@ -219,20 +228,18 @@ bool RegExpOptimize::A6( FormalRegExpElement * & n ) const
 
// input can be \e + \e, so at least one element must be preserved
 
FormalRegExpEpsilon * rightEmp = dynamic_cast<FormalRegExpEpsilon *>( node->right );
FormalRegExpEpsilon * rightEmp = dynamic_cast<FormalRegExpEpsilon *>( node->right.get() );
if( rightEmp ) {
delete rightEmp;
n = node->left;
node->left = NULL;
rightEmp = nullptr;
n = node->left.release();
delete node;
return true;
}
 
FormalRegExpEpsilon * leftEmp = dynamic_cast<FormalRegExpEpsilon *>( node->left );
FormalRegExpEpsilon * leftEmp = dynamic_cast<FormalRegExpEpsilon *>( node->left.get() );
if( leftEmp ) {
delete leftEmp;
n = node->right;
node->right = NULL;
leftEmp = nullptr;
n = node->right.release();
delete node;
return true;
}
......@@ -250,7 +257,7 @@ bool RegExpOptimize::A7( FormalRegExpElement * & n ) const
FormalRegExpConcatenation * node = dynamic_cast<FormalRegExpConcatenation *>( n );
if( ! node ) return false;
 
if( dynamic_cast<FormalRegExpEmpty *>( node->right ) || dynamic_cast<FormalRegExpEmpty *>( node->left ) ) {
if( dynamic_cast<FormalRegExpEmpty *>( node->right.get() ) || dynamic_cast<FormalRegExpEmpty *>( node->left.get() ) ) {
delete node;
n = new FormalRegExpEmpty { };
return true;
......@@ -295,60 +302,48 @@ bool RegExpOptimize::A10( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpEpsilon * leftEps = dynamic_cast<FormalRegExpEpsilon *>( node->left );
FormalRegExpEpsilon * leftEps = dynamic_cast<FormalRegExpEpsilon *>( node->left.get() );
if( leftEps ) {
FormalRegExpConcatenation * rightCon = dynamic_cast<FormalRegExpConcatenation *>( node->right );
FormalRegExpConcatenation * rightCon = dynamic_cast<FormalRegExpConcatenation *>( node->right.get() );
if( ! rightCon ) return false;
 
FormalRegExpIteration * rightLeftIte = dynamic_cast<FormalRegExpIteration *>( rightCon->left );
FormalRegExpIteration * rightLeftIte = dynamic_cast<FormalRegExpIteration *>( rightCon->left.get() );
if( rightLeftIte ) {
if(rightLeftIte->element == rightCon->right) {
delete leftEps;
delete rightCon->right;
n = rightCon->left;
rightCon->left = NULL;
if(*rightLeftIte->element == *rightCon->right) {
n = rightCon->left.release();
delete node;
return true;
}
}
 
FormalRegExpIteration * rightRightIte = dynamic_cast<FormalRegExpIteration *>( rightCon->right );
FormalRegExpIteration * rightRightIte = dynamic_cast<FormalRegExpIteration *>( rightCon->right.get() );
if( rightRightIte ) {
if(rightLeftIte->element == rightCon->left) {
delete leftEps;
delete rightCon->left;
n = rightCon->right;
rightCon->right = NULL;
if(*rightLeftIte->element == *rightCon->left) {
n = rightCon->right.release();
delete node;
return true;
}
}
}
 
FormalRegExpEpsilon * rightEps = dynamic_cast<FormalRegExpEpsilon *>( node->right );
FormalRegExpEpsilon * rightEps = dynamic_cast<FormalRegExpEpsilon *>( node->right.get() );
if( rightEps ) {
FormalRegExpConcatenation * leftCon = dynamic_cast<FormalRegExpConcatenation *>( node->left );
FormalRegExpConcatenation * leftCon = dynamic_cast<FormalRegExpConcatenation *>( node->left.get() );
if( ! leftCon ) return false;
 
FormalRegExpIteration * leftLeftIte = dynamic_cast<FormalRegExpIteration *>( leftCon->left );
FormalRegExpIteration * leftLeftIte = dynamic_cast<FormalRegExpIteration *>( leftCon->left.get() );
if( leftLeftIte ) {
if(leftLeftIte->element == leftCon->right) {
delete rightEps;
delete leftCon->right;
n = leftCon->left;
leftCon->left = NULL;
if(*leftLeftIte->element == *leftCon->right) {
n = leftCon->left.release();
delete node;
return true;
}
}
 
FormalRegExpIteration * leftRightIte = dynamic_cast<FormalRegExpIteration *>( leftCon->right );
FormalRegExpIteration * leftRightIte = dynamic_cast<FormalRegExpIteration *>( leftCon->right.get() );
if( leftRightIte ) {
if(leftLeftIte->element == leftCon->left) {
delete rightEps;
delete leftCon->left;
n = leftCon->right;
leftCon->right = NULL;
if(*leftLeftIte->element == *leftCon->left) {
n = leftCon->right.release();
delete node;
return true;
}
......@@ -368,19 +363,15 @@ bool RegExpOptimize::A11( FormalRegExpElement * & n ) const
FormalRegExpIteration * node = dynamic_cast<FormalRegExpIteration *>( n );
if( ! node ) return false;
 
FormalRegExpAlternation * childAlt = dynamic_cast<FormalRegExpAlternation *>( node->element );
FormalRegExpAlternation * childAlt = dynamic_cast<FormalRegExpAlternation *>( node->element.get() );
if( childAlt )
{
if(dynamic_cast<FormalRegExpEpsilon*>(childAlt->left)) {
node->element = childAlt->right;
childAlt->right = NULL;
delete childAlt;
if(dynamic_cast<FormalRegExpEpsilon*>(childAlt->left.get())) {
node->element = std::move ( childAlt->right );
return true;
}
if(dynamic_cast<FormalRegExpEpsilon*>(childAlt->right)) {
node->element = childAlt->left;
childAlt->left = NULL;
delete childAlt;
if(dynamic_cast<FormalRegExpEpsilon*>(childAlt->right.get())) {
node->element = std::move ( childAlt->left );
return true;
}
}
......@@ -398,7 +389,7 @@ bool RegExpOptimize::V1( FormalRegExpElement * & n ) const
FormalRegExpIteration * node = dynamic_cast<FormalRegExpIteration *>( n );
if( ! node ) return false;
 
if( dynamic_cast<FormalRegExpEmpty*>( node->element ) )
if( dynamic_cast<FormalRegExpEmpty*>( node->element.get() ) )
{
delete node;
n = new FormalRegExpEpsilon( );
......@@ -417,21 +408,19 @@ bool RegExpOptimize::V2( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left );
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left.get() );
if( leftIte ) {
if(leftIte->element == node->right) {
n = node->left;
node->left = NULL;
if(*leftIte->element == *node->right) {
n = node->left.release();
delete node;
return true;
}
}
 
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right );
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right.get() );
if( rightIte ) {
if(rightIte->element == node->left) {
n = node->right;
node->right = NULL;
if(*rightIte->element == *node->left) {
n = node->right.release();
delete node;
return true;
}
......@@ -450,13 +439,10 @@ bool RegExpOptimize::V3( FormalRegExpElement * & n ) const
FormalRegExpIteration * node = dynamic_cast<FormalRegExpIteration *>( n );
if( ! node ) return false;
 
FormalRegExpIteration* childIter = dynamic_cast<FormalRegExpIteration*>( node->element );
FormalRegExpIteration* childIter = dynamic_cast<FormalRegExpIteration*>( node->element.get() );
if( childIter )
{
node->element = childIter->element;
childIter->element = NULL;
delete childIter;
node->element = std::move ( childIter->element );
return true;
}
 
......@@ -473,16 +459,16 @@ bool RegExpOptimize::V4( FormalRegExpElement * & n ) const
FormalRegExpIteration * node = dynamic_cast<FormalRegExpIteration *>( n );
if( ! node ) return false;
 
FormalRegExpConcatenation * child = dynamic_cast<FormalRegExpConcatenation *>( node->element );
FormalRegExpConcatenation * child = dynamic_cast<FormalRegExpConcatenation *>( node->element.get() );
if( ! child ) return false;
 
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( child->left );
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( child->left.get() );
if( ! leftIte ) return false;
 
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( child->right );
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( child->right.get() );
if( ! rightIte ) return false;
 
n = new FormalRegExpIteration(FormalRegExpAlternation(std::move( *leftIte->element ), std::move(*rightIte->element)));
n = new FormalRegExpIteration( FormalRegExpAlternation(std::move( * leftIte->element ), std::move( * rightIte->element)));
 
delete node;
return true;
......@@ -538,13 +524,13 @@ bool RegExpOptimize::V10( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left );
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left.get() );
if( ! leftIte ) return false;
 
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right );
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right.get() );
if( ! rightIte ) return false;
 
n = new FormalRegExpConcatenation(std::move( *leftIte->element ), std::move(*rightIte->element));
n = new FormalRegExpConcatenation(std::move( * leftIte->element ), std::move( * rightIte->element ) );
 
delete node;
return true;
......@@ -560,21 +546,19 @@ bool RegExpOptimize::X1( FormalRegExpElement * & n ) const
FormalRegExpAlternation * node = dynamic_cast<FormalRegExpAlternation *>( n );
if( ! node ) return false;
 
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left );
FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left.get() );
if( leftIte ) {
if(dynamic_cast<FormalRegExpEpsilon*>(node->right)) {
n = node->left;
node->left = NULL;
if(dynamic_cast<FormalRegExpEpsilon*>(node->right.get())) {
n = node->left.release();
delete node;
return true;
}
}
 
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right );
FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right.get() );
if( rightIte ) {
if(dynamic_cast<FormalRegExpEpsilon*>(node->left)) {
n = node->right;
node->right = NULL;
if(dynamic_cast<FormalRegExpEpsilon*>(node->left.get())) {
n = node->right.release();
delete node;
return 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