Initialize Tizen 2.3
[external/ragel.git] / ragel / rubycodegen.h
1 /*
2  *  2007 Victor Hugo Borja <vic@rubyforge.org>
3  *  Copyright 2001-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_CODEGEN_H
24 #define _RUBY_CODEGEN_H
25
26 #include "common.h"
27 #include "gendata.h"
28
29 /* Integer array line length. */
30 #define IALL 8
31
32
33 class RubyCodeGen : public CodeGenData
34 {
35 public:
36    RubyCodeGen( ostream &out ) : CodeGenData(out) { }
37    virtual ~RubyCodeGen() {}
38 protected:
39         ostream &START_ARRAY_LINE();
40         ostream &ARRAY_ITEM( string item, int count, bool last );
41         ostream &END_ARRAY_LINE();
42   
43
44         string FSM_NAME();
45
46         string START_STATE_ID();
47         string ERROR_STATE();
48         string FIRST_FINAL_STATE();
49         void INLINE_LIST(ostream &ret, GenInlineList *inlineList, int targState, bool inFinish);
50         string ACCESS();
51
52         void ACTION( ostream &ret, GenAction *action, int targState, bool inFinish );
53         string GET_KEY();
54         string GET_WIDE_KEY();
55         string GET_WIDE_KEY( RedStateAp *state );
56         string KEY( Key key );
57         string TABS( int level );
58         string INT( int i );
59         void CONDITION( ostream &ret, GenAction *condition );
60         string ALPH_TYPE();
61         string WIDE_ALPH_TYPE();
62         string ARRAY_TYPE( unsigned long maxVal );
63         ostream &ACTIONS_ARRAY();
64         void STATE_IDS();
65
66
67         string DATA_PREFIX();
68         string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
69         string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
70         string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
71         string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
72         string I() { return "_" + DATA_PREFIX() + "indicies"; }
73         string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
74         string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
75         string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
76         string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
77         string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
78         string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
79         string A() { return "_" + DATA_PREFIX() + "actions"; }
80         string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
81         string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
82         string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
83         string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
84         string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
85         string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
86         string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
87         string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
88         string START() { return DATA_PREFIX() + "start"; }
89         string ERROR() { return DATA_PREFIX() + "error"; }
90         string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
91         string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
92
93 public:
94         string NULL_ITEM();
95         ostream &OPEN_ARRAY( string type, string name );
96         ostream &CLOSE_ARRAY();
97         ostream &STATIC_VAR( string type, string name );
98         string ARR_OFF( string ptr, string offset );
99
100         string P();
101         string PE();
102         string vEOF();
103
104         string vCS();
105         string TOP();
106         string STACK();
107         string ACT();
108         string TOKSTART();
109         string TOKEND();
110         string DATA();
111
112
113         void finishRagelDef();
114         unsigned int arrayTypeSize( unsigned long maxVal );
115
116 protected:
117         virtual void writeExports();
118         virtual void writeInit();
119         virtual void writeStart();
120         virtual void writeFirstFinal();
121         virtual void writeError();
122
123         /* Determine if we should use indicies. */
124         virtual void calcIndexSize();
125
126         virtual void BREAK( ostream &ret, int targState ) = 0;
127         virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0;
128         virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
129         virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0;
130         virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish ) = 0;
131         virtual void RET( ostream &ret, bool inFinish ) = 0;
132
133
134         virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0;
135         virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
136
137         virtual int TO_STATE_ACTION( RedStateAp *state ) = 0;
138         virtual int FROM_STATE_ACTION( RedStateAp *state ) = 0;
139         virtual int EOF_ACTION( RedStateAp *state ) = 0;
140
141         virtual int TRANS_ACTION( RedTransAp *trans );
142
143         void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
144         void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish );
145         void SET_ACT( ostream &ret, GenInlineItem *item );
146         void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
147         void INIT_ACT( ostream &ret, GenInlineItem *item );
148         void SET_TOKSTART( ostream &ret, GenInlineItem *item );
149         void SET_TOKEND( ostream &ret, GenInlineItem *item );
150         void GET_TOKEND( ostream &ret, GenInlineItem *item );
151         void SUB_ACTION( ostream &ret, GenInlineItem *item, int targState, bool inFinish );
152
153 protected:
154         ostream &source_warning(const InputLoc &loc);
155         ostream &source_error(const InputLoc &loc);
156
157
158         /* fields */
159         bool outLabelUsed;
160         bool againLabelUsed;
161         bool useIndicies;
162
163         void genLineDirective( ostream &out );
164 };
165
166 /*
167  * Local Variables:
168  * mode: c++
169  * indent-tabs-mode: 1
170  * c-file-style: "bsd"
171  * End:
172  */
173
174 #endif