Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.
-
Upload
gregory-hutchinson -
Category
Documents
-
view
215 -
download
0
Transcript of Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.
![Page 1: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/1.jpg)
Semantics
Connection to Traversal Graphs
![Page 2: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/2.jpg)
Strategy: From C1 to T
o1:C1 o2:C2e
go down e iff C1 <=.C C3 (=>.<=.C.=>)*.<=) Tgo down e iff C1 EI* EC C3 (EA*(EI* EC EA*)* EI*) T
declared type of o2 is C3=>C2
![Page 3: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/3.jpg)
Example 1strategy:{A -> B B -> C}
A
B
C
X
xx
b
c
class graph
A B C
Strategy s t
c
BOpt
Empty
Object graph
:A
c2:C
x1:X
:R
x2:X
c1:C
c3:C
e1:Empty SR
go down e iff C1 <=.C C3 (=>.<=.C.=>)*.<=) T
![Page 4: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/4.jpg)
Are the two concepts equivalent?
• Traversals done by Mitch’s semantics.
• Traversals done by the Traversal Methods Algorithm.
![Page 5: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/5.jpg)
Traversal methods algorithmAlgorithm 2
• Idea is to traverse an object graph while using the traversal graph as a road map.
• Maintain set of “tokens” placed on the traversal graph.
• May have several tokens: path leading to an object may be a prefix of several distinct paths in PathSet[SS,G,N,B].
![Page 6: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/6.jpg)
Traversal methods algorithm
– 4. Let Q be the set of labels which appear both on edges outgoing from a node in T’TG and on edges outgoing from this in the object graph. For each field name lQ, let
Tl = {v|(u,l,v) TG for some uT’}.
– 5. Call this.l.Traverse(Tl) for all lQ, ordered by “<“, the field ordering.
![Page 7: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/7.jpg)
Main Theorem
• Let SS be a strategy, let G be a class graph, let N be a name map, and let B be a constraint map. Let TG be the traversal graph generated by Algorithm 1, and let Ts
and Tf be the start and finish sets, respectively.
![Page 8: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/8.jpg)
Main Theorem (cont.)
• Let O be an object tree and let o be an object in O. Let H be the sequence of nodes visited when o.Traverse is called with argument Ts , guided by TG. Then traversing
O from o guided by PathSet[SS,G,N,B] produces H.
![Page 9: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/9.jpg)
Complexity of algorithm
• Algorithm 1: All steps run in time linear in the size of their input and output. Size of traversal graph: O(|S|2 |G| d0) where d0 is the maximal number of edges outgoing from a node in the class graph.
• Algorithm 2: How many tokens? Size of argument T is bounded by the number of edges in strategy graph.
![Page 10: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/10.jpg)
Explain directly in termsof paths in object graph
![Page 11: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/11.jpg)
A simple view of traversals
• When a traversal reaches a target node in the object graph, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be an expansion of an s-t path in the strategy graph. s is the source and t is the target of the strategy. Each each in the strategy graph corresponds to at least one edge in the object graph.
![Page 12: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/12.jpg)
A simple view of traversals
• When a traversal reaches a final node in the object graph without being at a target, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be a prefix of an expansion of an s-t path in the strategy graph. The prefix is the longest prefix such that there is still a possibility of success as determined by the class graph.
![Page 13: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/13.jpg)
Example 1strategy:{A -> B B -> C}
A
B
C
X
xx
b
c
class graph
A B C
Strategy s t
c
BOpt
Empty
Object graph
OG : A X R X COG’: A X B X CSG : A B C(CG: A X Bopt B X C)
:A
c2:C
x1:X
:R
x2:X
c1:C
c3:C
e1:Empty SR
Only node paths shown for space reasons
![Page 14: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/14.jpg)
Example 1Astrategy:{A -> S S -> C}
A
B
C
X
xx
b
c
class graph
A S C
Strategy s t
c
BOpt
Empty
Object graph
OG : A X R X OG’: A X B X SG : A B (CG: A X Bopt B X )
:A
c2:C
x1:X
:R
x2:X
c1:C
c3:C
e1:Empty SR
Only node paths shown for space reasons
early termination
![Page 15: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/15.jpg)
So far: Remarks about traversals
• Traversals are opportunistic: As long as there is a possibility for success (i.e., getting to the target), the branch is taken.
• In the TOPLAS 95 paper and my book (page 459): Notice that we let the set of paths guide the traversal as long as possible.
![Page 16: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/16.jpg)
A1 (=>.(<=C=>)*.<=) E2
A1
A2
K1
B1
B2 D1c1
D2
K2
E1
E2
![Page 17: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/17.jpg)
Definition
• POSS(Class c1, Class t, Object o1) = those edges e outgoing from o1 s.t. there is an object graph O (consistent with the class graph C), containing the object o1 of class c1, an object o2 of a class that is a subclass of t, and a path in O from o1 to o2 such that the first edge in the path is e.
• POSS: possibility of success
![Page 18: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/18.jpg)
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
a1:A
r1:R s1:S
:C :D
classgraph
strategy
object graph
POSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 0 edges
object graph slice
![Page 19: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/19.jpg)
Example
A
R
BX
S
D
0..1
0..1
0..1
C
T0..1
A -> TT -> D
a1:A
r1:R
s1:Sc1:C
:D
classgraph
strategyPOSS(A,T,a1) = 1 edgePOSS(R,T,r1) = 1 edgePOSS(S,T,s1) = 1 edgePOSS(T,D,t1) = 1 edgePOSS(R,D,r2) = 1 edge
t1:T
r2:R
c2:C
d2:D
s2:S
object graph
![Page 20: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/20.jpg)
Object Slice
• The object graph slice starting with o1 is the slice built by following the edges POSS(Class(o1), t, o1) starting at o1 and continuing until every path terminates (at an object of type t or if it terminates prematurely).
![Page 21: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/21.jpg)
Path concept
• Path from A to B:– EI implies EA in opposite direction – (EC | EA | EI)* but not EA followed by EI
– ((EI* EC) | EA )* EI*
• Equivalent: ?– EA* (EI* EC EA*)* EI*– ((EI* EC) | EA )* EI*
EI: inheritance or is-a edgesEA: subclass or alternation edgesEC: construction or has-a edges
![Page 22: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/22.jpg)
Agenda: Add to DJ
• Add WandVisitor as a new subclass to Visitor.
• In a WandVisitor visitor method activation is delayed until we are at a target.
• What are the semantics?
![Page 23: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/23.jpg)
WandVisitor example
// where has source A and target Cvoid someMethod(TraversalGraph where) { where.traverse(this, new WandVisitor(“A”,”C”) { void before(A a){print(a);} void before(B b){print(b);} void before(C c){print(c);} });}Which methods will be executed when a C-objectis visited? Not all As and Bs visited since last visit to a C-object?
![Page 24: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/24.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Source s, Target t); – -> Source,x,Target
• void cbefore(Source s, String partName, Target t); – -> Source, **, Target
• void cbefore_x(Source s); – -> Source, x, *
• void cbefore(Source s, String partName); // * – -> Source, **, *
![Page 25: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/25.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Target t); // * – -> *,x,Target
• void cbefore(String partName, Target t); // *– -> *,**,Target
• void cbefore_x(); // * – -> *,x,*
• void cbefore(String partName); // * ; all edges– -> *,**,*
![Page 26: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/26.jpg)
CEdgeInfo
CEdgeInfo =
[<sourceName> String]
[<partName> String]
[<targetName> String]
[<edgeKind> String].
// derived / public, protected, private
![Page 27: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/27.jpg)
SEdgeInfo
SEdgeInfo =
[<sourceName> String]
[<targetName> String].
![Page 28: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/28.jpg)
Visitor
has a method
EdgeInfo getCEdgeInfo()
that returns the EdgeInfo of the
current construction edge being traversed.
![Page 29: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/29.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Source s, Target t); – -> Source,x,Target
• void cbefore(Source s, Target t); – -> Source, *, Target
• void cbefore_x(Source s); – -> Source, x, *
• void cbefore(Source s); – -> Source, *, *
![Page 30: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/30.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Target t); // * – -> *,x,Target
• void cbefore(String partName, Target t); // *– -> *,**,Target
• void cbefore_x(); // * – -> *,x,*
• void cbefore(String partName); // * ; all edges– -> *,**,*
![Page 31: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/31.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Source s, EdgeInfo e); – -> Source, x, *
• void cbefore(Source s, EdgeInfo e); // * – -> Source, *, *
![Page 32: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/32.jpg)
Visitor Methods forConstruction Edges
• void cbefore_x(Target t, EdgeInfo e); // * – -> *,x,Target
• void cbefore(Target t, EdgeInfo); // *– -> *,**,Target
• void cbefore_x(EdgeInfo e); // * – -> *,x,*
• void cbefore(String partName); // * ; all edges– -> *,**,*
![Page 33: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/33.jpg)
Visitor Methods forStrategy Edges
• void sbefore(Source s, Target t); // strategy
![Page 34: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/34.jpg)
Programming with strategies
check whether currently in scope of subtraversal
// may be used in before, cbefore, rbefore, sbefore
– // sg a substrategy of current strategy
if (sg.contains(getSEdgeInfo())) {
// currently in traversal determined by strategy sg
– // tg a subgraph of current traversal graph
if (tg.contains(getSEdgeInfo())) {
// currently in traversal determined by tg
![Page 35: Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.](https://reader036.fdocuments.us/reader036/viewer/2022070400/56649f155503460f94c2b2c1/html5/thumbnails/35.jpg)
Programming with strategies
• check whether currently in scope of substrategy
// sg a substrategy of current strategy
// may be used in before, cbefore, rbefore, sbefore
if (sg.contains(getSEdgeInfo())) {
// currently in traversal determined by strategy sg
• check whether currently
// tg a subgraph of current traversal graph
// may only be used in cbefore
if (tg.contains(getCEdgeInfo())) {
// currently in traversal determined by tg