120 likes | 128 Views
Enhancing Program Comprehension with recovered State Models. Stéphane S. Somé Timothy C. Lethbridge SITE, University of Ottawa. State Transition Models can help program comprehension. High-level behavior models Capture design decisions Mapped to code
E N D
Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C. Lethbridge SITE, University of Ottawa
State Transition Models can help program comprehension • High-level behavior models • Capture design decisions • Mapped to code • Strong connection between resulting code and state model • Highlighted by use of state implementation idioms • Problem: what if the original state model is lost or has-been altered
State implementation idioms • Non-procedural languages • Based on goto • Procedural (non-OO) languages • Based on control structures (if, switch, …) • Table lookup • Object-oriented languages • Dynamic binding
Procedural idioms (1) void strans() { …. State = state1; /* initial state */ while(1) { switch(event) { case eventA: if (State == state1) a_1(); else a_2(); break; case eventB: if (State == state1) { b_1(); State = state2; …. } } State variable definition • change of a state variable
Procedural idioms (2) void eventB() { switch(State) { case state1: b_1(); State = state2; break; case state2: b_2(); State = state1; break; default: /* error */ exit(0); } } void eventA() { switch(State) { case state1: a_1(); break; case state2: a_2(); break; default: /* error */ exit(0); } }
State Model Recovery Process • State Model Implementation • Specification • Specifies how state model implemented • State Variable Used • Routines (and source files) • Idiom
Statement Tree • Abstraction of parse tree • with relevant information only • Provide code layout • Useful for dealing with statements affecting flow of execution
State Variable Definition Graph (SVDG) void strans() { (5) State = state1; while(1) { switch(event) { case eventA: if (State == state1) a_1(); else a_2(); break; case eventB: if (State == state1) { b_1(); (20) State = state2; …. } } captures state variables control flow
State Transition Graph • States defined as <variable,value> • Transitions • change from a state to another • events correspond to control structure conditions
Multiple routines (1) Generate partial models (2) combine
SRecover Recovers state models given state implementation specifications How to find a Specification ? Traditional code exploration
Conclusion • Supporting additional patterns • table based implementation • OO state patterns • Dealing with multiple state variables • Integration with code exploration tools