rubycodegen.h 5.7 KB

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