Promela |
Declarator |
typedef |
NAME
typedef -
to declare a user-defined structured data type.
SYNTAX
typedef name { decl_lst }
DESCRIPTION
Typedef declarations can be used to introduce user-defined data types.
User-defined types can be used anywhere predefined integer data types
can be used. Specifically, with some mild restrictions, they can be used as formal and actual
parameters for
proctype declarations and instantiations, as fields in
message channels, and as arguments in message send and receive
statements.
A typedef declaration can refer to other, previously declared typedef structures, but it may not be self-referential. A typedef definition must always be global, but it can be used to declare both local and global data objects of the new type.
EXAMPLES
The first example shows how to declare
a two-dimensional array of elements of type
byte with a
typedef .
typedef array { /* typedefs must be global */ byte aa[4] }; init { array a[8]; /* 8x4 = 32 bytes total */ a[3].aa[1] = 5 }The following example introduces two user-defined types named D and Msg , and declares an array of two objects of type Msg , named top :
typedef D { short f; byte g }; typedef Msg { byte a[3]; int fld1; D fld2; chan p[3]; bit b }; Msg top[2];The elements of top can be referenced as, for instance:
top[1].fld2.g = top[0].a[2]Objects of type Msg can be passed through a channel, provided that they do not contain any field of type unsigned, and provided that they do not contain arrays of typedef'ed structures.
chan q = [2] of { Msg }; q!top[0]; q?top[1]If we delete all arrays from the declaration of type Msg we can also use objects of this type in a run parameter, for instance, as follows:
typedef D { short f; byte g }; typedef Msg { int fld1; D fld2; bit b }; Msg top[2]; proctype boo(Msg m) { printf("fld1=%d\n", m.fld1); } init { chan q = [2] of { Msg }; top[0].fld1 = 12; q!top[0]; q?top[1]; run boo(top[1]) }
NOTES
The current Spin implementation imposes the following
restrictions on the use of
typedef objects.
It is not possible to assign the value of a complete
typedef object directly to another such object of the same type
in a single assignment.
A
typedef object may be sent through a message channel as a unit
provided that it contains no fields of type
unsigned and no arrays of typedef'ed structures.
A
typedef object can also be used as a parameter in a
run statement, but in this case it may not contain any arrays.
Beware that the use of this keyword differs from its namesake in the C programming language. The working of the C version of a typedef statement is best approximated with a macro definition.
SEE ALSO
arrays
datatypes
macros
mtype
Spin Online References Promela Manual Index Promela Grammar Spin HomePage |
(Page updated: 2 May 2009) |