3.3. Behavior package

[Warning]Text not verified for kermeta 2

Behavior package

Figure 3.7. Behavior package


Behavior main metaclasses

Figure 3.8. Behavior main metaclasses


3.3.1. Control Structures

Kermeta provides basic control structures : block, conditional branch, loop, and exception handling. Here there an excerpt of the Meta-model describing control structures. Each basic control structures derives from the Expression concept.

Control structure

Figure 3.9. Control structure


3.3.2. Variables

Use of variables

Figure 3.10. Use of variables


3.3.3. Call Expressions

use of exceptions

Figure 3.11. use of exceptions


3.3.3.1. CallSuperOperation

In the following example, the type of super[ParentClass](element) is CallSuperOperation :

class ParentClass {
    operation op(element : Integer) : Integer is do
        result := element + 1
    end

}

class ChildClass inherits ParentClass {
    method op(element : Integer) : Integer is do
        result := super[ParentClass](element)
    end
}

3.3.3.2. CallVariable

The type of callvar , below, is CallVariable:

var myvar : Integer
var callvar : Integer init 4
// 
myvar := callvar 

A special case, when calling a lambda expression : the type of lf in the assignment of res, is CallVariable.

var lf : <Integer->Integer>
var res : Integerlf := function  { i : Integer | i.plus(1) }
// The type of lf, below, is CallVariable
res := lf(4)
          

3.3.3.3. CallResult

The type of result is CallResult

operation op() : Integer is do
    result := 61
end

3.3.3.4. CallFeature and SelfExpression

  • The type of self is a SelfExpression!

  • The type of attr in the body of the operation myoperation is CallFeature (a callfeature on self ), and so is the type of myoperation(4) (a callfeature on a ).

class A {
    attribute attr : Integer
    operation myoperation(param : Integer) : Integer is do
        result := self.attr + param
    end
}
class B {
    operation anotheroperation() : Integer is do
        var a : A
        result := a.myoperation(4)
    end
}

3.3.4. Assignment

Kermeta assignment expression

Figure 3.12. Kermeta assignment expression


In the following example, thetarget is of type CallExpression and thevalue is of type Expression .

var num : Numeric
var thetarget : Integer
var thevalue : Integer
// assignment : thetarget->target, thevalue->value
thetarget := thevalue
// casting : a is casted into the type of num which is Numeric.
num ?= a

3.3.5. Literals

Kermeta Literal Expression

Figure 3.13. Kermeta Literal Expression


var i : Integer
i := 5    // 5 is a IntegerLiteral
var s : String 
s := "I am a string" // "I am a string" is a StringLiteral

3.3.6.  Lambda Expression

Kermeta lambda expressions

Figure 3.14. Kermeta lambda expressions