ControlConditionSwitch.xtend 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
  2. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
  3. import java.util.LinkedHashMap
  4. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
  5. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRule
  6. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.ControlRuleBlock
  7. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CustomControlRule
  8. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.DoStep
  9. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.StepSize
  10. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CurrentTime
  11. class ControlConditionSwitch extends InOutRulesConditionSwitch {
  12. new(String adaptationClassName,
  13. String adaptationName,
  14. LinkedHashMap<String,SAScalarVariable> SASVs
  15. ) {
  16. super(adaptationClassName, adaptationName, "", null, SASVs);
  17. }
  18. override ReturnInformation caseControlRuleBlock(ControlRuleBlock obj) {
  19. var retVal = new ReturnInformation();
  20. for (crtlRule : obj.eAllContents.toIterable.filter(ControlRule)) {
  21. retVal.appendCode(doSwitch(crtlRule).code);
  22. }
  23. return retVal;
  24. }
  25. override ReturnInformation caseCustomControlRule(CustomControlRule object) {
  26. var retVal = new ReturnInformation();
  27. var String tempDoSwitchCode = "";
  28. for (ruleStm : object.controlRulestatements) {
  29. tempDoSwitchCode += doSwitch(ruleStm).code;
  30. }
  31. var functionPrefix = "void ";
  32. var functionNameArgs = "executeInternalControlFlow(double h, double dt)"
  33. functionSignatures.add(functionPrefix + functionNameArgs + ";");
  34. retVal.code =
  35. '''
  36. «functionPrefix+this.adaptationName»::«functionNameArgs»
  37. {
  38. «tempDoSwitchCode»
  39. }
  40. ''';
  41. return retVal;
  42. }
  43. override ReturnInformation caseDoStep(DoStep object) {
  44. var retVal = new ReturnInformation();
  45. retVal.code = '''this->doStep(«object.fmu.name»,«doSwitch(object.h)»,«doSwitch(object.t)»);''';
  46. return retVal;
  47. }
  48. override ReturnInformation caseStepSize(StepSize object) {
  49. var retVal = new ReturnInformation();
  50. retVal.code = '''h''';
  51. return retVal;
  52. }
  53. override ReturnInformation caseCurrentTime(CurrentTime object) {
  54. var retVal = new ReturnInformation();
  55. retVal.code = '''dt''';
  56. return retVal;
  57. }
  58. }