gocodegen.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright 2001-2006 Adrian Thurston <thurston@complang.org>
  3. * 2004 Erich Ocean <eric.ocean@ampede.com>
  4. * 2005 Alan West <alan@alanz.com>
  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. #ifndef _GOCODEGEN_H
  23. #define _GOCODEGEN_H
  24. #include <iostream>
  25. #include <string>
  26. #include <stdio.h>
  27. #include "common.h"
  28. #include "gendata.h"
  29. using std::string;
  30. using std::ostream;
  31. /* Integer array line length. */
  32. #define IALL 8
  33. /* Forwards. */
  34. struct RedFsmAp;
  35. struct RedStateAp;
  36. struct CodeGenData;
  37. struct GenAction;
  38. struct NameInst;
  39. struct GenInlineItem;
  40. struct GenInlineList;
  41. struct RedAction;
  42. struct LongestMatch;
  43. struct LongestMatchPart;
  44. class GoCodeGen : public CodeGenData
  45. {
  46. public:
  47. GoCodeGen( ostream &out )
  48. : CodeGenData(out) {}
  49. virtual ~GoCodeGen() {}
  50. virtual void finishRagelDef();
  51. virtual void writeInit();
  52. virtual void writeStart();
  53. virtual void writeFirstFinal();
  54. virtual void writeError();
  55. virtual void writeExports();
  56. protected:
  57. string FSM_NAME();
  58. string START_STATE_ID();
  59. ostream &ACTIONS_ARRAY();
  60. string GET_WIDE_KEY();
  61. string GET_WIDE_KEY( RedStateAp *state );
  62. string TABS( int level );
  63. string KEY( Key key );
  64. string WIDE_KEY( RedStateAp *state, Key key );
  65. string LDIR_PATH( char *path );
  66. virtual void ACTION( ostream &ret, GenAction *action, int targState,
  67. bool inFinish, bool csForced );
  68. void CONDITION( ostream &ret, GenAction *condition );
  69. string ALPH_TYPE();
  70. string WIDE_ALPH_TYPE();
  71. string ARRAY_TYPE( unsigned long maxVal );
  72. bool isAlphTypeSigned();
  73. bool isWideAlphTypeSigned();
  74. virtual string CAST( string type, string expr );
  75. virtual string UINT();
  76. virtual string INT();
  77. virtual string NULL_ITEM();
  78. virtual string GET_KEY();
  79. string P();
  80. string PE();
  81. string vEOF();
  82. string ACCESS();
  83. string vCS();
  84. string STACK();
  85. string TOP();
  86. string TOKSTART();
  87. string TOKEND();
  88. string ACT();
  89. string DATA();
  90. string DATA_PREFIX();
  91. string PM() { return "_" + DATA_PREFIX() + "partition_map"; }
  92. string C() { return "_" + DATA_PREFIX() + "cond_spaces"; }
  93. string CK() { return "_" + DATA_PREFIX() + "cond_keys"; }
  94. string K() { return "_" + DATA_PREFIX() + "trans_keys"; }
  95. string I() { return "_" + DATA_PREFIX() + "indicies"; }
  96. string CO() { return "_" + DATA_PREFIX() + "cond_offsets"; }
  97. string KO() { return "_" + DATA_PREFIX() + "key_offsets"; }
  98. string IO() { return "_" + DATA_PREFIX() + "index_offsets"; }
  99. string CL() { return "_" + DATA_PREFIX() + "cond_lengths"; }
  100. string SL() { return "_" + DATA_PREFIX() + "single_lengths"; }
  101. string RL() { return "_" + DATA_PREFIX() + "range_lengths"; }
  102. string A() { return "_" + DATA_PREFIX() + "actions"; }
  103. string TA() { return "_" + DATA_PREFIX() + "trans_actions"; }
  104. string TT() { return "_" + DATA_PREFIX() + "trans_targs"; }
  105. string TSA() { return "_" + DATA_PREFIX() + "to_state_actions"; }
  106. string FSA() { return "_" + DATA_PREFIX() + "from_state_actions"; }
  107. string EA() { return "_" + DATA_PREFIX() + "eof_actions"; }
  108. string ET() { return "_" + DATA_PREFIX() + "eof_trans"; }
  109. string SP() { return "_" + DATA_PREFIX() + "key_spans"; }
  110. string CSP() { return "_" + DATA_PREFIX() + "cond_key_spans"; }
  111. string START() { return DATA_PREFIX() + "start"; }
  112. string ERROR() { return DATA_PREFIX() + "error"; }
  113. string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; }
  114. string CTXDATA() { return DATA_PREFIX() + "ctxdata"; }
  115. void INLINE_LIST( ostream &ret, GenInlineList *inlineList,
  116. int targState, bool inFinish, bool csForced );
  117. virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0;
  118. virtual void CALL( ostream &ret, int callDest, int targState, bool inFinish ) = 0;
  119. virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0;
  120. virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
  121. virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinish ) = 0;
  122. virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem,
  123. int targState, bool inFinish ) = 0;
  124. virtual void RET( ostream &ret, bool inFinish ) = 0;
  125. virtual void BREAK( ostream &ret, int targState, bool csForced ) = 0;
  126. virtual void CURS( ostream &ret, bool inFinish ) = 0;
  127. virtual void TARGS( ostream &ret, bool inFinish, int targState ) = 0;
  128. void EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish );
  129. void LM_SWITCH( ostream &ret, GenInlineItem *item, int targState,
  130. int inFinish, bool csForced );
  131. void SET_ACT( ostream &ret, GenInlineItem *item );
  132. void INIT_TOKSTART( ostream &ret, GenInlineItem *item );
  133. void INIT_ACT( ostream &ret, GenInlineItem *item );
  134. void SET_TOKSTART( ostream &ret, GenInlineItem *item );
  135. void SET_TOKEND( ostream &ret, GenInlineItem *item );
  136. void GET_TOKEND( ostream &ret, GenInlineItem *item );
  137. virtual void SUB_ACTION( ostream &ret, GenInlineItem *item,
  138. int targState, bool inFinish, bool csForced );
  139. void STATE_IDS();
  140. string ERROR_STATE();
  141. string FIRST_FINAL_STATE();
  142. virtual ostream &OPEN_ARRAY( string type, string name );
  143. virtual ostream &CLOSE_ARRAY();
  144. virtual ostream &STATIC_VAR( string type, string name );
  145. virtual ostream &CONST( string type, string name );
  146. ostream &source_warning(const InputLoc &loc);
  147. ostream &source_error(const InputLoc &loc);
  148. unsigned int arrayTypeSize( unsigned long maxVal );
  149. bool outLabelUsed;
  150. bool testEofUsed;
  151. bool againLabelUsed;
  152. bool useIndicies;
  153. void genLineDirective( ostream &out );
  154. public:
  155. /* Determine if we should use indicies. */
  156. virtual void calcIndexSize() {}
  157. };
  158. #endif