2 Copyright (c) 2000-2015 Ericsson Telecom AB
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
11 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8">
12 <meta http-equiv=
"Content-Language" content=
"en-us">
15 <body bgcolor=
"#DAD3C5" vlink=
"#0094D2" link=
"#003258">
16 <table align=
"left" border=
"0" cellspacing=
"0" cellpadding=
"0" valign=top
>
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>
21 <table border=
"0" align=
"right" cellpadding=
"0" cellspacing=
"0">
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>
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>
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%">
45 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
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
</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>
62 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>const
</b></font> keyword introduces the constant definition.
</p>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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>
111 <table border=
"0" width=
"100%" bgcolor=
"#C9C2BB" cellpadding=
"4">
114 <blockquote> <u>TITAN specific restriction compared to the standard
</u>: anytype is not implemented yet.
</blockquote>
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>
128 <p><i>const_identifier
</i> is the
name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.
<br>
129 According to the
Naming convention, the following prefixes are recommended:
</p>
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>
134 <p><b>cl_
</b> for constants declared elsewhere.
</p>
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>
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">
148 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
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
</i>
152 <font face=
"Courier New" color=
"#003258" size=
"5"> <b>:=
</b></font> <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>
161 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>const
</b></font> keyword introduces the constant definition.
</p>
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>
169 <table border=
"0" width=
"100%" bgcolor=
"#C9C2BB" cellpadding=
"4">
172 <blockquote> <u>TITAN specific restriction compared to the standard
</u>: objid
is not implemented yet; it is discarded when encountered.
</blockquote>
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>
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>
188 <table border=
"0" width=
"100%" bgcolor=
"#C9C2BB" cellpadding=
"4">
191 <blockquote> <u>TITAN specific restriction compared to the standard
</u>: field reference can only be used with structured constants defined in the module definition
195 <li><i><a href=
"BNF.html#extendedfieldreference">field_reference
</a></i> optionally stands for a field of a structured type.
204 <p><i>const_identifier
</i> is the
name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.
</p>
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>
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>
216 <table border=
"0" width=
"100%" bgcolor=
"#C9C2BB" cellpadding=
"4">
219 <blockquote> <u>TITAN specific restriction compared to the standard
</u>: value assignment can only be used with structured constants defined in the module definition
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>
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">
238 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
241 <h3 align=
"center"><font face=
"Courier New" color=
"#003258" size=
"5"><b>const
</b></font> <i>type
</i> <i>identifier
<sub>1</sub> </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> </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>
251 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>const
</b></font> keyword introduces the constant definition.
</p>
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>
257 <p><i>identifier
<sub>n
</sub></i> is the
name used to refer to the n
<sup>th
</sup> constant.
</p>
260 <p><i>constant_expression
<sub>n
</sub></i> determines the value of the n
<sup>th
</sup> constant.
</p>
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">
269 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
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>
281 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>const
</b></font> keyword introduces the constant definition.
</p>
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>
287 <p><i>const_identifier
</i> is the
name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.
</p>
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.
<br>
291 Alternatively, the lower and upper index values are given joined by two dots.
</p>
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>
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">
303 <table border=
"0" width=
"90%" bgcolor=
"#FFB599" cellpadding=
"4">
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>
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
319 <p>The
<font face=
"Courier New" color=
"#003258" size=
"4"><b>const
</b></font> keyword introduces the constant definition.
</p>
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>
325 <p><i>const_identifier
</i> is the
name used to refer to the constant. Must begin with a letter, may contain letters, numbers and underscore characters.
</p>
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>
336 <p><font face=
"Courier New">const bitstring c_myGarland := '
00101101'B;
<br>
337 const bitstring c_myBiggerGarland := c_myGarland
& '
11000010'B;
</font></p>
338 <p>Two constants are defined. The one called c_myBiggerGarland will have the binary value
11101111.
</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>
347 <p><font face=
"Courier New">type record G_Rec {float first_field, hexstring last_field};
<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.
</p>
352 <p><font face=
"Courier New">type record G_Rec {float first_field, hexstring last_field};
<br>
353 const G_Rec c_UeppigConst := {
<br>
354 first_field :=
5.77,
<br>
355 last_field := '
55'H;
<br>
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>
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.
</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>
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>
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>