gogoto.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 _GOGOTO_H
  23. #define _GOGOTO_H
  24. #include <iostream>
  25. #include "gotablish.h"
  26. /* Forwards. */
  27. struct CodeGenData;
  28. struct NameInst;
  29. struct RedTransAp;
  30. struct RedStateAp;
  31. struct GenStateCond;
  32. /*
  33. * Goto driven fsm.
  34. */
  35. class GoGotoCodeGen
  36. : public GoTablishCodeGen
  37. {
  38. public:
  39. GoGotoCodeGen( ostream &out )
  40. : GoTablishCodeGen(out) {}
  41. protected:
  42. std::ostream &TO_STATE_ACTION_SWITCH( int level );
  43. std::ostream &FROM_STATE_ACTION_SWITCH( int level );
  44. std::ostream &EOF_ACTION_SWITCH( int level );
  45. std::ostream &ACTION_SWITCH( int level );
  46. std::ostream &STATE_GOTOS( int level );
  47. std::ostream &TRANSITIONS();
  48. std::ostream &EXEC_FUNCS();
  49. std::ostream &FINISH_CASES();
  50. virtual unsigned int TO_STATE_ACTION( RedStateAp *state );
  51. virtual unsigned int FROM_STATE_ACTION( RedStateAp *state );
  52. virtual unsigned int EOF_ACTION( RedStateAp *state );
  53. std::ostream &TO_STATE_ACTIONS();
  54. std::ostream &FROM_STATE_ACTIONS();
  55. std::ostream &EOF_ACTIONS();
  56. void COND_TRANSLATE( GenStateCond *stateCond, int level );
  57. void emitCondBSearch( RedStateAp *state, int level, int low, int high );
  58. void STATE_CONDS( RedStateAp *state, bool genDefault );
  59. virtual std::ostream &TRANS_GOTO( RedTransAp *trans, int level );
  60. virtual int TRANS_NR( RedTransAp *trans );
  61. void emitSingleSwitch( RedStateAp *state, int level );
  62. void emitRangeBSearch( RedStateAp *state, int level, int low, int high );
  63. /* Called from STATE_GOTOS just before writing the gotos */
  64. virtual void GOTO_HEADER( RedStateAp *state, int level );
  65. virtual void STATE_GOTO_ERROR( int level );
  66. virtual void writeData();
  67. virtual void writeExec();
  68. };
  69. #endif