instate.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Thu Aug 04 12:51:01 2016
  3. Model author: Glenn De Jonghe
  4. Model name: TestInstate
  5. Model description:
  6. Testing the INSTATE macro.*/
  7. // package "TestInstate"
  8. var TestInstate = {};
  9. (function() {
  10. var Class1 = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeOne;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.NextSmallStep;
  14. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  15. this.semantics.priority = StatechartSemantics.SourceParent;
  16. this.semantics.concurrency = StatechartSemantics.Single;
  17. // build Statechart structure
  18. this.build_statechart_structure();
  19. // call user defined constructor
  20. Class1.prototype.user_defined_constructor.call(this);
  21. };
  22. Class1.prototype = new Object();
  23. (function() {
  24. var proto = new RuntimeClassBase();
  25. for (prop in proto) {
  26. Class1.prototype[prop] = proto[prop];
  27. }
  28. })();
  29. Class1.prototype.user_defined_constructor = function() {
  30. };
  31. Class1.prototype.user_defined_destructor = function() {
  32. };
  33. // builds Statechart structure
  34. Class1.prototype.build_statechart_structure = function() {
  35. // state <root>
  36. this.states[""] = new State(0, this);
  37. // state /parallel_1
  38. this.states["/parallel_1"] = new ParallelState(1, this);
  39. // state /parallel_1/orthogonal1
  40. this.states["/parallel_1/orthogonal1"] = new State(2, this);
  41. // state /parallel_1/orthogonal1/state1
  42. this.states["/parallel_1/orthogonal1/state1"] = new State(3, this);
  43. // state /parallel_1/orthogonal1/inner
  44. this.states["/parallel_1/orthogonal1/inner"] = new State(4, this);
  45. // state /parallel_1/orthogonal1/inner/state2
  46. this.states["/parallel_1/orthogonal1/inner/state2"] = new State(5, this);
  47. // state /parallel_1/orthogonal1/inner/state3
  48. this.states["/parallel_1/orthogonal1/inner/state3"] = new State(6, this);
  49. // state /parallel_1/orthogonal2
  50. this.states["/parallel_1/orthogonal2"] = new State(7, this);
  51. // state /parallel_1/orthogonal2/tester
  52. this.states["/parallel_1/orthogonal2/tester"] = new State(8, this);
  53. // state /parallel_1/orthogonal2/stop
  54. this.states["/parallel_1/orthogonal2/stop"] = new State(9, this);
  55. // add children
  56. this.states[""].addChild(this.states["/parallel_1"]);
  57. this.states["/parallel_1"].addChild(this.states["/parallel_1/orthogonal1"]);
  58. this.states["/parallel_1"].addChild(this.states["/parallel_1/orthogonal2"]);
  59. this.states["/parallel_1/orthogonal1"].addChild(this.states["/parallel_1/orthogonal1/state1"]);
  60. this.states["/parallel_1/orthogonal1"].addChild(this.states["/parallel_1/orthogonal1/inner"]);
  61. this.states["/parallel_1/orthogonal1/inner"].addChild(this.states["/parallel_1/orthogonal1/inner/state2"]);
  62. this.states["/parallel_1/orthogonal1/inner"].addChild(this.states["/parallel_1/orthogonal1/inner/state3"]);
  63. this.states["/parallel_1/orthogonal2"].addChild(this.states["/parallel_1/orthogonal2/tester"]);
  64. this.states["/parallel_1/orthogonal2"].addChild(this.states["/parallel_1/orthogonal2/stop"]);
  65. this.states[""].fixTree();
  66. this.states[""].default_state = this.states["/parallel_1"];
  67. this.states["/parallel_1/orthogonal1"].default_state = this.states["/parallel_1/orthogonal1/state1"];
  68. this.states["/parallel_1/orthogonal1/inner"].default_state = this.states["/parallel_1/orthogonal1/inner/state2"];
  69. this.states["/parallel_1/orthogonal2"].default_state = this.states["/parallel_1/orthogonal2/tester"];
  70. // transition /parallel_1/orthogonal1/state1
  71. var _parallel_1_orthogonal1_state1_0 = new Transition(this, this.states["/parallel_1/orthogonal1/state1"], [this.states["/parallel_1/orthogonal1/inner"]]);
  72. _parallel_1_orthogonal1_state1_0.trigger = new Event("to_inner", null);
  73. this.states["/parallel_1/orthogonal1/state1"].addTransition(_parallel_1_orthogonal1_state1_0);
  74. // transition /parallel_1/orthogonal1/inner/state2
  75. var _parallel_1_orthogonal1_inner_state2_0 = new Transition(this, this.states["/parallel_1/orthogonal1/inner/state2"], [this.states["/parallel_1/orthogonal1/inner/state3"]]);
  76. _parallel_1_orthogonal1_inner_state2_0.trigger = new Event("to_state3", null);
  77. this.states["/parallel_1/orthogonal1/inner/state2"].addTransition(_parallel_1_orthogonal1_inner_state2_0);
  78. // transition /parallel_1/orthogonal2/tester
  79. var _parallel_1_orthogonal2_tester_0 = new Transition(this, this.states["/parallel_1/orthogonal2/tester"], [this.states["/parallel_1/orthogonal2/tester"]]);
  80. _parallel_1_orthogonal2_tester_0.setAction(this._parallel_1_orthogonal2_tester_0_exec);
  81. _parallel_1_orthogonal2_tester_0.setGuard(this._parallel_1_orthogonal2_tester_0_guard);
  82. this.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_0);
  83. var _parallel_1_orthogonal2_tester_1 = new Transition(this, this.states["/parallel_1/orthogonal2/tester"], [this.states["/parallel_1/orthogonal2/tester"]]);
  84. _parallel_1_orthogonal2_tester_1.setAction(this._parallel_1_orthogonal2_tester_1_exec);
  85. _parallel_1_orthogonal2_tester_1.setGuard(this._parallel_1_orthogonal2_tester_1_guard);
  86. this.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_1);
  87. var _parallel_1_orthogonal2_tester_2 = new Transition(this, this.states["/parallel_1/orthogonal2/tester"], [this.states["/parallel_1/orthogonal2/stop"]]);
  88. _parallel_1_orthogonal2_tester_2.setAction(this._parallel_1_orthogonal2_tester_2_exec);
  89. _parallel_1_orthogonal2_tester_2.setGuard(this._parallel_1_orthogonal2_tester_2_guard);
  90. this.states["/parallel_1/orthogonal2/tester"].addTransition(_parallel_1_orthogonal2_tester_2);
  91. };
  92. Class1.prototype._parallel_1_orthogonal2_tester_0_exec = function(parameters) {
  93. this.big_step.outputEvent(new Event("check1", "test_output", new Array()));
  94. this.raiseInternalEvent(new Event("to_inner", null, new Array()));
  95. };
  96. Class1.prototype._parallel_1_orthogonal2_tester_0_guard = function(parameters) {
  97. return this.inState(["/parallel_1/orthogonal1/state1"]);
  98. };
  99. Class1.prototype._parallel_1_orthogonal2_tester_1_exec = function(parameters) {
  100. this.big_step.outputEvent(new Event("check2", "test_output", new Array()));
  101. this.raiseInternalEvent(new Event("to_state3", null, new Array()));
  102. };
  103. Class1.prototype._parallel_1_orthogonal2_tester_1_guard = function(parameters) {
  104. return this.inState(["/parallel_1/orthogonal1/inner/state2"]);
  105. };
  106. Class1.prototype._parallel_1_orthogonal2_tester_2_exec = function(parameters) {
  107. this.big_step.outputEvent(new Event("check3", "test_output", new Array()));
  108. };
  109. Class1.prototype._parallel_1_orthogonal2_tester_2_guard = function(parameters) {
  110. return this.inState(["/parallel_1/orthogonal1/inner/state3"]);
  111. };
  112. Class1.prototype.initializeStatechart = function() {
  113. // enter default state
  114. var states = this.states["/parallel_1"].getEffectiveTargetStates();
  115. this.updateConfiguration(states);
  116. for (var state_idx in states) {
  117. if (!states.hasOwnProperty(state_idx)) continue;
  118. var state = states[state_idx]
  119. if (state.enter) {
  120. state.enter();
  121. }
  122. }
  123. };
  124. // add symbol 'Class1' to package 'TestInstate'
  125. TestInstate.Class1 = Class1;
  126. var ObjectManager = function(controller) {
  127. ObjectManagerBase.call(this, controller);
  128. };
  129. ObjectManager.prototype = new Object();
  130. (function() {
  131. var proto = new ObjectManagerBase();
  132. for (prop in proto) {
  133. ObjectManager.prototype[prop] = proto[prop];
  134. }
  135. })();
  136. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  137. if (class_name === "Class1") {
  138. var instance = new Class1(this.controller);
  139. instance.associations = new Object();
  140. } else {
  141. throw new Error("Cannot instantiate class " + class_name);
  142. }
  143. return instance;
  144. };
  145. // add symbol 'ObjectManager' to package 'TestInstate'
  146. TestInstate.ObjectManager = ObjectManager;
  147. var Controller = function(event_loop_callbacks, finished_callback) {
  148. if (finished_callback === undefined) finished_callback = null;
  149. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  150. this.addOutputPort("test_output");
  151. this.object_manager.createInstance("Class1", new Array());
  152. };
  153. Controller.prototype = new Object();
  154. (function() {
  155. var proto = new EventLoopControllerBase();
  156. for (prop in proto) {
  157. Controller.prototype[prop] = proto[prop];
  158. }
  159. })();
  160. // add symbol 'Controller' to package 'TestInstate'
  161. TestInstate.Controller = Controller;
  162. var InputEvent = function(name, port, parameters, time_offset) {
  163. this.name = name;
  164. this.port = port;
  165. this.parameters = parameters;
  166. this.time_offset = time_offset;
  167. };
  168. // add symbol 'InputEvent' to package 'TestInstate'
  169. TestInstate.InputEvent = InputEvent;
  170. var Test = function() {
  171. };
  172. Test.prototype.input_events = new Array();
  173. Test.prototype.expected_events = [[new Event("check1", "test_output", new Array())], [new Event("check2", "test_output", new Array())], [new Event("check3", "test_output", new Array())]];
  174. // add symbol 'Test' to package 'TestInstate'
  175. TestInstate.Test = Test;
  176. })();