Software Design, Modelling and Analysis in UML Lecture 12: Core State Machines II 2015-12-15 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal – 12 – 2015-12-15 – main – Albert-Ludwigs-Universit¨ at Freiburg, Germany Contents & Goals Last Lecture: • Basic causality model • Ether/event pool • System configuration This Lecture: • Educational Objectives: Capabilities for following tasks/questions. • What does this State Machine mean? What happens if I inject this event? • Can you please model the following behaviour. • What is: Signal, Event, Ether, Transformer, Step, RTC. • Content: – 12 – 2015-12-15 – Sprelim – • System configuration cont’d • Transformers • Step, Run-to-Completion Step 2 /47
System Configuration – 12 – 2015-12-15 – main – 3 /47 System Configuration Definition. Let S 0 = ( T 0 , C 0 , V 0 , atr 0 , E ) be a signature with signals, D 0 a structure of S 0 , ( Eth , ready , ⊕ , ⊖ , [ · ]) an ether over S 0 and D 0 . Furthermore assume there is one core state machine M C per class C ∈ C . A system configuration over S 0 , D 0 , and Eth is a pair ( σ, ε ) ∈ Σ D S × Eth where • S = ( T 0 ˙ ∪ { S M C | C ∈ C 0 } , C 0 , V 0 ˙ ∪ {� stable : Bool , − , true , ∅�} ˙ ∪ {� st C : S M C , + , s 0 , ∅� | C ∈ C } ˙ ∪ {� params E : E 0 , 1 , + , ∅ , ∅� | E ∈ E 0 } , – 12 – 2015-12-15 – Sstmscnf – { C �→ atr 0 ( C ) ∪ { stable , st C } ∪ { params E | E ∈ E 0 } | C ∈ C } , E 0 ) • D = D 0 ˙ ∪ { S M C �→ S ( M C ) | C ∈ C } , and • σ ( u )( r ) ∩ D ( E 0 ) = ∅ for each u ∈ dom( σ ) and r ∈ V 0 . 4 /47
System Configuration: Example C ( σ, ε ) ∈ Σ D S 0 = ( T 0 , C 0 , V 0 , atr 0 , E ) , D 0 ; S × Eth where x : Int • S = ( T 0 ˙ ∪ { S M C | C ∈ C } , C 0 , V 0 ˙ ∪ {� stable : Bool , − , true , ∅�} ˙ ∪ {� st C : S M C , + , s 0 , ∅� | C ∈ C } c 0 .. 1 ˙ ∪ {� params E : E 0 , 1 , + , ∅ , ∅� | E ∈ E 0 } , { C �→ atr 0 ( C ) ∪ { stable , st C } ∪ { params E | E ∈ E 0 } | C ∈ C } , E 0 ) � � signal � � • D = D 0 ˙ ∪ { S M C �→ S ( M C ) | C ∈ C } , and E • σ ( u )( r ) ∩ D ( E 0 ) = ∅ for each u ∈ dom( σ ) and r ∈ V 0 . b : Bool � � signal � � F a : Int SM C : – 12 – 2015-12-15 – Sstmscnf – • s 1 s 2 s 3 5 /47 System Configuration Step-by-Step • We start with some signature with signals S 0 = ( T 0 , C 0 , V 0 , atr 0 , E ) . • A system configuration is a pair ( σ, ε ) which comprises a system state σ wrt. S (not wrt. S 0 ). • Such a system state σ wrt. S provides, for each object u ∈ dom( σ ) , • values for the explicit attributes in V 0 , • values for a number of implicit attributes , namely • a stability flag , i.e. σ ( u )( stable ) is a boolean value, • a current (state machine) state , i.e. σ ( u )( st ) denotes one of the states of core state machine M C , • a temporary association to access event parameters for each class, i.e. – 12 – 2015-12-15 – Sstmscnf – σ ( u )( params E ) is defined for each E ∈ E . • For convenience require: there is no link to an event except for params E . 6 /47
Stability Definition. Let ( σ, ε ) be a system configuration over some S 0 , D 0 , Eth . We call an object u ∈ dom( σ ) ∩ D ( C 0 ) stable in σ if and only if σ ( u )( stable ) = true . – 12 – 2015-12-15 – Sstmscnf – 7 /47 � � signal � � n Where are we? C E p x : Int D 0 .. 1 � � signal � � 0 .. 1 F • SM C : E [ n � = ∅ ] /x := x + 1; n ! F s 1 s 2 • : SM D F/ s 1 s 2 F/x := 0 /n := ∅ /p ! F s 3 ( { E } , { F } ) ( ∅ , ∅ ) ( { F } , ∅ ) ( σ 1 , ε 1 ) ( σ 2 , ε 2 ) ( σ 3 , ε 3 ) ( σ 4 , ε 4 ) u 1 u 1 u 2 – 12 – 2015-12-15 – Sstmscnf – u 1 : C u 1 : C u 1 : C u 1 : C x = 27 x = 28 x = 28 x = 28 st = s 1 st = s 2 st = s 3 st = s 3 stb = 1 u 3 : E stb = 0 u 4 : F stb = 0 u 4 : F stb = 0 p p p p n n to u 1 to u 2 to u 2 u 2 : D u 2 : D u 2 : D u 2 : D st = s 1 st = s 1 st = s 1 st = s 2 stb = 1 stb = 1 stb = 1 stb = 0 8 /47
Transformer – 12 – 2015-12-15 – main – 9 /47 Recall • The (simplified) syntax of transition annotations: � � annot ::= � event � [ ‘ [ ’ � guard � ‘ ] ’ ] [ ‘ / ’ � action � ] • Clear : � event � is from E of the corresponding signature. • But: What are � guard � and � action � ? • UML can be viewed as being parameterized in expression language (providing � guard � ) and action language (providing � action � ). • Examples : • Expression Language : • OCL • Java, C++, . . . expressions • . . . – 12 – 2015-12-15 – Strafo – • Action Language : • UML Action Semantics, “Executable UML” • Java, C++, . . . statements (plus some event send action) • . . . 10 /47
Needed: Semantics In the following, we assume that we’re given • an expression language Expr for guards, and • an action language Act for actions, and that we’re given • a semantics for boolean expressions in form of a partial function I � · � ( · , · ) : Expr × Σ D S × D ( C ) � → B which evaluates expressions in a given system configuration, Assuming I to be partial is a way to treat “undefined” during runtime. If I is not defined (for instance because of dangling-reference navigation or division-by-zero), we want to go – 12 – 2015-12-15 – Strafo – to a designated “error” system configuration. • a transformer for each action: for each act ∈ Act , we assume to have t act ⊆ D ( C ) × (Σ D S × Eth ) × (Σ D S × Eth ) 11 /47 Transformer Definition. Let Σ D S the set of system configurations over some S 0 , D 0 , Eth . We call a relation t ⊆ D ( C ) × (Σ D S × Eth ) × (Σ D S × Eth ) a (system configuration) transformer . Example : • t [ u x ]( σ, ε ) ⊆ Σ D S × Eth is • the set (!) of the system configurations – 12 – 2015-12-15 – Strafo – • which may result from object u x • executing transformer t . • t skip [ u x ]( σ, ε ) = { ( σ, ε ) } • t create [ u x ]( σ, ε ) : add a previously non-alive object to σ 12 /47
Observations • In the following, we assume that • each application of a transformer t • to some system configuration ( σ, ε ) • for object u x is associated with a set of observations Obs t [ u x ]( σ, ε ) ∈ 2 ( D ( E ) ˙ ∪ {∗ , + } ) × D ( C ) . • An observation ( u e , u dst ) ∈ Obs t [ u x ]( σ, ε ) represents the information that, as a “side effect” of object u x executing t in system configuration ( σ, ε ) , the event u e has been sent to u dst . – 12 – 2015-12-15 – Strafo – Special cases : creation (’ ∗ ’) / destruction (’ + ’). 13 /47 A Simple Action Language In the following we use Act S = { skip } ∪ { update ( expr 1 , v, expr 2 ) | expr 1 , expr 2 ∈ Expr S , v ∈ atr } ∪ { send ( E ( expr 1 , ..., expr n ) , expr dst ) | expr i , expr dst ∈ Expr S , E ∈ E } ∪ { create ( C, expr , v ) | C ∈ C , expr ∈ Expr S , v ∈ V } ∪ { destroy ( expr ) | expr ∈ Expr S } and OCL expressions over S (with partial interpretation) as Expr S . – 12 – 2015-12-15 – Sactlang – 14 /47
Transformer Examples: Presentation abstract syntax concrete syntax op intuitive semantics . . . well-typedness . . . semantics (( σ, ε ) , ( σ ′ , ε ′ )) ∈ t op [ u x ] iff . . . or t op [ u x ]( σ, ε ) = { ( σ ′ , ε ′ ) | where . . . } observables Obs op [ u x ] = { . . . } – 12 – 2015-12-15 – Sactlang – (error) conditions Not defined if . . . 15 /47 Transformer: Skip abstract syntax concrete syntax skip intuitive semantics do nothing well-typedness ./. semantics t skip [ u x ]( σ, ε ) = { ( σ, ε ) } observables Obs skip [ u x ]( σ, ε ) = ∅ (error) conditions – 12 – 2015-12-15 – Sactlang – 16 /47
Transformer: Update abstract syntax concrete syntax update ( expr 1 , v, expr 2 ) intuitive semantics Update attribute v in the object denoted by expr 1 to the value denoted by expr 2 . well-typedness expr 1 : T C and v : T ∈ atr ( C ) ; expr 2 : T ; expr 1 , expr 2 obey visibility and navigability semantics t update ( expr 1 ,v, expr 2 ) [ u x ]( σ, ε ) = { ( σ ′ , ε ) } where σ ′ = σ [ u �→ σ ( u )[ v �→ I � expr 2 � ( σ, u x )]] with u = I � expr 1 � ( σ, u x ) . observables – 12 – 2015-12-15 – Sactlang – Obs update ( expr 1 ,v, expr 2 ) [ u x ] = ∅ (error) conditions Not defined if I � expr 1 � ( σ, u x ) or I � expr 2 � ( σ, u x ) not defined. 17 /47 Update Transformer Example SM C : /x := x + 1 s 1 s 2 t update ( expr 1 ,v, expr 2 ) [ u x ]( σ, ε ) = ( σ ′ = σ [ u �→ σ ( u )[ v �→ I � expr 2 � ( σ, u x )]] , ε ) , u = I � expr 1 � ( σ, u x ) u 1 : C u 1 : C σ : : σ ′ x = 4 x = 5 y = 0 y = 0 – 12 – 2015-12-15 – Sactlang – ε : : ε ′ 18 /47
Recommend
More recommend