"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/fsmmin.cc" between
ragel-7.0.0.9.tar.gz and ragel-7.0.0.10.tar.gz

About:

fsmmin.cc  (ragel-7.0.0.9):fsmmin.cc  (ragel-7.0.0.10)
/* /*
* Copyright 2002 Adrian Thurston <thurston@complang.org> * Copyright 2002 Adrian Thurston <thurston@colm.net>
*/
/* This file is part of Ragel.
* *
* Ragel is free software; you can redistribute it and/or modify * Permission is hereby granted, free of charge, to any person obtaining a copy
* it under the terms of the GNU General Public License as published by * of this software and associated documentation files (the "Software"), to
* the Free Software Foundation; either version 2 of the License, or * deal in the Software without restriction, including without limitation the
* (at your option) any later version. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* *
* Ragel is distributed in the hope that it will be useful, * The above copyright notice and this permission notice shall be included in al
* but WITHOUT ANY WARRANTY; without even the implied warranty of l
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * copies or substantial portions of the Software.
* GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* along with Ragel; if not, write to the Free Software * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/ */
#include "fsmgraph.h" #include "fsmgraph.h"
#include "mergesort.h" #include "mergesort.h"
struct MergeSortInitPartition struct MergeSortInitPartition
: public MergeSort<StateAp*, InitPartitionCompare> : public MergeSort<StateAp*, InitPartitionCompare>
{ {
MergeSortInitPartition( FsmCtx *ctx ) MergeSortInitPartition( FsmCtx *ctx )
{ {
skipping to change at line 797 skipping to change at line 798
} }
else { else {
trans.increment(); trans.increment();
next.increment(); next.increment();
} }
} }
} }
} }
} }
bool FsmAp::elimCondBits()
{
bool modified = false;
for ( StateList::Iter st = stateList; st.lte(); st++ ) {
restart:
for ( TransList::Iter trans = st->outList; trans.lte(); trans++ )
{
if ( !trans->plain() ) {
CondSpace *cs = trans->condSpace;
for ( CondSet::Iter csi = cs->condSet; csi.lte();
csi++ ) {
long bit = 1 << csi.pos();
/* Sort into on and off lists. */
CondList on;
CondList off;
TransCondAp *tcap = trans->tcap();
while ( tcap->condList.length() > 0 ) {
CondAp *cond = tcap->condList.det
achFirst();
if ( cond->key.getVal() & bit ) {
cond->key = CondKey( cond
->key.getVal() & ~bit );
on.append( cond );
}
else {
off.append( cond );
}
}
bool merge = false;
if ( on.length() > 0 && on.length() == of
f.length() ) {
/* test if the same */
int cmpRes = compareCondListBitEl
im( on, off );
if ( cmpRes == 0 )
merge = true;
}
if ( merge ) {
if ( cs->condSet.length() == 1 )
{
/* clear out the on-list.
*/
while ( on.length() > 0 )
{
CondAp *cond = on
.detachFirst();
detachTrans( st,
cond->toState, cond );
}
/* turn back into a plain
transition. */
CondAp *cond = off.detach
First();
TransAp *n = convertToTra
nsAp( st, cond );
TransAp *before = trans->
prev;
st->outList.detach( trans
);
st->outList.addAfter( bef
ore, n );
modified = true;
goto restart;
}
else
{
CondSet newSet = cs->cond
Set;
newSet.Vector<Action*>::r
emove( csi.pos(), 1 );
trans->condSpace = addCon
dSpace( newSet );
/* clear out the on-list.
*/
while ( on.length() > 0 )
{
CondAp *cond = on
.detachFirst();
detachTrans( st,
cond->toState, cond );
}
}
}
/* Turn back into a single list. */
while ( on.length() > 0 || off.length() >
0 ) {
if ( on.length() == 0 ) {
while ( off.length() > 0
)
tcap->condList.ap
pend( off.detachFirst() );
}
else if ( off.length() == 0 ) {
while ( on.length() > 0 )
{
CondAp *cond = on
.detachFirst();
cond->key = CondK
ey( cond->key.getVal() | bit );
tcap->condList.ap
pend( cond );
}
}
else {
if ( off.head->key.getVal
() < ( on.head->key.getVal() | bit ) ) {
tcap->condList.ap
pend( off.detachFirst() );
}
else {
CondAp *cond = on
.detachFirst();
cond->key = CondK
ey( cond->key.getVal() | bit );
tcap->condList.ap
pend( cond );
}
}
}
if ( merge ) {
modified = true;
goto restart;
}
}
}
}
}
return modified;
}
/* Perform minimization after an operation according /* Perform minimization after an operation according
* to the command line args. */ * to the command line args. */
void FsmAp::afterOpMinimize( bool lastInSeq ) void FsmAp::afterOpMinimize( bool lastInSeq )
{ {
/* Switch on the prefered minimization algorithm. */ /* Switch on the prefered minimization algorithm. */
if ( ctx->minimizeOpt == MinimizeEveryOp || ( ctx->minimizeOpt == Minimiz eMostOps && lastInSeq ) ) { if ( ctx->minimizeOpt == MinimizeEveryOp || ( ctx->minimizeOpt == Minimiz eMostOps && lastInSeq ) ) {
/* First clean up the graph. FsmAp operations may leave these /* First clean up the graph. FsmAp operations may leave these
* lying around. There should be no dead end states. The subtract * lying around. There should be no dead end states. The subtract
* intersection operators are the only places where they may be * intersection operators are the only places where they may be
* created and those operators clean them up. */ * created and those operators clean them up. */
 End of changes. 5 change blocks. 
15 lines changed or deleted 155 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS