Guest User

Untitled

a guest
Jul 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Michael Betts
  2. CSE 321 - HW10
  3.  
  4.  
  5. global_function Integer Program_Occurrence_Count (
  6. preserves Program& p,
  7. preserves Text inst
  8. );
  9. {
  10. object Integer count;
  11. if (p.Size_Of_Context() == 0)
  12. {
  13. object Statement temp_statement;
  14. p.Swap_Body (temp_statement);
  15. count = Statement_Occurence_Count (temp_statement, inst);
  16. p.Swap_Body (temp_statement);
  17. return count;
  18. }
  19. else
  20. {
  21. object Text temp_name;
  22. object Statement temp_statement;
  23. p.Remove_Any_From_Context (temp_name, temp_statement);
  24. count = Statement_Occurence_Count (temp_statement, inst);
  25. count = count + Program_Occurence_Count (p, inst);
  26. p.Add_To_Context (temp_name, temp_statement);
  27. return count;
  28. }
  29. }
  30.  
  31.  
  32.  
  33. global_function Integer Statement_Occurrence_Count (
  34. preserves Statement& s,
  35. preserves Text inst
  36. );
  37. {
  38. object Integer count;
  39. if (s.Kind() == BLOCK)
  40. {
  41. object Integer pos;
  42. while (pos < s.Length_Of_Block())
  43. {
  44. object Statement temp_statement;
  45. s.Remove_From_Block (pos, temp_statement);
  46. count = count + Statement_Occurence_Count (temp_statement, inst);
  47. s.Add_To_Block (pos, temp_statement);
  48. pos++;
  49. }
  50. return count;
  51. }
  52. else if (s.Kind() == IF)
  53. {
  54. object Integer cond;
  55. object Statement temp_statement;
  56. s.Decompose_If (cond, temp_statement);
  57. count = Statement_Occurence_Count (temp_statement, inst);
  58. s.Compose_If (cond, temp_statement);
  59. return count;
  60. }
  61. else if (s.Kind() == IF_ELSE)
  62. {
  63. object Statement temp_statement1, temp_statement2;
  64. object Integer cond;
  65. s.Decompose_If_Else (cond, temp_statement1, temp_statement2);
  66. count = Statement_Occurence_Count (temp_statement1, inst);
  67. count = count + Statement_Occurence_Count (temp_statement2, inst);
  68. s.Compose_If_Else (cond, temp_statement1, temp_statement2);
  69. return count;
  70. }
  71. else if (s.Kind() == WHILE)
  72. {
  73. object Integer cond;
  74. object Statement temp_statement;
  75. s.Decompose_While (cond, temp_statement);
  76. count = Statement_Occurence_Count (temp_statement, inst);
  77. s.Compose_While (cond, temp_statement);
  78. return count;
  79. }
  80. else // Call statement
  81. {
  82. object Integer temp_inst;
  83. s.Decompose_Call (temp_inst);
  84. if (temp_inst == inst)
  85. {
  86. count = count + 1;
  87. }
  88. s.Compose_Call (temp_inst);
  89. }
  90. }
Add Comment
Please, Sign In to add comment