1 Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C....
-
Upload
clifton-west -
Category
Documents
-
view
213 -
download
0
Transcript of 1 Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C....
1
Enhancing Program Comprehension with
recovered State Models
Stéphane S. SoméTimothy C. Lethbridge
SITE, University of Ottawa
2
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
3
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
4
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
5
Procedural idioms (2)
void eventA(){ switch(State) { case state1: a_1(); break; case state2: a_2(); break; default: /* error */ exit(0); }}
void eventB(){ switch(State) { case state1: b_1(); State = state2; break; case state2: b_2(); State = state1; break; default: /* error */ exit(0); }}
6
State Model RecoveryProcess
State Model ImplementationSpecification• Specifies how state model implemented
• State Variable Used• Routines (and source files)• Idiom
7
Statement Tree
Abstraction of parse tree with relevant
information only Provide code
layout Useful for dealing
with statements affecting flow of execution
8
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; …. } }
capturesstate variables control flow
9
State Transition Graph
States defined as<variable,value>
Transitions change from a
state to another events correspond
to control structure conditions
10
Multiple routines(1) Generate partial models
(2) combine
11
SRecover
Recovers state models given state implementation specifications
How to find a Specification ?
Traditional code exploration
12
Conclusion Supporting additional patterns
table based implementation OO state patterns
Dealing with multiple state variables
Integration with code exploration tools