2 * 2007 Victor Hugo Borja <vic@rubyforge.org>
3 * Copyright 2001-2007 Adrian Thurston <thurston@cs.queensu.ca>
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 _RUBY_CODEGEN_H
24 #define _RUBY_CODEGEN_H
29 /* Integer array line length. */
32 inline string
itoa( int i
)
35 sprintf( buf
, "%i", i
);
40 class RubyCodeGen
: public CodeGenData
43 RubyCodeGen( ostream
&out
) : CodeGenData(out
) { }
44 virtual ~RubyCodeGen() {}
46 ostream
&START_ARRAY_LINE();
47 ostream
&ARRAY_ITEM( string item
, int count
, bool last
);
48 ostream
&END_ARRAY_LINE();
53 string
START_STATE_ID();
55 string
FIRST_FINAL_STATE();
56 void INLINE_LIST(ostream
&ret
, InlineList
*inlineList
, int targState
, bool inFinish
);
59 void ACTION( ostream
&ret
, Action
*action
, int targState
, bool inFinish
);
61 string
GET_WIDE_KEY();
62 string
GET_WIDE_KEY( RedStateAp
*state
);
63 string
KEY( Key key
);
64 string
TABS( int level
);
66 void CONDITION( ostream
&ret
, Action
*condition
);
68 string
WIDE_ALPH_TYPE();
69 string
ARRAY_TYPE( unsigned long maxVal
);
70 ostream
&ACTIONS_ARRAY();
75 string
PM() { return "_" + DATA_PREFIX() + "partition_map"; }
76 string
C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
77 string
CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
78 string
K() { return "_" + DATA_PREFIX() + "trans_keys"; }
79 string
I() { return "_" + DATA_PREFIX() + "indicies"; }
80 string
CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
81 string
KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
82 string
IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
83 string
CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
84 string
SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
85 string
RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
86 string
A() { return "_" + DATA_PREFIX() + "actions"; }
87 string
TA() { return "_" + DATA_PREFIX() + "trans_actions_wi"; }
88 string
TT() { return "_" + DATA_PREFIX() + "trans_targs_wi"; }
89 string
TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
90 string
FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
91 string
EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
92 string
ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
93 string
SP() { return "_" + DATA_PREFIX() + "key_spans"; }
94 string
CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
95 string
START() { return DATA_PREFIX() + "start"; }
96 string
ERROR() { return DATA_PREFIX() + "error"; }
97 string
FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
98 string
CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
102 ostream
&OPEN_ARRAY( string type
, string name
);
103 ostream
&CLOSE_ARRAY();
104 ostream
&STATIC_VAR( string type
, string name
);
105 string
ARR_OFF( string ptr
, string offset
);
120 void finishRagelDef();
121 unsigned int arrayTypeSize( unsigned long maxVal
);
124 virtual void writeExports();
125 virtual void writeInit();
127 /* Determine if we should use indicies. */
128 virtual void calcIndexSize();
130 virtual void BREAK( ostream
&ret
, int targState
) = 0;
131 virtual void GOTO( ostream
&ret
, int gotoDest
, bool inFinish
) = 0;
132 virtual void GOTO_EXPR( ostream
&ret
, InlineItem
*ilItem
, bool inFinish
) = 0;
133 virtual void CALL( ostream
&ret
, int callDest
, int targState
, bool inFinish
) = 0;
134 virtual void CALL_EXPR( ostream
&ret
, InlineItem
*ilItem
, int targState
, bool inFinish
) = 0;
135 virtual void RET( ostream
&ret
, bool inFinish
) = 0;
138 virtual void NEXT( ostream
&ret
, int nextDest
, bool inFinish
) = 0;
139 virtual void NEXT_EXPR( ostream
&ret
, InlineItem
*ilItem
, bool inFinish
) = 0;
141 virtual int TO_STATE_ACTION( RedStateAp
*state
) = 0;
142 virtual int FROM_STATE_ACTION( RedStateAp
*state
) = 0;
143 virtual int EOF_ACTION( RedStateAp
*state
) = 0;
145 virtual int TRANS_ACTION( RedTransAp
*trans
);
147 void EXEC( ostream
&ret
, InlineItem
*item
, int targState
, int inFinish
);
148 void LM_SWITCH( ostream
&ret
, InlineItem
*item
, int targState
, int inFinish
);
149 void SET_ACT( ostream
&ret
, InlineItem
*item
);
150 void INIT_TOKSTART( ostream
&ret
, InlineItem
*item
);
151 void INIT_ACT( ostream
&ret
, InlineItem
*item
);
152 void SET_TOKSTART( ostream
&ret
, InlineItem
*item
);
153 void SET_TOKEND( ostream
&ret
, InlineItem
*item
);
154 void GET_TOKEND( ostream
&ret
, InlineItem
*item
);
155 void SUB_ACTION( ostream
&ret
, InlineItem
*item
, int targState
, bool inFinish
);
158 ostream
&source_warning(const InputLoc
&loc
);
159 ostream
&source_error(const InputLoc
&loc
);
172 * indent-tabs-mode: 1
173 * c-file-style: "bsd"