Import from my private repository. Snapshot after version 5.16, immediately
[external/ragel.git] / ragel / xmlcodegen.h
1 /*
2  *  Copyright 2005, 2006 Adrian Thurston <thurston@cs.queensu.ca>
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 writeCtrlFlow( InlineItem *item, InlineItem *context );
94         void writePtrMod( InlineItem *item, InlineItem *context );
95         void writeGoto( InlineItem *item, InlineItem *context );
96         void writeGotoExpr( InlineItem *item, InlineItem *context );
97         void writeCall( InlineItem *item, InlineItem *context );
98         void writeCallExpr( InlineItem *item, InlineItem *context );
99         void writeNext( InlineItem *item, InlineItem *context );
100         void writeNextExpr( InlineItem *item, InlineItem *context );
101         void writeEntry( InlineItem *item );
102         void writeLmSetActId( InlineItem *item );
103         void writeLmOnLast( InlineItem *item );
104         void writeLmOnNext( InlineItem *item );
105         void writeLmOnLagBehind( InlineItem *item );
106
107         void writeEntryPoints();
108         void writeGetKeyExpr();
109         void writeAccessExpr();
110         void writeCurStateExpr();
111         void writeConditions();
112         void writeInlineList( InlineList *inlineList, InlineItem *context );
113         void writeAlphType();
114         void writeActionList();
115         void writeActionTableList();
116         void reduceTrans( TransAp *trans );
117         void reduceActionTables();
118         void writeTransList( StateAp *state );
119         void writeTrans( Key lowKey, Key highKey, TransAp *defTrans );
120         void writeAction( Action *action );
121         void writeLmSwitch( InlineItem *item );
122         void writeMachine();
123         void writeActionExec( InlineItem *item );
124         void writeActionExecTE( InlineItem *item );
125
126         char *fsmName;
127         ParseData *pd;
128         FsmAp *fsm;
129         std::ostream &out;
130         ActionTableMap actionTableMap;
131         int nextActionTableId;
132 };
133
134
135 #endif /* _XMLDOTGEN_H */