guard.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /* Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
  2. Date: Mon Aug 08 09:49:19 2016
  3. Model author: Glenn De Jonghe
  4. Model name: TestGuard
  5. Model description:
  6. Testing the guard.*/
  7. // package "TestGuard"
  8. var TestGuard = {};
  9. (function() {
  10. var Class1 = function(controller) {
  11. RuntimeClassBase.call(this, controller);
  12. this.semantics.big_step_maximality = StatechartSemantics.TakeMany;
  13. this.semantics.internal_event_lifeline = StatechartSemantics.Queue;
  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. // user defined attributes
  20. this.member1 = 0;
  21. // call user defined constructor
  22. Class1.prototype.user_defined_constructor.call(this);
  23. };
  24. Class1.prototype = new Object();
  25. (function() {
  26. var proto = new RuntimeClassBase();
  27. for (prop in proto) {
  28. Class1.prototype[prop] = proto[prop];
  29. }
  30. })();
  31. Class1.prototype.user_defined_constructor = function() {
  32. };
  33. Class1.prototype.user_defined_destructor = function() {
  34. };
  35. // builds Statechart structure
  36. Class1.prototype.build_statechart_structure = function() {
  37. // state <root>
  38. this.states[""] = new State(0, this);
  39. // state /state_1
  40. this.states["/state_1"] = new State(1, this);
  41. this.states["/state_1"].setEnter(this._state_1_enter);
  42. // state /state_2
  43. this.states["/state_2"] = new State(2, this);
  44. // state /state_3
  45. this.states["/state_3"] = new State(3, this);
  46. this.states["/state_3"].setEnter(this._state_3_enter);
  47. // add children
  48. this.states[""].addChild(this.states["/state_1"]);
  49. this.states[""].addChild(this.states["/state_2"]);
  50. this.states[""].addChild(this.states["/state_3"]);
  51. this.states[""].fixTree();
  52. this.states[""].default_state = this.states["/state_1"];
  53. // transition /state_1
  54. var _state_1_0 = new Transition(this, this.states["/state_1"], [this.states["/state_2"]]);
  55. _state_1_0.setTrigger(null);
  56. this.states["/state_1"].addTransition(_state_1_0);
  57. // transition /state_2
  58. var _state_2_0 = new Transition(this, this.states["/state_2"], [this.states["/state_1"]]);
  59. _state_2_0.setTrigger(null);
  60. _state_2_0.setGuard(this._state_2_0_guard);
  61. this.states["/state_2"].addTransition(_state_2_0);
  62. var _state_2_1 = new Transition(this, this.states["/state_2"], [this.states["/state_3"]]);
  63. _state_2_1.setTrigger(null);
  64. _state_2_1.setGuard(this._state_2_1_guard);
  65. this.states["/state_2"].addTransition(_state_2_1);
  66. };
  67. Class1.prototype._state_1_enter = function() {
  68. this.member1 = this.member1 + 1;
  69. };
  70. Class1.prototype._state_3_enter = function() {
  71. this.big_step.outputEvent(new Event("received", "test_output", [this.member1]));
  72. };
  73. Class1.prototype._state_2_0_guard = function(parameters) {
  74. return this.member1 < 3;
  75. };
  76. Class1.prototype._state_2_1_guard = function(parameters) {
  77. return this.member1 >= 3;
  78. };
  79. Class1.prototype.initializeStatechart = function() {
  80. // enter default state
  81. var states = this.states["/state_1"].getEffectiveTargetStates();
  82. this.updateConfiguration(states);
  83. for (var state_idx in states) {
  84. if (!states.hasOwnProperty(state_idx)) continue;
  85. var state = states[state_idx]
  86. if (state.enter) {
  87. state.enter();
  88. }
  89. }
  90. };
  91. // add symbol 'Class1' to package 'TestGuard'
  92. TestGuard.Class1 = Class1;
  93. var ObjectManager = function(controller) {
  94. ObjectManagerBase.call(this, controller);
  95. };
  96. ObjectManager.prototype = new Object();
  97. (function() {
  98. var proto = new ObjectManagerBase();
  99. for (prop in proto) {
  100. ObjectManager.prototype[prop] = proto[prop];
  101. }
  102. })();
  103. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  104. if (class_name === "Class1") {
  105. var instance = new Class1(this.controller);
  106. instance.associations = new Object();
  107. } else {
  108. throw new Error("Cannot instantiate class " + class_name);
  109. }
  110. return instance;
  111. };
  112. // add symbol 'ObjectManager' to package 'TestGuard'
  113. TestGuard.ObjectManager = ObjectManager;
  114. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  115. if (finished_callback === undefined) finished_callback = null;
  116. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  117. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  118. this.addOutputPort("test_output");
  119. this.object_manager.createInstance("Class1", new Array());
  120. };
  121. Controller.prototype = new Object();
  122. (function() {
  123. var proto = new EventLoopControllerBase();
  124. for (prop in proto) {
  125. Controller.prototype[prop] = proto[prop];
  126. }
  127. })();
  128. // add symbol 'Controller' to package 'TestGuard'
  129. TestGuard.Controller = Controller;
  130. var InputEvent = function(name, port, parameters, time_offset) {
  131. this.name = name;
  132. this.port = port;
  133. this.parameters = parameters;
  134. this.time_offset = time_offset;
  135. };
  136. // add symbol 'InputEvent' to package 'TestGuard'
  137. TestGuard.InputEvent = InputEvent;
  138. var Test = function() {
  139. };
  140. Test.prototype.input_events = new Array();
  141. Test.prototype.expected_events = [[new Event("received", "test_output", [3])]];
  142. // add symbol 'Test' to package 'TestGuard'
  143. TestGuard.Test = Test;
  144. })();