Upload
jalia
View
18
Download
0
Tags:
Embed Size (px)
DESCRIPTION
CASE/Re-factoring and program slicing. CASE tool construction. File level - programming environment Language level - program representation, compiling, testing - PowerPoint PPT Presentation
Citation preview
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.
© University of LiverpoolCOMP319 slide 2
COMP319 Software Engineering II
Slide 3
Program Language Level
• Grammar – to capture the notion of text based instructions
• Graph – to deal with the concept of sequence
Tool construction at the language level exploits form – which is usually either:
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
© University of LiverpoolCOMP319 slide 4
Re-factor types
• Encapsulate field
public int getLength() { return(length);}
• Re-name method, field• String pw• - • String password
© University of LiverpoolCOMP319 slide 5
Generalisation of type
class Customer {}
class Person {}class Customer extends Person {}
© University of LiverpoolCOMP319 slide 6
Code breaking up re-factors• Extract methodvoid setLength(int length) { if (length<0) { throw (new BadArgumentException()); } this.length=length;}void validateLength(int length) { if (length<0) { throw (new BadArgumentException()); }}void setLength(int length) { validateLength(length); this.length=length;}
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 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”);
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 slide 10
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;- }
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 slide 15
Backward Slicing
x = 1;y = 2; z = y-2; r = x; z = x+y; /* the slice point is the end of the program */.
x = 1;y = 2;z = x+y;
Original program
Backward Slice
Debugging with a slice
Pass = 0 ; Fail = 0 ; Count = 0 ;while (!eof()){ TotalMarks=0; scanf("%d",Marks); if (Marks >= 40) Pass = Pass + 1; if (Marks < 40) Fail = Fail + 1; Count = Count + 1; TotalMarks = TotalMarks+Marks ;}printf("Out of %d, %d passed and %d failed\n", Count, Pass, Fail) ;average = TotalMarks/Count; /* point of interest */printf("The average was %d\n",average) ;PassRate = Pass/Count*100 ;printf("This is a pass rate of %d\n",PassRate) ;
© University of LiverpoolCOMP319 slide 17
Bug location with backward slicingwhile (!eof()) { TotalMarks = 0; scanf("%d",Marks); Count = Count + 1; TotalMarks = TotalMarks+Marks;}average = TotalMarks/Count;printf("The average was %d\n",average) ;
© University of LiverpoolCOMP319 slide 18
© University of LiverpoolCOMP319 slide 19
Forward Slicing
x = 1; /* considering changing this line */y = 3;p = x + y ;z = y -2 ;if(p==0)r++ ;
Original program
Forward Slice
/* Change to first line will affect */p = x + y ;if(p==0)r++ ;
Maintenance - Example
© University of LiverpoolCOMP319 slide 20
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 %d\n",sum) ;printf("The product is %d\n",product) ;printf("The average is %d\n",average) ;
Maintenance – backward slice
© University of LiverpoolCOMP319 slide 21
sum = 1;scanf("%d",&x) ;while (x >= 0) { sum = sum + x; scanf("%d",&x);}printf("The total is %d\n",sum) ;
Maintenance – forward slicen = 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 %d\n",sum) ; /* AFFECTED */printf("The product is %d\n",product) ;printf("The average is %d\n",average) ; /* AFFECTED */
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 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
© University of LiverpoolCOMP319 slide 25