a calculus of untyped aspect-oriented programs paper by radha jagadeesan alan jeffrey james riely...

71
A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Post on 22-Dec-2015

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Calculus of Untyped Aspect-Oriented Programs

Paper byRadha

JagadeesanAlan JeffreyJames Riely

Presented byShay Cohen

Page 2: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 3: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction - example

Aspects have emerged as a powerful tool

For example:

Page 4: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction - intended

execution

The intended execution semantics is as follows: a call to foo() invokes the code

associated with the advice (the timer is started)

foo() method is invoked when control reaches proceed()

Upon termination of foo(), control returns to the advice

Page 5: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction - Example

public aspect WeavingAspect {

before (String s): execution(void go(*)) && args(s){

System.out.println("before (String s): execution(void go(*)) && args(s) " + s); }

before (Object s): execution(void go(*)) && args(s){

System.out.println("before (Object s): execution(void go(*)) && args(s) " + s); }

}

Page 6: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction- Problem

public class WeavingObject {

public static void main(String[] args) {WeavingObject obj = new

WeavingObject();

String s = null; obj.go(s);

System.out.println();

s = new String("String");obj.go(s);

}

public void go(Object s) {System.out.println("go(Object s) "

+ s); }

}

before (Object s): execution(void go(*)) && args(s) nullgo(Object s) null

before (String s): execution(void go(*)) && args(s) Stringbefore (Object s): execution(void go(*)) && args(s) Stringgo(Object s) String

Page 7: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction- Conclusion

Knowing the aspects semantics is essential.

One cannot naively extend object-oriented reasoning to aspect-oriented programs.

Page 8: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Introduction Reductionism and a specification for

weaving: Advice looked as a primitive Only around advice No reflection Focusing on dynamics

At the end correctness of the weaving transformation will be shown

Weavability will be defined to exclude programs that cannot be woven statically

Page 9: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 10: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language - Program

'P P

Transformation of a program

( )D HT

D

H

A program P has the form

is a set of declarations is a set of heap allocated threads and objects.

Page 11: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – class, thread (table 1)

thrd p{new class c<:d {...};} class c<:d {...}

thrd p{ }

class c<:d {...m(x) {C}...}============= =

Superclass dA set of method declarations

thrd p{S}Controlling object pStack S

Page 12: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – object (table 1)

obj o:c {... f =v ...} obj o:c {... f =v ...}

thrd p{let x=o.f;} thrd p{let x=v;}

obj o:c {... f =v ...}Actual class of the objectValue of fields

obj o:c {... f =u...} obj o:c {... f =v ...}

thrd p{set o.f =v;} thrd p{}

Page 13: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – Syntax (table 1)

Page 14: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language cont.

Method calls may be dispatched dynamic type static type

let x=o.m(v)

let x=o.c::m(v)

Page 15: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 16: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – Reduction

Reduction proceeds via a standard substitution of parameters

Page 17: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language –Reduction example

c

c

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

(R

-

VAL) th

thrd p{l

rd p{let x=p{let y=p.f; set p.

et x

f=b;

=p.m(b);

return )

}

y

(

c

c

c

c

;};}

(R -GET) thrd p{let x=p{let y=a; set p.f=b; return (y);};}

(R -VAL) thrd p{let x=p{set p.f=b; return (a);};}

(R -SET) thrd p{let x=p{return (a);};}

(R -RET

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=a}

Page 18: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language –Dynamic message (table 2)

c

c

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return

(R -VAL) thrd p{let

(y);}

x=p{le

thrd p{let

t y=p.f; se

;}

t

x=p.m(b

p.f=b;

);

re

tu y

}

rn ( )

c

c

c

c

;};}

(R -GET) thrd p{let x=p{let y=a; set p.f=b; return (y);};}

(R -VAL) thrd p{let x=p{set p.f=b; return (a);};}

(R -SET) thrd p{let x=p{return (a);};}

(R -RET

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=a}

Page 19: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language –Value (table 2)

c

c

thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

(R -VAL)

thrd p{let x

thrd p{let

=p.m(b);}

(

x=p{let y=p.f; set p.f=b; return (y

R -DY

)

N-MSG)

c

c

c

c

(R -GET) thrd p{let x=p{let y=a; set p.f=b; return (y);};}

(R -VAL) thrd p{let x=p{set p.f=b; return (a);};}

(R -SET) thrd p{let x=p{return (a);}

;}

(R -RE

}

T

;};

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=a}

Page 20: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language –Get (table 2)

c

c

thrd p{let x=p.m(b);}

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

