email address update: thurston@cs.queensu.ca -> thurston@complang.org
[external/ragel.git] / ragel / xmlcodegen.h
1 /*
2  *  Copyright 2005-2007 Adrian Thurston <thurston@complang.org>
3  */
4
5 /*  This file is part of Ragel.
6  *
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.
11  * 
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.
16  * 
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 
20  */
21
22 #ifndef _XMLDOTGEN_H
23 #define _XMLDOTGEN_H
24
25 #include <iostream>
26 #include "avltree.h"
27 #include "fsmgraph.h"
28 #include "parsedata.h"
29
30 /* Forwards. */
31 struct TransAp;
32 struct FsmAp;
33 struct ParseData;
34
35 struct RedActionTable
36 :
37         public AvlTreeEl<RedActionTable>
38 {
39         RedActionTable( const ActionTable &key )
40         :       
41                 key(key), 
42                 id(0)
43         { }
44
45         const ActionTable &getKey() 
46                 { return key; }
47
48         ActionTable key;
49         int id;
50 };
51
52 typedef AvlTree<RedActionTable, ActionTable, CmpActionTable> ActionTableMap;
53
54 struct NextRedTrans
55 {
56         Key lowKey, highKey;
57         TransAp *trans;
58         TransAp *next;
59
60         void load() {
61                 if ( trans != 0 ) {
62                         next = trans->next;
63                         lowKey = trans->lowKey;
64                         highKey = trans->highKey;
65                 }
66         }
67
68         NextRedTrans( TransAp *t ) {
69                 trans = t;
70                 load();
71         }
72
73         void increment() {
74                 trans = next;
75                 load();
76         }
77 };
78
79 class XMLCodeGen
80 {
81 public:
82         XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, std::ostream &out );
83         void writeXML( );
84
85 private:
86         void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans );
87         void writeStateActions( StateAp *state );
88         void writeStateList();
89         void writeStateConditions( StateAp *state );
90
91         void writeKey( Key key );
92         void writeText( InlineItem *item );
93         void writeGoto( InlineItem *item );
94         void writeGotoExpr( InlineItem *item );
95         void writeCall( InlineItem *item );
96         void writeCallExpr( InlineItem *item );
97         void writeNext( InlineItem *item );
98         void writeNextExpr( InlineItem *item );
99         void writeEntry( InlineItem *item );
100         void writeLmSetActId( InlineItem *item );
101         void writeLmOnLast( InlineItem *item );
102         void writeLmOnNext( InlineItem *item );
103         void writeLmOnLagBehind( InlineItem *item );
104
105         void writeExports();
106         bool writeNameInst( NameInst *nameInst );
107         void writeEntryPoints();
108         void writeConditions();
109         void writeInlineList( InlineList *inlineList );
110         void writeActionList();
111         void writeActionTableList();
112         void reduceTrans( TransAp *trans );
113         void reduceActionTables();
114         void writeTransList( StateAp *state );
115         void writeEofTrans( StateAp *state );
116         void writeTrans( Key lowKey, Key highKey, TransAp *defTrans );
117         void writeAction( Action *action );
118         void writeLmSwitch( InlineItem *item );
119         void writeMachine();
120         void writeActionExec( InlineItem *item );
121
122         char *fsmName;
123         ParseData *pd;
124         FsmAp *fsm;
125         std::ostream &out;
126         ActionTableMap actionTableMap;
127         int nextActionTableId;
128 };
129
130
131 #endif /* _XMLDOTGEN_H */