A fix to the documentation makefile from John D. Mitchell.
[ragel.git] / redfsm / gendata.h
blobf8c6d2fcb36cb7bcf9ef79cc42d49bc90e672841
1 /*
2 * Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
3 */
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
22 #ifndef _GENDATA_H
23 #define _GENDATA_H
25 #include <iostream>
26 #include "config.h"
27 #include "redfsm.h"
28 #include "common.h"
30 using std::ostream;
32 extern bool generateDot;
34 struct NameInst;
35 typedef DList<GenAction> GenActionList;
37 typedef unsigned long ulong;
39 extern int gblErrorCount;
41 struct CodeGenData;
43 typedef AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
44 typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;
47 * The interface to the parser
50 /* These functions must be implemented by the code generation executable.
51 * The openOutput function is invoked when the root element is opened. The
52 * makeCodeGen function is invoked when a ragel_def element is opened. */
53 std::ostream *cdOpenOutput( char *inputFile );
54 std::ostream *javaOpenOutput( char *inputFile );
55 std::ostream *rubyOpenOutput( char *inputFile );
56 std::ostream *csharpOpenOutput( char *inputFile );
57 std::ostream *dotOpenOutput( char *inputFile );
59 CodeGenData *cdMakeCodeGen( char *sourceFileName,
60 char *fsmName, ostream &out, bool wantComplete );
61 CodeGenData *javaMakeCodeGen( char *sourceFileName,
62 char *fsmName, ostream &out, bool wantComplete );
63 CodeGenData *rubyMakeCodeGen( char *sourceFileName,
64 char *fsmName, ostream &out, bool wantComplete );
65 CodeGenData *csharpMakeCodeGen( char *sourceFileName,
66 char *fsmName, ostream &out, bool wantComplete );
67 CodeGenData *dotMakeCodeGen( char *sourceFileName,
68 char *fsmName, ostream &out, bool wantComplete );
70 void cdLineDirective( ostream &out, const char *fileName, int line );
71 void javaLineDirective( ostream &out, const char *fileName, int line );
72 void rubyLineDirective( ostream &out, const char *fileName, int line );
73 void csharpLineDirective( ostream &out, const char *fileName, int line );
74 void genLineDirective( ostream &out );
76 /*********************************/
78 struct CodeGenData
81 * The interface to the code generator.
83 virtual void finishRagelDef() {}
85 /* These are invoked by the corresponding write statements. */
86 virtual void writeData() {};
87 virtual void writeInit() {};
88 virtual void writeExec() {};
89 virtual void writeExports() {};
91 /* This can also be overwridden to modify the processing of write
92 * statements. */
93 virtual void writeStatement( GenInputLoc &loc, int nargs, char **args );
95 /********************/
97 CodeGenData( ostream &out );
98 virtual ~CodeGenData() {}
101 * Collecting the machine.
104 char *sourceFileName;
105 char *fsmName;
106 ostream &out;
107 RedFsmAp *redFsm;
108 GenAction *allActions;
109 RedAction *allActionTables;
110 Condition *allConditions;
111 GenCondSpace *allCondSpaces;
112 RedStateAp *allStates;
113 NameInst **nameIndex;
114 int startState;
115 int errState;
116 GenActionList actionList;
117 ConditionList conditionList;
118 CondSpaceList condSpaceList;
119 GenInlineList *getKeyExpr;
120 GenInlineList *accessExpr;
121 GenInlineList *prePushExpr;
122 GenInlineList *postPopExpr;
124 /* Overriding variables. */
125 GenInlineList *pExpr;
126 GenInlineList *peExpr;
127 GenInlineList *eofExpr;
128 GenInlineList *csExpr;
129 GenInlineList *topExpr;
130 GenInlineList *stackExpr;
131 GenInlineList *actExpr;
132 GenInlineList *tokstartExpr;
133 GenInlineList *tokendExpr;
134 GenInlineList *dataExpr;
136 KeyOps thisKeyOps;
137 bool wantComplete;
138 EntryIdVect entryPointIds;
139 EntryNameVect entryPointNames;
140 bool hasLongestMatch;
141 ExportList exportList;
143 /* Write options. */
144 bool hasEnd;
145 bool dataPrefix;
146 bool writeFirstFinal;
147 bool writeErr;
148 bool writeCS;
150 void createMachine();
151 void initActionList( unsigned long length );
152 void newAction( int anum, char *name, int line, int col, GenInlineList *inlineList );
153 void initActionTableList( unsigned long length );
154 void initStateList( unsigned long length );
155 void setStartState( unsigned long startState );
156 void setErrorState( unsigned long errState );
157 void addEntryPoint( char *name, unsigned long entryState );
158 void setId( int snum, int id );
159 void setFinal( int snum );
160 void initTransList( int snum, unsigned long length );
161 void newTrans( int snum, int tnum, Key lowKey, Key highKey,
162 long targ, long act );
163 void finishTransList( int snum );
164 void setStateActions( int snum, long toStateAction,
165 long fromStateAction, long eofAction );
166 void setEofTrans( int snum, long targ, long eofAction );
167 void setForcedErrorState()
168 { redFsm->forcedErrorState = true; }
171 void initCondSpaceList( ulong length );
172 void condSpaceItem( int cnum, long condActionId );
173 void newCondSpace( int cnum, int condSpaceId, Key baseKey );
175 void initStateCondList( int snum, ulong length );
176 void addStateCond( int snum, Key lowKey, Key highKey, long condNum );
178 GenCondSpace *findCondSpace( Key lowKey, Key highKey );
179 Condition *findCondition( Key key );
181 bool setAlphType( char *data );
183 void resolveTargetStates( GenInlineList *inlineList );
184 Key findMaxKey();
186 /* Gather various info on the machine. */
187 void analyzeActionList( RedAction *redAct, GenInlineList *inlineList );
188 void analyzeAction( GenAction *act, GenInlineList *inlineList );
189 void findFinalActionRefs();
190 void analyzeMachine();
192 void closeMachine();
193 void setValueLimits();
194 void assignActionIds();
196 ostream &source_warning( const GenInputLoc &loc );
197 ostream &source_error( const GenInputLoc &loc );
201 #endif /* _GENDATA_H */