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>var</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="valueof.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td> | |
26 | <td><a href="variant.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>var</h1> | |
33 | <blockquote> | |
34 | <p>1. <a href="#1."> Declaring a variable of built-in type</a></p> | |
35 | <p>2. <a href="#2."> Declaring a variable of referenced type</a></p> | |
36 | <p>3. <a href="#3."> Multiple declaration of variables of the same type</a></p> | |
37 | <p>4. <a href="#4.">Declaring a variable array</a></p> | |
38 | </blockquote> | |
39 | <hr align="left" width="75%"> | |
40 | <h4><a name="1.">1. Declaring a variable of built-in type</a></h4> | |
41 | <hr align="left" width="50%"> | |
42 | <div align="center"> | |
43 | <center> | |
44 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
45 | <tr> | |
46 | <td width="100%"> | |
47 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>var </b></font> ( <font face="Courier New" color="#003258" size="5"><b>bitstring</b></font> | <font face="Courier New" | |
48 | color="#003258" size="5"><b>boolean</b></font> | <font face="Courier New" color="#003258" size="5"><b>charstring</b></font> | <font face="Courier New" color="#003258" size="5"><b>universal | |
49 | charstring</b></font> | <font face="Courier New" color="#003258" size="5"> <b>integer</b></font> | <font face="Courier New" color="#003258" size="5"> <b>octetstring</b></font> | <font face="Courier New" | |
50 | color="#003258" size="5"><b>objid</b></font> | <font face="Courier New" color="#003258" size="5"><b>hexstring</b></font> | <font face="Courier New" color="#003258" size="5"><b>verdicttype</b></font> | |
51 | | <font face="Courier New" color="#003258" size="5"><b>float</b></font> | <font face="Courier New" color="#003258" size="5"><b>address</b></font> | <font face="Courier New" color="#003258" | |
52 | size="5"><b>default</b></font> | <font face="Courier New" color="#003258" size="5"><b>anytype</b></font> ) <i>var_identifier </i> [<font face="Courier New" color="#003258" size="5"><b>:=</b></font> | |
53 | <i> single_variable_expression</i> ]<font face="Courier New" color="#003258" size="5"> <b>;</b></font></h3> | |
54 | </td> | |
55 | </tr> | |
56 | </table> | |
57 | </center> | |
58 | </div> | |
59 | <ul> | |
60 | <li> | |
61 | <p>The <font face="Courier New" color="#003258" size="4"><b>var</b></font> keyword introduces the variable definition.</p> | |
62 | </li> | |
63 | <li> | |
64 | <p><a href="bitstring.html" name="par1"><font face="Courier New" color="#003258" size="4"><b>bitstring</b></font></a> denotes an a type whose distinguished values are the ordered sequences of | |
65 | zero, one, or more bits.</p> | |
66 | </li> | |
67 | <li> | |
68 | <p><a href="boolean.html"><font face="Courier New" color="#003258" size="4"><b>boolean</b></font></a> is a simple basic type consisting of two distinguished values (namely true or false).</p> | |
69 | </li> | |
70 | <li> | |
71 | <p><a href="charstring.html"><font face="Courier New" color="#003258" size="4"><b>charstring</b></font></a> denotes a type whose distinguished values are the ordered sequences of characters of | |
72 | ISO/IEC 646 as described in ITU-T Recommendation T.50.</p> | |
73 | </li> | |
74 | <li> | |
75 | <p><a href="universal.html"><font face="Courier New" color="#003258" size="4"><b>universal charstring</b></font></a> denotes a type whose distinguished values are the ordered sequences of UCS-4 | |
76 | coded representation of ISO/IEC 10646 characters.</p> | |
77 | </li> | |
78 | <li> | |
79 | <p><a href="integer.html"><font face="Courier New" color="#003258" size="4"><b>integer</b></font></a> denotes a a type with distinguished values which are the positive and negative whole | |
80 | numbers, including zero.</p> | |
81 | </li> | |
82 | <li> | |
83 | <p><a href="octetstring.html"><font face="Courier New" color="#003258" size="4"><b>octetstring</b></font></a> stands for a a type whose distinguished values are the ordered sequences of zero or | |
84 | a positive even number of hexadecimal digits (every pair of digits corresponding to an ordered sequence of eight bits).</p> | |
85 | </li> | |
86 | <li> | |
87 | <p><a href="objid.html"><font face="Courier New" color="#003258" size="4"><b>objid</b></font></a> defines a type whose distinguished values are the set of all object identifiers conforming to | |
88 | clause 6.2 of ITU-T Recommendation X.660.</p> | |
89 | </li> | |
90 | <li> | |
91 | <p><a href="hexstring.html"><font face="Courier New" color="#003258" size="4"><b>hexstring</b></font></a> defines a type whose distinguished values are the ordered sequences of zero, one, or | |
92 | more hexadecimal digits, each corresponding to an ordered sequence of four bits.</p> | |
93 | </li> | |
94 | <li> | |
95 | <p><a href="verdicttype.html"><font face="Courier New" color="#003258" size="4"><b>verdicttype</b></font></a> defines a type for use with test verdicts consisting of 5 distinguished values.</p> | |
96 | </li> | |
97 | <li> | |
98 | <p><a href="float.html"><font face="Courier New" color="#003258" size="4"><b>float</b></font></a> defines a type to describe floating-point numbers.</p> | |
99 | </li> | |
100 | <li> | |
101 | <p><a href="address.html"><font face="Courier New" color="#003258" size="4"><b>address</b></font></a> denotes a user defined type to allow addressing specific entities inside the system under | |
102 | test.</p> | |
103 | </li> | |
104 | <li> | |
105 | <p><a href="default.html"><font face="Courier New" color="#003258" size="4"><b>default</b></font></a> is a reference to an activated default resulting from an activate operation.</p> | |
106 | </li> | |
107 | </ul> | |
108 | <div align="center"> | |
109 | <center> | |
110 | <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4"> | |
111 | <tr> | |
112 | <td width="100%"> | |
113 | <blockquote> <u>TITAN specific restriction compared to the standard</u>: anytype is not implemented yet.</blockquote> | |
114 | <ul> | |
115 | <li> | |
116 | <p><a href="anytype.html"><font face="Courier New" color="#003258" size="4"><b>anytype</b></font></a> defines as a shorthand for the union of all defined types, imported ASN.1 and other | |
117 | imported external types.</p> | |
118 | </li> | |
119 | </ul> | |
120 | </td> | |
121 | </tr> | |
122 | </table> | |
123 | </center> | |
124 | </div> | |
125 | <ul> | |
126 | <li> | |
127 | <p><i>var_identifier</i> is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters. <br> | |
128 | According to the Naming convention, the following prefixes are recommended: </p> | |
129 | <ul> | |
130 | <li><b>v_</b> for variables declared in the test component type definition,</li> | |
131 | <li><b>vc_</b> for variables defined within a component type and used to store component instance references (returned by a <b><font face="Courier New">create</font></b> operation),</li> | |
132 | <li><b>vd_</b> for variables defined within a component type used to store references to activated defaults (returned by an <b><font face="Courier New">activate</font></b> statement),;</li> | |
133 | <li><b>vl_</b> for variables declared in testcases, functions, altsteps, block of statements or in the control part,</li> | |
134 | <li><b>vlc_</b> for variables defined in testcases or functions and used to store component instance references (returned by a <b><font face="Courier New">create</font></b> operation),</li> | |
135 | <li> | |
136 | <p><b>vld_</b> for variables defined in testcases or functions used to store references to activated defaults (returned by an <b><font face="Courier New">activate</font></b> statement),</p> | |
137 | </li> | |
138 | </ul> | |
139 | </li> | |
140 | <li> | |
141 | <p>The optional <i>single_variable_expression</i> is used to define an initial value. It may contain variables and literal values as operands. The result of the expression must correspond to the | |
142 | type of the variable.</p> | |
143 | </li> | |
144 | </ul> | |
145 | <p><a href="#Ex1">Example</a></p> | |
146 | <hr align="left" width="75%" color="#0094D2"> | |
147 | <h4><a name="2.">2. Declaring a variable of referenced type</a></h4> | |
148 | <hr align="left" width="50%" color="#0094D2"> | |
149 | <div align="center"> | |
150 | <center> | |
151 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
152 | <tr> | |
153 | <td width="100%"> | |
154 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>var </b></font> [ <i>module_id</i> [.<i>obj_id</i> ].] <i>type_reference</i> [.<i>field_reference</i> ] <i>var_identifier </i> | |
155 | [<font face="Courier New" color="#003258" size="5"><b>:=</b></font> <br> | |
156 | <i>single_variable_expression</i> | <i>value_list</i> | <i>value_assginment_list</i> ]<font face="Courier New" color="#003258" size="5"><b>;</b></font></h3> | |
157 | </td> | |
158 | </tr> | |
159 | </table> | |
160 | </center> | |
161 | </div> | |
162 | <ul> | |
163 | <li> | |
164 | <p>The <font face="Courier New" color="#003258" size="4"><b>var</b></font> keyword introduces the variable definition.</p> | |
165 | </li> | |
166 | <li> | |
167 | <p><i><a href="BNF.html#moduleidentifier">module_id</a></i> is needed when the referenced type is defined in another TTCN-3 module and denotes the name of that module.</p> | |
168 | </li> | |
169 | </ul> | |
170 | <div align="center"> | |
171 | <center> | |
172 | <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4"> | |
173 | <tr> | |
174 | <td width="100%"> | |
175 | <blockquote> <u>TITAN specific restriction compared to the standard</u>: objid is not implemented yet; it is discarded when encountered.</blockquote> | |
176 | <ul> | |
177 | <li> | |
178 | <p><i><a href="BNF.html#objidcomponent">obj_id</a></i> is an optional object identifier which may follow the TTCN-3 module identifier.</p> | |
179 | </li> | |
180 | </ul> | |
181 | </td> | |
182 | </tr> | |
183 | </table> | |
184 | </center> | |
185 | </div> | |
186 | <ul> | |
187 | <li> | |
188 | <p><i><a name="par2">type_reference</a></i> refers to an already defined (structured or simple) <a href="type.html">type</a>.</p> | |
189 | </li> | |
190 | </ul> | |
191 | <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4"> | |
192 | <tr> | |
193 | <td width="100%"> | |
194 | <blockquote> <u>TITAN specific restriction compared to the standard</u>: field reference can only be used with structured variables defined in the module definition | |
195 | part.</blockquote> | |
196 | <ul> | |
197 | <p> | |
198 | <li><i><a href="BNF.html#extendedfieldreference">field_reference</a></i> optionally stands for a field of a structured type. | |
199 | </p> | |
200 | </li> | |
201 | </ul> | |
202 | </td> | |
203 | </tr> | |
204 | </table> | |
205 | <ul> | |
206 | <li> | |
207 | <p><i>var_identifier</i> is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters.</p> | |
208 | </li> | |
209 | <li> | |
210 | <p>The optional <a href="BNF.html#singleconstexpression"><i>single_variable_expression</i> </a> may contain variables and literal values as operands. The result of the expression | |
211 | must correspond to the type of the variable. Used with simple types to define an initial value.</p> | |
212 | </li> | |
213 | <li> | |
214 | <p>The optional <a href="BNF.html#arrayconstexpression"><i>value_list</i></a> is a comma-separated list of the variable values between curly brackets. Used with structured types | |
215 | to define an initial value</p> | |
216 | </li> | |
217 | </ul> | |
218 | <div align="center"> | |
219 | <center> | |
220 | <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4"> | |
221 | <tr> | |
222 | <td width="100%"> | |
223 | <blockquote> <u>TITAN specific restriction compared to the standard</u>: value assignment can only be used with structured variables defined in the module definition | |
224 | part.</blockquote> | |
225 | <ul> | |
226 | <li> | |
227 | <p>The optional <a href="BNF.html#fieldconstexpressionspec"><i>value_assignment_list</i></a> is a comma-separated list of the field name - variable value pairs between curly | |
228 | brackets. Used with structured types to define an initial value.</p> | |
229 | </li> | |
230 | </ul> | |
231 | </td> | |
232 | </tr> | |
233 | </table> | |
234 | </center> | |
235 | </div> | |
236 | <p><a href="#Ex2">Example</a></p> | |
237 | <hr align="left" width="75%" color="#0094D2"> | |
238 | <h4><a name="3.">3. Multiple declaration of variables of the same type</a></h4> | |
239 | <hr align="left" width="50%" color="#0094D2"> | |
240 | <div align="center"> | |
241 | <center> | |
242 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
243 | <tr> | |
244 | <td width="100%"> | |
245 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>var </b></font> <i>type </i> <i>identifier<sub>1</sub> </i>[ <font face="Courier New" color="#003258" | |
246 | size="5"> <b>:=</b></font> <i> variable_expression<sub>1</sub></i><font face="Courier New" color="#003258" size="5"><b>],</b></font><i> identifier<sub>2</sub> </i> [<font face="Courier New" | |
247 | color="#003258" size="5"><b>:=</b></font> <i> variable_expression<sub>2</sub> </i>]<i>…</i> <font face="Courier New" color="#003258" size="5"> <b>;</b></font></h3> | |
248 | </td> | |
249 | </tr> | |
250 | </table> | |
251 | </center> | |
252 | </div> | |
253 | <ul> | |
254 | <li> | |
255 | <p>The <font face="Courier New" color="#003258" size="4"><b>var</b></font> keyword introduces the variable definition.</p> | |
256 | </li> | |
257 | <li> | |
258 | <p align="left"><i>type</i> is one of the built-in types mentioned in <a href="#par1">paragraph 1</a> or referenced types mentioned in <a href="#par2">paragraph 2</a> .</p> | |
259 | </li> | |
260 | <li> | |
261 | <p><i>identifier<sub>n</sub></i> is the name used to refer to the n<sup>th</sup> variable.</p> | |
262 | </li> | |
263 | <li> | |
264 | <p>The optional <i>variable_expression<sub>n</sub></i> determines the initial value of the n<sup>th</sup> variable.</p> | |
265 | </li> | |
266 | </ul> | |
267 | <p><a href="#Ex3">Example</a></p> | |
268 | <hr align="left" width="75%" color="#0094D2"> | |
269 | <h4><a name="4.">4. Declaring a variable array</a></h4> | |
270 | <hr align="left" width="50%" color="#0094D2"> | |
271 | <div align="center"> | |
272 | <center> | |
273 | <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4"> | |
274 | <tr> | |
275 | <td width="100%"> | |
276 | <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>var </b></font> <i>type var_identifier </i> <font face="Courier New" color="#003258" size="5"><b>[ </b></font> <i>array_index</i> | |
277 | <font face="Courier New" color="#003258" size="5"><b> ]</b> </font>[<font face="Courier New" color="#003258" size="5"><b>:=</b></font> <i>value_list</i><font face="Courier New" color="#003258" | |
278 | size="5">]<b>;</b></font></h3> | |
279 | </td> | |
280 | </tr> | |
281 | </table> | |
282 | </center> | |
283 | </div> | |
284 | <ul> | |
285 | <li> | |
286 | <p>The <font face="Courier New" color="#003258" size="4"><b>var</b></font> keyword introduces the variable definition.</p> | |
287 | </li> | |
288 | <li> | |
289 | <p align="left"><i>type</i> is one of the built-in types mentioned in <a href="#par1">paragraph 1</a> or referenced types mentioned in <a href="#par2">paragraph 2</a> .</p> | |
290 | </li> | |
291 | <li> | |
292 | <p><i>var_identifier</i> is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters.</p> | |
293 | </li> | |
294 | <li> | |
295 | <p><i><a href="BNF.html#arraydef">array index</a></i> is a non-negative integer value corresponding to the number of elements in the array. <br> | |
296 | Alternatively, the lower and upper index values are given joined by two dots.</p> | |
297 | </li> | |
298 | <li> | |
299 | <p>The optional <a href="BNF.html#arrayconstexpression"><i>value_list</i> </a> is a comma-separated list of the initial variable values between curly brackets.</p> | |
300 | </li> | |
301 | </ul> | |
302 | <p><a href="#Ex4">Example</a></p> | |
303 | <hr align="left" width="50%"> | |
304 | <hr align="left" width="50%"> | |
305 | <p><a name="Ex1">Example 1a</a>: | |
306 | <p><font face="Courier New">var integer v_myVariable := 127;</font> | |
307 | <p>A variable called v_MyVariable is defined. The variable will have the initial value one hundred twenty seven.</p> | |
308 | <hr align="left" width="50%"> | |
309 | <p>Example 1b: | |
310 | <p><font face="Courier New">var bitstring v_myGarland := '00101101'B; <br> | |
311 | var bitstring v_myBiggerGarland := v_myGarland & '11000010'B;</font></p> | |
312 | <p>Two variables are defined. The one called v_myBiggerGarland initially will have the binary value 11101111.</p> | |
313 | <hr align="left" width="50%"> | |
314 | <p><a name="Ex2">Example 2a</a>: | |
315 | <p><font face="Courier New">type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere</font></p> | |
316 | <p><font face="Courier New">var Elsewhere.E_Rec v_CurrVar := {17, true};</font></p> | |
317 | <p>A record called E_Rec have been defined in the TTCN-3 module Elsewhere. In the current module we define a variable named v_CurrVar and assign values to all of its fields. In TITAN, the value | |
318 | notation as shown above may only be used in the module definition part.</p> | |
319 | <hr align="left" width="50%"> | |
320 | <p>Example 2b: | |
321 | <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field}; <br> | |
322 | var G_Rec.last_field v_FuzerVar;</font></p> | |
323 | <p>First we define a record called G_Rec. Then we define a variable named v_FuzerVar derived from the second field of the referred type and assign no initial value to it. </p> | |
324 | <hr align="left" width="50%"> | |
325 | <p>Example 2c: | |
326 | <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field}; <br> | |
327 | var G_Rec v_UeppigVar := {<br> | |
328 | first_field := 5.77,<br> | |
329 | last_field := '55'H;<br> | |
330 | }</font></p> | |
331 | <p>First we define a record called G_Rec. Then we define a variable named v_UeppigVar and assign initial values to both of its fields using assignment notation.</p> | |
332 | <hr align="left" width="50%"> | |
333 | <p><a name="Ex3">Example 3</a>: | |
334 | <p><font face="Courier New">var boolean v_MyVar2 := true, v_MyVar3;</font></p> | |
335 | <p>Two variables (v_MyVar2 and v_MyVar3) are declared within one operation. The latter variable has no initial value assigned.</p> | |
336 | <hr align="left" width="50%"> | |
337 | <p><a name="Ex4">Example 4a</a>: | |
338 | <p><font face="Courier New">var boolean v_MinVar[3] := { true, false, false };</font></p> | |
339 | <p>The array defined v_MinVar consists of three elements indexed from 0 to 2.</p> | |
340 | <hr align="left" width="50%"> | |
341 | <p>Example 4b: | |
342 | <p><font face="Courier New">var boolean v_DinVar[7..9] := { true, false, false };</font></p> | |
343 | <p>The array defined v_DinVar consists also of three elements as in the example 4a, but here the indices run from 7 to 9.</p> | |
344 | <hr align="left" width="25%"> | |
345 | <hr align="left" width="25%"> | |
346 | <p><a HREF="BNF.html#varinstance">BNF definition</a> of <font face="Courier New"> var</font></p> | |
347 | </body> | |
348 | </html> |