00_no_statechart_js.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Tue Aug 09 09:35:52 2016
  3. Model author: Herr Joeri Exelmans
  4. Model name: no_statechart
  5. Model description:
  6. Test to see what happens when a class with no statechart is defined.*/
  7. // package "no_statechart"
  8. var no_statechart = {};
  9. (function() {
  10. var my_struct = function(x, y) {
  11. // user defined attributes
  12. this.x = null;
  13. this.y = null;
  14. // call user defined constructor
  15. my_struct.prototype.user_defined_constructor.call(this, x, y);
  16. };
  17. my_struct.prototype.user_defined_constructor = function(x, y) {
  18. this.x = x;
  19. this.y = y;
  20. };
  21. my_struct.prototype.user_defined_destructor = function() {
  22. };
  23. // add symbol 'my_struct' to package 'no_statechart'
  24. no_statechart.my_struct = my_struct;
  25. var my_class = function(controller) {
  26. RuntimeClassBase.call(this, controller);
  27. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  28. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  29. this.semantics.input_event_lifeline = StatechartSemantics.FirstComboStep;
  30. this.semantics.priority = StatechartSemantics.SourceParent;
  31. this.semantics.concurrency = StatechartSemantics.Single;
  32. // build Statechart structure
  33. this.build_statechart_structure();
  34. // call user defined constructor
  35. my_class.prototype.user_defined_constructor.call(this);
  36. };
  37. my_class.prototype = new Object();
  38. (function() {
  39. var proto = new RuntimeClassBase();
  40. for (prop in proto) {
  41. my_class.prototype[prop] = proto[prop];
  42. }
  43. })();
  44. my_class.prototype.user_defined_constructor = function() {
  45. this.data = new my_struct(0, 0);
  46. };
  47. my_class.prototype.user_defined_destructor = function() {
  48. };
  49. // builds Statechart structure
  50. my_class.prototype.build_statechart_structure = function() {
  51. // state <root>
  52. this.states[""] = new State(0, this);
  53. // state /a
  54. this.states["/a"] = new State(1, this);
  55. this.states["/a"].setEnter(this._a_enter);
  56. this.states["/a"].setExit(this._a_exit);
  57. // state /b
  58. this.states["/b"] = new State(2, this);
  59. this.states["/b"].setEnter(this._b_enter);
  60. this.states["/b"].setExit(this._b_exit);
  61. // add children
  62. this.states[""].addChild(this.states["/a"]);
  63. this.states[""].addChild(this.states["/b"]);
  64. this.states[""].fixTree();
  65. this.states[""].default_state = this.states["/a"];
  66. // transition /a
  67. var _a_0 = new Transition(this, this.states["/a"], [this.states["/b"]]);
  68. _a_0.setAction(this._a_0_exec);
  69. _a_0.setTrigger(new Event("_0after"));
  70. _a_0.setGuard(this._a_0_guard);
  71. this.states["/a"].addTransition(_a_0);
  72. // transition /b
  73. var _b_0 = new Transition(this, this.states["/b"], [this.states["/a"]]);
  74. _b_0.setAction(this._b_0_exec);
  75. _b_0.setTrigger(new Event("_1after"));
  76. _b_0.setGuard(this._b_0_guard);
  77. this.states["/b"].addTransition(_b_0);
  78. };
  79. my_class.prototype._a_enter = function() {
  80. this.addTimer(0, 0.1);
  81. };
  82. my_class.prototype._a_exit = function() {
  83. this.removeTimer(0);
  84. };
  85. my_class.prototype._b_enter = function() {
  86. this.addTimer(1, 0.1);
  87. };
  88. my_class.prototype._b_exit = function() {
  89. this.removeTimer(1);
  90. };
  91. my_class.prototype._a_0_exec = function(parameters) {
  92. this.big_step.outputEvent(new Event("to_b", "out", [this.data.x]));
  93. this.data.x += 1;
  94. };
  95. my_class.prototype._a_0_guard = function(parameters) {
  96. return this.data.x < 2;
  97. };
  98. my_class.prototype._b_0_exec = function(parameters) {
  99. this.data.y += 1;
  100. this.big_step.outputEvent(new Event("to_a", "out", [this.data.y]));
  101. };
  102. my_class.prototype._b_0_guard = function(parameters) {
  103. return this.data.y < 2;
  104. };
  105. my_class.prototype.initializeStatechart = function() {
  106. // enter default state
  107. this.default_targets = this.states["/a"].getEffectiveTargetStates();
  108. RuntimeClassBase.prototype.initializeStatechart.call(this);
  109. };
  110. // add symbol 'my_class' to package 'no_statechart'
  111. no_statechart.my_class = my_class;
  112. var ObjectManager = function(controller) {
  113. ObjectManagerBase.call(this, controller);
  114. };
  115. ObjectManager.prototype = new Object();
  116. (function() {
  117. var proto = new ObjectManagerBase();
  118. for (prop in proto) {
  119. ObjectManager.prototype[prop] = proto[prop];
  120. }
  121. })();
  122. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  123. if (class_name === "my_struct") {
  124. var instance = new my_struct(this.controller, construct_params[0], construct_params[1]);
  125. instance.associations = new Object();
  126. } else if (class_name === "my_class") {
  127. var instance = new my_class(this.controller);
  128. instance.associations = new Object();
  129. } else {
  130. throw new Error("Cannot instantiate class " + class_name);
  131. }
  132. return instance;
  133. };
  134. // add symbol 'ObjectManager' to package 'no_statechart'
  135. no_statechart.ObjectManager = ObjectManager;
  136. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  137. if (finished_callback === undefined) finished_callback = null;
  138. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  139. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  140. this.addInputPort("in");
  141. this.addOutputPort("out");
  142. this.object_manager.createInstance("my_class", new Array());
  143. };
  144. Controller.prototype = new Object();
  145. (function() {
  146. var proto = new EventLoopControllerBase();
  147. for (prop in proto) {
  148. Controller.prototype[prop] = proto[prop];
  149. }
  150. })();
  151. // add symbol 'Controller' to package 'no_statechart'
  152. no_statechart.Controller = Controller;
  153. var InputEvent = function(name, port, parameters, time_offset) {
  154. this.name = name;
  155. this.port = port;
  156. this.parameters = parameters;
  157. this.time_offset = time_offset;
  158. };
  159. // add symbol 'InputEvent' to package 'no_statechart'
  160. no_statechart.InputEvent = InputEvent;
  161. var Test = function() {
  162. };
  163. Test.prototype.input_events = new Array();
  164. Test.prototype.expected_events = [[new Event("to_b", "out", [0])], [new Event("to_a", "out", [1])], [new Event("to_b", "out", [1])], [new Event("to_a", "out", [2])]];
  165. // add symbol 'Test' to package 'no_statechart'
  166. no_statechart.Test = Test;
  167. })();