You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
4.6 KiB

  1. #include "ProgramGraphBuilder.h"
  2. #include "storm-pgcl/storage/pgcl/AssignmentStatement.h"
  3. #include "storm-pgcl/storage/pgcl/ObserveStatement.h"
  4. #include "storm-pgcl/storage/pgcl/LoopStatement.h"
  5. #include "storm-pgcl/storage/pgcl/IfStatement.h"
  6. #include "storm-pgcl/storage/pgcl/NondeterministicBranch.h"
  7. #include "storm-pgcl/storage/pgcl/ProbabilisticBranch.h"
  8. namespace storm {
  9. namespace builder {
  10. void ProgramGraphBuilderVisitor::visit(storm::pgcl::AssignmentStatement const& s) {
  11. if(s.isDeterministic()) {
  12. builder.currentLoc()->addProgramEdgeToAllGroups(builder.addAction(s.getVariable(), boost::get<storm::expressions::Expression>(s.getExpression())), builder.nextLocId());
  13. } else {
  14. builder.currentLoc()->addProgramEdgeToAllGroups(builder.addAction(s.getVariable(), boost::get<storm::pgcl::UniformExpression>(s.getExpression())), builder.nextLocId());
  15. }
  16. }
  17. void ProgramGraphBuilderVisitor::visit(storm::pgcl::ObserveStatement const& s) {
  18. builder.currentLoc()->addProgramEdgeToAllGroups(builder.noAction(), s.getCondition().getBooleanExpression(), builder.nextLocId());
  19. }
  20. void ProgramGraphBuilderVisitor::visit(storm::pgcl::IfStatement const& s) {
  21. storm::expressions::Expression elseCondition;
  22. storm::ppg::ProgramLocation* beforeStatementLocation = builder.currentLoc();
  23. builder.storeNextLocation(builder.nextLoc());
  24. storm::ppg::ProgramLocation* ifbodyStart = builder.newLocation();
  25. builder.buildBlock(*s.getIfBody());
  26. storm::ppg::ProgramLocation* elsebodyStart;
  27. if(s.hasElse()) {
  28. builder.storeNextLocation(builder.nextLoc());
  29. elsebodyStart = builder.newLocation();
  30. builder.buildBlock(*s.getElseBody());
  31. }
  32. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), s.getCondition().getBooleanExpression(), ifbodyStart->id());
  33. elseCondition = !s.getCondition().getBooleanExpression();
  34. if(s.hasElse()) {
  35. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), elseCondition, elsebodyStart->id());
  36. } else {
  37. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), elseCondition, builder.nextLocId());
  38. }
  39. }
  40. void ProgramGraphBuilderVisitor::visit(storm::pgcl::LoopStatement const& s) {
  41. storm::ppg::ProgramLocation* beforeStatementLocation = builder.currentLoc();
  42. builder.storeNextLocation(beforeStatementLocation);
  43. storm::ppg::ProgramLocation* bodyStart = builder.newLocation();
  44. builder.buildBlock(*s.getBody());
  45. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), s.getCondition().getBooleanExpression(), bodyStart->id());
  46. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), !s.getCondition().getBooleanExpression(), builder.nextLocId());
  47. }
  48. void ProgramGraphBuilderVisitor::visit(storm::pgcl::NondeterministicBranch const& s) {
  49. storm::ppg::ProgramLocation* beforeStatementLocation = builder.currentLoc();
  50. builder.storeNextLocation(builder.nextLoc());
  51. storm::ppg::ProgramLocation* bodyStart = builder.newLocation();
  52. builder.buildBlock(*s.getLeftBranch());
  53. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), bodyStart->id());
  54. builder.storeNextLocation(builder.nextLoc());
  55. bodyStart = builder.newLocation();
  56. beforeStatementLocation->addProgramEdgeToAllGroups(builder.noAction(), bodyStart->id());
  57. builder.buildBlock(*s.getRightBranch());
  58. }
  59. void ProgramGraphBuilderVisitor::visit(storm::pgcl::ProbabilisticBranch const& s) {
  60. storm::ppg::ProgramLocation* beforeStatementLocation = builder.currentLoc();
  61. storm::ppg::ProgramLocation* afterStatementLocation = builder.nextLoc();
  62. builder.storeNextLocation(afterStatementLocation);
  63. storm::ppg::ProgramLocation* bodyStart = builder.newLocation();
  64. beforeStatementLocation->addProgramEdgeGroup(s.getProbability())->addEdge(builder.noAction(), bodyStart->id());
  65. builder.buildBlock(*s.getLeftBranch());
  66. builder.storeNextLocation(afterStatementLocation);
  67. bodyStart = builder.newLocation();
  68. beforeStatementLocation->addProgramEdgeGroup(1 - s.getProbability())->addEdge(builder.noAction(), bodyStart->id());
  69. builder.buildBlock(*s.getRightBranch());
  70. }
  71. }
  72. }