thrd p{let x=p{let y=p.f; set p. f= (R -VAL b; return )) (y

c

c

c

c

(R -VAL) thrd p{let x=p{set p.f=b

(R -GET) thrd p{let x=p{

; return (a);};}

(

;};

R -SET

let y=a; se

) thrd p

t p.f=b; return (y

{let x=p{return (a

);};}

);};}

(

R

RE

}

- T

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=a}

Page 21: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – Set (table 2)

c

c

thrd p{let x=p.m(b);}

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

(R -VAL) thrd p{let x

=p{let y=p.f; set p.f=b; retu

)

rn (y

c

c

c

c thrd p{let

;};}

x=p{set p.f=b;

(R -GET) thrd p{let x=p{let

return (a);};}

(R

y=a

-S

; set p.f=b; ret

ET) thrd p{le

urn (y);};

t x=p{retu

}

rn (a);};

}

(R -V

(R R T

A )

E

L

-

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=b}

Page 22: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language –Return (table 2)

c

c

thrd p{let x=p.m(b);}

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

(R -VAL) thrd p{let x=p{let y=p.f; set p.f=b; return (y)

c

c

c

c

;};}

(R -GET) thrd p{let x=p{let y=a; set p.f=b; return (y);};}

(R -VAL) thrd p{let x=p{set p.f=b; return (a);};}

(R thrd p{let x=p{return (a);};

-SET)

(R ET

}

-R

c

URN) thrd

(R -VAL)

p{let x=a

th {}

;}

rd p

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=b}

Page 23: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language -Reduction

c

c

thrd p{let x=p.m(b);}

(R -DYN-MSG) thrd p{let x=p{let z=b; let y=p.f; set p.f=z; return (y);};}

(R -VAL) thrd p{let x=p{let y=p.f; set p.f=b; return (y)

c

c

c

c

;};}

(R -GET) thrd p{let x=p{let y=a; set p.f=b; return (y);};}

(R -VAL) thrd p{let x=p{set p.f=b; return (a);};}

(R -SET) thrd p{let x=p{return (a);};}

(R -RET

c

URN) thrd p{let x=a;}

(R -VAL) thrd p{}

class d <: Object {m(x) {let z=x; let y=p.f; set p.f=z; return (y);}}

obj p:d{f=b}

Page 24: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – This, Super (table 2)

(L -THIS)c

D class c<: _ {M, m(x) {C}}

D body(c::m) = (x)C

============= =

============= =T

(R -SUPER)c

D class c<:d {M}

M m(_) {_}

D body(d::m) = (x)C

D body(c::m) = (x)C

============= =

============= =T

Page 25: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

A Class-based Language – Reduction summary

Rules Usage

(RC-LET), (RC-RETURN) and (RC-GARBAGE)

Deal with pushed frames

(RC-VALUE) Returned values to be substituted

(RC-DEC) and (RC-HEAP) Create new classes, objects and threads

(RC-GET) and (RC-SET) Manipulation of fields

(RC-DYN-MSG) and (RC-STC-MSG) Reduction on method calls

(LC-THIS) Method body to be retrieved

(LC-SUPER) Looks for a method in the superclass

Page 26: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 27: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Example

Advised message

Page 28: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Aspect declaration (table 3)

adv a(x): {C}============= =

Aspect declaration Name – allows reference Command sequence – what to

execute Pointcut – when to execute

pointcuts are presented as elements of the Boolean algebra

Page 29: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Advice (table 3)

Advised method call Call advice set Execution advice set

let x=o.m[a ; b](v)

ab

let x=proceed(v);

Advice body new command

Page 30: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – method (table 3)

Dynamically dispatched method changed We now have the static type as well Static type is needed for call advice

We ignore call advice for super calls

let x=o:c.m(v)

Page 31: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Advice creation

Given a method definition

class d <:c {...m(x) {C}...}============= =

class d <:c {...m[ ; cbl_d_m]...}

adv cbl_d_m(x):exec(d::m) {C[proceed/super.m]}

============= =

methods in the aspect calculus do not have any method bodies:

Page 32: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Aspect based syntax (table 3)

Page 33: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Semantics of pointcuts (table 4)

(S-EXTENDS)

D class c<:d {_}

D c<:d

(S-REFLEX)

D c<:c T

(S-TRANS)

D c<:d

D d <:e

D c<:e

Page 34: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Semantics of pointcuts (table 4)

(PC-EXEC)

D c<:d

D c::m execadv(exec(d::m))

(PC-CALL)

D c<:d

D c::m calladv(call(d::m))

Page 35: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Semantics of pointcuts (table 4)

Page 36: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Semantics of pointcuts (table 4)

Page 37: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen
Page 38: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 39: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Reduction example

A

A

A

(R -DYN-MSG) thrd p{let x=o.m[ca ; cb]();}

