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

make declaration definition naming match in FormalRegExp optimisation

parent 6f412d6a
No related branches found
No related tags found
1 merge request!95Many clang-tidy fixes
...@@ -120,17 +120,17 @@ bool RegExpOptimize::S( FormalRegExpElement < SymbolType > * & node ) { ...@@ -120,17 +120,17 @@ bool RegExpOptimize::S( FormalRegExpElement < SymbolType > * & node ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A1( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A1( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpAlternation < SymbolType > * node = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
if( dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & node->getLeft ( ) ) ) { if( dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & n->getLeft ( ) ) ) {
FormalRegExpAlternation < SymbolType > leftAlt ( std::move ( static_cast < FormalRegExpAlternation < SymbolType > & > ( node->getLeft ( ) ) ) ); FormalRegExpAlternation < SymbolType > leftAlt ( std::move ( static_cast < FormalRegExpAlternation < SymbolType > & > ( n->getLeft ( ) ) ) );
   
node->setLeft ( std::move ( leftAlt.getLeft ( ) ) ); n->setLeft ( std::move ( leftAlt.getLeft ( ) ) );
leftAlt.setLeft ( std::move ( leftAlt.getRight ( ) ) ); leftAlt.setLeft ( std::move ( leftAlt.getRight ( ) ) );
leftAlt.setRight ( std::move ( node->getRight ( ) ) ); leftAlt.setRight ( std::move ( n->getRight ( ) ) );
node->setRight ( std::move ( leftAlt ) ); n->setRight ( std::move ( leftAlt ) );
   
return true; return true;
} }
...@@ -144,17 +144,17 @@ bool RegExpOptimize::A1( FormalRegExpElement < SymbolType > * & n ) { ...@@ -144,17 +144,17 @@ bool RegExpOptimize::A1( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A2 ( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A2 ( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpAlternation < SymbolType > * node = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
if ( dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & node->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & n->getRight ( ) ) ) {
FormalRegExpAlternation < SymbolType > & rightAlt = static_cast < FormalRegExpAlternation < SymbolType > & > ( node->getRight ( ) ); FormalRegExpAlternation < SymbolType > & rightAlt = static_cast < FormalRegExpAlternation < SymbolType > & > ( n->getRight ( ) );
   
if ( node->getLeft ( ) > rightAlt.getLeft ( ) ) { if ( n->getLeft ( ) > rightAlt.getLeft ( ) ) {
ext::ptr_value < FormalRegExpElement < SymbolType > > tmp ( std::move ( node->getLeft ( ) ) ); ext::ptr_value < FormalRegExpElement < SymbolType > > tmp ( std::move ( n->getLeft ( ) ) );
   
node->setLeft ( std::move ( rightAlt.getLeft ( ) ) ); n->setLeft ( std::move ( rightAlt.getLeft ( ) ) );
rightAlt.setLeft ( std::move ( tmp ) ); rightAlt.setLeft ( std::move ( tmp ) );
return true; return true;
} else { } else {
...@@ -171,21 +171,21 @@ bool RegExpOptimize::A2 ( FormalRegExpElement < SymbolType > * & n ) { ...@@ -171,21 +171,21 @@ bool RegExpOptimize::A2 ( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A3 ( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A3 ( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpAlternation < SymbolType > * node = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( node );
if( ! node ) return false; if( ! n ) return false;
   
// input can be \0 + \0, so at least one element must be preserved // input can be \0 + \0, so at least one element must be preserved
   
if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & node->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & n->getRight ( ) ) ) {
n = std::move ( node->getLeft ( ) ).clone ( ); node = std::move ( n->getLeft ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
   
if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & node->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & n->getLeft ( ) ) ) {
n = std::move ( node->getRight ( ) ).clone ( ); node = std::move ( n->getRight ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
   
...@@ -198,7 +198,7 @@ bool RegExpOptimize::A3 ( FormalRegExpElement < SymbolType > * & n ) { ...@@ -198,7 +198,7 @@ bool RegExpOptimize::A3 ( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & node ) {
/* /*
* two ways of implementing this opitimization: * two ways of implementing this opitimization:
* - sort and call std::unique ( O(n lg n) + O(n) ), but it also sorts... * - sort and call std::unique ( O(n lg n) + O(n) ), but it also sorts...
...@@ -207,11 +207,11 @@ bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & n ) { ...@@ -207,11 +207,11 @@ bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & n ) {
* As we always sort in optimization, we can use the first version, but A4 must be __always__ called __after__ A2 * As we always sort in optimization, we can use the first version, but A4 must be __always__ called __after__ A2
*/ */
   
FormalRegExpAlternation < SymbolType > * node = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( node );
if ( ! node ) return false; if ( ! n ) return false;
   
if ( node->getLeftElement() == node->getRightElement() ) { if ( n->getLeftElement() == n->getRightElement() ) {
n = std::move ( node->getRight ( ) ).clone ( ); node = std::move ( n->getRight ( ) ).clone ( );
delete node; delete node;
return true; return true;
} }
...@@ -225,17 +225,17 @@ bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & n ) { ...@@ -225,17 +225,17 @@ bool RegExpOptimize::A4( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A5( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A5( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpConcatenation < SymbolType > * node = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( n ); FormalRegExpConcatenation < SymbolType > * n = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( node );
if( ! node ) return false; if( ! node ) return false;
   
if( dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & node->getLeft ( ) ) ) { if( dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & n->getLeft ( ) ) ) {
FormalRegExpConcatenation < SymbolType > leftCon ( std::move ( static_cast < FormalRegExpConcatenation < SymbolType > & > ( node->getLeft ( ) ) ) ); FormalRegExpConcatenation < SymbolType > leftCon ( std::move ( static_cast < FormalRegExpConcatenation < SymbolType > & > ( n->getLeft ( ) ) ) );
   
node->setLeft ( std::move ( leftCon.getLeft ( ) ) ); n->setLeft ( std::move ( leftCon.getLeft ( ) ) );
leftCon.setLeft ( std::move ( leftCon.getRight ( ) ) ); leftCon.setLeft ( std::move ( leftCon.getRight ( ) ) );
leftCon.setRight ( std::move ( node->getRight ( ) ) ); leftCon.setRight ( std::move ( n->getRight ( ) ) );
node->setRight ( std::move ( leftCon ) ); n->setRight ( std::move ( leftCon ) );
   
return true; return true;
} }
...@@ -249,20 +249,20 @@ bool RegExpOptimize::A5( FormalRegExpElement < SymbolType > * & n ) { ...@@ -249,20 +249,20 @@ bool RegExpOptimize::A5( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A6( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A6( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpConcatenation < SymbolType > * node = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( n ); FormalRegExpConcatenation < SymbolType > * n = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
// input can be \e + \e, so at least one element must be preserved // input can be \e + \e, so at least one element must be preserved
   
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getRight ( ) ) ) {
n = std::move ( node->getLeft ( ) ).clone ( ); node = std::move ( n->getLeft ( ) ).clone ( );
delete node; delete node;
return true; return true;
} }
   
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getLeft ( ) ) ) {
n = std::move ( node->getRight ( ) ).clone ( ); node = std::move ( n->getRight ( ) ).clone ( );
delete node; delete node;
return true; return true;
} }
...@@ -276,13 +276,13 @@ bool RegExpOptimize::A6( FormalRegExpElement < SymbolType > * & n ) { ...@@ -276,13 +276,13 @@ bool RegExpOptimize::A6( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A7( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A7( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpConcatenation < SymbolType > * node = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( n ); FormalRegExpConcatenation < SymbolType > * n = dynamic_cast<FormalRegExpConcatenation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & node->getRight ( ) ) || dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & node->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & n->getRight ( ) ) || dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & n->getLeft ( ) ) ) {
delete node; delete n;
n = new FormalRegExpEmpty < SymbolType > { }; node = new FormalRegExpEmpty < SymbolType > { };
return true; return true;
} }
   
...@@ -295,7 +295,7 @@ bool RegExpOptimize::A7( FormalRegExpElement < SymbolType > * & n ) { ...@@ -295,7 +295,7 @@ bool RegExpOptimize::A7( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A8( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::A8( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -305,7 +305,7 @@ bool RegExpOptimize::A8( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -305,7 +305,7 @@ bool RegExpOptimize::A8( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A9( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::A9( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -315,25 +315,25 @@ bool RegExpOptimize::A9( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -315,25 +315,25 @@ bool RegExpOptimize::A9( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & node ) {
/* /*
* problem: * problem:
* - \e + x*x = x* * - \e + x*x = x*
* - but if we do not have the eps, but we do have iteration, then \e \in h(iter), therefore \e in h(node). * - but if we do not have the eps, but we do have iteration, then \e \in h(iter), therefore \e in h(node).
*/ */
   
FormalRegExpAlternation < SymbolType > * node = dynamic_cast<FormalRegExpAlternation < SymbolType > * > ( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast<FormalRegExpAlternation < SymbolType > * > ( node );
if ( ! node ) return false; if ( ! n ) return false;
   
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getLeft ( ) ) ) {
FormalRegExpConcatenation < SymbolType > * rightCon = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & node->getRight ( ) ); FormalRegExpConcatenation < SymbolType > * rightCon = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & n->getRight ( ) );
if ( ! rightCon ) return false; if ( ! rightCon ) return false;
   
FormalRegExpIteration < SymbolType > * rightLeftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & rightCon->getLeft ( ) ); FormalRegExpIteration < SymbolType > * rightLeftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & rightCon->getLeft ( ) );
if ( rightLeftIte ) { if ( rightLeftIte ) {
if ( rightLeftIte->getElement ( ) == rightCon->getRightElement ( ) ) { if ( rightLeftIte->getElement ( ) == rightCon->getRightElement ( ) ) {
n = std::move ( rightCon->getLeft ( ) ).clone ( ); node = std::move ( rightCon->getLeft ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
...@@ -341,22 +341,22 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) { ...@@ -341,22 +341,22 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) {
FormalRegExpIteration < SymbolType > * rightRightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & rightCon->getRight ( ) ); FormalRegExpIteration < SymbolType > * rightRightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & rightCon->getRight ( ) );
if ( rightRightIte ) { if ( rightRightIte ) {
if ( rightRightIte->getElement ( ) == rightCon->getLeftElement ( ) ) { if ( rightRightIte->getElement ( ) == rightCon->getLeftElement ( ) ) {
n = std::move ( rightCon->getRight ( ) ).clone ( ); node = std::move ( rightCon->getRight ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
} }
   
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getRight ( ) ) ) {
FormalRegExpConcatenation < SymbolType > * leftCon = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & node->getLeft ( ) ); FormalRegExpConcatenation < SymbolType > * leftCon = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & n->getLeft ( ) );
if ( ! leftCon ) return false; if ( ! leftCon ) return false;
   
FormalRegExpIteration < SymbolType > * leftLeftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & leftCon->getLeft ( ) ); FormalRegExpIteration < SymbolType > * leftLeftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & leftCon->getLeft ( ) );
if ( leftLeftIte ) { if ( leftLeftIte ) {
if ( leftLeftIte->getElement ( ) == leftCon->getRightElement ( ) ) { if ( leftLeftIte->getElement ( ) == leftCon->getRightElement ( ) ) {
n = std::move ( leftCon->getLeft ( ) ).clone ( ); node = std::move ( leftCon->getLeft ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
...@@ -364,8 +364,8 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) { ...@@ -364,8 +364,8 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) {
FormalRegExpIteration < SymbolType > * leftRightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & leftCon->getRight ( ) ); FormalRegExpIteration < SymbolType > * leftRightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & leftCon->getRight ( ) );
if ( leftRightIte ) { if ( leftRightIte ) {
if ( leftRightIte->getElement ( ) == leftCon->getLeftElement ( ) ) { if ( leftRightIte->getElement ( ) == leftCon->getLeftElement ( ) ) {
n = std::move ( leftCon->getRight ( ) ).clone ( ); node = std::move ( leftCon->getRight ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
...@@ -380,18 +380,18 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) { ...@@ -380,18 +380,18 @@ bool RegExpOptimize::A10( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::A11( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::A11( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpIteration < SymbolType > * node = dynamic_cast<FormalRegExpIteration < SymbolType > *>( n ); FormalRegExpIteration < SymbolType > * n = dynamic_cast<FormalRegExpIteration < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpAlternation < SymbolType > * childAlt = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & node->getChild ( ) ); FormalRegExpAlternation < SymbolType > * childAlt = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & n->getChild ( ) );
if ( childAlt ) { if ( childAlt ) {
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & childAlt->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & childAlt->getLeft ( ) ) ) {
node->setChild ( std::move ( childAlt->getRight ( ) ) ); n->setChild ( std::move ( childAlt->getRight ( ) ) );
return true; return true;
} }
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & childAlt->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & childAlt->getRight ( ) ) ) {
node->setChild ( std::move ( childAlt->getLeft ( ) ) ); n->setChild ( std::move ( childAlt->getLeft ( ) ) );
return true; return true;
} }
} }
...@@ -406,18 +406,18 @@ bool RegExpOptimize::A11( FormalRegExpElement < SymbolType > * & n ) { ...@@ -406,18 +406,18 @@ bool RegExpOptimize::A11( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V1( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::V1( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpIteration < SymbolType > * node = dynamic_cast<FormalRegExpIteration < SymbolType > *>( n ); FormalRegExpIteration < SymbolType > * n = dynamic_cast<FormalRegExpIteration < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & node->getChild ( ) ) ) { if ( dynamic_cast < FormalRegExpEmpty < SymbolType > * > ( & n->getChild ( ) ) ) {
delete node; delete n;
n = new FormalRegExpEpsilon < SymbolType > ( ); node = new FormalRegExpEpsilon < SymbolType > ( );
return true; return true;
} }
if ( dynamic_cast<FormalRegExpEpsilon < SymbolType > * > ( & node->getChild ( ) ) ) { if ( dynamic_cast<FormalRegExpEpsilon < SymbolType > * > ( & n->getChild ( ) ) ) {
delete node; delete n;
n = new FormalRegExpEpsilon < SymbolType > ( ); node = new FormalRegExpEpsilon < SymbolType > ( );
return true; return true;
} }
return false; return false;
...@@ -429,24 +429,24 @@ bool RegExpOptimize::V1( FormalRegExpElement < SymbolType > * & n ) { ...@@ -429,24 +429,24 @@ bool RegExpOptimize::V1( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V2( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::V2( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpAlternation < SymbolType > * node = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & node->getLeft ( ) ); FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & n->getLeft ( ) );
if ( leftIte ) { if ( leftIte ) {
if ( leftIte->getElement ( ) == node->getRightElement ( ) ) { if ( leftIte->getElement ( ) == n->getRightElement ( ) ) {
n = std::move ( node->getLeft ( ) ).clone ( ); node = std::move ( n->getLeft ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
   
FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & node->getRight ( ) ); FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & n->getRight ( ) );
if ( rightIte ) { if ( rightIte ) {
if ( rightIte->getElement ( ) == node->getLeftElement ( ) ) { if ( rightIte->getElement ( ) == n->getLeftElement ( ) ) {
n = std::move ( node->getRight ( ) ).clone ( ); node = std::move ( n->getRight ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
...@@ -460,13 +460,13 @@ bool RegExpOptimize::V2( FormalRegExpElement < SymbolType > * & n ) { ...@@ -460,13 +460,13 @@ bool RegExpOptimize::V2( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V3( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::V3( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpIteration < SymbolType > * node = dynamic_cast<FormalRegExpIteration < SymbolType > *>( n ); FormalRegExpIteration < SymbolType > * n = dynamic_cast<FormalRegExpIteration < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpIteration < SymbolType > * childIter = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & node->getChild ( ) ); FormalRegExpIteration < SymbolType > * childIter = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & n->getChild ( ) );
if( childIter ) { if( childIter ) {
node->setChild ( std::move ( childIter->getChild ( ) ) ); n->setChild ( std::move ( childIter->getChild ( ) ) );
return true; return true;
} }
   
...@@ -479,11 +479,11 @@ bool RegExpOptimize::V3( FormalRegExpElement < SymbolType > * & n ) { ...@@ -479,11 +479,11 @@ bool RegExpOptimize::V3( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpIteration < SymbolType > * node = dynamic_cast < FormalRegExpIteration < SymbolType > *>( n ); FormalRegExpIteration < SymbolType > * n = dynamic_cast < FormalRegExpIteration < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpConcatenation < SymbolType > * child = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & node->getChild ( ) ); FormalRegExpConcatenation < SymbolType > * child = dynamic_cast < FormalRegExpConcatenation < SymbolType > * > ( & n->getChild ( ) );
if( ! child ) return false; if( ! child ) return false;
   
FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & child->getLeft ( ) ); FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & child->getLeft ( ) );
...@@ -492,7 +492,7 @@ bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & n ) { ...@@ -492,7 +492,7 @@ bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & n ) {
FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & child->getRight ( ) ); FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & child->getRight ( ) );
if( ! rightIte ) return false; if( ! rightIte ) return false;
   
node->setChild ( FormalRegExpAlternation < SymbolType >( std::move ( leftIte->getElement ( ) ), std::move ( rightIte->getElement ( ) ) ) ); n->setChild ( FormalRegExpAlternation < SymbolType >( std::move ( leftIte->getElement ( ) ), std::move ( rightIte->getElement ( ) ) ) );
   
return true; return true;
} }
...@@ -503,7 +503,7 @@ bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & n ) { ...@@ -503,7 +503,7 @@ bool RegExpOptimize::V4( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V5( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::V5( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -513,7 +513,7 @@ bool RegExpOptimize::V5( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -513,7 +513,7 @@ bool RegExpOptimize::V5( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V6( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::V6( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -523,7 +523,7 @@ bool RegExpOptimize::V6( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -523,7 +523,7 @@ bool RegExpOptimize::V6( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V8( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::V8( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -533,7 +533,7 @@ bool RegExpOptimize::V8( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -533,7 +533,7 @@ bool RegExpOptimize::V8( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V9( FormalRegExpElement < SymbolType > * & /* n */) { bool RegExpOptimize::V9( FormalRegExpElement < SymbolType > * & /* node */) {
return false; //TODO return false; //TODO
} }
   
...@@ -543,11 +543,11 @@ bool RegExpOptimize::V9( FormalRegExpElement < SymbolType > * & /* n */) { ...@@ -543,11 +543,11 @@ bool RegExpOptimize::V9( FormalRegExpElement < SymbolType > * & /* n */) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::V10( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::V10( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpIteration < SymbolType > * node = dynamic_cast < FormalRegExpIteration < SymbolType > *>( n ); FormalRegExpIteration < SymbolType > * n = dynamic_cast < FormalRegExpIteration < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpAlternation < SymbolType > * alt = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & node->getChild ( ) ); FormalRegExpAlternation < SymbolType > * alt = dynamic_cast < FormalRegExpAlternation < SymbolType > * > ( & n->getChild ( ) );
if( ! alt ) return false; if( ! alt ) return false;
   
FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & alt->getLeft ( ) ); FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & alt->getLeft ( ) );
...@@ -568,24 +568,24 @@ bool RegExpOptimize::V10( FormalRegExpElement < SymbolType > * & n ) { ...@@ -568,24 +568,24 @@ bool RegExpOptimize::V10( FormalRegExpElement < SymbolType > * & n ) {
* @return bool true if optimization applied else false * @return bool true if optimization applied else false
*/ */
template < class SymbolType > template < class SymbolType >
bool RegExpOptimize::X1( FormalRegExpElement < SymbolType > * & n ) { bool RegExpOptimize::X1( FormalRegExpElement < SymbolType > * & node ) {
FormalRegExpAlternation < SymbolType > * node = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( n ); FormalRegExpAlternation < SymbolType > * n = dynamic_cast<FormalRegExpAlternation < SymbolType > *>( node );
if( ! node ) return false; if( ! n ) return false;
   
FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & node->getLeft ( ) ); FormalRegExpIteration < SymbolType > * leftIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & n->getLeft ( ) );
if ( leftIte ) { if ( leftIte ) {
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getRight ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getRight ( ) ) ) {
n = std::move ( node->getLeft ( ) ).clone ( ); node = std::move ( n->getLeft ( ) ).clone ( );
delete node; delete n;
return true; return true;
} }
} }
   
FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & node->getRight ( ) ); FormalRegExpIteration < SymbolType > * rightIte = dynamic_cast < FormalRegExpIteration < SymbolType > * > ( & n->getRight ( ) );
if ( rightIte ) { if ( rightIte ) {
if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & node->getLeft ( ) ) ) { if ( dynamic_cast < FormalRegExpEpsilon < SymbolType > * > ( & n->getLeft ( ) ) ) {
n = std::move ( node->getRight ( ) ).clone ( ); node = std::move ( n->getRight ( ) ).clone ( );
delete node; delete n;
return true; 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