Enhancing Program Comprehension with recovered State Models Stphane

  • Slides: 12
Download presentation
Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C. Lethbridge SITE,

Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C. Lethbridge SITE, University of Ottawa 1

State Transition Models can help program comprehension n High-level behavior models Capture design decisions

State Transition Models can help program comprehension n High-level behavior models Capture design decisions Mapped to code n n n 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 2

State implementation idioms n Non-procedural languages n n Procedural (non-OO) languages n n n

State implementation idioms n Non-procedural languages n n Procedural (non-OO) languages n n n Based on goto Based on control structures (if, switch, …) Table lookup Object-oriented languages n Dynamic binding 3

Procedural idioms (1) State variable definition n change of a state variable void strans()

Procedural idioms (1) State variable definition n change of a state variable void strans() { …. State = state 1; /* initial state */ while(1) { switch(event) { case event. A: if (State == state 1) a_1(); else a_2(); break; case event. B: if (State == state 1) { b_1(); State = state 2; …. } } 4

Procedural idioms (2) void event. A() { switch(State) { case state 1: a_1(); break;

Procedural idioms (2) void event. A() { switch(State) { case state 1: a_1(); break; case state 2: a_2(); break; default: /* error */ exit(0); } } void event. B() { switch(State) { case state 1: b_1(); State = state 2; break; case state 2: b_2(); State = state 1; break; default: /* error */ exit(0); } } 5

State Model Recovery Process State Model Implementation Specification • Specifies how state model implemented

State Model Recovery Process State Model Implementation Specification • Specifies how state model implemented • State Variable Used • Routines (and source files) • Idiom 6

Statement Tree n Abstraction of parse tree n n n with relevant information only

Statement Tree n Abstraction of parse tree n n n with relevant information only Provide code layout Useful for dealing with statements affecting flow of execution 7

State Variable Definition Graph (SVDG) void strans() { (5) State = state 1; while(1)

State Variable Definition Graph (SVDG) void strans() { (5) State = state 1; while(1) { switch(event) { case event. A: if (State == state 1) a_1(); else a_2(); break; case event. B: if (State == state 1) { b_1(); (20) State = state 2; …. } } captures state variables control flow 8

State Transition Graph n States defined as <variable, value> n Transitions n n change

State Transition Graph n States defined as <variable, value> n Transitions n n change from a state to another events correspond to control structure conditions 9

Multiple routines (1) Generate partial models (2) combine 10

Multiple routines (1) Generate partial models (2) combine 10

SRecovers state models given state implementation specifications How to find a Specification ? Traditional

SRecovers state models given state implementation specifications How to find a Specification ? Traditional code exploration 11

Conclusion n Supporting additional patterns n n table based implementation OO state patterns Dealing

Conclusion n Supporting additional patterns n n table based implementation OO state patterns Dealing with multiple state variables Integration with code exploration tools 12