Commit | Line | Data |
---|---|---|
970ed795 | 1 | <!-- |
3abe9331 | 2 | Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | |
4 | All rights reserved. This program and the accompanying materials | |
5 | are made available under the terms of the Eclipse Public License v1.0 | |
6 | which accompanies this distribution, and is available at | |
7 | http://www.eclipse.org/legal/epl-v10.html | |
8 | --> | |
9 | <html> | |
10 | <head> | |
11 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
12 | <meta http-equiv="Content-Language" content="en-us"> | |
13 | <title>function</title> | |
14 | </head> | |
15 | <body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258"> | |
16 | <table align="left" border="0" cellspacing="0" cellpadding="0" valign=top> | |
17 | <tr> | |
18 | <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> | |
19 | </tr> | |
20 | </table> | |
21 | <table border="0" align="right" cellpadding="0" cellspacing="0"> | |
22 | <tr> | |
23 | <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td> | |
24 | <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td> | |
25 | <td><a href="from.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> | |
26 | <td><a href="get_stringencoding.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td> | |
27 | </tr> | |
28 | </table> | |
29 | <p><br clear="all"> | |
30 | </p> | |
31 | <hr> | |
32 | <h1>function</h1> | |
33 | <blockquote> | |
34 | <p>1. <a href="#4.">Declaring a function</a></p> | |
35 | <p>2. <a href="#5."> Declaring an external function</a></p> | |
36 | </blockquote> | |
37 | <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 | |
38 | have parameters and return a single value.</p> | |
39 | <p>Related keywords:</p> | |
40 | <ul> | |
41 | <li><a href="in.html"><b><font face="Courier New" color="#003258" size="4">in</font></b></a></li> | |
42 | <li><a href="inout.html"><b><font face="Courier New" color="#003258" size="4">inout</font></b></a></li> | |
43 | <li><a href="out.html"><b><font face="Courier New" color="#003258" size="4">out</font></b></a></li> | |
44 | <li><a href="return.html"><b><font face="Courier New" color="#003258" size="4">return</font></b></a></li> | |
45 | <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> | |
46 | <li><a href="template.html"><b><font face="Courier New" color="#003258" size="4">template</font></b></a></li> | |
47 | </ul> | |
48 | <hr align="left" width="75%"> | |
49 | <h4><a name="4.">1. Declaring a function</a></h4> | |
50 | <hr align="left" width="50%"> | |
51 | <div align="center"> | |
52 | <center> | |
53 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
54 | <tr> | |
55 | <td width="100%"> | |
56 | <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> | |
57 | 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 | |
58 | 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 | |
59 | face="Courier New" color="#003258" size="5"><b>};</b></font></h3> | |
60 | </td> | |
61 | </tr> | |
62 | </table> | |
63 | </center> | |
64 | </div> | |
65 | <ul> | |
66 | <li> | |
67 | <p>The <font face="Courier New" color="#003258" size="4"><b>function</b></font> keyword introduces the function definition.</p> | |
68 | </li> | |
69 | <li> | |
70 | <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 | |
71 | href="../docs/naming.pdf" target="_blank">Naming convention</a>, the prefix <b> f_</b> is recommended.</p> | |
72 | </li> | |
73 | <li> | |
74 | <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 | |
75 | 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>), | |
76 | 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 | |
77 | identifier.</p> | |
78 | </li> | |
79 | <li> | |
80 | <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>), | |
81 | continues with the keyword <font face="Courier New"><b>timer</b></font> and ends by a parameter identifier.</p> | |
82 | </li> | |
83 | <li> | |
84 | <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, | |
85 | 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>), | |
86 | 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" | |
87 | target="_blank"> referenced type</a>and ends by a parameter identifier.</p> | |
88 | </li> | |
89 | <li> | |
90 | <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>), | |
91 | continues with the port type identifier and ends by a parameter identifier.</p> | |
92 | </li> | |
93 | <li> | |
94 | <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> | |
95 | </li> | |
96 | <li> | |
97 | <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> | |
98 | </li> | |
99 | <li> | |
100 | <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 | |
101 | parts are linked by a dot.</p> | |
102 | </li> | |
103 | <li> | |
104 | <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> | |
105 | </li> | |
106 | <li> | |
107 | <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> | |
108 | determining what kind of a value will be returned</p> | |
109 | </li> | |
110 | <li> | |
111 | <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 | |
112 | part describing the program behavior.</p> | |
113 | </li> | |
114 | </ul> | |
115 | <p><a href="#Ex4">Example</a></p> | |
116 | <hr align="left" width="75%" color="#0094D2"> | |
117 | <h4><a name="5.">2. Declaring an external function</a></h4> | |
118 | <hr align="left" width="50%" color="#0094D2"> | |
119 | <div align="center"> | |
120 | <center> | |
121 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
122 | <tr> | |
123 | <td width="100%"> | |
124 | <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> | |
125 | [<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> | |
126 | returned_type </i>] <font face="Courier New" color="#003258" size="5"><b>;</b></font></h3> | |
127 | </td> | |
128 | </tr> | |
129 | </table> | |
130 | </center> | |
131 | </div> | |
132 | <ul> | |
133 | <li> | |
134 | <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 | |
135 | module written in C++).</p> | |
136 | </li> | |
137 | <li> | |
138 | <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> | |
139 | </li> | |
140 | <li> | |
141 | <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>, | |
142 | <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 | |
143 | 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> | |
144 | </li> | |
145 | <li> | |
146 | <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>), | |
147 | continues with the keyword <font face="Courier New"><b>timer</b></font> and ends by a parameter identifier.</p> | |
148 | </li> | |
149 | <li> | |
150 | <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 (?, * | |
151 | 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>), | |
152 | 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" | |
153 | target="_blank"> referenced type</a>and ends by a parameter identifier.</p> | |
154 | </li> | |
155 | <li> | |
156 | <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>), | |
157 | continues with the port type identifier and ends by a parameter identifier.</p> | |
158 | </li> | |
159 | <li> | |
160 | <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> | |
161 | </li> | |
162 | <li> | |
163 | <p>The optional keyword <font face="Courier New" color="#003258" size="4"><b>return</b></font> indicates that the function returns a value</p> | |
164 | </li> | |
165 | <li> | |
166 | <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> | |
167 | determining what kind of a value will be returned</p> | |
168 | </li> | |
169 | </ul> | |
170 | <p><a href="#Ex5">Example</a></p> | |
171 | <hr align="left" width="50%"> | |
172 | <hr align="left" width="50%"> | |
173 | <p><a name="Ex4">Example 1a</a>: | |
174 | <p><font face="Courier New">function f_MyF_1 (integer pl_1, boolean pl_2) {};</font></p> | |
175 | <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 | |
176 | empty.</p> | |
177 | <p>Example 1b: | |
178 | <p><font face="Courier New">function f_MyF_2() return integer { return 28 };</font></p> | |
179 | <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> | |
180 | <p>Example 1c: | |
181 | <p><font face="Courier New">function f_MyF_3() runs on MyCompType_CT {};</font></p> | |
182 | <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> | |
183 | <p><a name="Ex5">Example 2</a>: | |
184 | <p><font face="Courier New">external function f_Utifraan() return float;</font></p> | |
185 | <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> | |
186 | <hr align="left" width="25%"> | |
187 | <hr align="left" width="25%"> | |
188 | <p><a HREF="BNF.html#functiondef">BNF definition</a> of <font face="Courier New"> function</font></p> | |
189 | </body> | |
190 | </html> |