(R -ADV-MSG2) thrd p{let x=p

{let y=o.m[ ; cb]();return

();

thrd p{let x=o:c.m();}

};}

(R -ADV-MSG1) thrd p{let x=p

A

A

A

A

{let y=o{return ();};return ();};}

(R -RETURN) thrd p{let x=p{let y=();return ();};}

(R -VAL) thrd p{let x=p{return ();};}

(R -RETURN) thrd p{let x=();}

(R -VAL) th

rd p{}

obj p:Main {}

class Main{m[ ; ma]}

adv ma():exec(Main::m) {let x=o:c.m();return ();}

obj o:c {}

class c{m[ca ; cb]}

adv ca():call(c::m) {let y=proceed();return ();}

adv cb():exec(c::m) {return ();}

Page 40: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Dynamic message (table 5)

A

A

A

(R -DYN-MSG) thrd p{let x=o.m[ca ; cb]

(R -ADV-MSG2) thrd p{l

thr

et

x=p{let y=o.m[ ; cb]();return ()

d p

;};

{let x

}

(R -

ADV-

=o:c.m(

MSG1) thrd p{let x

();

=

}

p

);}

A

A

A

A

{let y=o{return ();};return ();};}

(R -RETURN) thrd p{let x=p{let y=();return ();};}

(R -VAL) thrd p{let x=p{return ();};}

(R -RETURN) thrd p{let x=();}

(R -VAL) th

rd p{}

obj p:Main {}

class Main{m[ ; ma]}

adv ma():exec(Main::m) {let x=o:c.m();return ();}

obj o:c {}

class c{m[ca ; cb]}

adv ca():call(c::m) {let y=proceed();return ();}

adv cb():exec(c::m) {return ();}

Page 41: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Advice message (call) (table 5)

A

A

A

thrd p{let x=o.m[ca ; cb]

(R -ADV-MSG2)

thrd p{let x=p{let y=o.m[ ; cb

thrd p{let x

]();return (

=o:c.m();}

(R -DYN-MSG

(R -ADV-MSG

)

1

);

)

(

thrd p{let x

)

};

}

p

;}

=

A

A

A

A

{let y=o{return ();};return ();};}

(R -RETURN) thrd p{let x=p{let y=();return ();};}

(R -VAL) thrd p{let x=p{return ();};}

(R -RETURN) thrd p{let x=();}

(R -VAL) th

rd p{}

obj p:Main {}

class Main{m[ ; ma]}

adv ma():exec(Main::m) {let x=o:c.m();return ();}

obj o:c {}

class c{m[ca ; cb]}

adv ca():call(c::m) {let y=proceed();return ();}

adv cb():exec(c::m) {return ();}

Page 42: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Advice message (execution) (table 5)

A

A

A

thrd p{let x=o:c.m();}

(R -DYN-MSG) thrd p{let x=o.m[ca ; cb]

thrd p{let x=p{let y=o.

m[ ; cb]();re

();}

(R -ADV-MSG turn ();

(

R

2)

-

ADV-MSG1) th

};}

rd

p

{let x=

p

A

A

A

A

(R -RETURN) thrd p{let x=p{let y=();return ();};}

(R -VAL) thrd p{let x=p{return ();};}

(R -RETURN) thrd

{let y=o{return ();};return

p{let x=();}

(R

();};}

-VAL) h

t

rd p{}

obj p:Main {}

class Main{m[ ; ma]}

adv ma():exec(Main::m) {let x=o:c.m();return ();}

obj o:c {}

class c{m[ca ; cb]}

adv ca():call(c::m) {let y=proceed();return ();}

adv cb():exec(c::m) {return ();}

Page 43: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Reduction

A

A

A

thrd p{let x=o:c.m();}

(R -DYN-MSG) thrd p{let x=o.m[ca ; cb]();}

(R -ADV-MSG2) thrd p{let x=p{let y=o.m[ ; cb]();return ();};}

(R -ADV-MSG1) thrd p{let x=p

A

A

A

A

{let y=o{return ();};return ();};}

(R -RETURN) thrd p{let x=p{let y=();return ();};}

(R -VAL) thrd p{let x=p{return ();};}

(R -RETURN) thrd p{let x=();}

(R -VAL) th

rd p{}

obj p:Main {}

class Main{m[ ; ma]}

adv ma():exec(Main::m) {let x=o:c.m();return ();}

obj o:c {}

class c{m[ca ; cb]}

adv ca():call(c::m) {let y=proceed();return ();}

adv cb():exec(c::m) {return ();}

Page 44: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Aspect based Reduction (table 5)

Page 45: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Reduction summary

Rules Purpose

(RA-DYN-MSG) and (RA-STC-MSG) Rely on the advice sets declared by methods.

