Presentation is loading. Please wait.

Presentation is loading. Please wait.

R O O T S Conditional Transformations Fabian Noth

Similar presentations


Presentation on theme: "R O O T S Conditional Transformations Fabian Noth"— Presentation transcript:

1 R O O T S Conditional Transformations Fabian Noth

2 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 2 R O O T S What are Conditional Transformations? Combining analysis and transformations on programs (nearly) every transformation requires an analysis Based on logic Program as logic factbase Uniformity Independecy from underlying system (e.g. java source code) Complex sequences Combination of simple CT

3 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 3 R O O T S Source codeFactbase Program as logic factbase class A { public int a; private double b; float c; void m(int i) { m(i); } class B { public int j; private int k; public boolean b; } classT(1,0,'A',[2,3,4,5]) fieldT(2,1,int,'a') modifierT(2, public') fieldT(3,1,double,'b') modifierT(3, 'private') fieldT(4,1,float,'c') modifierT(4, 'package') methodT(5,1,'m',[6],void, 7) paramT(6,5,int,'i') blockT(7,5)... classT(12,0,'B',[13,14,15]) fieldT(13,12,int,'j') modifierT(13, 'public') fieldT(14,12,int,'k') modifierT(14, 'private') fieldT(15,12,boolean,'b') modifierT(15, 'public')

4 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 4 R O O T S Conditional Transformation Program as logic factbase Evaluate if the condition is true Analysing the factbase Propagation of valid substitutions (IDs) Creation of missing IDs Propagation of all required IDs for Transformation Changing the factbase Transformation ID-Creation Condition

5 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 5 R O O T S Example: copyFields 1 ct( copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField), 2 condition ( ( 3 fieldT(SrcField, SrcClass, Ftype, Fname, _), 4 not( fieldT(_,TargetClass, _, Fname, _) ), 5 modifierT(SrcField, Mod) 6 ) ), 7 idcreation ( ( 8 new_node_id(TargetField) 9 ) ), 10 transformation ( ( 11 add(fieldT(TargetField, TargetClass, Ftype, Fname, null)), 12 add(modifierT(TargetField, Mod)), 13 add_to_class(TargetClass, TargetField) 14 )) 15 ). Transformation ID-Creation Condition

6 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 6 R O O T S ConditionFactbase Evaluating the condition Substitution Set SrcClassTarget Class SrcFieldFtypeFnameMod 1122intapublic 1124floatcpackage classT(1,0,'A',[2,3,4,5]) fieldT(2,1,int,'a') modifierT(2, public') fieldT(3,1,double,'b') modifierT(3, 'private') fieldT(4,1,float,'c') modifierT(4, 'package')... classT(12,0,'B',[13,14,15]) fieldT(13,12,int,'j') modifierT(13, 'public') fieldT(14,12,int,'k') modifierT(14, 'private') fieldT(15,12,boolean,'b') modifierT(15, 'public') condition ( ( fieldT(SrcField,SrcClass, Ftype, Fname, _), not( fieldT(_,TargetClass, _, Fname, _) ), modifierT(SrcField, Mod) ) ), Input: SrcClass = 1, TargetClass = 12

7 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 7 R O O T S ID-Creation No unbound variables are allowed in the transformation Variables which are not bound in the condition have to be bound in the ID-Creation new_node_id(Var) -Command Creates new, unique ID Binds variable Var to this ID For each substitution skip -Command If all variables are bound in the condition TargetField idcreation ( ( new_node_id(TargetField) )... +

8 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 8 R O O T S Transformation Transformation = Combination of: add delete replace Prolog predicates (e.g add_to_class ) transformation ( ( add(fieldT(TargetField, TargetClass, Ftype, Fname, null)), add(modifierT(TargetField, Mod)), add_to_class(TargetClass, TargetField) ))... classT(12,0,'B',[13,14,15])... classT(12,0,'B',[13,14,15, 16, 17]) fieldT(16,12,int,'a') modifierT(16, public') fieldT(17,12,float,'c') modifierT(17, 'package')...

9 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 9 R O O T S Blackbox 1 ct( copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField), 2 condition ( ( 3 fieldT(SrcField, SrcClass, Ftype, Fname, _), 4 not( fieldT(_,TargetClass, _, Fname, _) ), 5 modifierT(SrcField, Mod) 6 ) ), 7 idcreation ( ( 8 new_node_id(TargetField) 9 ) ), 10 transformation ( ( 11 add(fieldT(TargetField, TargetClass, Ftype, Fname, null)), 12 add(modifierT(TargetField, Mod)), 13 add_to_class(TargetClass, TargetField) 14 )) 15 ). Transformation ID-Creation Condition copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField)

10 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 10 R O O T S Blackbox copyField i-1 i

11 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 11 R O O T S Sequences Copy all possible fields Encapsulate all possible fields No matter if it is a copied field or not ctseq( copyAndEncapsulateFields_Or(SrcClass,SrcField,TargetClass,TargetField), orseq( ct(copyField(SourceClass,SourceField,FType,Fname,TargetClass,TargetField)), ct(encapsulateField(SourceField)) ) ). i-1 Copy i Encapsulate i+1

12 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 12 R O O T S Sequences Copy all fields Encapsulate only copied fields ctseq( copyAndEncapsulateFields_Prop(SrcClass,SrcField,TargetClass,TargetField), propseq( ct(copyField(SourceClass,SourceField,FType,Fname,TargetClass,TargetField)), ct(encapsulateField(SourceField)) ) ). i-1 Copy Encapsulate i+1 i

13 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 13 R O O T S Sequences Copy only encapsulatable fields Encapsulate only copied fields ctseq( copyAndEncapsulateFields_And(SrcClass,SrcField,TargetClass,TargetField), andseq( ct(copyField(SourceClass,SourceField,FType,Fname,TargetClass,TargetField)), ct(encapsulateField(SourceField)) ) ). i-1 Copy i Encapsulate i+1 Undo Copy negprop

14 Modellbasierte Softwareanalyse, 2010/2011Conditional Transformations 14 R O O T S CTs in Action CT-Example in Eclipse Copy fields Example for use of sequences


Download ppt "R O O T S Conditional Transformations Fabian Noth"

Similar presentations


Ads by Google