2 * Copyright 2006-2007 Adrian Thurston <thurston@complang.org>
3 * 2007 Colin Fleming <colin.fleming@caverock.com>
6 /* This file is part of Ragel.
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.
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.
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
23 #ifndef _JAVACODEGEN_H
24 #define _JAVACODEGEN_H
38 struct JavaTabCodeGen : public CodeGenData
40 JavaTabCodeGen( ostream &out ) :
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();
48 std::ostream &COND_KEYS();
49 std::ostream &COND_SPACES();
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();
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 );
74 void COND_TRANSLATE();
77 virtual void writeExec();
78 virtual void writeData();
79 virtual void writeInit();
80 virtual void writeExports();
81 virtual void writeStart();
82 virtual void writeFirstFinal();
83 virtual void writeError();
84 virtual void finishRagelDef();
86 void NEXT( ostream &ret, int nextDest, bool inFinish );
87 void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
89 int TO_STATE_ACTION( RedStateAp *state );
90 int FROM_STATE_ACTION( RedStateAp *state );
91 int EOF_ACTION( RedStateAp *state );
92 int TRANS_ACTION( RedTransAp *trans );
94 /* Determine if we should use indicies. */
105 virtual string NULL_ITEM();
106 virtual ostream &OPEN_ARRAY( string type, string name );
107 virtual ostream &ARRAY_ITEM( string item, bool last );
108 virtual ostream &CLOSE_ARRAY();
109 virtual ostream &STATIC_VAR( string type, string name );
110 virtual string ARR_OFF( string ptr, string offset );
111 virtual string CAST( string type );
112 virtual string GET_KEY();
113 virtual string CTRL_FLOW();
116 string START_STATE_ID();
117 ostream &ACTIONS_ARRAY();
118 string GET_WIDE_KEY();
119 string GET_WIDE_KEY( RedStateAp *state );
120 string TABS( int level );
121 string KEY( Key key );
123 void ACTION( ostream &ret, GenAction *action, int targState, bool inFinish );
124 void CONDITION( ostream &ret, GenAction *condition );
126 string WIDE_ALPH_TYPE();
127 string ARRAY_TYPE( unsigned long maxVal );
143 string DATA_PREFIX();
144 string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
145 string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
146 string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
147 string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
148 string I() { return "_" + DATA_PREFIX() + "indicies"; }
149 string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
150 string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
151 string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
152 string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
153 string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
154 string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
155 string A() { return "_" + DATA_PREFIX() + "actions"; }
156 string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
157 string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
158 string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
159 string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
160 string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
161 string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
162 string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
163 string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
164 string START() { return DATA_PREFIX() + "start"; }
165 string ERROR() { return DATA_PREFIX() + "error"; }
166 string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
167 string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
169 void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish );
170 void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
171 void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish );
172 void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish );
173 void SET_ACT( ostream &ret, GenInlineItem *item );
174 void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
175 void INIT_ACT( ostream &ret, GenInlineItem *item );
176 void SET_TOKSTART( ostream &ret, GenInlineItem *item );
177 void SET_TOKEND( ostream &ret, GenInlineItem *item );
178 void GET_TOKEND( ostream &ret, GenInlineItem *item );
179 void SUB_ACTION( ostream &ret, GenInlineItem *item,
180 int targState, bool inFinish );
182 string ERROR_STATE();
183 string FIRST_FINAL_STATE();
185 ostream &source_warning(const InputLoc &loc);
186 ostream &source_error(const InputLoc &loc);
188 unsigned int arrayTypeSize( unsigned long maxVal );
194 void genLineDirective( ostream &out );