1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Static Expressions and Static Subtypes</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-4-8.html">Previous</A> <A HREF="AA-4-9-1.html">Next</A></P>
<HR>
<H1> 4.9 Static Expressions and Static Subtypes</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> Certain expressions of a scalar or string type
are defined to be static. Similarly, certain discrete ranges are defined
to be static, and certain scalar and string subtypes are defined to be
static subtypes. [<A NAME="I2857"></A> <I>Static</I> means determinable
at compile time, using the declared properties or values of the program
entities.] <A NAME="I2858"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>As opposed
to more elaborate data flow analysis, etc. </FONT></DIV>
<H4 ALIGN=CENTER>Language Design Principles</H4>
<DIV Class="Paranum"><FONT SIZE=-2>1.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>For an expression to be static,
it has to be calculable at compile time.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Only scalar and string expressions
are static.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>To be static, an expression cannot
have any nonscalar, nonstring subexpressions (though it can have nonscalar
constituent <FONT FACE="Arial, Helvetica">name</FONT>s). A static scalar
expression cannot have any nonscalar subexpressions. There is one exception
-- a membership test for a string subtype can be static, and the result
is scalar, even though a subexpression is nonscalar.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The rules for evaluating static
expressions are designed to maximize portability of static calculations.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I2859"></A>A
static expression is [a scalar or string expression that is] one of the
following:</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">numeric_literal</FONT>;
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A <FONT FACE="Arial, Helvetica">numeric_literal</FONT>
is always a static expression, even if its expected type is not that
of a static subtype. However, if its value is explicitly converted to,
or qualified by, a nonstatic subtype, the resulting expression is nonstatic.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">string_literal</FONT> of
a static string subtype; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>4.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>That is,
the constrained subtype defined by the index range of the string is static.
Note that elementary values don't generally have subtypes, while composite
values do (since the bounds or discriminants are inherent in the value).
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">name</FONT> that denotes
the declaration of a named number or a static constant; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>5.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Note that
enumeration literals are covered by the <FONT FACE="Arial, Helvetica">function_call</FONT>
case. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">function_call</FONT> whose
<I>function_</I><FONT FACE="Arial, Helvetica">name</FONT> or <I>function_</I><FONT FACE="Arial, Helvetica">prefix</FONT>
statically denotes a static function, and whose actual parameters, if
any (whether given explicitly or by default), are all static expressions;
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>6.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This includes
uses of operators that are equivalent to <FONT FACE="Arial, Helvetica">function_call</FONT>s.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>an <FONT FACE="Arial, Helvetica">attribute_reference</FONT>
that denotes a scalar value, and whose <FONT FACE="Arial, Helvetica">prefix</FONT>
denotes a static scalar subtype;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Note that
this does not include the case of an attribute that is a function; a
reference to such an attribute is not even an expression. See above for
function <I>calls</I>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>An implementation may define the
staticness and other properties of implementation-defined attributes.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>an <FONT FACE="Arial, Helvetica">attribute_reference</FONT>
whose <FONT FACE="Arial, Helvetica">prefix</FONT> statically denotes
a statically constrained array object or array subtype, and whose <FONT FACE="Arial, Helvetica">attribute_designator</FONT>
is First, Last, or Length, with an optional dimension;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">type_conversion</FONT>
whose <FONT FACE="Arial, Helvetica">subtype_mark</FONT> denotes a static
scalar subtype, and whose operand is a static expression;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a <FONT FACE="Arial, Helvetica">qualified_expression</FONT>
whose <FONT FACE="Arial, Helvetica">subtype_mark</FONT> denotes a static
[(scalar or string)] subtype, and whose operand is a static expression;
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This rules
out the <FONT FACE="Arial, Helvetica">subtype_mark</FONT>'<FONT FACE="Arial, Helvetica">aggregate</FONT>
case. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Adding qualification
to an expression shouldn't make it nonstatic, even for strings. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a membership test whose <FONT FACE="Arial, Helvetica">simple_expression</FONT>
is a static expression, and whose <FONT FACE="Arial, Helvetica">range</FONT>
is a static range or whose <FONT FACE="Arial, Helvetica">subtype_mark</FONT>
denotes a static [(scalar or string)] subtype; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Clearly, we should
allow membership tests in exactly the same cases where we allow <FONT FACE="Arial, Helvetica">qualified_expression</FONT>s.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a short-circuit control form both of whose <FONT FACE="Arial, Helvetica">relation</FONT>s
are static expressions;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a static expression enclosed in parentheses. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B><A NAME="I2860"></A>Informally,
we talk about a <I>static value</I>. When we do, we mean a value specified
by a static expression. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The language
requires a static expression in a <FONT FACE="Arial, Helvetica">number_declaration</FONT>,
a numeric type definition, a <FONT FACE="Arial, Helvetica">discrete_choice</FONT>
(sometimes), certain representation items, an <FONT FACE="Arial, Helvetica">attribute_designator</FONT>,
and when specifying the value of a discriminant governing a <FONT FACE="Arial, Helvetica">variant_part</FONT>
in a <FONT FACE="Arial, Helvetica">record_aggregate</FONT> or <FONT FACE="Arial, Helvetica">extension_aggregate</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I2861"></A>A
<FONT FACE="Arial, Helvetica">name</FONT> <I>statically denotes</I> an
entity if it denotes the entity and: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It is a <FONT FACE="Arial, Helvetica">direct_name</FONT>,
expanded name, or <FONT FACE="Arial, Helvetica">character_literal</FONT>,
and it denotes a declaration other than a <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>;
or</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It is an <FONT FACE="Arial, Helvetica">attribute_reference</FONT>
whose <FONT FACE="Arial, Helvetica">prefix</FONT> statically denotes
some entity; or</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>It denotes a <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>
with a <FONT FACE="Arial, Helvetica">name</FONT> that statically denotes
the renamed entity. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>17.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B><FONT FACE="Arial, Helvetica">Selected_component</FONT>s
that are not expanded names and <FONT FACE="Arial, Helvetica">indexed_component</FONT>s
do not statically denote things. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I2862"></A>A
<I>static function</I> is one of the following: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>These are
the functions whose calls can be static expressions. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a predefined operator whose parameter and result types
are all scalar types none of which are descendants of formal scalar types;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a predefined concatenation operator whose result type is
a string type;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>an enumeration literal;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>a language-defined attribute that is a function, if the
<FONT FACE="Arial, Helvetica">prefix</FONT> denotes a static scalar subtype,
and if the parameter and result types are scalar. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Normal"> In any case, a generic formal subprogram is not
a static function.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2863"></A>A <I>static constant</I>
is a constant view declared by a full constant declaration or an <FONT FACE="Arial, Helvetica">object_renaming_declaration</FONT>
with a static nominal subtype, having a value defined by a static scalar
expression or by a static string expression whose value has a length
not exceeding the maximum length of a <FONT FACE="Arial, Helvetica">string_literal</FONT>
in the implementation. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A deferred
constant is not static; the view introduced by the corresponding full
constant declaration can be static. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>The reason for
restricting the length of static string constants is so that compilers
don't have to store giant strings in their symbol tables. Since most
string constants will be initialized from <FONT FACE="Arial, Helvetica">string_literal</FONT>s,
the length limit seems pretty natural. The reason for avoiding nonstring
types is also to save symbol table space. We're trying to keep it cheap
and simple (from the implementer's viewpoint), while still allowing,
for example, the link name of a pragma Import to contain a concatenation.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The length we're talking about
is the maximum number of characters in the value represented by a <FONT FACE="Arial, Helvetica">string_literal</FONT>,
not the number of characters in the source representation; the quotes
don't count.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2864"></A>A <I>static range</I> is
a <FONT FACE="Arial, Helvetica">range</FONT> whose bounds are static
expressions, [or a <FONT FACE="Arial, Helvetica">range_attribute_reference</FONT>
that is equivalent to such a <FONT FACE="Arial, Helvetica">range</FONT>.]
<A NAME="I2865"></A>A <I>static <FONT FACE="Arial, Helvetica">discrete_range</FONT></I>
is one that is a static range or is a <FONT FACE="Arial, Helvetica">subtype_indication</FONT>
that defines a static scalar subtype. The base range of a scalar type
is a static range, unless the type is a descendant of a formal scalar
type.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2866"></A>A <I>static subtype</I> is
either a <I>static scalar subtype</I> or a <I>static string subtype</I>.
<A NAME="I2867"></A>A static scalar subtype is an unconstrained scalar
subtype whose type is not a descendant of a formal scalar type, or a
constrained scalar subtype formed by imposing a compatible static constraint
on a static scalar subtype. <A NAME="I2868"></A>A static string subtype
is an unconstrained string subtype whose index subtype and component
subtype are static (and whose type is not a descendant of a formal array
type), or a constrained string subtype formed by imposing a compatible
static constraint on a static string subtype. In any case, the subtype
of a generic formal object of mode <B>in out</B>, and the result subtype
of a generic formal function, are not static. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>String subtypes
are the only composite subtypes that can be static. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.b</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Reason:
</B>The part about generic formal objects of mode <B>in out</B> is necessary
because the subtype of the formal is not required to have anything to
do with the subtype of the actual. For example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.c</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>subtype</B> Int10 <B>is</B> Integer <B>range</B> 1..10;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.d</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>generic</B><BR>
F : <B>in</B> <B>out</B> Int10;<BR>
<B>procedure</B> G;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.e</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>procedure</B> G <B>is</B><BR>
<B>begin</B><BR>
<B>case</B> F <B>is</B><BR>
<B>when</B> 1..10 => <B>null</B>;<BR>
--<I> Illegal!</I><BR>
<B>end</B> <B>case</B>;<BR>
<B>end</B> G;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.f</FONT></DIV>
<DIV Class="SmallExamples"><TT>X : Integer <B>range</B> 1..20;<BR>
<B>procedure</B> I <B>is</B> <B>new</B> G(F => X); --<I> OK.</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The <FONT FACE="Arial, Helvetica">case_statement</FONT>
is illegal, because the subtype of F is not static, so the choices have
to cover all values of Integer, not just those in the range 1..10. A
similar issue arises for generic formal functions, now that function
calls are object names. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I2869"></A>The
different kinds of <I>static constraint</I> are defined as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>A null constraint is always static;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2870"></A><A NAME="I2871"></A><A NAME="I2872"></A>A
scalar constraint is static if it has no <FONT FACE="Arial, Helvetica">range_constraint</FONT>,
or one with a static range;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2873"></A>An index constraint is static if each
<FONT FACE="Arial, Helvetica">discrete_range</FONT> is static, and each
index subtype of the corresponding array type is static;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I2874"></A>A discriminant constraint is static
if each <FONT FACE="Arial, Helvetica">expression</FONT> of the constraint
is static, and the subtype of each discriminant is static. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<DIV Class="Normal"> <A NAME="I2875"></A>A subtype is <I>statically
constrained</I> if it is constrained, and its constraint is static. An
object is <I>statically constrained</I> if its nominal subtype is statically
constrained, or if it is a static string constant. </DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> A static expression
is evaluated at compile time except when it is part of the right operand
of a static short-circuit control form whose value is determined by its
left operand. This evaluation is performed exactly, without performing
Overflow_Checks. For a static expression that is evaluated: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>The expression is illegal if its evaluation fails a language-defined
check other than Overflow_Check.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>35</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the expression is not part of a larger static expression,
then its value shall be within the base range of its expected type. Otherwise,
the value may be arbitrarily large or small.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>36</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>If the expression is of type <I>universal_real</I> and
its expected type is a decimal fixed point type, then its value shall
be a multiple of the <I>small</I> of the decimal type. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>36.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This means
that a <FONT FACE="Arial, Helvetica">numeric_literal</FONT> for a decimal
type cannot have ``extra'' significant digits. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37</FONT></DIV>
<DIV Class="Normal"> The last two restrictions above do not apply
if the expected type is a descendant of a formal scalar type (or a corresponding
actual type in an instance).</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Values outside
the base range are not permitted when crossing from the ``static'' domain
to the ``dynamic'' domain. This rule is designed to enhance portability
of programs containing static expressions. Note that this rule applies
to the exact value, not the value after any rounding or truncation. (See
below for the rounding and truncation requirements.)</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.b</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>Short-circuit
control forms are a special case: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.c</FONT></DIV>
<DIV Class="SmallExamples"><TT>N: <B>constant</B> := 0.0;<BR>
X: <B>constant</B> Boolean := (N = 0.0) <B>or</B> <B>else</B> (1.0/N > 0.5); --<I> Static.</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The declaration of X is legal,
since the divide-by-zero part of the expression is not evaluated. X is
a static constant equal to True.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>37.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>There is no requirement
to recheck these rules in an instance; the base range check will generally
be performed at run time anyway. </FONT></DIV>
<H4 ALIGN=CENTER>Implementation Requirements</H4>
<DIV Class="Paranum"><FONT SIZE=-2>38</FONT></DIV>
<DIV Class="Normal"> For a real static expression that is not part
of a larger static expression, and whose expected type is not a descendant
of a formal scalar type, the implementation shall round or truncate the
value (according to the Machine_Rounds attribute of the expected type)
to the nearest machine number of the expected type; if the value is exactly
half-way between two machine numbers, any rounding shall be performed
away from zero. If the expected type is a descendant of a formal scalar
type, no special rounding or truncating is required -- normal accuracy
rules apply (see <A HREF="AA-G.html">Annex G</A>). </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Discarding extended
precision enhances portability by ensuring that the value of a static
constant of a real type is always a machine number of the type. Deterministic
rounding of exact halves also enhances portability.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>When the expected type is a descendant
of a formal floating point type, extended precision (beyond that of the
machine numbers) can be retained when evaluating a static expression,
to ease code sharing for generic instantiations. For similar reasons,
normal (nondeterministic) rounding or truncating rules apply for descendants
of a formal fixed point type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Note
that the implementation of static expressions has to keep track of plus
and minus zero for a type whose Signed_Zeros attribute is True.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>38.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the only values of a
fixed point type are the multiples of the small, so a static conversion
to a fixed-point type, or division by an integer, must do truncation
to a multiple of small. It is not correct for the implementation to do
all static calculations in infinite precision.</FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>28 An expression can be static
even if it occurs in a context where staticness is not required. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Ramification:
</B>For example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39.b</FONT></DIV>
<DIV Class="SmallExamples"><TT>X : Float := Float'(1.0E+400) + 1.0 - Float'(1.0E+400);</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The expression is static, which
means that the value of X must be exactly 1.0, independent of the accuracy
or range of the run-time floating point implementation.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>39.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The following kinds of expressions
are never static: <FONT FACE="Arial, Helvetica">explicit_dereference</FONT>,
<FONT FACE="Arial, Helvetica">indexed_component</FONT>, <FONT FACE="Arial, Helvetica">slice</FONT>,
<B>null</B>, <FONT FACE="Arial, Helvetica">aggregate</FONT>, <FONT FACE="Arial, Helvetica">allocator</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>40</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>29 A static (or run-time)
<FONT FACE="Arial, Helvetica">type_conversion</FONT> from a real type
to an integer type performs rounding. If the operand value is exactly
half-way between two integers, the rounding is performed away from zero.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>40.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>We specify this
for portability. The reason for not choosing round-to-nearest-even, for
example, is that this method is easier to undo. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>40.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The attribute
Truncation (see <A HREF="AA-A-5-3.html">A.5.3</A>) can be used to perform
a (static) truncation prior to conversion, to prevent rounding. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>40.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>The
value of the literal 0E999999999999999999999999999999999999999999999
is zero. The implementation must take care to evaluate such literals
properly.</FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>41</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
static expressions:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>42</FONT></DIV>
<DIV Class="Examples"><TT>1 + 1 <I>-- 2</I><BR>
<B>abs</B>(-10)*3 <I>-- 30</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>43</FONT></DIV>
<DIV Class="Examples"><TT>Kilo : <B>constant</B> := 1000;<BR>
Mega : <B>constant</B> := Kilo*Kilo; <I>-- 1_000_000</I><BR>
Long : <B>constant</B> := Float'Digits*2;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44</FONT></DIV>
<DIV Class="Examples"><TT>Half_Pi : <B>constant</B> := Pi/2; <I>-- see <A HREF="AA-3-3-2.html">3.3.2</A></I><BR>
Deg_To_Rad : <B>constant</B> := Half_Pi/90;<BR>
Rad_To_Deg : <B>constant</B> := 1.0/Deg_To_Rad; <I>-- equivalent to 1.0/((3.14159_26536/2)/90)</I></TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>44.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2876"></A>The rules
for static expressions and static subtypes are generalized to allow more
kinds of compile-time-known expressions to be used where compile-time-known
values are required, as follows: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.b</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>Membership tests and short-circuit control forms may appear
in a static expression.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>44.c</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The bounds and length of statically constrained array objects
or subtypes are static.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>44.d</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The Range attribute of a statically constrained array subtype
or object gives a static range.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>44.e</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>A <FONT FACE="Arial, Helvetica">type_conversion</FONT>
is static if the <FONT FACE="Arial, Helvetica">subtype_mark</FONT> denotes
a static scalar subtype and the operand is a static expression.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>44.f</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>All numeric literals are now static, even if the expected
type is a formal scalar type. This is useful in <FONT FACE="Arial, Helvetica">case_statement</FONT>s
and <FONT FACE="Arial, Helvetica">variant_part</FONT>s, which both now
allow a value of a formal scalar type to control the selection, to ease
conversion of a package into a generic package. Similarly, named array
aggregates are also permitted for array types with an index type that
is a formal scalar type. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>44.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The rules for the evaluation of
static expressions are revised to require exact evaluation at compile
time, and force a machine number result when crossing from the static
realm to the dynamic realm, to enhance portability and predictability.
Exact evaluation is not required for descendants of a formal scalar type,
to simplify generic code sharing and to avoid generic contract model
problems.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.h</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>Static
expressions are legal even if an intermediate in the expression goes
outside the base range of the type. Therefore, the following will succeed
in Ada 95, whereas it might raise an exception in Ada 83: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.i</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>type</B> Short_Int <B>is</B> <B>range</B> -32_768 .. 32_767;<BR>
I : Short_Int := -32_768;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.j</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>This might raise an exception
in Ada 83 because "32_768" is out of range, even though "-32_768"
is not. In Ada 95, this will always succeed.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.k</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Certain expressions involving
string operations (in particular concatenation and membership tests)
are considered static in Ada 95.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.l</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The reason for this change is
to simplify the rule requiring compile-time-known string expressions
as the link name in an interfacing pragma, and to simplify the preelaborability
rules. </FONT></DIV>
<H4 ALIGN=CENTER>Incompatibilities With Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>44.m</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I2877"></A>An Ada 83
program that uses an out-of-range static value is illegal in Ada 95,
unless the expression is part of a larger static expression, or the expression
is not evaluated due to being on the right-hand side of a short-circuit
control form. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>44.n</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>This clause (and <A HREF="AA-4-5-5.html">4.5.5</A>,
``<A HREF="AA-4-5-5.html">Multiplying Operators</A>'') subsumes the RM83
section on Universal Expressions.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.o</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The existence of static string
expressions necessitated changing the definition of static subtype to
include string subtypes. Most occurrences of "static subtype"
have been changed to "static scalar subtype", in order to preserve
the effect of the Ada 83 rules. This has the added benefit of clarifying
the difference between "static subtype" and "statically
constrained subtype", which has been a source of confusion. In cases
where we allow static string subtypes, we explicitly use phrases like
"static string subtype" or "static (scalar or string)
subtype", in order to clarify the meaning for those who have gotten
used to the Ada 83 terminology.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.p</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>In
Ada 83, an expression was considered nonstatic if it raised an exception.
Thus, for example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.q</FONT></DIV>
<DIV Class="SmallExamples"><TT>Bad: <B>constant</B> := 1/0; --<I> Illegal!</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>44.r</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>was illegal because 1/0 was not
static. In Ada 95, the above example is still illegal, but for a different
reason: 1/0 is static, but there's a separate rule forbidding the exception
raising.</FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-4-8.html">Previous</A> <A HREF="AA-4-9-1.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|