InRulesConditionSwitch.xtend 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package be.uantwerpen.ansymo.semanticadaptation.cg.cpp.generation
  2. import java.util.LinkedHashMap
  3. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.MappedScalarVariable
  4. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.SAScalarVariable
  5. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.CompositeOutputFunction
  6. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.ReturnInformation
  7. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.Assignment
  8. import be.uantwerpen.ansymo.semanticadaptation.cg.cpp.data.GlobalInOutVariable
  9. import be.uantwerpen.ansymo.semanticadaptation.semanticAdaptation.InRulesBlock
  10. class InRulesConditionSwitch extends RulesConditionSwitch {
  11. private Boolean inOutputFunction = false;
  12. new(
  13. String adaptationClassName,
  14. String adaptationName,
  15. LinkedHashMap<String, LinkedHashMap<String, MappedScalarVariable>> mSVars,
  16. LinkedHashMap<String, SAScalarVariable> SASVs,
  17. LinkedHashMap<String, GlobalInOutVariable> params,
  18. LinkedHashMap<String, GlobalInOutVariable> inVars,
  19. LinkedHashMap<String, GlobalInOutVariable> outVars,
  20. LinkedHashMap<String, GlobalInOutVariable> crtlVars
  21. ) {
  22. super(adaptationClassName, adaptationName, "in_rule_", mSVars, SASVs, params, inVars, outVars, crtlVars);
  23. }
  24. public def LinkedHashMap<String, GlobalInOutVariable> getGlobalVars(InRulesBlock object) {
  25. if (object.globalInVars !== null) {
  26. this.globalDeclaration = true;
  27. for (gVar : object.globalInVars)
  28. doSwitch(gVar);
  29. this.globalDeclaration = false;
  30. }
  31. return this.gVars;
  32. }
  33. override ReturnInformation caseInRulesBlock(InRulesBlock object) {
  34. return this.doSwitch(object.globalInVars, object);
  35. }
  36. override ReturnInformation caseCompositeOutputFunction(CompositeOutputFunction object) {
  37. this.inOutputFunction = true;
  38. val ReturnInformation retVal = super.caseCompositeOutputFunction(object);
  39. this.inOutputFunction = false;
  40. return retVal;
  41. }
  42. override ReturnInformation caseAssignment(Assignment object) {
  43. var retVal = new ReturnInformation();
  44. if (inOutputFunction) {
  45. retVal.code = '''setValue(«object.lvalue.owner.name»,«mSVars.get(object.lvalue.owner.name).get(object.lvalue.ref.name).define»,«doSwitch(object.expr).code»)''';
  46. return retVal;
  47. } else {
  48. return super.caseAssignment(object);
  49. }
  50. }
  51. }