2 * Copyright 2007 Victor Hugo Borja <vic@rubyforge.org>
3 * 2006-2007 Adrian Thurston <thurston@complang.org>
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 _RBX_GOTOCODEGEN_H
24 #define _RBX_GOTOCODEGEN_H
28 #include "rubycodegen.h"
32 class RbxGotoCodeGen : public RubyCodeGen
35 RbxGotoCodeGen( ostream &out ) : RubyCodeGen(out) {}
36 virtual ~RbxGotoCodeGen() {}
38 std::ostream &TO_STATE_ACTION_SWITCH();
39 std::ostream &FROM_STATE_ACTION_SWITCH();
40 std::ostream &EOF_ACTION_SWITCH();
41 std::ostream &ACTION_SWITCH();
42 std::ostream &STATE_GOTOS();
43 std::ostream &TRANSITIONS();
44 std::ostream &EXEC_FUNCS();
45 std::ostream &FINISH_CASES();
47 void GOTO( ostream &ret, int gotoDest, bool inFinish );
48 void CALL( ostream &ret, int callDest, int targState, bool inFinish );
49 void NEXT( ostream &ret, int nextDest, bool inFinish );
50 void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
51 void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
52 void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
53 void CURS( ostream &ret, bool inFinish );
54 void TARGS( ostream &ret, bool inFinish, int targState );
55 void RET( ostream &ret, bool inFinish );
56 void BREAK( ostream &ret, int targState );
58 int TO_STATE_ACTION( RedStateAp *state );
59 int FROM_STATE_ACTION( RedStateAp *state );
60 int EOF_ACTION( RedStateAp *state );
62 void COND_TRANSLATE( GenStateCond *stateCond, int level );
63 void emitCondBSearch( RedStateAp *state, int level, int low, int high );
64 void STATE_CONDS( RedStateAp *state, bool genDefault );
66 virtual std::ostream &TRANS_GOTO( RedTransAp *trans, int level );
68 void emitSingleSwitch( RedStateAp *state );
69 void emitRangeBSearch( RedStateAp *state, int level, int low, int high );
71 /* Called from STATE_GOTOS just before writing the gotos */
72 virtual void GOTO_HEADER( RedStateAp *state );
73 virtual void STATE_GOTO_ERROR();
75 virtual void writeData();
76 virtual void writeEOF();
77 virtual void writeExec();
80 std::ostream &TO_STATE_ACTIONS();
81 std::ostream &FROM_STATE_ACTIONS();
82 std::ostream &EOF_ACTIONS();
85 ostream &rbxGoto(ostream &out, string label);
86 ostream &rbxLabel(ostream &out, string label);