summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-11-26 16:20:57 -0500
committerAdrian Thurston <thurston@complang.org>2014-11-26 16:20:57 -0500
commit2efb22221312d7eef584003ed9e703e819053163 (patch)
treea011ff6cdfd6e664ba4cb5c03f13acf297a47a15
parent3242fcd9f0a3bf1a986b2b94fb8f8837ac370145 (diff)
downloadragel-2efb22221312d7eef584003ed9e703e819053163.tar.gz
remaing C/D table codegens using table array wrapper
-rw-r--r--ragel/cdfflat.cpp62
-rw-r--r--ragel/cdfgoto.cpp36
-rw-r--r--ragel/cdflat.cpp76
-rw-r--r--ragel/cdftable.cpp86
-rw-r--r--ragel/cdgoto.cpp36
-rw-r--r--ragel/cdtable.cpp135
6 files changed, 241 insertions, 190 deletions
diff --git a/ragel/cdfflat.cpp b/ragel/cdfflat.cpp
index 163e88c6..fe12ebe3 100644
--- a/ragel/cdfflat.cpp
+++ b/ragel/cdfflat.cpp
@@ -31,7 +31,7 @@ std::ostream &FFlatCodeGen::TO_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->toStateAction != 0 )
act = state->toStateAction->actListId+1;
- out << act;
+ taTSA.VAL( act );
return out;
}
@@ -40,7 +40,7 @@ std::ostream &FFlatCodeGen::FROM_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->fromStateAction != 0 )
act = state->fromStateAction->actListId+1;
- out << act;
+ taFSA.VAL( act );
return out;
}
@@ -49,7 +49,7 @@ std::ostream &FFlatCodeGen::EOF_ACTION( RedStateAp *state )
int act = 0;
if ( state->eofAction != 0 )
act = state->eofAction->actListId+1;
- out << act;
+ taEA.VAL( act );
return out;
}
@@ -59,7 +59,7 @@ std::ostream &FFlatCodeGen::TRANS_ACTION( RedTransAp *trans )
int action = 0;
if ( trans->action != 0 )
action = trans->action->actListId+1;
- out << action;
+ taTA.VAL( action );
return out;
}
@@ -151,6 +151,8 @@ std::ostream &FFlatCodeGen::ACTION_SWITCH()
std::ostream &FFlatCodeGen::TRANS_ACTIONS()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActListId) );
+
/* Transitions must be written ordered by their id. */
RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
@@ -171,11 +173,17 @@ std::ostream &FFlatCodeGen::TRANS_ACTIONS()
}
out << "\n";
delete[] transPtrs;
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FFlatCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -188,11 +196,17 @@ std::ostream &FFlatCodeGen::TO_STATE_ACTIONS()
}
}
out << "\n";
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FFlatCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -205,11 +219,17 @@ std::ostream &FFlatCodeGen::FROM_STATE_ACTIONS()
}
}
out << "\n";
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FFlatCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActListId) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -222,6 +242,10 @@ std::ostream &FFlatCodeGen::EOF_ACTIONS()
}
}
out << "\n";
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
@@ -245,40 +269,20 @@ void FFlatCodeGen::writeData()
TRANS_TARGS();
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofTrans() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() );
+ if ( redFsm->anyEofTrans() )
EOF_TRANS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}
diff --git a/ragel/cdfgoto.cpp b/ragel/cdfgoto.cpp
index 6c98ddb6..28a8ba7e 100644
--- a/ragel/cdfgoto.cpp
+++ b/ragel/cdfgoto.cpp
@@ -152,6 +152,8 @@ unsigned int FGotoCodeGen::EOF_ACTION( RedStateAp *state )
std::ostream &FGotoCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -172,11 +174,17 @@ std::ostream &FGotoCodeGen::TO_STATE_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FGotoCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -197,11 +205,17 @@ std::ostream &FGotoCodeGen::FROM_STATE_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FGotoCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -222,32 +236,24 @@ std::ostream &FGotoCodeGen::EOF_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
void FGotoCodeGen::writeData()
{
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}
diff --git a/ragel/cdflat.cpp b/ragel/cdflat.cpp
index 606c7f43..557ec9a9 100644
--- a/ragel/cdflat.cpp
+++ b/ragel/cdflat.cpp
@@ -31,7 +31,7 @@ std::ostream &FlatCodeGen::TO_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->toStateAction != 0 )
act = state->toStateAction->location+1;
- out << act;
+ taTSA.VAL( act );
return out;
}
@@ -40,7 +40,7 @@ std::ostream &FlatCodeGen::FROM_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->fromStateAction != 0 )
act = state->fromStateAction->location+1;
- out << act;
+ taFSA.VAL( act );
return out;
}
@@ -49,7 +49,7 @@ std::ostream &FlatCodeGen::EOF_ACTION( RedStateAp *state )
int act = 0;
if ( state->eofAction != 0 )
act = state->eofAction->location+1;
- out << act;
+ taEA.VAL( act );
return out;
}
@@ -59,7 +59,7 @@ std::ostream &FlatCodeGen::TRANS_ACTION( RedTransAp *trans )
int act = 0;
if ( trans->action != 0 )
act = trans->action->location+1;
- out << act;
+ taTA.VAL( act );
return out;
}
@@ -191,6 +191,8 @@ std::ostream &FlatCodeGen::KEY_SPANS()
std::ostream &FlatCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -203,11 +205,17 @@ std::ostream &FlatCodeGen::TO_STATE_ACTIONS()
}
}
out << "\n";
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FlatCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -220,11 +228,17 @@ std::ostream &FlatCodeGen::FROM_STATE_ACTIONS()
}
}
out << "\n";
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FlatCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -237,11 +251,17 @@ std::ostream &FlatCodeGen::EOF_ACTIONS()
}
}
out << "\n";
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FlatCodeGen::EOF_TRANS()
{
+ taET.OPEN( ARRAY_TYPE(redFsm->maxIndexOffset+1) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -252,7 +272,7 @@ std::ostream &FlatCodeGen::EOF_TRANS()
assert( st->eofTrans->pos >= 0 );
trans = st->eofTrans->pos+1;
}
- out << trans;
+ taET.VAL( trans );
if ( !st.last() ) {
out << ", ";
@@ -261,13 +281,17 @@ std::ostream &FlatCodeGen::EOF_TRANS()
}
}
out << "\n";
+
+ taET.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FlatCodeGen::COND_KEYS()
{
- OPEN_ARRAY( WIDE_ALPH_TYPE(), CK() );
+ taCK.OPEN( WIDE_ALPH_TYPE() );
out << '\t';
int totalTrans = 0;
@@ -286,8 +310,8 @@ std::ostream &FlatCodeGen::COND_KEYS()
taCK.KEY ( 0 );
out << "\n";
- CLOSE_ARRAY() <<
- "\n";
+ taCK.CLOSE();
+ out << "\n";
return out;
}
@@ -481,6 +505,8 @@ std::ostream &FlatCodeGen::TRANS_TARGS()
std::ostream &FlatCodeGen::TRANS_ACTIONS()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Transitions must be written ordered by their id. */
RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
@@ -501,6 +527,10 @@ std::ostream &FlatCodeGen::TRANS_ACTIONS()
}
out << "\n";
delete[] transPtrs;
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
@@ -626,40 +656,20 @@ void FlatCodeGen::writeData()
TRANS_TARGS();
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofTrans() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() );
+ if ( redFsm->anyEofTrans() )
EOF_TRANS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}
diff --git a/ragel/cdftable.cpp b/ragel/cdftable.cpp
index 60120008..f4bde0bf 100644
--- a/ragel/cdftable.cpp
+++ b/ragel/cdftable.cpp
@@ -59,7 +59,7 @@ std::ostream &FTabCodeGen::TO_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->toStateAction != 0 )
act = state->toStateAction->actListId+1;
- out << act;
+ taTSA.VAL( act );
return out;
}
@@ -68,7 +68,7 @@ std::ostream &FTabCodeGen::FROM_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->fromStateAction != 0 )
act = state->fromStateAction->actListId+1;
- out << act;
+ taFSA.VAL( act );
return out;
}
@@ -77,7 +77,7 @@ std::ostream &FTabCodeGen::EOF_ACTION( RedStateAp *state )
int act = 0;
if ( state->eofAction != 0 )
act = state->eofAction->actListId+1;
- out << act;
+ taEA.VAL( act );
return out;
}
@@ -88,7 +88,7 @@ std::ostream &FTabCodeGen::TRANS_ACTION( RedTransAp *trans )
int action = 0;
if ( trans->action != 0 )
action = trans->action->actListId+1;
- out << action;
+ taTA.VAL( action );
return out;
}
@@ -180,6 +180,8 @@ std::ostream &FTabCodeGen::ACTION_SWITCH()
std::ostream &FTabCodeGen::TRANS_ACTIONS()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActListId) );
+
int totalTrans = 0;
out << '\t';
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -221,12 +223,19 @@ std::ostream &FTabCodeGen::TRANS_ACTIONS()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taTA.VAL( 0 );
+ out << "\n";
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FTabCodeGen::TRANS_ACTIONS_WI()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActListId) );
+
/* Transitions must be written ordered by their id. */
RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
@@ -247,12 +256,18 @@ std::ostream &FTabCodeGen::TRANS_ACTIONS_WI()
}
out << "\n";
delete[] transPtrs;
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FTabCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -265,11 +280,17 @@ std::ostream &FTabCodeGen::TO_STATE_ACTIONS()
}
}
out << "\n";
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FTabCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -282,11 +303,17 @@ std::ostream &FTabCodeGen::FROM_STATE_ACTIONS()
}
}
out << "\n";
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &FTabCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActListId) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -299,6 +326,10 @@ std::ostream &FTabCodeGen::EOF_ACTIONS()
}
}
out << "\n";
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
@@ -320,64 +351,31 @@ void FTabCodeGen::writeData()
INDEX_OFFSETS();
if ( useIndicies ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS_WI();
- CLOSE_ARRAY() <<
- "\n";
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS_WI();
- CLOSE_ARRAY() <<
- "\n";
- }
}
else {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
- CLOSE_ARRAY() <<
- "\n";
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
}
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActListId), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofTrans() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() );
+ if ( redFsm->anyEofTrans() )
EOF_TRANS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}
diff --git a/ragel/cdgoto.cpp b/ragel/cdgoto.cpp
index 4eebc61e..a67af285 100644
--- a/ragel/cdgoto.cpp
+++ b/ragel/cdgoto.cpp
@@ -452,6 +452,8 @@ unsigned int GotoCodeGen::EOF_ACTION( RedStateAp *state )
std::ostream &GotoCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -472,11 +474,17 @@ std::ostream &GotoCodeGen::TO_STATE_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &GotoCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -497,11 +505,17 @@ std::ostream &GotoCodeGen::FROM_STATE_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &GotoCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Take one off for the psuedo start state. */
int numStates = redFsm->stateList.length();
unsigned int *vals = new unsigned int[numStates];
@@ -522,6 +536,10 @@ std::ostream &GotoCodeGen::EOF_ACTIONS()
}
out << "\n";
delete[] vals;
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
@@ -629,26 +647,14 @@ void GotoCodeGen::writeData()
if ( redFsm->anyActions() )
ACTIONS_ARRAY();
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}
diff --git a/ragel/cdtable.cpp b/ragel/cdtable.cpp
index ade15522..ac1c94fd 100644
--- a/ragel/cdtable.cpp
+++ b/ragel/cdtable.cpp
@@ -59,7 +59,7 @@ std::ostream &TabCodeGen::TO_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->toStateAction != 0 )
act = state->toStateAction->location+1;
- out << act;
+ taTSA.VAL( act );
return out;
}
@@ -68,7 +68,7 @@ std::ostream &TabCodeGen::FROM_STATE_ACTION( RedStateAp *state )
int act = 0;
if ( state->fromStateAction != 0 )
act = state->fromStateAction->location+1;
- out << act;
+ taFSA.VAL( act );
return out;
}
@@ -77,7 +77,7 @@ std::ostream &TabCodeGen::EOF_ACTION( RedStateAp *state )
int act = 0;
if ( state->eofAction != 0 )
act = state->eofAction->location+1;
- out << act;
+ taEA.VAL( act );
return out;
}
@@ -88,7 +88,7 @@ std::ostream &TabCodeGen::TRANS_ACTION( RedTransAp *trans )
int act = 0;
if ( trans->action != 0 )
act = trans->action->location+1;
- out << act;
+ taTA.VAL( act );
return out;
}
@@ -311,6 +311,8 @@ std::ostream &TabCodeGen::RANGE_LENS()
std::ostream &TabCodeGen::TO_STATE_ACTIONS()
{
+ taTSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -323,11 +325,17 @@ std::ostream &TabCodeGen::TO_STATE_ACTIONS()
}
}
out << "\n";
+
+ taTSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::FROM_STATE_ACTIONS()
{
+ taFSA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -340,11 +348,17 @@ std::ostream &TabCodeGen::FROM_STATE_ACTIONS()
}
}
out << "\n";
+
+ taFSA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::EOF_ACTIONS()
{
+ taEA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -357,11 +371,17 @@ std::ostream &TabCodeGen::EOF_ACTIONS()
}
}
out << "\n";
+
+ taEA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::EOF_TRANS()
{
+ taET.OPEN( ARRAY_TYPE(redFsm->maxIndexOffset+1) );
+
out << "\t";
int totalStateNum = 0;
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -380,6 +400,9 @@ std::ostream &TabCodeGen::EOF_TRANS()
}
}
out << "\n";
+
+ taET.CLOSE();
+ out << "\n";
return out;
}
@@ -488,26 +511,31 @@ std::ostream &TabCodeGen::KEYS()
std::ostream &TabCodeGen::INDICIES()
{
+ taI.OPEN( ARRAY_TYPE(redFsm->maxIndex) );
+
int totalTrans = 0;
out << '\t';
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Walk the singles. */
for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
- out << stel->value->id << ", ";
+ taI.VAL( stel->value->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
/* Walk the ranges. */
for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- out << rtel->value->id << ", ";
+ taI.VAL( rtel->value->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
/* The state's default index goes next. */
if ( st->defTrans != 0 ) {
- out << st->defTrans->id << ", ";
+ taI.VAL( st->defTrans->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -515,19 +543,26 @@ std::ostream &TabCodeGen::INDICIES()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taI.VAL( 0 );
+ out << "\n";
+
+ taI.CLOSE();
+ out << "\n";
return out;
}
std::ostream &TabCodeGen::TRANS_TARGS()
{
+ taTT.OPEN( ARRAY_TYPE(redFsm->maxState) );
+
int totalTrans = 0;
out << '\t';
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
/* Walk the singles. */
for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
RedTransAp *trans = stel->value;
- out << trans->targ->id << ", ";
+ taTT.VAL( trans->targ->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -535,7 +570,8 @@ std::ostream &TabCodeGen::TRANS_TARGS()
/* Walk the ranges. */
for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
RedTransAp *trans = rtel->value;
- out << trans->targ->id << ", ";
+ taTT.VAL( trans->targ->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -543,7 +579,8 @@ std::ostream &TabCodeGen::TRANS_TARGS()
/* The state's default target state. */
if ( st->defTrans != 0 ) {
RedTransAp *trans = st->defTrans;
- out << trans->targ->id << ", ";
+ taTT.VAL( trans->targ->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
@@ -554,22 +591,29 @@ std::ostream &TabCodeGen::TRANS_TARGS()
if ( st->eofTrans != 0 ) {
RedTransAp *trans = st->eofTrans;
trans->pos = totalTrans;
- out << trans->targ->id << ", ";
+ taTT.VAL( trans->targ->id );
+ out << ", ";
if ( ++totalTrans % IALL == 0 )
out << "\n\t";
}
}
-
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
- out << 0 << "\n";
+ taTT.VAL( 0 );
+ out << "\n";
+
+ taTT.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::TRANS_ACTIONS()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
int totalTrans = 0;
out << '\t';
for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
@@ -612,11 +656,17 @@ std::ostream &TabCodeGen::TRANS_ACTIONS()
/* Output one last number so we don't have to figure out when the last
* entry is and avoid writing a comma. */
out << 0 << "\n";
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::TRANS_TARGS_WI()
{
+ taTT.OPEN( ARRAY_TYPE(redFsm->maxState) );
+
/* Transitions must be written ordered by their id. */
RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
@@ -631,7 +681,7 @@ std::ostream &TabCodeGen::TRANS_TARGS_WI()
trans->pos = t;
/* Write out the target state. */
- out << trans->targ->id;
+ taTT.VAL( trans->targ->id );
if ( t < redFsm->transSet.length()-1 ) {
out << ", ";
if ( ++totalStates % IALL == 0 )
@@ -640,12 +690,18 @@ std::ostream &TabCodeGen::TRANS_TARGS_WI()
}
out << "\n";
delete[] transPtrs;
+
+ taTT.CLOSE();
+ out << "\n";
+
return out;
}
std::ostream &TabCodeGen::TRANS_ACTIONS_WI()
{
+ taTA.OPEN( ARRAY_TYPE(redFsm->maxActionLoc) );
+
/* Transitions must be written ordered by their id. */
RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
@@ -666,6 +722,10 @@ std::ostream &TabCodeGen::TRANS_ACTIONS_WI()
}
out << "\n";
delete[] transPtrs;
+
+ taTA.CLOSE();
+ out << "\n";
+
return out;
}
@@ -831,64 +891,31 @@ void TabCodeGen::writeData()
INDEX_OFFSETS();
if ( useIndicies ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndex), I() );
INDICIES();
- CLOSE_ARRAY() <<
- "\n";
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS_WI();
- CLOSE_ARRAY() <<
- "\n";
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS_WI();
- CLOSE_ARRAY() <<
- "\n";
- }
}
else {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxState), TT() );
TRANS_TARGS();
- CLOSE_ARRAY() <<
- "\n";
- if ( redFsm->anyActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TA() );
+ if ( redFsm->anyActions() )
TRANS_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
}
- if ( redFsm->anyToStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), TSA() );
+ if ( redFsm->anyToStateActions() )
TO_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyFromStateActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), FSA() );
+ if ( redFsm->anyFromStateActions() )
FROM_STATE_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofActions() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxActionLoc), EA() );
+ if ( redFsm->anyEofActions() )
EOF_ACTIONS();
- CLOSE_ARRAY() <<
- "\n";
- }
- if ( redFsm->anyEofTrans() ) {
- OPEN_ARRAY( ARRAY_TYPE(redFsm->maxIndexOffset+1), ET() );
+ if ( redFsm->anyEofTrans() )
EOF_TRANS();
- CLOSE_ARRAY() <<
- "\n";
- }
STATE_IDS();
}