2 * Copyright 2006-2007 Adrian Thurston <thurston@cs.queensu.ca>
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 finishRagelDef();
83 void NEXT( ostream
&ret
, int nextDest
, bool inFinish
);
84 void NEXT_EXPR( ostream
&ret
, GenInlineItem
*ilItem
, bool inFinish
);
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
);
91 /* Determine if we should use indicies. */
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();
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
);
120 void ACTION( ostream
&ret
, GenAction
*action
, int targState
, bool inFinish
);
121 void CONDITION( ostream
&ret
, GenAction
*condition
);
123 string
WIDE_ALPH_TYPE();
124 string
ARRAY_TYPE( unsigned long maxVal
);
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"; }
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
);
179 string
ERROR_STATE();
180 string
FIRST_FINAL_STATE();
182 ostream
&source_warning(const GenInputLoc
&loc
);
183 ostream
&source_error(const GenInputLoc
&loc
);
185 unsigned int arrayTypeSize( unsigned long maxVal
);
191 void genLineDirective( ostream
&out
);