Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Michael Betts
- CSE 321 - HW10
- global_function Integer Program_Occurrence_Count (
- preserves Program& p,
- preserves Text inst
- );
- {
- object Integer count;
- if (p.Size_Of_Context() == 0)
- {
- object Statement temp_statement;
- p.Swap_Body (temp_statement);
- count = Statement_Occurence_Count (temp_statement, inst);
- p.Swap_Body (temp_statement);
- return count;
- }
- else
- {
- object Text temp_name;
- object Statement temp_statement;
- p.Remove_Any_From_Context (temp_name, temp_statement);
- count = Statement_Occurence_Count (temp_statement, inst);
- count = count + Program_Occurence_Count (p, inst);
- p.Add_To_Context (temp_name, temp_statement);
- return count;
- }
- }
- global_function Integer Statement_Occurrence_Count (
- preserves Statement& s,
- preserves Text inst
- );
- {
- object Integer count;
- if (s.Kind() == BLOCK)
- {
- object Integer pos;
- while (pos < s.Length_Of_Block())
- {
- object Statement temp_statement;
- s.Remove_From_Block (pos, temp_statement);
- count = count + Statement_Occurence_Count (temp_statement, inst);
- s.Add_To_Block (pos, temp_statement);
- pos++;
- }
- return count;
- }
- else if (s.Kind() == IF)
- {
- object Integer cond;
- object Statement temp_statement;
- s.Decompose_If (cond, temp_statement);
- count = Statement_Occurence_Count (temp_statement, inst);
- s.Compose_If (cond, temp_statement);
- return count;
- }
- else if (s.Kind() == IF_ELSE)
- {
- object Statement temp_statement1, temp_statement2;
- object Integer cond;
- s.Decompose_If_Else (cond, temp_statement1, temp_statement2);
- count = Statement_Occurence_Count (temp_statement1, inst);
- count = count + Statement_Occurence_Count (temp_statement2, inst);
- s.Compose_If_Else (cond, temp_statement1, temp_statement2);
- return count;
- }
- else if (s.Kind() == WHILE)
- {
- object Integer cond;
- object Statement temp_statement;
- s.Decompose_While (cond, temp_statement);
- count = Statement_Occurence_Count (temp_statement, inst);
- s.Compose_While (cond, temp_statement);
- return count;
- }
- else // Call statement
- {
- object Integer temp_inst;
- s.Decompose_Call (temp_inst);
- if (temp_inst == inst)
- {
- count = count + 1;
- }
- s.Compose_Call (temp_inst);
- }
- }
Add Comment
Please, Sign In to add comment