1 /*
2  *  Copyright 2007 Victor Hugo Borja <vic@rubyforge.org>
3  *            2006-2007 Adrian Thurston <thurston@complang.org>
4  */
5 
6 /*  This file is part of Ragel.
7  *
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.
12  *
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.
17  *
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
21  */
22 
23 #ifndef _RUBY_TABCODEGEN_H
24 #define _RUBY_TABCODEGEN_H
25 
26 #include <iostream>
27 #include <string>
28 #include <stdio.h>
29 #include "common.h"
30 #include "gendata.h"
31 #include "rubycodegen.h"
32 
33 
34 using std::string;
35 using std::ostream;
36 
37 /*
38  * RubyCodeGen
39  */
40 class RubyTabCodeGen : public RubyCodeGen
41 {
42 public:
RubyTabCodeGen(ostream & out)43 	RubyTabCodeGen( ostream &out ) :
44           RubyCodeGen(out) {}
~RubyTabCodeGen()45         virtual ~RubyTabCodeGen() {}
46 
47 public:
48 	void BREAK( ostream &ret, int targState );
49 	void GOTO( ostream &ret, int gotoDest, bool inFinish );
50 	void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
51 	void CALL( ostream &ret, int callDest, int targState, bool inFinish );
52 	void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
53 	void RET( ostream &ret, bool inFinish );
54 
55 	void COND_TRANSLATE();
56 	void LOCATE_TRANS();
57 
58 	virtual void writeExec();
59 	virtual void writeData();
60 
61  protected:
62 	virtual std::ostream &TO_STATE_ACTION_SWITCH();
63 	virtual std::ostream &FROM_STATE_ACTION_SWITCH();
64 	virtual std::ostream &EOF_ACTION_SWITCH();
65 	virtual std::ostream &ACTION_SWITCH();
66 
67 	std::ostream &COND_KEYS();
68 	std::ostream &COND_SPACES();
69 	std::ostream &KEYS();
70 	std::ostream &INDICIES();
71 	std::ostream &COND_OFFSETS();
72 	std::ostream &KEY_OFFSETS();
73 	std::ostream &INDEX_OFFSETS();
74 	std::ostream &COND_LENS();
75 	std::ostream &SINGLE_LENS();
76 	std::ostream &RANGE_LENS();
77 	std::ostream &TO_STATE_ACTIONS();
78 	std::ostream &FROM_STATE_ACTIONS();
79 	std::ostream &EOF_ACTIONS();
80 	std::ostream &EOF_TRANS();
81 	std::ostream &TRANS_TARGS();
82 	std::ostream &TRANS_ACTIONS();
83 	std::ostream &TRANS_TARGS_WI();
84 	std::ostream &TRANS_ACTIONS_WI();
85 
86 
87 	void NEXT( ostream &ret, int nextDest, bool inFinish );
88 	void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
89 
90 	virtual int TO_STATE_ACTION( RedStateAp *state );
91 	virtual int FROM_STATE_ACTION( RedStateAp *state );
92 	virtual int EOF_ACTION( RedStateAp *state );
93 
94 private:
95 	string array_type;
96 	string array_name;
97 
98 public:
99 
100 	void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
101 	void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish );
102 	void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish );
103 	void SET_ACT( ostream &ret, GenInlineItem *item );
104 	void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
105 	void INIT_ACT( ostream &ret, GenInlineItem *item );
106 	void SET_TOKSTART( ostream &ret, GenInlineItem *item );
107 	void SET_TOKEND( ostream &ret, GenInlineItem *item );
108 	void GET_TOKEND( ostream &ret, GenInlineItem *item );
109 	void SUB_ACTION( ostream &ret, GenInlineItem *item,
110 			int targState, bool inFinish );
111 
112 
113 };
114 
115 
116 #endif
117 
118 /*
119  * Local Variables:
120  * mode: c++
121  * indent-tabs-mode: 1
122  * c-file-style: "bsd"
123  * End:
124  */
125