Use portable types in the C/C++ code generator
[ragel-jkt.git] / ragel / rubycodegen.h
blob4e3a30d69a3d406175c44e4d1f970eac876de69a
1 /*
2 * 2007 Victor Hugo Borja <vic@rubyforge.org>
3 * Copyright 2001-2007 Adrian Thurston <thurston@complang.org>
4 */
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
26 #include "common.h"
27 #include "gendata.h"
29 /* Integer array line length. */
30 #define IALL 8
33 class RubyCodeGen : public CodeGenData
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();
44 string FSM_NAME();
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();
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();
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"; }
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 );
100 string P();
101 string PE();
102 string vEOF();
104 string vCS();
105 string TOP();
106 string STACK();
107 string ACT();
108 string TOKSTART();
109 string TOKEND();
110 string DATA();
113 void finishRagelDef();
114 unsigned int arrayTypeSize( unsigned long maxVal );
116 protected:
117 virtual void writeExports();
118 virtual void writeInit();
119 virtual void writeStart();
120 virtual void writeFirstFinal();
121 virtual void writeError();
123 /* Determine if we should use indicies. */
124 virtual void calcIndexSize();
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;
134 virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0;
135 virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
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;
141 virtual int TRANS_ACTION( RedTransAp *trans );
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 );
153 protected:
154 ostream &source_warning(const InputLoc &loc);
155 ostream &source_error(const InputLoc &loc);
158 /* fields */
159 bool outLabelUsed;
160 bool againLabelUsed;
161 bool useIndicies;
163 void genLineDirective( ostream &out );
167 * Local Variables:
168 * mode: c++
169 * indent-tabs-mode: 1
170 * c-file-style: "bsd"
171 * End:
174 #endif