javacodegen.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Copyright 2006-2007 Adrian Thurston <thurston@complang.org>
  3. * 2007 Colin Fleming <colin.fleming@caverock.com>
  4. */
  5. /* This file is part of Ragel.
  6. *
  7. * Ragel is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Ragel is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Ragel; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef _JAVACODEGEN_H
  22. #define _JAVACODEGEN_H
  23. #include <iostream>
  24. #include <string>
  25. #include <stdio.h>
  26. #include "common.h"
  27. #include "gendata.h"
  28. using std::string;
  29. using std::ostream;
  30. /*
  31. * JavaTabCodeGen
  32. */
  33. struct JavaTabCodeGen : public CodeGenData
  34. {
  35. JavaTabCodeGen( ostream &out ) :
  36. CodeGenData(out) {}
  37. std::ostream &TO_STATE_ACTION_SWITCH();
  38. std::ostream &FROM_STATE_ACTION_SWITCH();
  39. std::ostream &EOF_ACTION_SWITCH();
  40. std::ostream &ACTION_SWITCH();
  41. std::ostream &COND_KEYS();
  42. std::ostream &COND_SPACES();
  43. std::ostream &KEYS();
  44. std::ostream &INDICIES();
  45. std::ostream &COND_OFFSETS();
  46. std::ostream &KEY_OFFSETS();
  47. std::ostream &INDEX_OFFSETS();
  48. std::ostream &COND_LENS();
  49. std::ostream &SINGLE_LENS();
  50. std::ostream &RANGE_LENS();
  51. std::ostream &TO_STATE_ACTIONS();
  52. std::ostream &FROM_STATE_ACTIONS();
  53. std::ostream &EOF_ACTIONS();
  54. std::ostream &EOF_TRANS();
  55. std::ostream &TRANS_TARGS();
  56. std::ostream &TRANS_ACTIONS();
  57. std::ostream &TRANS_TARGS_WI();
  58. std::ostream &TRANS_ACTIONS_WI();
  59. void BREAK( ostream &ret, int targState );
  60. void GOTO( ostream &ret, int gotoDest, bool inFinish );
  61. void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
  62. void CALL( ostream &ret, int callDest, int targState, bool inFinish );
  63. void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, int targState, bool inFinish );
  64. void RET( ostream &ret, bool inFinish );
  65. void COND_TRANSLATE();
  66. void LOCATE_TRANS();
  67. virtual void writeExec();
  68. virtual void writeData();
  69. virtual void writeInit();
  70. virtual void writeExports();
  71. virtual void writeStart();
  72. virtual void writeFirstFinal();
  73. virtual void writeError();
  74. virtual void finishRagelDef();
  75. void NEXT( ostream &ret, int nextDest, bool inFinish );
  76. void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish );
  77. int TO_STATE_ACTION( RedStateAp *state );
  78. int FROM_STATE_ACTION( RedStateAp *state );
  79. int EOF_ACTION( RedStateAp *state );
  80. int TRANS_ACTION( RedTransAp *trans );
  81. /* Determine if we should use indicies. */
  82. void calcIndexSize();
  83. private:
  84. string array_type;
  85. string array_name;
  86. int item_count;
  87. int div_count;
  88. public:
  89. virtual string NULL_ITEM();
  90. virtual ostream &OPEN_ARRAY( string type, string name );
  91. virtual ostream &ARRAY_ITEM( string item, bool last );
  92. virtual ostream &CLOSE_ARRAY();
  93. virtual ostream &STATIC_VAR( string type, string name );
  94. virtual string ARR_OFF( string ptr, string offset );
  95. virtual string CAST( string type );
  96. virtual string GET_KEY();
  97. virtual string CTRL_FLOW();
  98. string FSM_NAME();
  99. string START_STATE_ID();
  100. ostream &ACTIONS_ARRAY();
  101. string GET_WIDE_KEY();
  102. string GET_WIDE_KEY( RedStateAp *state );
  103. string TABS( int level );
  104. string KEY( Key key );
  105. string INT( int i );
  106. void ACTION( ostream &ret, GenAction *action, int targState, bool inFinish );
  107. void CONDITION( ostream &ret, GenAction *condition );
  108. string ALPH_TYPE();
  109. string WIDE_ALPH_TYPE();
  110. string ARRAY_TYPE( unsigned long maxVal );
  111. string ACCESS();
  112. string P();
  113. string PE();
  114. string vEOF();
  115. string vCS();
  116. string STACK();
  117. string TOP();
  118. string TOKSTART();
  119. string TOKEND();
  120. string ACT();
  121. string DATA();
  122. string DATA_PREFIX();
  123. string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
  124. string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
  125. string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
  126. string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
  127. string I() { return "_" + DATA_PREFIX() + "indicies"; }
  128. string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
  129. string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
  130. string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
  131. string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
  132. string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
  133. string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
  134. string A() { return "_" + DATA_PREFIX() + "actions"; }
  135. string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
  136. string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
  137. string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
  138. string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
  139. string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
  140. string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
  141. string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
  142. string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
  143. string START() { return DATA_PREFIX() + "start"; }
  144. string ERROR() { return DATA_PREFIX() + "error"; }
  145. string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
  146. string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
  147. void INLINE_LIST( ostream &ret, GenInlineList *inlineList, int targState, bool inFinish );
  148. void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
  149. void EXECTE( ostream &ret, GenInlineItem *item, int targState, int inFinish );
  150. void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState, int inFinish );
  151. void SET_ACT( ostream &ret, GenInlineItem *item );
  152. void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
  153. void INIT_ACT( ostream &ret, GenInlineItem *item );
  154. void SET_TOKSTART( ostream &ret, GenInlineItem *item );
  155. void SET_TOKEND( ostream &ret, GenInlineItem *item );
  156. void GET_TOKEND( ostream &ret, GenInlineItem *item );
  157. void SUB_ACTION( ostream &ret, GenInlineItem *item,
  158. int targState, bool inFinish );
  159. string ERROR_STATE();
  160. string FIRST_FINAL_STATE();
  161. ostream &source_warning(const InputLoc &loc);
  162. ostream &source_error(const InputLoc &loc);
  163. unsigned int arrayTypeSize( unsigned long maxVal );
  164. bool outLabelUsed;
  165. bool againLabelUsed;
  166. bool useIndicies;
  167. void genLineDirective( ostream &out );
  168. };
  169. #endif