Debian Codegraph @

help/info/const.html

raw symbols SCIP
1 <!--
2 Copyright (c) 2000-2021 Ericsson Telecom AB
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Eclipse Public License v2.0
5 which accompanies this distribution, and is available at
6 https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
7
8 Contributors:
9 Baji, Laszlo
10 Balasko, Jeno
11 Farkas, Laszlo
12 Feher, Csaba
13 Szabados, Kristof
14 -->
15 <html>
16 <head>
17 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
18 <meta http-equiv="Content-Language" content="en-us">
19 <title>const</title>
20 </head>
21 <body bgcolor="#DAD3C5" vlink="#0094D2" link="#003258">
22 <table align="left" border="0" cellspacing="0" cellpadding="0" valign=top>
23 <tr>
24 <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>
25 </tr>
26 </table>
27 <table border="0" align="right" cellpadding="0" cellspacing="0">
28 <tr>
29 <td><a href="../titan_main.html" alt="contents"><img border="0" src="../images/ao.jpg" width="53" height="40"></a></td>
30 <td><a href="../titan_index.html" alt="index"><img border="0" src="../images/up.jpg" width="53" height="40"></a></td>
31 <td><a href="connect.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td>
32 <td><a href="continue.html" alt="next"><img border="0" src="../images/right.jpg" width="53" height="40"></a></td>
33 </tr>
34 </table>
35 <p><br clear="all">
36 </p>
37 <hr>
38 <h1>const</h1>
39 <blockquote>
40 <p>1. <a href="#1."> Declaring a constant of built-in type</a></p>
41 <p>2. <a href="#2."> Declaring a constant of referenced type</a></p>
42 <p>3. <a href="#3."> Multiple declaration of constants of the same type</a></p>
43 <p>4. <a href="#4.">Declaring a constant array</a></p>
44 <p>5. <a href="#5."> Declaring an external constant</a></p>
45 </blockquote>
46 <hr align="left" width="75%">
47 <h4><a name="1.">1. Declaring a constant of built-in type</a></h4>
48 <hr align="left" width="50%">
49 <div align="center">
50 <center>
51 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
52 <tr>
53 <td width="100%">
54 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>const </b></font> ( <font face="Courier New" color="#003258" size="5"><b>bitstring</b></font> | <font
55 face="Courier New" 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
56 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"
57 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>
58 | <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"
59 size="5"><b>default</b></font> | <font face="Courier New" color="#003258" size="5"><b>anytype</b></font> ) <i>const_identifier&nbsp;</i> <font face="Courier New" color="#003258" size="5">
60 <b>:=</b></font> <i> single_constant_expression</i> <font face="Courier New" color="#003258" size="5"> <b>;</b></font></h3>
61 </td>
62 </tr>
63 </table>
64 </center>
65 </div>
66 <ul>
67 <li>
68 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
69 </li>
70 <li>
71 <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
72 zero, one, or more bits.</p>
73 </li>
74 <li>
75 <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>
76 </li>
77 <li>
78 <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
79 ISO/IEC 646 as described in ITU-T Recommendation T.50.</p>
80 </li>
81 <li>
82 <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
83 coded representation of ISO/IEC 10646 characters.</p>
84 </li>
85 <li>
86 <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
87 numbers, including zero.</p>
88 </li>
89 <li>
90 <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
91 a positive even number of hexadecimal digits (every pair of digits corresponding to an ordered sequence of eight bits).</p>
92 </li>
93 <li>
94 <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
95 clause 6.2 of ITU-T Recommendation X.660.</p>
96 </li>
97 <li>
98 <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
99 more hexadecimal digits, each corresponding to an ordered sequence of four bits.</p>
100 </li>
101 <li>
102 <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>
103 </li>
104 <li>
105 <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>
106 </li>
107 <li>
108 <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
109 test.</p>
110 </li>
111 <li>
112 <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>
113 </li>
114 </ul>
115 <div align="center">
116 <center>
117 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
118 <tr>
119 <td width="100%">
120 <blockquote>&nbsp;&nbsp;&nbsp;<u>TITAN specific restriction compared to the standard</u>: anytype is not implemented yet.</blockquote>
121 <ul>
122 <li>
123 <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
124 imported external types.</p>
125 </li>
126 </ul>
127 </td>
128 </tr>
129 </table>
130 </center>
131 </div>
132 <ul>
133 <li>
134 <p><i>const_identifier</i> is the&nbsp;name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.&nbsp;<br>
135 According to the&nbsp; Naming convention, the following prefixes are recommended:&nbsp;</p>
136 <ul>
137 <li><b>cg_</b> for global constants (defined in the module declaration part),</li>
138 <li><b>c_</b> for constants declared in componets and</li>
139 <li>
140 <p><b>cl_</b> for constants declared elsewhere.</p>
141 </li>
142 </ul>
143 </li>
144 <li>
145 <p><i>single_constant_expression</i> may contain constants and literal values as operands. The result of the expression must correspond to the type of the constant.</p>
146 </li>
147 </ul>
148 <p><a href="#Ex1">Example</a></p>
149 <hr align="left" width="75%" color="#0094D2">
150 <h4><a name="2.">2. Declaring a constant of referenced type</a></h4>
151 <hr align="left" width="50%" color="#0094D2">
152 <div align="center">
153 <center>
154 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
155 <tr>
156 <td width="100%">
157 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>const </b></font> [ <i>module_id</i> [.<i>obj_id</i> ].] <i>type_reference</i> [.<i>field_reference</i> ] <i>const_identifier&nbsp;</i>
158 <font face="Courier New" color="#003258" size="5"> <b>:=</b></font> &nbsp;<br>
159 (<i>single_constant_expression</i> | <i>value_list</i> | <i>value_assginment_list</i>)<font face="Courier New" color="#003258" size="5"><b>;</b></font></h3>
160 </td>
161 </tr>
162 </table>
163 </center>
164 </div>
165 <ul>
166 <li>
167 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
168 </li>
169 <li>
170 <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>
171 </li>
172 </ul>
173 <div align="center">
174 <center>
175 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
176 <tr>
177 <td width="100%">
178 <blockquote>&nbsp;&nbsp;&nbsp;<u>TITAN specific restriction compared to the standard</u>: objid&nbsp; is not implemented yet; it is discarded when encountered.</blockquote>
179 <ul>
180 <li>
181 <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>
182 </li>
183 </ul>
184 </td>
185 </tr>
186 </table>
187 </center>
188 </div>
189 <ul>
190 <li>
191 <p><i><a name="par2">type_reference</a></i> refers to an already defined (structured or simple) <a href="type.html">type</a>.</p>
192 </li>
193 </ul>
194 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
195 <tr>
196 <td width="100%">
197 <blockquote>&nbsp;&nbsp;&nbsp;<u>TITAN specific restriction compared to the standard</u>: field reference can only be used with structured constants defined in the module definition
198 part.</blockquote>
199 <ul>
200 <p>
201 <li><i><a href="BNF.html#extendedfieldreference">field_reference</a></i> optionally stands for a field of a structured type.
202 </p>
203 </li>
204 </ul>
205 </td>
206 </tr>
207 </table>
208 <ul>
209 <li>
210 <p><i>const_identifier</i> is the&nbsp;name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.</p>
211 </li>
212 <li>
213 <p><a href="BNF.html#singleconstexpression"><i>single_constant_expression</i> </a> may contain constants and literal values as operands. The result of the expression must
214 correspond to the type of the constant. Used with simple types.</p>
215 </li>
216 <li>
217 <p><a href="BNF.html#arrayconstexpression"><i>value_list</i> </a> is a comma-separated list of the constant values between curly brackets. Used with structured types.</p>
218 </li>
219 </ul>
220 <div align="center">
221 <center>
222 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
223 <tr>
224 <td width="100%">
225 <blockquote>&nbsp;&nbsp;&nbsp;<u>TITAN specific restriction compared to the standard</u>: value assignment can only be used with structured constants defined in the module definition
226 part.</blockquote>
227 <ul>
228 <li>
229 <p><a href="BNF.html#fieldconstexpressionspec"><i>value_assignment_list</i></a> is a comma-separated list of the field name - constant value pairs between curly brackets.
230 Used with structured types.</p>
231 </li>
232 </ul>
233 </td>
234 </tr>
235 </table>
236 </center>
237 </div>
238 <p><a href="#Ex2">Example</a></p>
239 <hr align="left" width="75%" color="#0094D2">
240 <h4><a name="3.">3. Multiple declaration of constants of the same type</a></h4>
241 <hr align="left" width="50%" color="#0094D2">
242 <div align="center">
243 <center>
244 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
245 <tr>
246 <td width="100%">
247 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>const </b></font> <i>type&nbsp;</i> <i>identifier<sub>1</sub>&nbsp;</i> <font face="Courier New" color="#003258"
248 size="5"> <b>:=</b></font> <i> constant_expression<sub>1</sub></i><font face="Courier New" color="#003258" size="5"><b>,</b></font><i> identifier<sub>2</sub>&nbsp;</i> <font face="Courier New"
249 color="#003258" size="5"> <b>:=</b></font> <i> constant_expression<sub>2</sub> …</i> <font face="Courier New" color="#003258" size="5"> <b>;</b></font></h3>
250 </td>
251 </tr>
252 </table>
253 </center>
254 </div>
255 <ul>
256 <li>
257 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
258 </li>
259 <li>
260 <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>
261 </li>
262 <li>
263 <p><i>identifier<sub>n</sub></i> is the&nbsp;name used to refer to the n<sup>th</sup> constant.</p>
264 </li>
265 <li>
266 <p><i>constant_expression<sub>n</sub></i> determines the value of the n<sup>th</sup> constant.</p>
267 </li>
268 </ul>
269 <p><a href="#Ex3">Example</a></p>
270 <hr align="left" width="75%" color="#0094D2">
271 <h4><a name="4.">4. Declaring a constant array</a></h4>
272 <hr align="left" width="50%" color="#0094D2">
273 <div align="center">
274 <center>
275 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
276 <tr>
277 <td width="100%">
278 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>const </b></font> <i>type const_identifier </i> <font face="Courier New" color="#003258" size="5"><b>[ </b></font> <i>array_index</i>
279 <font face="Courier New" color="#003258" size="5"><b> ] :=</b></font> <i>value_list</i><font face="Courier New" color="#003258" size="5"><b>;</b></font></h3>
280 </td>
281 </tr>
282 </table>
283 </center>
284 </div>
285 <ul>
286 <li>
287 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
288 </li>
289 <li>
290 <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>
291 </li>
292 <li>
293 <p><i>const_identifier</i> is the&nbsp;name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.</p>
294 </li>
295 <li>
296 <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.&nbsp;<br>
297 &nbsp;&nbsp;&nbsp; Alternatively, the lower and upper index values are given joined by two dots.</p>
298 </li>
299 <li>
300 <p><a href="BNF.html#arrayconstexpression"><i>value_list</i> </a> is a comma-separated list of the constant values between curly brackets.</p>
301 </li>
302 </ul>
303 <p><a href="#Ex4">Example</a></p>
304 <hr align="left" width="75%" color="#0094D2">
305 <h4><a name="5.">5. Declaring an external constant</a></h4>
306 <hr align="left" width="50%" color="#0094D2">
307 <div align="center">
308 <center>
309 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
310 <tr>
311 <td width="100%">
312 <h3 align="center"><font face="Courier New" color="#003258" size="5"><b>external const </b></font> <i>type const_identifier </i> <font face="Courier New" color="#003258" size="5"><b>;</b></font>
313 </h3>
314 </td>
315 </tr>
316 </table>
317 </center>
318 </div>
319 <ul>
320 <li>
321 <p>The <font face="Courier New" color="#003258" size="4"><b>external</b></font> keyword means that the constant is defined in a module other than TTCN-3 or ASN.1 (for example in a module written
322 in C++).</p>
323 </li>
324 <li>
325 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
326 </li>
327 <li>
328 <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>
329 </li>
330 <li>
331 <p><i>const_identifier</i> is the&nbsp;name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.</p>
332 </li>
333 </ul>
334 <p><a href="#Ex5">Example</a></p>
335 <hr align="left" width="50%">
336 <hr align="left" width="50%">
337 <p><a name="Ex1">Example 1a</a>:
338 <p><font face="Courier New">const integer c_myConstant := 127;</font>
339 <p>A constant called c_MyConstant is defined. The constant will have the value one hundred twenty seven.</p>
340 <p>&nbsp;</p>
341 <p>Example 1b:
342 <p><font face="Courier New">const bitstring c_myGarland := '00101101'B;&nbsp;<br>
343 const bitstring c_myBiggerGarland := c_myGarland &amp; '11000010'B;</font></p>
344 <p>Two constants are defined. The one called c_myBiggerGarland will have the binary value 11101111.</p>
345 <p>&nbsp;</p>
346 <p><a name="Ex2">Example 2a</a>:
347 <p><font face="Courier New">type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere</font></p>
348 <p><font face="Courier New">const Elsewhere.E_Rec c_CurrConst := {17, true};</font></p>
349 <p>A record called E_Rec have been defined in the TTCN-3 module Elsewhere. In the current module we define a constant named c_CurrConst and assign values to all of its fields. In TITAN, the value
350 notation as shown above may only be used in the module definition part.</p>
351 <p>&nbsp;</p>
352 <p>Example 2b:
353 <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field};&nbsp;<br>
354 const G_Rec.last_field c_FuzerConst := 'AA'H;</font></p>
355 <p>First we define a record called G_Rec. Then we define a constant named c_FuzerConst derived from the second field of the referred type and assign the hexadecimal value AA to it.&nbsp;</p>
356 <p>&nbsp;</p>
357 <p>Example 2c:
358 <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field};&nbsp;<br>
359 const G_Rec c_UeppigConst := {<br>
360 &nbsp;&nbsp;&nbsp; first_field := 5.77,<br>
361 &nbsp;&nbsp;&nbsp; last_field := '55'H;<br>
362 }</font></p>
363 <p>First we define a record called G_Rec. Then we define a constant named c_UeppigConst and assign values to both of its fields using assignment notation.</p>
364 <p>&nbsp;</p>
365 <p><a name="Ex3">Example 3</a>:
366 <p><font face="Courier New">const boolean c_MyConst2 := true, c_MyConst3 := false;</font></p>
367 <p>Two constants (c_MyConst2 and c_MyConst3) are declared within one operation.&nbsp;</p>
368 <p>&nbsp;</p>
369 <p><a name="Ex4">Example 4a</a>:
370 <p><font face="Courier New">const boolean c_MinConst[3] := { true, false, false };</font></p>
371 <p>The array defined c_MinConst consists of three elements indexed from 0 to 2.</p>
372 <p>&nbsp;</p>
373 <p>Example 4b:
374 <p><font face="Courier New">const boolean c_DinConst[7..9] := { true, false, false };</font></p>
375 <p>The array defined c_DinConst consists also of three elements as in the example 4a, but here the indices run from 7 to 9.</p>
376 <p>&nbsp;</p>
377 <p><a name="Ex5">Example 5</a>:
378 <p><font face="Courier New">external const objid MonConst;</font></p>
379 <p>The constant called MonConst (an object identifier) is defined in an external module, e.g. in a module written in C++.</p>
380 <hr align="left" width="25%">
381 <hr align="left" width="25%">
382 <p><a HREF="BNF.html#constdef">BNF definition</a> of <font face="Courier New"> const</font></p>
383 </body>
384 </html>