1 / 26

CASE/Re-factoring and program slicing

CASE/Re-factoring and program slicing. CASE tool construction. File level - programming environment Language level - program representation, compiling, testing

jalia
Download Presentation

CASE/Re-factoring and program slicing

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CASE/Re-factoringand program slicing COMP 319

  2. 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. COMP319

  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

  4. 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 COMP319

  5. Re-factor types • Encapsulate field public intgetLength() { return(length); } • Re-name method, field • String pw • - • String password COMP319

  6. Generalisation of type class Customer { }  class Person { } class Customer extends Person { } COMP319

  7. Code breaking up re-factors • Extract method void 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; } COMP319

  8. 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 COMP319

  9. 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”); COMP319

  10. 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 COMP319

  11. Example Program and its Dependence Graph COMP319

  12. Example Program and its Dependence Graph COMP319

  13. 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; • } COMP319

  14. 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 COMP319

  15. 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 COMP319

  16. 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;

  17. 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) ; COMP319

  18. Bug location with backward slicing while (!eof()) { TotalMarks = 0;scanf("%d",Marks); Count = Count + 1;TotalMarks = TotalMarks+Marks;}average = TotalMarks/Count;printf("The average was %d\n",average) ; COMP319

  19. 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++ ; COMP319

  20. 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 %d\n",sum) ;printf("The product is %d\n",product) ;printf("The average is %d\n",average) ; COMP319

  21. Maintenance – backward slice sum = 1;scanf("%d",&x) ;while (x >= 0) { sum = sum + x; scanf("%d",&x);}printf("The total is %d\n",sum) ; COMP319

  22. 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 %d\n",sum) ; /* AFFECTED */printf("The product is %d\n",product) ;printf("The average is %d\n",average) ; /* AFFECTED */ COMP319

  23. 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 COMP319

  24. 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 COMP319

  25. 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 COMP319

  26. 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 COMP319

More Related