Loading src/00-type-expressions.md 0 → 100644 +19 −0 Original line number Diff line number Diff line ## Type Expression The type expression `template(omit)` may be replaced by the shorthand notation `omit`. **Examples** ```ttcn3 example="template(omit) shorthand in declarations" var omit integer t1; // expect: typeof(t1) == "template(omit) integer" ``` ```ttcn3 example="template(omit) shorthand in return-type" external function f() return omit integer; ``` ```ttcn3 example="template(omit) shorthand in formal parameter lists" function f(in omit integer p) { /* … */ } ``` src/11-declaring-variables.md +1 −1 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ permits that. > NOTE: Local variables always have [local visibility], while variables in > class declarations can specify private or protected visibility. A variable declaration may also specify attributes using a `with`-clause. A variable declaration may also specify [attributes] using a `with`-clause. **Examples** Loading src/16-declaring-dynamic-behaviour.md +201 −23 Original line number Diff line number Diff line # Declaring dynamic behaviour # Declaring behaviour ## General - specify dynamic behaviour: - test-cases - default handling - calculate values - interact with SUT or platform - dynamic templates or behaviour through parameterization In TTCN-3, [functions], [altsteps] and [testcases] are used to specify and structure test behaviour, define default behaviour and to structure computation in a module. The extension for [object oriented features] also permits declaring [methods]. Platform specific behaviour may be provided by the means of [external functions]. > In TTCN-3, functions, altsteps and testcases are used to specify and > structure test behaviour, define default behaviour and to structure > computation in a module, etc. as described in the following clauses. > Functions are used in TTCN-3 to express test behaviour, to organize test > execution or to structure computation in a module, for example, to calculate > a single value, to initialize a set of variables or to check some condition. ## Parameterization ### General - different kinds of parameterization - type parameterization - indirect parameterization through references - parameterization through arguments Parameterization may be used to specify dynamic behaviour -- or [values in the case of dynamic templates](15.2). TTCN-3 distinguishes between different kinds of parameterization: > NOTE: module parameters - semantically a parameter is a local variable - each activate frame is its own location - _value parameterization_ as specified in the following chapters. - _type parameterization_ as specified in [advanced parameterization extension]. > NOTE: technically there is also a kind of indirect parameterization through > the use of references. But it is strongly recommended to favor the more > explicit _value parameterization_ over _indirect parameterization through > references_ when possible; because the later can introduce subtle > inconsistencies between individual tools and use-cases. > > The term _parameterization_ will be used interchangeably with _value > parameterization_ in this document, unless stated differently. > NOTE: Parameters are very similar to variables in the sense they > provide a memory location to store the value of a specific type. **Examples** ```ttcn3 example="type parameterization" function f<type T>() { /* ... */ } control { f<integer>(); // function called with type parameter `integer` f<boolean>(); // function called with type parameter `boolean` } ``` ```ttcn3 example="indirect parameterization" modulepar integer mpar; external function timestamp() return integer; function f() { // each call of f will have its own copy of integers referenced // by module parameter `mpar` and external function `timestamp`. var integer v := mpar + timestamp(); log(v); } control { f(); f(); } ``` ```ttcn3 example="value paramerterization" modulepar integer mpar; external function timestamp() return integer; function f(in integer p) { // each call of f will have its own copy of integers referenced // by module parameter `mpar` and external function `timestamp`. log(p); } control { f(mpar+timestamp()); f(mpar+timesteamp()); } ``` ### Formal parameters A _formal parameter list_ specifies the parameters that are accepted. **Syntactical Description** ```ebnf FormalPars ::= "(" {FormalPar ","}, ")". FormalPar ::= [ "in" | "out" | "inout" ] TypeExpr name {"[" integer "]"} ["..."] [ ":=" Expr]. ``` Formal parameters are very similar to variables in the sense they introduce a memory location to store a value of a specific type. **Semantic description** A _formal parameter_ may be declared for [functions], [testcases], [altsteps], [external functions], [methods] and [parameterized templates]. The _formal parameter_ declaration adds a new parameter with given _name_ into the scope of the parameterized language element (see [uniqueness of identifiers]). A _formal parameter_ has a static type associated with it. The type of the parameter shall be specified using a _[type expression]_ and shall not change during its [lifetime]. A _formal parameter_ may be declared as array by using the [array short-hand notation]. The _type expression_, _default value assignment_ and _array notation_ of a _formal parameter_ shall not reference any formal parameters defined in the same _formal parameter list_. A [default value] may the speficied. - direction - in (default): Loading @@ -58,12 +126,122 @@ introduce a memory location to store a value of a specific type. - incremential changes visible - implcit deference **Examples** ```ttcn3 example="scope" function f(integer p) { log(p) // p is in the scope of function f } ``` ```ttcn3 example="array" function f(integer a[3]) { // expect: typeof(a) == "array of integer" } ``` ```ttcn3 example="cannot reference a parameter from the same formal parameter list" external function f(integer n, integer a[n]); // error external function g(integer n, integer a := n*2); // error external function h(integer n, record length(n) of integer a); // error ``` ### Default parameters ### Variadic parameters The last formal parameter of _formal parameter list_ may have a suffix `...` (three dots). Such formal parameter is called variadic parameter and accepts zero or more values of the specified type. The _variadic formal parameter_ shall be an `in` parameter. Using of `inout` or `out` kind of parameterization for variadic parameters is forbidden. A _variadic formal parameter_ may declare array-types using the array-notation. A _variadic formal parameter_ may have an _default value assignment_. Inside the scope of parameterized language element, the type of the formal variadic parameter shall be a `record of` of the specified type. There are three ways of passing an actual parameter to the formal variadic parameter when using the list notation: - The actual parameter is not present in the list of actual parameters or skipped by using the dash symbol. The actual parameter is equal to an empty record of value or template in this case. - Using comma-separated values of the specified type as the actual parameter. The actual variadic parameter is equal to a `record of` value that contains all the comma-separated values in their passing order. - Using a single parameter of a compatible `record of` the specified type followed by `...`. The actual parameter is passed directly to the formal variadic parameter in this case. When using the assignment notation for an actual variadic parameter, the actual parameter shall be a value or template of a compatible record of the specified type without any additional ellipsis. The actual parameter is passed directly to the formal variadic parameter in this case. **Examples** ```ttcn3 example="invalid position" external function f(integer args..., integer n); // error external function g(integer args1..., integer args2...); // error ``` ```ttcn3 example="in parameters only" external function f(inout integer args...); // error external function g(out integer args...); // error ``` ```ttcn3 example="array notation" function f(integer args[3]...) { // expect: typeof(args) == "record of record length(3) of integer" } ``` ```ttcn3 example="passing variadic parameters" control { f(1,2,3); // var record of integer a := {1,2,3} f(a...); f(args := a); } function f(integer args...) { // expect: args == {1,2,3} } ``` ```ttcn3 example="pass empty argument" control { f(); f(-); f(args := {}); } function f(integer args...) { // expect: lengthof(args) == 0 } ``` ```ttcn3 example="default parameter" control { f(); f(-); } function f(integer args... := {1,2,3}) { // expect: args == {1,2,3} } ``` ### Actual parameters - semantically a parameter is a local variable - each activate frame is its own location - default parameter - assignment list notation allowed > NOTE 1: Reference to a string element cannot be passed by reference as string types are not structured types. Loading src/19.1-assignments.md +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ and copies the result to the destination specified by the left hand side. The _primary expression_ on the left hand side shall specify an [addressable value]. - Mention expansion rules for templates and others Additional rules apply, if the right hand side is a value list literal or a assignment list literal. Loading @@ -46,6 +47,7 @@ a := { ``` - Reference to general Assignment-Mechanics: - Compatibility, Other places (parameters, for-range-loop, default-parameters, ...) - Value-Types, Reference-Types Loading Loading
src/00-type-expressions.md 0 → 100644 +19 −0 Original line number Diff line number Diff line ## Type Expression The type expression `template(omit)` may be replaced by the shorthand notation `omit`. **Examples** ```ttcn3 example="template(omit) shorthand in declarations" var omit integer t1; // expect: typeof(t1) == "template(omit) integer" ``` ```ttcn3 example="template(omit) shorthand in return-type" external function f() return omit integer; ``` ```ttcn3 example="template(omit) shorthand in formal parameter lists" function f(in omit integer p) { /* … */ } ```
src/11-declaring-variables.md +1 −1 Original line number Diff line number Diff line Loading @@ -98,7 +98,7 @@ permits that. > NOTE: Local variables always have [local visibility], while variables in > class declarations can specify private or protected visibility. A variable declaration may also specify attributes using a `with`-clause. A variable declaration may also specify [attributes] using a `with`-clause. **Examples** Loading
src/16-declaring-dynamic-behaviour.md +201 −23 Original line number Diff line number Diff line # Declaring dynamic behaviour # Declaring behaviour ## General - specify dynamic behaviour: - test-cases - default handling - calculate values - interact with SUT or platform - dynamic templates or behaviour through parameterization In TTCN-3, [functions], [altsteps] and [testcases] are used to specify and structure test behaviour, define default behaviour and to structure computation in a module. The extension for [object oriented features] also permits declaring [methods]. Platform specific behaviour may be provided by the means of [external functions]. > In TTCN-3, functions, altsteps and testcases are used to specify and > structure test behaviour, define default behaviour and to structure > computation in a module, etc. as described in the following clauses. > Functions are used in TTCN-3 to express test behaviour, to organize test > execution or to structure computation in a module, for example, to calculate > a single value, to initialize a set of variables or to check some condition. ## Parameterization ### General - different kinds of parameterization - type parameterization - indirect parameterization through references - parameterization through arguments Parameterization may be used to specify dynamic behaviour -- or [values in the case of dynamic templates](15.2). TTCN-3 distinguishes between different kinds of parameterization: > NOTE: module parameters - semantically a parameter is a local variable - each activate frame is its own location - _value parameterization_ as specified in the following chapters. - _type parameterization_ as specified in [advanced parameterization extension]. > NOTE: technically there is also a kind of indirect parameterization through > the use of references. But it is strongly recommended to favor the more > explicit _value parameterization_ over _indirect parameterization through > references_ when possible; because the later can introduce subtle > inconsistencies between individual tools and use-cases. > > The term _parameterization_ will be used interchangeably with _value > parameterization_ in this document, unless stated differently. > NOTE: Parameters are very similar to variables in the sense they > provide a memory location to store the value of a specific type. **Examples** ```ttcn3 example="type parameterization" function f<type T>() { /* ... */ } control { f<integer>(); // function called with type parameter `integer` f<boolean>(); // function called with type parameter `boolean` } ``` ```ttcn3 example="indirect parameterization" modulepar integer mpar; external function timestamp() return integer; function f() { // each call of f will have its own copy of integers referenced // by module parameter `mpar` and external function `timestamp`. var integer v := mpar + timestamp(); log(v); } control { f(); f(); } ``` ```ttcn3 example="value paramerterization" modulepar integer mpar; external function timestamp() return integer; function f(in integer p) { // each call of f will have its own copy of integers referenced // by module parameter `mpar` and external function `timestamp`. log(p); } control { f(mpar+timestamp()); f(mpar+timesteamp()); } ``` ### Formal parameters A _formal parameter list_ specifies the parameters that are accepted. **Syntactical Description** ```ebnf FormalPars ::= "(" {FormalPar ","}, ")". FormalPar ::= [ "in" | "out" | "inout" ] TypeExpr name {"[" integer "]"} ["..."] [ ":=" Expr]. ``` Formal parameters are very similar to variables in the sense they introduce a memory location to store a value of a specific type. **Semantic description** A _formal parameter_ may be declared for [functions], [testcases], [altsteps], [external functions], [methods] and [parameterized templates]. The _formal parameter_ declaration adds a new parameter with given _name_ into the scope of the parameterized language element (see [uniqueness of identifiers]). A _formal parameter_ has a static type associated with it. The type of the parameter shall be specified using a _[type expression]_ and shall not change during its [lifetime]. A _formal parameter_ may be declared as array by using the [array short-hand notation]. The _type expression_, _default value assignment_ and _array notation_ of a _formal parameter_ shall not reference any formal parameters defined in the same _formal parameter list_. A [default value] may the speficied. - direction - in (default): Loading @@ -58,12 +126,122 @@ introduce a memory location to store a value of a specific type. - incremential changes visible - implcit deference **Examples** ```ttcn3 example="scope" function f(integer p) { log(p) // p is in the scope of function f } ``` ```ttcn3 example="array" function f(integer a[3]) { // expect: typeof(a) == "array of integer" } ``` ```ttcn3 example="cannot reference a parameter from the same formal parameter list" external function f(integer n, integer a[n]); // error external function g(integer n, integer a := n*2); // error external function h(integer n, record length(n) of integer a); // error ``` ### Default parameters ### Variadic parameters The last formal parameter of _formal parameter list_ may have a suffix `...` (three dots). Such formal parameter is called variadic parameter and accepts zero or more values of the specified type. The _variadic formal parameter_ shall be an `in` parameter. Using of `inout` or `out` kind of parameterization for variadic parameters is forbidden. A _variadic formal parameter_ may declare array-types using the array-notation. A _variadic formal parameter_ may have an _default value assignment_. Inside the scope of parameterized language element, the type of the formal variadic parameter shall be a `record of` of the specified type. There are three ways of passing an actual parameter to the formal variadic parameter when using the list notation: - The actual parameter is not present in the list of actual parameters or skipped by using the dash symbol. The actual parameter is equal to an empty record of value or template in this case. - Using comma-separated values of the specified type as the actual parameter. The actual variadic parameter is equal to a `record of` value that contains all the comma-separated values in their passing order. - Using a single parameter of a compatible `record of` the specified type followed by `...`. The actual parameter is passed directly to the formal variadic parameter in this case. When using the assignment notation for an actual variadic parameter, the actual parameter shall be a value or template of a compatible record of the specified type without any additional ellipsis. The actual parameter is passed directly to the formal variadic parameter in this case. **Examples** ```ttcn3 example="invalid position" external function f(integer args..., integer n); // error external function g(integer args1..., integer args2...); // error ``` ```ttcn3 example="in parameters only" external function f(inout integer args...); // error external function g(out integer args...); // error ``` ```ttcn3 example="array notation" function f(integer args[3]...) { // expect: typeof(args) == "record of record length(3) of integer" } ``` ```ttcn3 example="passing variadic parameters" control { f(1,2,3); // var record of integer a := {1,2,3} f(a...); f(args := a); } function f(integer args...) { // expect: args == {1,2,3} } ``` ```ttcn3 example="pass empty argument" control { f(); f(-); f(args := {}); } function f(integer args...) { // expect: lengthof(args) == 0 } ``` ```ttcn3 example="default parameter" control { f(); f(-); } function f(integer args... := {1,2,3}) { // expect: args == {1,2,3} } ``` ### Actual parameters - semantically a parameter is a local variable - each activate frame is its own location - default parameter - assignment list notation allowed > NOTE 1: Reference to a string element cannot be passed by reference as string types are not structured types. Loading
src/19.1-assignments.md +2 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ and copies the result to the destination specified by the left hand side. The _primary expression_ on the left hand side shall specify an [addressable value]. - Mention expansion rules for templates and others Additional rules apply, if the right hand side is a value list literal or a assignment list literal. Loading @@ -46,6 +47,7 @@ a := { ``` - Reference to general Assignment-Mechanics: - Compatibility, Other places (parameters, for-range-loop, default-parameters, ...) - Value-Types, Reference-Types Loading