1 / 13

# Conditional Transformations - PowerPoint PPT Presentation

Conditional Transformations. Fabian Noth [email protected] What are Conditional Transformations ?. Combining analysis and transformations on programs ( nearly ) every transformation requires an analysis Based on logic Program as logic factbase Uniformity

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' Conditional Transformations' - xiu

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Conditional Transformations

Fabian Noth

WhatareConditionalTransformations?

• Combininganalysisandtransformations on programs

• (nearly) everytransformationrequires an analysis

• Based on logic

• Program aslogicfactbase

• Uniformity

• Independecyfromunderlyingsystem (e.g. javasourcecode)

• Complexsequences

• Combinationof simple CT

Program aslogicfactbase

Source code

Factbase

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')

class A {

publicint a;

private double b;

float c;

void m(int i)

{

m(i);

}

}

class B {

publicint j;

private int k;

publicboolean b;

}

Conditional Transformation

• Program aslogicfactbase

• Evaluateiftheconditionistrue

• Analysingthefactbase

• Propagation of valid substitutions (IDs)

• Creationofmissing IDs

• Propagation of all required IDs for Transformation

• Changingthefactbase

Condition

ID-Creation

Transformation

Example: copyFields

1ct( copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField),

2condition( (

3fieldT(SrcField, SrcClass, Ftype, Fname, _),

4 not( fieldT(_,TargetClass, _, Fname, _) ),

5modifierT(SrcField, Mod)

6 ) ),

7idcreation( (

8new_node_id(TargetField)

9 ) ),

10transformation( (

14 ))

15 ).

Condition

ID-Creation

Transformation

Evaluatingthecondition

Condition

Factbase

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')

Input: SrcClass = 1, TargetClass = 12

condition( (

fieldT(SrcField,SrcClass, Ftype, Fname, _),

not( fieldT(_,TargetClass, _, Fname, _) ),

modifierT(SrcField, Mod)

) ),

• Substitution Set

ID-Creation

• Nounbound variables areallowed in thetransformation

• Variables whichare not bound in theconditionhavetobebound in the ID-Creation

• new_node_id(Var)-Command

• Createsnew, unique ID

• Binds variable Vartothis ID

• Foreachsubstitution

• skip-Command

• If all variables arebound in thecondition

idcreation( (

new_node_id(TargetField)

) )

+

• Transformation = Combinationof:

• delete

• replace

transformation( (

))

...

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')

...

1ct( copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField),

2condition( (

3fieldT(SrcField, SrcClass, Ftype, Fname, _),

4 not( fieldT(_,TargetClass, _, Fname, _) ),

5modifierT(SrcField, Mod)

6 ) ),

7idcreation( (

8new_node_id(TargetField)

9 ) ),

10transformation( (

14 ))

15 ).

copyField( SrcClass, SrcField, Ftype, Fname, TargetClass, TargetField)

Condition

ID-Creation

Transformation

i-1

i

copyField

ctseq(

copyAndEncapsulateFields_Or(SrcClass,SrcField,TargetClass,TargetField),

orseq(

ct(copyField(SourceClass,SourceField,FType,Fname,TargetClass,TargetField)),

ct(encapsulateField(SourceField))

)

).

• Copy all possiblefields

• Encapsulate all possiblefields

• No matter ifitis a copiedfieldor not

i-1

i+1

Copy

Encapsulate

i

ctseq(

copyAndEncapsulateFields_Prop(SrcClass,SrcField,TargetClass,TargetField),

propseq(

ct(copyField(SourceClass,SourceField,FType,Fname,TargetClass,TargetField)),

ct(encapsulateField(SourceField))

)

).

• Copy all fields

• Encapsulateonlycopiedfields

i-1

i+1

Copy

Encapsulate

i

• CT-Example in Eclipse

• Copyfields

• Exampleforuseofsequences