Get ragel working again while the direct-to-backend code is being written.
[external/ragel.git] / rlgen-java / javacodegen.h
1 /*
2  *  Copyright 2006-2007 Adrian Thurston <thurston@complang.org>
3  *            2007 Colin Fleming <colin.fleming@caverock.com>
4  */
5
6 /*  This file is part of Ragel.
7  *
8  *  Ragel is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  * 
13  *  Ragel is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  * 
18  *  You should have received a copy of the GNU General Public License
19  *  along with Ragel; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
21  */
22
23 #ifndef _JAVACODEGEN_H
24 #define _JAVACODEGEN_H
25
26 #include <iostream>
27 #include <string>
28 #include <stdio.h>
29 #include "common.h"
30 #include "gendata.h"
31
32 using std::string;
33 using std::ostream;
34
35 /*
36  * JavaTabCodeGen
37  */
38 struct JavaTabCodeGen : public CodeGenData
39 {
40         JavaTabCodeGen( ostream &out ) : 
41                 CodeGenData(out) {}
42
43         std::ostream &TO_STATE_ACTION_SWITCH();
44         std::ostream &FROM_STATE_ACTION_SWITCH();
45         std::ostream &EOF_ACTION_SWITCH();
46         std::ostream &ACTION_SWITCH();
47
48         std::ostream &COND_KEYS();
49         std::ostream &COND_SPACES();
50         std::ostream &KEYS();
51         std::ostream &INDICIES();
52         std::ostream &COND_OFFSETS();
53         std::ostream &KEY_OFFSETS();
54         std::ostream &INDEX_OFFSETS();
55         std::ostream &COND_LENS();
56         std::ostream &SINGLE_LENS();
57         std::ostream &RANGE_LENS();
58         std::ostream &TO_STATE_ACTIONS();
59         std::ostream &FROM_STATE_ACTIONS();
60         std::ostream &EOF_ACTIONS();
61         std::ostream &EOF_TRANS();
62         std::ostream &TRANS_TARGS();
63         std::ostream &TRANS_ACTIONS();
64         std::ostream &TRANS_TARGS_WI();
65         std::ostream &TRANS_ACTIONS_WI();
66
67         void BREAK( ostream &ret, int targState );
68         void GOTO( ostream &ret, int gotoDest, bool inFinish );
69         void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
70         void CALL( ostream &ret, int callDest, int targState, bool inFinish );
71         void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
72         void RET( ostream &ret, bool inFinish );
73
74         void COND_TRANSLATE();
75         void LOCATE_TRANS();
76
77         virtual void writeExec();
78         virtual void writeData();
79         virtual void writeInit();
80         virtual void writeExports();
81         virtual void finishRagelDef();
82
83         void NEXT( ostream &ret, int nextDest, bool inFinish );
84         void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
85
86         int TO_STATE_ACTION( RedStateAp *state );
87         int FROM_STATE_ACTION( RedStateAp *state );
88         int EOF_ACTION( RedStateAp *state );
89         int TRANS_ACTION( RedTransAp *trans );
90
91         /* Determine if we should use indicies. */
92         void calcIndexSize();
93
94 private:
95         string array_type;
96         string array_name;
97         int item_count;
98         int div_count;
99
100 public:
101
102         virtual string NULL_ITEM();
103         virtual ostream &OPEN_ARRAY( string type, string name );
104         virtual ostream &ARRAY_ITEM( string item, bool last );
105         virtual ostream &CLOSE_ARRAY();
106         virtual ostream &STATIC_VAR( string type, string name );
107         virtual string ARR_OFF( string ptr, string offset );
108         virtual string CAST( string type );
109         virtual string GET_KEY();
110         virtual string CTRL_FLOW();
111
112         string FSM_NAME();
113         string START_STATE_ID();
114         ostream &ACTIONS_ARRAY();
115         string GET_WIDE_KEY();
116         string GET_WIDE_KEY( RedStateAp *state );
117         string TABS( int level );
118         string KEY( Key key );
119         string INT( int i );
120         void ACTION( ostream &ret, GenAction *action, int targState, bool inFinish );
121         void CONDITION( ostream &ret, GenAction *condition );
122         string ALPH_TYPE();
123         string WIDE_ALPH_TYPE();
124         string ARRAY_TYPE( unsigned long maxVal );
125
126         string ACCESS();
127
128         string P();
129         string PE();
130         string EOFV();
131
132         string CS();
133         string STACK();
134         string TOP();
135         string TOKSTART();
136         string TOKEND();
137         string ACT();
138         string DATA();
139
140         string DATA_PREFIX();
141         string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
142         string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
143         string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
144         string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
145         string I() { return "_" + DATA_PREFIX() + "indicies"; }
146         string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
147         string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
148         string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
149         string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
150         string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
151         string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
152         string A() { return "_" + DATA_PREFIX() + "actions"; }
153         string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
154         string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
155         string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
156         string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
157         string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
158         string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
159         string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
160         string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
161         string START() { return DATA_PREFIX() + "start"; }
162         string ERROR() { return DATA_PREFIX() + "error"; }
163         string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
164         string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
165
166         void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish );
167         void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
168         void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish );
169         void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish );
170         void SET_ACT( ostream &ret, GenInlineItem *item );
171         void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
172         void INIT_ACT( ostream &ret, GenInlineItem *item );
173         void SET_TOKSTART( ostream &ret, GenInlineItem *item );
174         void SET_TOKEND( ostream &ret, GenInlineItem *item );
175         void GET_TOKEND( ostream &ret, GenInlineItem *item );
176         void SUB_ACTION( ostream &ret, GenInlineItem *item, 
177                         int targState, bool inFinish );
178
179         string ERROR_STATE();
180         string FIRST_FINAL_STATE();
181
182         ostream &source_warning(const GenInputLoc &loc);
183         ostream &source_error(const GenInputLoc &loc);
184
185         unsigned int arrayTypeSize( unsigned long maxVal );
186
187         bool outLabelUsed;
188         bool againLabelUsed;
189         bool useIndicies;
190
191         void genLineDirective( ostream &out );
192 };
193
194
195 #endif