2 * Copyright 2005-2007 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
33 typedef DList
<Action
> ActionList
;
35 typedef unsigned long ulong
;
37 extern int gblErrorCount
;
41 typedef AvlMap
<char *, CodeGenData
*, CmpStr
> CodeGenMap
;
42 typedef AvlMapEl
<char *, CodeGenData
*> CodeGenMapEl
;
45 * The interface to the parser
48 /* These functions must be implemented by the code generation executable.
49 * The openOutput function is invoked when the root element is opened. The
50 * makeCodeGen function is invoked when a ragel_def element is opened. */
51 std::ostream
*openOutput( char *inputFile
);
52 CodeGenData
*makeCodeGen( char *sourceFileName
,
53 char *fsmName
, ostream
&out
, bool wantComplete
);
55 void lineDirective( ostream
&out
, char *fileName
, int line
);
56 void genLineDirective( ostream
&out
);
58 /*********************************/
63 * The interface to the code generator.
65 virtual void finishRagelDef() {}
67 /* These are invoked by the corresponding write statements. */
68 virtual void writeData() {};
69 virtual void writeInit() {};
70 virtual void writeExec() {};
71 virtual void writeExports() {};
73 /* This can also be overwridden to modify the processing of write
75 virtual void writeStatement( InputLoc
&loc
, int nargs
, char **args
);
77 /********************/
79 CodeGenData( ostream
&out
);
80 virtual ~CodeGenData() {}
83 * Collecting the machine.
91 RedAction
*allActionTables
;
92 Condition
*allConditions
;
93 CondSpace
*allCondSpaces
;
94 RedStateAp
*allStates
;
98 ActionList actionList
;
99 ConditionList conditionList
;
100 CondSpaceList condSpaceList
;
101 InlineList
*getKeyExpr
;
102 InlineList
*accessExpr
;
103 InlineList
*prePushExpr
;
104 InlineList
*postPopExpr
;
106 /* Overriding variables. */
112 InlineList
*stackExpr
;
114 InlineList
*tokstartExpr
;
115 InlineList
*tokendExpr
;
116 InlineList
*dataExpr
;
120 EntryIdVect entryPointIds
;
121 EntryNameVect entryPointNames
;
122 bool hasLongestMatch
;
123 ExportList exportList
;
128 bool writeFirstFinal
;
132 void createMachine();
133 void initActionList( unsigned long length
);
134 void newAction( int anum
, char *name
, int line
, int col
, InlineList
*inlineList
);
135 void initActionTableList( unsigned long length
);
136 void initStateList( unsigned long length
);
137 void setStartState( unsigned long startState
);
138 void setErrorState( unsigned long errState
);
139 void addEntryPoint( char *name
, unsigned long entryState
);
140 void setId( int snum
, int id
);
141 void setFinal( int snum
);
142 void initTransList( int snum
, unsigned long length
);
143 void newTrans( int snum
, int tnum
, Key lowKey
, Key highKey
,
144 long targ
, long act
);
145 void finishTransList( int snum
);
146 void setStateActions( int snum
, long toStateAction
,
147 long fromStateAction
, long eofAction
);
148 void setEofTrans( int snum
, long targ
, long eofAction
);
149 void setForcedErrorState()
150 { redFsm
->forcedErrorState
= true; }
153 void initCondSpaceList( ulong length
);
154 void condSpaceItem( int cnum
, long condActionId
);
155 void newCondSpace( int cnum
, int condSpaceId
, Key baseKey
);
157 void initStateCondList( int snum
, ulong length
);
158 void addStateCond( int snum
, Key lowKey
, Key highKey
, long condNum
);
160 CondSpace
*findCondSpace( Key lowKey
, Key highKey
);
161 Condition
*findCondition( Key key
);
163 bool setAlphType( char *data
);
165 void resolveTargetStates( InlineList
*inlineList
);
168 /* Gather various info on the machine. */
169 void analyzeActionList( RedAction
*redAct
, InlineList
*inlineList
);
170 void analyzeAction( Action
*act
, InlineList
*inlineList
);
171 void findFinalActionRefs();
172 void analyzeMachine();
175 void setValueLimits();
176 void assignActionIds();
178 ostream
&source_warning( const InputLoc
&loc
);
179 ostream
&source_error( const InputLoc
&loc
);
183 #endif /* _GENDATA_H */