Update README.md
[deliverable/titan.core.git] / help / info / const.html
1 <!--
2 Copyright (c) 2000-2014 Ericsson Telecom AB
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>const</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="connect.html" alt="previous"><img border="0" src="../images/left.jpg" width="53" height="40"></a></td>
26 <td><a href="continue.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>const</h1>
33 <blockquote>
34 <p>1. <a href="#1."> Declaring a constant of built-in type</a></p>
35 <p>2. <a href="#2."> Declaring a constant of referenced type</a></p>
36 <p>3. <a href="#3."> Multiple declaration of constants of the same type</a></p>
37 <p>4. <a href="#4.">Declaring a constant array</a></p>
38 <p>5. <a href="#5."> Declaring an external constant</a></p>
39 </blockquote>
40 <hr align="left" width="75%">
41 <h4><a name="1.">1. Declaring a constant of built-in type</a></h4>
42 <hr align="left" width="50%">
43 <div align="center">
44 <center>
45 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
46 <tr>
47 <td width="100%">
48 <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
49 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
50 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"
51 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>
52 | <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"
53 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">
54 <b>:=</b></font> <i> single_constant_expression</i> <font face="Courier New" color="#003258" size="5"> <b>;</b></font></h3>
55 </td>
56 </tr>
57 </table>
58 </center>
59 </div>
60 <ul>
61 <li>
62 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
63 </li>
64 <li>
65 <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
66 zero, one, or more bits.</p>
67 </li>
68 <li>
69 <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>
70 </li>
71 <li>
72 <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
73 ISO/IEC 646 as described in ITU-T Recommendation T.50.</p>
74 </li>
75 <li>
76 <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
77 coded representation of ISO/IEC 10646 characters.</p>
78 </li>
79 <li>
80 <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
81 numbers, including zero.</p>
82 </li>
83 <li>
84 <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
85 a positive even number of hexadecimal digits (every pair of digits corresponding to an ordered sequence of eight bits).</p>
86 </li>
87 <li>
88 <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
89 clause 6.2 of ITU-T Recommendation X.660.</p>
90 </li>
91 <li>
92 <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
93 more hexadecimal digits, each corresponding to an ordered sequence of four bits.</p>
94 </li>
95 <li>
96 <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>
97 </li>
98 <li>
99 <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>
100 </li>
101 <li>
102 <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
103 test.</p>
104 </li>
105 <li>
106 <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>
107 </li>
108 </ul>
109 <div align="center">
110 <center>
111 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
112 <tr>
113 <td width="100%">
114 <blockquote>&nbsp;&nbsp;&nbsp;<u>TITAN specific restriction compared to the standard</u>: anytype is not implemented yet.</blockquote>
115 <ul>
116 <li>
117 <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
118 imported external types.</p>
119 </li>
120 </ul>
121 </td>
122 </tr>
123 </table>
124 </center>
125 </div>
126 <ul>
127 <li>
128 <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>
129 According to the&nbsp; Naming convention, the following prefixes are recommended:&nbsp;</p>
130 <ul>
131 <li><b>cg_</b> for global constants (defined in the module declaration part),</li>
132 <li><b>c_</b> for constants declared in componets and</li>
133 <li>
134 <p><b>cl_</b> for constants declared elsewhere.</p>
135 </li>
136 </ul>
137 </li>
138 <li>
139 <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>
140 </li>
141 </ul>
142 <p><a href="#Ex1">Example</a></p>
143 <hr align="left" width="75%" color="#0094D2">
144 <h4><a name="2.">2. Declaring a constant of referenced type</a></h4>
145 <hr align="left" width="50%" color="#0094D2">
146 <div align="center">
147 <center>
148 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
149 <tr>
150 <td width="100%">
151 <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>
152 <font face="Courier New" color="#003258" size="5"> <b>:=</b></font> &nbsp;<br>
153 (<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>
154 </td>
155 </tr>
156 </table>
157 </center>
158 </div>
159 <ul>
160 <li>
161 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
162 </li>
163 <li>
164 <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>
165 </li>
166 </ul>
167 <div align="center">
168 <center>
169 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
170 <tr>
171 <td width="100%">
172 <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>
173 <ul>
174 <li>
175 <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>
176 </li>
177 </ul>
178 </td>
179 </tr>
180 </table>
181 </center>
182 </div>
183 <ul>
184 <li>
185 <p><i><a name="par2">type_reference</a></i> refers to an already defined (structured or simple) <a href="type.html">type</a>.</p>
186 </li>
187 </ul>
188 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
189 <tr>
190 <td width="100%">
191 <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
192 part.</blockquote>
193 <ul>
194 <p>
195 <li><i><a href="BNF.html#extendedfieldreference">field_reference</a></i> optionally stands for a field of a structured type.
196 </p>
197 </li>
198 </ul>
199 </td>
200 </tr>
201 </table>
202 <ul>
203 <li>
204 <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>
205 </li>
206 <li>
207 <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
208 correspond to the type of the constant. Used with simple types.</p>
209 </li>
210 <li>
211 <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>
212 </li>
213 </ul>
214 <div align="center">
215 <center>
216 <table border="0" width="100%" bgcolor="#C9C2BB" cellpadding="4">
217 <tr>
218 <td width="100%">
219 <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
220 part.</blockquote>
221 <ul>
222 <li>
223 <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.
224 Used with structured types.</p>
225 </li>
226 </ul>
227 </td>
228 </tr>
229 </table>
230 </center>
231 </div>
232 <p><a href="#Ex2">Example</a></p>
233 <hr align="left" width="75%" color="#0094D2">
234 <h4><a name="3.">3. Multiple declaration of constants of the same type</a></h4>
235 <hr align="left" width="50%" color="#0094D2">
236 <div align="center">
237 <center>
238 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
239 <tr>
240 <td width="100%">
241 <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"
242 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"
243 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>
244 </td>
245 </tr>
246 </table>
247 </center>
248 </div>
249 <ul>
250 <li>
251 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
252 </li>
253 <li>
254 <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>
255 </li>
256 <li>
257 <p><i>identifier<sub>n</sub></i> is the&nbsp;name used to refer to the n<sup>th</sup> constant.</p>
258 </li>
259 <li>
260 <p><i>constant_expression<sub>n</sub></i> determines the value of the n<sup>th</sup> constant.</p>
261 </li>
262 </ul>
263 <p><a href="#Ex3">Example</a></p>
264 <hr align="left" width="75%" color="#0094D2">
265 <h4><a name="4.">4. Declaring a constant array</a></h4>
266 <hr align="left" width="50%" color="#0094D2">
267 <div align="center">
268 <center>
269 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
270 <tr>
271 <td width="100%">
272 <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>
273 <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>
274 </td>
275 </tr>
276 </table>
277 </center>
278 </div>
279 <ul>
280 <li>
281 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
282 </li>
283 <li>
284 <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>
285 </li>
286 <li>
287 <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>
288 </li>
289 <li>
290 <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>
291 &nbsp;&nbsp;&nbsp; Alternatively, the lower and upper index values are given joined by two dots.</p>
292 </li>
293 <li>
294 <p><a href="BNF.html#arrayconstexpression"><i>value_list</i> </a> is a comma-separated list of the constant values between curly brackets.</p>
295 </li>
296 </ul>
297 <p><a href="#Ex4">Example</a></p>
298 <hr align="left" width="75%" color="#0094D2">
299 <h4><a name="5.">5. Declaring an external constant</a></h4>
300 <hr align="left" width="50%" color="#0094D2">
301 <div align="center">
302 <center>
303 <table border="0" width="90%" bgcolor="#FFB599" cellpadding="4">
304 <tr>
305 <td width="100%">
306 <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>
307 </h3>
308 </td>
309 </tr>
310 </table>
311 </center>
312 </div>
313 <ul>
314 <li>
315 <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
316 in C++).</p>
317 </li>
318 <li>
319 <p>The <font face="Courier New" color="#003258" size="4"><b>const</b></font> keyword introduces the constant definition.</p>
320 </li>
321 <li>
322 <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>
323 </li>
324 <li>
325 <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>
326 </li>
327 </ul>
328 <p><a href="#Ex5">Example</a></p>
329 <hr align="left" width="50%">
330 <hr align="left" width="50%">
331 <p><a name="Ex1">Example 1a</a>:
332 <p><font face="Courier New">const integer c_myConstant := 127;</font>
333 <p>A constant called c_MyConstant is defined. The constant will have the value one hundred twenty seven.</p>
334 <p>&nbsp;</p>
335 <p>Example 1b:
336 <p><font face="Courier New">const bitstring c_myGarland := '00101101'B;&nbsp;<br>
337 const bitstring c_myBiggerGarland := c_myGarland &amp; '11000010'B;</font></p>
338 <p>Two constants are defined. The one called c_myBiggerGarland will have the binary value 11101111.</p>
339 <p>&nbsp;</p>
340 <p><a name="Ex2">Example 2a</a>:
341 <p><font face="Courier New">type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere</font></p>
342 <p><font face="Courier New">const Elsewhere.E_Rec c_CurrConst := {17, true};</font></p>
343 <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
344 notation as shown above may only be used in the module definition part.</p>
345 <p>&nbsp;</p>
346 <p>Example 2b:
347 <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field};&nbsp;<br>
348 const G_Rec.last_field c_FuzerConst := 'AA'H;</font></p>
349 <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>
350 <p>&nbsp;</p>
351 <p>Example 2c:
352 <p><font face="Courier New">type record G_Rec {float first_field, hexstring last_field};&nbsp;<br>
353 const G_Rec c_UeppigConst := {<br>
354 &nbsp;&nbsp;&nbsp; first_field := 5.77,<br>
355 &nbsp;&nbsp;&nbsp; last_field := '55'H;<br>
356 }</font></p>
357 <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>
358 <p>&nbsp;</p>
359 <p><a name="Ex3">Example 3</a>:
360 <p><font face="Courier New">const boolean c_MyConst2 := true, c_MyConst3 := false;</font></p>
361 <p>Two constants (c_MyConst2 and c_MyConst3) are declared within one operation.&nbsp;</p>
362 <p>&nbsp;</p>
363 <p><a name="Ex4">Example 4a</a>:
364 <p><font face="Courier New">const boolean c_MinConst[3] := { true, false, false };</font></p>
365 <p>The array defined c_MinConst consists of three elements indexed from 0 to 2.</p>
366 <p>&nbsp;</p>
367 <p>Example 4b:
368 <p><font face="Courier New">const boolean c_DinConst[7..9] := { true, false, false };</font></p>
369 <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>
370 <p>&nbsp;</p>
371 <p><a name="Ex5">Example 5</a>:
372 <p><font face="Courier New">external const objid MonConst;</font></p>
373 <p>The constant called MonConst (an object identifier) is defined in an external module, e.g. in a module written in C++.</p>
374 <hr align="left" width="25%">
375 <hr align="left" width="25%">
376 <p><a HREF="BNF.html#constdef">BNF definition</a> of <font face="Courier New"> const</font></p>
377 </body>
378 </html>
This page took 0.039685 seconds and 5 git commands to generate.