guard.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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: 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. this.default_targets = this.states["/state_1"].getEffectiveTargetStates();
  82. RuntimeClassBase.prototype.initializeStatechart.call(this);
  83. };
  84. // add symbol 'Class1' to package 'TestGuard'
  85. TestGuard.Class1 = Class1;
  86. var ObjectManager = function(controller) {
  87. ObjectManagerBase.call(this, controller);
  88. };
  89. ObjectManager.prototype = new Object();
  90. (function() {
  91. var proto = new ObjectManagerBase();
  92. for (prop in proto) {
  93. ObjectManager.prototype[prop] = proto[prop];
  94. }
  95. })();
  96. ObjectManager.prototype.instantiate = function(class_name, construct_params) {
  97. if (class_name === "Class1") {
  98. var instance = new Class1(this.controller);
  99. instance.associations = new Object();
  100. } else {
  101. throw new Error("Cannot instantiate class " + class_name);
  102. }
  103. return instance;
  104. };
  105. // add symbol 'ObjectManager' to package 'TestGuard'
  106. TestGuard.ObjectManager = ObjectManager;
  107. var Controller = function(event_loop_callbacks, finished_callback, behind_schedule_callback) {
  108. if (finished_callback === undefined) finished_callback = null;
  109. if (behind_schedule_callback === undefined) behind_schedule_callback = null;
  110. EventLoopControllerBase.call(this, new ObjectManager(this), event_loop_callbacks, finished_callback, behind_schedule_callback);
  111. this.addOutputPort("test_output");
  112. this.object_manager.createInstance("Class1", new Array());
  113. };
  114. Controller.prototype = new Object();
  115. (function() {
  116. var proto = new EventLoopControllerBase();
  117. for (prop in proto) {
  118. Controller.prototype[prop] = proto[prop];
  119. }
  120. })();
  121. // add symbol 'Controller' to package 'TestGuard'
  122. TestGuard.Controller = Controller;
  123. var InputEvent = function(name, port, parameters, time_offset) {
  124. this.name = name;
  125. this.port = port;
  126. this.parameters = parameters;
  127. this.time_offset = time_offset;
  128. };
  129. // add symbol 'InputEvent' to package 'TestGuard'
  130. TestGuard.InputEvent = InputEvent;
  131. var Test = function() {
  132. };
  133. Test.prototype.input_events = new Array();
  134. Test.prototype.expected_events = [[new Event("received", "test_output", [3])]];
  135. // add symbol 'Test' to package 'TestGuard'
  136. TestGuard.Test = Test;
  137. })();