Presentation is loading. Please wait.

Presentation is loading. Please wait.

Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.<=) T go down e iff C1 EI* EC C3 (EA*(EI* EC EA*)*

Similar presentations


Presentation on theme: "Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.<=) T go down e iff C1 EI* EC C3 (EA*(EI* EC EA*)*"— Presentation transcript:

1 Semantics Connection to Traversal Graphs

2 Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.<=) T go down e iff C1 EI* EC C3 (EA*(EI* EC EA*)* EI*) T declared type of o2 is C3=>C2

3 Example 1 strategy: {A -> B B -> C} A B C X x x b c class graph ABC Strategy s t c BOpt Empty Object graph :A c2:C x1:X :R x2:X c1:C c3:C e1:Empty S R go down e iff C1. )*.<=) T

4 Are the two concepts equivalent? Traversals done by Mitch’s semantics. Traversals done by the Traversal Methods Algorithm.

5 Traversal methods algorithm Algorithm 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].

6 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 l  Q, let T l = {v|(u,l,v)  TG for some u  T’}. –5. Call this.l.Traverse(T l ) for all l  Q, ordered by “<“, the field ordering.

7 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 T s and T f be the start and finish sets, respectively.

8 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 T s, guided by TG. Then traversing O from o guided by PathSet[SS,G,N,B] produces H.

9 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| d 0 ) where d 0 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.

10 Explain directly in terms of paths in object graph

11 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.

12 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.

13 Example 1 strategy: {A -> B B -> C} A B C X x x b c class graph ABC Strategy s t c BOpt Empty Object graph OG : A X R X C OG’: A X B X C SG : A B C (CG: A X Bopt B X C) :A c2:C x1:X :R x2:X c1:C c3:C e1:Empty S R Only node paths shown for space reasons

14 Example 1A strategy: {A -> S S -> C} A B C X x x b c class graph ASC 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 S R Only node paths shown for space reasons early termination

15 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.

16 A1 (=>.( )*.<=) E2 A1 A2 K1 B1 B2 D1 c1 D2 K2 E1 E2

17 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

18 Example A R B X S D 0..1 C T A -> T T -> D a1:A r1:Rs1:S :C :D class graph strategy object graph POSS(A,T,a1) = 1 edge POSS(R,T,r1) = 1 edge POSS(S,T,s1) = 0 edges object graph slice

19 Example A R B X S D 0..1 C T A -> T T -> D a1:A r1:R s1:S c1:C :D class graph strategy POSS(A,T,a1) = 1 edge POSS(R,T,r1) = 1 edge POSS(S,T,s1) = 1 edge POSS(T,D,t1) = 1 edge POSS(R,D,r2) = 1 edge t1:T r2:R c2:C d2:D s2:S object graph

20 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).

21 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 edges EA: subclass or alternation edges EC: construction or has-a edges

22 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?

23 WandVisitor example // where has source A and target C void 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-object is visited? Not all As and Bs visited since last visit to a C-object?

24 Visitor Methods for Construction 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, **, *

25 Visitor Methods for Construction 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 –-> *,**,*

26 CEdgeInfo CEdgeInfo = [ String] [ String]. // derived / public, protected, private

27 SEdgeInfo SEdgeInfo = [ String] [ String].

28 Visitor has a method EdgeInfo getCEdgeInfo() that returns the EdgeInfo of the current construction edge being traversed.

29 Visitor Methods for Construction 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, *, *

30 Visitor Methods for Construction 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 –-> *,**,*

31 Visitor Methods for Construction Edges void cbefore_x(Source s, EdgeInfo e); –-> Source, x, * void cbefore(Source s, EdgeInfo e); // * –-> Source, *, *

32 Visitor Methods for Construction 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 –-> *,**,*

33 Visitor Methods for Strategy Edges void sbefore(Source s, Target t); // strategy

34 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

35 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


Download ppt "Semantics Connection to Traversal Graphs. Strategy: From C1 to T o1:C1 o2:C2 e go down e iff C1. )*.<=) T go down e iff C1 EI* EC C3 (EA*(EI* EC EA*)*"

Similar presentations


Ads by Google