guard.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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:00 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. this.states["/state_1"].addTransition(_state_1_0);
  56. // transition /state_2
  57. var _state_2_0 = new Transition(this, this.states["/state_2"], [this.states["/state_1"]]);
  58. _state_2_0.setGuard(this._state_2_0_guard);
  59. this.states["/state_2"].addTransition(_state_2_0);
  60. var _state_2_1 = new Transition(this, this.states["/state_2"], [this.states["/state_3"]]);
  61. _state_2_1.setGuard(this._state_2_1_guard);
  62. this.states["/state_2"].addTransition(_state_2_1);
  63. };
  64. Class1.prototype._state_1_enter = function() {
  65. this.member1 = this.member1 + 1;
  66. };
  67. Class1.prototype._state_3_enter = function() {
  68. this.big_step.outputEvent(new Event("received", "test_output", [this.member1]));
  69. };
  70. Class1.prototype._state_2_0_guard = function(parameters) {
  71. return this.member1 < 3;
  72. };
  73. Class1.prototype._state_2_1_guard = function(parameters) {
  74. return this.member1 >= 3;
  75. };
  76. Class1.prototype.initializeStatechart = function() {
  77. // enter default state
  78. var states = this.states["/state_1"].getEffectiveTargetStates();
  79. this.updateConfiguration(states);
  80. for (var state_idx in states) {
  81. if (!states.hasOwnProperty(state_idx)) continue;
  82. var state = states[state_idx]
  83. if (state.enter) {
  84. state.enter();
  85. }
  86. }
  87. };
  88. // add symbol 'Class1' to package 'TestGuard'
  89. TestGuard.Class1 = Class1;
  90. var ObjectManager = function(controller) {
  91. ObjectManagerBase.call(this, controller);
  92. };
  93. ObjectManager.prototype = new Object();
  94. (function() {
  95. var proto = new ObjectManagerBase();
  96. for (prop in proto) {
  97. ObjectManager.prototype[prop] = proto[prop];
  98. }
  99. })();
  100. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  101. if (class_name === "Class1") {
  102. var instance = new Class1(this.controller);
  103. instance.associations = new Object();
  104. } else {
  105. throw new Error("Cannot instantiate class " + class_name);
  106. }
  107. return instance;
  108. };
  109. // add symbol 'ObjectManager' to package 'TestGuard'
  110. TestGuard.ObjectManager = ObjectManager;
  111. var Controller = function(event_loop_callbacks, finished_callback) {
  112. if (finished_callback === undefined) finished_callback = null;
  113. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback);
  114. this.addOutputPort("test_output");
  115. this.object_manager.createInstance("Class1", new Array());
  116. };
  117. Controller.prototype = new Object();
  118. (function() {
  119. var proto = new EventLoopControllerBase();
  120. for (prop in proto) {
  121. Controller.prototype[prop] = proto[prop];
  122. }
  123. })();
  124. // add symbol 'Controller' to package 'TestGuard'
  125. TestGuard.Controller = Controller;
  126. var InputEvent = function(name, port, parameters, time_offset) {
  127. this.name = name;
  128. this.port = port;
  129. this.parameters = parameters;
  130. this.time_offset = time_offset;
  131. };
  132. // add symbol 'InputEvent' to package 'TestGuard'
  133. TestGuard.InputEvent = InputEvent;
  134. var Test = function() {
  135. };
  136. Test.prototype.input_events = new Array();
  137. Test.prototype.expected_events = [[new Event("received", "test_output", [3])]];
  138. // add symbol 'Test' to package 'TestGuard'
  139. TestGuard.Test = Test;
  140. })();