adaslicer: an ada program slicer

24
AdaSlicer: An Ada Program AdaSlicer: An Ada Program Slicer Slicer Ricky E. Sward Department of Computer Science USAF Academy, CO [email protected] A.T. Chamillard Computer Science Department University of Colorado Spring, CO [email protected]

Upload: dylan-potter

Post on 04-Jan-2016

17 views

Category:

Documents


1 download

DESCRIPTION

AdaSlicer: An Ada Program Slicer. Ricky E. Sward Department of Computer Science USAF Academy, CO [email protected]. A.T. Chamillard Computer Science Department University of Colorado Spring, CO [email protected]. Overview. Background Global Variables Identifying Globals - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: AdaSlicer:  An Ada Program Slicer

AdaSlicer: An Ada Program SlicerAdaSlicer: An Ada Program Slicer

Ricky E. SwardDepartment of Computer Science

USAF Academy, CO

[email protected]

A.T. ChamillardComputer Science Department

University of Colorado Spring, CO [email protected]

Page 2: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 3: AdaSlicer:  An Ada Program Slicer

BackgroundBackground

• Identifying global variables is well-defined • Discussed in programming language texts• Tools available to identify global variables• Useful to identify during re-engineering• In SPARK, globals are allowed, must annotate• Goal is to convert to parameters

Page 4: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 5: AdaSlicer:  An Ada Program Slicer

Global VariablesGlobal Variables

• In Ada, each variable must be declared• Scope defines where a variable is visible

• A and B are local variables

procedure Local is A : Integer := 0; B : Integer := 3; begin A := B * 2;end Local;

Page 6: AdaSlicer:  An Ada Program Slicer

Global VariablesGlobal Variables

• A non-local variable is defined outside scope• A global variable is non-local and also visible to

entire programprocedure Outer_Procedure is A : Integer := 0; procedure Inner_Procedure is B : Integer := 1; begin A := A + B; end Inner_Procedure;begin A := A + 1;end Outer_Procedure;

A is global

Page 7: AdaSlicer:  An Ada Program Slicer

Global VariablesGlobal Variables• A package variable is in package global scope • A package variable is a “good” global

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is begin X := X + 1; end Outera;end One_Global;

Package var X

Page 8: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 9: AdaSlicer:  An Ada Program Slicer

Identifying Global VariablesIdentifying Global Variables

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb (B : in out Integer) is begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(A); end Outera;end One_Global;

A is a parameter

Y is local

• Using static analysis consider the scope of variables • Ignore local variables and parameters

Page 10: AdaSlicer:  An Ada Program Slicer

Identifying Global VariablesIdentifying Global Variables• Using static analysis consider the scope of variables • Ignore local variables and parameters

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb (B : in out Integer) is begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(A); end Outera;end One_Global;

B is a parameter

X is global

Page 11: AdaSlicer:  An Ada Program Slicer

Identifying Global VariablesIdentifying Global Variables• Access declaration information in symbol table• Ok if package variable and procedure in outer scope

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb (B : in out Integer) is begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(A); end Outera;end One_Global;

Variable Scope Nesting

Y Outera 1

X One_Global 0

... ... ...

Symbol Table

Page 12: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 13: AdaSlicer:  An Ada Program Slicer

Annotating Global VariablesAnnotating Global Variables• One option in our tool is to add SPARK annotation

--# global <mode> <variable name>;

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb (B : in out Integer) is --# global in out X; begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(A); end Outera;end One_Global;

Page 14: AdaSlicer:  An Ada Program Slicer

package One_Global is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb (B : in out Integer) is --# global in out X; begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(A); end Outera;end One_Global;

Annotating Global VariablesAnnotating Global Variables

REF set: { B, X }

DEF set: { B, X }

• To determine mode of global, look at DEF and REF

Page 15: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 16: AdaSlicer:  An Ada Program Slicer

Re-engineering Global VariablesRe-engineering Global Variables• Add global as formal parameter• Add global as actual parameter in call• Use the global definition of the variable to build

the parameter• Use the DEF and REF set to build the mode

– Appears only in REF, build as “in” parameter– Appears only in DEF, build as “out” parameter– Appears in both DEF and REF, build as “in out” using

conservative approach

• For example...

Page 17: AdaSlicer:  An Ada Program Slicer

package One_Global_New is X : Integer := 10; procedure Outera (A : in out Integer);end One_Global;

package body One_Global_New is procedure Outera (A : in out Integer) is Y : Integer := 0; procedure Innerb ( B : in out Integer; X : in out Integer ) is begin B := X; X := X + 1; end Innerb; begin Y := A; Innerb(B => A, X => X); end Outera;end One_Global_New;

Re-engineering Global VariablesRe-engineering Global Variables

Add as formal

Add as actual

Page 18: AdaSlicer:  An Ada Program Slicer

Re-engineering Global VariablesRe-engineering Global Variables

• What if a global is nested deeper?• May need to change two or more procedures• Add global as formal parameter• Add global as actual parameter• Check to see if actual is global

• For example...

Page 19: AdaSlicer:  An Ada Program Slicer

package body Two_Globals is procedure Outera ( A : in out Integer ) is procedure Innerb ( B : in out Integer ) is procedure Innerc ( C : in out Integer ) is begin C := Y; Y := Y + 1; end Innerc; begin B := B + 1; Innerc(C => B); end Innerb; begin Innerb(B => A); end Outera;end Two_Globals;

Re-engineering Global VariablesRe-engineering Global Variables

Y is a global

Page 20: AdaSlicer:  An Ada Program Slicer

package body Two_Globals_new is procedure Outera ( A : in out Integer ) is procedure Innerb ( B : in out Integer) is procedure Innerc ( C : in out Integer; Y : in out Integer ) is begin C := Y; Y := Y + 1; end Innerc; begin B := B + 1; Innerc(C => B, Y => Y); end Innerb; begin Innerb(B => A); end Outera;end Two_Globals_new;

Re-engineering Global VariablesRe-engineering Global Variables

Y is a global

Need Y here

Page 21: AdaSlicer:  An Ada Program Slicer

package body Two_Globals_new is procedure Outera ( A : in out Integer ) is procedure Innerb ( B : in out Integer; Y : in out Integer) is procedure Innerc ( C : in out Integer; Y : in out Integer ) is begin C := Y; Y := Y + 1; end Innerc; begin B := B + 1; Innerc(C => B, Y => Y); end Innerb; begin Innerb(B => A, Y => Y); end Outera;end Two_Globals_new;

Re-engineering Global VariablesRe-engineering Global Variables

Add Y as formal

Add Y as actual

Add Y as formal

Add Y as actual

Page 22: AdaSlicer:  An Ada Program Slicer

OverviewOverview• Background• Global Variables• Identifying Globals• Annotating Globals• Re-engineering Globals• ASIS• Conclusions

Page 23: AdaSlicer:  An Ada Program Slicer

Ada Semantic Interface Specification Ada Semantic Interface Specification (ASIS)(ASIS)

• Procedures for accessing Ada program structure• Used ASIS 3.15a1 & GNAT Ada Compiler 3.15a1• Reasonable learning curve• Examples provided with ASIS are great• Very powerful tool

Page 24: AdaSlicer:  An Ada Program Slicer

ConclusionsConclusions

• Need to develop a graphical user interface• Target re-engineering efforts• Also automatic refactoring applications