summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2020-03-16 09:07:42 +0200
committerAdrian Thurston <thurston@colm.net>2020-03-16 09:07:58 +0200
commit2b9836a94c27b6be724677fc415dc6544e7f3276 (patch)
tree93b0747de95d5f4af56fcda4d6ea37e4657b9d93
parentbd3557e33f4281c021266829f3ef693e13160178 (diff)
downloadragel-2b9836a94c27b6be724677fc415dc6544e7f3276.tar.gz
removal of libfsm files and adjusting includes files
-rw-r--r--src/Makefile.am4
-rw-r--r--src/actexp.h62
-rw-r--r--src/action.h116
-rw-r--r--src/actloop.h63
-rw-r--r--src/asm.h248
-rw-r--r--src/binary.cc819
-rw-r--r--src/binary.h98
-rw-r--r--src/binbreak.cc132
-rw-r--r--src/binbreak.h71
-rw-r--r--src/bingoto.cc131
-rw-r--r--src/bingoto.h71
-rw-r--r--src/binvar.cc139
-rw-r--r--src/binvar.h72
-rw-r--r--src/codegen.h459
-rw-r--r--src/common.h504
-rw-r--r--src/dot.cc399
-rw-r--r--src/dot.h53
-rw-r--r--src/flat.cc576
-rw-r--r--src/flat.h94
-rw-r--r--src/flatbreak.cc118
-rw-r--r--src/flatbreak.h72
-rw-r--r--src/flatgoto.cc118
-rw-r--r--src/flatgoto.h72
-rw-r--r--src/flatvar.cc119
-rw-r--r--src/flatvar.h70
-rw-r--r--src/fsmgraph.h2541
-rw-r--r--src/gendata.h477
-rw-r--r--src/goto.cc978
-rw-r--r--src/goto.h226
-rw-r--r--src/gotoexp.cc208
-rw-r--r--src/gotoexp.h75
-rw-r--r--src/gotoloop.cc227
-rw-r--r--src/gotoloop.h72
-rw-r--r--src/host-asm/main.cc2
-rw-r--r--src/inputdata.cc4
-rw-r--r--src/inputdata.h2
-rw-r--r--src/ipgoto.h129
-rw-r--r--src/load.cc2
-rw-r--r--src/load.h2
-rw-r--r--src/longest.cc2
-rw-r--r--src/parsedata.cc2
-rw-r--r--src/parsedata.h6
-rw-r--r--src/parsetree.cc4
-rw-r--r--src/parsetree.h4
-rw-r--r--src/ragel.h108
-rw-r--r--src/redfsm.h889
-rw-r--r--src/switch.cc1036
-rw-r--r--src/switch.h106
-rw-r--r--src/switchbreak.cc75
-rw-r--r--src/switchbreak.h70
-rw-r--r--src/switchgoto.cc73
-rw-r--r--src/switchgoto.h70
-rw-r--r--src/switchvar.cc77
-rw-r--r--src/switchvar.h72
-rw-r--r--src/tables.h265
55 files changed, 15 insertions, 12469 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ff642072..f654674f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,10 +16,6 @@ lib_LTLIBRARIES = libragel.la
bin_PROGRAMS = ragel
-pkginclude_HEADERS = \
- action.h fsmgraph.h ragel.h common.h \
- gendata.h redfsm.h dot.h
-
# nodist_pkginclude_HEADERS = config.h
data_DATA = ragel.lm
diff --git a/src/actexp.h b/src/actexp.h
deleted file mode 100644
index 49165755..00000000
--- a/src/actexp.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _BINEXP_H
-#define _BINEXP_H
-
-#include "binary.h"
-
-struct RedStateAp;
-struct RedCondPair;
-
-class ActExp
- : public virtual Tables
-{
-public:
- ActExp( const CodeGenArgs &args )
- :
- Tables( args )
- {}
-
- virtual void FROM_STATE_ACTION( RedStateAp *state );
- virtual void COND_ACTION( RedCondPair *cond );
- virtual void TO_STATE_ACTION( RedStateAp *state );
- virtual void EOF_ACTION( RedStateAp *state );
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ );
- virtual void NFA_POP_TEST( RedNfaTarg *targ );
-
- virtual std::ostream &FROM_STATE_ACTION_SWITCH();
- virtual std::ostream &ACTION_SWITCH();
- virtual std::ostream &TO_STATE_ACTION_SWITCH();
- virtual std::ostream &EOF_ACTION_SWITCH();
-
- virtual void TO_STATE_ACTIONS();
- virtual void REG_ACTIONS( std::string cond );
- virtual void FROM_STATE_ACTIONS();
- virtual void EOF_ACTIONS();
-
- virtual void NFA_FROM_STATE_ACTION_EXEC();
-};
-
-#endif
-
diff --git a/src/action.h b/src/action.h
deleted file mode 100644
index 39169202..00000000
--- a/src/action.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _ACTION_H
-#define _ACTION_H
-
-#include "fsmgraph.h"
-
-struct NameInst;
-struct NameRef;
-struct LongestMatch;
-struct InlineList;
-
-/*
- * Inline code tree
- */
-struct InlineItem
-{
- enum Type
- {
- Text, Goto, Call, Ncall, Next, GotoExpr, CallExpr, NcallExpr, NextExpr, Ret, Nret,
- PChar, Char, Hold, Curs, Targs, Entry, Exec, Break, Nbreak,
- LmSwitch, LmSetActId, LmSetTokEnd, LmOnLast, LmOnNext, LmOnLagBehind,
- LmInitAct, LmInitTokStart, LmSetTokStart, LmNfaOnNext, LmNfaOnLast, LmNfaOnEof, Stmt, Subst,
- NfaWrapAction, NfaWrapConds
- };
-
- InlineItem( const InputLoc &loc, std::string data, Type type ) :
- loc(loc), data(data), nameRef(0), children(0), type(type) { }
-
- InlineItem( const InputLoc &loc, NameRef *nameRef, Type type ) :
- loc(loc), nameRef(nameRef), children(0), type(type) { }
-
- InlineItem( const InputLoc &loc, LongestMatch *longestMatch,
- LongestMatchPart *longestMatchPart, Type type ) : loc(loc),
- nameRef(0), children(0), longestMatch(longestMatch),
- longestMatchPart(longestMatchPart), type(type) { }
-
- InlineItem( const InputLoc &loc, NameInst *nameTarg, Type type ) :
- loc(loc), nameRef(0), nameTarg(nameTarg), children(0),
- type(type) { }
-
- InlineItem( const InputLoc &loc, Type type ) :
- loc(loc), nameRef(0), children(0), type(type) { }
-
- InlineItem( const InputLoc &loc, Action *wrappedAction, Type type )
- :
- loc(loc), nameRef(0), children(0), longestMatch(0),
- longestMatchPart(0), wrappedAction(wrappedAction), type(type)
- {}
-
- InlineItem( const InputLoc &loc, CondSpace *condSpace,
- const CondKeySet &condKeySet, Type type )
- :
- loc(loc), nameRef(0), children(0), longestMatch(0),
- longestMatchPart(0), wrappedAction(0), condSpace(condSpace),
- condKeySet(condKeySet), type(type)
- {}
-
- ~InlineItem();
-
- InputLoc loc;
- std::string data;
- NameRef *nameRef;
- NameInst *nameTarg;
- InlineList *children;
- LongestMatch *longestMatch;
- LongestMatchPart *longestMatchPart;
- long substPos;
- Action *wrappedAction;
- CondSpace *condSpace;
- CondKeySet condKeySet;
- Type type;
-
- InlineItem *prev, *next;
-};
-
-/* Normally this would be atypedef, but that would entail including DList from
- * ptreetypes, which should be just typedef forwards. */
-struct InlineList : public DList<InlineItem> { };
-
-struct InlineBlock
-{
- InlineBlock( const InputLoc &loc, InlineList *inlineList )
- : loc(loc), inlineList(inlineList) {}
-
- ~InlineBlock()
- {
- inlineList->empty();
- delete inlineList;
- }
-
- InputLoc loc;
- InlineList *inlineList;
-};
-
-#endif
diff --git a/src/actloop.h b/src/actloop.h
deleted file mode 100644
index 238ba72a..00000000
--- a/src/actloop.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _BINLOOP_H
-#define _BINLOOP_H
-
-#include "binary.h"
-#include "tables.h"
-
-struct RedStateAp;
-struct RedCondPair;
-
-class ActLoop
- : public virtual Tables
-{
-public:
- ActLoop( const CodeGenArgs &args )
- :
- Tables( args )
- {}
-
- virtual void FROM_STATE_ACTION( RedStateAp *state );
- virtual void COND_ACTION( RedCondPair *cond );
- virtual void TO_STATE_ACTION( RedStateAp *state );
- virtual void EOF_ACTION( RedStateAp *state );
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ );
- virtual void NFA_POP_TEST( RedNfaTarg *targ );
-
- virtual std::ostream &FROM_STATE_ACTION_SWITCH();
- virtual std::ostream &ACTION_SWITCH();
- virtual std::ostream &TO_STATE_ACTION_SWITCH();
- virtual std::ostream &EOF_ACTION_SWITCH();
-
- virtual void FROM_STATE_ACTIONS();
- virtual void REG_ACTIONS( std::string cond );
- virtual void TO_STATE_ACTIONS();
- virtual void EOF_ACTIONS();
-
- virtual void NFA_FROM_STATE_ACTION_EXEC();
-};
-
-
-#endif
diff --git a/src/asm.h b/src/asm.h
deleted file mode 100644
index 3b4229d4..00000000
--- a/src/asm.h
+++ /dev/null
@@ -1,248 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _ASM_H
-#define _ASM_H
-
-#include <iostream>
-#include <string>
-#include <iomanip>
-#include <stdio.h>
-
-#include "common.h"
-#include "gendata.h"
-#include "ragel.h"
-
-using std::string;
-using std::ostream;
-
-/* Integer array line length. */
-#define IALL_INTEGRAL 8
-#define IALL_STRING 128
-
-/* Forwards. */
-struct RedFsmAp;
-struct RedStateAp;
-struct CodeGenData;
-struct GenAction;
-struct NameInst;
-struct GenInlineItem;
-struct GenInlineList;
-struct RedAction;
-struct LongestMatch;
-struct LongestMatchPart;
-class AsmCodeGen;
-struct RedTransAp;
-struct RedStateAp;
-struct GenStateCond;
-
-string itoa( int i );
-
-/*
- * class AsmCodeGen
- */
-class AsmCodeGen : public CodeGenData
-{
-public:
- AsmCodeGen( const CodeGenArgs &args );
- virtual ~AsmCodeGen() {}
-
- virtual void writeInit();
- virtual void writeStart();
- virtual void writeFirstFinal();
- virtual void writeError();
-
- virtual void statsSummary() {}
- virtual void genAnalysis();
-
-protected:
- string FSM_NAME();
- string START_STATE_ID();
- string KEY( Key key );
- string COND_KEY( CondKey key );
- string LDIR_PATH( char *path );
- virtual void ACTION( ostream &ret, GenAction *action, int targState,
- bool inFinish, bool csForced );
- void CONDITION( ostream &ret, GenAction *condition );
- void NFA_CONDITION( ostream &ret, GenAction *condition, bool last );
- string ALPH_TYPE();
-
- bool isAlphTypeSigned();
-
- string GET_KEY();
-
- string P();
- string PE();
- string vEOF();
- string NBREAK();
-
- string ACCESS();
- string vCS();
- string STACK();
- string TOP();
- string TOKSTART();
- string TOKEND();
- string ACT();
-
- string NFA_STACK();
- string NFA_TOP();
- string NFA_SZ();
-
- string DATA_PREFIX();
- string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
- string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
- string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
- string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
- string I() { return "_" + DATA_PREFIX() + "indices"; }
- string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
- string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
- string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
- string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
- string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
- string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
- string A() { return "_" + DATA_PREFIX() + "actions"; }
- string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
- string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
- string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
- string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
- string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
- string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
- string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
- string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
- string START() { return DATA_PREFIX() + "start"; }
- string ERROR() { return DATA_PREFIX() + "error"; }
- string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
- string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
-
- string LABEL( const char *type, long i );
- string LABEL( const char *name );
-
- void INLINE_LIST( ostream &ret, GenInlineList *inlineList,
- int targState, bool inFinish, bool csForced );
- void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
- void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState,
- int inFinish, bool csForced );
- void SET_ACT( ostream &ret, GenInlineItem *item );
- void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
- void INIT_ACT( ostream &ret, GenInlineItem *item );
- void SET_TOKSTART( ostream &ret, GenInlineItem *item );
- void SET_TOKEND( ostream &ret, GenInlineItem *item );
- void GET_TOKEND( ostream &ret, GenInlineItem *item );
- void STATIC_CONST_INT( const string &name, const string &val );
- void STATE_IDS();
-
- string ERROR_STATE();
- string FIRST_FINAL_STATE();
-
- bool outLabelUsed;
- bool testEofUsed;
- bool againLabelUsed;
- long nextLmSwitchLabel;
- bool stackCS;
-
- void NBREAK( ostream &ret, int targState, bool csForced );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
-
- void HOST_STMT( ostream &ret, GenInlineItem *item,
- int targState, bool inFinish, bool csForced );
- void HOST_EXPR( ostream &ret, GenInlineItem *item,
- int targState, bool inFinish, bool csForced );
- void HOST_TEXT( ostream &ret, GenInlineItem *item,
- int targState, bool inFinish, bool csForced );
- void GEN_STMT( ostream &ret, GenInlineItem *item,
- int targState, bool inFinish, bool csForced );
- void GEN_EXPR( ostream &ret, GenInlineItem *item,
- int targState, bool inFinish, bool csForced );
-
-public:
-
- virtual string NULL_ITEM();
- virtual string POINTER();
- virtual ostream &SWITCH_DEFAULT();
- virtual ostream &OPEN_ARRAY( string type, string name );
- virtual ostream &CLOSE_ARRAY();
- virtual ostream &STATIC_VAR( string type, string name );
- virtual string ARR_OFF( string ptr, string offset );
- virtual string CAST( string type );
- virtual string UINT();
- virtual string PTR_CONST();
- virtual string PTR_CONST_END();
- virtual string CTRL_FLOW();
-
- virtual void writeExports();
-
- unsigned int TO_STATE_ACTION( RedStateAp *state );
- unsigned int FROM_STATE_ACTION( RedStateAp *state );
- unsigned int EOF_ACTION( RedStateAp *state );
-
- void COND_TRANSLATE( GenStateCond *stateCond );
- void STATE_CONDS( RedStateAp *state, bool genDefault );
-
- std::ostream &EXIT_STATES();
- std::string TRANS_GOTO_TARG( RedTransAp *trans );
- std::string TRANS_GOTO_TARG( RedCondPair *pair );
- std::ostream &TRANS_GOTO( RedTransAp *trans );
- std::ostream &AGAIN_CASES();
- std::ostream &FINISH_CASES();
- std::ostream &ENTRY_CASES();
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NEXT( ostream &ret, int nextDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void RET( ostream &ret, bool inFinish );
- void CURS( ostream &ret, bool inFinish );
- void TARGS( ostream &ret, bool inFinish, int targState );
- void BREAK( ostream &ret, int targState, bool csForced );
- void LM_EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
-
- virtual void writeData();
- virtual void writeExec();
-
- bool useAgainLabel();
-
- void NFA_PUSH( RedStateAp *state );
- bool IN_TRANS_ACTIONS( RedStateAp *state );
- void STATE_GOTOS();
-
- void emitSingleIfElseIf( RedStateAp *state );
- void emitSingleJumpTable( RedStateAp *state, std::string def );
- void emitRangeBSearch( RedStateAp *state, int low, int high );
- void emitCharClassIfElseIf( RedStateAp *state );
- void emitCharClassJumpTable( RedStateAp *state, std::string def );
-
- /* Set up labelNeeded flag for each state. */
- void setLabelsNeeded( RedCondPair *pair );
- void setLabelsNeeded( GenInlineList *inlineList );
- void setLabelsNeeded();
-
- void setNfaIds();
-
- void genOutputLineDirective( ostream &out ) {}
- void genLineDirective( ostream &out, int line, const char *file ) {}
-};
-
-#endif
diff --git a/src/binary.cc b/src/binary.cc
deleted file mode 100644
index 39b58a47..00000000
--- a/src/binary.cc
+++ /dev/null
@@ -1,819 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "binary.h"
-#include "redfsm.h"
-#include "gendata.h"
-
-#include <assert.h>
-
-void Binary::genAnalysis()
-{
- redFsm->sortByStateId();
-
- /* Choose default transitions and the single transition. */
- redFsm->chooseDefaultSpan();
-
- /* Choose the singles. */
- redFsm->moveSelectTransToSingle();
-
- if ( redFsm->errState != 0 )
- redFsm->getErrorCond();
-
- /* If any errors have occured in the input file then don't write anything. */
- if ( red->id->errorCount > 0 )
- return;
-
- /* Anlayze Machine will find the final action reference counts, among other
- * things. We will use these in reporting the usage of fsm directives in
- * action code. */
- red->analyzeMachine();
-
- setKeyType();
-
- /* Run the analysis pass over the table data. */
- setTableState( TableArray::AnalyzePass );
- tableDataPass();
-
- /* Switch the tables over to the code gen mode. */
- setTableState( TableArray::GeneratePass );
-}
-
-
-void Binary::tableDataPass()
-{
- if ( type == Loop )
- taActions();
-
- taKeyOffsets();
- taSingleLens();
- taRangeLens();
- taIndexOffsets();
- taIndices();
-
- taTransCondSpacesWi();
- taTransOffsetsWi();
- taTransLengthsWi();
-
- taTransCondSpaces();
- taTransOffsets();
- taTransLengths();
-
- taCondTargs();
- taCondActions();
-
- taToStateActions();
- taFromStateActions();
- taEofActions();
- taEofConds();
- taEofTrans();
-
- taKeys();
- taCondKeys();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-}
-
-void Binary::writeData()
-{
- if ( type == Loop ) {
- /* If there are any transtion functions then output the array. If there
- * are none, don't bother emitting an empty array that won't be used. */
- if ( redFsm->anyActions() )
- taActions();
- }
-
- taKeyOffsets();
- taKeys();
- taSingleLens();
- taRangeLens();
- taIndexOffsets();
-
- taTransCondSpaces();
- taTransOffsets();
- taTransLengths();
-
- taCondKeys();
- taCondTargs();
- taCondActions();
-
- if ( redFsm->anyToStateActions() )
- taToStateActions();
-
- if ( redFsm->anyFromStateActions() )
- taFromStateActions();
-
- if ( redFsm->anyEofActions() )
- taEofActions();
-
- taEofConds();
-
- if ( redFsm->anyEofTrans() )
- taEofTrans();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-
- STATE_IDS();
-}
-
-
-void Binary::setKeyType()
-{
- transKeys.setType( ALPH_TYPE(), alphType->size, alphType->isChar );
- transKeys.isSigned = keyOps->isSigned;
-}
-
-void Binary::setTableState( TableArray::State state )
-{
- for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) {
- TableArray *tableArray = *i;
- tableArray->setState( state );
- }
-}
-
-void Binary::taKeyOffsets()
-{
- keyOffsets.start();
-
- int curKeyOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- keyOffsets.value( curKeyOffset );
- curKeyOffset += st->outSingle.length() + st->outRange.length()*2;
- }
-
- keyOffsets.finish();
-}
-
-
-void Binary::taSingleLens()
-{
- singleLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- singleLens.value( st->outSingle.length() );
-
- singleLens.finish();
-}
-
-
-void Binary::taRangeLens()
-{
- rangeLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- rangeLens.value( st->outRange.length() );
-
- rangeLens.finish();
-}
-
-void Binary::taIndexOffsets()
-{
- indexOffsets.start();
-
- int curIndOffset = 0;
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write the index offset. */
- indexOffsets.value( curIndOffset );
-
- /* Move the index offset ahead. */
- curIndOffset += st->outSingle.length() + st->outRange.length();
- if ( st->defTrans != 0 )
- curIndOffset += 1;
- }
-
- indexOffsets.finish();
-}
-
-void Binary::taToStateActions()
-{
- toStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- TO_STATE_ACTION(st);
-
- toStateActions.finish();
-}
-
-void Binary::taFromStateActions()
-{
- fromStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- FROM_STATE_ACTION(st);
-
- fromStateActions.finish();
-}
-
-void Binary::taEofActions()
-{
- eofActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- EOF_ACTION( st );
-
- eofActions.finish();
-}
-
-void Binary::taEofConds()
-{
- /*
- * EOF Cond Spaces
- */
- eofCondSpaces.start();
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 )
- eofCondSpaces.value( st->outCondSpace->condSpaceId );
- else
- eofCondSpaces.value( -1 );
- }
- eofCondSpaces.finish();
-
- /*
- * EOF Cond Key Indixes
- */
- eofCondKeyOffs.start();
-
- int curOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long off = 0;
- if ( st->outCondSpace != 0 ) {
- off = curOffset;
- curOffset += st->outCondKeys.length();
- }
- eofCondKeyOffs.value( off );
- }
-
- eofCondKeyOffs.finish();
-
- /*
- * EOF Cond Key Lengths.
- */
- eofCondKeyLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long len = 0;
- if ( st->outCondSpace != 0 )
- len = st->outCondKeys.length();
- eofCondKeyLens.value( len );
- }
-
- eofCondKeyLens.finish();
-
- /*
- * EOF Cond Keys
- */
- eofCondKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 ) {
- for ( int c = 0; c < st->outCondKeys.length(); c++ ) {
- CondKey key = st->outCondKeys[c];
- eofCondKeys.value( key.getVal() );
- }
- }
- }
-
- eofCondKeys.finish();
-}
-
-void Binary::taEofTrans()
-{
- eofTrans.start();
-
- /* Need to compute transition positions. */
- int totalTrans = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- totalTrans += st->outSingle.length();
- totalTrans += st->outRange.length();
- if ( st->defTrans != 0 )
- totalTrans += 1;
- }
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long trans = 0;
- if ( st->eofTrans != 0 ) {
- trans = totalTrans + 1;
- totalTrans += 1;
- }
-
- eofTrans.value( trans );
- }
-
- eofTrans.finish();
-}
-
-void Binary::taKeys()
-{
- transKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Loop the singles. */
- for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
- transKeys.value( stel->lowKey.getVal() );
- }
-
- /* Loop the state's transitions. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- /* Lower key. */
- transKeys.value( rtel->lowKey.getVal() );
-
- /* Upper key. */
- transKeys.value( rtel->highKey.getVal() );
- }
- }
-
- transKeys.finish();
-}
-
-void Binary::taIndices()
-{
- indices.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Walk the singles. */
- for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ )
- indices.value( stel->value->id );
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ )
- indices.value( rtel->value->id );
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 )
- indices.value( st->defTrans->id );
- }
-
- indices.finish();
-}
-
-void Binary::taTransCondSpaces()
-{
- transCondSpaces.start();
-
- 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;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
- }
-
- transCondSpaces.finish();
-}
-
-void Binary::taTransOffsets()
-{
- transOffsets.start();
-
- int curOffset = 0;
- 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;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
- }
-
- errCondOffset = curOffset;
-
- transOffsets.finish();
-}
-
-void Binary::taTransLengths()
-{
- transLengths.start();
-
- 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;
- transLengths.value( trans->numConds() );
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- transLengths.value( trans->numConds() );
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- transLengths.value( trans->numConds() );
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- transLengths.value( trans->numConds() );
- }
- }
-
- transLengths.finish();
-}
-
-void Binary::taTransCondSpacesWi()
-{
- transCondSpacesWi.start();
-
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- /* Cond Space id. */
- if ( trans->condSpace != 0 )
- transCondSpacesWi.value( trans->condSpace->condSpaceId );
- else
- transCondSpacesWi.value( -1 );
- }
-
- transCondSpacesWi.finish();
-}
-
-void Binary::taTransOffsetsWi()
-{
- transOffsetsWi.start();
-
- int curOffset = 0;
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- transOffsetsWi.value( curOffset );
-
- TransApSet::Iter next = trans;
- next.increment();
-
- curOffset += trans->numConds();
- }
-
- transOffsetsWi.finish();
-}
-
-void Binary::taTransLengthsWi()
-{
- transLengthsWi.start();
-
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- transLengthsWi.value( trans->numConds() );
-
- TransApSet::Iter next = trans;
- next.increment();
- }
-
- transLengthsWi.finish();
-}
-
-void Binary::taCondKeys()
-{
- condKeys.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
- }
-
- condKeys.finish();
-}
-
-void Binary::taCondTargs()
-{
- condTargs.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
- }
-
- if ( redFsm->errCond != 0 ) {
- RedCondPair *cond = &redFsm->errCond->p;
- condTargs.value( cond->targ->id );
- }
-
- condTargs.finish();
-}
-
-void Binary::taCondActions()
-{
- condActions.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- COND_ACTION( cond );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- COND_ACTION( cond );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond(c);
- COND_ACTION( cond );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond(c);
- COND_ACTION( cond );
- }
- }
- }
-
- if ( redFsm->errCond != 0 ) {
- RedCondPair *cond = &redFsm->errCond->p;
- COND_ACTION( cond );
- }
-
- condActions.finish();
-}
-
-void Binary::taNfaTargs()
-{
- nfaTargs.start();
-
- /* Offset of zero means no NFA targs, put a filler there. */
- nfaTargs.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaTargs.value( st->nfaTargs->length() );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- nfaTargs.value( targ->state->id );
- }
- }
-
- nfaTargs.finish();
-}
-
-/* These need to mirror nfa targs. */
-void Binary::taNfaPushActions()
-{
- nfaPushActions.start();
-
- nfaPushActions.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaPushActions.value( 0 );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_PUSH_ACTION( targ );
- }
- }
-
- nfaPushActions.finish();
-}
-
-void Binary::taNfaPopTrans()
-{
- nfaPopTrans.start();
-
- nfaPopTrans.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
-
- nfaPopTrans.value( 0 );
-
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_POP_TEST( targ );
- }
- }
-
- nfaPopTrans.finish();
-}
-
-void Binary::taNfaOffsets()
-{
- nfaOffsets.start();
-
- /* Offset of zero means no NFA targs, real targs start at 1. */
- long offset = 1;
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs == 0 ) {
- nfaOffsets.value( 0 );
- }
- else {
- nfaOffsets.value( offset );
- offset += 1 + st->nfaTargs->length();
- }
- }
-
- nfaOffsets.finish();
-}
-
-
-/* Write out the array of actions. */
-std::ostream &Binary::ACTIONS_ARRAY()
-{
- out << "\t0, ";
- int totalActions = 1;
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Write out the length, which will never be the last character. */
- out << act->key.length() << ", ";
- /* Put in a line break every 8 */
- if ( totalActions++ % 8 == 7 )
- out << "\n\t";
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
- out << item->value->actionId;
- if ( ! (act.last() && item.last()) )
- out << ", ";
-
- /* Put in a line break every 8 */
- if ( totalActions++ % 8 == 7 )
- out << "\n\t";
- }
- }
- out << "\n";
- return out;
-}
-
-void Binary::taActions()
-{
- actions.start();
-
- /* Put "no-action" at the beginning. */
- actions.value( 0 );
-
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Write out the length, which will never be the last character. */
- actions.value( act->key.length() );
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ )
- actions.value( item->value->actionId );
- }
-
- actions.finish();
-}
-
-
-
-
diff --git a/src/binary.h b/src/binary.h
deleted file mode 100644
index d947483d..00000000
--- a/src/binary.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _C_BINARY_H
-#define _C_BINARY_H
-
-#include <iostream>
-#include "codegen.h"
-#include "tables.h"
-
-/* Forwards. */
-struct CodeGenData;
-struct NameInst;
-struct RedTransAp;
-struct RedStateAp;
-
-class Binary
- : public virtual Tables
-{
-protected:
- enum Type {
- Loop = 1, Exp
- };
-
-public:
- Binary( const CodeGenArgs &args, Type type )
- :
- Tables( args ),
- type(type)
- {}
-
-protected:
- Type type;
-
- std::ostream &COND_KEYS_v1();
- std::ostream &COND_SPACES_v1();
- std::ostream &INDICES();
- std::ostream &INDEX_OFFSETS();
- std::ostream &SINGLE_LENS();
- std::ostream &RANGE_LENS();
- std::ostream &TRANS_TARGS_WI();
- std::ostream &ACTIONS_ARRAY();
-
- void taKeyOffsets();
- void taSingleLens();
- void taRangeLens();
- void taIndexOffsets();
- void taIndices();
- void taTransCondSpacesWi();
- void taTransOffsetsWi();
- void taTransLengthsWi();
- void taTransCondSpaces();
- void taTransOffsets();
- void taTransLengths();
- void taCondTargs();
- void taCondActions();
- void taToStateActions();
- void taFromStateActions();
- void taEofTrans();
- void taEofConds();
- void taEofActions();
- void taKeys();
- void taActions();
- void taCondKeys();
- void taNfaTargs();
- void taNfaOffsets();
- void taNfaPushActions();
- void taNfaPopTrans();
-
- void setKeyType();
-
- void setTableState( TableArray::State );
-
- virtual void writeData();
- virtual void tableDataPass();
- virtual void genAnalysis();
-};
-
-#endif
diff --git a/src/binbreak.cc b/src/binbreak.cc
deleted file mode 100644
index 18b71542..00000000
--- a/src/binbreak.cc
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "binbreak.h"
-
-void BinBreak::LOCATE_TRANS()
-{
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), ARR_REF( keyOffsets ) + "[" + vCS() + "]" ) << ";\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexOffsets ) << "[" << vCS() << "];\n"
- "\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( singleLens ) << "[" << vCS() << "];\n"
- " " << have << " = 0;\n"
- " if ( " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + " << klen << " - 1;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << keys << " += " << klen << ";\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << have << " = 1;\n"
- " " << trans << " += " << CAST( UINT() ) << "(_mid - " << keys << ");\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- "\n"
- " " << klen << " = " << CAST("int") << ARR_REF( rangeLens ) << "[" << vCS() << "];\n"
- " if ( " << have << " == 0 && " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + (" << klen << "<<1) - 2;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 2;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid + 1" ) << " )\n"
- " _lower = _mid + 2;\n"
- " else {\n"
- " " << trans << " += " << CAST( UINT() ) << "((_mid - " << keys << ")>>1);\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- "\n";
-}
-
-void BinBreak::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-
- out << EMIT_LABEL( _match_cond );
-}
-
diff --git a/src/binbreak.h b/src/binbreak.h
deleted file mode 100644
index 1b48ab24..00000000
--- a/src/binbreak.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_BINBREAK_H
-#define RAGEL_BINBREAK_H
-
-#include "binary.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct BinBreak
-:
- public Binary, public TabBreak
-{
- BinBreak( const CodeGenArgs &args, Binary::Type type )
- :
- Tables( args ),
- Binary( args, type ),
- TabBreak( args )
- {}
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class BinBreakLoop
- : public BinBreak, public ActLoop
-{
-public:
- BinBreakLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- BinBreak( args, Loop ),
- ActLoop( args )
- {}
-};
-
-
-class BinBreakExp
- : public BinBreak, public ActExp
-{
-public:
- BinBreakExp( const CodeGenArgs &args )
- :
- Tables( args ),
- BinBreak( args, Exp ),
- ActExp( args )
- {}
-};
-
-
-#endif
diff --git a/src/bingoto.cc b/src/bingoto.cc
deleted file mode 100644
index 1f4a818d..00000000
--- a/src/bingoto.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "bingoto.h"
-
-void BinGoto::LOCATE_TRANS()
-{
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), ARR_REF( keyOffsets ) + "[" + vCS() + "]" ) << ";\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexOffsets ) << "[" << vCS() << "];\n"
- "\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( singleLens ) << "[" << vCS() << "];\n"
- " if ( " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + " << klen << " - 1;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << keys << " += " << klen << ";\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << trans << " += " << CAST( UINT() ) << "(_mid - " << keys << ");\n"
- " goto " << _match << ";\n"
- " }\n"
- " }\n"
- " }\n"
- "\n"
- " " << klen << " = " << CAST("int") << ARR_REF( rangeLens ) << "[" << vCS() << "];\n"
- " if ( " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + (" << klen << "<<1) - 2;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 2;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid + 1" ) << " )\n"
- " _lower = _mid + 2;\n"
- " else {\n"
- " " << trans << " += " << CAST( UINT() ) << "((_mid - " << keys << ")>>1);\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- "\n";
-
- out << EMIT_LABEL( _match );
-}
-
-
-void BinGoto::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-}
-
diff --git a/src/bingoto.h b/src/bingoto.h
deleted file mode 100644
index 18fa8397..00000000
--- a/src/bingoto.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_BINGOTO_H
-#define RAGEL_BINGOTO_H
-
-#include "binary.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct BinGoto
-:
- public Binary, public TabGoto
-{
- BinGoto( const CodeGenArgs &args, Binary::Type type )
- :
- Tables( args ),
- Binary( args, type ),
- TabGoto( args )
- {}
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class BinGotoLoop
- : public BinGoto, public ActLoop
-{
-public:
- BinGotoLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- BinGoto( args, Loop ),
- ActLoop( args )
- {}
-};
-
-
-class BinGotoExp
- : public BinGoto, public ActExp
-{
-public:
- BinGotoExp( const CodeGenArgs &args )
- :
- Tables( args ),
- BinGoto( args, Exp ),
- ActExp( args )
- {}
-};
-
-
-#endif
diff --git a/src/binvar.cc b/src/binvar.cc
deleted file mode 100644
index addec681..00000000
--- a/src/binvar.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "binvar.h"
-#include "parsedata.h"
-#include "inputdata.h"
-
-
-void BinVar::LOCATE_TRANS()
-{
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), ARR_REF( keyOffsets ) + "[" + vCS() + "]" ) << ";\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexOffsets ) << "[" << vCS() << "];\n"
- "\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( singleLens ) << "[" << vCS() << "];\n"
- " " << have << " = 0;\n"
- " if ( " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + " << klen << " - 1;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " _bsc = 1;\n"
- " while ( _bsc == 1 ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << keys << " += " << klen << ";\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " _bsc = 0;\n"
- " }\n"
- " else {\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << have << " = 1;\n"
- " " << trans << " += " << CAST( UINT() ) << "(_mid - " << keys << ");\n"
- " _bsc = 0;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "\n"
- " " << klen << " = " << CAST("int") << ARR_REF( rangeLens ) << "[" << vCS() << "];\n"
- " if ( " << have << " == 0 && " << klen << " > 0 ) {\n"
- " " << INDEX( ALPH_TYPE(), "_lower" ) << " = " << keys << ";\n"
- " " << INDEX( ALPH_TYPE(), "_upper" ) << " = " << keys << " + (" << klen << "<<1) - 2;\n"
- " " << INDEX( ALPH_TYPE(), "_mid" ) << ";\n"
- " _bsc = 1;\n"
- " while ( _bsc == 1 ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << trans << " += " << CAST( UINT() ) << "" << klen << ";\n"
- " _bsc = 0;\n"
- " }\n"
- " else {\n"
- " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n"
- " if ( " << GET_KEY() << " < " << DEREF( ARR_REF( transKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 2;\n"
- " else if ( " << GET_KEY() << " > " << DEREF( ARR_REF( transKeys ), "_mid + 1" ) << " )\n"
- " _lower = _mid + 2;\n"
- " else {\n"
- " " << trans << " += " << CAST( UINT() ) << "((_mid - " << keys << ")>>1);\n"
- " _bsc = 0;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- "\n";
-}
-
-void BinVar::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " _bsc = 1;\n"
- " while ( _bsc == 1 ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " _bsc = 0;\n"
- " }\n"
- " else {\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " _bsc = 0;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-}
-
diff --git a/src/binvar.h b/src/binvar.h
deleted file mode 100644
index cbbcef79..00000000
--- a/src/binvar.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_BINVAR_H
-#define RAGEL_BINVAR_H
-
-#include "binary.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct BinVar
-:
- public Binary, public TabVar
-{
- BinVar( const CodeGenArgs &args, Binary::Type type )
- :
- Tables( args ),
- Binary( args, type ),
- TabVar( args )
- {}
-
- void VAR_COND_BIN_SEARCH( Variable &var, TableArray &keys, std::string ok, std::string error );
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class BinVarLoop
- : public BinVar, public ActLoop
-{
-public:
- BinVarLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- BinVar( args, Loop ),
- ActLoop( args )
- {}
-};
-
-class BinVarExp
-:
- public BinVar, public ActExp
-{
-public:
- BinVarExp( const CodeGenArgs &args )
- :
- Tables( args ),
- BinVar( args, Exp ),
- ActExp( args )
- {}
-};
-
-#endif
diff --git a/src/codegen.h b/src/codegen.h
deleted file mode 100644
index 904c839f..00000000
--- a/src/codegen.h
+++ /dev/null
@@ -1,459 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _C_CODEGEN_H
-#define _C_CODEGEN_H
-
-#include <iostream>
-#include <string>
-#include <stdio.h>
-#include "common.h"
-#include "gendata.h"
-#include "vector.h"
-
-using std::string;
-using std::ostream;
-
-/* Integer array line length. */
-//#define IALL 8
-
-#define IALL_INTEGRAL 8
-#define IALL_STRING 128
-
-
-/* Forwards. */
-struct RedFsmAp;
-struct RedStateAp;
-struct CodeGenData;
-struct GenAction;
-struct NameInst;
-struct GenInlineItem;
-struct GenInlineList;
-struct RedAction;
-struct LongestMatch;
-struct LongestMatchPart;
-
-string itoa( int i );
-
-struct Variable
-{
- Variable( const char *name ) : name(name), isReferenced(false) {}
-
- const std::string ref() { isReferenced = true; return name; }
-
- const char *name;
- bool isReferenced;
-};
-
-struct GotoLabel
-{
- GotoLabel( const char *name ) : name(name), isReferenced(false) {}
-
- const std::string ref() { isReferenced = true; return name; }
-
- const char *name;
- bool isReferenced;
-};
-
-std::ostream &operator<<( std::ostream &out, GotoLabel &l );
-std::ostream &operator<<( std::ostream &out, Variable &v );
-
-struct TableArray;
-typedef Vector<TableArray*> ArrayVector;
-class CodeGen;
-
-struct TableArray
-{
- enum State {
- InitialState = 1,
- AnalyzePass,
- GeneratePass
- };
-
- TableArray( const char *name, CodeGen &codeGen );
-
- void start();
- void startAnalyze();
- void startGenerate();
-
- void setType( std::string type, int width, bool isChar )
- {
- this->type = type;
- this->width = width;
- this->isChar = isChar;
- }
-
- std::string ref();
-
- void value( long long v );
-
- void valueAnalyze( long long v );
- void valueGenerate( long long v );
- void stringGenerate( long long value );
-
- void finish();
- void finishAnalyze();
- void finishGenerate();
-
- void setState( TableArray::State state )
- { this->state = state; }
-
- long long size();
-
- State state;
- const char *name;
- std::string type;
- int width;
- bool isSigned;
- bool isChar;
- bool stringTables;
- int iall;
- long long values;
- long long min;
- long long max;
- CodeGen &codeGen;
- std::ostream &out;
- int ln;
- bool isReferenced;
- bool started;
-};
-
-struct IlOpts
-{
- IlOpts( int targState, bool inFinish, bool csForced )
- : targState(targState), inFinish(inFinish), csForced(csForced) {}
-
- int targState;
- bool inFinish;
- bool csForced;
-};
-
-
-/*
- * class CodeGen
- */
-class CodeGen : public CodeGenData
-{
-public:
- CodeGen( const CodeGenArgs &args );
-
- virtual ~CodeGen() {}
-
- virtual void writeInit();
- virtual void writeStart();
- virtual void writeFirstFinal();
- virtual void writeError();
- virtual void statsSummary();
-
-protected:
- friend TableArray;
- typedef Vector<TableArray*> ArrayVector;
- ArrayVector arrayVector;
-
- Variable cpc;
- Variable pop_test;
- Variable new_recs;
- Variable alt;
-
- string FSM_NAME();
- string START_STATE_ID();
- void taActions();
- string KEY( Key key );
- string LDIR_PATH( char *path );
-
- void ACTION( ostream &ret, GenAction *action, IlOpts opts );
- void NFA_CONDITION( ostream &ret, GenAction *condition, bool last );
- void NFA_POP_TEST_EXEC();
- void CONDITION( ostream &ret, GenAction *condition );
- string ALPH_TYPE();
-
- bool isAlphTypeSigned();
- long long tableData;
- RagelBackend backend;
- bool stringTables;
- BackendFeature backendFeature;
-
- TableArray nfaTargs;
- TableArray nfaOffsets;
- TableArray nfaPushActions;
- TableArray nfaPopTrans;
-
- virtual string GET_KEY();
-
- string P();
- string PE();
- string vEOF();
-
- string ACCESS();
- string vCS();
- string STACK();
- string TOP();
- string TOKSTART();
- string TOKEND();
- string ACT();
-
- string DATA_PREFIX();
- string START() { return DATA_PREFIX() + "start"; }
- string ERROR() { return DATA_PREFIX() + "error"; }
- string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
-
- /* Declare a variable only if referenced. */
- void DECLARE( std::string type, Variable &var, std::string init = "" );
-
- string CAST( string type );
-
- string ARR_TYPE( const TableArray &ta )
- { return ta.type; }
-
- string ARR_REF( TableArray &ta )
- { return ta.ref(); }
-
- void INLINE_EXPR( ostream &ret, GenInlineList *inlineList );
- void INLINE_BLOCK( ostream &ret, GenInlineExpr *inlineExpr );
- void INLINE_PLAIN( ostream &ret, GenInlineExpr *inlineExpr );
-
- void INLINE_LIST( ostream &ret, GenInlineList *inlineList,
- int targState, bool inFinish, bool csForced );
- virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0;
- virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0;
- virtual void NCALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0;
- virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0;
- virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
- virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
- virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem,
- int targState, bool inFinish ) = 0;
- virtual void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem,
- int targState, bool inFinish ) = 0;
- virtual void RET( ostream &ret, bool inFinish ) = 0;
- virtual void NRET( ostream &ret, bool inFinish ) = 0;
- virtual void BREAK( ostream &ret, int targState, bool csForced ) = 0;
- virtual void NBREAK( ostream &ret, int targState, bool csForced ) = 0;
- virtual void CURS( ostream &ret, bool inFinish ) = 0;
- virtual void TARGS( ostream &ret, bool inFinish, int targState ) = 0;
- void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
- void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState,
- int inFinish, bool csForced );
- void LM_EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
- void SET_ACT( ostream &ret, GenInlineItem *item );
- void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
- void INIT_ACT( ostream &ret, GenInlineItem *item );
- void SET_TOKSTART( ostream &ret, GenInlineItem *item );
- void SET_TOKEND( ostream &ret, GenInlineItem *item );
- void GET_TOKEND( ostream &ret, GenInlineItem *item );
-
- void HOST_STMT( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced );
- void HOST_EXPR( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced );
- void HOST_TEXT( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced );
- void GEN_STMT( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced );
- void GEN_EXPR( ostream &ret, GenInlineItem *item, int targState, bool inFinish, bool csForced );
-
- void STATE_IDS();
-
- string ERROR_STATE();
- string FIRST_FINAL_STATE();
-
- string STR( int v );
-
- void VALUE( string type, string name, string value );
-
- string ACCESS_OPER()
- { return backend == Direct ? "" : " -> "; }
-
- string OPEN_HOST_EXPR()
- { return backend == Direct ? "(" : "host( \"-\", 1 ) ={"; }
-
- string OPEN_HOST_EXPR( string fileName, int line )
- {
- return backend == Direct ? "(" : "host( \"" + fileName + "\", " + STR(line) + " ) ={";
- }
-
- string CLOSE_HOST_EXPR()
- { return backend == Direct ? ")" : "}="; }
-
- string OPEN_HOST_BLOCK( string fileName, int line )
- {
- if ( backend == Direct ) {
- std::stringstream ss;
- ss << "{\n" ;
- (*genLineDirective)( ss, lineDirectives, line, fileName.c_str() );
- return ss.str();
- }
- else {
- return "host( \"" + fileName + "\", " + STR(line) + " ) ${";
- }
- }
-
- string OPEN_HOST_BLOCK( GenInlineExpr *inlineExpr )
- {
- return OPEN_HOST_BLOCK( inlineExpr->loc.fileName, inlineExpr->loc.line );
- }
-
- string CLOSE_HOST_BLOCK()
- { return backend == Direct ? "}\n" : "}$"; }
-
- string OPEN_HOST_PLAIN()
- { return backend == Direct ? "" : "host( \"-\", 1 ) @{"; }
-
- string CLOSE_HOST_PLAIN()
- { return backend == Direct ? "" : "}@"; }
-
- string OPEN_GEN_EXPR()
- { return backend == Direct ? "(" : "={"; }
-
- string CLOSE_GEN_EXPR()
- { return backend == Direct ? ")" : "}="; }
-
- string OPEN_GEN_BLOCK()
- { return backend == Direct ? "{" : "${"; }
-
- string CLOSE_GEN_BLOCK()
- { return backend == Direct ? "}" : "}$"; }
-
- string OPEN_GEN_PLAIN()
- { return backend == Direct ? "" : "@{"; }
-
- string CLOSE_GEN_PLAIN()
- { return backend == Direct ? "" : "}@"; }
-
- string INT()
- { return "int"; }
-
- string UINT()
- { return backend == Direct ? "unsigned int" : "uint"; }
-
- string INDEX( string type, string name )
- {
- if ( backend == Direct )
- return "const " + type + " *" + name;
- else
- return "index " + type + " " + name;
- }
-
- string INDEX( string type )
- {
- if ( backend == Direct )
- return "const " + type + " *";
- else
- return "index " + type + " ";
- }
-
- string LABEL( string name )
- {
- return name + ": ";
- }
-
- string EMIT_LABEL( GotoLabel label )
- {
- if ( label.isReferenced )
- return std::string(label.name) + ": {}\n";
- else
- return "";
- }
-
- string OFFSET( string arr, string off )
- {
- if ( backend == Direct )
- return "( " + arr + " + (" + off + "))";
- else
- return "offset( " + arr + ", " + off + " )";
- }
-
- string TRUE()
- {
- if ( backend == Direct )
- return "1";
- else
- return "TRUE";
- }
-
- string DEREF( string arr, string off )
- {
- if ( backend == Direct )
- return "(*( " + off + "))";
- else
- return "deref( " + arr + ", " + off + " )";
- }
-
- string CASE( string val )
- {
- if ( backend == Direct )
- return "case " + val + ": ";
- else
- return "case " + val;
- }
-
- string DEFAULT()
- {
- if ( backend == Direct )
- return "default:";
- else
- return "default";
- }
-
- string CEND( )
- {
- if ( backend == Direct )
- return " break; ";
- else
- return " ";
- }
-
- string FALLTHROUGH()
- {
- if ( backend == Direct )
- return " ";
- else
- return "fallthrough;";
- }
-
- string NIL()
- {
- if ( backend == Direct )
- return "0";
- else
- return "nil";
- }
-
- string EXPORT( string type, string name, string value )
- {
- if ( backend == Direct )
- return "#define " + name + " " + value;
- else
- return "export " + type + " " + name + " " + value + ";";
- }
-
- void NFA_POST_POP();
- virtual void NFA_PUSH( std::string );
- virtual void NFA_POP() = 0;
- virtual void LOCATE_TRANS() {}
- virtual void LOCATE_COND() {}
- virtual void EOF_TRANS() {}
-
-
- virtual void COND_EXEC( std::string expr ) {}
- virtual void COND_BIN_SEARCH( Variable &var, TableArray &keys, std::string ok, std::string error ) {}
-
-public:
- virtual void writeExports();
-};
-
-#endif
diff --git a/src/common.h b/src/common.h
deleted file mode 100644
index 9754ecf5..00000000
--- a/src/common.h
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _COMMON_H
-#define _COMMON_H
-
-#include <iostream>
-#include <fstream>
-#include <climits>
-#include <aapl/dlist.h>
-
-struct colm_location;
-
-struct InputData;
-struct CodeGenData;
-struct HostLang;
-struct CodeGenArgs;
-
-enum RagelBackend
-{
- Direct,
- Translated
-};
-
-enum BackendFeature
-{
- GotoFeature,
- BreakFeature,
- VarFeature
-};
-
-#define S8BIT_MIN -128
-#define S8BIT_MAX 127
-
-#define U8BIT_MIN 0
-#define U8BIT_MAX 255
-
-#define S16BIT_MIN -32768
-#define S16BIT_MAX 32767
-
-#define U16BIT_MIN 0
-#define U16BIT_MAX 65535
-
-#define S31BIT_MIN -1073741824l
-#define S31BIT_MAX 1073741823l
-
-#define S32BIT_MIN -2147483648l
-#define S32BIT_MAX 2147483647l
-
-#define U32BIT_MIN 0
-#define U32BIT_MAX 4294967295l
-
-#define S64BIT_MIN (-9223372036854775807LL - 1LL)
-#define S64BIT_MAX 9223372036854775807LL
-
-#define U64BIT_MIN 0
-#define U64BIT_MAX 18446744073709551615ULL
-
-struct ParserLoc
-{
- const char *fileName;
- int line;
- int col;
-};
-
-/* Location in an input file. */
-struct InputLoc
-{
- InputLoc( colm_location *pcloc );
-
- InputLoc() : fileName(0), line(-1), col(-1) {}
-
- InputLoc( const ParserLoc loc )
- {
- fileName = loc.fileName;
- line = loc.line;
- col = loc.col;
-
- if ( fileName == 0 )
- fileName = "-";
- if ( line == 0 )
- line = 1;
- }
-
- InputLoc( const InputLoc &loc )
- {
- fileName = loc.fileName;
- line = loc.line;
- col = loc.col;
-
- if ( fileName == 0 )
- fileName = "-";
- if ( line == 0 )
- line = 1;
- }
-
- InputLoc( const char *fileName, int line, int col )
- : fileName(fileName), line(line), col(col) {}
-
- const char *fileName;
- int line;
- int col;
-};
-
-extern InputLoc internal;
-
-typedef unsigned long long Size;
-
-struct Key
-{
-private:
- long key;
-
-public:
- friend struct KeyOps;
-
- Key( ) {}
- Key( const Key &key ) : key(key.key) {}
- Key( long key ) : key(key) {}
-
- /* Returns the value used to represent the key. This value must be
- * interpreted based on signedness. */
- long getVal() const { return key; };
-
- bool isUpper() const { return ( 'A' <= key && key <= 'Z' ); }
- bool isLower() const { return ( 'a' <= key && key <= 'z' ); }
- bool isPrintable() const
- {
- return ( 7 <= key && key <= 13 ) || ( 32 <= key && key < 127 );
- }
-
- Key toUpper() const
- { return Key( 'A' + ( key - 'a' ) ); }
- Key toLower() const
- { return Key( 'a' + ( key - 'A' ) ); }
-};
-
-struct CondKey
-{
-private:
- long key;
-
-public:
- friend inline bool operator<( const CondKey key1, const CondKey key2 );
- friend inline bool operator>( const CondKey key1, const CondKey key2 );
- friend inline bool operator==( const CondKey key1, const CondKey key2 );
- friend inline CondKey operator+( const CondKey key1, const CondKey key2 );
- friend inline CondKey operator-( const CondKey key1, const CondKey key2 );
-
- friend struct KeyOps;
-
- CondKey( ) {}
- CondKey( const CondKey &key ) : key(key.key) {}
- CondKey( long key ) : key(key) {}
-
- /* Returns the value used to represent the key. This value must be
- * interpreted based on signedness. */
- long getVal() const { return key; };
-
- bool isUpper() const { return ( 'A' <= key && key <= 'Z' ); }
- bool isLower() const { return ( 'a' <= key && key <= 'z' ); }
- bool isPrintable() const
- {
- return ( 7 <= key && key <= 13 ) || ( 32 <= key && key < 127 );
- }
-
- CondKey toUpper() const
- { return CondKey( 'A' + ( key - 'a' ) ); }
- CondKey toLower() const
- { return CondKey( 'a' + ( key - 'A' ) ); }
-
- /* Decrement. Needed only for ranges. */
- inline void decrement();
- inline void increment();
-};
-
-inline CondKey operator+(const CondKey key1, const CondKey key2)
-{
- return CondKey( key1.key + key2.key );
-}
-
-inline CondKey operator-(const CondKey key1, const CondKey key2)
-{
- return CondKey( key1.key - key2.key );
-}
-
-struct HostType
-{
- const char *data1;
- const char *data2;
- const char *internalName;
- bool isSigned;
- bool isOrd;
- bool isChar;
- long long sMinVal;
- long long sMaxVal;
- unsigned long long uMinVal;
- unsigned long long uMaxVal;
- unsigned int size;
-};
-
-typedef void (*GenLineDirectiveT)( std::ostream &out, bool nld, int line, const char *file );
-typedef const char *(*DefaultOutFnT)( const char *inputFileName );
-typedef CodeGenData *(*MakeCodeGenT)( const HostLang *hostLang, const CodeGenArgs &args );
-
-struct HostLang
-{
- HostType *hostTypes;
- int numHostTypes;
- int defaultAlphType;
- bool explicitUnsigned;
- bool loopLabels;
-
- RagelBackend backend;
- BackendFeature feature;
-
- MakeCodeGenT makeCodeGen;
- DefaultOutFnT defaultOutFn;
- GenLineDirectiveT genLineDirective;
-};
-
-void genLineDirectiveC( std::ostream &out, bool nld, int line, const char *file );
-void genLineDirectiveAsm( std::ostream &out, bool nld, int line, const char *file );
-void genLineDirectiveTrans( std::ostream &out, bool nld, int line, const char *file );
-
-extern const HostLang hostLangC;
-extern const HostLang hostLangAsm;
-
-HostType *findAlphType( const HostLang *hostLang, const char *s1 );
-HostType *findAlphType( const HostLang *hostLang, const char *s1, const char *s2 );
-HostType *findAlphTypeInternal( const HostLang *hostLang, const char *s1 );
-
-const char *defaultOutFnC( const char *inputFileName );
-extern HostType hostTypesC[];
-
-/* An abstraction of the key operators that manages key operations such as
- * comparison and increment according the signedness of the key. */
-struct KeyOps
-{
- /* Defaults to C "char" type: Signed 8 bit. */
- KeyOps()
- :
- isSigned(true),
- explicitUnsigned(true),
- minKey(CHAR_MIN),
- maxKey(CHAR_MAX)
- {}
-
- bool isSigned;
- bool explicitUnsigned;
- Key minKey, maxKey;
-
- void setAlphType( const HostLang *hostLang, const HostType *alphType )
- {
- isSigned = alphType->isSigned;
- explicitUnsigned = hostLang->explicitUnsigned;
-
- if ( isSigned ) {
- minKey = (long) alphType->sMinVal;
- maxKey = (long) alphType->sMaxVal;
- }
- else {
- minKey = (long) alphType->uMinVal;
- maxKey = (long) alphType->uMaxVal;
- }
- }
-
- /* Compute the distance between two keys. */
- Size span( Key key1, Key key2 )
- {
- return isSigned ?
- (unsigned long long)(
- (long long)key2.key -
- (long long)key1.key + 1) :
- (unsigned long long)(
- (unsigned long)key2.key) -
- (unsigned long long)((unsigned long)key1.key) + 1;
- }
-
- Size alphSize()
- { return span( minKey, maxKey ); }
-
- inline bool lt( const Key key1, const Key key2 )
- {
- return this->isSigned ? key1.key < key2.key :
- (unsigned long)key1.key < (unsigned long)key2.key;
- }
-
- inline bool le( const Key key1, const Key key2 )
- {
- return this->isSigned ? key1.key <= key2.key :
- (unsigned long)key1.key <= (unsigned long)key2.key;
- }
-
- inline bool gt( const Key key1, const Key key2 )
- {
- return this->isSigned ? key1.key > key2.key :
- (unsigned long)key1.key > (unsigned long)key2.key;
- }
-
- inline bool ge( const Key key1, const Key key2 )
- {
- return this->isSigned ? key1.key >= key2.key :
- (unsigned long)key1.key >= (unsigned long)key2.key;
- }
-
- inline bool eq( const Key key1, const Key key2 )
- {
- return key1.key == key2.key;
- }
-
- inline bool ne( const Key key1, const Key key2 )
- {
- return key1.key != key2.key;
- }
-
- inline Key add(const Key key1, const Key key2)
- {
- /* FIXME: must be made aware of isSigned. */
- return Key( key1.key + key2.key );
- }
-
- inline Key sub(const Key key1, const Key key2)
- {
- /* FIXME: must be made aware of isSigned. */
- return Key( key1.key - key2.key );
- }
-
- /* Decrement. Needed only for ranges. */
- inline void decrement( Key &key )
- {
- key.key = this->isSigned ? key.key - 1 : ((unsigned long)key.key)-1;
- }
-
- /* Increment. Needed only for ranges. */
- inline void increment( Key &key )
- {
- key.key = this->isSigned ? key.key+1 : ((unsigned long)key.key)+1;
- }
-
- /* Returns the key casted to a long long. This form of the key does not
- * require any signedness interpretation. */
- inline long long getLongLong( const Key &key )
- {
- return this->isSigned ? (long long)key.key : (long long)(unsigned long)key.key;
- }
-};
-
-/* CondKey */
-
-inline bool operator<( const CondKey key1, const CondKey key2 )
-{
- return key1.key < key2.key;
-}
-
-inline bool operator>( const CondKey key1, const CondKey key2 )
-{
- return key1.key > key2.key;
-}
-
-inline bool operator==( const CondKey key1, const CondKey key2 )
-{
- return key1.key == key2.key;
-}
-
-/* Increment. Needed only for ranges. */
-inline void CondKey::increment()
-{
- key = key + 1;
-}
-
-
-/* Filter on the output stream that keeps track of the number of lines
- * output. */
-class output_filter
-:
- public std::filebuf
-{
-public:
- output_filter( const char *fileName )
- :
- fileName(fileName),
- line(1),
- level(0),
- indent(false),
- singleIndent(false)
- {}
-
- virtual int sync();
- virtual std::streamsize xsputn( const char* s, std::streamsize n );
-
- std::streamsize countAndWrite( const char* s, std::streamsize n );
-
- const char *fileName;
- int line;
- int level;
- bool indent;
- bool singleIndent;
-};
-
-class nullbuf
-:
- public std::streambuf
-{
-public:
- virtual std::streamsize xsputn( const char * s, std::streamsize n )
- { return n; }
-
- virtual int overflow( int c )
- { return 1; }
-};
-
-class cfilebuf : public std::streambuf
-{
-public:
- cfilebuf( char *fileName, FILE* file ) : fileName(fileName), file(file) { }
- char *fileName;
- FILE *file;
-
- int sync()
- {
- fflush( file );
- return 0;
- }
-
- int overflow( int c )
- {
- if ( c != EOF )
- fputc( c, file );
- return 0;
- }
-
- std::streamsize xsputn( const char* s, std::streamsize n )
- {
- std::streamsize written = fwrite( s, 1, n, file );
- return written;
- }
-};
-
-class costream : public std::ostream
-{
-public:
- costream( cfilebuf *b ) :
- std::ostream(b), b(b) {}
-
- ~costream()
- { delete b; }
-
- void fclose()
- { ::fclose( b->file ); }
-
- cfilebuf *b;
-};
-
-
-const char *findFileExtension( const char *stemFile );
-const char *fileNameFromStem( const char *stemFile, const char *suffix );
-
-struct Export
-{
- Export( std::string name, Key key )
- : name(name), key(key) {}
-
- std::string name;
- Key key;
-
- Export *prev, *next;
-};
-
-typedef DList<Export> ExportList;
-
-struct exit_object { };
-extern exit_object endp;
-void operator<<( std::ostream &out, exit_object & );
-
-enum RagelFrontend
-{
- KelbtBased,
- ReduceBased
-};
-
-CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
-CodeGenData *makeCodeGenAsm( const HostLang *hostLang, const CodeGenArgs &args );
-
-#endif
diff --git a/src/dot.cc b/src/dot.cc
deleted file mode 100644
index edd4225b..00000000
--- a/src/dot.cc
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "dot.h"
-#include "gendata.h"
-#include "inputdata.h"
-#include "parsedata.h"
-
-using std::istream;
-using std::ifstream;
-using std::ostream;
-using std::ios;
-using std::cin;
-using std::endl;
-
-void GraphvizDotGen::key( Key key )
-{
- if ( id->displayPrintables && key.isPrintable() ) {
- // Output values as characters, ensuring we escape the quote (") character
- char cVal = (char) key.getVal();
- switch ( cVal ) {
- case '"': case '\\':
- out << "'\\" << cVal << "'";
- break;
- case '\a':
- out << "'\\\\a'";
- break;
- case '\b':
- out << "'\\\\b'";
- break;
- case '\t':
- out << "'\\\\t'";
- break;
- case '\n':
- out << "'\\\\n'";
- break;
- case '\v':
- out << "'\\\\v'";
- break;
- case '\f':
- out << "'\\\\f'";
- break;
- case '\r':
- out << "'\\\\r'";
- break;
- case ' ':
- out << "SP";
- break;
- default:
- out << "'" << cVal << "'";
- break;
- }
- }
- else {
- if ( keyOps->isSigned )
- out << key.getVal();
- else
- out << (unsigned long) key.getVal();
- }
-}
-
-void GraphvizDotGen::condSpec( CondSpace *condSpace, long condVals )
-{
- if ( condSpace != 0 ) {
- out << "(";
- for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
- bool set = condVals & (1 << csi.pos());
- if ( !set )
- out << "!";
- (*csi)->actionName( out );
- if ( !csi.last() )
- out << ", ";
- }
- out << ")";
- }
-}
-
-void GraphvizDotGen::onChar( Key lowKey, Key highKey, CondSpace *condSpace, long condVals )
-{
- /* Output the key. Possibly a range. */
- key( lowKey );
- if ( keyOps->ne( highKey, lowKey ) ) {
- out << "..";
- key( highKey );
- }
-
- condSpec( condSpace, condVals );
-}
-
-
-void GraphvizDotGen::fromStateAction( StateAp *fromState )
-{
- int n = 0;
- ActionTable *actionTables[3] = { 0, 0, 0 };
-
- if ( fromState->fromStateActionTable.length() != 0 )
- actionTables[n++] = &fromState->fromStateActionTable;
-
-
- /* Loop the existing actions and write out what's there. */
- for ( int a = 0; a < n; a++ ) {
- for ( ActionTable::Iter actIt = actionTables[a]->first(); actIt.lte(); actIt++ ) {
- Action *action = actIt->value;
- action->actionName( out );
- if ( a < n-1 || !actIt.last() )
- out << ", ";
- }
- }
-
- if ( n > 0 )
- out << " / ";
-}
-
-void GraphvizDotGen::transAction( StateAp *fromState, TransData *trans )
-{
- int n = 0;
- ActionTable *actionTables[3] = { 0, 0, 0 };
-
- if ( trans->actionTable.length() != 0 )
- actionTables[n++] = &trans->actionTable;
- if ( trans->toState != 0 && trans->toState->toStateActionTable.length() != 0 )
- actionTables[n++] = &trans->toState->toStateActionTable;
-
- if ( n > 0 )
- out << " / ";
-
- /* Loop the existing actions and write out what's there. */
- for ( int a = 0; a < n; a++ ) {
- for ( ActionTable::Iter actIt = actionTables[a]->first(); actIt.lte(); actIt++ ) {
- Action *action = actIt->value;
- action->actionName( out );
- if ( a < n-1 || !actIt.last() )
- out << ", ";
- }
- }
-}
-
-void GraphvizDotGen::action( ActionTable *actionTable )
-{
- /* The action. */
- out << " / ";
- for ( ActionTable::Iter actIt = actionTable->first(); actIt.lte(); actIt++ ) {
- Action *action = actIt->value;
- action->actionName( out );
- if ( !actIt.last() )
- out << ", ";
- }
-}
-
-void GraphvizDotGen::transList( StateAp *state )
-{
- /* Build the set of unique transitions out of this state. */
- RedTransSet stTransSet;
- for ( TransList::Iter tel = state->outList; tel.lte(); tel++ ) {
- if ( tel->plain() ) {
- TransDataAp *tdap = tel->tdap();
-
- /* Write out the from and to states. */
- out << "\t" << state->alg.stateNum << " -> ";
-
- if ( tdap->toState == 0 )
- out << "err_" << state->alg.stateNum;
- else
- out << tdap->toState->alg.stateNum;
-
- /* Begin the label. */
- out << " [ label = \"";
-
- fromStateAction( state );
-
- onChar( tel->lowKey, tel->highKey, 0, 0 );
-
- /* Write the action and close the transition. */
- transAction( state, tdap );
-
- out << "\" ];\n";
- }
- else {
- for ( CondList::Iter ctel = tel->tcap()->condList; ctel.lte(); ctel++ ) {
- /* Write out the from and to states. */
- out << "\t" << state->alg.stateNum << " -> ";
-
- if ( ctel->toState == 0 )
- out << "err_" << state->alg.stateNum;
- else
- out << ctel->toState->alg.stateNum;
-
- /* Begin the label. */
- out << " [ label = \"";
-
- fromStateAction( state );
-
- onChar( tel->lowKey, tel->highKey, tel->condSpace, ctel->key.getVal() );
-
- /* Write the action and close the transition. */
- transAction( state, ctel );
- out << "\" ];\n";
- }
- }
- }
-
- if ( state->nfaOut != 0 ) {
- for ( NfaTransList::Iter nfa = *state->nfaOut; nfa.lte(); nfa++ ) {
- out << "\t" << state->alg.stateNum <<
- " -> " << nfa->toState->alg.stateNum <<
- " [ label = \"EP," << nfa->order << " ";
-
- fromStateAction( state );
-
-// if ( nfa->popTest.length() > 0 ||
-// nfa->popAction.length() > 0 ||
-// nfa->popCondKeys.length() > 0 )
-// {
-// out << " / ";
-// }
-
- if ( nfa->popCondKeys.length() > 0 ) {
- for ( CondKeySet::Iter key = nfa->popCondKeys; key.lte(); key++ ) {
- out << "(";
- long condVals = *key;
- for ( CondSet::Iter csi = nfa->popCondSpace->condSet; csi.lte(); csi++ ) {
- bool set = condVals & (1 << csi.pos());
- if ( !set )
- out << "!";
- (*csi)->actionName( out );
- if ( !csi.last() )
- out << ", ";
- }
- out << ") ";
- }
- }
-
- if ( nfa->popAction.length() > 0 ) {
- for ( ActionTable::Iter pa = nfa->popAction; pa.lte(); pa++ ) {
- pa->value->actionName( out );
- if ( !pa.last() )
- out << ",";
- }
- }
-
- if ( nfa->popTest.length() > 0 ) {
- for ( ActionTable::Iter pt = nfa->popTest; pt.lte(); pt++ ) {
- pt->value->actionName( out );
- if ( !pt.last() )
- out << ",";
- }
- }
-
- out << "\" ];";
- }
- }
-}
-
-bool GraphvizDotGen::makeNameInst( std::string &res, NameInst *nameInst )
-{
- bool written = false;
- if ( nameInst->parent != 0 )
- written = makeNameInst( res, nameInst->parent );
-
- if ( !nameInst->name.empty() ) {
- if ( written )
- res += '_';
- res += nameInst->name;
- written = true;
- }
-
- return written;
-}
-
-void GraphvizDotGen::write( )
-{
- out <<
- "digraph " << fsmName << " {\n"
- " rankdir=LR;\n";
-
- /* Define the psuedo states. Transitions will be done after the states
- * have been defined as either final or not final. */
- out << " node [ shape = point ];\n";
-
- if ( fsm->startState != 0 )
- out << " ENTRY;\n";
-
- /* Psuedo states for entry points in the entry map. */
- for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
- StateAp *state = en->value;
- out << " en_" << state->alg.stateNum << ";\n";
- }
-
- /* Psuedo states for final states with eof actions. */
- for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
- //if ( st->eofTrans != 0 && st->eofTrans->action != 0 )
- // out << " eof_" << st->id << ";\n";
- if ( st->eofActionTable.length() > 0 )
- out << " eof_" << st->alg.stateNum << ";\n";
- }
-
- out << " node [ shape = circle, height = 0.2 ];\n";
-
- /* Psuedo states for states whose default actions go to error. */
- for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
- bool needsErr = false;
- for ( TransList::Iter tel = st->outList; tel.lte(); tel++ ) {
- if ( tel->plain() ) {
- if ( tel->tdap()->toState == 0 ) {
- needsErr = true;
- break;
- }
- }
- else {
- for ( CondList::Iter ctel = tel->tcap()->condList; ctel.lte(); ctel++ ) {
- if ( ctel->toState == 0 ) {
- needsErr = true;
- break;
- }
- }
- }
- }
-
- if ( needsErr )
- out << " err_" << st->alg.stateNum << " [ label=\"\"];\n";
- }
-
- /* Attributes common to all nodes, plus double circle for final states. */
- out << " node [ fixedsize = true, height = 0.65, shape = doublecircle ];\n";
-
- /* List Final states. */
- for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
- if ( st->isFinState() )
- out << " " << st->alg.stateNum << ";\n";
- }
-
- /* List transitions. */
- out << " node [ shape = circle ];\n";
-
- /* Walk the states. */
- for ( StateList::Iter st = fsm->stateList; st.lte(); st++ )
- transList( st );
-
- /* Transitions into the start state. */
- if ( fsm->startState != 0 )
- out << " ENTRY -> " << fsm->startState->alg.stateNum << " [ label = \"IN\" ];\n";
-
- for ( EntryMap::Iter en = fsm->entryPoints; en.lte(); en++ ) {
- NameInst *nameInst = fsmCtx->nameIndex[en->key];
- std::string name;
- makeNameInst( name, nameInst );
- StateAp *state = en->value;
- out << " en_" << state->alg.stateNum <<
- " -> " << state->alg.stateNum <<
- " [ label = \"" << name << "\" ];\n";
- }
-
- /* Out action transitions. */
- for ( StateList::Iter st = fsm->stateList; st.lte(); st++ ) {
- if ( st->eofActionTable.length() != 0 ) {
- out << " " << st->alg.stateNum << " -> eof_" <<
- st->alg.stateNum << " [ label = \"EOF";
-
- for ( CondKeySet::Iter i = st->outCondKeys; i.lte(); i++ ) {
- if ( i.pos() > 0 )
- out << "|";
- condSpec( st->outCondSpace, *i );
- }
-
- action( &st->eofActionTable );
- out << "\" ];\n";
- }
- }
-
- out <<
- "}\n";
-}
-
-void InputData::writeDot( ostream &out )
-{
- ParseData *pd = dotGenPd;
- GraphvizDotGen dotGen( this, pd->fsmCtx, pd->sectionGraph, pd->sectionName, pd->machineId, out );
- dotGen.write();
-}
diff --git a/src/dot.h b/src/dot.h
deleted file mode 100644
index 13f53532..00000000
--- a/src/dot.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _GVDOTGEN_H
-#define _GVDOTGEN_H
-
-#include <iostream>
-#include "gendata.h"
-
-
-class GraphvizDotGen : public RedBase
-{
-public:
- GraphvizDotGen( FsmGbl *id, FsmCtx *fsmCtx, FsmAp *fsm,
- std::string fsmName, int machineId, std::ostream &out )
- :
- RedBase(id, fsmCtx, fsm, fsmName, machineId),
- out(out)
- {}
-
- bool makeNameInst( std::string &res, NameInst *nameInst );
- void action( ActionTable *actionTable );
- void transAction( StateAp *fromState, TransData *trans );
- void key( Key key );
- void condSpec( CondSpace *condSpace, long condVals );
- void onChar( Key lowKey, Key highKey, CondSpace *condSpace, long condVals );
- void transList( StateAp *state );
- void write();
- void fromStateAction( StateAp *fromState );
-
- ostream &out;
-};
-
-#endif
diff --git a/src/flat.cc b/src/flat.cc
deleted file mode 100644
index 8cda30db..00000000
--- a/src/flat.cc
+++ /dev/null
@@ -1,576 +0,0 @@
-/*
- * Copyright 2004-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "flat.h"
-#include "redfsm.h"
-#include "gendata.h"
-
-void Flat::genAnalysis()
-{
- redFsm->sortByStateId();
-
- /* Choose default transitions and the single transition. */
- redFsm->chooseDefaultSpan();
-
- /* Do flat expand. */
- redFsm->makeFlatClass();
-
- /* If any errors have occured in the input file then don't write anything. */
- if ( red->id->errorCount > 0 )
- return;
-
- /* Anlayze Machine will find the final action reference counts, among other
- * things. We will use these in reporting the usage of fsm directives in
- * action code. */
- red->analyzeMachine();
-
- setKeyType();
-
- /* Run the analysis pass over the table data. */
- setTableState( TableArray::AnalyzePass );
- tableDataPass();
-
- /* Switch the tables over to the code gen mode. */
- setTableState( TableArray::GeneratePass );
-}
-
-void Flat::tableDataPass()
-{
- if ( type == Flat::Loop ) {
- if ( redFsm->anyActions() )
- taActions();
- }
-
- taKeys();
- taCharClass();
- taFlatIndexOffset();
-
- taIndices();
- taIndexDefaults();
- taTransCondSpaces();
-
- if ( red->condSpaceList.length() > 0 )
- taTransOffsets();
-
- taCondTargs();
- taCondActions();
-
- taToStateActions();
- taFromStateActions();
- taEofConds();
- taEofActions();
- taEofTrans();
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-}
-
-void Flat::writeData()
-{
- if ( type == Flat::Loop ) {
- /* If there are any transtion functions then output the array. If there
- * are none, don't bother emitting an empty array that won't be used. */
- if ( redFsm->anyActions() )
- taActions();
- }
-
- taKeys();
- taCharClass();
- taFlatIndexOffset();
-
- taIndices();
- taIndexDefaults();
- taTransCondSpaces();
- if ( red->condSpaceList.length() > 0 )
- taTransOffsets();
- taCondTargs();
- taCondActions();
-
- if ( redFsm->anyToStateActions() )
- taToStateActions();
-
- if ( redFsm->anyFromStateActions() )
- taFromStateActions();
-
- taEofConds();
-
- if ( redFsm->anyEofActions() )
- taEofActions();
-
- if ( redFsm->anyEofTrans() )
- taEofTrans();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-
- STATE_IDS();
-}
-
-
-void Flat::setKeyType()
-{
- transKeys.setType( ALPH_TYPE(), alphType->size, alphType->isChar );
- transKeys.isSigned = keyOps->isSigned;
-}
-
-void Flat::setTableState( TableArray::State state )
-{
- for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) {
- TableArray *tableArray = *i;
- tableArray->setState( state );
- }
-}
-
-void Flat::taFlatIndexOffset()
-{
- flatIndexOffset.start();
-
- int curIndOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write the index offset. */
- flatIndexOffset.value( curIndOffset );
-
- /* Move the index offset ahead. */
- if ( st->transList != 0 )
- curIndOffset += ( st->high - st->low + 1 );
- }
-
- flatIndexOffset.finish();
-}
-
-void Flat::taCharClass()
-{
- charClass.start();
-
- if ( redFsm->classMap != 0 ) {
- long long maxSpan = keyOps->span( redFsm->lowKey, redFsm->highKey );
-
- for ( long long pos = 0; pos < maxSpan; pos++ )
- charClass.value( redFsm->classMap[pos] );
- }
-
- charClass.finish();
-}
-
-void Flat::taToStateActions()
-{
- toStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write any eof action. */
- TO_STATE_ACTION(st);
- }
-
- toStateActions.finish();
-}
-
-void Flat::taFromStateActions()
-{
- fromStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write any eof action. */
- FROM_STATE_ACTION( st );
- }
-
- fromStateActions.finish();
-}
-
-void Flat::taEofActions()
-{
- eofActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write any eof action. */
- EOF_ACTION( st );
- }
-
- eofActions.finish();
-}
-
-void Flat::taEofConds()
-{
- /*
- * EOF Cond Spaces
- */
- eofCondSpaces.start();
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 )
- eofCondSpaces.value( st->outCondSpace->condSpaceId );
- else
- eofCondSpaces.value( -1 );
- }
- eofCondSpaces.finish();
-
- /*
- * EOF Cond Key Indixes
- */
- eofCondKeyOffs.start();
-
- int curOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long off = 0;
- if ( st->outCondSpace != 0 ) {
- off = curOffset;
- curOffset += st->outCondKeys.length();
- }
- eofCondKeyOffs.value( off );
- }
-
- eofCondKeyOffs.finish();
-
- /*
- * EOF Cond Key Lengths.
- */
- eofCondKeyLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long len = 0;
- if ( st->outCondSpace != 0 )
- len = st->outCondKeys.length();
- eofCondKeyLens.value( len );
- }
-
- eofCondKeyLens.finish();
-
- /*
- * EOF Cond Keys
- */
- eofCondKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 ) {
- for ( int c = 0; c < st->outCondKeys.length(); c++ ) {
- CondKey key = st->outCondKeys[c];
- eofCondKeys.value( key.getVal() );
- }
- }
- }
-
- eofCondKeys.finish();
-}
-
-void Flat::taEofTrans()
-{
- /* Transitions must be written ordered by their id. */
- RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
- transPtrs[trans->id] = trans;
-
- long *transPos = new long[redFsm->transSet.length()];
- for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
- /* Save the position. Needed for eofTargs. */
- RedTransAp *trans = transPtrs[t];
- transPos[trans->id] = t;
- }
-
- eofTrans.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long trans = 0;
-
- if ( st->eofTrans != 0 )
- trans = transPos[st->eofTrans->id] + 1;
-
- eofTrans.value( trans );
- }
-
- eofTrans.finish();
-
- delete[] transPtrs;
- delete[] transPos;
-}
-
-void Flat::taKeys()
-{
- transKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->transList ) {
- /* Emit just low key and high key. */
- transKeys.value( st->low );
- transKeys.value( st->high );
- }
- else {
- /* Emit an impossible range so the driver fails the lookup. */
- transKeys.value( 1 );
- transKeys.value( 0 );
- }
- }
-
- transKeys.finish();
-}
-
-void Flat::taIndices()
-{
- indices.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->transList != 0 ) {
- long long span = st->high - st->low + 1;
- for ( long long pos = 0; pos < span; pos++ )
- indices.value( st->transList[pos]->id );
- }
- }
-
- indices.finish();
-}
-
-void Flat::taIndexDefaults()
-{
- indexDefaults.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* The state's default index goes next. */
- if ( st->defTrans != 0 )
- indexDefaults.value( st->defTrans->id );
- else
- indexDefaults.value( 0 );
- }
-
- indexDefaults.finish();
-}
-
-
-void Flat::taTransCondSpaces()
-{
- transCondSpaces.start();
-
- /* Transitions must be written ordered by their id. */
- RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- transPtrs[trans->id] = trans;
- }
-
- /* Keep a count of the num of items in the array written. */
- for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
- /* Save the position. Needed for eofTargs. */
- RedTransAp *trans = transPtrs[t];
-
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
- delete[] transPtrs;
-
- transCondSpaces.finish();
-}
-
-void Flat::taTransOffsets()
-{
- transOffsets.start();
-
- /* Transitions must be written ordered by their id. */
- RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
- transPtrs[trans->id] = trans;
-
- /* Keep a count of the num of items in the array written. */
- int curOffset = 0;
- for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
- /* Save the position. Needed for eofTargs. */
- RedTransAp *trans = transPtrs[t];
-
- transOffsets.value( curOffset );
-
- curOffset += trans->condFullSize();
- }
-
- delete[] transPtrs;
-
- transOffsets.finish();
-}
-
-void Flat::taCondTargs()
-{
- condTargs.start();
-
- /* Transitions must be written ordered by their id. */
- RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
- transPtrs[trans->id] = trans;
-
- /* Keep a count of the num of items in the array written. */
- for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
- /* Save the position. Needed for eofTargs. */
- RedTransAp *trans = transPtrs[t];
-
- long fullSize = trans->condFullSize();
- RedCondPair **fullPairs = new RedCondPair*[fullSize];
- for ( long k = 0; k < fullSize; k++ )
- fullPairs[k] = trans->errCond();
-
- for ( int c = 0; c < trans->numConds(); c++ )
- fullPairs[trans->outCondKey( c ).getVal()] = trans->outCond( c );
-
- for ( int k = 0; k < fullSize; k++ ) {
- RedCondPair *cond = fullPairs[k];
- condTargs.value( cond->targ->id );
- }
-
- delete[] fullPairs;
- }
- delete[] transPtrs;
-
- condTargs.finish();
-}
-
-void Flat::taCondActions()
-{
- condActions.start();
-
- /* Transitions must be written ordered by their id. */
- RedTransAp **transPtrs = new RedTransAp*[redFsm->transSet.length()];
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ )
- transPtrs[trans->id] = trans;
-
- /* Keep a count of the num of items in the array written. */
- for ( int t = 0; t < redFsm->transSet.length(); t++ ) {
- /* Save the position. Needed for eofTargs. */
- RedTransAp *trans = transPtrs[t];
-
- long fullSize = trans->condFullSize();
- RedCondPair **fullPairs = new RedCondPair*[fullSize];
- for ( long k = 0; k < fullSize; k++ )
- fullPairs[k] = trans->errCond();
-
- for ( int c = 0; c < trans->numConds(); c++ )
- fullPairs[trans->outCondKey( c ).getVal()] = trans->outCond( c );
-
- for ( int k = 0; k < fullSize; k++ ) {
- RedCondPair *cond = fullPairs[k];
- COND_ACTION( cond );
- }
- delete[] fullPairs;
- }
- delete[] transPtrs;
-
- condActions.finish();
-}
-
-/* Write out the array of actions. */
-void Flat::taActions()
-{
- actions.start();
-
- /* Add in the the empty actions array. */
- actions.value( 0 );
-
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Length first. */
- actions.value( act->key.length() );
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ )
- actions.value( item->value->actionId );
- }
-
- actions.finish();
-}
-
-void Flat::taNfaTargs()
-{
- nfaTargs.start();
-
- /* Offset of zero means no NFA targs, put a filler there. */
- nfaTargs.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaTargs.value( st->nfaTargs->length() );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- nfaTargs.value( targ->state->id );
- }
- }
-
- nfaTargs.finish();
-}
-
-/* These need to mirror nfa targs. */
-void Flat::taNfaPushActions()
-{
- nfaPushActions.start();
-
- nfaPushActions.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaPushActions.value( 0 );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_PUSH_ACTION( targ );
- }
- }
-
- nfaPushActions.finish();
-}
-
-void Flat::taNfaPopTrans()
-{
- nfaPopTrans.start();
-
- nfaPopTrans.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
-
- nfaPopTrans.value( 0 );
-
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_POP_TEST( targ );
- }
- }
-
- nfaPopTrans.finish();
-}
-
-
-void Flat::taNfaOffsets()
-{
- nfaOffsets.start();
-
- /* Offset of zero means no NFA targs, real targs start at 1. */
- long offset = 1;
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs == 0 ) {
- nfaOffsets.value( 0 );
- }
- else {
- nfaOffsets.value( offset );
- offset += 1 + st->nfaTargs->length();
- }
- }
-
- nfaOffsets.finish();
-}
-
-
-
-
-
-
-
-
diff --git a/src/flat.h b/src/flat.h
deleted file mode 100644
index 1e54f5ab..00000000
--- a/src/flat.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 2004-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _C_FLAT_H
-#define _C_FLAT_H
-
-#include <iostream>
-#include "codegen.h"
-#include "tables.h"
-
-/* Forwards. */
-struct CodeGenData;
-struct NameInst;
-struct RedTransAp;
-struct RedStateAp;
-
-class Flat
- : public virtual Tables
-{
-protected:
- enum Type {
- Loop = 1, Exp
- };
-
-public:
- Flat( const CodeGenArgs &args, Type type )
- :
- Tables( args ),
- type(type)
- {}
-
- virtual ~Flat() { }
-
-protected:
- Type type;
-
- void taKeys();
- void taKeySpans();
- void taCharClass();
- void taActions();
- void taFlatIndexOffset();
- void taIndices();
- void taIndexDefaults();
- void taTransCondSpaces();
- void taTransOffsets();
- void taCondTargs();
- void taCondActions();
- void taToStateActions();
- void taFromStateActions();
- void taEofActions();
- void taEofTrans();
- void taEofConds();
- void taNfaTargs();
- void taNfaOffsets();
- void taNfaPushActions();
- void taNfaPopTrans();
-
- void setKeyType();
-
- std::ostream &INDICES();
- std::ostream &TRANS_COND_SPACES();
- std::ostream &TRANS_OFFSETS();
- std::ostream &TRANS_LENGTHS();
- std::ostream &COND_KEYS();
- std::ostream &COND_TARGS();
- std::ostream &COND_ACTIONS();
-
- virtual void setTableState( TableArray::State );
-
- virtual void genAnalysis();
- virtual void tableDataPass();
- virtual void writeData();
-};
-
-#endif
diff --git a/src/flatbreak.cc b/src/flatbreak.cc
deleted file mode 100644
index 08342625..00000000
--- a/src/flatbreak.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "flatbreak.h"
-
-void FlatBreak::LOCATE_TRANS()
-{
- if ( redFsm->classMap == 0 ) {
- out <<
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n";
- }
- else {
- long lowKey = redFsm->lowKey.getVal();
- long highKey = redFsm->highKey.getVal();
-
- bool limitLow = keyOps->eq( lowKey, keyOps->minKey );
- bool limitHigh = keyOps->eq( highKey, keyOps->maxKey );
-
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), "(" + vCS() + "<<1)" ) << ";\n"
- " " << inds << " = " << OFFSET( ARR_REF( indices ),
- ARR_REF( flatIndexOffset ) + "[" + vCS() + "]" ) << ";\n"
- "\n";
-
- if ( !limitLow || !limitHigh ) {
- out << " if ( ";
-
- if ( !limitHigh )
- out << GET_KEY() << " <= " << highKey;
-
- if ( !limitHigh && !limitLow )
- out << " && ";
-
- if ( !limitLow )
- out << GET_KEY() << " >= " << lowKey;
-
- out << " ) {\n";
- }
-
- out <<
- " " << ic << " = " << CAST("int") << ARR_REF( charClass ) << "[" << CAST("int") << GET_KEY() <<
- " - " << lowKey << "];\n"
- " if ( " << ic << " <= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "+1" ) << " && " <<
- "" << ic << " >= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "" ) << " )\n"
- " " << trans << " = " << CAST(UINT()) << DEREF( ARR_REF( indices ),
- inds.ref() + " + " + CAST("int") + "( " + ic.ref() + " - " + CAST("int") +
- DEREF( ARR_REF( transKeys ), keys.ref() + "" ) + " ) " ) << "; \n"
- " else\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) <<
- "[" << vCS() << "]" << ";\n";
-
- if ( !limitLow || !limitHigh ) {
- out <<
- " }\n"
- " else {\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n"
- " }\n"
- "\n";
- }
- }
-
-
-}
-
-void FlatBreak::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- out <<
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- out <<
- " switch ( " << ARR_REF( transCondSpaces ) << "[" << trans << "] ) {\n"
- "\n";
-
- for ( CondSpaceList::Iter csi = red->condSpaceList; csi.lte(); csi++ ) {
- GenCondSpace *condSpace = csi;
- if ( condSpace->numTransRefs > 0 ) {
- out << " " << CASE( STR(condSpace->condSpaceId) ) << " {\n";
- for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
- out << "if ( ";
- CONDITION( out, *csi );
- Size condValOffset = (1 << csi.pos());
- out << " ) " << cpc << " += " << condValOffset << ";\n";
- }
-
- out <<
- " " << CEND() << "\n}\n";
- }
- }
-
- out <<
- " }\n"
- " " << cond << " += " << CAST( UINT() ) << "" << cpc << ";\n";
- }
-}
diff --git a/src/flatbreak.h b/src/flatbreak.h
deleted file mode 100644
index 23400000..00000000
--- a/src/flatbreak.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_FLATBREAK_H
-#define RAGEL_FLATBREAK_H
-
-#include "flat.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct FlatBreak
-:
- public Flat, public TabBreak
-{
- FlatBreak( const CodeGenArgs &args, Flat::Type type )
- :
- Tables( args ),
- Flat( args, type ),
- TabBreak( args )
- {}
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class FlatBreakLoop
- : public FlatBreak, public ActLoop
-{
-public:
- FlatBreakLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatBreak( args, Flat::Loop ),
- ActLoop( args )
- {}
-};
-
-/*
- * FlatBreakExp
- */
-class FlatBreakExp
- : public FlatBreak, public ActExp
-{
-public:
- FlatBreakExp( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatBreak( args, Flat::Exp ),
- ActExp( args )
- {}
-};
-
-#endif
diff --git a/src/flatgoto.cc b/src/flatgoto.cc
deleted file mode 100644
index c3206191..00000000
--- a/src/flatgoto.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "flatgoto.h"
-
-void FlatGoto::LOCATE_TRANS()
-{
- if ( redFsm->classMap == 0 ) {
- out <<
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n";
- }
- else {
- long lowKey = redFsm->lowKey.getVal();
- long highKey = redFsm->highKey.getVal();
-
- bool limitLow = keyOps->eq( lowKey, keyOps->minKey );
- bool limitHigh = keyOps->eq( highKey, keyOps->maxKey );
-
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), "(" + vCS() + "<<1)" ) << ";\n"
- " " << inds << " = " << OFFSET( ARR_REF( indices ),
- ARR_REF( flatIndexOffset ) + "[" + vCS() + "]" ) << ";\n"
- "\n";
-
- if ( !limitLow || !limitHigh ) {
- out << " if ( ";
-
- if ( !limitHigh )
- out << GET_KEY() << " <= " << highKey;
-
- if ( !limitHigh && !limitLow )
- out << " && ";
-
- if ( !limitLow )
- out << GET_KEY() << " >= " << lowKey;
-
- out << " ) {\n";
- }
-
- out <<
- " " << ic << " = " << CAST("int") << ARR_REF( charClass ) << "[" << CAST("int") << GET_KEY() <<
- " - " << lowKey << "];\n"
- " if ( " << ic << " <= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "+1" ) << " && " <<
- "" << ic << " >= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "" ) << " )\n"
- " " << trans << " = " << CAST(UINT()) << DEREF( ARR_REF( indices ),
- inds.ref() + " + " + CAST("int") + "( " + ic.ref() + " - " + CAST("int") +
- DEREF( ARR_REF( transKeys ), keys.ref() + "" ) + " ) " ) << "; \n"
- " else\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) <<
- "[" << vCS() << "]" << ";\n";
-
- if ( !limitLow || !limitHigh ) {
- out <<
- " }\n"
- " else {\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n"
- " }\n"
- "\n";
- }
- }
-
-}
-
-
-void FlatGoto::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- out <<
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- out <<
- " switch ( " << ARR_REF( transCondSpaces ) << "[" << trans << "] ) {\n"
- "\n";
-
- for ( CondSpaceList::Iter csi = red->condSpaceList; csi.lte(); csi++ ) {
- GenCondSpace *condSpace = csi;
- if ( condSpace->numTransRefs > 0 ) {
- out << " " << CASE( STR(condSpace->condSpaceId) ) << " {\n";
- for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
- out << "if ( ";
- CONDITION( out, *csi );
- Size condValOffset = (1 << csi.pos());
- out << " ) " << cpc << " += " << condValOffset << ";\n";
- }
-
- out <<
- " " << CEND() << "\n}\n";
- }
- }
-
- out <<
- " }\n"
- " " << cond << " += " << CAST( UINT() ) << "" << cpc << ";\n";
- }
-}
diff --git a/src/flatgoto.h b/src/flatgoto.h
deleted file mode 100644
index e21b6cd9..00000000
--- a/src/flatgoto.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_FLATGOTO_H
-#define RAGEL_FLATGOTO_H
-
-#include "flat.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct FlatGoto
-:
- public Flat, public TabGoto
-{
- FlatGoto( const CodeGenArgs &args, Flat::Type type )
- :
- Tables( args ),
- Flat( args, type ),
- TabGoto( args )
- {}
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class FlatGotoLoop
- : public FlatGoto, public ActLoop
-{
-public:
- FlatGotoLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatGoto( args, Flat::Loop ),
- ActLoop( args )
- {}
-};
-
-/*
- * FlatGotoExp
- */
-class FlatGotoExp
- : public FlatGoto, public ActExp
-{
-public:
- FlatGotoExp( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatGoto( args, Flat::Exp ),
- ActExp( args )
- {}
-};
-
-#endif
diff --git a/src/flatvar.cc b/src/flatvar.cc
deleted file mode 100644
index b747afcd..00000000
--- a/src/flatvar.cc
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "flatvar.h"
-
-#include "parsedata.h"
-#include "inputdata.h"
-
-void FlatVar::LOCATE_TRANS()
-{
- if ( redFsm->classMap == 0 ) {
- out <<
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n";
- }
- else {
- long lowKey = redFsm->lowKey.getVal();
- long highKey = redFsm->highKey.getVal();
-
- bool limitLow = keyOps->eq( lowKey, keyOps->minKey );
- bool limitHigh = keyOps->eq( highKey, keyOps->maxKey );
-
- out <<
- " " << keys << " = " << OFFSET( ARR_REF( transKeys ), "(" + vCS() + "<<1)" ) << ";\n"
- " " << inds << " = " << OFFSET( ARR_REF( indices ),
- ARR_REF( flatIndexOffset ) + "[" + vCS() + "]" ) << ";\n"
- "\n";
-
- if ( !limitLow || !limitHigh ) {
- out << " if ( ";
-
- if ( !limitHigh )
- out << GET_KEY() << " <= " << highKey;
-
- if ( !limitHigh && !limitLow )
- out << " && ";
-
- if ( !limitLow )
- out << GET_KEY() << " >= " << lowKey;
-
- out << " ) {\n";
- }
-
- out <<
- " " << ic << " = " << CAST("int") << ARR_REF( charClass ) << "[" << CAST("int") << GET_KEY() <<
- " - " << lowKey << "];\n"
- " if ( " << ic << " <= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "+1" ) << " && " <<
- "" << ic << " >= " << CAST("int") << DEREF( ARR_REF( transKeys ), keys.ref() + "" ) << " )\n"
- " " << trans << " = " << CAST(UINT()) << DEREF( ARR_REF( indices ),
- inds.ref() + " + " + CAST("int") + "( " + ic.ref() + " - " + CAST("int") +
- DEREF( ARR_REF( transKeys ), keys.ref() + "" ) + " ) " ) << "; \n"
- " else\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) <<
- "[" << vCS() << "]" << ";\n";
-
- if ( !limitLow || !limitHigh ) {
- out <<
- " }\n"
- " else {\n"
- " " << trans << " = " << CAST(UINT()) << ARR_REF( indexDefaults ) << "[" << vCS() << "]" << ";\n"
- " }\n"
- "\n";
- }
- }
-}
-
-void FlatVar::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- out <<
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- out <<
- " switch ( " << ARR_REF( transCondSpaces ) << "[" << trans << "] ) {\n"
- "\n";
-
- for ( CondSpaceList::Iter csi = red->condSpaceList; csi.lte(); csi++ ) {
- GenCondSpace *condSpace = csi;
- if ( condSpace->numTransRefs > 0 ) {
- out << " " << CASE( STR(condSpace->condSpaceId) ) << " {\n";
- for ( GenCondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) {
- out << "if ( ";
- CONDITION( out, *csi );
- Size condValOffset = (1 << csi.pos());
- out << " ) " << cpc << " += " << condValOffset << ";\n";
- }
-
- out <<
- " " << CEND() << "\n}\n";
- }
- }
-
- out <<
- " }\n"
- " " << cond << " += " << CAST( UINT() ) << "" << cpc << ";\n";
- }
-}
diff --git a/src/flatvar.h b/src/flatvar.h
deleted file mode 100644
index 9cd80eab..00000000
--- a/src/flatvar.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_FLATVAR_H
-#define RAGEL_FLATVAR_H
-
-#include "flat.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct FlatVar
-:
- public Flat, public TabVar
-{
- FlatVar( const CodeGenArgs &args, Flat::Type type )
- :
- Tables( args ),
- Flat( args, type ),
- TabVar( args )
- {}
-
- void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class FlatVarLoop
- : public FlatVar, public ActLoop
-{
-public:
- FlatVarLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatVar( args, Flat::Loop ),
- ActLoop( args )
- {}
-};
-
-class FlatVarExp
-:
- public FlatVar, public ActExp
-{
-public:
- FlatVarExp( const CodeGenArgs &args )
- :
- Tables( args ),
- FlatVar( args, Flat::Exp ),
- ActExp( args )
- {}
-};
-
-#endif
diff --git a/src/fsmgraph.h b/src/fsmgraph.h
deleted file mode 100644
index 2429d923..00000000
--- a/src/fsmgraph.h
+++ /dev/null
@@ -1,2541 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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
-#define _FSMGRAPH_H
-
-#include "config.h"
-#include "ragel.h"
-#include "common.h"
-#include "vector.h"
-#include "bstset.h"
-#include "compare.h"
-#include "avltree.h"
-#include "dlist.h"
-#include "dlistmel.h"
-#include "bstmap.h"
-#include "sbstmap.h"
-#include "sbstset.h"
-#include "sbsttable.h"
-#include "avlset.h"
-#include "avlmap.h"
-
-#include <assert.h>
-#include <iostream>
-#include <sstream>
-#include <string>
-
-
-/* Flags that control merging. */
-#define STB_GRAPH1 0x01
-#define STB_GRAPH2 0x02
-#define STB_BOTH 0x03
-#define STB_ISFINAL 0x04
-#define STB_ISMARKED 0x08
-#define STB_ONLIST 0x10
-#define STB_NFA_REP 0x20
-
-using std::ostream;
-
-struct TransAp;
-struct StateAp;
-struct FsmAp;
-struct Action;
-struct LongestMatchPart;
-struct LengthDef;
-struct CondSpace;
-struct FsmCtx;
-struct InlineBlock;
-struct InlineList;
-
-struct TooManyStates {};
-
-struct PriorInteraction
-{
- PriorInteraction( long long id ) : id(id) {}
- long long id;
-};
-
-struct NfaRound
-{
- NfaRound( long depth, long groups )
- : depth(depth), groups(groups) {}
-
- long depth;
- long groups;
-};
-
-typedef Vector<NfaRound> NfaRoundVect;
-
-struct CondCostTooHigh
-{
- CondCostTooHigh( long long costId )
- : costId(costId) {}
-
- long long costId;
-};
-
-
-/* State list element for unambiguous access to list element. */
-struct FsmListEl
-{
- StateAp *prev, *next;
-};
-
-/* This is the marked index for a state pair. Used in minimization. It keeps
- * track of whether or not the state pair is marked. */
-struct MarkIndex
-{
- MarkIndex(int states);
- ~MarkIndex();
-
- void markPair(int state1, int state2);
- bool isPairMarked(int state1, int state2);
-
-private:
- int numStates;
- bool *array;
-};
-
-/* Transistion Action Element. */
-typedef SBstMapEl< int, Action* > ActionTableEl;
-
-/* Nodes in the tree that use this action. */
-struct NameInst;
-struct InlineList;
-typedef Vector<NameInst*> NameInstVect;
-
-struct ActionParam
-{
- ActionParam( std::string name )
- : name(name) {}
-
- std::string name;
-};
-
-typedef Vector<ActionParam*> ActionParamList;
-
-typedef Vector<Action*> ActionArgList;
-
-struct CmpActionArgList
-{
- static inline int compare( const ActionArgList *list1, const ActionArgList *list2 )
- {
- return CmpTable<Action*>::compare( *list1, *list2 );
- }
-};
-
-typedef BstMap<ActionArgList*, Action*, CmpActionArgList> ActionArgListMap;
-typedef BstMapEl<ActionArgList*, Action*> ActionArgListMapEl;
-
-/* Element in list of actions. Contains the string for the code to exectute. */
-struct Action
-:
- public DListEl<Action>,
- public AvlTreeEl<Action>
-{
-public:
-
- Action( const InputLoc &loc, std::string name, InlineList *inlineList, int condId )
- :
- loc(loc),
- name(name),
- inlineList(inlineList),
- actionId(-1),
- numTransRefs(0),
- numToStateRefs(0),
- numFromStateRefs(0),
- numEofRefs(0),
- numCondRefs(0),
- numNfaRefs(0),
- anyCall(false),
- isLmAction(false),
- condId(condId),
- costMark(false),
- costId(0),
- paramList(0),
- argListMap(0),
- substOf(0),
- argList(0)
- {
- }
-
- ~Action();
-
- static Action *cons( const InputLoc &loc, Action *substOf,
- ActionArgList *argList, int condId )
- {
- Action *action = new Action( loc, std::string(), 0, condId );
- action->substOf = substOf;
- action->argList = argList;
- action->inlineList = substOf->inlineList;
- return action;
- }
-
- /* Key for action dictionary. */
- std::string getKey() const { return name; }
-
- /* Data collected during parse. */
- InputLoc loc;
- std::string name;
- InlineList *inlineList;
- int actionId;
-
- void actionName( ostream &out )
- {
- if ( name.empty() )
- out << loc.line << ":" << loc.col;
- else
- out << name;
- }
-
- /* Nodes in the name tree where the action is embedded. This serves as the
- * root for name searches. Since actions can be used multiple times we use
- * a vector. Name resolver deals with contracts. */
- NameInstVect embedRoots;
-
- /* Number of references in the final machine. */
- int numRefs()
- {
- return numTransRefs + numToStateRefs +
- numFromStateRefs + numEofRefs +
- numNfaRefs;
- }
-
- int numTransRefs;
- int numToStateRefs;
- int numFromStateRefs;
- int numEofRefs;
- int numCondRefs;
- int numNfaRefs;
- bool anyCall;
-
- bool isLmAction;
- int condId;
-
- bool costMark;
- long long costId;
-
- ActionParamList *paramList;
- ActionArgListMap *argListMap;
- Action *substOf;
- ActionArgList *argList;
-};
-
-struct CmpCondId
-{
- static inline int compare( const Action *cond1, const Action *cond2 )
- {
- if ( cond1->condId < cond2->condId )
- return -1;
- else if ( cond1->condId > cond2->condId )
- return 1;
- return 0;
- }
-};
-
-/* A list of actions. */
-typedef DList<Action> ActionList;
-typedef AvlTree<Action, std::string, CmpString> ActionDict;
-
-/* Structure for reverse action mapping. */
-struct RevActionMapEl
-{
- char *name;
- InputLoc location;
-};
-
-
-/* Transition Action Table. */
-struct ActionTable
- : public SBstMap< int, Action*, CmpOrd<int> >
-{
- void setAction( int ordering, Action *action );
- void setActions( int *orderings, Action **actions, int nActs );
- void setActions( const ActionTable &other );
-
- bool hasAction( Action *action );
-};
-
-typedef SBstSet< Action*, CmpOrd<Action*> > ActionSet;
-typedef CmpSTable< Action*, CmpOrd<Action*> > CmpActionSet;
-
-/* Transistion Action Element. */
-typedef SBstMapEl< int, LongestMatchPart* > LmActionTableEl;
-
-/* Transition Action Table. */
-struct LmActionTable
- : public SBstMap< int, LongestMatchPart*, CmpOrd<int> >
-{
- void setAction( int ordering, LongestMatchPart *action );
- void setActions( const LmActionTable &other );
-};
-
-/* Compare of a whole action table element (key & value). */
-struct CmpActionTableEl
-{
- static int compare( const ActionTableEl &action1,
- const ActionTableEl &action2 )
- {
- if ( action1.key < action2.key )
- return -1;
- else if ( action1.key > action2.key )
- return 1;
- else if ( action1.value < action2.value )
- return -1;
- else if ( action1.value > action2.value )
- return 1;
- return 0;
- }
-};
-
-/* Compare for ActionTable. */
-typedef CmpSTable< ActionTableEl, CmpActionTableEl > CmpActionTable;
-
-/* Compare of a whole lm action table element (key & value). */
-struct CmpLmActionTableEl
-{
- static int compare( const LmActionTableEl &lmAction1,
- const LmActionTableEl &lmAction2 )
- {
- if ( lmAction1.key < lmAction2.key )
- return -1;
- else if ( lmAction1.key > lmAction2.key )
- return 1;
- else if ( lmAction1.value < lmAction2.value )
- return -1;
- else if ( lmAction1.value > lmAction2.value )
- return 1;
- return 0;
- }
-};
-
-/* Compare for ActionTable. */
-typedef CmpSTable< LmActionTableEl, CmpLmActionTableEl > CmpLmActionTable;
-
-/* Action table element for error action tables. Adds the encoding of transfer
- * point. */
-struct ErrActionTableEl
-{
- ErrActionTableEl( Action *action, int ordering, int transferPoint )
- : ordering(ordering), action(action), transferPoint(transferPoint) { }
-
- /* Ordering and id of the action embedding. */
- int ordering;
- Action *action;
-
- /* Id of point of transfere from Error action table to transtions and
- * eofActionTable. */
- int transferPoint;
-
- int getKey() const { return ordering; }
-};
-
-struct ErrActionTable
- : public SBstTable< ErrActionTableEl, int, CmpOrd<int> >
-{
- void setAction( int ordering, Action *action, int transferPoint );
- void setActions( const ErrActionTable &other );
-};
-
-/* Compare of an error action table element (key & value). */
-struct CmpErrActionTableEl
-{
- static int compare( const ErrActionTableEl &action1,
- const ErrActionTableEl &action2 )
- {
- if ( action1.ordering < action2.ordering )
- return -1;
- else if ( action1.ordering > action2.ordering )
- return 1;
- else if ( action1.action < action2.action )
- return -1;
- else if ( action1.action > action2.action )
- return 1;
- else if ( action1.transferPoint < action2.transferPoint )
- return -1;
- else if ( action1.transferPoint > action2.transferPoint )
- return 1;
- return 0;
- }
-};
-
-/* Compare for ErrActionTable. */
-typedef CmpSTable< ErrActionTableEl, CmpErrActionTableEl > CmpErrActionTable;
-
-
-/* Descibe a priority, shared among PriorEls.
- * Has key and whether or not used. */
-struct PriorDesc
-{
- PriorDesc()
- :
- key(0),
- priority(0),
- guarded(false),
- guardId(0),
- other(0)
- {}
-
- int key;
- int priority;
- bool guarded;
- long long guardId;
- PriorDesc *other;
-
- PriorDesc *prev, *next;
-};
-
-typedef DList<PriorDesc> PriorDescList;
-
-/* Element in the arrays of priorities for transitions and arrays. Ordering is
- * unique among instantiations of machines, desc is shared. */
-struct PriorEl
-{
- PriorEl( int ordering, PriorDesc *desc )
- : ordering(ordering), desc(desc) { }
-
- int ordering;
- PriorDesc *desc;
-};
-
-/* Compare priority elements, which are ordered by the priority descriptor
- * key. */
-struct PriorElCmp
-{
- static inline int compare( const PriorEl &pel1, const PriorEl &pel2 )
- {
- if ( pel1.desc->key < pel2.desc->key )
- return -1;
- else if ( pel1.desc->key > pel2.desc->key )
- return 1;
- else
- return 0;
- }
-};
-
-
-/* Priority Table. */
-struct PriorTable
- : public SBstSet< PriorEl, PriorElCmp >
-{
- void setPrior( int ordering, PriorDesc *desc );
- void setPriors( const PriorTable &other );
-};
-
-/* Compare of prior table elements for distinguising state data. */
-struct CmpPriorEl
-{
- static inline int compare( const PriorEl &pel1, const PriorEl &pel2 )
- {
- if ( pel1.desc < pel2.desc )
- return -1;
- else if ( pel1.desc > pel2.desc )
- return 1;
- else if ( pel1.ordering < pel2.ordering )
- return -1;
- else if ( pel1.ordering > pel2.ordering )
- return 1;
- return 0;
- }
-};
-
-/* Compare of PriorTable distinguising state data. Using a compare of the
- * pointers is a little more strict than it needs be. It requires that
- * prioritiy tables have the exact same set of priority assignment operators
- * (from the input lang) to be considered equal.
- *
- * Really only key-value pairs need be tested and ordering be merged. However
- * this would require that in the fuseing of states, priority descriptors be
- * chosen for the new fused state based on priority. Since the out transition
- * lists and ranges aren't necessarily going to line up, this is more work for
- * little gain. Final compression resets all priorities first, so this would
- * only be useful for compression at every operator, which is only an
- * undocumented test feature.
- */
-typedef CmpSTable<PriorEl, CmpPriorEl> CmpPriorTable;
-
-/* Plain action list that imposes no ordering. */
-typedef Vector<int> TransFuncList;
-
-/* Comparison for TransFuncList. */
-typedef CmpTable< int, CmpOrd<int> > TransFuncListCompare;
-
-/* In transition list. Like DList except only has head pointers, which is all
- * that is required. Insertion and deletion is handled by the graph. This class
- * provides the iterator of a single list. */
-template <class Element> struct InList
-{
- InList() : head(0) { }
-
- Element *head;
-
- struct Iter
- {
- /* Default construct. */
- Iter() : ptr(0) { }
-
- /* Construct, assign from a list. */
- Iter( const InList &il ) : ptr(il.head) { }
- Iter &operator=( const InList &dl ) { ptr = dl.head; return *this; }
-
- /* At the end */
- bool lte() const { return ptr != 0; }
- bool end() const { return ptr == 0; }
-
- /* At the first, last element. */
- bool first() const { return ptr && ptr->ilprev == 0; }
- bool last() const { return ptr && ptr->ilnext == 0; }
-
- /* Cast, dereference, arrow ops. */
- operator Element*() const { return ptr; }
- Element &operator *() const { return *ptr; }
- Element *operator->() const { return ptr; }
-
- /* Increment, decrement. */
- inline void operator++(int) { ptr = ptr->ilnext; }
- inline void operator--(int) { ptr = ptr->ilprev; }
-
- /* The iterator is simply a pointer. */
- Element *ptr;
- };
-};
-
-struct TransData
-{
- TransData()
- :
- fromState(0), toState(0)
- {}
-
- TransData( const TransData &other )
- :
- fromState(0), toState(0),
- actionTable(other.actionTable),
- priorTable(other.priorTable),
- lmActionTable(other.lmActionTable)
- {
- }
-
- StateAp *fromState;
- StateAp *toState;
-
- /* The function table and priority for the transition. */
- ActionTable actionTable;
- PriorTable priorTable;
-
- LmActionTable lmActionTable;
-};
-
-
-/* The element for the sub-list within a TransAp. These specify the transitions
- * and are keyed by the condition expressions. */
-struct CondAp
- : public TransData
-{
- CondAp( TransAp *transAp )
- :
- TransData(),
- transAp(transAp),
- key(0)
- {}
-
- CondAp( const CondAp &other, TransAp *transAp )
- :
- TransData( other ),
- transAp(transAp),
- key(other.key)
- {
- }
-
- /* Owning transition. */
- TransAp *transAp;
-
- CondKey key;
-
- /* Pointers for outlist. */
- CondAp *prev, *next;
-
- /* Pointers for in-list. */
- CondAp *ilprev, *ilnext;
-};
-
-typedef DList<CondAp> CondList;
-
-struct TransCondAp;
-struct TransDataAp;
-
-/* Transition class that implements actions and priorities. */
-struct TransAp
-{
- TransAp()
- : condSpace(0) {}
-
- TransAp( const TransAp &other )
- :
- lowKey(other.lowKey),
- highKey(other.highKey),
- condSpace(other.condSpace)
- {
- }
-
- ~TransAp()
- {
- // delete condList.head;
- // condList.abandon();
- }
-
- bool plain() const
- { return condSpace == 0; }
-
- TransCondAp *tcap();
- TransDataAp *tdap();
-
- long condFullSize();
-
- Key lowKey, highKey;
-
- /* Which conditions are tested on this range. */
- CondSpace *condSpace;
-
- /* Pointers for outlist. */
- TransAp *prev, *next;
-};
-
-struct TransCondAp
- : public TransAp
-{
- TransCondAp()
- :
- TransAp()
- {}
-
- TransCondAp( const TransCondAp &other )
- :
- TransAp( other ),
- condList()
- {}
-
- ~TransCondAp()
- {
- condList.empty();
- }
-
- /* Cond trans list. Sorted by key value. */
- CondList condList;
-};
-
-struct TransDataAp
- : public TransAp, public TransData
-{
- TransDataAp()
- :
- TransAp(),
- TransData()
- {}
-
- TransDataAp( const TransDataAp &other )
- :
- TransAp( other ),
- TransData( other )
- {}
-
- /* Pointers for in-list. */
- TransDataAp *ilprev, *ilnext;
-};
-
-inline TransCondAp *TransAp::tcap()
- { return this->condSpace != 0 ? static_cast<TransCondAp*>( this ) : 0; }
-
-inline TransDataAp *TransAp::tdap()
- { return this->condSpace == 0 ? static_cast<TransDataAp*>( this ) : 0; }
-
-typedef DList<TransAp> TransList;
-
-/* Need the base vector type for accessing underlying remove function. */
-typedef BstSet<int> CondKeySet;
-typedef Vector<int> CondKeyVect;
-
-/* State class that implements actions and priorities. */
-
-struct NfaActions
-{
- NfaActions( Action *push, Action *pop, int order )
- : push(push), pop(pop), order(order) {}
-
- Action *push;
- Action *pop;
-
- int order;
-
- ActionTable pushTable;
- ActionTable popTable;
-};
-
-struct NfaTrans
-{
- NfaTrans( int order )
- :
- fromState(0),
- toState(0),
- order(order),
- popCondSpace(0)
- {
- }
-
- NfaTrans( const ActionTable &pushTable,
- const ActionTable &restoreTable,
- const ActionTable &popFrom,
- CondSpace *popCondSpace,
- const CondKeySet popCondKeys,
- const ActionTable &popAction,
- const ActionTable &popTable,
- int order )
- :
- fromState(0), toState(0),
- order(order),
- pushTable(pushTable),
- restoreTable(restoreTable),
- popFrom(popFrom),
- popCondSpace(popCondSpace),
- popCondKeys(popCondKeys),
- popAction(popAction),
- popTest(popTable)
- {}
-
- NfaTrans( const NfaTrans &other )
- :
- fromState(0), toState(0),
- order(other.order),
- pushTable(other.pushTable),
- restoreTable(other.restoreTable),
- popCondSpace(other.popCondSpace),
- popCondKeys(other.popCondKeys),
- popAction(other.popAction),
- popTest(other.popTest),
- priorTable(other.priorTable)
- {}
-
-
- StateAp *fromState;
- StateAp *toState;
-
- int order;
-
- ActionTable pushTable;
- ActionTable restoreTable;
-
- /*
- * 1. Conditions transferred (always tested first)
- * 2. Actions transferred
- * 3. Pop actions created during epsilon draw.
- */
- ActionTable popFrom;
- CondSpace *popCondSpace;
- CondKeySet popCondKeys;
-
- ActionTable popAction;
- ActionTable popTest;
-
- PriorTable priorTable;
-
- NfaTrans *prev, *next;
- NfaTrans *ilprev, *ilnext;
-};
-
-
-typedef BstMap<StateAp*, NfaActions> NfaStateMap;
-typedef BstMapEl<StateAp*, NfaActions> NfaStateMapEl;
-
-typedef DList<NfaTrans> NfaTransList;
-typedef InList<NfaTrans> NfaInList;
-
-struct CmpNfaTrans
-{
- static int compare( NfaTrans *t1, NfaTrans *t2 )
- {
- /* This comparison is too strong. (okay to use something too strong --
- * we just don't find minimal). * */
- if ( t1->toState < t2->toState )
- return -1;
- else if ( t1->toState > t2->toState )
- return 1;
- else if ( t1->order < t2->order )
- return -1;
- else if ( t1->order > t2->order )
- return 1;
- else
- {
- int r = CmpActionTable::compare( t1->pushTable, t2->pushTable );
- if ( r != 0 )
- return r;
-
- r = CmpActionTable::compare( t1->restoreTable, t2->restoreTable );
- if ( r != 0 )
- return r;
-
- if ( t1->popCondSpace < t2->popCondSpace )
- return -1;
- else if ( t1->popCondSpace > t2->popCondSpace )
- return 1;
-
- r = CmpTable<int>::compare( t1->popCondKeys, t2->popCondKeys );
- if ( r != 0 )
- return r;
-
- r = CmpActionTable::compare( t1->popTest, t2->popTest );
- if ( r != 0 )
- return r;
-
- r = CmpActionTable::compare( t1->popAction, t2->popAction );
- if ( r != 0 )
- return r;
- }
-
- return 0;
- }
-};
-
-struct CmpNfaTransList
-{
- static int compare( const NfaTransList &l1, const NfaTransList &l2 )
- {
- if ( l1.length() < l2.length() )
- return -1;
- else if ( l1.length() > l2.length() )
- return 1;
- else {
- NfaTransList::Iter i1 = l1;
- NfaTransList::Iter i2 = l2;
- while ( i1.lte() ) {
- int r = CmpNfaTrans::compare( i1, i2 );
- if ( r != 0 )
- return r;
- i1++, i2++;
- }
- }
- return 0;
- }
-};
-
-struct CmpNfaStateMapEl
-{
- static int compare( const NfaStateMapEl &el1, const NfaStateMapEl &el2 )
- {
- if ( el1.key < el2.key )
- return -1;
- else if ( el1.key > el2.key )
- return 1;
- else if ( el1.value.push < el2.value.push )
- return -1;
- else if ( el1.value.push > el2.value.push )
- return 1;
- else if ( el1.value.pop < el2.value.pop )
- return -1;
- else if ( el1.value.pop > el2.value.pop )
- return 1;
- else if ( el1.value.order < el2.value.order )
- return -1;
- else if ( el1.value.order > el2.value.order )
- return 1;
- return 0;
- }
-};
-
-/* Set of states, list of states. */
-typedef BstSet<StateAp*> StateSet;
-typedef DList<StateAp> StateList;
-
-/* A element in a state dict. */
-struct StateDictEl
-:
- public AvlTreeEl<StateDictEl>
-{
- StateDictEl(const StateSet &stateSet)
- : stateSet(stateSet) { }
-
- const StateSet &getKey() { return stateSet; }
- StateSet stateSet;
- StateAp *targState;
-};
-
-/* Dictionary mapping a set of states to a target state. */
-typedef AvlTree< StateDictEl, StateSet, CmpTable<StateAp*> > StateDict;
-
-struct TransEl
-{
- /* Constructors. */
- TransEl() { }
- TransEl( Key lowKey, Key highKey )
- : lowKey(lowKey), highKey(highKey) { }
- TransEl( Key lowKey, Key highKey, TransAp *value )
- : lowKey(lowKey), highKey(highKey), value(value) { }
-
- Key lowKey, highKey;
- TransAp *value;
-};
-
-struct CmpKey
-{
- CmpKey()
- : keyOps(0) {}
-
- KeyOps *keyOps;
-
- int compare( const Key key1, const Key key2 )
- {
- if ( keyOps->lt( key1, key2 ) )
- return -1;
- else if ( keyOps->gt( key1, key2 ) )
- return 1;
- else
- return 0;
- }
-};
-
-/* Vector based set of key items. */
-struct KeySet
-:
- public BstSet<Key, CmpKey>
-{
- KeySet( KeyOps *keyOps )
- {
- CmpKey::keyOps = keyOps;
- }
-};
-
-struct MinPartition
-{
- MinPartition() : active(false) { }
-
- StateList list;
- bool active;
-
- MinPartition *prev, *next;
-};
-
-/* Epsilon transition stored in a state. Specifies the target */
-typedef Vector<int> EpsilonTrans;
-
-/* List of states that are to be drawn into this. */
-struct EptVectEl
-{
- EptVectEl( StateAp *targ, bool leaving )
- : targ(targ), leaving(leaving) { }
-
- StateAp *targ;
- bool leaving;
-};
-typedef Vector<EptVectEl> EptVect;
-
-/* Set of entry ids that go into this state. */
-typedef BstSet<int> EntryIdSet;
-
-/* Set of longest match items that may be active in a given state. */
-typedef BstSet<LongestMatchPart*> LmItemSet;
-
-/* A Conditions which is to be
- * transfered on pending out transitions. */
-struct OutCond
-{
- OutCond( Action *action, bool sense )
- : action(action), sense(sense) {}
-
- Action *action;
- bool sense;
-};
-
-struct CmpOutCond
-{
- static int compare( const OutCond &outCond1, const OutCond &outCond2 )
- {
- if ( outCond1.action < outCond2.action )
- return -1;
- else if ( outCond1.action > outCond2.action )
- return 1;
- else if ( outCond1.sense < outCond2.sense )
- return -1;
- else if ( outCond1.sense > outCond2.sense )
- return 1;
- return 0;
- }
-};
-
-/* Conditions. */
-typedef BstSet< Action*, CmpCondId > CondSet;
-typedef CmpTable< Action*, CmpCondId > CmpCondSet;
-
-struct CondSpace
- : public AvlTreeEl<CondSpace>
-{
- CondSpace( const CondSet &condSet )
- : condSet(condSet) {}
-
- const CondSet &getKey() { return condSet; }
-
- long fullSize()
- { return ( 1 << condSet.length() ); }
-
- CondSet condSet;
- long condSpaceId;
-};
-
-typedef Vector<CondSpace*> CondSpaceVect;
-
-typedef AvlTree<CondSpace, CondSet, CmpCondSet> CondSpaceMap;
-
-typedef Vector<long> LongVect;
-
-struct CondData
-{
- CondSpaceMap condSpaceMap;
-
- ~CondData()
- {
- condSpaceMap.empty();
- }
-};
-
-struct FsmGbl
-{
- FsmGbl( const HostLang *hostLang )
- :
- printStatistics(false),
- errorCount(0),
- displayPrintables(false),
- hostLang(hostLang),
- stringTables(false),
- checkPriorInteraction(0),
- wantDupsRemoved(true),
- minimizeLevel(MinimizePartition2),
- minimizeOpt(MinimizeMostOps)
- {}
-
- bool printStatistics;
-
- /*
- * Error reporting.
- */
-
- /* PROGNAME: txt */
- std::ostream &error();
-
- /* file:loc: txt */
- std::ostream &error( const InputLoc &loc );
-
- /* txt */
- std::ostream &error_plain();
-
- /* file:loc: warning: txt */
- std::ostream &warning( const InputLoc &loc );
-
- /* Stats reporting. */
- std::ostream &stats();
-
- /* Requested info. */
- std::ostream &info();
-
- std::stringstream libcerr;
- std::stringstream libcout;
-
- int errorCount;
- void abortCompile( int code );
- bool displayPrintables;
-
- const HostLang *hostLang;
- bool stringTables;
- bool checkPriorInteraction;
- bool wantDupsRemoved;
-
- MinimizeLevel minimizeLevel;
- MinimizeOpt minimizeOpt;
-};
-
-/* All FSM operations must be between machines that have been created using the
- * same context object. */
-struct FsmCtx
-{
- FsmCtx( FsmGbl *fsmGbl );
- ~FsmCtx();
-
- KeyOps *keyOps;
- CondData *condData;
- MinimizeLevel minimizeLevel;
- MinimizeOpt minimizeOpt;
-
- static const int STATE_UNLIMITED = 0;
-
- long stateLimit;
- bool printStatistics;
- bool checkPriorInteraction;
-
- bool unionOp;
-
- long condsCheckDepth;
-
- /* Counting the action and priority ordering. */
- int curActionOrd;
- int curPriorOrd;
-
- int nextPriorKey;
- int nextCondId;
-
- PriorDesc *allocPriorDesc()
- {
- PriorDesc *priorDesc = new PriorDesc();
- priorDescList.append( priorDesc );
- return priorDesc;
- }
-
- PriorDescList priorDescList;
-
- FsmGbl *fsmGbl;
-
- /* List of actions. Will be pasted into a switch statement. */
- ActionList actionList;
-
- ExportList exportList;
-
- bool generatingSectionSubset;
- bool lmRequiresErrorState;
-
- /* Make name ids to name inst pointers. */
- NameInst **nameIndex;
-
- /* Element type and get key expression. */
- InlineList *getKeyExpr;
- InlineList *accessExpr;
-
- /* Stack management */
- InlineBlock *prePushExpr;
- InlineBlock *postPopExpr;
-
- /* Nfa stack managment. */
- InlineBlock *nfaPrePushExpr;
- InlineBlock *nfaPostPopExpr;
-
- /* Overriding variables. */
- InlineList *pExpr;
- InlineList *peExpr;
- InlineList *eofExpr;
- InlineList *csExpr;
- InlineList *topExpr;
- InlineList *stackExpr;
- InlineList *actExpr;
- InlineList *tokstartExpr;
- InlineList *tokendExpr;
- InlineList *dataExpr;
-
- Action *newNfaWrapAction( const char *name, InlineList *inlineList, Action *optWrap );
- void createNfaActions( FsmAp *fsm );
-
- /* Checking the contents of actions. */
- void checkAction( Action *action );
- void checkInlineList( Action *act, InlineList *inlineList );
-
- void analyzeAction( Action *action, InlineList *inlineList );
- void analyzeGraph( FsmAp *graph );
-
- void finalizeInstance( FsmAp *graph );
- void prepareReduction( FsmAp *sectionGraph );
-};
-
-typedef InList<CondAp> CondInList;
-typedef InList<TransDataAp> TransInList;
-
-struct NfaStateEl
-{
- StateAp *prev, *next;
-};
-
-typedef DListMel<StateAp, NfaStateEl> NfaStateList;
-
-struct StateAp
- : public NfaStateEl
-{
- StateAp();
- StateAp(const StateAp &other);
- ~StateAp();
-
- /* Is the state final? */
- bool isFinState() { return stateBits & STB_ISFINAL; }
-
- /* Out transition list and the pointer for the default out trans. */
- TransList outList;
-
- /* In transition Lists. */
- TransInList inTrans;
- CondInList inCond;
-
- /* Set only during scanner construction when actions are added. NFA to DFA
- * code can ignore this. */
- StateAp *eofTarget;
-
- /* Entry points into the state. */
- EntryIdSet entryIds;
-
- /* Epsilon transitions. */
- EpsilonTrans epsilonTrans;
-
- /* Number of in transitions from states other than ourselves. */
- int foreignInTrans;
-
- /* Temporary data for various algorithms. */
- union {
- /* When duplicating the fsm we need to map each
- * state to the new state representing it. */
- StateAp *stateMap;
-
- /* When minimizing machines by partitioning, this maps to the group
- * the state is in. */
- MinPartition *partition;
-
- /* Identification for printing and stable minimization. */
- int stateNum;
-
- } alg;
-
- /* Data used in epsilon operation, maybe fit into alg? */
- StateAp *isolatedShadow;
- int owningGraph;
-
- /* A pointer to a dict element that contains the set of states this state
- * represents. This cannot go into alg, because alg.next is used during
- * the merging process. */
- StateDictEl *stateDictEl;
- StateSet *stateDictIn;
-
- NfaTransList *nfaOut;
- NfaInList *nfaIn;
-
- /* When drawing epsilon transitions, holds the list of states to merge
- * with. */
- EptVect *eptVect;
-
- /* Bits controlling the behaviour of the state during collapsing to dfa. */
- int stateBits;
-
- /* State list elements. */
- StateAp *next, *prev;
-
- /*
- * Priority and Action data.
- */
-
- /* Out priorities transfered to out transitions. */
- PriorTable outPriorTable;
-
- /* The following two action tables are distinguished by the fact that when
- * toState actions are executed immediatly after transition actions of
- * incoming transitions and the current character will be the same as the
- * one available then. The fromState actions are executed immediately
- * before the transition actions of outgoing transitions and the current
- * character is same as the one available then. */
-
- /* Actions to execute upon entering into a state. */
- ActionTable toStateActionTable;
-
- /* Actions to execute when going from the state to the transition. */
- ActionTable fromStateActionTable;
-
- /* Actions to add to any future transitions that leave via this state. */
- ActionTable outActionTable;
-
- /* Conditions to add to any future transiions that leave via this state. */
- CondSpace *outCondSpace;
- CondKeySet outCondKeys;
-
- /* Error action tables. */
- ErrActionTable errActionTable;
-
- /* Actions to execute on eof. */
- ActionTable eofActionTable;
-
- /* Set of longest match items that may be active in this state. */
- LmItemSet lmItemSet;
-
- PriorTable guardedInTable;
-
- /* Used by the NFA-based scanner to track the origin of final states. We
- * only use it in cases where just one match is possible, starting with the
- * final state duplicates that are drawn using NFA transitions. */
- LmItemSet lmNfaParts;
-};
-
-/* Return and re-entry for the co-routine iterators. This should ALWAYS be
- * used inside of a block. */
-#define CO_RETURN(label) \
- itState = label; \
- return; \
- entry##label: {}
-
-/* Return and re-entry for the co-routine iterators. This should ALWAYS be
- * used inside of a block. */
-#define CO_RETURN2(label, uState) \
- itState = label; \
- userState = uState; \
- return; \
- entry##label: {}
-
-template <class Item> struct PiList
-{
- PiList()
- : ptr(0) {}
-
- PiList( const DList<Item> &l )
- : ptr(l.head) {}
-
- PiList( Item *ptr )
- : ptr(ptr) {}
-
- operator Item *() const { return ptr; }
- Item *operator->() const { return ptr; }
-
- bool end() { return ptr == 0; }
- void clear() { ptr = 0; }
-
- PiList next()
- { return PiList( ptr->next ); }
-
- Item *ptr;
-};
-
-template <class Item> struct PiSingle
-{
- PiSingle()
- : ptr(0) {}
-
- PiSingle( Item *ptr )
- : ptr(ptr) {}
-
- operator Item *() const { return ptr; }
- Item *operator->() const { return ptr; }
-
- bool end() { return ptr == 0; }
- void clear() { ptr = 0; }
-
- /* Next is always nil. */
- PiSingle next()
- { return PiSingle( 0 ); }
-
- Item *ptr;
-};
-
-template <class Item> struct PiVector
-{
- PiVector()
- : ptr(0), length(0) {}
-
- PiVector( const Vector<Item> &v )
- : ptr(v.data), length(v.length()) {}
-
- PiVector( Item *ptr, long length )
- : ptr(ptr), length(length) {}
-
- operator Item *() const { return ptr; }
- Item *operator->() const { return ptr; }
-
- bool end() { return length == 0; }
- void clear() { ptr = 0; length = 0; }
-
- PiVector next()
- { return PiVector( ptr + 1, length - 1 ); }
-
- Item *ptr;
- long length;
-};
-
-
-template <class ItemIter1, class ItemIter2 = ItemIter1> struct ValPairIter
-{
- /* Encodes the states that are meaningful to the of caller the iterator. */
- enum UserState
- {
- RangeInS1, RangeInS2,
- RangeOverlap,
- };
-
- /* Encodes the different states that an fsm iterator can be in. */
- enum IterState {
- Begin,
- ConsumeS1Range, ConsumeS2Range,
- OnlyInS1Range, OnlyInS2Range,
- ExactOverlap, End
- };
-
- ValPairIter( const ItemIter1 &list1, const ItemIter2 &list2 );
-
- template <class ItemIter> struct NextTrans
- {
- CondKey key;
- ItemIter trans;
- ItemIter next;
-
- NextTrans() { key = 0; }
-
- void load() {
- if ( trans.end() )
- next.clear();
- else {
- next = trans->next;
- key = trans->key;
- }
- }
-
- void set( const ItemIter &t ) {
- trans = t;
- load();
- }
-
- void increment() {
- trans = next;
- load();
- }
- };
-
- /* Query iterator. */
- bool lte() { return itState != End; }
- bool end() { return itState == End; }
- void operator++(int) { findNext(); }
- void operator++() { findNext(); }
-
- /* Iterator state. */
- ItemIter1 list1;
- ItemIter2 list2;
- IterState itState;
- UserState userState;
-
- NextTrans<ItemIter1> s1Tel;
- NextTrans<ItemIter2> s2Tel;
- Key bottomLow, bottomHigh;
- ItemIter1 *bottomTrans1;
- ItemIter2 *bottomTrans2;
-
-private:
- void findNext();
-};
-
-/* Init the iterator by advancing to the first item. */
-template <class ItemIter1, class ItemIter2>
- ValPairIter<ItemIter1, ItemIter2>::
- ValPairIter( const ItemIter1 &list1, const ItemIter2 &list2 )
-:
- list1(list1),
- list2(list2),
- itState(Begin)
-{
- findNext();
-}
-
-/* Advance to the next transition. When returns, trans points to the next
- * transition, unless there are no more, in which case end() returns true. */
-template <class ItemIter1, class ItemIter2>
- void ValPairIter<ItemIter1, ItemIter2>::findNext()
-{
- /* Jump into the iterator routine base on the iterator state. */
- switch ( itState ) {
- case Begin: goto entryBegin;
- case ConsumeS1Range: goto entryConsumeS1Range;
- case ConsumeS2Range: goto entryConsumeS2Range;
- case OnlyInS1Range: goto entryOnlyInS1Range;
- case OnlyInS2Range: goto entryOnlyInS2Range;
- case ExactOverlap: goto entryExactOverlap;
- case End: goto entryEnd;
- }
-
-entryBegin:
- /* Set up the next structs at the head of the transition lists. */
- s1Tel.set( list1 );
- s2Tel.set( list2 );
-
- /* Concurrently scan both out ranges. */
- while ( true ) {
- if ( s1Tel.trans.end() ) {
- /* We are at the end of state1's ranges. Process the rest of
- * state2's ranges. */
- while ( !s2Tel.trans.end() ) {
- /* Range is only in s2. */
- CO_RETURN2( ConsumeS2Range, RangeInS2 );
- s2Tel.increment();
- }
- break;
- }
- else if ( s2Tel.trans.end() ) {
- /* We are at the end of state2's ranges. Process the rest of
- * state1's ranges. */
- while ( !s1Tel.trans.end() ) {
- /* Range is only in s1. */
- CO_RETURN2( ConsumeS1Range, RangeInS1 );
- s1Tel.increment();
- }
- break;
- }
- /* Both state1's and state2's transition elements are good.
- * The signiture of no overlap is a back key being in front of a
- * front key. */
- else if ( s1Tel.key < s2Tel.key ) {
- /* A range exists in state1 that does not overlap with state2. */
- CO_RETURN2( OnlyInS1Range, RangeInS1 );
- s1Tel.increment();
- }
- else if ( s2Tel.key < s1Tel.key ) {
- /* A range exists in state2 that does not overlap with state1. */
- CO_RETURN2( OnlyInS2Range, RangeInS2 );
- s2Tel.increment();
- }
- else {
- /* There is an exact overlap. */
- CO_RETURN2( ExactOverlap, RangeOverlap );
-
- s1Tel.increment();
- s2Tel.increment();
- }
- }
-
- /* Done, go into end state. */
- CO_RETURN( End );
-}
-
-template <class ItemIter1, class ItemIter2 = ItemIter1> struct RangePairIter
-{
- /* Encodes the states that are meaningful to the of caller the iterator. */
- enum UserState
- {
- RangeInS1, RangeInS2,
- RangeOverlap,
- BreakS1, BreakS2
- };
-
- /* Encodes the different states that an fsm iterator can be in. */
- enum IterState {
- Begin,
- ConsumeS1Range, ConsumeS2Range,
- OnlyInS1Range, OnlyInS2Range,
- S1SticksOut, S1SticksOutBreak,
- S2SticksOut, S2SticksOutBreak,
- S1DragsBehind, S1DragsBehindBreak,
- S2DragsBehind, S2DragsBehindBreak,
- ExactOverlap, End
- };
-
- RangePairIter( FsmCtx *ctx, const ItemIter1 &list1, const ItemIter2 &list2 );
-
- template <class ItemIter> struct NextTrans
- {
- Key lowKey, highKey;
- ItemIter trans;
- ItemIter next;
-
- NextTrans()
- {
- highKey = 0;
- lowKey = 0;
- }
-
- void load() {
- if ( trans.end() )
- next.clear();
- else {
- next = trans.next();
- lowKey = trans->lowKey;
- highKey = trans->highKey;
- }
- }
-
- void set( const ItemIter &t ) {
- trans = t;
- load();
- }
-
- void increment() {
- trans = next;
- load();
- }
- };
-
- /* Query iterator. */
- bool lte() { return itState != End; }
- bool end() { return itState == End; }
- void operator++(int) { findNext(); }
- void operator++() { findNext(); }
-
- FsmCtx *ctx;
-
- /* Iterator state. */
- ItemIter1 list1;
- ItemIter2 list2;
- IterState itState;
- UserState userState;
-
- NextTrans<ItemIter1> s1Tel;
- NextTrans<ItemIter2> s2Tel;
- Key bottomLow, bottomHigh;
- ItemIter1 bottomTrans1;
- ItemIter2 bottomTrans2;
-
-private:
- void findNext();
-};
-
-/* Init the iterator by advancing to the first item. */
-template <class ItemIter1, class ItemIter2> RangePairIter<ItemIter1, ItemIter2>::
- RangePairIter( FsmCtx *ctx, const ItemIter1 &list1, const ItemIter2 &list2 )
-:
- ctx(ctx),
- list1(list1),
- list2(list2),
- itState(Begin)
-{
- bottomLow = 0;
- bottomHigh = 0;
- findNext();
-}
-
-/* Advance to the next transition. When returns, trans points to the next
- * transition, unless there are no more, in which case end() returns true. */
-template <class ItemIter1, class ItemIter2>
- void RangePairIter<ItemIter1, ItemIter2>::findNext()
-{
- /* Jump into the iterator routine base on the iterator state. */
- switch ( itState ) {
- case Begin: goto entryBegin;
- case ConsumeS1Range: goto entryConsumeS1Range;
- case ConsumeS2Range: goto entryConsumeS2Range;
- case OnlyInS1Range: goto entryOnlyInS1Range;
- case OnlyInS2Range: goto entryOnlyInS2Range;
- case S1SticksOut: goto entryS1SticksOut;
- case S1SticksOutBreak: goto entryS1SticksOutBreak;
- case S2SticksOut: goto entryS2SticksOut;
- case S2SticksOutBreak: goto entryS2SticksOutBreak;
- case S1DragsBehind: goto entryS1DragsBehind;
- case S1DragsBehindBreak: goto entryS1DragsBehindBreak;
- case S2DragsBehind: goto entryS2DragsBehind;
- case S2DragsBehindBreak: goto entryS2DragsBehindBreak;
- case ExactOverlap: goto entryExactOverlap;
- case End: goto entryEnd;
- }
-
-entryBegin:
- /* Set up the next structs at the head of the transition lists. */
- s1Tel.set( list1 );
- s2Tel.set( list2 );
-
- /* Concurrently scan both out ranges. */
- while ( true ) {
- if ( s1Tel.trans.end() ) {
- /* We are at the end of state1's ranges. Process the rest of
- * state2's ranges. */
- while ( !s2Tel.trans.end() ) {
- /* Range is only in s2. */
- CO_RETURN2( ConsumeS2Range, RangeInS2 );
- s2Tel.increment();
- }
- break;
- }
- else if ( s2Tel.trans.end() ) {
- /* We are at the end of state2's ranges. Process the rest of
- * state1's ranges. */
- while ( !s1Tel.trans.end() ) {
- /* Range is only in s1. */
- CO_RETURN2( ConsumeS1Range, RangeInS1 );
- s1Tel.increment();
- }
- break;
- }
- /* Both state1's and state2's transition elements are good.
- * The signiture of no overlap is a back key being in front of a
- * front key. */
- else if ( ctx->keyOps->lt( s1Tel.highKey, s2Tel.lowKey ) ) {
- /* A range exists in state1 that does not overlap with state2. */
- CO_RETURN2( OnlyInS1Range, RangeInS1 );
- s1Tel.increment();
- }
- else if ( ctx->keyOps->lt( s2Tel.highKey, s1Tel.lowKey ) ) {
- /* A range exists in state2 that does not overlap with state1. */
- CO_RETURN2( OnlyInS2Range, RangeInS2 );
- s2Tel.increment();
- }
- /* There is overlap, must mix the ranges in some way. */
- else if ( ctx->keyOps->lt( s1Tel.lowKey, s2Tel.lowKey ) ) {
- /* Range from state1 sticks out front. Must break it into
- * non-overlaping and overlaping segments. */
- bottomLow = s2Tel.lowKey;
- bottomHigh = s1Tel.highKey;
- s1Tel.highKey = s2Tel.lowKey;
- ctx->keyOps->decrement( s1Tel.highKey );
- bottomTrans1 = s1Tel.trans;
-
- /* Notify the caller that we are breaking s1. This gives them a
- * chance to duplicate s1Tel[0,1].value. */
- CO_RETURN2( S1SticksOutBreak, BreakS1 );
-
- /* Broken off range is only in s1. */
- CO_RETURN2( S1SticksOut, RangeInS1 );
-
- /* Advance over the part sticking out front. */
- s1Tel.lowKey = bottomLow;
- s1Tel.highKey = bottomHigh;
- s1Tel.trans = bottomTrans1;
- }
- else if ( ctx->keyOps->lt( s2Tel.lowKey, s1Tel.lowKey ) ) {
- /* Range from state2 sticks out front. Must break it into
- * non-overlaping and overlaping segments. */
- bottomLow = s1Tel.lowKey;
- bottomHigh = s2Tel.highKey;
- s2Tel.highKey = s1Tel.lowKey;
- ctx->keyOps->decrement( s2Tel.highKey );
- bottomTrans2 = s2Tel.trans;
-
- /* Notify the caller that we are breaking s2. This gives them a
- * chance to duplicate s2Tel[0,1].value. */
- CO_RETURN2( S2SticksOutBreak, BreakS2 );
-
- /* Broken off range is only in s2. */
- CO_RETURN2( S2SticksOut, RangeInS2 );
-
- /* Advance over the part sticking out front. */
- s2Tel.lowKey = bottomLow;
- s2Tel.highKey = bottomHigh;
- s2Tel.trans = bottomTrans2;
- }
- /* Low ends are even. Are the high ends even? */
- else if ( ctx->keyOps->lt( s1Tel.highKey, s2Tel.highKey ) ) {
- /* Range from state2 goes longer than the range from state1. We
- * must break the range from state2 into an evenly overlaping
- * segment. */
- bottomLow = s1Tel.highKey;
- ctx->keyOps->increment( bottomLow );
- bottomHigh = s2Tel.highKey;
- s2Tel.highKey = s1Tel.highKey;
- bottomTrans2 = s2Tel.trans;
-
- /* Notify the caller that we are breaking s2. This gives them a
- * chance to duplicate s2Tel[0,1].value. */
- CO_RETURN2( S2DragsBehindBreak, BreakS2 );
-
- /* Breaking s2 produces exact overlap. */
- CO_RETURN2( S2DragsBehind, RangeOverlap );
-
- /* Advance over the front we just broke off of range 2. */
- s2Tel.lowKey = bottomLow;
- s2Tel.highKey = bottomHigh;
- s2Tel.trans = bottomTrans2;
-
- /* Advance over the entire s1Tel. We have consumed it. */
- s1Tel.increment();
- }
- else if ( ctx->keyOps->lt( s2Tel.highKey, s1Tel.highKey ) ) {
- /* Range from state1 goes longer than the range from state2. We
- * must break the range from state1 into an evenly overlaping
- * segment. */
- bottomLow = s2Tel.highKey;
- ctx->keyOps->increment( bottomLow );
- bottomHigh = s1Tel.highKey;
- s1Tel.highKey = s2Tel.highKey;
- bottomTrans1 = s1Tel.trans;
-
- /* Notify the caller that we are breaking s1. This gives them a
- * chance to duplicate s2Tel[0,1].value. */
- CO_RETURN2( S1DragsBehindBreak, BreakS1 );
-
- /* Breaking s1 produces exact overlap. */
- CO_RETURN2( S1DragsBehind, RangeOverlap );
-
- /* Advance over the front we just broke off of range 1. */
- s1Tel.lowKey = bottomLow;
- s1Tel.highKey = bottomHigh;
- s1Tel.trans = bottomTrans1;
-
- /* Advance over the entire s2Tel. We have consumed it. */
- s2Tel.increment();
- }
- else {
- /* There is an exact overlap. */
- CO_RETURN2( ExactOverlap, RangeOverlap );
-
- s1Tel.increment();
- s2Tel.increment();
- }
- }
-
- /* Done, go into end state. */
- CO_RETURN( End );
-}
-
-
-/* Compare lists of epsilon transitions. Entries are name ids of targets. */
-typedef CmpTable< int, CmpOrd<int> > CmpEpsilonTrans;
-
-/* Compare class for the Approximate minimization. */
-class ApproxCompare
-{
-public:
- ApproxCompare( FsmCtx *ctx = 0 ) : ctx(ctx) { }
- int compare( const StateAp *pState1, const StateAp *pState2 );
- FsmCtx *ctx;
-};
-
-/* Compare class for the initial partitioning of a partition minimization. */
-class InitPartitionCompare
-{
-public:
- InitPartitionCompare( FsmCtx *ctx = 0 ) : ctx(ctx) { }
- int compare( const StateAp *pState1, const StateAp *pState2 );
- FsmCtx *ctx;
-};
-
-/* Compare class for the regular partitioning of a partition minimization. */
-class PartitionCompare
-{
-public:
- PartitionCompare( FsmCtx *ctx = 0 ) : ctx(ctx) { }
- int compare( const StateAp *pState1, const StateAp *pState2 );
- FsmCtx *ctx;
-};
-
-/* Compare class for a minimization that marks pairs. Provides the shouldMark
- * routine. */
-class MarkCompare
-{
-public:
- MarkCompare( FsmCtx *ctx ) : ctx(ctx) { }
- bool shouldMark( MarkIndex &markIndex, const StateAp *pState1,
- const StateAp *pState2 );
- FsmCtx *ctx;
-};
-
-/* List of partitions. */
-typedef DList< MinPartition > PartitionList;
-
-/* List of transtions out of a state. */
-typedef Vector<TransEl> TransListVect;
-
-/* Entry point map used for keeping track of entry points in a machine. */
-typedef BstSet< int > EntryIdSet;
-typedef BstMapEl< int, StateAp* > EntryMapEl;
-typedef BstMap< int, StateAp* > EntryMap;
-typedef Vector<EntryMapEl> EntryMapBase;
-
-struct BreadthCost
-{
- BreadthCost( std::string name, double cost )
- : name(name), cost(cost) {}
-
- std::string name;
- double cost;
-};
-
-struct BreadthResult
-{
- BreadthResult( double start ) : start(start) {}
-
- double start;
- Vector<BreadthCost> costs;
-};
-
-/* Result of an operation. */
-struct FsmRes
-{
- struct Fsm {};
- struct TooManyStates {};
- struct PriorInteraction {};
- struct CondCostTooHigh {};
- struct InternalError {};
-
- enum Type
- {
- TypeFsm = 1,
- TypeTooManyStates,
- TypePriorInteraction,
- TypeCondCostTooHigh,
- TypeInternalError,
- };
-
- FsmRes( const Fsm &, FsmAp *fsm )
- : fsm(fsm), type(TypeFsm) {}
-
- FsmRes( const TooManyStates & )
- : fsm(0), type(TypeTooManyStates) {}
-
- FsmRes( const PriorInteraction &, long long guardId )
- : fsm(0), type(TypePriorInteraction), id(guardId) {}
-
- FsmRes( const CondCostTooHigh &, long long costId )
- : fsm(0), type(TypeCondCostTooHigh), id(costId) {}
-
- FsmRes( const InternalError & )
- : fsm(0), type(TypeInternalError) {}
-
- bool success()
- { return fsm != 0; }
-
- operator FsmAp*()
- { return type == TypeFsm ? fsm : 0; }
- FsmAp *operator->()
- { return type == TypeFsm ? fsm : 0; }
-
- FsmAp *fsm;
- Type type;
- long long id;
-};
-
-/* Graph class that implements actions and priorities. */
-struct FsmAp
-{
- /* Constructors/Destructors. */
- FsmAp( FsmCtx *ctx );
- FsmAp( const FsmAp &graph );
- ~FsmAp();
-
- FsmCtx *ctx;
-
- bool priorInteraction;
- int guardId;
-
- /* The list of states. */
- StateList stateList;
- StateList misfitList;
- NfaStateList nfaList;
- StateDict stateDict;
-
- /* The map of entry points. */
- EntryMap entryPoints;
-
- /* The start state. */
- StateAp *startState;
-
- /* Error state, possibly created only when the final machine has been
- * created and the XML machine is about to be written. No transitions
- * point to this state. */
- StateAp *errState;
-
- /* The set of final states. */
- StateSet finStateSet;
-
- /* Misfit Accounting. Are misfits put on a separate list. */
- bool misfitAccounting;
-
- /*
- * Transition actions and priorities.
- */
-
- /* Set priorities on transtions. */
- void startFsmPrior( int ordering, PriorDesc *prior );
- void allTransPrior( int ordering, PriorDesc *prior );
- void finishFsmPrior( int ordering, PriorDesc *prior );
- void leaveFsmPrior( int ordering, PriorDesc *prior );
-
- /* Action setting support. */
- void transferOutActions( StateAp *state );
- void transferErrorActions( StateAp *state, int transferPoint );
- void setErrorActions( StateAp *state, const ActionTable &other );
- void setErrorAction( StateAp *state, int ordering, Action *action );
-
- /* Fill all spaces in a transition list with an error transition. */
- void fillGaps( StateAp *state );
-
- /* Similar to setErrorAction, instead gives a state to go to on error. */
- void setErrorTarget( StateAp *state, StateAp *target, int *orderings,
- Action **actions, int nActs );
-
- /* Set actions to execute. */
- void startFsmAction( int ordering, Action *action );
- void allTransAction( int ordering, Action *action );
- void finishFsmAction( int ordering, Action *action );
- void leaveFsmAction( int ordering, Action *action );
- void longMatchAction( int ordering, LongestMatchPart *lmPart );
-
- /* Set conditions. */
- CondSpace *addCondSpace( const CondSet &condSet );
-
- void convertToCondAp( StateAp *state );
-
-private:
- /* Can generate states. */
- void doEmbedCondition( StateAp *state,
- const CondSet &set, const CondKeySet &vals );
-
-
-public:
- static FsmRes embedCondition( FsmAp *fsm, StateAp *state, const CondSet &set,
- const CondKeySet &vals );
-
- FsmRes startFsmCondition( Action *condAction, bool sense );
- void allTransCondition( Action *condAction, bool sense );
- void leaveFsmCondition( Action *condAction, bool sense );
-
- /* Set error actions to execute. */
- void startErrorAction( int ordering, Action *action, int transferPoint );
- void allErrorAction( int ordering, Action *action, int transferPoint );
- void finalErrorAction( int ordering, Action *action, int transferPoint );
- void notStartErrorAction( int ordering, Action *action, int transferPoint );
- void notFinalErrorAction( int ordering, Action *action, int transferPoint );
- void middleErrorAction( int ordering, Action *action, int transferPoint );
-
- /* Set EOF actions. */
- void startEOFAction( int ordering, Action *action );
- void allEOFAction( int ordering, Action *action );
- void finalEOFAction( int ordering, Action *action );
- void notStartEOFAction( int ordering, Action *action );
- void notFinalEOFAction( int ordering, Action *action );
- void middleEOFAction( int ordering, Action *action );
-
- /* Set To State actions. */
- void startToStateAction( int ordering, Action *action );
- void allToStateAction( int ordering, Action *action );
- void finalToStateAction( int ordering, Action *action );
- void notStartToStateAction( int ordering, Action *action );
- void notFinalToStateAction( int ordering, Action *action );
- void middleToStateAction( int ordering, Action *action );
-
- /* Set From State actions. */
- void startFromStateAction( int ordering, Action *action );
- void allFromStateAction( int ordering, Action *action );
- void finalFromStateAction( int ordering, Action *action );
- void notStartFromStateAction( int ordering, Action *action );
- void notFinalFromStateAction( int ordering, Action *action );
- void middleFromStateAction( int ordering, Action *action );
-
- /* Shift the action ordering of the start transitions to start at
- * fromOrder and increase in units of 1. Useful before kleene star
- * operation. */
- int shiftStartActionOrder( int fromOrder );
-
- /* Clear all priorities from the fsm to so they won't affcet minimization
- * of the final fsm. */
- void clearAllPriorities();
-
- /* Zero out all the function keys. */
- void nullActionKeys();
-
- /* Walk the list of states and verify state properties. */
- void verifyStates();
-
- /* Misfit Accounting. Are misfits put on a separate list. */
- void setMisfitAccounting( bool val )
- { misfitAccounting = val; }
-
- /* Set and Unset a state as final. */
- void setFinState( StateAp *state );
- void unsetFinState( StateAp *state );
-
- void setStartState( StateAp *state );
- void unsetStartState( );
-
- /* Set and unset a state as an entry point. */
- void setEntry( int id, StateAp *state );
- void changeEntry( int id, StateAp *to, StateAp *from );
- void unsetEntry( int id, StateAp *state );
- void unsetEntry( int id );
- void unsetAllEntryPoints();
-
- /* Epsilon transitions. */
- void epsilonTrans( int id );
-
- void checkEpsilonRegularInteraction( const PriorTable &t1, const PriorTable &t2 );
-
-private:
- /* Can generate staes. */
- void shadowReadWriteStates();
-
- void afterOpMinimize( bool lastInSeq = true );
-
- void removeDups( ActionTable &table );
-
-public:
-
- void removeActionDups();
-
- /*
- * Basic attaching and detaching.
- */
-
- /* Common to attaching/detaching list and default. */
- template < class Head > void attachToInList( StateAp *from,
- StateAp *to, Head *&head, Head *trans );
- template < class Head > void detachFromInList( StateAp *from,
- StateAp *to, Head *&head, Head *trans );
-
- void attachToNfa( StateAp *from, StateAp *to, NfaTrans *nfaTrans );
- void detachFromNfa( StateAp *from, StateAp *to, NfaTrans *nfaTrans );
-
- void attachStateDict( StateAp *from, StateAp *to );
- void detachStateDict( StateAp *from, StateAp *to );
-
- /* Attach with a new transition. */
- CondAp *attachNewCond( TransAp *trans, StateAp *from,
- StateAp *to, CondKey onChar );
- TransAp *attachNewTrans( StateAp *from, StateAp *to,
- Key onChar1, Key onChar2 );
-
- /* Attach with an existing transition that already in an out list. */
- void attachTrans( StateAp *from, StateAp *to, TransDataAp *trans );
- void attachTrans( StateAp *from, StateAp *to, CondAp *trans );
-
- /* Redirect a transition away from error and towards some state. */
- void redirectErrorTrans( StateAp *from, StateAp *to, TransDataAp *trans );
- void redirectErrorTrans( StateAp *from, StateAp *to, CondAp *trans );
-
- /* Detach a transition from a target state. */
- void detachTrans( StateAp *from, StateAp *to, TransDataAp *trans );
- void detachTrans( StateAp *from, StateAp *to, CondAp *trans );
-
- /* Detach a state from the graph. */
- void detachState( StateAp *state );
-
- /*
- * NFA to DFA conversion routines.
- */
-
- /* Duplicate a transition that will dropin to a free spot. */
- TransDataAp *dupTransData( StateAp *from, TransDataAp *srcTrans );
- TransAp *dupTrans( StateAp *from, TransAp *srcTrans );
- CondAp *dupCondTrans( StateAp *from, TransAp *destParent, CondAp *srcTrans );
-
-private:
- /* In crossing, two transitions both go to real states. Can generate
- * states. */
- template< class Trans > Trans *fsmAttachStates(
- StateAp *from, Trans *destTrans, Trans *srcTrans );
-
-public:
- void expandConds( StateAp *fromState, TransAp *trans,
- CondSpace *fromSpace, CondSpace *mergedSpace );
- TransAp *copyTransForExpansion( StateAp *fromState, TransAp *srcTrans );
- StateAp *copyStateForExpansion( StateAp *srcState );
- void freeEffectiveTrans( TransAp *srcTrans );
-
-private:
- /* Two transitions are to be crossed, handle the possibility of either
- * going to the error state. Can generate states. */
- template< class Trans > Trans *mergeTrans( StateAp *from,
- Trans *destTrans, Trans *srcTrans );
-
-public:
- /* Compare deterimne relative priorities of two transition tables. */
- int comparePrior( const PriorTable &priorTable1, const PriorTable &priorTable2 );
-
- void addOutCondition( StateAp *state, Action *condAction, bool sense );
-
- void expandCondKeys( CondKeySet &condKeys, CondSpace *fromSpace,
- 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. */
- TransCondAp *convertToCondAp( StateAp *state, TransDataAp *trans );
- CondSpace *expandCondSpace( TransAp *destTrans, TransAp *srcTrans );
-
-private:
- /* Can generate states. */
- TransAp *crossTransitions( StateAp *from,
- TransAp *destTrans, TransAp *srcTrans );
- TransDataAp *crossTransitionsBothPlain( StateAp *from,
- TransDataAp *destTrans, TransDataAp *srcTrans );
- CondAp *crossCondTransitions( StateAp *from,
- TransAp *destParent, CondAp *destTrans, CondAp *srcTrans );
-
-public:
- void prepareNfaRound();
- void finalizeNfaRound();
-
- void outTransCopy( StateAp *dest, TransAp *srcList );
- void nfaMergeStates( StateAp *destState, StateAp **srcStates, int numSrc );
- void mergeOutConds( StateAp *destState, StateAp *srcState, bool leaving = false );
- void checkPriorInteractions( StateAp *destState, StateAp *srcState );
- void mergeNfaTransitions( StateAp *destState, StateAp *srcState );
- void mergeStateProperties( StateAp *destState, StateAp *srcState );
- void mergeStatesLeaving( StateAp *destState, StateAp *srcState );
- void mergeStateBits( StateAp *destState, StateAp *srcState );
- void mergeStates( StateAp *destState, StateAp *srcState, bool leaving = false );
-
- /* Merge a set of states into destState. */
- void mergeStateList( StateAp *destState, StateAp **srcStates, int numSrc );
-
- /* Make all states that are combinations of other states and that
- * have not yet had their out transitions filled in. This will
- * empty out stateDict and stFil. */
- void cleanAbortedFill( StateAp *state );
- void cleanAbortedFill();
- bool overStateLimit();
- void nfaFillInStates();
-
- /*
- * Transition Comparison.
- */
-
- template< class Trans > int compareCondBitElim( Trans *trans1, Trans *trans2 );
- template< class Trans > int compareCondBitElimPtr( Trans *trans1, Trans *trans2 );
- int compareCondListBitElim( const CondList &condList1, const CondList &condList2 );
-
- /* Compare priority and function table of transitions. */
- static int compareTransData( TransAp *trans1, TransAp *trans2 );
- template< class Trans > static int compareCondData( Trans *trans1, Trans *trans2 );
-
- /* Compare transition data. Either of the pointers may be null. */
- static int compareTransDataPtr( TransAp *trans1, TransAp *trans2 );
- template< class Trans > static int compareCondDataPtr( Trans *trans1, Trans *trans2 );
-
- /* Compare target state and transition data. Either pointer may be null. */
- static int compareFullPtr( TransAp *trans1, TransAp *trans2 );
-
- /* Compare target partitions. Either pointer may be null. */
- static int compareTransPartPtr( TransAp *trans1, TransAp *trans2 );
- template< class Trans > static int compareCondPartPtr( Trans *trans1, Trans *trans2 );
-
- static int comparePart( TransAp *trans1, TransAp *trans2 );
-
- /* Check marked status of target states. Either pointer may be null. */
- static bool shouldMarkPtr( MarkIndex &markIndex,
- TransAp *trans1, TransAp *trans2 );
-
- /*
- * Callbacks.
- */
-
- /* Add in the properties of srcTrans into this. */
- template< class Trans > void addInTrans( Trans *destTrans, Trans *srcTrans );
-
- /* Compare states on data stored in the states. */
- static int compareStateData( const StateAp *state1, const StateAp *state2 );
-
- /* Out transition data. */
- void clearOutData( StateAp *state );
- bool hasOutData( StateAp *state );
- void transferOutData( StateAp *destState, StateAp *srcState );
-
- /*
- * Allocation.
- */
-
- /* New up a state and add it to the graph. */
- StateAp *addState();
-
- /*
- * Building basic machines
- */
-
- static FsmAp *concatFsm( FsmCtx *ctx, Key c );
- static FsmAp *concatFsmCI( FsmCtx *ctx, Key c );
- static FsmAp *concatFsm( FsmCtx *ctx, Key *str, int len );
- static FsmAp *concatFsmCI( FsmCtx *ctx, Key *str, int len );
- static FsmAp *orFsm( FsmCtx *ctx, Key *set, int len );
- static FsmAp *rangeFsm( FsmCtx *ctx, Key low, Key high );
- static FsmAp *rangeFsmCI( FsmCtx *ctx, Key low, Key high );
- static FsmAp *rangeStarFsm( FsmCtx *ctx, Key low, Key high );
- static FsmAp *emptyFsm( FsmCtx *ctx );
- static FsmAp *lambdaFsm( FsmCtx *ctx );
- static FsmAp *dotFsm( FsmCtx *ctx );
- static FsmAp *dotStarFsm( FsmCtx *ctx );
- static FsmAp *notRangeFsm( FsmCtx *ctx, Key low, Key high );
-
- /*
- * Fsm operators.
- */
-
- static FsmRes starOp( FsmAp *fsm );
- static FsmRes plusOp( FsmAp *fsm );
- static FsmRes questionOp( FsmAp *fsm );
-
- static FsmRes exactRepeatOp( FsmAp *fsm, int times );
- static FsmRes maxRepeatOp( FsmAp *fsm, int times );
- static FsmRes minRepeatOp( FsmAp *fsm, int times );
- static FsmRes rangeRepeatOp( FsmAp *fsm, int lower, int upper );
-
- static FsmRes concatOp( FsmAp *fsm, FsmAp *other, bool lastInSeq = true,
- StateSet *fromStates = 0, bool optional = false );
- static FsmRes unionOp( FsmAp *fsm, FsmAp *other, bool lastInSeq = true );
- static FsmRes intersectOp( FsmAp *fsm, FsmAp *other, bool lastInSeq = true );
- static FsmRes subtractOp( FsmAp *fsm, FsmAp *other, bool lastInSeq = true );
- static FsmRes epsilonOp( FsmAp *fsm );
- static FsmRes joinOp( FsmAp *fsm, int startId, int finalId, FsmAp **others, int numOthers );
-
- static FsmRes rightStartConcatOp( FsmAp *fsm, FsmAp *other, bool lastInSeq = true );
-
- void transferOutToNfaTrans( NfaTrans *trans, StateAp *state );
-
- enum NfaRepeatMode {
- NfaLegacy = 1,
- NfaGreedy,
- NfaLazy
- };
-
- static FsmRes applyNfaTrans( FsmAp *fsm, StateAp *fromState, StateAp *toState, NfaTrans *nfaTrans );
-
- /* Results in an NFA. */
- static FsmRes nfaUnionOp( FsmAp *fsm, FsmAp **others, int n, int depth, std::ostream &stats );
- static FsmRes nfaRepeatOp( FsmAp *fsm, Action *push, Action *pop, Action *init,
- Action *stay, Action *repeat, Action *exit );
-
- static FsmRes nfaRepeatOp2( FsmAp *fsm, Action *push, Action *pop, Action *init,
- Action *stay, Action *repeat, Action *exit, NfaRepeatMode mode = NfaGreedy );
- static FsmRes nfaWrap( FsmAp *fsm, Action *push, Action *pop, Action *init,
- Action *stay, Action *exit, NfaRepeatMode mode = NfaGreedy );
-
- static FsmRes nfaUnion( const NfaRoundVect &roundsList, FsmAp **machines,
- int numMachines, std::ostream &stats, bool printStatistics );
-
- static FsmRes condPlus( FsmAp *fsm, long repId, Action *ini, Action *inc, Action *min, Action *max );
- static FsmRes condStar( FsmAp *fsm, long repId, Action *ini, Action *inc, Action *min, Action *max );
-
- /* Make a new start state that has no entry points. Will not change the
- * meaning of the fsm. */
- static FsmRes isolateStartState( FsmAp *fsm );
-
- /*
- * Analysis Functions
- */
- static FsmRes condCostFromState( FsmAp *fsm, StateAp *state, long depth );
- static FsmRes condCostSearch( FsmAp *fsm );
- static void breadthFromEntry( double &total, int &minDepth, double *histogram, FsmAp *fsm, StateAp *state );
- static void breadthFromState( double &total, int &minDepth, double *histogram, FsmAp *fsm, StateAp *state,
- long depth, int maxDepth, double stateScore);
-
- /*
- * Operator workers
- */
- void globOp( FsmAp **others, int numOthers );
- void deterministicEntry();
-
- /* Determine if there are any entry points into a start state other than
- * the start state. */
- bool isStartStateIsolated();
-
- /* Make a new start state that has no entry points. Will not change the
- * meaning of the fsm. */
- StateAp *dupStartState();
-
- /* Workers for resolving epsilon transitions. */
- bool inEptVect( EptVect *eptVect, StateAp *targ );
- void epsilonFillEptVectFrom( StateAp *root, StateAp *from, bool parentLeaving );
- void resolveEpsilonTrans();
-
- static bool fillAbort( FsmRes &res, FsmAp *fsm );
-
- static FsmRes fillInStates( FsmAp *fsm );
-
- /* Workers for concatenation and union. */
- static FsmRes doUnion( FsmAp *fsm, FsmAp *other );
- static FsmRes doConcat( FsmAp *fsm, FsmAp *other, StateSet *fromStates, bool optional );
-
- static void condCost( Action *action, long repId );
- static void applyEntryPriorGuard( FsmAp *fsm, long repId );
- static void applyRepeatPriorGuard( FsmAp *fsm, long repId );
-
- /*
- * Final states
- */
-
- /* Unset any final states that are no longer to be final
- * due to final bits. */
- void unsetIncompleteFinals();
- void unsetKilledFinals();
-
- /* Bring in other's entry points. Assumes others states are going to be
- * copied into this machine. */
- void copyInEntryPoints( FsmAp *other );
-
- /* Ordering states. */
- void depthFirstOrdering( StateAp *state );
- void depthFirstOrdering();
- void sortStatesByFinal();
-
- /* Set sqequential state numbers starting at 0. */
- void setStateNumbers( int base );
-
- /* Unset all final states. */
- void unsetAllFinStates();
-
- /* Set the bits of final states and clear the bits of non final states. */
- void setFinBits( int finStateBits );
- void unsetFinBits( int finStateBits );
-
- /*
- * Self-consistency checks.
- */
-
- /* Run a sanity check on the machine. */
- void verifyIntegrity();
-
- /* Verify that there are no unreachable states, or dead end states. */
- void verifyReachability();
- void verifyNoDeadEndStates();
-
- /*
- * Path pruning
- */
-
- /* Mark all states reachable from state. */
- void markReachableFromHereReverse( StateAp *state );
-
- /* Mark all states reachable from state. */
- void markReachableFromHere( StateAp *state );
- void markReachableFromHereStopFinal( StateAp *state );
-
- /* Any transitions to another state? */
- bool anyRegularTransitions( StateAp *state );
-
- /* Removes states that cannot be reached by any path in the fsm and are
- * thus wasted silicon. */
- void removeDeadEndStates();
-
- /* Removes states that cannot be reached by any path in the fsm and are
- * thus wasted silicon. */
- long removeUnreachableStates();
-
- /* Remove error actions from states on which the error transition will
- * never be taken. */
- bool outListCovers( StateAp *state );
- bool anyErrorRange( StateAp *state );
-
- /* Remove states that are on the misfit list. */
- void removeMisfits();
-
- /*
- * FSM Minimization
- */
-
- /* Minimization by partitioning. */
- void minimizePartition1();
- void minimizePartition2();
-
- /* Minimize the final state Machine. The result is the minimal fsm. Slow
- * but stable, correct minimization. Uses n^2 space (lookout) and average
- * n^2 time. Worst case n^3 time, but a that is a very rare case. */
- void minimizeStable();
-
- /* Minimize the final state machine. Does not find the minimal fsm, but a
- * pretty good approximation. Does not use any extra space. Average n^2
- * time. Worst case n^3 time, but a that is a very rare case. */
- void minimizeApproximate();
-
- /* This is the worker for the minimize approximate solution. It merges
- * states that have identical out transitions. */
- bool minimizeRound( );
-
- /* Given an intial partioning of states, split partitions that have out trans
- * to differing partitions. */
- int partitionRound( StateAp **statePtrs, MinPartition *parts, int numParts );
-
- /* Split partitions that have a transition to a previously split partition, until
- * there are no more partitions to split. */
- int splitCandidates( StateAp **statePtrs, MinPartition *parts, int numParts );
-
- /* Fuse together states in the same partition. */
- void fusePartitions( MinPartition *parts, int numParts );
-
- /* Mark pairs where out final stateness differs, out trans data differs,
- * trans pairs go to a marked pair or trans data differs. Should get
- * alot of pairs. */
- void initialMarkRound( MarkIndex &markIndex );
-
- /* One marking round on all state pairs. Considers if trans pairs go
- * to a marked state only. Returns whether or not a pair was marked. */
- bool markRound( MarkIndex &markIndex );
-
- /* Move the in trans into src into dest. */
- void moveInwardTrans(StateAp *dest, StateAp *src);
-
- /* Make state src and dest the same state. */
- void fuseEquivStates( StateAp *dest, StateAp *src );
-
- /* Find any states that didn't get marked by the marking algorithm and
- * merge them into the primary states of their equivalence class. */
- void fuseUnmarkedPairs( MarkIndex &markIndex );
-
- /* Merge neighboring transitions go to the same state and have the same
- * transitions data. */
- void compressTransitions();
-
- /* Returns true if there is a transtion (either explicit or by a gap) to
- * the error state. */
- bool checkErrTrans( StateAp *state, TransAp *trans );
- bool checkErrTrans( StateAp *state, CondAp *trans );
- bool checkErrTransFinish( StateAp *state );
- bool hasErrorTrans();
-
- /* Check if a machine defines a single character. This is useful in
- * validating ranges and machines to export. */
- bool checkSingleCharMachine( );
-
- bool elimCondBits();
-};
-
-/* Callback invoked when another trans (or possibly this) is added into this
- * transition during the merging process. Draw in any properties of srcTrans
- * 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
- * other transitions. AddInTrans will be called for each transition that the
- * new transition is to represent. */
-template< class Trans > void FsmAp::addInTrans( Trans *destTrans, Trans *srcTrans )
-{
- /* Protect against adding in from ourselves. */
- if ( srcTrans == destTrans ) {
- /* Adding in ourselves, need to make a copy of the source transitions.
- * The priorities are not copied in as that would have no effect. */
- destTrans->lmActionTable.setActions( LmActionTable(srcTrans->lmActionTable) );
- destTrans->actionTable.setActions( ActionTable(srcTrans->actionTable) );
- }
- else {
- /* Not a copy of ourself, get the functions and priorities. */
- destTrans->lmActionTable.setActions( srcTrans->lmActionTable );
- destTrans->actionTable.setActions( srcTrans->actionTable );
- destTrans->priorTable.setPriors( srcTrans->priorTable );
- }
-}
-
-/* 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::compareCondDataPtr( 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 = compareCondData( trans1, trans2 );
- if ( compareRes != 0 )
- return compareRes;
- }
- 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
diff --git a/src/gendata.h b/src/gendata.h
deleted file mode 100644
index f34f2629..00000000
--- a/src/gendata.h
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * Copyright 2005-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _GENDATA_H
-#define _GENDATA_H
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include "config.h"
-#include "redfsm.h"
-#include "common.h"
-#include "fsmgraph.h"
-
-/* Forwards. */
-struct TransAp;
-struct FsmAp;
-struct PdBase;
-struct InputData;
-struct FsmGbl;
-struct GenInlineList;
-struct InlineItem;
-
-struct RedActionTable
-:
- public AvlTreeEl<RedActionTable>
-{
- RedActionTable( const ActionTable &key )
- :
- key(key),
- id(0)
- { }
-
- const ActionTable &getKey()
- { return key; }
-
- ActionTable key;
- int id;
-};
-
-typedef AvlTree<RedActionTable, ActionTable, CmpActionTable> ActionTableMap;
-
-struct NextRedTrans
-{
- Key lowKey, highKey;
- TransAp *trans;
- TransAp *next;
-
- void load() {
- if ( trans != 0 ) {
- next = trans->next;
- lowKey = trans->lowKey;
- highKey = trans->highKey;
- }
- }
-
- NextRedTrans( TransAp *t ) {
- trans = t;
- load();
- }
-
- void increment() {
- trans = next;
- load();
- }
-};
-
-struct RedBase
-{
- RedBase( FsmGbl *id, FsmCtx *fsmCtx, FsmAp *fsm, std::string fsmName, int machineId )
- :
- id(id),
- fsmCtx(fsmCtx),
- fsm(fsm),
- fsmName(fsmName),
- machineId(machineId),
- keyOps(fsm->ctx->keyOps),
- nextActionTableId(0)
- {
- }
-
- FsmGbl *id;
- FsmCtx *fsmCtx;
- FsmAp *fsm;
- std::string fsmName;
- int machineId;
-
- KeyOps *keyOps;
-
- ActionTableMap actionTableMap;
- int nextActionTableId;
-};
-
-struct NameInst;
-typedef DList<GenAction> GenActionList;
-
-typedef unsigned long ulong;
-
-void openHostBlock( char opener, InputData *id, std::ostream &out, const char *fileName, int line );
-
-string itoa( int i );
-
-struct Reducer
- : public RedBase
-{
- Reducer( FsmGbl *id, FsmCtx *fsmCtx, FsmAp *fsm, std::string fsmName, int machineId )
- :
- RedBase( id, fsmCtx, fsm, fsmName, machineId ),
- redFsm(0),
- allActions(0),
- allActionTables(0),
- allConditions(0),
- allCondSpaces(0),
- allStates(0),
- nameIndex(0),
- startState(-1),
- errState(-1),
- getKeyExpr(0),
- accessExpr(0),
- prePushExpr(0),
- postPopExpr(0),
- nfaPrePushExpr(0),
- nfaPostPopExpr(0),
- pExpr(0),
- peExpr(0),
- eofExpr(0),
- csExpr(0),
- topExpr(0),
- stackExpr(0),
- actExpr(0),
- tokstartExpr(0),
- tokendExpr(0),
- dataExpr(0),
- hasLongestMatch(false)
- {
- }
-
- ~Reducer()
- {
- if ( redFsm != 0 )
- delete redFsm;
-
- delete[] allActions;
- delete[] allActionTables;
- delete[] allConditions;
- delete[] allCondSpaces;
-
- actionTableMap.empty();
-
- if ( getKeyExpr != 0 )
- delete getKeyExpr;
- if ( accessExpr != 0 )
- delete accessExpr;
- if ( prePushExpr != 0 )
- delete prePushExpr;
- if ( postPopExpr != 0 )
- delete postPopExpr;
- if ( nfaPrePushExpr != 0 )
- delete nfaPrePushExpr;
- if ( nfaPostPopExpr != 0 )
- delete nfaPostPopExpr;
- if ( pExpr != 0 )
- delete pExpr;
- if ( peExpr != 0 )
- delete peExpr;
- if ( eofExpr != 0 )
- delete eofExpr;
- if ( csExpr != 0 )
- delete csExpr;
- if ( topExpr != 0 )
- delete topExpr;
- if ( stackExpr != 0 )
- delete stackExpr;
- if ( actExpr != 0 )
- delete actExpr;
- if ( tokstartExpr != 0 )
- delete tokstartExpr;
- if ( tokendExpr != 0 )
- delete tokendExpr;
- if ( dataExpr != 0 )
- delete dataExpr;
- }
-
-protected:
- /* Collected during parsing. */
- int curAction;
- int curActionTable;
- int curState;
-
- void makeKey( GenInlineList *outList, Key key );
- void makeText( GenInlineList *outList, InlineItem *item );
- void makeLmOnLast( GenInlineList *outList, InlineItem *item );
- void makeLmOnNext( GenInlineList *outList, InlineItem *item );
- void makeLmOnLagBehind( GenInlineList *outList, InlineItem *item );
- void makeLmSwitch( GenInlineList *outList, InlineItem *item );
- void makeLmNfaOnLast( GenInlineList *outList, InlineItem *item );
- void makeLmNfaOnNext( GenInlineList *outList, InlineItem *item );
- void makeLmNfaOnEof( GenInlineList *outList, InlineItem *item );
- void makeActionExec( GenInlineList *outList, InlineItem *item );
- void makeSetTokend( GenInlineList *outList, long offset );
- void makeSetAct( GenInlineList *outList, long lmId );
- void makeSubList( GenInlineList *outList, InlineList *inlineList,
- GenInlineItem::Type type );
- void makeTargetItem( GenInlineList *outList, NameInst *nameTarg,
- GenInlineItem::Type type );
- void makeExecGetTokend( GenInlineList *outList );
- void makeActionList();
- void makeAction( Action *action );
- void makeActionTableList();
- void makeConditions();
- void makeEntryPoints();
- bool makeNameInst( std::string &out, NameInst *nameInst );
- void makeStateList();
-
- void makeStateActions( StateAp *state );
- void makeEofTrans( StateAp *state );
- void makeTransList( StateAp *state );
- void makeTrans( Key lowKey, Key highKey, TransAp *trans );
- void newTrans( RedStateAp *state, Key lowKey, Key highKey, RedTransAp *trans );
-
- void makeSubList( GenInlineList *outList, const InputLoc &loc,
- InlineList *inlineList, GenInlineItem::Type type );
-
- void createMachine();
- void initActionList( unsigned long length );
- void newAction( int anum, std::string name,
- const InputLoc &loc, GenInlineList *inlineList );
- void initActionTableList( unsigned long length );
- void initStateList( unsigned long length );
- void setStartState( unsigned long startState );
- void setErrorState( unsigned long errState );
- void addEntryPoint( char *name, unsigned long entryState );
- void setId( int snum, int id );
- void setFinal( int snum );
- void initTransList( int snum, unsigned long length );
-
- void newTrans( int snum, int tnum, Key lowKey, Key highKey,
- GenCondSpace *gcs, RedTransAp *trans );
-
- void finishTransList( int snum );
- void setStateActions( int snum, long toStateAction,
- long fromStateAction, long eofAction );
- void setEofTrans( int snum, long targ, long eofAction );
- void setEofTrans( int snum, GenCondSpace *condSpace,
- RedCondEl *outConds, int numConds, RedCondAp *errCond );
- void setForcedErrorState()
- { redFsm->forcedErrorState = true; }
-
- void condSpaceItem( int cnum, long condActionId );
- void newCondSpace( int cnum, int condSpaceId );
-
- void initStateCondList( int snum, ulong length );
- void addStateCond( int snum, Key lowKey, Key highKey, long condNum );
-
-
- void resolveTargetStates( GenInlineList *inlineList );
- void resolveTargetStates();
-
-
- /* Gather various info on the machine. */
- void analyzeActionList( RedAction *redAct, GenInlineList *inlineList );
- void analyzeAction( GenAction *act, GenInlineList *inlineList );
- void actionActionRefs( RedAction *action );
- void transListActionRefs( RedTransList &list );
- void transActionRefs( RedTransAp *trans );
- void findFinalActionRefs();
-
- void setValueLimits();
- void assignActionIds();
-
-
- void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans );
- void reduceActionTables();
-
-public:
-
- Key findMaxKey();
- void makeMachine();
- void makeExports();
- void makeGenInlineList( GenInlineList *outList, InlineList *inList );
- bool setAlphType( const HostLang *hostLang, const char *data );
- void analyzeMachine();
- void make( const HostLang *hostLang, const HostType *alphType );
-
- /*
- * Collecting the machine.
- */
-
- RedFsmAp *redFsm;
- GenAction *allActions;
- RedAction *allActionTables;
- Condition *allConditions;
- GenCondSpace *allCondSpaces;
- RedStateAp *allStates;
- NameInst **nameIndex;
- int startState;
- int errState;
- GenActionList actionList;
- CondSpaceList condSpaceList;
-
- GenInlineList *getKeyExpr;
- GenInlineList *accessExpr;
- GenInlineExpr *prePushExpr;
- GenInlineExpr *postPopExpr;
-
- GenInlineExpr *nfaPrePushExpr;
- GenInlineExpr *nfaPostPopExpr;
-
- /* Overriding variables. */
- GenInlineList *pExpr;
- GenInlineList *peExpr;
- GenInlineList *eofExpr;
- GenInlineList *csExpr;
- GenInlineList *topExpr;
- GenInlineList *stackExpr;
- GenInlineList *actExpr;
- GenInlineList *tokstartExpr;
- GenInlineList *tokendExpr;
- GenInlineList *dataExpr;
-
- EntryIdVect entryPointIds;
- EntryNameVect entryPointNames;
- bool hasLongestMatch;
- ExportList exportList;
- Action *curInlineAction;
-};
-
-struct CodeGenArgs
-{
- CodeGenArgs( FsmGbl *id, Reducer *red, HostType *alphType,
- int machineId, std::string sourceFileName,
- std::string fsmName, std::ostream &out,
- CodeStyle codeStyle )
- :
- id(id),
- red(red),
- alphType(alphType),
- machineId(machineId),
- sourceFileName(sourceFileName),
- fsmName(fsmName),
- out(out),
- codeStyle(codeStyle),
- lineDirectives(true),
- forceVar(false),
- loopLabels(false)
- {}
-
- FsmGbl *id;
- Reducer *red;
- HostType *alphType;
- int machineId;
- std::string sourceFileName;
- std::string fsmName;
- std::ostream &out;
- CodeStyle codeStyle;
- bool lineDirectives;
- GenLineDirectiveT genLineDirective;
- bool forceVar;
- bool loopLabels;
-};
-
-struct CodeGenData
-{
- CodeGenData( const CodeGenArgs &args )
- :
- red(args.red),
- redFsm(args.red->redFsm),
- sourceFileName(args.sourceFileName),
- fsmName(args.fsmName),
- keyOps(red->keyOps),
- alphType(args.alphType),
- out(args.out),
- noEnd(false),
- noPrefix(false),
- noFinal(false),
- noError(false),
- noCS(false),
- lineDirectives(args.lineDirectives),
- cleared(false),
- referencesCollected(false),
- genLineDirective(args.id->hostLang->genLineDirective)
- {
- }
-
- /*
- * The interface to the code generator.
- */
- virtual void genAnalysis() = 0;
-
- /* These are invoked by writeStatement and are normally what are used to
- * implement the code generators. */
- virtual void writeData() {};
- virtual void writeInit() {};
- virtual void writeExec() {};
- virtual void writeExports() {};
- virtual void writeStart() {};
- virtual void writeFirstFinal() {};
- virtual void writeError() {};
- virtual void writeClear();
-
- /* Show some stats after a write data. */
- virtual void statsSummary() = 0;
-
- /* This can also be overridden to modify the processing of write
- * statements. */
- virtual void writeStatement( InputLoc &loc, int nargs,
- std::vector<std::string> &args, bool generateDot, const HostLang *hostLang );
-
- /********************/
-
- virtual ~CodeGenData()
- {
- }
-
- void clear()
- {
- delete red->redFsm;
- red->redFsm = 0;
- }
-
- void collectReferences();
-
-protected:
-
- Reducer *red;
- RedFsmAp *redFsm;
- std::string sourceFileName;
- std::string fsmName;
- KeyOps *keyOps;
- HostType *alphType;
- ostream &out;
-
- /* Write options. */
- bool noEnd;
- bool noPrefix;
- bool noFinal;
- bool noError;
- bool noCS;
-
- void write_option_error( InputLoc &loc, std::string arg );
-
- bool lineDirectives;
- bool cleared;
-
- bool referencesCollected;
-
- void genOutputLineDirective( std::ostream &out ) const;
- GenLineDirectiveT genLineDirective;
-};
-
-/* Selects and constructs the codegen based on the output options. */
-CodeGenData *makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
-CodeGenData *asm_makeCodeGen( const HostLang *hostLang, const CodeGenArgs &args );
-
-typedef AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
-typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;
-
-#endif
diff --git a/src/goto.cc b/src/goto.cc
deleted file mode 100644
index 610f44d1..00000000
--- a/src/goto.cc
+++ /dev/null
@@ -1,978 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "goto.h"
-#include "redfsm.h"
-#include "bstmap.h"
-#include "gendata.h"
-
-#include <sstream>
-
-using std::ostringstream;
-
-IpLabel *Goto::allocateLabels( IpLabel *labels, IpLabel::Type type, int n )
-{
- if ( labels == 0 ) {
- labels = new IpLabel[n];
- for ( int id = 0; id < n; id++ ) {
- labels[id].type = type;
- labels[id].stid = id;
- }
- }
-
- return labels;
-}
-
-void Goto::setTableState( TableArray::State state )
-{
- for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) {
- TableArray *tableArray = *i;
- tableArray->setState( state );
- }
-}
-
-/* Emit the goto to take for a given transition. */
-std::ostream &Goto::COND_GOTO( RedCondPair *cond )
-{
- out << "goto " << ctrLabel[cond->id].reference() << ";";
- return out;
-}
-
-/* Emit the goto to take for a given transition. */
-std::ostream &Goto::TRANS_GOTO( RedTransAp *trans )
-{
- if ( trans->condSpace == 0 || trans->condSpace->condSet.length() == 0 ) {
- /* Existing. */
- assert( trans->numConds() == 1 );
- RedCondPair *cond = trans->outCond( 0 );
-
- /* Go to the transition which will go to the state. */
- out << "goto " << ctrLabel[cond->id].reference() << ";";
- }
- else {
- out << ck << " = 0;\n";
- for ( GenCondSet::Iter csi = trans->condSpace->condSet; csi.lte(); csi++ ) {
- out << "if ( ";
- CONDITION( out, *csi );
- Size condValOffset = (1 << csi.pos());
- out << " )\n" << ck << " += " << condValOffset << ";\n";
- }
- CondKey lower = 0;
- CondKey upper = trans->condFullSize() - 1;
- COND_B_SEARCH( trans, lower, upper, 0, trans->numConds()-1 );
-
- if ( trans->errCond() != 0 ) {
- COND_GOTO( trans->errCond() ) << "\n";
- }
- }
-
- return out;
-}
-
-/* Write out the array of actions. */
-void Goto::taActions()
-{
- actions.start();
-
- actions.value( 0 );
-
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Write out the length, which will never be the last character. */
- actions.value( act->key.length() );
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ )
- actions.value( item->value->actionId );
- }
-
- actions.finish();
-}
-
-void Goto::GOTO_HEADER( RedStateAp *state )
-{
- /* Label the state. */
- out << "case " << state->id << ":\n";
-}
-
-
-void Goto::SINGLE_SWITCH( RedStateAp *state )
-{
- /* Load up the singles. */
- int numSingles = state->outSingle.length();
- RedTransEl *data = state->outSingle.data;
-
- if ( numSingles == 1 ) {
- /* If there is a single single key then write it out as an if. */
- out << "if ( " << GET_KEY() << " == " <<
- KEY(data[0].lowKey) << " ) {\n";
-
- /* Virtual function for writing the target of the transition. */
- TRANS_GOTO(data[0].value) << "\n";
- out << "}\n";
- }
- else if ( numSingles > 1 ) {
- /* Write out single keys in a switch if there is more than one. */
- out << "switch( " << GET_KEY() << " ) {\n";
-
- /* Write out the single indices. */
- for ( int j = 0; j < numSingles; j++ ) {
- out << "case " << KEY(data[j].lowKey) << ": {\n";
- TRANS_GOTO(data[j].value) << "\n";
- out << "}\n";
- }
-
- /* Close off the transition switch. */
- out << "}\n";
- }
-}
-
-void Goto::RANGE_B_SEARCH( RedStateAp *state, Key lower, Key upper, int low, int high )
-{
- /* Get the mid position, staying on the lower end of the range. */
- int mid = (low + high) >> 1;
- RedTransEl *data = state->outRange.data;
-
- /* Determine if we need to look higher or lower. */
- bool anyLower = mid > low;
- bool anyHigher = mid < high;
-
- /* Determine if the keys at mid are the limits of the alphabet. */
- bool limitLow = keyOps->eq( data[mid].lowKey, lower );
- bool limitHigh = keyOps->eq( data[mid].highKey, upper );
-
- if ( anyLower && anyHigher ) {
- /* Can go lower and higher than mid. */
- out << "if ( " << GET_KEY() << " < " <<
- KEY(data[mid].lowKey) << " ) {\n";
- RANGE_B_SEARCH( state, lower, keyOps->sub( data[mid].lowKey, 1 ), low, mid-1 );
- out << "} else if ( " << GET_KEY() << " > " <<
- KEY(data[mid].highKey) << " ) {\n";
- RANGE_B_SEARCH( state, keyOps->add( data[mid].highKey, 1 ), upper, mid+1, high );
- out << "} else {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else if ( anyLower && !anyHigher ) {
- /* Can go lower than mid but not higher. */
- out << "if ( " << GET_KEY() << " < " <<
- KEY(data[mid].lowKey) << " ) {\n";
- RANGE_B_SEARCH( state, lower, keyOps->sub( data[mid].lowKey, 1 ), low, mid-1 );
-
- /* if the higher is the highest in the alphabet then there is no
- * sense testing it. */
- if ( limitHigh ) {
- out << "} else {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- }
- else if ( !anyLower && anyHigher ) {
- /* Can go higher than mid but not lower. */
- out << "if ( " << GET_KEY() << " > " <<
- KEY(data[mid].highKey) << " ) {\n";
- RANGE_B_SEARCH( state, keyOps->add( data[mid].highKey, 1 ), upper, mid+1, high );
-
- /* If the lower end is the lowest in the alphabet then there is no
- * sense testing it. */
- if ( limitLow ) {
- out << "} else {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << GET_KEY() << " >= " <<
- KEY(data[mid].lowKey) << " ) {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- }
- else {
- /* Cannot go higher or lower than mid. It's mid or bust. What
- * tests to do depends on limits of alphabet. */
- if ( !limitLow && !limitHigh ) {
- out << "if ( " << KEY(data[mid].lowKey) << " <= " <<
- GET_KEY() << " && " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else if ( limitLow && !limitHigh ) {
- out << "if ( " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else if ( !limitLow && limitHigh ) {
- out << "if ( " << KEY(data[mid].lowKey) << " <= " <<
- GET_KEY() << " ) {\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- else {
- /* Both high and low are at the limit. No tests to do. */
- out << "{\n";
- TRANS_GOTO(data[mid].value) << "\n";
- out << "}\n";
- }
- }
-}
-
-/* Write out a key from the fsm code gen. Depends on wether or not the key is
- * signed. */
-string Goto::CKEY( CondKey key )
-{
- ostringstream ret;
- ret << key.getVal();
- return ret.str();
-}
-
-void Goto::COND_B_SEARCH( RedTransAp *trans, CondKey lower,
- CondKey upper, int low, int high )
-{
- /* Get the mid position, staying on the lower end of the range. */
- int mid = (low + high) >> 1;
-// RedCondEl *data = trans->outCond(0);
-
- /* Determine if we need to look higher or lower. */
- bool anyLower = mid > low;
- bool anyHigher = mid < high;
-
- CondKey midKey = trans->outCondKey( mid );
- RedCondPair *midTrans = trans->outCond( mid );
-
- /* Determine if the keys at mid are the limits of the alphabet. */
- bool limitLow = midKey == lower;
- bool limitHigh = midKey == upper;
-
- if ( anyLower && anyHigher ) {
- /* Can go lower and higher than mid. */
- out << "if ( " << ck << " < " <<
- CKEY(midKey) << " ) {\n";
- COND_B_SEARCH( trans, lower, midKey-1, low, mid-1 );
- out << "} else if ( " << ck << " > " <<
- CKEY(midKey) << " ) {\n";
- COND_B_SEARCH( trans, midKey+1, upper, mid+1, high );
- out << "} else {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else if ( anyLower && !anyHigher ) {
- /* Can go lower than mid but not higher. */
- out << "if ( " << ck << " < " <<
- CKEY(midKey) << " ) {\n";
- COND_B_SEARCH( trans, lower, midKey-1, low, mid-1);
-
- /* if the higher is the highest in the alphabet then there is no
- * sense testing it. */
- if ( limitHigh ) {
- out << "} else {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << ck << " <= " <<
- CKEY(midKey) << " ) {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- }
- else if ( !anyLower && anyHigher ) {
- /* Can go higher than mid but not lower. */
- out << "if ( " << ck << " > " <<
- CKEY(midKey) << " ) {\n";
- COND_B_SEARCH( trans, midKey+1, upper, mid+1, high );
-
- /* If the lower end is the lowest in the alphabet then there is no
- * sense testing it. */
- if ( limitLow ) {
- out << "} else {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << ck << " >= " <<
- CKEY(midKey) << " ) {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- }
- else {
- /* Cannot go higher or lower than mid. It's mid or bust. What
- * tests to do depends on limits of alphabet. */
- if ( !limitLow && !limitHigh ) {
- out << "if ( " << ck << " == " <<
- CKEY(midKey) << " ) {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else if ( limitLow && !limitHigh ) {
- out << "if ( " << ck << " <= " <<
- CKEY(midKey) << " ) {\n";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else if ( !limitLow && limitHigh ) {
- out << "if ( " << CKEY(midKey) << " <= " << ck << " )\n {";
- COND_GOTO(midTrans) << "\n";
- out << "}\n";
- }
- else {
- /* Both high and low are at the limit. No tests to do. */
- COND_GOTO(midTrans) << "\n";
- }
- }
-}
-
-void Goto::STATE_GOTO_ERROR()
-{
- /* Bail out immediately. */
- out << " goto " << _again << ";\n";
-}
-
-void Goto::FROM_STATE_ACTION_EMIT( RedStateAp *state )
-{
- if ( state->fromStateAction != 0 ) {
- /* Write every action in the list. */
- for ( GenActionTable::Iter item = state->fromStateAction->key; item.lte(); item++ ) {
- ACTION( out, item->value, IlOpts( state->id, false,
- state->fromStateAction->anyNextStmt() ) );
- out << "\n";
- }
- }
-}
-
-std::ostream &Goto::STATE_CASES()
-{
- bool eof = redFsm->anyEofActivity() || redFsm->anyNfaStates();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Writing code above state gotos. */
- GOTO_HEADER( st );
-
- FROM_STATE_ACTION_EMIT( st );
-
- if ( !noEnd && eof ) {
- out <<
- "if ( " << P() << " == " << vEOF() << " ) {\n";
-
- if ( st->eofTrans != 0 )
- TRANS_GOTO( st->eofTrans );
-
- out <<
- " goto " << _again << ";\n"
- "}\n"
- "else {\n";
- }
-
- if ( st == redFsm->errState )
- STATE_GOTO_ERROR();
- else {
- /* Try singles. */
- if ( st->outSingle.length() > 0 )
- SINGLE_SWITCH( st );
-
- /* Default case is to binary search for the ranges, if that fails then */
- if ( st->outRange.length() > 0 ) {
- RANGE_B_SEARCH( st, keyOps->minKey, keyOps->maxKey,
- 0, st->outRange.length() - 1 );
- }
-
- /* Write the default transition. */
- TRANS_GOTO( st->defTrans ) << "\n";
- }
-
- if ( !noEnd && eof ) {
- out <<
- "}\n";
- }
- }
- return out;
-}
-
-std::ostream &Goto::TRANSITION( RedCondPair *pair )
-{
- /* Write the label for the transition so it can be jumped to. */
- if ( ctrLabel[pair->id].isReferenced )
- out << "_ctr" << pair->id << ": ";
-
- /* Destination state. */
- if ( pair->action != 0 && pair->action->anyCurStateRef() )
- out << ps << " = " << vCS() << ";";
- out << vCS() << " = " << pair->targ->id << "; ";
-
- if ( pair->action != 0 ) {
- /* Write out the transition func. */
- out << "goto f" << pair->action->actListId << ";\n";
- }
- else {
- /* No code to execute, just loop around. */
- out << "goto " << _again << ";\n";
- }
- return out;
-}
-
-std::ostream &Goto::TRANSITIONS()
-{
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- if ( trans->condSpace == 0 )
- TRANSITION( &trans->p );
- }
-
- for ( CondApSet::Iter cond = redFsm->condSet; cond.lte(); cond++ )
- TRANSITION( &cond->p );
-
- return out;
-}
-
-unsigned int Goto::TO_STATE_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->toStateAction != 0 )
- act = state->toStateAction->location+1;
- return act;
-}
-
-unsigned int Goto::FROM_STATE_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->fromStateAction != 0 )
- act = state->fromStateAction->location+1;
- return act;
-}
-
-unsigned int Goto::EOF_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->eofAction != 0 )
- act = state->eofAction->location+1;
- return act;
-}
-
-void Goto::taToStateActions()
-{
- toStateActions.start();
-
- /* Take one off for the psuedo start state. */
- int numStates = redFsm->stateList.length();
- unsigned int *vals = new unsigned int[numStates];
- memset( vals, 0, sizeof(unsigned int)*numStates );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- vals[st->id] = TO_STATE_ACTION(st);
-
- for ( int st = 0; st < redFsm->nextStateId; st++ ) {
- /* Write any eof action. */
- toStateActions.value( vals[st] );
- }
- delete[] vals;
-
- toStateActions.finish();
-}
-
-void Goto::taFromStateActions()
-{
- fromStateActions.start();
-
- /* Take one off for the psuedo start state. */
- int numStates = redFsm->stateList.length();
- unsigned int *vals = new unsigned int[numStates];
- memset( vals, 0, sizeof(unsigned int)*numStates );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- vals[st->id] = FROM_STATE_ACTION(st);
-
- for ( int st = 0; st < redFsm->nextStateId; st++ ) {
- /* Write any eof action. */
- fromStateActions.value( vals[st] );
- }
- delete[] vals;
-
- fromStateActions.finish();
-}
-
-void Goto::taEofActions()
-{
- eofActions.start();
-
- /* Take one off for the psuedo start state. */
- int numStates = redFsm->stateList.length();
- unsigned int *vals = new unsigned int[numStates];
- memset( vals, 0, sizeof(unsigned int)*numStates );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- vals[st->id] = EOF_ACTION(st);
-
- for ( int st = 0; st < redFsm->nextStateId; st++ ) {
- /* Write any eof action. */
- eofActions.value( vals[st] );
- }
- delete[] vals;
-
- eofActions.finish();
-}
-
-void Goto::taNfaOffsets()
-{
- nfaOffsets.start();
-
- /* Offset of zero means no NFA targs, real targs start at 1. */
- long offset = 1;
-
- /* Take one off for the psuedo start state. */
- int numStates = redFsm->stateList.length();
- unsigned int *vals = new unsigned int[numStates];
- memset( vals, 0, sizeof(unsigned int)*numStates );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs == 0 ) {
- vals[st->id] = 0;
- //nfaOffsets.value( 0 );
- }
- else {
- vals[st->id] = offset;
- //nfaOffsets.value( offset );
- offset += 1 + st->nfaTargs->length();
- }
- }
-
- for ( int st = 0; st < redFsm->nextStateId; st++ )
- nfaOffsets.value( vals[st] );
- delete[] vals;
-
- nfaOffsets.finish();
-}
-
-void Goto::taNfaTargs()
-{
- nfaTargs.start();
-
- /* Offset of zero means no NFA targs, put a filler there. */
- nfaTargs.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaTargs.value( st->nfaTargs->length() );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- nfaTargs.value( targ->state->id );
- }
- }
-
- nfaTargs.finish();
-}
-
-/* These need to mirror nfa targs. */
-void Goto::taNfaPushActions()
-{
- nfaPushActions.start();
-
- nfaPushActions.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaPushActions.value( 0 );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_PUSH_ACTION( targ );
- }
- }
-
- nfaPushActions.finish();
-}
-
-void Goto::taNfaPopTrans()
-{
- nfaPopTrans.start();
-
- nfaPopTrans.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaPopTrans.value( 0 );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_POP_TEST( targ );
- }
- }
-
- nfaPopTrans.finish();
-}
-
-void Goto::EOF_CHECK( ostream &ret )
-{
- ret <<
- " if ( " << P() << " == " << PE() << " )\n"
- " goto " << _test_eof << ";\n";
-}
-
-void Goto::GOTO( ostream &ret, int gotoDest, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK() << vCS() << " = " << gotoDest << "; ";
-
- if ( inFinish && !noEnd )
- EOF_CHECK( ret );
-
- ret << "goto " << _again << ";";
-
- ret << CLOSE_GEN_BLOCK();
-}
-
-void Goto::GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK() << vCS() << " = " << OPEN_HOST_EXPR();
- INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
- ret << CLOSE_HOST_EXPR() << ";";
-
- if ( inFinish && !noEnd )
- EOF_CHECK( ret );
-
- ret << " goto " << _again << ";";
-
- ret << CLOSE_GEN_BLOCK();
-}
-
-void Goto::CURS( ostream &ret, bool inFinish )
-{
- ret << "(" << ps << ")";
-}
-
-void Goto::TARGS( ostream &ret, bool inFinish, int targState )
-{
- ret << "(" << vCS() << ")";
-}
-
-void Goto::NEXT( ostream &ret, int nextDest, bool inFinish )
-{
- ret << vCS() << " = " << nextDest << ";";
-}
-
-void Goto::NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish )
-{
- ret << vCS() << " = (";
- INLINE_LIST( ret, ilItem->children, 0, inFinish, false );
- ret << ");";
-}
-
-void Goto::CALL( ostream &ret, int callDest, int targState, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK();
-
- if ( red->prePushExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->prePushExpr );
- INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " <<
- TOP() << " += 1;" << vCS() << " = " <<
- callDest << ";";
-
- if ( inFinish && !noEnd )
- EOF_CHECK( ret );
-
- ret << " goto " << _again << ";";
-
- ret << CLOSE_GEN_BLOCK();
-}
-
-void Goto::NCALL( ostream &ret, int callDest, int targState, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK();
-
- if ( red->prePushExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->prePushExpr );
- INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " <<
- TOP() << " += 1;" << vCS() << " = " <<
- callDest << "; " << CLOSE_GEN_BLOCK();
-}
-
-void Goto::CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK();
-
- if ( red->prePushExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->prePushExpr );
- INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " << TOP() << " += 1;" <<
- vCS() << " = " << OPEN_HOST_EXPR();
- INLINE_LIST( ret, ilItem->children, targState, inFinish, false );
- ret << CLOSE_HOST_EXPR() << ";";
-
- if ( inFinish && !noEnd )
- EOF_CHECK( ret );
-
- ret << " goto " << _again << ";";
-
- ret << CLOSE_GEN_BLOCK();
-}
-
-void Goto::NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK();
-
- if ( red->prePushExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->prePushExpr );
- INLINE_LIST( ret, red->prePushExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- ret << STACK() << "[" << TOP() << "] = " << vCS() << "; " << TOP() << " += 1;" <<
- vCS() << " = " << OPEN_HOST_EXPR();
- INLINE_LIST( ret, ilItem->children, targState, inFinish, false );
- ret << CLOSE_HOST_EXPR() << "; " << CLOSE_GEN_BLOCK();
-}
-
-void Goto::RET( ostream &ret, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK() << TOP() << "-= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];";
-
- if ( red->postPopExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->postPopExpr );
- INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- if ( inFinish && !noEnd )
- EOF_CHECK( ret );
-
- ret << "goto " << _again << ";" << CLOSE_GEN_BLOCK();
-}
-
-void Goto::NRET( ostream &ret, bool inFinish )
-{
- ret << OPEN_GEN_BLOCK() << TOP() << "-= 1;" << vCS() << " = " << STACK() << "[" << TOP() << "];";
-
- if ( red->postPopExpr != 0 ) {
- ret << OPEN_HOST_BLOCK( red->postPopExpr );
- INLINE_LIST( ret, red->postPopExpr->inlineList, 0, false, false );
- ret << CLOSE_HOST_BLOCK();
- }
-
- ret << CLOSE_GEN_BLOCK();
-}
-
-void Goto::BREAK( ostream &ret, int targState, bool csForced )
-{
- ret << OPEN_GEN_BLOCK() << P() << " += 1; " << "goto " << _out << "; " << CLOSE_GEN_BLOCK();
-}
-
-void Goto::NBREAK( ostream &ret, int targState, bool csForced )
-{
- ret << OPEN_GEN_BLOCK() << P() << " += 1; " << nbreak << " = 1; " << CLOSE_GEN_BLOCK();
-}
-
-void Goto::tableDataPass()
-{
- if ( type == Loop )
- taActions();
-
- taToStateActions();
- taFromStateActions();
- taEofActions();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-}
-
-void Goto::genAnalysis()
-{
- /* For directly executable machines there is no required state
- * ordering. Choose a depth-first ordering to increase the
- * potential for fall-throughs. */
- redFsm->depthFirstOrdering();
-
- /* Choose default transitions and the single transition. */
- redFsm->chooseDefaultSpan();
-
- /* Choose single. */
- redFsm->moveSelectTransToSingle();
-
- /* If any errors have occured in the input file then don't write anything. */
- if ( red->id->errorCount > 0 )
- return;
-
- /* Anlayze Machine will find the final action reference counts, among other
- * things. We will use these in reporting the usage of fsm directives in
- * action code. */
- red->analyzeMachine();
-
- /* Run the analysis pass over the table data. */
- setTableState( TableArray::AnalyzePass );
- tableDataPass();
-
- /* Switch the tables over to the code gen mode. */
- setTableState( TableArray::GeneratePass );
-}
-
-void Goto::writeData()
-{
- if ( type == Loop ) {
- if ( redFsm->anyActions() )
- taActions();
- }
-
- if ( redFsm->anyToStateActions() )
- taToStateActions();
-
- if ( redFsm->anyFromStateActions() )
- taFromStateActions();
-
- if ( redFsm->anyEofActions() )
- taEofActions();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-
- STATE_IDS();
-}
-
-void Goto::writeExec()
-{
- int maxCtrId = redFsm->nextCondId > redFsm->nextTransId ? redFsm->nextCondId : redFsm->nextTransId;
- ctrLabel = allocateLabels( ctrLabel, IpLabel::Ctr, maxCtrId );
-
- out << "{\n";
-
- DECLARE( INT(), cpc );
- DECLARE( INT(), ck );
- DECLARE( INT(), pop_test );
- DECLARE( INT(), nbreak );
- DECLARE( INT(), ps, " = 0" );
- DECLARE( INT(), new_recs );
- DECLARE( INT(), alt );
- DECLARE( INDEX( ARR_TYPE( actions ) ), acts );
- DECLARE( UINT(), nacts );
-
- out << "\n";
-
- out << EMIT_LABEL( _resume );
-
- /* Do we break out on no more input. */
- bool eof = redFsm->anyEofActivity() || redFsm->anyNfaStates();
- if ( !noEnd ) {
- if ( eof ) {
- out <<
- " if ( " << P() << " == " << PE() << " && " << P() << " != " << vEOF() << " )\n"
- " goto " << _out << ";\n";
- }
- else {
- out <<
- " if ( " << P() << " == " << PE() << " )\n"
- " goto " << _out << ";\n";
- }
- }
-
- NFA_PUSH( vCS() );
-
- out <<
- " switch ( " << vCS() << " ) {\n";
- STATE_CASES() <<
- " }\n"
- "\n";
- TRANSITIONS() <<
- "\n";
-
- if ( redFsm->anyRegActions() )
- EXEC_FUNCS() << "\n";
-
- out << EMIT_LABEL( _again );
-
- if ( !noEnd && eof ) {
- out <<
- " if ( " << P() << " == " << vEOF() << " ) {\n"
- " if ( " << vCS() << " >= " << FIRST_FINAL_STATE() << " )\n"
- " goto " << _out << ";\n"
- " }\n"
- " else {\n";
- }
-
- TO_STATE_ACTIONS();
-
- if ( redFsm->errState != 0 ) {
- out <<
- " if ( " << vCS() << " != " << redFsm->errState->id << " ) {\n";
- }
-
- out <<
- " " << P() << " += 1;\n"
- " goto " << _resume << ";\n";
-
- if ( redFsm->errState != 0 ) {
- out <<
- " }\n";
- }
-
- if ( !noEnd && eof ) {
- out <<
- " }\n";
- }
-
- if ( redFsm->anyNfaStates() ) {
- out <<
- " if ( nfa_len == 0 )\n"
- " goto " << _out << ";\n"
- "\n"
- " nfa_count += 1;\n"
- " nfa_len -= 1;\n"
- " " << P() << " = nfa_bp[nfa_len].p;\n"
- ;
-
- if ( redFsm->bAnyNfaPops ) {
- NFA_FROM_STATE_ACTION_EXEC();
-
- NFA_POP_TEST_EXEC();
-
- out <<
- " if ( " << pop_test << " )\n"
- " " << vCS() << " = nfa_bp[nfa_len].state;\n"
- " else\n"
- " " << vCS() << " = " << ERROR_STATE() << ";\n";
- }
- else {
- out <<
- " " << vCS() << " = nfa_bp[nfa_len].state;\n";
-
- }
-
- NFA_POST_POP();
-
- out << "goto " << _resume << ";\n";
- }
-
- out << EMIT_LABEL( _out );
-
- out << "}\n";
-}
diff --git a/src/goto.h b/src/goto.h
deleted file mode 100644
index dcf13448..00000000
--- a/src/goto.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _C_GOTO_H
-#define _C_GOTO_H
-
-#include <iostream>
-#include "codegen.h"
-
-/* Forwards. */
-struct CodeGenData;
-struct NameInst;
-struct RedTransAp;
-struct RedStateAp;
-struct GenStateCond;
-
-struct IpLabel
-{
- IpLabel()
- :
- type(None),
- stid(0),
- isReferenced(false)
- {}
-
- enum Type
- {
- None = 1,
- TestEof,
- Ctr,
- St,
- Out,
- Pop
- };
-
- std::string reference()
- {
- isReferenced = true;
- return define();
- }
-
- std::string define()
- {
- std::stringstream ss;
- switch ( type ) {
- case None: break;
- case TestEof:
- ss << "_test_eof" << stid;
- break;
- case Ctr:
- ss << "_ctr" << stid;
- break;
- case St:
- ss << "_st" << stid;
- break;
- case Out:
- ss << "_out" << stid;
- break;
- case Pop:
- ss << "_pop" << stid;
- break;
- }
-
- return ss.str();
- }
-
- Type type;
- int stid;
- bool isReferenced;
-};
-
-
-/*
- * Goto driven fsm.
- */
-class Goto
- : public CodeGen
-{
-public:
- enum Type {
- Loop = 1,
- Exp,
- Ip
- };
-
- Goto( const CodeGenArgs &args, Type type )
- :
- CodeGen( args ),
- type(type),
- acts( "_acts" ),
- nacts( "_nacts" ),
- ck( "_ck" ),
- nbreak( "_nbreak" ),
- ps( "_ps" ),
- _out("_out"),
- _pop("_pop"),
- _again("_again"),
- _resume("_resume"),
- _test_eof("_test_eof"),
- actions( "actions", *this ),
- toStateActions( "to_state_actions", *this ),
- fromStateActions( "from_state_actions", *this ),
- eofActions( "eof_actions", *this ),
- ctrLabel(0)
- {}
-
- void tableDataPass();
- virtual void genAnalysis();
- virtual void writeData();
- virtual void writeExec();
-
- std::ostream &TRANSITION( RedCondPair *pair );
-
- void FROM_STATE_ACTION_EMIT( RedStateAp *state );
-
- std::ostream &STATE_CASES();
- std::ostream &TRANSITIONS();
-
- Type type;
-
- Variable acts;
- Variable nacts;
- Variable ck;
- Variable nbreak;
- Variable ps;
-
- GotoLabel _out;
- GotoLabel _pop;
- GotoLabel _again;
- GotoLabel _resume;
- GotoLabel _test_eof;
-
- TableArray actions;
- TableArray toStateActions;
- TableArray fromStateActions;
- TableArray eofActions;
-
- IpLabel *ctrLabel;
-
- void taActions();
- void taToStateActions();
- void taFromStateActions();
- void taEofActions();
- void taNfaTargs();
- void taNfaOffsets();
- void taNfaPushActions();
- void taNfaPopTrans();
-
- void EOF_CHECK( ostream &ret );
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NEXT( ostream &ret, int nextDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void CURS( ostream &ret, bool inFinish );
- void TARGS( ostream &ret, bool inFinish, int targState );
- void RET( ostream &ret, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
- void BREAK( ostream &ret, int targState, bool csForced );
- void NBREAK( ostream &ret, int targState, bool csForced );
-
- virtual unsigned int TO_STATE_ACTION( RedStateAp *state );
- virtual unsigned int FROM_STATE_ACTION( RedStateAp *state );
- virtual unsigned int EOF_ACTION( RedStateAp *state );
-
- virtual std::ostream &EXEC_FUNCS() = 0;
- virtual std::ostream &TO_STATE_ACTION_SWITCH() = 0;
- virtual std::ostream &FROM_STATE_ACTION_SWITCH() = 0;
- virtual std::ostream &EOF_ACTION_SWITCH() = 0;
-
- std::ostream &ACTIONS_ARRAY();
-
- void setTableState( TableArray::State );
-
- virtual std::ostream &COND_GOTO( RedCondPair *trans );
-
- string CKEY( CondKey key );
- void COND_B_SEARCH( RedTransAp *trans, CondKey lower, CondKey upper, int low, int high);
-
- virtual std::ostream &TRANS_GOTO( RedTransAp *trans );
-
- void SINGLE_SWITCH( RedStateAp *state );
- void RANGE_B_SEARCH( RedStateAp *state, Key lower, Key upper, int low, int high );
-
- /* Called from STATE_GOTOS just before writing the gotos */
- virtual void GOTO_HEADER( RedStateAp *state );
- virtual void STATE_GOTO_ERROR();
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ ) = 0;
- virtual void NFA_POP_TEST( RedNfaTarg *targ ) {}
- virtual void NFA_FROM_STATE_ACTION_EXEC() = 0;
-
- void NFA_POP() {}
-
- virtual void FROM_STATE_ACTIONS() = 0;
- virtual void TO_STATE_ACTIONS() = 0;
- virtual void REG_ACTIONS() = 0;
- virtual void EOF_ACTIONS() = 0;
-
- IpLabel *allocateLabels( IpLabel *labels, IpLabel::Type type, int n );
-};
-
-#endif
diff --git a/src/gotoexp.cc b/src/gotoexp.cc
deleted file mode 100644
index dea9029c..00000000
--- a/src/gotoexp.cc
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "gotoexp.h"
-#include "redfsm.h"
-#include "gendata.h"
-#include "bstmap.h"
-#include "parsedata.h"
-#include "inputdata.h"
-
-std::ostream &GotoExp::EXEC_FUNCS()
-{
- /* Loop the actions. */
- for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
- if ( redAct->numTransRefs > 0 ) {
- /* We are at the start of a glob, write the case. */
- out << "f" << redAct->actListId << ":\n";
-
- if ( redFsm->anyRegNbreak() )
- out << nbreak << " = 0;\n";
-
- /* Write each action in the list of action items. */
- for ( GenActionTable::Iter item = redAct->key; item.lte(); item++ )
- ACTION( out, item->value, IlOpts( 0, false, false ) );
-
- if ( redFsm->anyRegNbreak() ) {
- out <<
- " if ( " << nbreak << " == 1 )\n"
- " goto " << _out << ";\n";
- }
-
-
- out << "goto " << _again << ";\n";
- }
- }
- return out;
-}
-
-/* Write out the function switch. This switch is keyed on the values
- * of the func index. */
-std::ostream &GotoExp::TO_STATE_ACTION_SWITCH()
-{
- /* Loop the actions. */
- for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
- if ( redAct->numToStateRefs > 0 ) {
- /* Write the entry label. */
- out << "\t" << CASE( STR( redAct->actListId+1 ) ) << "{\n";
-
- /* Write each action in the list of action items. */
- for ( GenActionTable::Iter item = redAct->key; item.lte(); item++ )
- ACTION( out, item->value, IlOpts( 0, false, false ) );
-
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-/* Write out the function switch. This switch is keyed on the values
- * of the func index. */
-std::ostream &GotoExp::FROM_STATE_ACTION_SWITCH()
-{
- /* Loop the actions. */
- for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
- if ( redAct->numFromStateRefs > 0 ) {
- /* Write the entry label. */
- out << "\t" << CASE( STR( redAct->actListId+1 ) ) << "{\n";
-
- /* Write each action in the list of action items. */
- for ( GenActionTable::Iter item = redAct->key; item.lte(); item++ )
- ACTION( out, item->value, IlOpts( 0, false, false ) );
-
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-std::ostream &GotoExp::EOF_ACTION_SWITCH()
-{
- /* Loop the actions. */
- for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
- if ( redAct->numEofRefs > 0 ) {
- /* Write the entry label. */
- out << "\t" << CASE( STR( redAct->actListId+1 ) ) << "{\n";
-
- /* Write each action in the list of action items. */
- for ( GenActionTable::Iter item = redAct->key; item.lte(); item++ )
- ACTION( out, item->value, IlOpts( 0, true, false ) );
-
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-unsigned int GotoExp::TO_STATE_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->toStateAction != 0 )
- act = state->toStateAction->actListId+1;
- return act;
-}
-
-unsigned int GotoExp::FROM_STATE_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->fromStateAction != 0 )
- act = state->fromStateAction->actListId+1;
- return act;
-}
-
-unsigned int GotoExp::EOF_ACTION( RedStateAp *state )
-{
- int act = 0;
- if ( state->eofAction != 0 )
- act = state->eofAction->actListId+1;
- return act;
-}
-
-void GotoExp::NFA_PUSH_ACTION( RedNfaTarg *targ )
-{
- int act = 0;
- if ( targ->push != 0 )
- act = targ->push->actListId+1;
- nfaPushActions.value( act );
-}
-
-void GotoExp::NFA_POP_TEST( RedNfaTarg *targ )
-{
- int act = 0;
- if ( targ->popTest != 0 )
- act = targ->popTest->actListId+1;
- nfaPopTrans.value( act );
-}
-
-
-void GotoExp::NFA_FROM_STATE_ACTION_EXEC()
-{
- if ( redFsm->anyFromStateActions() ) {
- out <<
- " switch ( " << ARR_REF( fromStateActions ) << "[nfa_bp[nfa_len].state] ) {\n";
- FROM_STATE_ACTION_SWITCH() <<
- " }\n"
- "\n";
- }
-}
-
-void GotoExp::FROM_STATE_ACTIONS()
-{
- if ( redFsm->anyFromStateActions() ) {
- out <<
- " switch ( " << ARR_REF( fromStateActions ) << "[" << vCS() << "] ) {\n";
- FROM_STATE_ACTION_SWITCH() <<
- " }\n"
- "\n";
- }
-}
-
-void GotoExp::TO_STATE_ACTIONS()
-{
- if ( redFsm->anyToStateActions() ) {
- out <<
- " switch ( " << ARR_REF( toStateActions ) << "[" << vCS() << "] ) {\n";
- TO_STATE_ACTION_SWITCH() <<
- " }\n"
- "\n";
- }
-}
-
-void GotoExp::REG_ACTIONS()
-{
-
-}
-
-void GotoExp::EOF_ACTIONS()
-{
- if ( redFsm->anyEofActions() ) {
- out <<
- " switch ( " << ARR_REF( eofActions ) << "[" << vCS() << "] ) {\n";
- EOF_ACTION_SWITCH() <<
- " }\n";
- }
-
-}
diff --git a/src/gotoexp.h b/src/gotoexp.h
deleted file mode 100644
index ddb3f138..00000000
--- a/src/gotoexp.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 SWITCH_GOTO_EXP_H
-#define SWITCH_GOTO_EXP_H
-
-#include <iostream>
-#include "goto.h"
-
-/* Forwards. */
-struct CodeGenData;
-
-/*
- * class GotoExp
- */
-class GotoExp
- : public Goto
-{
-public:
- GotoExp( const CodeGenArgs &args )
- : Goto(args, Exp) {}
-
- virtual std::ostream &EXEC_FUNCS();
- virtual std::ostream &TO_STATE_ACTION_SWITCH();
- virtual std::ostream &FROM_STATE_ACTION_SWITCH();
- virtual std::ostream &EOF_ACTION_SWITCH();
-
- unsigned int TO_STATE_ACTION( RedStateAp *state );
- unsigned int FROM_STATE_ACTION( RedStateAp *state );
- unsigned int EOF_ACTION( RedStateAp *state );
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ );
- virtual void NFA_POP_TEST( RedNfaTarg *targ );
- virtual void NFA_FROM_STATE_ACTION_EXEC();
-
- virtual void FROM_STATE_ACTIONS();
- virtual void TO_STATE_ACTIONS();
- virtual void REG_ACTIONS();
- virtual void EOF_ACTIONS();
-};
-
-namespace C
-{
- class GotoExp
- :
- public ::GotoExp
- {
- public:
- GotoExp( const CodeGenArgs &args )
- : ::GotoExp( args )
- {}
- };
-}
-
-
-#endif
diff --git a/src/gotoloop.cc b/src/gotoloop.cc
deleted file mode 100644
index 41a8cd8a..00000000
--- a/src/gotoloop.cc
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "gotoloop.h"
-#include "redfsm.h"
-#include "bstmap.h"
-#include "gendata.h"
-#include "parsedata.h"
-#include "inputdata.h"
-
-std::ostream &GotoLoop::ACTION_SWITCH()
-{
- /* Walk the list of functions, printing the cases. */
- for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
- /* Write out referenced actions. */
- if ( act->numTransRefs > 0 ) {
- /* Write the case label, the action and the case break. */
- out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
- ACTION( out, act, IlOpts( 0, false, false ) );
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-std::ostream &GotoLoop::EOF_ACTION_SWITCH()
-{
- /* Walk the list of functions, printing the cases. */
- for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
- /* Write out referenced actions. */
- if ( act->numEofRefs > 0 ) {
- /* Write the case label, the action and the case break. */
- out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
- ACTION( out, act, IlOpts( 0, true, false ) );
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-std::ostream &GotoLoop::FROM_STATE_ACTION_SWITCH()
-{
- /* Walk the list of functions, printing the cases. */
- for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
- /* Write out referenced actions. */
- if ( act->numFromStateRefs > 0 ) {
- /* Write the case label, the action and the case break. */
- out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
- ACTION( out, act, IlOpts( 0, false, false ) );
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-std::ostream &GotoLoop::TO_STATE_ACTION_SWITCH()
-{
- /* Walk the list of functions, printing the cases. */
- for ( GenActionList::Iter act = red->actionList; act.lte(); act++ ) {
- /* Write out referenced actions. */
- if ( act->numToStateRefs > 0 ) {
- /* Write the case label, the action and the case break. */
- out << "\t" << CASE( STR( act->actionId ) ) << "{\n";
- ACTION( out, act, IlOpts( 0, false, false ) );
- out << "\n\t" << CEND() << "\n}\n";
- }
- }
-
- return out;
-}
-
-void GotoLoop::NFA_PUSH_ACTION( RedNfaTarg *targ )
-{
- int act = 0;
- if ( targ->push != 0 )
- act = targ->push->actListId+1;
- nfaPushActions.value( act );
-}
-
-void GotoLoop::NFA_POP_TEST( RedNfaTarg *targ )
-{
- int act = 0;
- if ( targ->popTest != 0 )
- act = targ->popTest->actListId+1;
- nfaPopTrans.value( act );
-}
-
-std::ostream &GotoLoop::EXEC_FUNCS()
-{
- /* Make labels that set acts and jump to execFuncs. Loop func indices. */
- for ( GenActionTableMap::Iter redAct = redFsm->actionMap; redAct.lte(); redAct++ ) {
- if ( redAct->numTransRefs > 0 ) {
- out << " f" << redAct->actListId << ": " <<
- "" << acts << " = " << OFFSET( ARR_REF( actions ), itoa( redAct->location+1 ) ) << ";"
- " goto execFuncs;\n";
- }
- }
-
- out <<
- "\n"
- "execFuncs:\n";
-
- if ( redFsm->anyRegNbreak() )
- out << nbreak << " = 0;\n";
-
- out <<
- " " << nacts << " = " << CAST( UINT() ) << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << ";\n"
- " " << acts << " += 1;\n"
- " while ( " << nacts << " > 0 ) {\n"
- " switch ( " << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << " ) {\n";
- ACTION_SWITCH() <<
- " }\n"
- " " << acts << " += 1;\n"
- " " << nacts << " -= 1;\n"
- " }\n"
- "\n";
-
- if ( redFsm->anyRegNbreak() ) {
- out <<
- " if ( " << nbreak << " == 1 )\n"
- " goto " << _out << ";\n";
- }
-
- out <<
- " goto _again;\n";
- return out;
-}
-
-void GotoLoop::NFA_FROM_STATE_ACTION_EXEC()
-{
- if ( redFsm->anyFromStateActions() ) {
- out <<
- " " << acts << " = " << OFFSET( ARR_REF( actions ), ARR_REF( fromStateActions ) + "[nfa_bp[nfa_len].state]" ) << ";\n"
- " " << nacts << " = " << CAST( UINT() ) << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << ";\n"
- " " << acts << " += 1;\n"
- " while ( " << nacts << " > 0 ) {\n"
- " switch ( " << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << " ) {\n";
- FROM_STATE_ACTION_SWITCH() <<
- " }\n"
- " " << nacts << " -= 1;\n"
- " " << acts << " += 1;\n"
- " }\n"
- "\n";
- }
-}
-
-void GotoLoop::FROM_STATE_ACTIONS()
-{
- if ( redFsm->anyFromStateActions() ) {
- out <<
- " " << acts << " = " << OFFSET( ARR_REF( actions ),
- ARR_REF( fromStateActions ) + "[" + vCS() + "]" ) << ";\n"
- " " << nacts << " = " << CAST( UINT() ) << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << "; " << acts << " += 1;\n"
- " while ( " << nacts << " > 0 ) {\n"
- " switch ( " << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << " ) {\n";
- FROM_STATE_ACTION_SWITCH() <<
- " }\n"
- " " << acts << " += 1;\n"
- " " << nacts << " -= 1;\n"
- " }\n"
- "\n";
- }
-}
-
-void GotoLoop::TO_STATE_ACTIONS()
-{
- if ( redFsm->anyToStateActions() ) {
- out <<
- " " << acts << " = " << OFFSET( ARR_REF( actions ),
- ARR_REF( toStateActions ) + "[" + vCS() + "]" ) << ";\n"
- " " << nacts << " = " << CAST( UINT() ) << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << "; " << acts << " += 1;\n"
- " while ( " << nacts << " > 0 ) {\n"
- " switch ( " << DEREF( ARR_REF( actions ), "" + acts.ref() + "" ) << " ) {\n";
- TO_STATE_ACTION_SWITCH() <<
- " }\n"
- " " << acts << " += 1;\n"
- " " << nacts << " -= 1;\n"
- " }\n"
- "\n";
- }
-}
-
-void GotoLoop::REG_ACTIONS()
-{
-}
-
-void GotoLoop::EOF_ACTIONS()
-{
- if ( redFsm->anyEofActions() ) {
- out <<
- " " << INDEX( ARR_TYPE( actions ), "__acts" ) << ";\n"
- " " << UINT() << " __nacts;\n"
- " __acts = " << OFFSET( ARR_REF( actions ),
- ARR_REF( eofActions ) + "[" + vCS() + "]" ) << ";\n"
- " __nacts = " << CAST( UINT() ) << DEREF( ARR_REF( actions ), "__acts" ) << "; __acts += 1;\n"
- " while ( __nacts > 0 ) {\n"
- " switch ( " << DEREF( ARR_REF( actions ), "__acts" ) << " ) {\n";
- EOF_ACTION_SWITCH() <<
- " }\n"
- " __acts += 1;\n"
- " __nacts -= 1;\n"
- " }\n";
- }
-}
diff --git a/src/gotoloop.h b/src/gotoloop.h
deleted file mode 100644
index 68c43ce2..00000000
--- a/src/gotoloop.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 SWITCH_GOTO_LOOP_H
-#define SWITCH_GOTO_LOOP_H
-
-#include <iostream>
-#include "goto.h"
-
-/* Forwards. */
-struct CodeGenData;
-struct NameInst;
-struct RedTransAp;
-struct RedStateAp;
-struct GenStateCond;
-
-class GotoLoop
- : public Goto
-{
-public:
- GotoLoop( const CodeGenArgs &args )
- : Goto(args, Loop) {}
-
- virtual std::ostream &ACTION_SWITCH();
- virtual std::ostream &EXEC_FUNCS();
- virtual std::ostream &TO_STATE_ACTION_SWITCH();
- virtual std::ostream &FROM_STATE_ACTION_SWITCH();
- virtual std::ostream &EOF_ACTION_SWITCH();
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ );
- virtual void NFA_POP_TEST( RedNfaTarg *targ );
- virtual void NFA_FROM_STATE_ACTION_EXEC();
-
- virtual void FROM_STATE_ACTIONS();
- virtual void TO_STATE_ACTIONS();
- virtual void REG_ACTIONS();
- virtual void EOF_ACTIONS();
-};
-
-namespace C
-{
- class GotoLoop
- :
- public ::GotoLoop
- {
- public:
- GotoLoop( const CodeGenArgs &args )
- : ::GotoLoop( args )
- {}
- };
-}
-
-#endif
diff --git a/src/host-asm/main.cc b/src/host-asm/main.cc
index 21f8a515..c5523737 100644
--- a/src/host-asm/main.cc
+++ b/src/host-asm/main.cc
@@ -21,7 +21,7 @@
*/
#include "inputdata.h"
-#include "asm.h"
+#include <libfsm/asm.h>
extern struct colm_sections rlparseAsm;
diff --git a/src/inputdata.cc b/src/inputdata.cc
index 66ec4afb..d7e075d8 100644
--- a/src/inputdata.cc
+++ b/src/inputdata.cc
@@ -20,8 +20,8 @@
* SOFTWARE.
*/
-#include "ragel.h"
-#include "common.h"
+#include <libfsm/ragel.h>
+#include <libfsm/common.h>
#include "inputdata.h"
#include "parsedata.h"
#include "load.h"
diff --git a/src/inputdata.h b/src/inputdata.h
index 689f9078..44199ac1 100644
--- a/src/inputdata.h
+++ b/src/inputdata.h
@@ -23,7 +23,7 @@
#ifndef _INPUT_DATA
#define _INPUT_DATA
-#include "gendata.h"
+#include <libfsm/gendata.h>
#include <iostream>
#include <sstream>
#include <vector>
diff --git a/src/ipgoto.h b/src/ipgoto.h
deleted file mode 100644
index 1ec51bbf..00000000
--- a/src/ipgoto.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 IPGOTO_H
-#define IPGOTO_H
-
-#include <iostream>
-#include "goto.h"
-
-/* Forwards. */
-struct CodeGenData;
-
-/*
- * class FGotoCodeGen
- */
-class IpGoto
- : public Goto
-{
-public:
- IpGoto( const CodeGenArgs &args )
- :
- Goto( args, Ip ),
- stLabel(0),
- ctrLabel(0),
- outLabel(0),
- popLabel(0)
- {}
-
- std::ostream &EXIT_STATES();
- std::ostream &TRANS_GOTO( RedTransAp *trans );
- std::ostream &COND_GOTO( RedCondPair *trans );
- std::ostream &FINISH_CASES();
- std::ostream &AGAIN_CASES();
- std::ostream &STATE_GOTOS();
- std::ostream &STATE_GOTO_CASES();
-
- /* unused. */
- virtual std::ostream &ACTION_SWITCH() { return out; }
- virtual std::ostream &EXEC_FUNCS() { return out; }
- virtual std::ostream &TO_STATE_ACTION_SWITCH() { return out; }
- virtual std::ostream &FROM_STATE_ACTION_SWITCH() { return out; }
- virtual std::ostream &EOF_ACTION_SWITCH() { return out; }
-
- /* Unused */
- virtual void FROM_STATE_ACTIONS() {}
- virtual void TO_STATE_ACTIONS() {}
- virtual void REG_ACTIONS() {}
- virtual void EOF_ACTIONS() {}
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NEXT( ostream &ret, int nextDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void RET( ostream &ret, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
- void CURS( ostream &ret, bool inFinish );
- void TARGS( ostream &ret, bool inFinish, int targState );
- void BREAK( ostream &ret, int targState, bool csForced );
- void NBREAK( ostream &ret, int targState, bool csForced );
-
- virtual void genAnalysis();
- virtual void writeData();
- virtual void writeExec();
-
-protected:
- bool useAgainLabel();
-
- /* Called from Goto::STATE_GOTOS just before writing the gotos for
- * each state. */
- bool IN_TRANS_ACTIONS( RedStateAp *state );
- void GOTO_HEADER( RedStateAp *state );
- void STATE_GOTO_ERROR();
-
- /* Set up labelNeeded flag for each state. */
- void setLabelsNeeded( RedCondPair *pair );
- void setLabelsNeeded( GenInlineList *inlineList );
- void setLabelsNeeded();
-
- void NFA_PUSH_ACTION( RedNfaTarg *targ );
- void NFA_POP_TEST( RedNfaTarg *targ );
- virtual void NFA_FROM_STATE_ACTION_EXEC();
-
- void NFA_PUSH_ST( RedStateAp *state );
-
- void tableDataPass();
-
- IpLabel *stLabel;
- IpLabel *ctrLabel;
- IpLabel *outLabel;
- IpLabel *popLabel;
-};
-
-namespace C
-{
- class IpGoto
- :
- public ::IpGoto
- {
- public:
- IpGoto( const CodeGenArgs &args )
- : ::IpGoto( args )
- {}
- };
-}
-
-#endif
diff --git a/src/load.cc b/src/load.cc
index 47aee0d4..d76c72e2 100644
--- a/src/load.cc
+++ b/src/load.cc
@@ -20,8 +20,8 @@
* SOFTWARE.
*/
+#include <libfsm/ragel.h>
#include "load.h"
-#include "ragel.h"
#include "inputdata.h"
#include "parsedata.h"
#include "parsetree.h"
diff --git a/src/load.h b/src/load.h
index 6ef7d57c..455a3090 100644
--- a/src/load.h
+++ b/src/load.h
@@ -23,7 +23,7 @@
#ifndef _LOAD_H
#define _LOAD_H
-#include "ragel.h"
+#include <libfsm/ragel.h>
struct LoadRagel;
struct InputData;
diff --git a/src/longest.cc b/src/longest.cc
index bf1b2a54..00c08ec9 100644
--- a/src/longest.cc
+++ b/src/longest.cc
@@ -29,7 +29,7 @@
#include <inputdata.h>
/* Parsing. */
-#include "ragel.h"
+#include <libfsm/ragel.h>
#include "parsetree.h"
#include "parsedata.h"
diff --git a/src/parsedata.cc b/src/parsedata.cc
index d3474684..9eb0b262 100644
--- a/src/parsedata.cc
+++ b/src/parsedata.cc
@@ -26,7 +26,7 @@
#include <stdlib.h>
#include <limits.h>
-#include "ragel.h"
+#include <libfsm/ragel.h>
#include "parsedata.h"
#include "parsetree.h"
#include "mergesort.h"
diff --git a/src/parsedata.h b/src/parsedata.h
index d45de5a6..1df3aa2e 100644
--- a/src/parsedata.h
+++ b/src/parsedata.h
@@ -33,12 +33,12 @@
#include "bstmap.h"
#include "vector.h"
#include "dlist.h"
-#include "fsmgraph.h"
+#include <libfsm/fsmgraph.h>
#include "compare.h"
#include "vector.h"
-#include "common.h"
+#include <libfsm/common.h>
#include "parsetree.h"
-#include "action.h"
+#include <libfsm/action.h>
/* Forwards. */
diff --git a/src/parsetree.cc b/src/parsetree.cc
index 38646cf6..f51c35e8 100644
--- a/src/parsetree.cc
+++ b/src/parsetree.cc
@@ -26,10 +26,10 @@
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
-#include <inputdata.h>
+#include "inputdata.h"
/* Parsing. */
-#include "ragel.h"
+#include <libfsm/ragel.h>
#include "parsetree.h"
#include "parsedata.h"
diff --git a/src/parsetree.h b/src/parsetree.h
index 1d4f7e6b..37f2fda7 100644
--- a/src/parsetree.h
+++ b/src/parsetree.h
@@ -23,12 +23,12 @@
#ifndef _PARSETREE_H
#define _PARSETREE_H
-#include "ragel.h"
+#include <libfsm/ragel.h>
+#include <libfsm/fsmgraph.h>
#include "avlmap.h"
#include "bstmap.h"
#include "vector.h"
#include "dlist.h"
-#include "fsmgraph.h"
struct NameInst;
diff --git a/src/ragel.h b/src/ragel.h
deleted file mode 100644
index c3fd6f22..00000000
--- a/src/ragel.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _RAGEL_H
-#define _RAGEL_H
-
-#include <stdio.h>
-#include <iostream>
-#include <fstream>
-#include <string>
-#include "vector.h"
-#include "config.h"
-#include "common.h"
-
-#define PROGNAME "ragel"
-
-#define MAIN_MACHINE "main"
-
-/* Target output style. */
-enum CodeStyle
-{
- GenBinaryLoop,
- GenBinaryExp,
- GenFlatLoop,
- GenFlatExp,
- GenGotoLoop,
- GenGotoExp,
- GenSwitchLoop,
- GenSwitchExp,
- GenIpGoto
-};
-
-/* To what degree are machine minimized. */
-enum MinimizeLevel {
- #ifdef TO_UPGRADE_CONDS
- MinimizeApprox,
- #endif
- #ifdef TO_UPGRADE_CONDS
- MinimizeStable,
- #endif
- MinimizePartition1,
- MinimizePartition2
-};
-
-enum MinimizeOpt {
- MinimizeNone,
- MinimizeEnd,
- MinimizeMostOps,
- MinimizeEveryOp
-};
-
-/* Target implementation */
-enum RubyImplEnum
-{
- MRI,
- Rubinius
-};
-
-/* Error reporting format. */
-enum ErrorFormat {
- ErrorFormatGNU,
- ErrorFormatMSVC,
-};
-
-extern ErrorFormat errorFormat;
-
-
-struct colm_location;
-
-InputLoc makeInputLoc( const char *fileName, int line = 0, int col = 0 );
-InputLoc makeInputLoc( const struct colm_location *loc );
-std::ostream &operator<<( std::ostream &out, const InputLoc &loc );
-
-void xmlEscapeHost( std::ostream &out, const char *data, long len );
-
-
-using std::endl;
-
-extern const char mainMachine[];
-
-struct AbortCompile
-{
- AbortCompile( int code )
- : code(code) {}
-
- int code;
-};
-
-#endif
diff --git a/src/redfsm.h b/src/redfsm.h
deleted file mode 100644
index 392b1a9c..00000000
--- a/src/redfsm.h
+++ /dev/null
@@ -1,889 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _REDFSM_H
-#define _REDFSM_H
-
-#include <assert.h>
-#include <string.h>
-#include <string>
-#include "config.h"
-#include "common.h"
-#include "vector.h"
-#include "dlist.h"
-#include "compare.h"
-#include "bstmap.h"
-#include "bstset.h"
-#include "avlmap.h"
-#include "avltree.h"
-#include "avlbasic.h"
-#include "mergesort.h"
-#include "sbstmap.h"
-#include "sbstset.h"
-#include "sbsttable.h"
-
-#define TRANS_ERR_TRANS 0
-#define STATE_ERR_STATE 0
-#define FUNC_NO_FUNC 0
-
-// #define SCORE_ORDERING 1
-
-using std::string;
-
-struct RedStateAp;
-struct GenInlineList;
-struct GenAction;
-struct FsmCtx;
-struct GenCondSpace;
-typedef BstSet<int> RedCondKeySet;
-
-/*
- * Inline code tree
- */
-struct GenInlineItem
-{
- enum Type
- {
- Text, Goto, Call, Ncall, Next, GotoExpr, CallExpr,
- NcallExpr, NextExpr, Ret, Nret,
- PChar, Char, Hold, Curs, Targs, Entry, Exec, Break, Nbreak,
- LmSwitch, LmExec, LmSetActId, LmSetTokEnd, LmGetTokEnd,
- LmInitAct, LmInitTokStart, LmSetTokStart, NfaClear,
- HostStmt, HostExpr, HostText,
- GenStmt, GenExpr, LmCase, LmHold,
- NfaWrapAction, NfaWrapConds
- };
-
- GenInlineItem( const InputLoc &loc, Type type ) :
- loc(loc), targId(0), targState(0),
- lmId(0), children(0), offset(0),
- wrappedAction(0), type(type) { }
-
- ~GenInlineItem();
-
- InputLoc loc;
- std::string data;
- int targId;
- RedStateAp *targState;
- int lmId;
- GenInlineList *children;
- int offset;
- GenAction *wrappedAction;
- GenCondSpace *condSpace;
- RedCondKeySet condKeySet;
- Type type;
-
- GenInlineItem *prev, *next;
-};
-
-/* Normally this would be atypedef, but that would entail including DList from
- * ptreetypes, which should be just typedef forwards. */
-struct GenInlineList : public DList<GenInlineItem> { };
-
-struct GenInlineExpr
-{
- GenInlineExpr( const InputLoc &loc, GenInlineList *inlineList )
- : loc(loc), inlineList( inlineList ) {}
-
- ~GenInlineExpr()
- {
- if ( inlineList != 0 ) {
- inlineList->empty();
- delete inlineList;
- }
- }
-
- InputLoc loc;
- GenInlineList *inlineList;
-};
-
-/* Element in list of actions. Contains the string for the code to exectute. */
-struct GenAction
-:
- public DListEl<GenAction>
-{
- GenAction( )
- :
- inlineList(0),
- actionId(0),
- numTransRefs(0),
- numToStateRefs(0),
- numFromStateRefs(0),
- numEofRefs(0),
- numNfaPushRefs(0),
- numNfaRestoreRefs(0),
- numNfaPopActionRefs(0),
- numNfaPopTestRefs(0)
- {
- }
-
- ~GenAction()
- {
- if ( inlineList != 0 ) {
- inlineList->empty();
- delete inlineList;
- }
- }
-
- /* Data collected during parse. */
- InputLoc loc;
- std::string name;
- GenInlineList *inlineList;
- int actionId;
-
- string nameOrLoc();
-
- /* Number of references in the final machine. */
- int numRefs()
- { return numTransRefs + numToStateRefs + numFromStateRefs + numEofRefs; }
- int numTransRefs;
- int numToStateRefs;
- int numFromStateRefs;
- int numEofRefs;
- int numNfaPushRefs;
- int numNfaRestoreRefs;
- int numNfaPopActionRefs;
- int numNfaPopTestRefs;
-};
-
-
-/* Forwards. */
-struct RedStateAp;
-struct StateAp;
-
-/* Transistion GenAction Element. */
-typedef SBstMapEl< int, GenAction* > GenActionTableEl;
-
-/* Transition GenAction Table. */
-struct GenActionTable
- : public SBstMap< int, GenAction*, CmpOrd<int> >
-{
- void setAction( int ordering, GenAction *action );
- void setActions( int *orderings, GenAction **actions, int nActs );
- void setActions( const GenActionTable &other );
-};
-
-/* Compare of a whole action table element (key & value). */
-struct CmpGenActionTableEl
-{
- static int compare( const GenActionTableEl &action1,
- const GenActionTableEl &action2 )
- {
- if ( action1.key < action2.key )
- return -1;
- else if ( action1.key > action2.key )
- return 1;
- else if ( action1.value < action2.value )
- return -1;
- else if ( action1.value > action2.value )
- return 1;
- return 0;
- }
-};
-
-/* Compare for GenActionTable. */
-typedef CmpSTable< GenActionTableEl, CmpGenActionTableEl > CmpGenActionTable;
-
-/* Set of states. */
-typedef BstSet<RedStateAp*> RedStateSet;
-typedef BstSet<int> IntSet;
-
-/* Reduced action. */
-struct RedAction
-:
- public AvlTreeEl<RedAction>
-{
- RedAction( )
- :
- key(),
- eofRefs(0),
- numTransRefs(0),
- numToStateRefs(0),
- numFromStateRefs(0),
- numEofRefs(0),
- numNfaPushRefs(0),
- numNfaRestoreRefs(0),
- numNfaPopActionRefs(0),
- numNfaPopTestRefs(0),
- bAnyNextStmt(false),
- bAnyCurStateRef(false),
- bAnyBreakStmt(false),
- bUsingAct(false)
- { }
-
- const GenActionTable &getKey()
- { return key; }
-
- GenActionTable key;
- int actListId;
- int location;
- IntSet *eofRefs;
-
- /* Number of references in the final machine. */
- int numRefs()
- { return numTransRefs + numToStateRefs + numFromStateRefs + numEofRefs; }
- int numTransRefs;
- int numToStateRefs;
- int numFromStateRefs;
- int numEofRefs;
- int numNfaPushRefs;
- int numNfaRestoreRefs;
- int numNfaPopActionRefs;
- int numNfaPopTestRefs;
-
- bool anyNextStmt() { return bAnyNextStmt; }
- bool anyCurStateRef() { return bAnyCurStateRef; }
- bool anyBreakStmt() { return bAnyBreakStmt; }
- bool usingAct() { return bUsingAct; }
-
- bool bAnyNextStmt;
- bool bAnyCurStateRef;
- bool bAnyBreakStmt;
- bool bUsingAct;
-};
-
-typedef AvlTree<RedAction, GenActionTable, CmpGenActionTable> GenActionTableMap;
-
-struct RedCondPair
-{
- int id;
- RedStateAp *targ;
- RedAction *action;
-};
-
-struct RedCondAp
-:
- public AvlTreeEl<RedCondAp>
-{
- RedCondAp( RedStateAp *targ, RedAction *action, int id )
- {
- p.id = id;
- p.targ = targ;
- p.action = action;
- }
-
- RedCondPair p;
-};
-
-struct RedCondEl
-{
- CondKey key;
- RedCondAp *value;
-};
-
-struct CmpRedCondEl
-{
- static int compare( const RedCondEl &el1, const RedCondEl &el2 )
- {
- if ( el1.key < el2.key )
- return -1;
- else if ( el1.key > el2.key )
- return 1;
- else if ( el1.value < el2.value )
- return -1;
- else if ( el1.value > el2.value )
- return 1;
- else
- return 0;
- }
-};
-
-typedef Vector< GenAction* > GenCondSet;
-
-struct GenCondSpace
-{
- GenCondSpace()
- :
- numTransRefs(0),
- numNfaRefs(0)
- {}
-
- Key baseKey;
- GenCondSet condSet;
- int condSpaceId;
-
- long fullSize()
- { return ( 1 << condSet.length() ); }
-
- long numTransRefs;
- long numNfaRefs;
-
- GenCondSpace *next, *prev;
-};
-
-typedef DList<GenCondSpace> CondSpaceList;
-
-struct RedCondVect
-{
- int numConds;
- RedCondEl *outConds;
- RedCondAp *errCond;
-};
-
-/* Reduced transition. */
-struct RedTransAp
-:
- public AvlTreeEl<RedTransAp>
-{
- RedTransAp( int id, GenCondSpace *condSpace,
- RedCondEl *outConds, int numConds, RedCondAp *errCond )
- :
- id(id),
- condSpace(condSpace)
- {
- v.outConds = outConds;
- v.numConds = numConds;
- v.errCond = errCond;
- }
-
- RedTransAp( int id, int condId, RedStateAp *targ, RedAction *action )
- :
- id(id),
- condSpace(0)
- {
- p.id = condId;
- p.targ = targ;
- p.action = action;
- }
-
- long condFullSize()
- {
- return condSpace == 0 ? 1 : condSpace->fullSize();
- }
-
- CondKey outCondKey( int off )
- {
- return condSpace == 0 ? CondKey(0) : v.outConds[off].key;
- }
-
- RedCondPair *outCond( int off )
- {
- return condSpace == 0 ? &p : &v.outConds[off].value->p;
- }
-
- int numConds()
- {
- return condSpace == 0 ? 1 : v.numConds;
- }
-
- RedCondPair *errCond()
- {
- return condSpace == 0 ? 0 : ( v.errCond != 0 ? &v.errCond->p : 0 );
- }
-
- int id;
- GenCondSpace *condSpace;
-
- /* Either a pair or a vector of conds. */
- union
- {
- RedCondPair p;
- RedCondVect v;
- };
-};
-
-/* Compare of transitions for the final reduction of transitions. Comparison
- * is on target and the pointer to the shared action table. It is assumed that
- * when this is used the action tables have been reduced. */
-struct CmpRedTransAp
-{
- static int compare( const RedTransAp &t1, const RedTransAp &t2 )
- {
- if ( t1.condSpace < t2.condSpace )
- return -1;
- else if ( t1.condSpace > t2.condSpace )
- return 1;
- else {
- if ( t1.condSpace == 0 ) {
- if ( t1.p.targ < t2.p.targ )
- return -1;
- else if ( t1.p.targ > t2.p.targ )
- return 1;
- else if ( t1.p.action < t2.p.action )
- return -1;
- else if ( t1.p.action > t2.p.action )
- return 1;
- else
- return 0;
-
- }
- else {
- if ( t1.v.numConds < t2.v.numConds )
- return -1;
- else if ( t1.v.numConds > t2.v.numConds )
- return 1;
- else
- {
- RedCondEl *i1 = t1.v.outConds, *i2 = t2.v.outConds;
- long len = t1.v.numConds, cmpResult;
- for ( long pos = 0; pos < len;
- pos += 1, i1 += 1, i2 += 1 )
- {
- cmpResult = CmpRedCondEl::compare(*i1, *i2);
- if ( cmpResult != 0 )
- return cmpResult;
- }
- return 0;
- }
- }
- }
- }
-};
-
-struct CmpRedCondAp
-{
- static int compare( const RedCondAp &t1, const RedCondAp &t2 )
- {
- if ( t1.p.targ < t2.p.targ )
- return -1;
- else if ( t1.p.targ > t2.p.targ )
- return 1;
- else if ( t1.p.action < t2.p.action )
- return -1;
- else if ( t1.p.action > t2.p.action )
- return 1;
- else
- return 0;
- }
-};
-
-typedef AvlBasic<RedTransAp, CmpRedTransAp> TransApSet;
-typedef AvlBasic<RedCondAp, CmpRedCondAp> CondApSet;
-
-/* Element in out range. */
-struct RedTransEl
-{
- /* Constructors. */
- RedTransEl( Key lowKey, Key highKey, RedTransAp *value )
- :
- lowKey(lowKey),
- highKey(highKey),
- value(value)
-#ifdef SCORE_ORDERING
- , score(0)
-#endif
- { }
-
- Key lowKey, highKey;
- RedTransAp *value;
-#ifdef SCORE_ORDERING
- long long score;
-#endif
-};
-
-typedef Vector<RedTransEl> RedTransList;
-typedef Vector<RedStateAp*> RedStateVect;
-
-typedef BstMapEl<RedStateAp*, unsigned long long> RedSpanMapEl;
-typedef BstMap<RedStateAp*, unsigned long long> RedSpanMap;
-
-/* Compare used by span map sort. Reverse sorts by the span. */
-struct CmpRedSpanMapEl
-{
- static int compare( const RedSpanMapEl &smel1, const RedSpanMapEl &smel2 )
- {
- if ( smel1.value > smel2.value )
- return -1;
- else if ( smel1.value < smel2.value )
- return 1;
- else
- return 0;
- }
-};
-
-/* Sorting state-span map entries by span. */
-typedef MergeSort<RedSpanMapEl, CmpRedSpanMapEl> RedSpanMapSort;
-
-/* Set of entry ids that go into this state. */
-typedef Vector<int> EntryIdVect;
-typedef Vector<char*> EntryNameVect;
-
-struct Condition
-{
- Condition( )
- : key(0), baseKey(0) {}
-
- Key key;
- Key baseKey;
- GenCondSet condSet;
-
- Condition *next, *prev;
-};
-typedef DList<Condition> ConditionList;
-
-struct GenStateCond
-{
- Key lowKey;
- Key highKey;
-
- GenCondSpace *condSpace;
-
- GenStateCond *prev, *next;
-};
-typedef DList<GenStateCond> GenStateCondList;
-typedef Vector<GenStateCond*> StateCondVect;
-
-struct RedNfaTarg
-{
- RedNfaTarg( RedStateAp *state, RedAction *push,
- RedAction *popTest, int order )
- :
- id(0),
- state(state),
- push(push),
- popTest(popTest),
- order(order)
- {}
-
- long id;
- RedStateAp *state;
- RedAction *push;
- RedAction *popTest;
- int order;
-};
-
-struct RedNfaTargCmp
-{
- static inline long compare( const RedNfaTarg &k1, const RedNfaTarg &k2 )
- {
- if ( k1.order < k2.order )
- return -1;
- else if ( k1.order > k2.order )
- return 1;
- return 0;
- }
-};
-
-typedef Vector<RedNfaTarg> RedNfaTargs;
-
-/* Reduced state. */
-struct RedStateAp
-{
- RedStateAp()
- :
- defTrans(0),
- transList(0),
- isFinal(false),
- labelNeeded(false),
- outNeeded(false),
- onStateList(false),
- onListRest(false),
- toStateAction(0),
- fromStateAction(0),
- eofAction(0),
- eofTrans(0),
- id(0),
- bAnyRegCurStateRef(false),
- partitionBoundary(false),
- inConds(0),
- numInConds(0),
- inCondTests(0),
- numInCondTests(0),
- nfaTargs(0),
- outCondSpace(0)
- { }
-
- /* Transitions out. */
- RedTransList outSingle;
- RedTransList outRange;
- RedTransAp *defTrans;
-
- /* For flat keys. */
- Key lowKey, highKey;
- RedTransAp **transList;
- long long low, high;
-
- /* The list of states that transitions from this state go to. */
- RedStateVect targStates;
-
- bool isFinal;
- bool labelNeeded;
- bool outNeeded;
- bool onStateList;
- bool onListRest;
- RedAction *toStateAction;
- RedAction *fromStateAction;
- RedAction *eofAction;
- RedTransAp *eofTrans;
- int id;
-
- /* Pointers for the list of states. */
- RedStateAp *prev, *next;
-
- bool anyRegCurStateRef() { return bAnyRegCurStateRef; }
- bool bAnyRegCurStateRef;
-
- int partition;
- bool partitionBoundary;
-
- RedCondPair **inConds;
- int numInConds;
-
- RedTransAp **inCondTests;
- int numInCondTests;
-
- RedNfaTargs *nfaTargs;
- GenCondSpace *outCondSpace;
- RedCondKeySet outCondKeys;
-};
-
-/* List of states. */
-typedef DList<RedStateAp> RedStateList;
-
-/* Set of reduced transitons. Comparison is by pointer. */
-typedef BstSet< RedTransAp*, CmpOrd<RedTransAp*> > RedTransSet;
-
-/* Next version of the fsm machine. */
-struct RedFsmAp
-{
- RedFsmAp( FsmCtx *fsmCtx, int machineId );
- ~RedFsmAp();
-
- KeyOps *keyOps;
- FsmCtx *fsmCtx;
- int machineId;
-
- bool forcedErrorState;
-
- int nextActionId;
- int nextTransId;
- int nextCondId;
-
- /* Next State Id doubles as the total number of state ids. */
- int nextStateId;
-
- TransApSet transSet;
- CondApSet condSet;
- GenActionTableMap actionMap;
- RedStateList stateList;
- RedStateSet entryPoints;
- RedStateAp *startState;
- RedStateAp *errState;
- RedTransAp *errTrans;
- RedCondAp *errCond;
- RedTransAp *errActionTrans;
- RedStateAp *firstFinState;
- RedStateAp *allStates;
- int numFinStates;
- int nParts;
-
- bool bAnyToStateActions;
- bool bAnyFromStateActions;
- bool bAnyRegActions;
- bool bAnyEofActions;
- bool bAnyEofTrans;
- bool bAnyEofActivity;
- bool bAnyActionGotos;
- bool bAnyActionCalls;
- bool bAnyActionNcalls;
- bool bAnyActionRets;
- bool bAnyActionNrets;
- bool bAnyActionByValControl;
- bool bAnyRegActionRets;
- bool bAnyRegActionByValControl;
- bool bAnyRegNextStmt;
- bool bAnyRegCurStateRef;
- bool bAnyRegBreak;
- bool bAnyRegNbreak;
- bool bUsingAct;
- bool bAnyNfaStates;
- bool bAnyNfaPushPops;
- bool bAnyNfaPushes;
- bool bAnyNfaPops;
- bool bAnyTransCondRefs;
- bool bAnyNfaCondRefs;
-
- int maxState;
- int maxSingleLen;
- int maxRangeLen;
- int maxKeyOffset;
- int maxIndexOffset;
- int maxIndex;
- int maxActListId;
- int maxActionLoc;
- int maxActArrItem;
- unsigned long long maxSpan;
- int maxFlatIndexOffset;
- Key maxKey;
- int maxCondSpaceId;
- int maxCond;
-
- bool anyActions();
- bool anyToStateActions() { return bAnyToStateActions; }
- bool anyFromStateActions() { return bAnyFromStateActions; }
- bool anyRegActions() { return bAnyRegActions; }
- bool anyEofActions() { return bAnyEofActions; }
- bool anyEofTrans() { return bAnyEofTrans; }
- bool anyEofActivity() { return bAnyEofActivity; }
- bool anyActionGotos() { return bAnyActionGotos; }
- bool anyActionCalls() { return bAnyActionCalls; }
- bool anyActionNcalls() { return bAnyActionNcalls; }
- bool anyActionRets() { return bAnyActionRets; }
- bool anyActionNrets() { return bAnyActionNrets; }
- bool anyActionByValControl() { return bAnyActionByValControl; }
- bool anyRegActionRets() { return bAnyRegActionRets; }
- bool anyRegActionByValControl() { return bAnyRegActionByValControl; }
- bool anyRegNextStmt() { return bAnyRegNextStmt; }
- bool anyRegCurStateRef() { return bAnyRegCurStateRef; }
- bool anyRegBreak() { return bAnyRegBreak; }
- bool usingAct() { return bUsingAct; }
- bool anyRegNbreak() { return bAnyRegNbreak; }
- bool anyNfaStates() { return bAnyNfaStates; }
-
- /* Is is it possible to extend a range by bumping ranges that span only
- * one character to the singles array. */
- bool canExtend( const RedTransList &list, int pos );
-
- /* Pick single transitions from the ranges. */
- void moveSelectTransToSingle( RedStateAp *state );
- void moveAllTransToSingle( RedStateAp *state );
-
- void moveSelectTransToSingle();
- void moveAllTransToSingle();
-
- void makeFlat();
-
- /* State low/high, in key space and class space. */
- Key lowKey;
- Key highKey;
- long long nextClass;
- long long *classMap;
-
- /* Support structs for equivalence class computation. */
- struct EquivClass
- {
- EquivClass( Key lowKey, Key highKey, long long value )
- : lowKey(lowKey), highKey(highKey), value(value) {}
-
- Key lowKey, highKey;
- long long value;
- EquivClass *prev, *next;
- };
-
- typedef DList<EquivClass> EquivList;
- typedef BstMap<RedTransAp*, int> EquivAlloc;
- typedef BstMapEl<RedTransAp*, int> EquivAllocEl;
-
- struct PairKey
- {
- PairKey( long long k1, long long k2 )
- : k1(k1), k2(k2) {}
-
- long long k1;
- long long k2;
- };
-
- struct PairKeyCmp
- {
- static inline long compare( const PairKey &k1, const PairKey &k2 )
- {
- if ( k1.k1 < k2.k1 )
- return -1;
- else if ( k1.k1 > k2.k1 )
- return 1;
- if ( k1.k2 < k2.k2 )
- return -1;
- else if ( k1.k2 > k2.k2 )
- return 1;
- else
- return 0;
- }
- };
-
- typedef BstMap< PairKey, long long, PairKeyCmp > PairKeyMap;
- typedef BstMapEl< PairKey, long long > PairKeyMapEl;
-
- void characterClass( EquivList &equiv );
- void makeFlatClass();
-
- /* Move a selected transition from ranges to default. */
- void moveToDefault( RedTransAp *defTrans, RedStateAp *state );
-
- /* Pick a default transition by largest span. */
- RedTransAp *chooseDefaultSpan( RedStateAp *state );
- void chooseDefaultSpan();
-
- /* Pick a default transition by most number of ranges. */
- RedTransAp *chooseDefaultNumRanges( RedStateAp *state );
- void chooseDefaultNumRanges();
-
- /* Pick a default transition tailored towards goto driven machine. */
- RedTransAp *chooseDefaultGoto( RedStateAp *state );
- void chooseDefaultGoto();
-
- /* Ordering states by transition connections. */
- void optimizeStateOrdering( RedStateAp *state );
- void optimizeStateOrdering();
-
- /* Ordering states by transition connections. */
- void depthFirstOrdering( RedStateAp *state );
- void depthFirstOrdering();
-
- void breadthFirstAdd( RedStateAp *state );
- void breadthFirstOrdering();
-
- void randomizedOrdering();
-
-#ifdef SCORE_ORDERING
- long **scores;
- void scoreSecondPass( RedStateAp *state );
- void scoreOrderingBreadth();
- void readScores();
- void scoreOrderingDepth( RedStateAp *state );
- void scoreOrderingDepth();
-#endif
-
- /* Set state ids. */
- void sequentialStateIds();
- void sortStateIdsByFinal();
-
- /* Arrange states in by final id. This is a stable sort. */
- void sortStatesByFinal();
-
- /* Sorting states by id. */
- void sortByStateId();
-
- /* Locating the first final state. This is the final state with the lowest
- * id. */
- void findFirstFinState();
-
- void assignActionLocs();
-
- RedCondAp *getErrorCond();
- RedTransAp *getErrorTrans();
- RedStateAp *getErrorState();
-
- /* Is every char in the alphabet covered? */
- bool alphabetCovered( RedTransList &outRange );
-
- RedTransAp *allocateTrans( RedStateAp *targ, RedAction *action );
- RedTransAp *allocateTrans( GenCondSpace *condSpace,
- RedCondEl *outConds, int numConds, RedCondAp *errCond );
-
- RedCondAp *allocateCond( RedStateAp *targState, RedAction *actionTable );
-
- void partitionFsm( int nParts );
-
- void setInTrans();
-};
-
-#endif
diff --git a/src/switch.cc b/src/switch.cc
deleted file mode 100644
index 076f3585..00000000
--- a/src/switch.cc
+++ /dev/null
@@ -1,1036 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "ragel.h"
-#include "switch.h"
-#include "redfsm.h"
-#include "gendata.h"
-
-#include <assert.h>
-
-std::ostream &Switch::TRANS_GOTO( int off, RedTransAp *trans )
-{
- out << "_trans = " << off << ";\n";
- return out;
-}
-
-void Switch::RANGE_B_SEARCH( RedStateAp *state, Key lower, Key upper, int low, int high )
-{
- /* Get the mid position, staying on the lower end of the range. */
- int mid = (low + high) >> 1;
- RedTransEl *data = state->outRange.data;
-
- /* Determine if we need to look higher or lower. */
- bool anyLower = mid > low;
- bool anyHigher = mid < high;
-
- /* Determine if the keys at mid are the limits of the alphabet. */
- bool limitLow = keyOps->eq( data[mid].lowKey, lower );
- bool limitHigh = keyOps->eq( data[mid].highKey, upper );
-
- if ( anyLower && anyHigher ) {
- /* Can go lower and higher than mid. */
- out << "if ( " << GET_KEY() << " < " <<
- KEY(data[mid].lowKey) << " ) {\n";
- RANGE_B_SEARCH( state, lower, keyOps->sub( data[mid].lowKey, 1 ), low, mid-1 );
- out << "} else if ( " << GET_KEY() << " > " <<
- KEY(data[mid].highKey) << " ) {\n";
- RANGE_B_SEARCH( state, keyOps->add( data[mid].highKey, 1 ), upper, mid+1, high );
- out << "} else {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value ) << "\n";
- out << "}\n";
- }
- else if ( anyLower && !anyHigher ) {
- /* Can go lower than mid but not higher. */
- out << "if ( " << GET_KEY() << " < " <<
- KEY(data[mid].lowKey) << " ) {\n";
- RANGE_B_SEARCH( state, lower, keyOps->sub( data[mid].lowKey, 1 ), low, mid-1 );
-
- /* if the higher is the highest in the alphabet then there is no
- * sense testing it. */
- if ( limitHigh ) {
- out << "} else {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
-
- out << "else {\n";
- DEFAULT( state );
- out << "}\n";
- }
- }
- else if ( !anyLower && anyHigher ) {
- /* Can go higher than mid but not lower. */
- out << "if ( " << GET_KEY() << " > " <<
- KEY(data[mid].highKey) << " ) {\n";
- RANGE_B_SEARCH( state, keyOps->add( data[mid].highKey, 1 ), upper, mid+1, high );
-
- /* If the lower end is the lowest in the alphabet then there is no
- * sense testing it. */
- if ( limitLow ) {
- out << "} else {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
- }
- else {
- out << "} else if ( " << GET_KEY() << " >= " <<
- KEY(data[mid].lowKey) << " ) {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
-
- out << "else {\n";
- DEFAULT( state );
- out << "}\n";
- }
- }
- else {
- /* Cannot go higher or lower than mid. It's mid or bust. What
- * tests to do depends on limits of alphabet. */
- if ( !limitLow && !limitHigh ) {
- out << "if ( " << KEY(data[mid].lowKey) << " <= " <<
- GET_KEY() << " && " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
-
- out << "else {\n";
- DEFAULT( state );
- out << "}\n";
- }
- else if ( limitLow && !limitHigh ) {
- out << "if ( " << GET_KEY() << " <= " <<
- KEY(data[mid].highKey) << " ) {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
-
- out << "else {\n";
- DEFAULT( state );
- out << "}\n";
- }
- else if ( !limitLow && limitHigh ) {
- out << "if ( " << KEY(data[mid].lowKey) << " <= " <<
- GET_KEY() << " ) {\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
-
- out << "else {\n";
- DEFAULT( state );
- out << "}\n";
- }
- else {
- /* Both high and low are at the limit. No tests to do. */
- out << "{\n";
- TRANS_GOTO(transBase + state->outSingle.length() + (mid), data[mid].value) << "\n";
- out << "}\n";
- }
- }
-}
-
-void Switch::SINGLE_SWITCH( RedStateAp *st )
-{
- /* Load up the singles. */
- int numSingles = st->outSingle.length();
- RedTransEl *data = st->outSingle.data;
-
- if ( numSingles == 1 ) {
- /* If there is a single single key then write it out as an if. */
- out << "\tif ( " << GET_KEY() << " == " <<
- KEY(data[0].lowKey) << " ) {\n\t\t";
-
- /* Virtual function for writing the target of the transition. */
- TRANS_GOTO(transBase, data[0].value) << "\n";
- out << "\t}\n";
-
- out << "else {\n";
- NOT_SINGLE( st );
- out << "}\n";
- }
- else if ( numSingles > 1 ) {
- /* Write out single keys in a switch if there is more than one. */
- out << "\tswitch( " << GET_KEY() << " ) {\n";
-
- /* Write out the single indices. */
- for ( int j = 0; j < numSingles; j++ ) {
- out << CASE( KEY(data[j].lowKey) ) << " {\n";
- TRANS_GOTO(transBase + j, data[j].value) << "\n";
- out << CEND() << "\n}\n";
- }
-
- out << CodeGen::DEFAULT() << " {\n";
- NOT_SINGLE( st );
- out << CEND() << "\n}\n";
-
- /* Close off the transition switch. */
- out << "\t}\n";
- }
-}
-
-void Switch::DEFAULT( RedStateAp *st )
-{
- if ( st->defTrans != 0 ) {
- TRANS_GOTO( transBase + st->outSingle.length() + st->outRange.length(), st->defTrans ) << "\n";
- }
-}
-
-void Switch::NOT_SINGLE( RedStateAp *st )
-{
- if ( st->outRange.length() > 0 ) {
- RANGE_B_SEARCH( st, keyOps->minKey, keyOps->maxKey,
- 0, st->outRange.length() - 1 );
- }
- else {
- DEFAULT( st );
- }
-}
-
-void Switch::LOCATE_TRANS()
-{
- transBase = 0;
-
- out <<
- " switch ( " << vCS() << " ) {\n";
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st == redFsm->errState ) {
- out << CASE( STR( st->id ) ) << " {\n";
- out << CEND() << "\n}\n";
- }
- else {
- /* Label the state. */
- out << CASE( STR( st->id ) ) << " {\n";
-
- /* Try singles. */
- if ( st->outSingle.length() > 0 ) {
- SINGLE_SWITCH( st );
- }
- else {
- NOT_SINGLE( st );
- }
-
- out << CEND() << "\n}\n";
- }
-
- transBase += st->outSingle.length() +
- st->outRange.length() +
- ( st->defTrans != 0 ? 1 : 0 );
- }
-
- out <<
- " }\n"
- "\n";
-}
-
-void Switch::genAnalysis()
-{
- redFsm->sortByStateId();
-
- /* Choose default transitions and the single transition. */
- redFsm->chooseDefaultSpan();
-
- /* Choose the singles. */
- redFsm->moveSelectTransToSingle();
-
- if ( redFsm->errState != 0 )
- redFsm->getErrorCond();
-
- /* If any errors have occured in the input file then don't write anything. */
- if ( red->id->errorCount > 0 )
- return;
-
- /* Anlayze Machine will find the final action reference counts, among other
- * things. We will use these in reporting the usage of fsm directives in
- * action code. */
- red->analyzeMachine();
-
- setKeyType();
-
- /* Run the analysis pass over the table data. */
- setTableState( TableArray::AnalyzePass );
- tableDataPass();
-
- /* Switch the tables over to the code gen mode. */
- setTableState( TableArray::GeneratePass );
-}
-
-
-void Switch::tableDataPass()
-{
- if ( type == Loop )
- taActions();
-
- taKeyOffsets();
- taSingleLens();
- taRangeLens();
- taIndexOffsets();
- taIndices();
-
- taTransCondSpacesWi();
- taTransOffsetsWi();
- taTransLengthsWi();
-
- taTransCondSpaces();
- taTransOffsets();
- taTransLengths();
-
- taCondTargs();
- taCondActions();
-
- taToStateActions();
- taFromStateActions();
- taEofActions();
- taEofConds();
- taEofTrans();
-
- taKeys();
- taCondKeys();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-}
-
-void Switch::writeData()
-{
- if ( type == Loop ) {
- /* If there are any transtion functions then output the array. If there
- * are none, don't bother emitting an empty array that won't be used. */
- if ( redFsm->anyActions() )
- taActions();
- }
-
- taKeyOffsets();
- taKeys();
- taSingleLens();
- taRangeLens();
- taIndexOffsets();
-
- taTransCondSpaces();
- taTransOffsets();
- taTransLengths();
-
- taCondKeys();
- taCondTargs();
- taCondActions();
-
- if ( redFsm->anyToStateActions() )
- taToStateActions();
-
- if ( redFsm->anyFromStateActions() )
- taFromStateActions();
-
- if ( redFsm->anyEofActions() )
- taEofActions();
-
- taEofConds();
-
- if ( redFsm->anyEofTrans() )
- taEofTrans();
-
- taNfaTargs();
- taNfaOffsets();
- taNfaPushActions();
- taNfaPopTrans();
-
- STATE_IDS();
-}
-
-
-void Switch::setKeyType()
-{
- transKeys.setType( ALPH_TYPE(), alphType->size, alphType->isChar );
- transKeys.isSigned = keyOps->isSigned;
-}
-
-void Switch::setTableState( TableArray::State state )
-{
- for ( ArrayVector::Iter i = arrayVector; i.lte(); i++ ) {
- TableArray *tableArray = *i;
- tableArray->setState( state );
- }
-}
-
-void Switch::taKeyOffsets()
-{
- keyOffsets.start();
-
- int curKeyOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- keyOffsets.value( curKeyOffset );
- curKeyOffset += st->outSingle.length() + st->outRange.length() * 2;
- }
-
- keyOffsets.finish();
-}
-
-
-void Switch::taSingleLens()
-{
- singleLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- singleLens.value( st->outSingle.length() );
-
- singleLens.finish();
-}
-
-
-void Switch::taRangeLens()
-{
- rangeLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- rangeLens.value( st->outRange.length() );
-
- rangeLens.finish();
-}
-
-void Switch::taIndexOffsets()
-{
- indexOffsets.start();
-
- int curIndOffset = 0;
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Write the index offset. */
- indexOffsets.value( curIndOffset );
-
- /* Move the index offset ahead. */
- curIndOffset += st->outSingle.length() + st->outRange.length();
- if ( st->defTrans != 0 )
- curIndOffset += 1;
- }
-
- indexOffsets.finish();
-}
-
-void Switch::taToStateActions()
-{
- toStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- TO_STATE_ACTION(st);
-
- toStateActions.finish();
-}
-
-void Switch::taFromStateActions()
-{
- fromStateActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- FROM_STATE_ACTION(st);
-
- fromStateActions.finish();
-}
-
-void Switch::taEofActions()
-{
- eofActions.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ )
- EOF_ACTION( st );
-
- eofActions.finish();
-}
-
-void Switch::taEofConds()
-{
- /*
- * EOF Cond Spaces
- */
- eofCondSpaces.start();
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 )
- eofCondSpaces.value( st->outCondSpace->condSpaceId );
- else
- eofCondSpaces.value( -1 );
- }
- eofCondSpaces.finish();
-
- /*
- * EOF Cond Key Indixes
- */
- eofCondKeyOffs.start();
-
- int curOffset = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long off = 0;
- if ( st->outCondSpace != 0 ) {
- off = curOffset;
- curOffset += st->outCondKeys.length();
- }
- eofCondKeyOffs.value( off );
- }
-
- eofCondKeyOffs.finish();
-
- /*
- * EOF Cond Key Lengths.
- */
- eofCondKeyLens.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long len = 0;
- if ( st->outCondSpace != 0 )
- len = st->outCondKeys.length();
- eofCondKeyLens.value( len );
- }
-
- eofCondKeyLens.finish();
-
- /*
- * EOF Cond Keys
- */
- eofCondKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->outCondSpace != 0 ) {
- for ( int c = 0; c < st->outCondKeys.length(); c++ ) {
- CondKey key = st->outCondKeys[c];
- eofCondKeys.value( key.getVal() );
- }
- }
- }
-
- eofCondKeys.finish();
-}
-
-void Switch::taEofTrans()
-{
- eofTrans.start();
-
- /* Need to compute transition positions. */
- int totalTrans = 0;
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- totalTrans += st->outSingle.length();
- totalTrans += st->outRange.length();
- if ( st->defTrans != 0 )
- totalTrans += 1;
- }
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- long trans = 0;
- if ( st->eofTrans != 0 ) {
- trans = totalTrans + 1;
- totalTrans += 1;
- }
-
- eofTrans.value( trans );
- }
-
- eofTrans.finish();
-}
-
-void Switch::taKeys()
-{
- transKeys.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Loop the singles. */
- for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ ) {
- transKeys.value( stel->lowKey.getVal() );
- }
-
- /* Loop the state's transitions. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- /* Lower key. */
- transKeys.value( rtel->lowKey.getVal() );
-
- /* Upper key. */
- transKeys.value( rtel->highKey.getVal() );
- }
- }
-
- transKeys.finish();
-}
-
-void Switch::taIndices()
-{
- indices.start();
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- /* Walk the singles. */
- for ( RedTransList::Iter stel = st->outSingle; stel.lte(); stel++ )
- indices.value( stel->value->id );
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ )
- indices.value( rtel->value->id );
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 )
- indices.value( st->defTrans->id );
- }
-
- indices.finish();
-}
-
-void Switch::taTransCondSpaces()
-{
- transCondSpaces.start();
-
- 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;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- if ( trans->condSpace != 0 )
- transCondSpaces.value( trans->condSpace->condSpaceId );
- else
- transCondSpaces.value( -1 );
- }
- }
-
- transCondSpaces.finish();
-}
-
-void Switch::taTransOffsets()
-{
- transOffsets.start();
-
- int curOffset = 0;
- 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;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- transOffsets.value( curOffset );
- curOffset += trans->numConds();
- }
- }
-
- errCondOffset = curOffset;
-
- transOffsets.finish();
-}
-
-void Switch::taTransLengths()
-{
- transLengths.start();
-
- 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;
- transLengths.value( trans->numConds() );
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- transLengths.value( trans->numConds() );
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- transLengths.value( trans->numConds() );
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- transLengths.value( trans->numConds() );
- }
- }
-
- transLengths.finish();
-}
-
-void Switch::taTransCondSpacesWi()
-{
- transCondSpacesWi.start();
-
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- /* Cond Space id. */
- if ( trans->condSpace != 0 )
- transCondSpacesWi.value( trans->condSpace->condSpaceId );
- else
- transCondSpacesWi.value( -1 );
- }
-
- transCondSpacesWi.finish();
-}
-
-void Switch::taTransOffsetsWi()
-{
- transOffsetsWi.start();
-
- int curOffset = 0;
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- transOffsetsWi.value( curOffset );
-
- TransApSet::Iter next = trans;
- next.increment();
-
- curOffset += trans->numConds();
- }
-
- transOffsetsWi.finish();
-}
-
-void Switch::taTransLengthsWi()
-{
- transLengthsWi.start();
-
- for ( TransApSet::Iter trans = redFsm->transSet; trans.lte(); trans++ ) {
- transLengthsWi.value( trans->numConds() );
-
- TransApSet::Iter next = trans;
- next.increment();
- }
-
- transLengthsWi.finish();
-}
-
-void Switch::taCondKeys()
-{
- condKeys.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- CondKey key = trans->outCondKey( c );
- condKeys.value( key.getVal() );
- }
- }
- }
-
- condKeys.finish();
-}
-
-void Switch::taCondTargs()
-{
- condTargs.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- condTargs.value( cond->targ->id );
- }
- }
- }
-
- if ( redFsm->errCond != 0 ) {
- RedCondPair *cond = &redFsm->errCond->p;
- condTargs.value( cond->targ->id );
- }
-
- condTargs.finish();
-}
-
-void Switch::taCondActions()
-{
- condActions.start();
-
- 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;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- COND_ACTION( cond );
- }
- }
-
- /* Walk the ranges. */
- for ( RedTransList::Iter rtel = st->outRange; rtel.lte(); rtel++ ) {
- RedTransAp *trans = rtel->value;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond( c );
- COND_ACTION( cond );
- }
- }
-
- /* The state's default index goes next. */
- if ( st->defTrans != 0 ) {
- RedTransAp *trans = st->defTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond(c);
- COND_ACTION( cond );
- }
- }
- }
-
- /* Add any eof transitions that have not yet been written out above. */
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->eofTrans != 0 ) {
- RedTransAp *trans = st->eofTrans;
- for ( int c = 0; c < trans->numConds(); c++ ) {
- RedCondPair *cond = trans->outCond(c);
- COND_ACTION( cond );
- }
- }
- }
-
- if ( redFsm->errCond != 0 ) {
- RedCondPair *cond = &redFsm->errCond->p;
- COND_ACTION( cond );
- }
-
- condActions.finish();
-}
-
-void Switch::taNfaTargs()
-{
- nfaTargs.start();
-
- /* Offset of zero means no NFA targs, put a filler there. */
- nfaTargs.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaTargs.value( st->nfaTargs->length() );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- nfaTargs.value( targ->state->id );
- }
- }
-
- nfaTargs.finish();
-}
-
-/* These need to mirror nfa targs. */
-void Switch::taNfaPushActions()
-{
- nfaPushActions.start();
-
- nfaPushActions.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
- nfaPushActions.value( 0 );
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_PUSH_ACTION( targ );
- }
- }
-
- nfaPushActions.finish();
-}
-
-void Switch::taNfaPopTrans()
-{
- nfaPopTrans.start();
-
- nfaPopTrans.value( 0 );
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs != 0 ) {
-
- nfaPopTrans.value( 0 );
-
- for ( RedNfaTargs::Iter targ = *st->nfaTargs; targ.lte(); targ++ )
- NFA_POP_TEST( targ );
- }
- }
-
- nfaPopTrans.finish();
-}
-
-void Switch::taNfaOffsets()
-{
- nfaOffsets.start();
-
- /* Offset of zero means no NFA targs, real targs start at 1. */
- long offset = 1;
-
- for ( RedStateList::Iter st = redFsm->stateList; st.lte(); st++ ) {
- if ( st->nfaTargs == 0 ) {
- nfaOffsets.value( 0 );
- }
- else {
- nfaOffsets.value( offset );
- offset += 1 + st->nfaTargs->length();
- }
- }
-
- nfaOffsets.finish();
-}
-
-
-/* Write out the array of actions. */
-std::ostream &Switch::ACTIONS_ARRAY()
-{
- out << "\t0, ";
- int totalActions = 1;
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Write out the length, which will never be the last character. */
- out << act->key.length() << ", ";
- /* Put in a line break every 8 */
- if ( totalActions++ % 8 == 7 )
- out << "\n\t";
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
- out << item->value->actionId;
- if ( ! (act.last() && item.last()) )
- out << ", ";
-
- /* Put in a line break every 8 */
- if ( totalActions++ % 8 == 7 )
- out << "\n\t";
- }
- }
- out << "\n";
- return out;
-}
-
-void Switch::taActions()
-{
- actions.start();
-
- /* Put "no-action" at the beginning. */
- actions.value( 0 );
-
- for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
- /* Write out the length, which will never be the last character. */
- actions.value( act->key.length() );
-
- for ( GenActionTable::Iter item = act->key; item.lte(); item++ )
- actions.value( item->value->actionId );
- }
-
- actions.finish();
-}
-
-
-
-
diff --git a/src/switch.h b/src/switch.h
deleted file mode 100644
index 7f23778b..00000000
--- a/src/switch.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _C_SWITCH_H
-#define _C_SWITCH_H
-
-#include <iostream>
-#include "codegen.h"
-#include "tables.h"
-
-/* Forwards. */
-struct CodeGenData;
-struct NameInst;
-struct RedTransAp;
-struct RedStateAp;
-
-class Switch
- : public virtual Tables
-{
-protected:
- enum Type {
- Loop = 1, Exp
- };
-
-public:
- Switch( const CodeGenArgs &args, Type type )
- :
- Tables( args ),
- type(type)
- {}
-
- std::ostream &TRANS_GOTO( int off, RedTransAp *trans );
- void RANGE_B_SEARCH( RedStateAp *state, Key lower, Key upper, int low, int high );
- void SINGLE_SWITCH( RedStateAp *st );
- void DEFAULT( RedStateAp *st );
- void NOT_SINGLE( RedStateAp *st );
- void LOCATE_TRANS();
-
-protected:
- Type type;
- int transBase;
-
- std::ostream &COND_KEYS_v1();
- std::ostream &COND_SPACES_v1();
- std::ostream &INDICES();
- std::ostream &INDEX_OFFSETS();
- std::ostream &SINGLE_LENS();
- std::ostream &RANGE_LENS();
- std::ostream &TRANS_TARGS_WI();
- std::ostream &ACTIONS_ARRAY();
-
- void taKeyOffsets();
- void taSingleLens();
- void taRangeLens();
- void taIndexOffsets();
- void taIndices();
- void taTransCondSpacesWi();
- void taTransOffsetsWi();
- void taTransLengthsWi();
- void taTransCondSpaces();
- void taTransOffsets();
- void taTransLengths();
- void taCondTargs();
- void taCondActions();
- void taToStateActions();
- void taFromStateActions();
- void taEofTrans();
- void taEofConds();
- void taEofActions();
- void taKeys();
- void taActions();
- void taCondKeys();
- void taNfaTargs();
- void taNfaOffsets();
- void taNfaPushActions();
- void taNfaPopTrans();
-
- void setKeyType();
-
- void setTableState( TableArray::State );
-
- virtual void writeData();
- virtual void tableDataPass();
- virtual void genAnalysis();
-};
-
-#endif
diff --git a/src/switchbreak.cc b/src/switchbreak.cc
deleted file mode 100644
index 567dfbc4..00000000
--- a/src/switchbreak.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "switchbreak.h"
-
-void SwitchBreak::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-
- out << EMIT_LABEL( _match_cond );
-}
-
diff --git a/src/switchbreak.h b/src/switchbreak.h
deleted file mode 100644
index fdbac68c..00000000
--- a/src/switchbreak.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_SWITCHBREAK_H
-#define RAGEL_SWITCHBREAK_H
-
-#include "switch.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct SwitchBreak
-:
- public Switch, public TabBreak
-{
- SwitchBreak( const CodeGenArgs &args, Switch::Type type )
- :
- Tables( args ),
- Switch( args, type ),
- TabBreak( args )
- {}
-
- void LOCATE_COND();
-};
-
-class SwitchBreakLoop
- : public SwitchBreak, public ActLoop
-{
-public:
- SwitchBreakLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchBreak( args, Loop ),
- ActLoop( args )
- {}
-};
-
-
-class SwitchBreakExp
- : public SwitchBreak, public ActExp
-{
-public:
- SwitchBreakExp( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchBreak( args, Exp ),
- ActExp( args )
- {}
-};
-
-
-#endif
diff --git a/src/switchgoto.cc b/src/switchgoto.cc
deleted file mode 100644
index 3b293c70..00000000
--- a/src/switchgoto.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2001-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "switchgoto.h"
-
-void SwitchGoto::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " while ( " << TRUE() << " ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " break;\n"
- " }\n"
- "\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " break;\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-}
-
diff --git a/src/switchgoto.h b/src/switchgoto.h
deleted file mode 100644
index d8207325..00000000
--- a/src/switchgoto.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_SWITCHGOTO_H
-#define RAGEL_SWITCHGOTO_H
-
-#include "switch.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct SwitchGoto
-:
- public Switch, public TabGoto
-{
- SwitchGoto( const CodeGenArgs &args, Switch::Type type )
- :
- Tables( args ),
- Switch( args, type ),
- TabGoto( args )
- {}
-
- void LOCATE_COND();
-};
-
-class SwitchGotoLoop
- : public SwitchGoto, public ActLoop
-{
-public:
- SwitchGotoLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchGoto( args, Loop ),
- ActLoop( args )
- {}
-};
-
-
-class SwitchGotoExp
- : public SwitchGoto, public ActExp
-{
-public:
- SwitchGotoExp( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchGoto( args, Exp ),
- ActExp( args )
- {}
-};
-
-
-#endif
diff --git a/src/switchvar.cc b/src/switchvar.cc
deleted file mode 100644
index b19f28db..00000000
--- a/src/switchvar.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 "switchvar.h"
-#include "parsedata.h"
-#include "inputdata.h"
-
-void SwitchVar::LOCATE_COND()
-{
- if ( red->condSpaceList.length() > 0 ) {
- std::stringstream success, error;
-
- out <<
- " " << ckeys << " = " << OFFSET( ARR_REF( condKeys ), ARR_REF( transOffsets ) + "[" + trans.ref() + "]" ) << ";\n"
- " " << klen << " = " << CAST( "int" ) << ARR_REF( transLengths ) << "[" << trans << "];\n"
- " " << cond << " = " << CAST( UINT() ) << ARR_REF( transOffsets ) << "[" << trans << "];\n"
- "\n";
-
- out <<
- " " << cpc << " = 0;\n";
-
- if ( red->condSpaceList.length() > 0 )
- COND_EXEC( ARR_REF( transCondSpaces ) + "[" + trans.ref() + "]" );
-
- success <<
- cond << " += " << CAST( UINT() ) << "(_mid - " << ckeys << ");\n";
-
- error <<
- cond << " = " << errCondOffset << ";\n";
-
- out <<
- " {\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_lower" ) << " = " << ckeys << ";\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_upper" ) << " = " << ckeys << " + " << klen << " - 1;\n"
- " " << INDEX( ARR_TYPE( condKeys ), "_mid" ) << ";\n"
- " _bsc = 1;\n"
- " while ( _bsc == 1 ) {\n"
- " if ( _upper < _lower ) {\n"
- " " << error.str() << "\n"
- " _bsc = 0;\n"
- " }\n"
- " else {\n"
- " _mid = _lower + ((_upper-_lower) >> 1);\n"
- " if ( " << cpc << " < " << CAST("int") << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _upper = _mid - 1;\n"
- " else if ( " << cpc << " > " << CAST( "int" ) << DEREF( ARR_REF( condKeys ), "_mid" ) << " )\n"
- " _lower = _mid + 1;\n"
- " else {\n"
- " " << success.str() << "\n"
- " _bsc = 0;\n"
- " }\n"
- " }\n"
- " }\n"
- " }\n"
- ;
- }
-}
-
diff --git a/src/switchvar.h b/src/switchvar.h
deleted file mode 100644
index 220963a4..00000000
--- a/src/switchvar.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2014-2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 RAGEL_SWITCHVAR_H
-#define RAGEL_SWITCHVAR_H
-
-#include "switch.h"
-#include "actloop.h"
-#include "actexp.h"
-
-struct SwitchVar
-:
- public Switch, public TabVar
-{
- SwitchVar( const CodeGenArgs &args, Switch::Type type )
- :
- Tables( args ),
- Switch( args, type ),
- TabVar( args )
- {}
-
- void VAR_COND_BIN_SEARCH( Variable &var, TableArray &keys, std::string ok, std::string error );
-
- //void LOCATE_TRANS();
- void LOCATE_COND();
-};
-
-class SwitchVarLoop
- : public SwitchVar, public ActLoop
-{
-public:
- SwitchVarLoop( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchVar( args, Loop ),
- ActLoop( args )
- {}
-};
-
-class SwitchVarExp
-:
- public SwitchVar, public ActExp
-{
-public:
- SwitchVarExp( const CodeGenArgs &args )
- :
- Tables( args ),
- SwitchVar( args, Exp ),
- ActExp( args )
- {}
-};
-
-#endif
diff --git a/src/tables.h b/src/tables.h
deleted file mode 100644
index 258f869e..00000000
--- a/src/tables.h
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright 2018 Adrian Thurston <thurston@colm.net>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * 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 _TABLES_H
-#define _TABLES_H
-
-#include <iostream>
-#include "codegen.h"
-
-struct Tables
-:
- public CodeGen
-{
- Tables( const CodeGenArgs &args )
- :
- CodeGen( args ),
-
- pa( "_pa" ),
- klen( "_klen" ),
- ckeys( "_ckeys" ),
- cekeys( "_cekeys" ),
- trans( "_trans" ),
- cond( "_cond" ),
- keys( "_keys" ),
- acts( "_acts" ),
- nacts( "_nacts" ),
- inds( "_inds" ),
-
- cont( "_cont" ),
- nfa_repeat( "_nfa_repeat" ),
- nfa_test( "_nfa_test" ),
- ps( "_ps" ),
- nbreak( "_nbreak" ),
- have( "__have" ),
- ic( "_ic" ),
-
- _out("_out"),
- _pop("_pop"),
- _test_eof( "_test_eof" ),
- _resume( "_resume" ),
- _match_cond( "_match_cond" ),
- _again( "_again" ),
- _match( "_match" ),
- _eof_goto( "_eof_goto" ),
-
- actions( "actions", *this ),
- transKeys( "trans_keys", *this ),
- charClass( "char_class", *this ),
- flatIndexOffset( "index_offsets", *this ),
- indices( "indices", *this ),
- indexDefaults( "index_defaults", *this ),
- transCondSpaces( "trans_cond_spaces", *this ),
- transOffsets( "trans_offsets", *this ),
- condTargs( "cond_targs", *this ),
- condActions( "cond_actions", *this ),
- toStateActions( "to_state_actions", *this ),
- fromStateActions( "from_state_actions", *this ),
- eofCondSpaces( "eof_cond_spaces", *this ),
- eofCondKeyOffs( "eof_cond_key_offs", *this ),
- eofCondKeyLens( "eof_cond_key_lens", *this ),
- eofCondKeys( "eof_cond_keys", *this ),
- eofActions( "eof_actions", *this ),
- eofTrans( "eof_trans", *this ),
-
- keyOffsets( "key_offsets", *this ),
- singleLens( "single_lengths", *this ),
- rangeLens( "range_lengths", *this ),
- indexOffsets( "index_offsets", *this ),
- transCondSpacesWi( "trans_cond_spaces_wi", *this ),
- transOffsetsWi( "trans_offsets_wi", *this ),
- transLengthsWi( "trans_lengths_wi", *this ),
- transLengths( "trans_lengths", *this ),
- condKeys( "cond_keys", *this )
- {}
-
- Variable pa;
- Variable klen;
- Variable ckeys;
- Variable cekeys;
- Variable trans;
- Variable cond;
- Variable keys;
- Variable acts;
- Variable nacts;
- Variable inds;
- Variable cont;
- Variable nfa_repeat;
- Variable nfa_test;
- Variable ps;
- Variable nbreak;
- Variable have;
- Variable ic;
-
- GotoLabel _out;
- GotoLabel _pop;
- GotoLabel _test_eof;
- GotoLabel _resume;
- GotoLabel _match_cond;
- GotoLabel _again;
- GotoLabel _match;
- GotoLabel _eof_goto;
-
- TableArray actions;
- TableArray transKeys;
- TableArray charClass;
- TableArray flatIndexOffset;
- TableArray indices;
- TableArray indexDefaults;
- TableArray transCondSpaces;
- TableArray transOffsets;
- TableArray condTargs;
- TableArray condActions;
- TableArray toStateActions;
- TableArray fromStateActions;
- TableArray eofCondSpaces;
- TableArray eofCondKeyOffs;
- TableArray eofCondKeyLens;
- TableArray eofCondKeys;
- TableArray eofActions;
- TableArray eofTrans;
-
- TableArray keyOffsets;
- TableArray singleLens;
- TableArray rangeLens;
- TableArray indexOffsets;
- TableArray transCondSpacesWi;
- TableArray transOffsetsWi;
- TableArray transLengthsWi;
- TableArray transLengths;
- TableArray condKeys;
-
- int errCondOffset;
-
- virtual void TO_STATE_ACTION( RedStateAp *state ) = 0;
- virtual void FROM_STATE_ACTION( RedStateAp *state ) = 0;
- virtual void EOF_ACTION( RedStateAp *state ) = 0;
- virtual void COND_ACTION( RedCondPair *cond ) = 0;
-
- virtual void NFA_PUSH_ACTION( RedNfaTarg *targ ) = 0;
- virtual void NFA_POP_TEST( RedNfaTarg *targ ) = 0;
- virtual void NFA_FROM_STATE_ACTION_EXEC() = 0;
-
- virtual void FROM_STATE_ACTIONS() = 0;
- virtual void REG_ACTIONS( std::string cond ) = 0;
- virtual void TO_STATE_ACTIONS() = 0;
- virtual void EOF_ACTIONS() = 0;
-
- void CURS( ostream &ret, bool inFinish );
- void TARGS( ostream &ret, bool inFinish, int targState );
- void NEXT( ostream &ret, int nextDest, bool inFinish );
- void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void EOF_TRANS();
- void COND_EXEC( std::string expr );
-};
-
-struct TabGoto
-:
- public virtual Tables
-{
- TabGoto( const CodeGenArgs &args )
- :
- Tables( args )
- {}
-
- void CONTROL_JUMP( ostream &ret, bool inFinish );
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void RET( ostream &ret, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
- void BREAK( ostream &ret, int targState, bool csForced );
- void NBREAK( ostream &ret, int targState, bool csForced );
-
- void NFA_POP() {}
-
- void writeExec();
-};
-
-struct TabBreak
-:
- public virtual Tables
-{
- TabBreak( const CodeGenArgs &args )
- :
- Tables( args ),
- loopLabels( args.loopLabels )
- {}
-
- void CONTROL_JUMP( ostream &ret, bool inFinish );
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void RET( ostream &ret, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
- void BREAK( ostream &ret, int targState, bool csForced );
- void NBREAK( ostream &ret, int targState, bool csForced );
-
- void NFA_POP() {}
-
- void writeExec();
-
- bool loopLabels;
- std::string BREAK( GotoLabel &label );
- std::string CONTINUE( GotoLabel &label );
- std::string BREAK_LABEL( GotoLabel &label );
-};
-
-struct TabVar
-:
- public virtual Tables
-{
- TabVar( const CodeGenArgs &args )
- :
- Tables( args )
- {}
-
- void GOTO( ostream &ret, int gotoDest, bool inFinish );
- void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
- void CALL( ostream &ret, int callDest, int targState, bool inFinish );
- void NCALL( ostream &ret, int callDest, int targState, bool inFinish );
- void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void NCALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
- void RET( ostream &ret, bool inFinish );
- void NRET( ostream &ret, bool inFinish );
- void BREAK( ostream &ret, int targState, bool csForced );
- void NBREAK( ostream &ret, int targState, bool csForced );
-
- void NFA_POP() {}
-
- std::string BREAK( GotoLabel &label );
- std::string CONTINUE( GotoLabel &label );
- std::string BREAK_LABEL( GotoLabel &label );
-
- void writeExec();
-};
-
-
-#endif