1 Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C....

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

Transcript of 1 Enhancing Program Comprehension with recovered State Models Stéphane S. Somé Timothy C....

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

1

Enhancing Program Comprehension with

recovered State Models

Stéphane S. SoméTimothy C. Lethbridge

SITE, University of Ottawa

Page 2: 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

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

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

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

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

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

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); }}

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

6

State Model RecoveryProcess

State Model ImplementationSpecification• Specifies how state model implemented

• State Variable Used• Routines (and source files)• Idiom

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

7

Statement Tree

Abstraction of parse tree with relevant

information only Provide code

layout Useful for dealing

with statements affecting flow of execution

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

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

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

9

State Transition Graph

States defined as<variable,value>

Transitions change from a

state to another events correspond

to control structure conditions

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

10

Multiple routines(1) Generate partial models

(2) combine

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

11

SRecover

Recovers state models given state implementation specifications

How to find a Specification ?

Traditional code exploration

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

12

Conclusion Supporting additional patterns

table based implementation OO state patterns

Dealing with multiple state variables

Integration with code exploration tools