Titan



type


The keyword is used to specify user-defined structured types, subtypes or behavior types ( function type, altstep type or testcase type).


Related keyword:


1. Structured type

type ( record | union | set | record of | set of | enumerated | port | component ) identifier  { body };


2. Subtype

Another use of the keyword is the subtype definition.


type parent_identifier  ( identifier  | address) [ array_def] [ ( list )] [length] [ ; ]


Example 1:

type enumerated Example {tisdag, fredag, onsdag};

The enumerated type called Example containing three elements is defined.

Example 2:

type Ex_subt Example (tisdag, onsdag);

The sub-type, called Ex_subt, may contain only two elements of the parent type (called Example).


3. Behavior type

Another use of the keyword is the behavior type definition.

It introduces a function type, an altstep type or a testcase type.


3.1. Function type

type function Function_type_name ( formal_parameter_list ) [ runs on component_type_ref ] [return returned_type ] [;]


Example 3:

type function F_type(in integer pl_i) runs on CT returns charstring; // line 1

function f(in integer pl_ii) runs on CT returns charstring { log(pl_ii);return "Hello" }; // line 2

var F_type v_f := refers(f); // line 3

var CT v_comp := CT.create; // line 4

v_comp.start(derefers(v_f)(1));// line 5

v_f.apply(2); // line 6

Line 1: Function type "F_type" is defined. Its parameter is type of integer and it is an "in" parameter. It runs on CT and its return value a charstring.

Line 2: The function f defined here has type of F_type.

Line 3: The function reference variable v_f has a type of function (reference) type F_type and its value is defined here as a reference to function f. This definition is valid because v_f refers to the same type as f.

Line 5: The behavior function referenced by v_f is started on component v_comp.

Line 6: The function referenced by v_f is called. It is the same as calling f(2).


3.2. Altstep type

type altstep  altstep_identifier ( [ altstep_parameter ... ] ) runs on component_type_ref [ ;]

Example 4:

type component CT {}

type altstep As_type() runs on CT

altstep as_1() runs on CT {

  [else] {}

}

testcase tc() runs on CT {

  var As_type v_as := refers(as_1);

  v_as.apply(); //same as "as_1();"

};


3.3. Testcase type

type testcase testcase_identifier ( [ testcase_parameters ...  ] ) runs on component_type_ref  [ system system_component_type_ref ] [ ; ]

BNF definition of type