Commit 8a5719f9 authored by Matthias Simon's avatar Matthias Simon
Browse files

Add list-types

parent 51bdd586
Loading
Loading
Loading
Loading
+133 −1
Original line number Diff line number Diff line
# Types and Values

## General

- static, static means every expression has a single un-ambigiou type assigned to it.
> NOTE: static does not mean during compile time (see unions)

- TTCN-3 differenciates between data-types and reference types

## Booleans

The predefined type `boolean` is the set of boolean values true and false.
@@ -44,7 +51,7 @@ true and false == true
true and true == true
```

## Numbers
## Numerical values

TTCN-3 provides two numerical types: `integer` and `float`.

@@ -364,4 +371,129 @@ type enumerated verdicttype {
}
```

## List types

### General

A list type is a collection of elements of the same type.
The type of the elements is called the _element type_ of the list.
The element types can be referenced using index notation `[-]`.

```ttcn3 test="element type reference"
type record of integer R;
var R[-] i := 23;
```

**List size**

The total number of initialized and uninitialized elements in a list
is called the _size_ of the list.

The size is returned by the `sizeof` function (see 0.0).


**Logical length**

The interpreted number of elements if called the _logical length_ of a list.

The logical length is returned by the `lengthof` function (see 0.0).

> NOTE: The term length is informally used interchangeably with "number of elements" sometimes.

### Index operation

An individual element of a list value is accessed using the index operator `[]`
and the index that identifies the element.

```ttcn3 test="index operator"
{"a","b","c"}[1] == "b"
```
The first element has index `0`, the second element has index `1`, and so on.

**Concatenation**

Two lists with the same root type can be concatenated using the `&` operator.
The result is a new list with the root type of the operands.

```ttcn3 test="concatenation"
type integer uint8  (0..255);
type integer uint16 (0..65535);

var uint8  a := {1,2,-};
var uint16 b := {-,5,6};
var c := a & b;
log(c); // {1,2,-,-,5,6}
typeof(c); // record of integer
```

```ttcn3
var record of record { integer a, integer b } a := { {1,2}, {3,4} }
var record of record { integer x, integer y } b := { {5,6}, {7,8} }
log(a & b) // 
```

### Character strings

The predefined list type `string` represents the set of character strings.
A character string is a sequence of Unicode code points.

The element type of a `string` is itself a `string`.

A `string` value shall not contain uninitialized elements.

Individual characters are accessed using the index operator `[]`.


### Binary strings

TTCN-3 provides three types to represent binary data.

  - Bitstring
  - Hexstring
  - Octetstring


### Record of and set of

A _record of_ is a numbered sequence of elements of a single type, called
the element type.

A _record of_ may contain uninitialized elements.

accings elements later automatcall creates new lements


<!-- TODO: specify length constraint -->


```ebnf
NamedListType = "type" ListType name [ValueConstraint] [LengthConstraint].
ListType = ("record"|"set") [LengthConstraint] "of" TypeExpr.
```

<!-- TODO: What is a set exactly? -->

<!-- TODO: equivalent witrh array -->

## Subtypes

**Syntactical Structure**

```ebnf
SubType = "type" PrimaryExpr name [ValueConstraint] [LengthConstrain] [With].
```

**Semantic Description**

A subtype definition introduces a new type.
- base-type
- constraints must be compatible
- different attributes

- empty type is considered an error



## Type inference rules