(LA-TOP) Ensure that (RA-DYN-MSG)always succeeds

(RA-DYN-MSG) Call and execution advice

(RA-ADV-MSG1) Reduction of execution advice.

(RA-ADV-MSG2) Reduction of call advice

Page 46: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Coherence

advice that appears in a method declaration must be consistent with that which is attached to a pointcut

A collection of declarations D is coherent (resp. semicoherent)

if whenever D adv b(_): {_} and D class c<:_ {...m[a ; a']...} then

b a iff (resp

DEFINITION 1

. implies) D

(COHERENCE)

c::m ca

.

lladv(

T )

and b a' iff (resp. implies) D c::m execadv( ) T

Page 47: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Close

(C-FIX)

We define the function close(D),

which saturates class

declarations with

DEF

advice:

D is coh

INITION 2 (C

erent

close(D

LOSE).

) = D

(C-CALL)

(C-EXEC)

D adv a(_): {_}

D c::m calladv( )

D = E, class c<:d {M, m[a ; b]}

close(D) = close(E, class c<:d {M, m[a, a; b]})

D adv b(_): {_}

D c::m execadv( )

D= E, class c<:d {M, m[a ; b]}

close

(D) = close(E, class c<:d { M, m[a; b, b]})

Page 48: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

An Aspect-based Language – Lemma

If D is semi-coherent, then close(

LEMMA 1

D) is co

(

h

CLOSE).

erent.

Cohe

LEMMA

rence

2 (COHERE

is preser

NCE PRESE

ved by re

RVATIO

duc

N).

tion.

Note that any program where each class declaration is taken

from the class-based language is semi-coherent by construction.

Page 49: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 50: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – Requirements

Correctness is formalized by demanding that the following diagram can be completed

We also expect that a woven program not have spurious new reductions.

Page 51: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – Macro expansion

Weaving as Macro Expansion The body of a method is determined

by selecting the body of the first advice named in the advice list.

The rule is applied again, after substituting the remaining advice through for proceed.

Page 52: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – New methods

Weaving by Introducing New Methods given a method m affected by advice

, we create an auxiliary method for each suffix of the list .

Call advised methods are placed in the class of the caller, whereas execution advised methods are placed in the class of the callee.

a

a

Page 53: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – Advice weaving (table 6)

Page 54: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – Advice weaving (table 6)

Page 55: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Weaving – Advice weaving, execution, call (table 6, 7)

Page 56: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Contents Introduction A Class-based Language

Syntax Reduction

An Aspect-based Language Syntax Reduction

Weaving The Correctness of Weaving

Page 57: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Weavability

Weaving is not correct for all programs. Weaving does not support the dynamic

loading of advice Controlling object of all threads must be

defined All advised messages m[ ; ] in a thread with

controlling object p should arise no dangling references

We formalize these intuitions as Weavability.

Page 58: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Weavability definition

We define D; H ; n weavable(·) on stacks in Table 8.

Extend the definition to programs and advice declarations as follows:

D; H; bn(H) weava

DEFINITION 3 (W

ble(D)

D; H; bn(

EAVA

H) weavable(H

BILITY).

T )

weavable(D H)

D; H; n, x, this, target weavable(this{C})

D; H; n weavable(adv a(x): {C})

============= =

============= =

Page 59: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Weavability of stacks (table 8)

Page 60: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Lemma

Weavability is preserved by red

LEMMA 3.

uction.

Page 61: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Name equivalence

Let be the equivalence on class-based commands generated by:

H obj o:d {_}

D advice(d::m) = [_; b]

D; H let x=o.m(v); let x=o

DEFINITION 4 (NAME EQUIV

.exec_b(v);

D advic

ALENCE)

e(c::m) = b]

.

[_;

D; H let x=o.c::m(v); let x=o.exec_b(v);

C is not a method call

D; H C C

Extend the definition to all other program constructs homorphically using conjunction.

Let P = (D H) and P' = (D' H')

T T . We write "P P0" when D; H P P' and

D'; H' P P'.

Page 62: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The Correctness of Weaving – Theorem

Suppose that an aspect-based program P is coherent and weavable, and

that P P'. Then there exists some Q', such that weave(P) Q' and Q' weave(P').

Suppose that an aspect-based p

THEOREM 1

rogram P c

.

is

oherent and weavable, and that weave(P) Q'.

Then there exists some P', such that P P' and P' weave(Q').

Page 63: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

The end

Page 64: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 1

Page 65: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 2

Page 66: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 3

Page 67: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 4

Page 68: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 5

Page 69: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 6

Page 70: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 7

Page 71: A Calculus of Untyped Aspect-Oriented Programs Paper by Radha Jagadeesan Alan Jeffrey James Riely Presented by Shay Cohen

Table 8