| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
<html> |
| 15 |
<head> |
| 16 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 17 |
<meta http-equiv="Content-Language" content="en-us"> |
| 18 |
<title>function</title> |
| 19 |
</head> |
| 20 |
<body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> |
| 21 |
<table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> |
| 22 |
<tr> |
| 23 |
<td width=105 height=40><a href="https://projects.eclipse.org/projects/tools.titan"><img src="../images/titan_transparent.gif" border=0 width=105 height=40 align="left" alt="Titan"></a></td> |
| 24 |
</tr> |
| 25 |
</table> |
| 26 |
<table border="0" align="right" cellpadding="0" cellspacing="0"> |
| 27 |
<tr> |
| 28 |
<td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> |
| 29 |
<td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> |
| 30 |
<td><a href="from.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> |
| 31 |
<td><a href="get_stringencoding.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> |
| 32 |
</tr> |
| 33 |
</table> |
| 34 |
<p><br clear="all"> |
| 35 |
</p> |
| 36 |
<hr> |
| 37 |
<h1>function</h1> |
| 38 |
<blockquote> |
| 39 |
<p>1. <a href="#4.">Declaring a function</a></p> |
| 40 |
<p>2. <a href="#5."> Declaring an external function</a></p> |
| 41 |
</blockquote> |
| 42 |
<p>Functions are used to determine test behavior, organize test execution and structure computation. They can be defined within a module or externally; restricted to a component or not. They may |
| 43 |
have parameters and return a single value.</p> |
| 44 |
<p>Related keywords:</p> |
| 45 |
<ul> |
| 46 |
<li><a href="in.html"><b><font face="Courier New" color="#003258" size="4">in</font></b></a></li> |
| 47 |
<li><a href="inout.html"><b><font face="Courier New" color="#003258" size="4">inout</font></b></a></li> |
| 48 |
<li><a href="out.html"><b><font face="Courier New" color="#003258" size="4">out</font></b></a></li> |
| 49 |
<li><a href="return.html"><b><font face="Courier New" color="#003258" size="4">return</font></b></a></li> |
| 50 |
<li><a href="runs.html"><b><font face="Courier New" color="#003258" size="4">runs</font></b></a> <a href="on.html"><b><font face="Courier New" color="#003258" size="4">on</font></b></a></li> |
| 51 |
<li><a href="template.html"><b><font face="Courier New" color="#003258" size="4">template</font></b></a></li> |
| 52 |
</ul> |
| 53 |
<hr align="left" width="75%"> |
| 54 |
<h4><a name="4.">1. Declaring a function</a></h4> |
| 55 |
<hr align="left" width="50%"> |
| 56 |
<div align="center"> |
| 57 |
<center> |
| 58 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 59 |
<tr> |
| 60 |
<td width="100%"> |
| 61 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>function</b></font><i> function_identifier </i> <font face="Courier New" color="#003258" size="5"><b>(</b></font> [<i> |
| 62 |
value </i>|<i>timer </i>|<i>template </i>|<i>port </i> ... ] <font face="Courier New" color="#003258" size="5"><b>)</b></font>[ <font face="Courier New" color="#003258" size="5"><b>runs |
| 63 |
on</b></font><i> component_reference </i>] [ <font face="Courier New" color="#003258" size="5"><b>return</b></font><i> returned_type </i>] <font face="Courier New" color="#003258" size="5"><b>{</b></font><i>statement_block</i><font |
| 64 |
face="Courier New" color="#003258" size="5"><b>};</b></font></h3> |
| 65 |
</td> |
| 66 |
</tr> |
| 67 |
</table> |
| 68 |
</center> |
| 69 |
</div> |
| 70 |
<ul> |
| 71 |
<li> |
| 72 |
<p>The <font face="Courier New" color="#003258" size="4"><b>function</b></font> keyword introduces the function definition.</p> |
| 73 |
</li> |
| 74 |
<li> |
| 75 |
<p><i>function_identifier</i> is the name used to refer to the function. Must begin with a letter, may contain letters, numbers and underscore characters. According to the <a |
| 76 |
href="../docs/naming.pdf" target="_blank">Naming convention</a>, the prefix <b> f_</b> is recommended.</p> |
| 77 |
</li> |
| 78 |
<li> |
| 79 |
<p><a name="inout"><i>value</i> </a> indicates a value parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="in.html"><font |
| 80 |
face="Courier New" size="4"><b>in</b></font></a>, <a href="out.html"><font face="Courier New" size="4"><b>out</b></font></a> or <a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 81 |
continues with a reference to a built-in type (cf. <a href="const.html#par1">their list</a>) or a <a href="type.html"> referenced type</a> and ends by a parameter |
| 82 |
identifier.</p> |
| 83 |
</li> |
| 84 |
<li> |
| 85 |
<p><i>timer</i> indicates a timer parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 86 |
continues with the keyword <font face="Courier New"><b>timer</b></font> and ends by a parameter identifier.</p> |
| 87 |
</li> |
| 88 |
<li> |
| 89 |
<p><a name="template"><i>template</i> </a> indicates a template parameter. A template parameter may hold values defined for the value parameter and, in addition, the special value omit, |
| 90 |
matching symbols (?, * etc.) and templates. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 91 |
continues with the keyword <font face="Courier New"><b>template</b></font>, a reference to a built-in type (cf. <a href="const.html#par1">their list</a>) or a <a href="type.html" |
| 92 |
target="_blank"> referenced type</a>and ends by a parameter identifier.</p> |
| 93 |
</li> |
| 94 |
<li> |
| 95 |
<p><i>port</i> indicates a port parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 96 |
continues with the port type identifier and ends by a parameter identifier.</p> |
| 97 |
</li> |
| 98 |
<li> |
| 99 |
<p><b>...</b> indicates that all kind of parameters (<i>value</i>, <i>timer</i>, <i>template</i> and <i>port</i>) may be repeated. They are separated by comma.</p> |
| 100 |
</li> |
| 101 |
<li> |
| 102 |
<p><a name="The optional">The optional</a> keywords <font face="Courier New" color="#003258" size="4"><b>runs on</b></font> restrict the function to a component.</p> |
| 103 |
</li> |
| 104 |
<li> |
| 105 |
<p><i>component_reference</i> refers to the component the function is tied to. It is composed of two parts: the module identifier (may be omitted) and the component tpye identifier. The two |
| 106 |
parts are linked by a dot.</p> |
| 107 |
</li> |
| 108 |
<li> |
| 109 |
<p><a name="return">The</a> optional keyword <font face="Courier New" color="#003258" size="4"><b>return</b></font> indicates that the function returns a value</p> |
| 110 |
</li> |
| 111 |
<li> |
| 112 |
<p align="left"><i>returned_type</i> is one of the built-in types (cf. <a href="const.html#par1">their list</a>) or <a href="type.html"> referenced types</a> |
| 113 |
determining what kind of a value will be returned</p> |
| 114 |
</li> |
| 115 |
<li> |
| 116 |
<p align="left"><i><a name="statement_block">statement_block</a></i> may contain both local definitions (of constants, variables and timers) visible only in the defined function and the program |
| 117 |
part describing the program behavior.</p> |
| 118 |
</li> |
| 119 |
</ul> |
| 120 |
<p><a href="#Ex4">Example</a></p> |
| 121 |
<hr align="left" width="75%" color="#0094D2"> |
| 122 |
<h4><a name="5.">2. Declaring an external function</a></h4> |
| 123 |
<hr align="left" width="50%" color="#0094D2"> |
| 124 |
<div align="center"> |
| 125 |
<center> |
| 126 |
<table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> |
| 127 |
<tr> |
| 128 |
<td width="100%"> |
| 129 |
<h3 align="center"><font face="Courier New" color="#003258" size="5"><b>external function</b></font><i> function_identifier </i> <font face="Courier New" color="#003258" size="5"><b>(</b></font> |
| 130 |
[<i> value </i>|<i>timer </i>|<i>template </i>|<i>port </i> ... ] <font face="Courier New" color="#003258" size="5"><b>)</b></font> [ <font face="Courier New" color="#003258" size="5"><b>return</b></font><i> |
| 131 |
returned_type </i>] <font face="Courier New" color="#003258" size="5"><b>;</b></font></h3> |
| 132 |
</td> |
| 133 |
</tr> |
| 134 |
</table> |
| 135 |
</center> |
| 136 |
</div> |
| 137 |
<ul> |
| 138 |
<li> |
| 139 |
<p>The <font face="Courier New" color="#003258" size="4"><b>external function</b></font> keywords mean that the function is defined in a module other than TTCN-3 or ASN.1 (for example in a |
| 140 |
module written in C++).</p> |
| 141 |
</li> |
| 142 |
<li> |
| 143 |
<p><i>function_identifier</i> is the name used to refer to the function. Must begin with a letter, may contain letters, numbers and underscore characters.</p> |
| 144 |
</li> |
| 145 |
<li> |
| 146 |
<p><i>value</i> indicates a value parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="in.html"><font face="Courier New" size="4"><b>in</b></font></a>, |
| 147 |
<a href="out.html"><font face="Courier New" size="4"><b>out</b></font></a> or <a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), continues with a reference to a |
| 148 |
built-in type (cf. <a href="const.html#par1">their list</a>) or a <a href="type.html">referenced type</a> and ends by a parameter identifier.</p> |
| 149 |
</li> |
| 150 |
<li> |
| 151 |
<p><i>timer</i> indicates a timer parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 152 |
continues with the keyword <font face="Courier New"><b>timer</b></font> and ends by a parameter identifier.</p> |
| 153 |
</li> |
| 154 |
<li> |
| 155 |
<p><i>template</i> indicates a template parameter. A template parameter may hold values defined for the value parameter and, in addition, the special value omit, matching symbols (?, * |
| 156 |
etc.) and templates. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 157 |
continues with the keyword <font face="Courier New"><b>template</b></font>, a reference to a built-in type (cf. <a href="const.html#par1">their list</a>) or a <a href="type.html" |
| 158 |
target="_blank"> referenced type</a>and ends by a parameter identifier.</p> |
| 159 |
</li> |
| 160 |
<li> |
| 161 |
<p><i>port</i> indicates a port parameter. The expression begins with an optional keyword indicating the parameter passing method (<a href="inout.html"><font face="Courier New" size="4"><b>inout</b></font></a>), |
| 162 |
continues with the port type identifier and ends by a parameter identifier.</p> |
| 163 |
</li> |
| 164 |
<li> |
| 165 |
<p><b>...</b> indicates that all kind of parameters (<i>value</i>, <i>timer</i>, <i>template</i> and <i>port</i>) may be repeated. They are separated by comma.</p> |
| 166 |
</li> |
| 167 |
<li> |
| 168 |
<p>The optional keyword <font face="Courier New" color="#003258" size="4"><b>return</b></font> indicates that the function returns a value</p> |
| 169 |
</li> |
| 170 |
<li> |
| 171 |
<p align="left"><i>returned_type</i> is one of the built-in types (cf. <a href="const.html#par1">their list</a>) or <a href="type.html"> referenced types</a> |
| 172 |
determining what kind of a value will be returned</p> |
| 173 |
</li> |
| 174 |
</ul> |
| 175 |
<p><a href="#Ex5">Example</a></p> |
| 176 |
<hr align="left" width="50%"> |
| 177 |
<hr align="left" width="50%"> |
| 178 |
<p><a name="Ex4">Example 1a</a>: |
| 179 |
<p><font face="Courier New">function f_MyF_1 (integer pl_1, boolean pl_2) {};</font></p> |
| 180 |
<p>The function f_MyF_1 has two input parameters (the integer pl_1 and the Boolean pl_2). No value is returned and the function is not restricted to a given component. The statement block is |
| 181 |
empty.</p> |
| 182 |
<p>Example 1b: |
| 183 |
<p><font face="Courier New">function f_MyF_2() return integer { return 28 };</font></p> |
| 184 |
<p>The function f_MyF_2 has no input parameters but an integer value is returned. The function is not restricted to a given component. The statement block is always returns the integer value 28.</p> |
| 185 |
<p>Example 1c: |
| 186 |
<p><font face="Courier New">function f_MyF_3() runs on MyCompType_CT {};</font></p> |
| 187 |
<p>The function f_MyF_3 has neither input parameters nor returns any value. The function is not restricted to the component MyCompType_CT. The statement block is empty.</p> |
| 188 |
<p><a name="Ex5">Example 2</a>: |
| 189 |
<p><font face="Courier New">external function f_Utifraan() return float;</font></p> |
| 190 |
<p>The function called f_Utifraan MonConst is defined in an external module, e.g. in a module written in C++. It has no input parameters but returns a floating point value.</p> |
| 191 |
<hr align="left" width="25%"> |
| 192 |
<hr align="left" width="25%"> |
| 193 |
<p><a HREF="BNF.html#functiondef">BNF definition</a> of <font face="Courier New"> function</font></p> |
| 194 |
</body> |
| 195 |
</html> |