Commit 3d4e0214 authored by Matthias Simon's avatar Matthias Simon
Browse files

Update drafts

parent 9bf763be
Loading
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -60,6 +60,19 @@ Attribute:
- Inside a statement block or alternation block, however, a name shall not be used before it has been declared,
- additional rules for enumerated types, fields for records and sets and formal parameters.

- in statementblocks: not before declartation
- in other scopes (compuents, objects, ...) topological

```ttcn3
module Example {
    const integer X := f();
    const integer Y := 5;
    function f() return integer {
        return X;
    }
}
```


### Cyclic Definitions

+106 −6
Original line number Diff line number Diff line
@@ -5,16 +5,116 @@ A variable is a named memory location to store the value of a given type.
**Syntactic Structure**

```ebnf
VarDecl = "var" [TypeExpr] Declarator { "," Declarator} [With].
Declarator = name {"[" integer "]"} [":=" Expr].
VarDecl ::= "var" [TypeExpr] Declarator { "," Declarator} [With].
Declarator ::= name {"[" integer "]"} [":=" Expr].
```

**Semantic Description**

A _variable declaration_ adds a new variable with given _name_ into its enclosing scope. 
A _variable declaration_ adds a new variable with given _name_ into its
enclosing scope.
The scoping rules for variables are specified in clause 0.0.

The initial value of a value type variable is _undefined_.
The initial value of a reference type variable is `null`.
A variable shall only be declared in scopes where permitted explicitly, i.e.
[statement blocks], [component type definitions], etc.

A variable shall not be declared in module scope.
Each variable has a static type associated with it.
The type of the variable is specified using a _type expression_
and shall not change during its [lifetime].

 ```ttcn3
 function f(in integer n) {
     var integer a[n]; // type of a is static during its lifetime.
 }
 f(3)
 f(10)
 ```

> NOTE: How types depending on runtime values or how nested types are
> implemented is vendor specific. For example, it is not required to create a
> new type object for every function call as long as TTCN-3 semantics
> are not violated.

The _type expression_ may be omitted if each variable has an _initial value
expression_ with a type that can be inferred statically and unambiguously (see
inference rules for expressions in clause 0.0). The type of the
variable shall be the equal to type of the _initial value expression_.

```ttcn3 test
var int a;
var b := a;               // typeof(b) == typeof(a) and typeof(b) == "int"
var r := {1,2,3};         // typeof(r) == "record of integer"
var i := 0, s := "hello"; // typeof(i) == "integer" and typeof(s) == string
var t1 := integer:?       // typeof(t1) == "template integer"
var t2 := ?; // error: ambigous type
```
The array notion shall not be used when the _type expression_ is omitted.

```ttcn3 example
var a[3] := {1,2,3}; // error: not allowed.
```

<!-- TODO: Discuss if `var template a := (1..10)` is still permitted. The standard becomes simpler if not -->

> NOTE: This implicit type inference can be implemented as syntax transformation:
> `var a := {1,2,3}` becomes `var typeof({1,2,3}) a := {1,2,3}`, which becomes
> `var record of integer a := {1,2,3}`.


Every variable that comes into scope shall have an initial value depending on its type:

- the initial value of a reference type variable shall be `null`.
- the initial value of a variable of a verdict type shall be `none`.
- the initial value of any other value type variable shall be [uninitialized].

A variable declaration may also have an explicit _initial value assignment_.
This assignment is semantically equivalent to a separate assignment statement,
as described in [the assignment statement].

The following two examples are semantically equivalent:

```ttcn3
var integer i := 0;
```

```ttcn3
var integer i;
i := 0
```

If the initial value assignment could not succeed,
the variable keeps its initial value as described earlier:

```ttcn3
var float f := 1/0; // value of f stays uninitialized, since the expression `1/0`
                    // failed and the assignment operation did not succeed.
```

The expression of the _initial value assignment_ in variables that are declared
in [statement blocks] is evaluated at the place of the declaration. This
includes variable declared as part of [an initialization statement].

The expression of the _initial value assignment_ in variables that are declared
in scopes that allow [use before declaration] (e.g. inside component type
declarations) may be deferred to a later moment, but at least until its first use.


> NOTE: Optimisation (loop-unrolling, extreaction, macros, ...)



- evaluation order

- addressing/references
- it is recommended to at least throw a warning or even error when non-deterministic functions are used


> NOTE: It is left 

- shorthand array-notation
```ttcn3 example
var integer i := 0, a[3] := {1,2,3};
```
- shorthand timers
- multiple variable declarations
+6 −4
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@
**Syntactical Description**

```ebnf
FormalPars = "(" {FormalPar ","} ")".
FormalPar = [ "in" | "out" | "inout" ] TypeExpr name {"[" integer "]"} [ ":=" Expr].
FormalPars = "(" {FormalPar ","}, ")".
FormalPar = [ "in" | "out" | "inout" ] TypeExpr name {"[" integer "]"} ["..."] [ ":=" Expr].

```

@@ -59,6 +59,9 @@ introduce a memory location to store a value of a specific type.
      - implcit deference


### Variadic parameters


### Actual parameters

- assignment list notation allowed
@@ -79,12 +82,11 @@ the inout parameter or the component variable may also change the other simultan
break the intended algorithm. For this reason, such situations should be avoided.


### Variadic parameters

## Invoking functions
- evaluate arguments in caller scope
- pass arguments to callee scope
-

## Prefedined Functions
## External functions
## Control functions
+41 −1
Original line number Diff line number Diff line
## 19.1 Assignments
## 19.1 Assignment

Assign the result of an expression to a variable or field.

**Syntactic Description**

```ebnf
Assignment ::= PrimaryExpr ":=" Expr.
```

**Semantic Description**

An assignment statement evaluates the expression on the right hand side 
and copies the result to the destination specified by the left hand side.

> NOTE: In case of values of reference types only the reference is copied,
> not the referenced object itself!

> NOTE: Copying large data type values can become expensive.
> A tool vendor might consider implementing a copy on write scheme for data-types.

The _primary expression_ on the left hand side shall specify an [addressable value].


Additional rules apply, if the right hand side is a value list literal or a assignment list literal.

- Assignment-Statements: Expression-Assisgnment, Value-List-Assignment, Assignmen-List-Assignment
- Increment, Decrement: Shorthand for expression-assignment

- Assignment recursive?
```ttcn3
var integer a[3][3] := {
    {1,2,3},
    {4,5,6},
    {7,8,9},
}

a := { 
        [1] := { [1] := 55, },
}


```


- Reference to general Assignment-Mechanics:
  - Compatibility, Other places (parameters, for-range-loop, default-parameters, ...)
  - Value-Types, Reference-Types