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, bool wantComplete )
61 wantComplete(wantComplete),
67 hasLongestMatch(false),
70 writeFirstFinal(true),
72 hasBeenPrepared(false)
76 * Collecting the machine.
83 RedAction *allActionTables;
84 Condition *allConditions;
85 CondSpace *allCondSpaces;
86 RedStateAp *allStates;
89 ActionList actionList;
90 ConditionList conditionList;
91 CondSpaceList condSpaceList;
92 InlineList *getKeyExpr;
93 InlineList *accessExpr;
94 InlineList *curStateExpr;
103 EntryIdVect entryPointIds;
104 EntryNameVect entryPointNames;
105 bool hasLongestMatch;
110 bool writeFirstFinal;
113 void createMachine();
114 void initActionList( unsigned long length );
115 void newAction( int anum, char *name, int line, int col, InlineList *inlineList );
116 void initActionTableList( unsigned long length );
117 void initStateList( unsigned long length );
118 void setStartState( unsigned long startState );
119 void addEntryPoint( char *name, unsigned long entryState );
120 void setFinal( int snum );
121 void initTransList( int snum, unsigned long length );
122 void newTrans( int snum, int tnum, Key lowKey, Key highKey,
123 long targ, long act );
124 void finishTransList( int snum );
125 void setStateActions( int snum, long toStateAction,
126 long fromStateAction, long eofAction );
127 void finishMachine();
128 void setForcedErrorState()
129 { redFsm->forcedErrorState = true; }
131 void initCondSpaceList( ulong length );
132 void condSpaceItem( int cnum, long condActionId );
133 void newCondSpace( int cnum, int condSpaceId, Key baseKey );
135 void initStateCondList( int snum, ulong length );
136 void addStateCond( int snum, Key lowKey, Key highKey, long condNum );
138 CondSpace *findCondSpace( Key lowKey, Key highKey );
139 Condition *findCondition( Key key );
141 bool setAlphType( char *data );
144 void generateGraphviz();
145 void resolveTargetStates( InlineList *inlineList );
150 void prepareMachine();
151 bool hasBeenPrepared;
154 extern CodeGenData *cgd;
156 void lineDirective( ostream &out, char *fileName, int line );
157 void genLineDirective( ostream &out );
159 #endif /* _GENDATA_H */