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
&TRANS_TARGS();
62 std::ostream
&TRANS_ACTIONS();
63 std::ostream
&TRANS_TARGS_WI();
64 std::ostream
&TRANS_ACTIONS_WI();
66 void BREAK( ostream
&ret
, int targState
);
67 void GOTO( ostream
&ret
, int gotoDest
, bool inFinish
);
68 void GOTO_EXPR( ostream
&ret
, InlineItem
*ilItem
, bool inFinish
);
69 void CALL( ostream
&ret
, int callDest
, int targState
, bool inFinish
);
70 void CALL_EXPR( ostream
&ret
, InlineItem
*ilItem
, int targState
, bool inFinish
);
71 void RET( ostream
&ret
, bool inFinish
);
73 void COND_TRANSLATE();
76 virtual void writeOutExec();
77 virtual void writeOutEOF();
78 virtual void writeOutData();
79 virtual void writeOutInit();
80 virtual void finishRagelDef();
82 void NEXT( ostream
&ret
, int nextDest
, bool inFinish
);
83 void NEXT_EXPR( ostream
&ret
, InlineItem
*ilItem
, bool inFinish
);
85 int TO_STATE_ACTION( RedStateAp
*state
);
86 int FROM_STATE_ACTION( RedStateAp
*state
);
87 int EOF_ACTION( RedStateAp
*state
);
88 int TRANS_ACTION( RedTransAp
*trans
);
90 /* Determine if we should use indicies. */
99 virtual string
NULL_ITEM();
100 virtual ostream
&OPEN_ARRAY( string type
, string name
);
101 virtual ostream
&START_ARRAY_LINE();
102 virtual ostream
&ARRAY_ITEM( int item
, int count
, bool last
);
103 virtual ostream
&END_ARRAY_LINE();
104 virtual ostream
&CLOSE_ARRAY();
105 virtual ostream
&STATIC_VAR( string type
, string name
);
106 virtual string
ARR_OFF( string ptr
, string offset
);
107 virtual string
CAST( string type
);
108 virtual string
GET_KEY();
109 virtual string
CTRL_FLOW();
112 string
START_STATE_ID();
113 ostream
&ACTIONS_ARRAY();
114 string
GET_WIDE_KEY();
115 string
GET_WIDE_KEY( RedStateAp
*state
);
116 string
TABS( int level
);
118 void ACTION( ostream
&ret
, Action
*action
, int targState
, bool inFinish
);
119 void CONDITION( ostream
&ret
, Action
*condition
);
121 string
WIDE_ALPH_TYPE();
122 string
ARRAY_TYPE( unsigned long maxVal
);
124 string
P() { return "p"; }
125 string
PE() { return "pe"; }
129 string
STACK() { return ACCESS() + "stack"; }
130 string
TOP() { return ACCESS() + "top"; }
131 string
TOKSTART() { return ACCESS() + "tokstart"; }
132 string
TOKEND() { return ACCESS() + "tokend"; }
133 string
ACT() { return ACCESS() + "act"; }
135 string
DATA_PREFIX();
136 string
PM() { return "_" + DATA_PREFIX() + "partition_map"; }
137 string
C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
138 string
CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
139 string
K() { return "_" + DATA_PREFIX() + "trans_keys"; }
140 string
I() { return "_" + DATA_PREFIX() + "indicies"; }
141 string
CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
142 string
KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
143 string
IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
144 string
CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
145 string
SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
146 string
RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
147 string
A() { return "_" + DATA_PREFIX() + "actions"; }
148 string
TA() { return "_" + DATA_PREFIX() + "trans_actions_wi"; }
149 string
TT() { return "_" + DATA_PREFIX() + "trans_targs_wi"; }
150 string
TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
151 string
FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
152 string
EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
153 string
SP() { return "_" + DATA_PREFIX() + "key_spans"; }
154 string
CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
155 string
START() { return DATA_PREFIX() + "start"; }
156 string
ERROR() { return DATA_PREFIX() + "error"; }
157 string
FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
158 string
CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
160 void INLINE_LIST( ostream
&ret
, InlineList
*inlineList
, int targState
, bool inFinish
);
161 void EXEC( ostream
&ret
, InlineItem
*item
, int targState
, int inFinish
);
162 void EXECTE( ostream
&ret
, InlineItem
*item
, int targState
, int inFinish
);
163 void LM_SWITCH( ostream
&ret
, InlineItem
*item
, int targState
, int inFinish
);
164 void SET_ACT( ostream
&ret
, InlineItem
*item
);
165 void INIT_TOKSTART( ostream
&ret
, InlineItem
*item
);
166 void INIT_ACT( ostream
&ret
, InlineItem
*item
);
167 void SET_TOKSTART( ostream
&ret
, InlineItem
*item
);
168 void SET_TOKEND( ostream
&ret
, InlineItem
*item
);
169 void GET_TOKEND( ostream
&ret
, InlineItem
*item
);
170 void SUB_ACTION( ostream
&ret
, InlineItem
*item
,
171 int targState
, bool inFinish
);
173 string
ERROR_STATE();
174 string
FIRST_FINAL_STATE();
176 ostream
&source_warning(const InputLoc
&loc
);
177 ostream
&source_error(const InputLoc
&loc
);
179 unsigned int arrayTypeSize( unsigned long maxVal
);