CASEREFACTORING AND PROGRAM SLICING COMP 319 University of
- Slides: 26
CASE/RE-FACTORING AND PROGRAM SLICING COMP 319 © University of Liverpool slide 1
CASE tool construction • File level - programming environment • Language level - program representation, compiling, testing • Work flow level - stages in the software engineering process itself: specification, design, development, verification, validation, management. COMP 319 © University of Liverpool slide 2
Slide 3 Program Language Level Tool construction at the language level exploits form – which is usually either: • Grammar – to capture the notion of text based instructions • Graph – to deal with the concept of sequence COMP 319 Software Engineering II
Refactoring • Why CASE? - not alter functionality (must be correct) - cover all instances (i. e. be complete) - Keep code tidy and to standard format - Be quick COMP 319 © University of Liverpool slide 4
Re-factor types • Encapsulate field public int get. Length() { return(length); } • Re-name method, field • String pw • - • String password COMP 319 © University of Liverpool slide 5
Generalisation of type class Customer { } class Person { } class Customer extends Person { } COMP 319 © University of Liverpool slide 6
Code breaking up re-factors • Extract method void set. Length(int length) { if (length<0) { throw (new Bad. Argument. Exception()); } this. length=length; } void validate. Length(int length) { if (length<0) { throw (new Bad. Argument. Exception()); } } void set. Length(int length) { validate. Length(length); this. length=length; } COMP 319 © University of Liverpool slide 7
Graphs • • • A diagram depicting a network Points at the end of arcs Nodes at the junction of arcs Regions enclosed by arcs Used for representing: - Solid figures (vertices, edges, faces) - Electrical circuits - Relationships between entities • Graph or network theory COMP 319 © University of Liverpool slide 8
Dependence graphs • All computing systems have dependencies • Control dependence - 1 method calling another • Data dependence - 1 expression effecting another - A=B*2 - C=A*4 • Control/data dependence - If (age<=18) { println(“Age invalid”); COMP 319 © University of Liverpool slide 9
Program dependency graphs • Term appears in a paper by Kuck, Muraoka & Chen (1981) although the idea is in Turing’s early description of “algorithms” in 1936 • Captures sequence/time between entities (compare connection/distance) • Control Dependence • Data Dependence COMP 319 © University of Liverpool slide 10
Example Program and its Dependence Graph COMP 319 © University of Liverpool slide 11
Example Program and its Dependence Graph COMP 319 © University of Liverpool slide 12
Dependency graph usage • Optimisation - Multiple independent statements can run in parallel - Code that never runs can be removed - Boolean skip=true; - If (!skip) then - Loop invariance - For (k=1; k<max_items; k++) { - sum=sum+a*b; -} COMP 319 © University of Liverpool slide 13
Program slicing • Interactive method for - Debugging - Program understanding - Program maintenance • Program reduction technique (highlighter) • A demonstration of SDG allowing: - Control flow analysis - Data flow analysis COMP 319 © University of Liverpool slide 14
How does it work • Choose v a variable or set of variables • Choose n a point of interest • Using the dependence graph the slice v at n is constructed • The slice v at n can be compiled and studied separately • Slices may be forward or backward from n COMP 319 © University of Liverpool slide 15
Backward Slicing Original program x = 1; y = 2; z = y-2; r = x; z = x+y; /* the slice point is the end of the program */. Backward Slice x = 1; y = 2; z = x+y;
Debugging with a slice Pass = 0 ; Fail = 0 ; Count = 0 ; while (!eof()) { Total. Marks=0; scanf("%d", Marks); if (Marks >= 40) Pass = Pass + 1; if (Marks < 40) Fail = Fail + 1; Count = Count + 1; Total. Marks = Total. Marks+Marks ; } printf("Out of %d, %d passed and %d failedn", Count, Pass, Fail) ; average = Total. Marks/Count; /* point of interest */ printf("The average was %dn", average) ; Pass. Rate = Pass/Count*100 ; printf("This is a pass rate of %dn", Pass. Rate) ; COMP 319 © University of Liverpool slide 17
Bug location with backward slicing while (!eof()) { Total. Marks = 0; scanf("%d", Marks); Count = Count + 1; Total. Marks = Total. Marks+Marks; } average = Total. Marks/Count; printf("The average was %dn", average) ; COMP 319 © University of Liverpool slide 18
Forward Slicing Original program x = 1; /* considering changing this line */ y = 3; p = x + y ; z = y -2 ; if(p==0) r++ ; Forward Slice /* Change to first line will affect */ p = x + y ; if(p==0) r++ ; COMP 319 © University of Liverpool slide 19
Maintenance - Example n = 0; product = 1; sum = 1; scanf("%d", &x) ; while (x >= 0) { sum = sum + x; product = product * x ; n = n + 1; scanf("%d", &x); } average = (sum - 1) / n ; printf("The total is %dn", sum) ; printf("The product is %dn", product) ; printf("The average is %dn", average) ; COMP 319 © University of Liverpool slide 20
Maintenance – backward slice sum = 1; scanf("%d", &x) ; while (x >= 0) { sum = sum + x; scanf("%d", &x); } printf("The total is %dn", sum) ; COMP 319 © University of Liverpool slide 21
Maintenance – forward slice n = 0; product = 1; sum = 0; scanf("%d", &x) ; while (x >= 0) { sum = sum + x; /* AFFECTED */ product = product * x ; n = n + 1; scanf("%d", &x); } Average = (sum - 1) / n ; /* AFFECTED */ printf("The total is %dn", sum) ; /* AFFECTED */ printf("The product is %dn", product) ; printf("The average is %dn", average) ; /* AFFECTED */ COMP 319 © University of Liverpool slide 22
Types of slicing • Static – described above. Slices are constructed at compile time • Dynamic slicing where slices are constructed once the input is known • Conditional slicing done at breakpoints during execution • Inter-modular slicing - complex systems COMP 319 © University of Liverpool slide 23
The Horowitz, Prins, & Rep (HPR) algorithm (merging) • Step 1. Determine changed and preserved slices e. g. adding a diameter calculation • Step 2. Form the merged graph. Using the idea of ‘graph union’ • Step 3. Test for interference i. e the merged graph preserves all the slices of all the variants. • Step 4. Construct source from the merged graph COMP 319 © University of Liverpool slide 24
• Why richer constructs? - More useful slicing • SDG and inter-module slicing - SDG from parse trees - Other methods of generating an SDG - Calls and variable scope handling • Pointers, aliases, classes COMP 319 © University of Liverpool slide 25
JSlice • Java slicing software developed by National University of Singapore • Performs dynamic slicing • Uses a compressed trace which records - Flow control instructions - Data manipulation • JVM - Kaffe - Clean room implementation of Java COMP 319 © University of Liverpool slide 26
- Program slicing tool
- Jkeyword planner
- Matthew v. eldridge
- Prevaricação crime
- Prevaricação crime
- Art. 319 cp
- Cpsc 319
- Cpsc 319 u of c
- Cwa 319
- 87,539,319 = 2283 + _ _ _ 3
- Hsci 319
- Polyder matlab
- Breadth and depth
- Me 319
- Pc 319
- Slicing and dicing in cognos
- Rgb
- Slicing and dicing in olap
- Network slicing simulator
- Network slicing nssai
- Intensity slicing in digital image processing
- Color slicing in digital image processing
- Color slicing in digital image processing
- Chapter 16 milady
- Java array slicing
- Slicing
- Network slicing with segment routing