2 * Copyright 2001-2006 Adrian Thurston <thurston@cs.queensu.ca>
3 * 2004 Erich Ocean <eric.ocean@ampede.com>
4 * 2005 Alan West <alan@alanz.com>
7 /* This file is part of Ragel.
9 * Ragel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Ragel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Ragel; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 /* Integer array line length. */
49 struct LongestMatchPart
;
51 inline string
itoa( int i
)
54 sprintf( buf
, "%i", i
);
61 class FsmCodeGen
: public CodeGenData
64 FsmCodeGen( ostream
&out
);
65 virtual ~FsmCodeGen() {}
67 virtual void finishRagelDef();
68 virtual void writeInit();
72 string
START_STATE_ID();
73 ostream
&ACTIONS_ARRAY();
74 string
GET_WIDE_KEY();
75 string
GET_WIDE_KEY( RedStateAp
*state
);
76 string
TABS( int level
);
77 string
KEY( Key key
);
78 string
LDIR_PATH( char *path
);
79 void ACTION( ostream
&ret
, GenAction
*action
, int targState
,
80 bool inFinish
, bool csForced
);
81 void CONDITION( ostream
&ret
, GenAction
*condition
);
83 string
WIDE_ALPH_TYPE();
84 string
ARRAY_TYPE( unsigned long maxVal
);
86 virtual string
ARR_OFF( string ptr
, string offset
) = 0;
87 virtual string
CAST( string type
) = 0;
88 virtual string
UINT() = 0;
89 virtual string
NULL_ITEM() = 0;
90 virtual string
POINTER() = 0;
91 virtual string
GET_KEY();
92 virtual ostream
&SWITCH_DEFAULT() = 0;
106 string
DATA_PREFIX();
107 string
PM() { return "_" + DATA_PREFIX() + "partition_map"; }
108 string
C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
109 string
CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
110 string
K() { return "_" + DATA_PREFIX() + "trans_keys"; }
111 string
I() { return "_" + DATA_PREFIX() + "indicies"; }
112 string
CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
113 string
KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
114 string
IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
115 string
CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
116 string
SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
117 string
RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
118 string
A() { return "_" + DATA_PREFIX() + "actions"; }
119 string
TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
120 string
TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
121 string
TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
122 string
FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
123 string
EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
124 string
ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
125 string
SP() { return "_" + DATA_PREFIX() + "key_spans"; }
126 string
CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
127 string
START() { return DATA_PREFIX() + "start"; }
128 string
ERROR() { return DATA_PREFIX() + "error"; }
129 string
FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
130 string
CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
132 void INLINE_LIST( ostream
&ret
, GenInlineList
*inlineList
,
133 int targState
, bool inFinish
, bool csForced
);
134 virtual void GOTO( ostream
&ret
, int gotoDest
, bool inFinish
) = 0;
135 virtual void CALL( ostream
&ret
, int callDest
, int targState
, bool inFinish
) = 0;
136 virtual void NEXT( ostream
&ret
, int nextDest
, bool inFinish
) = 0;
137 virtual void GOTO_EXPR( ostream
&ret
, GenInlineItem
*ilItem
, bool inFinish
) = 0;
138 virtual void NEXT_EXPR( ostream
&ret
, GenInlineItem
*ilItem
, bool inFinish
) = 0;
139 virtual void CALL_EXPR( ostream
&ret
, GenInlineItem
*ilItem
,
140 int targState
, bool inFinish
) = 0;
141 virtual void RET( ostream
&ret
, bool inFinish
) = 0;
142 virtual void BREAK( ostream
&ret
, int targState
, bool csForced
) = 0;
143 virtual void CURS( ostream
&ret
, bool inFinish
) = 0;
144 virtual void TARGS( ostream
&ret
, bool inFinish
, int targState
) = 0;
145 void EXEC( ostream
&ret
, GenInlineItem
*item
, int targState
, int inFinish
);
146 void LM_SWITCH( ostream
&ret
, GenInlineItem
*item
, int targState
,
147 int inFinish
, bool csForced
);
148 void SET_ACT( ostream
&ret
, GenInlineItem
*item
);
149 void INIT_TOKSTART( ostream
&ret
, GenInlineItem
*item
);
150 void INIT_ACT( ostream
&ret
, GenInlineItem
*item
);
151 void SET_TOKSTART( ostream
&ret
, GenInlineItem
*item
);
152 void SET_TOKEND( ostream
&ret
, GenInlineItem
*item
);
153 void GET_TOKEND( ostream
&ret
, GenInlineItem
*item
);
154 void SUB_ACTION( ostream
&ret
, GenInlineItem
*item
,
155 int targState
, bool inFinish
, bool csForced
);
158 string
ERROR_STATE();
159 string
FIRST_FINAL_STATE();
161 virtual string
PTR_CONST() = 0;
162 virtual ostream
&OPEN_ARRAY( string type
, string name
) = 0;
163 virtual ostream
&CLOSE_ARRAY() = 0;
164 virtual ostream
&STATIC_VAR( string type
, string name
) = 0;
166 virtual string
CTRL_FLOW() = 0;
168 ostream
&source_warning(const GenInputLoc
&loc
);
169 ostream
&source_error(const GenInputLoc
&loc
);
171 unsigned int arrayTypeSize( unsigned long maxVal
);
178 void genLineDirective( ostream
&out
);
181 /* Determine if we should use indicies. */
182 virtual void calcIndexSize() {}
185 class CCodeGen
: virtual public FsmCodeGen
188 CCodeGen( ostream
&out
) : FsmCodeGen(out
) {}
190 virtual string
NULL_ITEM();
191 virtual string
POINTER();
192 virtual ostream
&SWITCH_DEFAULT();
193 virtual ostream
&OPEN_ARRAY( string type
, string name
);
194 virtual ostream
&CLOSE_ARRAY();
195 virtual ostream
&STATIC_VAR( string type
, string name
);
196 virtual string
ARR_OFF( string ptr
, string offset
);
197 virtual string
CAST( string type
);
198 virtual string
UINT();
199 virtual string
PTR_CONST();
200 virtual string
CTRL_FLOW();
202 virtual void writeExports();
205 class DCodeGen
: virtual public FsmCodeGen
208 DCodeGen( ostream
&out
) : FsmCodeGen(out
) {}
210 virtual string
NULL_ITEM();
211 virtual string
POINTER();
212 virtual ostream
&SWITCH_DEFAULT();
213 virtual ostream
&OPEN_ARRAY( string type
, string name
);
214 virtual ostream
&CLOSE_ARRAY();
215 virtual ostream
&STATIC_VAR( string type
, string name
);
216 virtual string
ARR_OFF( string ptr
, string offset
);
217 virtual string
CAST( string type
);
218 virtual string
UINT();
219 virtual string
PTR_CONST();
220 virtual string
CTRL_FLOW();
222 virtual void writeExports();
225 #endif /* _FSMCODEGEN_H */