fsmgraph.h (ragel-7.0.0.9) | : | fsmgraph.h (ragel-7.0.0.10) | ||
---|---|---|---|---|
/* | /* | |||
* Copyright 2001-2016 Adrian Thurston <thurston@complang.org> | * Copyright 2001-2016 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. | ||||
*/ | */ | |||
#ifndef _FSMGRAPH_H | #ifndef _FSMGRAPH_H | |||
#define _FSMGRAPH_H | #define _FSMGRAPH_H | |||
#include "config.h" | #include "config.h" | |||
#include "ragel.h" | #include "ragel.h" | |||
#include "common.h" | #include "common.h" | |||
#include "vector.h" | #include "vector.h" | |||
#include "bstset.h" | #include "bstset.h" | |||
skipping to change at line 639 | skipping to change at line 640 | |||
: | : | |||
TransAp( other ), | TransAp( other ), | |||
condList() | condList() | |||
{} | {} | |||
~TransCondAp() | ~TransCondAp() | |||
{ | { | |||
condList.empty(); | condList.empty(); | |||
} | } | |||
/* Cond trans list. */ | /* Cond trans list. Sorted by key value. */ | |||
CondList condList; | CondList condList; | |||
}; | }; | |||
struct TransDataAp | struct TransDataAp | |||
: public TransAp, public TransData | : public TransAp, public TransData | |||
{ | { | |||
TransDataAp() | TransDataAp() | |||
: | : | |||
TransAp(), | TransAp(), | |||
TransData() | TransData() | |||
skipping to change at line 1015 | skipping to change at line 1016 | |||
condSpaceMap.empty(); | condSpaceMap.empty(); | |||
} | } | |||
}; | }; | |||
struct FsmGbl | struct FsmGbl | |||
{ | { | |||
FsmGbl() | FsmGbl() | |||
: | : | |||
printStatistics(false), | printStatistics(false), | |||
errorCount(0), | errorCount(0), | |||
inLibRagel(false), | //inLibRagel(false), | |||
displayPrintables(false), | displayPrintables(false), | |||
backend(Direct), | ||||
stringTables(false), | stringTables(false), | |||
backendFeature(GotoFeature), | ||||
checkPriorInteraction(0), | checkPriorInteraction(0), | |||
wantDupsRemoved(true), | wantDupsRemoved(true), | |||
minimizeLevel(MinimizePartition2), | minimizeLevel(MinimizePartition2), | |||
minimizeOpt(MinimizeMostOps) | minimizeOpt(MinimizeMostOps) | |||
{} | {} | |||
bool printStatistics; | bool printStatistics; | |||
/* Error reporting. */ | /* | |||
* Error reporting. | ||||
*/ | ||||
/* PROGNAME: txt */ | ||||
std::ostream &error(); | std::ostream &error(); | |||
/* file:loc: txt */ | ||||
std::ostream &error( const InputLoc &loc ); | std::ostream &error( const InputLoc &loc ); | |||
/* txt */ | ||||
std::ostream &error_plain(); | ||||
/* file:loc: warning: txt */ | ||||
std::ostream &warning( const InputLoc &loc ); | std::ostream &warning( const InputLoc &loc ); | |||
/* Stats reporting. */ | /* Stats reporting. */ | |||
std::ostream &stats(); | std::ostream &stats(); | |||
/* Requested info. */ | /* Requested info. */ | |||
std::ostream &info(); | std::ostream &info(); | |||
std::stringstream libcerr; | std::stringstream libcerr; | |||
std::stringstream libcout; | std::stringstream libcout; | |||
int errorCount; | int errorCount; | |||
bool inLibRagel; | //bool inLibRagel; | |||
void abortCompile( int code ); | void abortCompile( int code ); | |||
bool displayPrintables; | bool displayPrintables; | |||
RagelBackend backend; | ||||
bool stringTables; | bool stringTables; | |||
BackendFeature backendFeature; | ||||
bool checkPriorInteraction; | bool checkPriorInteraction; | |||
bool wantDupsRemoved; | bool wantDupsRemoved; | |||
MinimizeLevel minimizeLevel; | MinimizeLevel minimizeLevel; | |||
MinimizeOpt minimizeOpt; | MinimizeOpt minimizeOpt; | |||
}; | }; | |||
/* All FSM operations must be between machines that have been created using the | /* All FSM operations must be between machines that have been created using the | |||
* same context object. */ | * same context object. */ | |||
struct FsmCtx | struct FsmCtx | |||
skipping to change at line 2117 | skipping to change at line 2125 | |||
public: | public: | |||
/* Compare deterimne relative priorities of two transition tables. */ | /* Compare deterimne relative priorities of two transition tables. */ | |||
int comparePrior( const PriorTable &priorTable1, const PriorTable &priorT able2 ); | int comparePrior( const PriorTable &priorTable1, const PriorTable &priorT able2 ); | |||
void addOutCondition( StateAp *state, Action *condAction, bool sense ); | void addOutCondition( StateAp *state, Action *condAction, bool sense ); | |||
void expandCondKeys( CondKeySet &condKeys, CondSpace *fromSpace, | void expandCondKeys( CondKeySet &condKeys, CondSpace *fromSpace, | |||
CondSpace *mergedSpace ); | CondSpace *mergedSpace ); | |||
/* Back to trans ap (minimmization) */ | ||||
TransDataAp *convertToTransAp( StateAp *from, CondAp *cond ); | ||||
/* Cross a src transition with one that is already occupying a spot. */ | /* Cross a src transition with one that is already occupying a spot. */ | |||
TransCondAp *convertToCondAp( StateAp *state, TransDataAp *trans ); | TransCondAp *convertToCondAp( StateAp *state, TransDataAp *trans ); | |||
CondSpace *expandCondSpace( TransAp *destTrans, TransAp *srcTrans ); | CondSpace *expandCondSpace( TransAp *destTrans, TransAp *srcTrans ); | |||
private: | private: | |||
/* Can generate states. */ | /* Can generate states. */ | |||
TransAp *crossTransitions( StateAp *from, | TransAp *crossTransitions( StateAp *from, | |||
TransAp *destTrans, TransAp *srcTrans ); | TransAp *destTrans, TransAp *srcTrans ); | |||
TransDataAp *crossTransitionsBothPlain( StateAp *from, | TransDataAp *crossTransitionsBothPlain( StateAp *from, | |||
TransDataAp *destTrans, TransDataAp *srcTrans ); | TransDataAp *destTrans, TransDataAp *srcTrans ); | |||
skipping to change at line 2159 | skipping to change at line 2170 | |||
* empty out stateDict and stFil. */ | * empty out stateDict and stFil. */ | |||
void cleanAbortedFill( StateAp *state ); | void cleanAbortedFill( StateAp *state ); | |||
void cleanAbortedFill(); | void cleanAbortedFill(); | |||
bool overStateLimit(); | bool overStateLimit(); | |||
void nfaFillInStates(); | void nfaFillInStates(); | |||
/* | /* | |||
* Transition Comparison. | * Transition Comparison. | |||
*/ | */ | |||
template< class Trans > int compareCondBitElim( Trans *trans1, Trans *tra | ||||
ns2 ); | ||||
template< class Trans > int compareCondBitElimPtr( Trans *trans1, Trans * | ||||
trans2 ); | ||||
int compareCondListBitElim( const CondList &condList1, const CondList &co | ||||
ndList2 ); | ||||
/* Compare priority and function table of transitions. */ | /* Compare priority and function table of transitions. */ | |||
static int compareTransData( TransAp *trans1, TransAp *trans2 ); | static int compareTransData( TransAp *trans1, TransAp *trans2 ); | |||
template< class Trans > static int compareCondData( Trans *trans1, Trans *trans2 ); | template< class Trans > static int compareCondData( Trans *trans1, Trans *trans2 ); | |||
/* Compare transition data. Either of the pointers may be null. */ | /* Compare transition data. Either of the pointers may be null. */ | |||
static int compareTransDataPtr( TransAp *trans1, TransAp *trans2 ); | static int compareTransDataPtr( TransAp *trans1, TransAp *trans2 ); | |||
template< class Trans > static int compareCondDataPtr( Trans *trans1, Tra ns *trans2 ); | template< class Trans > static int compareCondDataPtr( Trans *trans1, Tra ns *trans2 ); | |||
/* Compare target state and transition data. Either pointer may be null. */ | /* Compare target state and transition data. Either pointer may be null. */ | |||
static int compareFullPtr( TransAp *trans1, TransAp *trans2 ); | static int compareFullPtr( TransAp *trans1, TransAp *trans2 ); | |||
skipping to change at line 2431 | skipping to change at line 2446 | |||
/* Returns true if there is a transtion (either explicit or by a gap) to | /* Returns true if there is a transtion (either explicit or by a gap) to | |||
* the error state. */ | * the error state. */ | |||
bool checkErrTrans( StateAp *state, TransAp *trans ); | bool checkErrTrans( StateAp *state, TransAp *trans ); | |||
bool checkErrTrans( StateAp *state, CondAp *trans ); | bool checkErrTrans( StateAp *state, CondAp *trans ); | |||
bool checkErrTransFinish( StateAp *state ); | bool checkErrTransFinish( StateAp *state ); | |||
bool hasErrorTrans(); | bool hasErrorTrans(); | |||
/* Check if a machine defines a single character. This is useful in | /* Check if a machine defines a single character. This is useful in | |||
* validating ranges and machines to export. */ | * validating ranges and machines to export. */ | |||
bool checkSingleCharMachine( ); | bool checkSingleCharMachine( ); | |||
bool elimCondBits(); | ||||
}; | }; | |||
/* Callback invoked when another trans (or possibly this) is added into this | /* Callback invoked when another trans (or possibly this) is added into this | |||
* transition during the merging process. Draw in any properties of srcTrans | * transition during the merging process. Draw in any properties of srcTrans | |||
* into this transition. AddInTrans is called when a new transitions is made | * into this transition. AddInTrans is called when a new transitions is made | |||
* that will be a duplicate of another transition or a combination of several | * that will be a duplicate of another transition or a combination of several | |||
* other transitions. AddInTrans will be called for each transition that the | * other transitions. AddInTrans will be called for each transition that the | |||
* new transition is to represent. */ | * new transition is to represent. */ | |||
template< class Trans > void FsmAp::addInTrans( Trans *destTrans, Trans *srcTran s ) | template< class Trans > void FsmAp::addInTrans( Trans *destTrans, Trans *srcTran s ) | |||
{ | { | |||
skipping to change at line 2473 | skipping to change at line 2490 | |||
return 1; | return 1; | |||
else if ( trans1 != 0 ) { | else if ( trans1 != 0 ) { | |||
/* Both of the transition pointers are set. */ | /* Both of the transition pointers are set. */ | |||
int compareRes = compareCondData( trans1, trans2 ); | int compareRes = compareCondData( trans1, trans2 ); | |||
if ( compareRes != 0 ) | if ( compareRes != 0 ) | |||
return compareRes; | return compareRes; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
/* Compares two transition pointers according to priority and functions. | ||||
* Either pointer may be null. Does not consider to state or from state. */ | ||||
template< class Trans > int FsmAp::compareCondBitElimPtr( Trans *trans1, Trans * | ||||
trans2 ) | ||||
{ | ||||
if ( trans1 == 0 && trans2 != 0 ) | ||||
return -1; | ||||
else if ( trans1 != 0 && trans2 == 0 ) | ||||
return 1; | ||||
else if ( trans1 != 0 ) { | ||||
/* Both of the transition pointers are set. */ | ||||
int compareRes = compareCondBitElim( trans1, trans2 ); | ||||
if ( compareRes != 0 ) | ||||
return compareRes; | ||||
} | ||||
return 0; | ||||
} | ||||
#endif | #endif | |||
End of changes. 18 change blocks. | ||||
23 lines changed or deleted | 62 lines changed or added |