2 * Copyright 2005-2006 Adrian Thurston <thurston@cs.queensu.ca>
5 /* This file is part of Ragel.
7 * Ragel is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Ragel is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Ragel; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "fsmcodegen.h"
31 typedef DList<Action> ActionList;
33 typedef unsigned long ulong;
35 typedef AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
36 typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;
39 #define WO_NOERROR 0x02
40 #define WO_NOPREFIX 0x04
45 CodeGenData( char *fileName, char *fsmName, ostream &out, bool wantComplete )
62 wantComplete(wantComplete),
68 hasLongestMatch(false),
71 writeFirstFinal(true),
73 hasBeenPrepared(false)
77 * Collecting the machine.
85 RedAction *allActionTables;
86 Condition *allConditions;
87 CondSpace *allCondSpaces;
88 RedStateAp *allStates;
91 ActionList actionList;
92 ConditionList conditionList;
93 CondSpaceList condSpaceList;
94 InlineList *getKeyExpr;
95 InlineList *accessExpr;
96 InlineList *curStateExpr;
105 EntryIdVect entryPointIds;
106 EntryNameVect entryPointNames;
107 bool hasLongestMatch;
112 bool writeFirstFinal;
115 void createMachine();
116 void initActionList( unsigned long length );
117 void newAction( int anum, char *name, int line, int col, InlineList *inlineList );
118 void initActionTableList( unsigned long length );
119 void initStateList( unsigned long length );
120 void setStartState( unsigned long startState );
121 void addEntryPoint( char *name, unsigned long entryState );
122 void setFinal( int snum );
123 void initTransList( int snum, unsigned long length );
124 void newTrans( int snum, int tnum, Key lowKey, Key highKey,
125 long targ, long act );
126 void finishTransList( int snum );
127 void setStateActions( int snum, long toStateAction,
128 long fromStateAction, long eofAction );
129 void finishMachine();
130 void setForcedErrorState()
131 { redFsm->forcedErrorState = true; }
133 void initCondSpaceList( ulong length );
134 void condSpaceItem( int cnum, long condActionId );
135 void newCondSpace( int cnum, int condSpaceId, Key baseKey );
137 void initStateCondList( int snum, ulong length );
138 void addStateCond( int snum, Key lowKey, Key highKey, long condNum );
140 CondSpace *findCondSpace( Key lowKey, Key highKey );
141 Condition *findCondition( Key key );
143 bool setAlphType( char *data );
146 void generateGraphviz();
147 void resolveTargetStates( InlineList *inlineList );
153 /* Gather various info on the machine. */
154 void analyzeActionList( RedAction *redAct, InlineList *inlineList );
155 void analyzeAction( Action *act, InlineList *inlineList );
156 void findFinalActionRefs();
157 void analyzeMachine();
158 void prepareMachine();
159 bool hasBeenPrepared;
162 extern CodeGenData *cgd;
164 void lineDirective( ostream &out, char *fileName, int line );
165 void genLineDirective( ostream &out );
167 #endif /* _GENDATA_H */