home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / lrm / chap04.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  91.4 KB  |  3,632 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. The following document is a draft  of  the  corresponding  chapter  of  the
  7. version  of  the  Ada  Reference  Manual  produced  in response to the Ansi
  8. Canvass.  It is given a limited circulation  to  Ada  implementers  and  to
  9. other groups contributing comments (according to the conventions defined in
  10. RRM.comments).  This draft should not be referred to in any publication.
  11.  
  12.  
  13.  
  14.                       ANSI-RM-04-v23 - Draft Chapter
  15.                          4  Names and Expressions
  16.                                 version 23
  17.  
  18.                                  83-02-11
  19.  
  20.  
  21. This revision has addressed all comments up to #5795
  22.  
  23. (this  revision  does not include the amendment proposed in comments #2390,
  24. 2861, 4435 for section 4.6)
  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.                          4. Names and Expressions
  78.  
  79.  
  80.  
  81. The rules applicable to the different forms of name and expression, and  to
  82. their evaluation, are given in this chapter.
  83.  
  84.  
  85.  
  86. 4.1  Names
  87.  
  88.  
  89. Names   can  denote  declared  entities,  whether  declared  explicitly  or
  90. implicitly (see 3.1).  Names can also denote objects designated  by  access
  91. values;   subcomponents  and slices of objects and values;  single entries,
  92. entry families, and entries in families of  entries.   Finally,  names  can
  93. denote attributes of any of the foregoing.
  94.  
  95.     name ::= simple_name
  96.        | character_literal  | operator_symbol
  97.        | indexed_component  | slice
  98.        | selected_component | attribute
  99.  
  100.     simple_name ::= identifier
  101.  
  102.     prefix ::= name | function_call
  103.  
  104. A  simple  name  for an entity is either the identifier associated with the
  105. entity by its declaration, or another identifier associated with the entity
  106. by a renaming declaration.
  107.  
  108. Certain forms  of  name  (indexed  and  selected  components,  slices,  and
  109. attributes)  include a prefix that is either a name or a function call.  If
  110. the type of a prefix is an access type, then the prefix must not be a  name
  111. that denotes a formal parameter of mode out or a subcomponent thereof.
  112.  
  113. If  the  prefix  of  a  name  is  a  function call, then the name denotes a
  114. component, a slice, an attribute, an entry, or an entry family,  either  of
  115. the  result  of the function call, or (if the result is an access value) of
  116. the object designated by the result.
  117.  
  118. A prefix is said to be appropriate for a type in either  of  the  following
  119. cases:
  120.  
  121.   -  The type of the prefix is the type considered.
  122.  
  123.   -  The type of the prefix is an access type whose designated type is  the
  124.      type considered.
  125.  
  126.  
  127.  
  128.  
  129.                                    4 - 1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. The  evaluation  of a name determines the entity denoted by the name.  This
  139. evaluation has no other effect  for  a  name  that  is  a  simple  name,  a
  140. character literal, or an operator symbol.
  141.  
  142. The  evaluation  of a name that has a prefix includes the evaluation of the
  143. prefix, that is, of the corresponding name or function call.  If  the  type
  144. of  the prefix is an access type, the evaluation of the prefix includes the
  145. determination of the object designated by the corresponding  access  value;
  146. the  exception  CONSTRAINT_ERROR  is raised if the value of the prefix is a
  147. null access value, except in the case of the  prefix  of  a  representation
  148. attribute (see 13.7.2).
  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.                                    4 - 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. Examples of simple names:
  205.  
  206.     PI      --  the simple name of a number               (see 3.2.2)
  207.     LIMIT   --  the simple name of a constant             (see 3.2.1)
  208.     COUNT   --  the simple name of a scalar variable      (see 3.2.1)
  209.     BOARD   --  the simple name of an array variable      (see 3.6.1)
  210.     MATRIX  --  the simple name of a type                 (see 3.6)
  211.     RANDOM  --  the simple name of a function             (see 6.1)
  212.     ERROR   --  the simple name of an exception           (see 11.1)
  213.  
  214. References:   access type 3.8, access value 3.8, attribute 4.1.4, belong to
  215. a  type  3.3,  character  literal  2.5,  component  3.3,   constraint_error
  216. exception 11.1, declaration 3.1, designate 3.8, designated type 3.8, entity
  217. 3.1,  entry  9.5,  entry  family 9.5, evaluation 4.5, formal parameter 6.1,
  218. function call 6.4, identifier 2.3, indexed component 4.1.1, mode 6.1,  null
  219. access  value 3.8, object 3.2.1, operator symbol 6.1, raising of exceptions
  220. 11, renaming declarations  8.5,  selected  component  4.1.3,  slice  4.1.2,
  221. subcomponent 3.3, type 3.3
  222.  
  223.  
  224.  
  225.  
  226. 4.1.1  Indexed Components
  227.  
  228.  
  229. An  indexed component denotes either a component of an array or an entry in
  230. a family of entries.
  231.  
  232.     indexed_component ::= prefix(expression {, expression})
  233.  
  234. In the case of a component of an array, the prefix must be appropriate  for
  235. an array type.  The expressions specify the index values for the component;
  236. there  must  be  one  such  expression for each index position of the array
  237. type.  In the case of an entry in a family of entries, the prefix must be a
  238. name that denotes an  entry family of a task  object,  and  the  expression
  239. (there  must  be  exactly one) specifies the index value for the individual
  240. entry.
  241.  
  242. Each expression must be of the type of the corresponding  index.   For  the
  243. evaluation  of  an  indexed  component,  the prefix and the expressions are
  244. evaluated in some order that is not defined by the language.  The exception
  245. CONSTRAINT_ERROR is raised if an index value does not belong to  the  range
  246. of the corresponding index of the prefixing array or entry family.
  247.  
  248. Examples of indexed components:
  249.  
  250.     MY_SCHEDULE(SAT)       --  a component of a one-dimensional array   (see 3.6.1)
  251.     PAGE(10)               --  a component of a one-dimensional array   (see 3.6)
  252.     BOARD(M, J + 1)        --  a component of a two-dimensional array   (see 3.6.1)
  253.     PAGE(10)(20)           --  a component of a component               (see 3.6)
  254.     REQUEST(MEDIUM)        --  an entry in a family of entries          (see 9.5)
  255.     NEXT_FRAME(L)(M, N)    --  a component of a function call           (see 6.1)
  256.  
  257. Notes on the examples:
  258.  
  259.  
  260.  
  261.                                    4 - 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. Distinct notations are used for components of multidimensional arrays (such
  271. as  BOARD) and arrays of arrays (such as PAGE).  The components of an array
  272. of arrays are arrays and  can  therefore  be  indexed.   Thus  PAGE(10)(20)
  273. denotes  the 20th component of PAGE(10).  In the last example NEXT_FRAME(L)
  274. is  a  function  call  returning  an  access  value  which   designates   a
  275. two-dimensional array.
  276.  
  277. References:   appropriate  for  a  type 4.1, array type 3.6, component 3.3,
  278. component of an array 3.6, constraint_error exception 11.1, dimension  3.6,
  279. entry  9.5, entry family 9.5, evaluation 4.5, expression 4.4, function call
  280. 6.4, in some order 1.6,  index  3.6,  name  4.1,  prefix  4.1,  raising  of
  281. exceptions 11, returned value 5.8 6.5, task object 9.2
  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.                                    4 - 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. 4.1.2  Slices
  337.  
  338.  
  339. A slice denotes a one-dimensional array formed by a sequence of consecutive
  340. components  of  a  one-dimensional  array.   A  slice  of  a  variable is a
  341. variable;  a slice of a constant is a constant;  a slice of a  value  is  a
  342. value.
  343.  
  344.     slice ::= prefix(discrete_range)
  345.  
  346. The prefix of a slice must be appropriate for a one-dimensional array type.
  347. The  type  of the slice is the base type of this array type.  The bounds of
  348. the discrete range define those of the slice and must be of the type of the
  349. index;  the slice is a null slice denoting a null  array  if  the  discrete
  350. range is a null range.
  351.  
  352. For  the  evaluation of a name that is a slice, the prefix and the discrete
  353. range are evaluated in some order that is not defined by the language.  The
  354. exception CONSTRAINT_ERROR is raised by the evaluation of  a  slice,  other
  355. than  a  null  slice,  if  any of the bounds of the discrete range does not
  356. belong to the index range of the prefixing array.  (The bounds  of  a  null
  357. slice need not belong to the subtype of the index.)
  358.  
  359. Examples of slices:
  360.  
  361.     STARS(1 .. 15)         --  a slice of 15 characters         (see 3.6.3)
  362.     PAGE(10 .. 10 + SIZE)  --  a slice of 1 + SIZE components   (see 3.6 and 3.2.1)
  363.     PAGE(L)(A .. B)        --  a slice of the array PAGE(L)     (see 3.6)
  364.     STARS(1 .. 0)          --  a null slice                     (see 3.6.3)
  365.     MY_SCHEDULE(WEEKDAY)   --  bounds given by subtype          (see 3.6 and 3.5.1)
  366.     STARS(5 .. 15)(K)      --  same as STARS(K)                 (see 3.6.3)
  367.                            --  provided that K is in 5 .. 15
  368.  
  369. Notes:
  370.  
  371. For  a  one-dimensional  array  A,  the  name  A(N  .. N) is a slice of one
  372. component;  its type is the base type of A.  On the other hand, A(N)  is  a
  373. component of the array A and has the corresponding component type.
  374.  
  375. References:   appropriate  for a type 4.1, array 3.6, array type 3.6, array
  376. value 3.8, base type 3.3, belong to a subtype  3.3,  bound  of  a  discrete
  377. range  3.6.1, component 3.3, component type 3.3, constant 3.2.1, constraint
  378. 3.3, constraint_error exception 11.1, dimension 3.6,  discrete  range  3.6,
  379. evaluation  4.5,  index  3.6,  index range 3.6, name 4.1, null array 3.6.1,
  380. null range 3.5, prefix 4.1, raising of exceptions 11,  type  3.3,  variable
  381. 3.2.1
  382.  
  383.  
  384.  
  385. 4.1.3  Selected Components
  386.  
  387.  
  388. Selected  components  are  used to denote record components, entries, entry
  389. families, and objects designated by access values; they are  also  used  as
  390. expanded names as described below.
  391.  
  392.  
  393.                                    4 - 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.     selected_component ::= prefix.selector
  403.  
  404.     selector ::= simple_name
  405.        | character_literal | operator_symbol | all
  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.                                    4 - 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. The  following  four  forms  of  selected  components  are used to denote a
  469. discriminant, a record component, an entry, or an object designated  by  an
  470. access value:
  471.  
  472. (a)  A discriminant:
  473.  
  474.      The  selector  must  be  a  simple  name denoting a discriminant of an
  475.      object or value.  The prefix must be appropriate for the type of  this
  476.      object or value.
  477.  
  478. (b)  A component of a record:
  479.  
  480.      The  selector  must  be a simple name denoting a component of a record
  481.      object or value.  The prefix must be appropriate for the type of  this
  482.      object or value.
  483.  
  484.      For  a  component of a variant, a check is made that the values of the
  485.      discriminants are such  that  the  record  has  this  component.   The
  486.      exception CONSTRAINT_ERROR is raised if this check fails.
  487.  
  488. (c)  A single entry or an entry family of a task:
  489.  
  490.      The selector must be a simple name denoting a single entry or an entry
  491.      family of a task.  The prefix must be appropriate for the type of this
  492.      task.
  493.  
  494. (d)  An object designated by an access value:
  495.  
  496.      The  selector  must be the reserved word all.  The value of the prefix
  497.      must belong to an access type.
  498.  
  499. A selected component of one  of  the  remaining  two  forms  is  called  an
  500. expanded  name.   In each case the selector must be either a simple name, a
  501. character literal, or an operator symbol.  A function call is  not  allowed
  502. as the prefix of an expanded name.  An expanded name can denote:
  503.  
  504. (e)  An entity declared in the visible part of a package:
  505.  
  506.      The  prefix  must denote the package.  The selector must be the simple
  507.      name, character literal, or operator symbol of the entity.
  508.  
  509. (f)  An  entity  whose  declaration  occurs  immediately  within  a   named
  510.      construct:
  511.  
  512.      The  prefix  must  denote a construct that is either a program unit, a
  513.      block statement, a loop statement, or an  accept  statement.   In  the
  514.      case of an accept statement, the prefix must be either the simple name
  515.      of  the  entry or entry family, or an expanded name ending with such a
  516.      simple name (that is, no index is allowed).  The selector must be  the
  517.      simple  name, character literal, or operator symbol of an entity whose
  518.      declaration occurs immediately within the construct.
  519.  
  520.      This form of expanded name is only allowed within the construct itself
  521.      (including the body and any subunits, in the case of a program  unit).
  522.      A  name  declared  by  a  renaming  declaration  is not allowed as the
  523.  
  524.  
  525.                                    4 - 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.      prefix.  If the prefix is the name of a subprogram or accept statement
  535.      and if there is more than one visible enclosing subprogram  or  accept
  536.      statement  of this name, the expanded name is ambiguous, independently
  537.      of the selector.
  538.  
  539. If, according to the visibility rules,  there  is  at  least  one  possible
  540. interpretation  of  the  prefix  of  a selected component as the name of an
  541. enclosing subprogram or accept statement,  then  the  only  interpretations
  542. considered  are those of rule (f), as expanded names (no interpretations of
  543. the prefix as a function call are then considered).
  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.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                    4 - 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. The evaluation of  a  name  that  is  a  selected  component  includes  the
  601. evaluation of the prefix.
  602.  
  603. Examples of selected components:
  604.  
  605.     TOMORROW.MONTH     --  a record component                    (see 3.7)
  606.     NEXT_CAR.OWNER     --  a record component                    (see 3.8.1)
  607.     NEXT_CAR.OWNER.AGE --  a record component                    (see 3.8.1)
  608.     WRITER.UNIT        --  a record component (a discriminant)   (see 3.7.3)
  609.     MIN_CELL(H).VALUE  --  a record component of the result      (see 6.1 and 3.8.1)
  610.                        --  of the function call MIN_CELL(H)
  611.  
  612.     CONTROL.SEIZE      --  an entry of the task CONTROL          (see 9.1 and 9.2)
  613.     POOL(K).WRITE      --  an entry of the task POOL(K)          (see 9.1 and 9.2)
  614.  
  615.     NEXT_CAR.all       --  the object designated by
  616.                        --  the access variable NEXT_CAR          (see 3.8.1)
  617.  
  618. Examples of expanded names:
  619.  
  620.     TABLE_MANAGER.INSERT --  a procedure of the visible part of a package (see 7.5)
  621.     KEY_MANAGER."<"      --  an operator of the visible part of a package (see 7.4.2)
  622.  
  623.     DOT_PRODUCT.SUM      --  a variable declared in a procedure body      (see 6.5)
  624.     BUFFER.POOL          --  a variable declared in a task unit           (see 9.12)
  625.     BUFFER.READ          --  an entry of a task unit                      (see 9.12)
  626.     SWAP.TEMP            --  a variable declared in a block statement     (see 5.6)
  627.     STANDARD.BOOLEAN     --  the name of a predefined type                (see 8.6 and C)
  628.  
  629. Note:
  630.  
  631. For  a record with components that are other records, the above rules imply
  632. that the simple name must be  given  at  each  level  for  the  name  of  a
  633. subcomponent.   For  example, the name NEXT_CAR.OWNER.BIRTH.MONTH cannot be
  634. shortened (NEXT_CAR.OWNER.MONTH is not allowed).
  635.  
  636. References:  accept statement 9.5,  access  type  3.8,  access  value  3.8,
  637. appropriate  for  a  type  4.1, block statement 5.6, body of a program unit
  638. 3.9, character literal 2.5, component of  a  record  3.7,  constraint_error
  639. exception  11.1,  declaration  3.1, designate 3.8, discriminant 3.3, entity
  640. 3.1, entry 9.5, entry family  9.5,  function  call  6.4,  index  3.6,  loop
  641. statement  5.5,  object  3.2.1, occur immediately within 8.1, operator 4.5,
  642. operator symbol 6.1, overloading 8.3, package 7, predefined type C,  prefix
  643. 4.1,  procedure  body 6.3, program unit 6, raising of exceptions 11, record
  644. 3.7, record component 3.7, renaming declaration  8.5,  reserved  word  2.9,
  645. simple  name 4.1, subprogram 6, subunit 10.2, task 9, task object 9.2, task
  646. unit 9, variable 3.7.3, variant 3.7.3, visibility 8.3, visible part 3.7.3
  647.  
  648.  
  649.  
  650. 4.1.4  Attributes
  651.  
  652.  
  653. An attribute denotes a basic operation of an entity given by a prefix.
  654.  
  655.  
  656.  
  657.                                    4 - 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.     attribute ::= prefix'attribute_designator
  667.  
  668.     attribute_designator ::= simple_name [(universal_static_expression)]
  669.  
  670. The applicable attribute designators depend on the  prefix.   An  attribute
  671. can  be  a  basic  operation delivering a value;  alternatively it can be a
  672. function, a type, or a range.  The meaning of the prefix  of  an  attribute
  673. must   be  determinable  independently  of  the  attribute  designator  and
  674. independently of the fact that it is the prefix of an attribute.
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                   4 - 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. The attributes defined by the language  are  summarized  in  Annex  A.   In
  733. addition,  an implementation may provide implementation-defined attributes;
  734. their description must be given in Appendix F.  The attribute designator of
  735. any implementation-defined attribute must not be the same as  that  of  any
  736. language-defined attribute.
  737.  
  738. The evaluation of a name that is an attribute consists of the evaluation of
  739. the prefix.
  740.  
  741. Notes:
  742.  
  743. The attribute designators DIGITS, DELTA, and RANGE have the same identifier
  744. as  a  reserved word.  However, no confusion is possible since an attribute
  745. designator is always  preceded  by  an  apostrophe.   The  only  predefined
  746. attribute  designators  that  have  a  universal  expression  are those for
  747. certain operations of array types (see 3.6.2).
  748.  
  749. Examples of attributes:
  750.  
  751.     COLOR'FIRST        -- minimum value of the enumeration type COLOR  (see 3.3.1 and 3.5)
  752.     RAINBOW'BASE'FIRST -- same as COLOR'FIRST                          (see 3.3.2 and 3.3.3)
  753.     REAL'DIGITS        -- precision of the type REAL                   (see 3.5.7 and 3.5.8)
  754.     BOARD'LAST(2)      -- upper bound of the second dimension of BOARD (see 3.6.1 and 3.6.2)
  755.     BOARD'RANGE(1)     -- index range of the first dimension of BOARD  (see 3.6.1 and 3.6.2)
  756.     POOL(K)'TERMINATED -- TRUE if task POOL(K) is terminated           (see 9.2   and 9.9)
  757.     DATE'SIZE          -- number of bits for records of type DATE      (see 3.7   and 13.7.2)
  758.     MESSAGE'ADDRESS    -- address of the record variable MESSAGE       (see 3.7.2 and 13.7.2)
  759.  
  760. References:  appropriate for a type 4.1, basic  operation  3.3.3,  declared
  761. entity  3.1,  name  4.1,  prefix  4.1,  reserved word 2.9, simple name 4.1,
  762. static expression 4.9, type 3.3, universal expression 4.10
  763.  
  764.  
  765.  
  766. 4.2  Literals
  767.  
  768.  
  769. A literal is either a numeric literal, an enumeration literal, the  literal
  770. null,  or  a  string  literal.   The  evaluation  of  a  literal yields the
  771. corresponding value.
  772.  
  773. Numeric literals are  the  literals  of  the  types  universal_integer  and
  774. universal_real.   Enumeration literals include character literals and yield
  775. values of the corresponding enumeration types.  The literal null  yields  a
  776. null access value which designates no objects at all.
  777.  
  778. A  string  literal  is  a  basic  operation  that  combines  a  sequence of
  779. characters into a value of a one-dimensional array  of  a  character  type;
  780. the  bounds  of  this  array  are  determined  according  to  the rules for
  781. positional array aggregates (see 4.3.2).  For a null  string  literal,  the
  782. upper  bound  is  the  predecessor,  as given by the PRED attribute, of the
  783. lower bound.  The evaluation of a null string literal raises the  exception
  784. CONSTRAINT_ERROR  if  the  lower  bound  does  not  have a predecessor (see
  785. 3.5.5).
  786.  
  787.  
  788.  
  789.                                   4 - 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. The type of a string literal and likewise the type of the literal null must
  799. be determinable solely from the context  in  which  this  literal  appears,
  800. excluding the literal itself, but using the fact that the literal null is a
  801. value  of an access type, and similarly that a string literal is a value of
  802. a one-dimensional array type whose component type is a character type.
  803.  
  804. The character literals corresponding to the  graphic  characters  contained
  805. within  a string literal must be visible at the place of the string literal
  806. (although these characters themselves are not used to determine the type of
  807. the string literal).
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                   4 - 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. Examples:
  865.  
  866.     3.14159_26536  --  a real literal
  867.     1_345          --  an integer literal
  868.     CLUBS          --  an enumeration literal
  869.     'A'            --  a character literal
  870.     "SOME TEXT"    --  a string literal
  871.  
  872. References:  access type 3.8, aggregate 4.3, array 3.6,  array  bound  3.6,
  873. array type 3.6, character literal 2.5, character type 3.5.2, component type
  874. 3.3,   constraint_error  exception  11.1,  designate  3.8,  dimension  3.6,
  875. enumeration literal 3.5.1, graphic character 2.1, integer literal 2.4, null
  876. access value 3.8, null literal 3.8, numeric literal 2.4, object 3.2.1, real
  877. literal 2.4, string literal 2.6, type 3.3,  universal_integer  type  3.5.4,
  878. universal_real type 3.5.6, visibility 8.3
  879.  
  880.  
  881.  
  882. 4.3  Aggregates
  883.  
  884.  
  885. An  aggregate  is  a  basic operation that combines component values into a
  886. composite value of a record or array type.
  887.  
  888.     aggregate ::=
  889.        (component_association {, component_association})
  890.  
  891.     component_association ::=
  892.        [choice {| choice} => ] expression
  893.  
  894. Each  component  association  associates  an  expression  with   components
  895. (possibly  none).   A  component  association  is  said  to be named if the
  896. components are specified explicitly by choices;  it is otherwise said to be
  897. positional.  For  a  positional  association,  the  (single)  component  is
  898. implicitly  specified  by  position,  in  the  order  of  the corresponding
  899. component declarations for record components,  in  index  order  for  array
  900. components.
  901.  
  902. Named  associations  can  be  given  in  any  order  (except for the choice
  903. others), but if both positional and named associations are used in the same
  904. aggregate, then positional associations must occur first, at  their  normal
  905. position.   Hence  once  a  named  association  is  used,  the  rest of the
  906. aggregate must use only named associations.  Aggregates containing a single
  907. component association must always be given  in  named  notation.   Specific
  908. rules  concerning  component  associations  exist for record aggregates and
  909. array aggregates.
  910.  
  911. Choices in component associations have the same syntax as in variant  parts
  912. (see 3.7.3).  A choice that is a component simple name is only allowed in a
  913. record  aggregate.   For a component association, a choice that is a simple
  914. expression or a discrete range is only allowed in an  array  aggregate;   a
  915. choice  that  is  a  simple  expression  specifies  the  component  at  the
  916. corresponding index  value;   similarly  a  discrete  range  specifies  the
  917. components  at  the  index  values in the range.  The choice others is only
  918. allowed in a component association if the association appears last and  has
  919.  
  920.  
  921.                                   4 - 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930. this single choice;  it specifies all remaining components, if any.
  931.  
  932. Each  component  of  the  value defined by an aggregate must be represented
  933. once and only once in the aggregate.  Hence each aggregate must be complete
  934. and a given component is not allowed to  be  specified  by  more  than  one
  935. choice.
  936.  
  937. The  type  of  an aggregate must be determinable solely from the context in
  938. which the aggregate appears, excluding the aggregate itself, but using  the
  939. fact  that  this  type  must  be composite and not limited.  The type of an
  940. aggregate in turn determines the required type for each of its  components.
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                   4 - 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996. Notes:
  997.  
  998. The  above  rule implies that the determination of the type of an aggregate
  999. cannot use any information from within the aggregate.  In particular,  this
  1000. determination  cannot  use  the  type  of  the  expression  of  a component
  1001. association, or the form or the type of a choice.  An aggregate can  always
  1002. be  distinguished  from  an  expression enclosed by parentheses:  this is a
  1003. consequence of the fact that named notation is required  for  an  aggregate
  1004. with a single component.
  1005.  
  1006. References:   array aggregate 4.3.2, array type 3.6, basic operation 3.3.3,
  1007. choice 3.7.3, component 3.3,  composite  type  3.3,  composite  value  3.3,
  1008. discrete  range 3.6, expression 4.4, index 3.6, limited type 7.4.4, primary
  1009. 4.4, record aggregate 4.3.1, record type 3.7, simple expression 4.4, simple
  1010. name 4.1, type 3.3, variant part 3.7.3
  1011.  
  1012.  
  1013.  
  1014. 4.3.1  Record Aggregates
  1015.  
  1016.  
  1017. If the type of an aggregate is a record type, the component names given  as
  1018. choices  must  denote  components  (including  discriminants) of the record
  1019. type.  If the choice others is given as a choice of a record aggregate,  it
  1020. must  represent  at  least one component.  A component association with the
  1021. choice others or  with  more  than  one  choice  is  only  allowed  if  the
  1022. represented  components  are  all  of  the  same type.  The expression of a
  1023. component  association  must  have  the  type  of  the  associated   record
  1024. components.
  1025.  
  1026. The  value specified for a discriminant that governs a variant part must be
  1027. given by a  static  expression  (note  that  this  value  determines  which
  1028. dependent components must appear in the record value).
  1029.  
  1030. For  the  evaluation  of  a  record aggregate, the expressions given in the
  1031. component associations are evaluated in some order that is not  defined  by
  1032. the  language.  The expression of a named association is evaluated once for
  1033. each associated component.   A  check  is  made  that  the  value  of  each
  1034. subcomponent  of the aggregate belongs to the subtype of this subcomponent.
  1035. The exception CONSTRAINT_ERROR is raised if this check fails.
  1036.  
  1037. Example of a record aggregate with positional associations:
  1038.  
  1039.     (4, JULY, 1776)                      --  see 3.7
  1040.  
  1041. Examples of record aggregates with named associations:
  1042.  
  1043.     (DAY => 4, MONTH => JULY, YEAR => 1776)
  1044.     (MONTH => JULY, DAY => 4, YEAR => 1776)
  1045.  
  1046.     (DISK, CLOSED, TRACK => 5, CYLINDER => 12)       --  see 3.7.3
  1047.     (UNIT => DISK, STATUS => CLOSED, CYLINDER => 9, TRACK => 1)
  1048.  
  1049. Example of component association with several choices:
  1050.  
  1051.  
  1052.  
  1053.                                   4 - 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.     (VALUE => 0, SUCC|PRED => new CELL'(0, null, null))        --  see 3.8.1
  1063.     --  The allocator is evaluated twice:  SUCC and PRED designate different cells
  1064.  
  1065. Note:
  1066.  
  1067. For an aggregate with positional associations, discriminant  values  appear
  1068. first  since  the  discriminant  part  is  given  first  in the record type
  1069. declaration;  they must be in the same order as in the  discriminant  part.
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                   4 - 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128. References:    aggregate   4.3,  allocator  4.8,  choice  3.7.3,  component
  1129. association 4.3,  component  name  3.7,  constraint  3.3,  constraint_error
  1130. exception   11.1,   depend  on  a  discriminant  3.7.1,  discriminant  3.3,
  1131. discriminant part 3.7.1, evaluate 4.5, expression 4.4, in some  order  1.6,
  1132. program  10,  raising  of  exceptions 11, record component 3.7, record type
  1133. 3.7, satisfy 3.3, static expression 4.9, subcomponent 3.3,  subtype  3.3.2,
  1134. type 3.3, variant part 3.7.3
  1135.  
  1136.  
  1137.  
  1138. 4.3.2  Array Aggregates
  1139.  
  1140.  
  1141. If  the  type  of  an  aggregate is a one-dimensional array type, then each
  1142. choice must specify values of the index type, and the  expression  of  each
  1143. component association must be of the component type.
  1144.  
  1145. If  the  type  of  an  aggregate  is  a  multidimensional  array  type,  an
  1146. n-dimensional aggregate is written as a one-dimensional aggregate, in which
  1147. the expression specified for each component association is  itself  written
  1148. as  an  (n-1)-dimensional  aggregate  which  is called a subaggregate;  the
  1149. index subtype of the one-dimensional aggregate is given by the first  index
  1150. position  of the array type.  The same rule is used to write a subaggregate
  1151. if it is again  multidimensional,  using  successive  index  positions.   A
  1152. string literal is allowed in a multidimensional aggregate at the place of a
  1153. one-dimensional  array  of  a  character  type.  In what follows, the rules
  1154. concerning array aggregates are  formulated  in  terms  of  one-dimensional
  1155. aggregates.
  1156.  
  1157. Apart from a final component association with the single choice others, the
  1158. rest  (if  any) of the component associations of an array aggregate must be
  1159. either all positional or all  named.   A  named  association  of  an  array
  1160. aggregate  is only allowed to have a choice that is not static, or likewise
  1161. a choice that is a null range, if the aggregate includes a single component
  1162. association and this component association has a single choice.  An  others
  1163. choice is static if the applicable index constraint is static.
  1164.  
  1165. The  bounds  of an array aggregate that has an others choice are determined
  1166. by the applicable index constraint.  An others choice is  only  allowed  if
  1167. the  aggregate  appears in one of the following contexts (which defines the
  1168. applicable index constraint):
  1169.  
  1170. (a)  The aggregate is an actual parameter, a generic actual parameter,  the
  1171.      result  expression  of  a  function, or the expression that follows an
  1172.      assignment  compound  delimiter.   Moreover,  the   subtype   of   the
  1173.      corresponding  formal  parameter,  generic  formal parameter, function
  1174.      result, or object is a constrained array subtype.
  1175.  
  1176.      For an aggregate that appears  in  such  a  context  and  contains  an
  1177.      association  with an others choice, named associations are allowed for
  1178.      other associations only in the case of a (nongeneric) actual parameter
  1179.      or function result.  If the aggregate  is  a  multidimensional  array,
  1180.      this restriction also applies to each of its subaggregates.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                   4 - 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. (b)  The aggregate is the operand of a qualified expression whose type mark
  1195.      denotes a constrained array subtype.
  1196.  
  1197. (c)  The aggregate is the expression of the  component  association  of  an
  1198.      enclosing  (array  or  record) aggregate.  Moreover, if this enclosing
  1199.      aggregate is a multidimensional array aggregate then it is  itself  in
  1200.      one of these three contexts.
  1201.  
  1202. The  bounds  of  an array aggregate that does not have an others choice are
  1203. determined as follows.  For an aggregate that has named  associations,  the
  1204. bounds  are  determined  by  the smallest and largest choices given.  For a
  1205. positional aggregate, the lower bound is determined by the applicable index
  1206. constraint if the aggregate appears in one of the contexts (a) through (c);
  1207. otherwise, the lower bound is  given  by  S'FIRST  where  S  is  the  index
  1208. subtype;   in  either  case, the upper bound is determined by the number of
  1209. components.
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                   4 - 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. The evaluation of an array aggregate that is not a subaggregate proceeds in
  1261. two steps.  First, the choices of this aggregate and of its  subaggregates,
  1262. if  any,  are  evaluated in some order that is not defined by the language.
  1263. Second,  the  expressions  of  the  component  associations  of  the  array
  1264. aggregate  are evaluated in some order that is not defined by the language;
  1265. the expression of a named association is evaluated once for each associated
  1266. component.  The evaluation of a subaggregate consists of this  second  step
  1267. (the  first step is omitted since the choices have already been evaluated).
  1268.  
  1269. For the evaluation of an aggregate that is not a null  array,  a  check  is
  1270. made  that  the index values defined by choices belong to the corresponding
  1271. index subtypes, and also  that  the  value  of  each  subcomponent  of  the
  1272. aggregate   belongs   to   the   subtype  of  this  subcomponent.   For  an
  1273. n-dimensional  multidimensional  aggregate,  a  check  is  made  that   all
  1274. (n-1)-dimensional  subaggregates  have  the  same  bounds.   The  exception
  1275. CONSTRAINT_ERROR is raised if any of these checks fails.
  1276.  
  1277. Note:
  1278.  
  1279. The allowed contexts for an array aggregate including an others choice  are
  1280. such  that  the  bounds  of  such  an  aggregate  are always known from the
  1281. context.
  1282.  
  1283. Examples of array aggregates with positional associations:
  1284.  
  1285.     (7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
  1286.     TABLE'(5, 8, 4, 1, others => 0)  --  see 3.6
  1287.  
  1288. Examples of array aggregates with named associations:
  1289.  
  1290.     (1 .. 5 => (1 .. 8 => 0.0))     --  two-dimensional
  1291.     (1 .. N => new CELL)            --  N new cells, in particular for N = 0
  1292.  
  1293.     TABLE'(2 | 4 | 10 => 1, others => 0)
  1294.     SCHEDULE'(MON .. FRI => TRUE,  others => FALSE)  --  see 3.6
  1295.     SCHEDULE'(WED | SUN  => FALSE, others => TRUE)
  1296.  
  1297. Examples of two-dimensional array aggregates:
  1298.  
  1299.     -- Three aggregates for the same value of type MATRIX (see 3.6):
  1300.  
  1301.     ((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
  1302.     (1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3))
  1303.     (1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3))
  1304.  
  1305. Examples of aggregates as initial values:
  1306.  
  1307.     A : TABLE := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0);        -- A(1)=7, A(10)=0
  1308.     B : TABLE := TABLE'(2 | 4 | 10 => 1, others => 0);  -- B(1)=0, B(10)=1
  1309.     C : constant MATRIX := (1 .. 5 => (1 .. 8 => 0.0)); -- C'FIRST(1)=1, C'LAST(2)=8
  1310.  
  1311.     D : BIT_VECTOR(M .. N) := (M .. N => TRUE);  -- see 3.6
  1312.     E : BIT_VECTOR(M .. N) := (others => TRUE);
  1313.     F : STRING(1 .. 1) := (1 => 'F');  -- a one component aggregate: same as "F"
  1314.  
  1315.  
  1316.  
  1317.                                   4 - 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326. References:   actual  parameter  6.4.1,  aggregate  4.3,  array  type  3.6,
  1327. assignment  compound  delimiter 5.2, choice 3.7.3, component 3.3, component
  1328. association  4.3,  component  type  3.3,  constrained  array  subtype  3.6,
  1329. constraint  3.3,  constraint_error  exception 11.1, dimension 3.6, evaluate
  1330. 4.5, expression 4.4, formal parameter 6.1, function 6.5, in some order 1.6,
  1331. index constraint 3.6.1, index range 3.6, index subtype 3.6, index type 3.6,
  1332. named component association 4.3, null array 3.6.1, object  3.2,  positional
  1333. component  association 4.3, qualified expression 4.7, raising of exceptions
  1334. 11, static expression 4.9, subcomponent 3.3, type 3.3
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                   4 - 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392. 4.4  Expressions
  1393.  
  1394.  
  1395. An expression is a formula that defines the computation of a value.
  1396.  
  1397.     expression ::=
  1398.          relation {and relation} | relation {and then relation}
  1399.        | relation {or relation}  | relation {or else relation}
  1400.        | relation {xor relation}
  1401.  
  1402.     relation ::=
  1403.          simple_expression [relational_operator simple_expression]
  1404.        | simple_expression [not] in range
  1405.        | simple_expression [not] in type_mark
  1406.  
  1407.     simple_expression ::= [unary_adding_operator] term {binary_adding_operator term}
  1408.  
  1409.     term ::= factor {multiplying_operator factor}
  1410.  
  1411.     factor ::= primary [** primary] | abs primary | not primary
  1412.  
  1413.     primary ::=
  1414.          numeric_literal | null | aggregate | string_literal | name | allocator
  1415.        | function_call | type_conversion | qualified_expression | (expression)
  1416.  
  1417. Each primary has a value and a type.  The only names allowed  as  primaries
  1418. are  named  numbers;   attributes  that  yield  values;  and names denoting
  1419. objects (the value of such a  primary  is  the  value  of  the  object)  or
  1420. denoting  values.   Names that denote formal parameters of mode out are not
  1421. allowed as primaries;  names of their subcomponents are only allowed in the
  1422. case of discriminants.
  1423.  
  1424. The type of an expression depends only on the type of its constituents  and
  1425. on  the  operators applied;  for an overloaded constituent or operator, the
  1426. determination of  the  constituent  type,  or  the  identification  of  the
  1427. appropriate   operator,  depends  on  the  context.   For  each  predefined
  1428. operator, the operand and result types are given in section 4.5.
  1429.  
  1430. Examples of primaries:
  1431.  
  1432.     4.0                --  real literal
  1433.     PI                 --  named number
  1434.     (1 .. 10 => 0)     --  array aggregate
  1435.     SUM                --  variable
  1436.     INTEGER'LAST       --  attribute
  1437.     SINE(X)            --  function call
  1438.     COLOR'(BLUE)       --  qualified expression
  1439.     REAL(M*N)          --  conversion
  1440.     (LINE_COUNT + 10)  --  parenthesized expression
  1441.  
  1442. Examples of expressions:
  1443.  
  1444.     VOLUME                  -- primary
  1445.     not DESTROYED           -- factor
  1446.     2*LINE_COUNT            -- term
  1447.  
  1448.  
  1449.                                   4 - 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.     -4.0                      -- simple expression
  1459.     -4.0 + A                  -- simple expression
  1460.     B**2 - 4.0*A*C            -- simple expression
  1461.     PASSWORD(1 .. 3) = "BWV"    -- relation
  1462.     COUNT in SMALL_INT          -- relation
  1463.     COUNT not in SMALL_INT      -- relation
  1464.     INDEX = 0 or ITEM_HIT         -- expression
  1465.     (COLD and SUNNY) or WARM      -- expression (parentheses are required)
  1466.     A**(B**C)                     -- expression (parentheses are required)
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                   4 - 22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524. References:  aggregate 4.3, allocator 4.8, array aggregate 4.3.2, attribute
  1525. 4.1.4, binary adding operator 4.5 4.5.3,  context  of  overload  resolution
  1526. 8.7,  exponentiating  operator  4.5  4.5.6,  function call 6.4, multiplying
  1527. operator 4.5 4.5.5, name 4.1, named number 3.2, null literal  3.8,  numeric
  1528. literal  2.4,  object  3.2,  operator  4.5, overloading 8.3, overloading an
  1529. operator 6.7, qualified  expression  4.7,  range  3.5,  real  literal  2.4,
  1530. relation  4.5.1,  relational  operator  4.5  4.5.2, result type 6.1, string
  1531. literal 2.6, type 3.3, type conversion 4.6, type mark 3.3.2,  unary  adding
  1532. operator 4.5 4.5.4, variable 3.2.1
  1533.  
  1534.  
  1535.  
  1536. 4.5  Operators and Expression Evaluation
  1537.  
  1538.  
  1539. The   language  defines  the  following  six  classes  of  operators.   The
  1540. corresponding operator symbols (except /=), and only those, can be used  as
  1541. designators  in declarations of functions for user-defined operators.  They
  1542. are given in the order of increasing precedence.
  1543.  
  1544.     logical_operator             ::=  and | or  | xor
  1545.  
  1546.     relational_operator          ::=  =   | /=  | <   | <= | > | >=
  1547.  
  1548.     binary_adding_operator       ::=  +   | -   | &
  1549.  
  1550.     unary_adding_operator        ::=  +   | -
  1551.  
  1552.     multiplying_operator         ::=  *   | /   | mod | rem
  1553.  
  1554.     highest_precedence_operator  ::=  **  | abs | not
  1555.  
  1556. The short-circuit control  forms  and  then  and  or  else  have  the  same
  1557. precedence  as  logical operators.  The membership tests in and not in have
  1558. the same precedence as relational operators.
  1559.  
  1560. For a term, simple expression, relation, or expression, operators of higher
  1561. precedence are associated with their operands  before  operators  of  lower
  1562. precedence.   In  this  case,  for  a  sequence  of  operators  of the same
  1563. precedence level, the operators are associated in textual order  from  left
  1564. to right;  parentheses can be used to impose specific associations.
  1565.  
  1566. The  operands  of  a  factor,  of  a  term, of a simple expression, or of a
  1567. relation, and the operands  of  an  expression  that  does  not  contain  a
  1568. short-circuit control form, are evaluated in some order that is not defined
  1569. by  the  language  (but  before application of the corresponding operator).
  1570. The right operand of a short-circuit control form is evaluated if and  only
  1571. if the left operand has a certain value (see 4.5.1).
  1572.  
  1573. For  each  form  of  type  declaration,  certain of the above operators are
  1574. predefined, that is, they are implicitly declared by the type  declaration.
  1575. For  each  such  implicit operator declaration, the names of the parameters
  1576. are LEFT and RIGHT for binary operators;  the single  parameter  is  called
  1577. RIGHT  for  unary adding operators and for the unary operators abs and not.
  1578. The effect of the predefined operators is explained  in  subsections  4.5.1
  1579.  
  1580.  
  1581.                                   4 - 23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590. through 4.5.7.
  1591.  
  1592. The  predefined operations on integer types either yield the mathematically
  1593. correct  result  or  raise  the  exception  NUMERIC_ERROR.   A   predefined
  1594. operation   that   delivers  a  result  of  an  integer  type  (other  than
  1595. universal_integer) can  only  raise  the  exception  NUMERIC_ERROR  if  the
  1596. mathematical  result is not a value of the type.  The predefined operations
  1597. on real types yield results whose accuracy is defined in section 4.5.7.   A
  1598. predefined  operation  that  delivers  a  result of a real type (other than
  1599. universal_real) can only raise the exception NUMERIC_ERROR if the result is
  1600. not within the range of the safe numbers  of  the  type,  as  explained  in
  1601. section 4.5.7.
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                   4 - 24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656. Examples of precedence:
  1657.  
  1658.     not SUNNY or WARM    --  same as (not SUNNY) or WARM
  1659.     X > 4.0 and Y > 0.0  --  same as (X > 4.0) and (Y > 0.0)
  1660.  
  1661.     -4.0*A**2            --  same as -(4.0 * (A**2))
  1662.     abs(1 + A) + B       --  same as (abs (1 + A)) + B
  1663.     Y**(-3)              --  parentheses are necessary
  1664.     A / B * C            --  same as (A/B)*C
  1665.     A + (B + C)          --  evaluate B + C before adding it to A
  1666.  
  1667. References:    designator   6.1,   expression  4.4,  factor  4.4,  implicit
  1668. declaration 3.1, in some order 1.6, integer  type  3.5.4,  membership  test
  1669. 4.5.2, name 4.1, numeric_error exception 11.1, overloading 6.6 8.7, raising
  1670. of  an  exception 11, range 3.5, real type 3.5.6, relation 4.4, safe number
  1671. 3.5.6, short-circuit control form 4.5 4.5.1, simple  expression  4.4,  term
  1672. 4.4,  type  3.3,  type  declaration  3.3.1,  universal_integer  type 3.5.4,
  1673. universal_real type 3.5.6
  1674.  
  1675.  
  1676.  
  1677. 4.5.1  Logical Operators and Short-circuit Control Forms
  1678.  
  1679.  
  1680. The following logical operators are predefined for any boolean type and any
  1681. one-dimensional array type whose components are  of  a  boolean  type;   in
  1682. either case the two operands have the same type.
  1683.  
  1684.     Operator   Operation               Operand type                  Result type
  1685.  
  1686.     and        conjunction             any boolean type              same boolean type
  1687.                                        array of boolean components   same array type
  1688.  
  1689.     or         inclusive disjunction   any boolean type              same boolean type
  1690.                                        array of boolean components   same array type
  1691.  
  1692.     xor        exclusive disjunction   any boolean type              same boolean type
  1693.                                        array of boolean components   same array type
  1694.  
  1695. The operations on arrays are performed on a component-by-component basis on
  1696. matching  components,  if  any (as for equality, see 4.5.2).  The bounds of
  1697. the resulting array are those of the left operand.  A check  is  made  that
  1698. for each component of the left operand there is a matching component of the
  1699. right operand, and vice versa.  The exception CONSTRAINT_ERROR is raised if
  1700. this check fails.
  1701.  
  1702. The  short-circuit  control  forms and then and or else are defined for two
  1703. operands of a boolean type and deliver a result of the same type.  The left
  1704. operand of a short-circuit control form is always evaluated first.  If  the
  1705. left  operand  of an expression with the control form and then evaluates to
  1706. FALSE, the right operand is not evaluated and the value of  the  expression
  1707. is  FALSE.   If  the left operand of an expression with the control form or
  1708. else evaluates to TRUE, the right operand is not evaluated and the value of
  1709. the expression is TRUE.  If both operands are evaluated, and then  delivers
  1710. the same result as and, and or else delivers the same result as or.
  1711.  
  1712.  
  1713.                                   4 - 25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722. Note:  The  conventional  meaning  of the logical operators is given by the
  1723. following truth table:
  1724.  
  1725.     A        B       (A and B)    (A or B)    (A xor B)
  1726.  
  1727.     TRUE    TRUE     TRUE         TRUE        FALSE
  1728.     TRUE    FALSE    FALSE        TRUE        TRUE
  1729.     FALSE   TRUE     FALSE        TRUE        TRUE
  1730.     FALSE   FALSE    FALSE        FALSE       FALSE
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                   4 - 26
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788. Examples of logical operators:
  1789.  
  1790.     SUNNY or WARM
  1791.     FILTER(1 .. 10) and FILTER(15 .. 24)   --   see 3.6.1
  1792.  
  1793. Examples of short-circuit control forms:
  1794.  
  1795.     NEXT_CAR.OWNER /= null and then NEXT_CAR.OWNER.AGE > 25   --   see 3.8.1
  1796.     N = 0 or else A(N) = HIT_VALUE
  1797.  
  1798. References:  array type 3.6, boolean type 3.5.3, bound of  an  index  range
  1799. 3.6.1,   component  of  an  array  3.6,  constraint_error  exception  11.1,
  1800. dimension 3.6, false boolean  value  3.5.3,  index  subtype  3.6,  matching
  1801. components  of arrays 4.5.2, null array 3.6.1, operation 3.3, operator 4.5,
  1802. predefined operator 4.5, raising  of  exceptions  11,  true  boolean  value
  1803. 3.5.3, type 3.3
  1804.  
  1805.  
  1806.  
  1807. 4.5.2  Relational Operators and Membership Tests
  1808.  
  1809.  
  1810. The  equality  and inequality operators are predefined for any type that is
  1811. not limited.  The other relational operators are the ordering  operators  <
  1812. (less  than),  <=  (less  than or equal), > (greater than), and >= (greater
  1813. than or equal).  The ordering operators   are  predefined  for  any  scalar
  1814. type,  and  for  any  discrete array type, that is, a one-dimensional array
  1815. type whose components are  of  a  discrete  type.   The  operands  of  each
  1816. predefined  relational operator have the same type.  The result type is the
  1817. predefined type BOOLEAN.
  1818.  
  1819. The relational operators have their conventional meaning:   the  result  is
  1820. equal  to  TRUE  if the corresponding relation is satisfied;  the result is
  1821. FALSE otherwise.  The inequality operator gives the complementary result to
  1822. the equality operator:  FALSE if equal, TRUE if not equal.
  1823.  
  1824.     Operator    Operation                 Operand type          Result type
  1825.  
  1826.     = /=        equality and inequality   any type              BOOLEAN
  1827.  
  1828.     < <= > >=   test for ordering         any scalar type       BOOLEAN
  1829.                                           discrete array type   BOOLEAN
  1830.  
  1831. Equality for the discrete types  is  equality  of  the  values.   For  real
  1832. operands  whose  values  are  nearly  equal,  the results of the predefined
  1833. relational operators are given in section 4.5.7.   Two  access  values  are
  1834. equal either if they designate the same object, or if both are equal to the
  1835. null value of the access type.
  1836.  
  1837. For  two  array  values  or  two  record  values of the same type, the left
  1838. operand is equal to the right operand if and only if for each component  of
  1839. the  left  operand  there  is a matching component of the right operand and
  1840. vice versa;  and the values of matching components are equal, as  given  by
  1841. the  predefined  equality  operator for the component type.  In particular,
  1842. two null arrays of the same type are always equal;  two null records of the
  1843.  
  1844.  
  1845.                                   4 - 27
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854. same type are always equal.
  1855.  
  1856. For comparing two records of the same type, matching components  are  those
  1857. which have the same component identifier.
  1858.  
  1859. For  comparing  two  one-dimensional  arrays  of  the  same  type, matching
  1860. components are those (if any) whose index values  match  in  the  following
  1861. sense:   the lower bounds of the index ranges are defined to match, and the
  1862. successors of matching indices are defined to  match.   For  comparing  two
  1863. multidimensional  arrays,  matching components are those whose index values
  1864. match in successive index positions.
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                   4 - 28
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920. If equality is explicitly defined for a limited type, it does not extend to
  1921. composite  types  having  subcomponents  of  the  limited  type   (explicit
  1922. definition of equality is allowed for such composite types).
  1923.  
  1924. The ordering operators <, <=, >, and >= that are defined for discrete array
  1925. types correspond to lexicographic order using the predefined order relation
  1926. of  the  component  type.   A null array is lexicographically less than any
  1927. array having at least one component.  In the case of  nonnull  arrays,  the
  1928. left  operand is lexicographically less than the right operand if the first
  1929. component of the left operand is less than that of  the  right;   otherwise
  1930. the  left  operand is lexicographically less than the right operand only if
  1931. their first components are equal and  the  tail  of  the  left  operand  is
  1932. lexicographically  less  than  that  of the right (the tail consists of the
  1933. remaining components beyond the first and can be null).
  1934.  
  1935. The membership tests in and not in  are  predefined  for  all  types.   The
  1936. result  type  is the predefined type BOOLEAN.  For a membership test with a
  1937. range, the simple expression and the bounds of the range  must  be  of  the
  1938. same  scalar type;  for a membership test with a type mark, the type of the
  1939. simple expression must be the base type of the type mark.   The  evaluation
  1940. of the membership test in yields the result TRUE if the value of the simple
  1941. expression  is  within  the  given  range,  or if this value belongs to the
  1942. subtype denoted by the given type mark;  otherwise this  evaluation  yields
  1943. the  result  FALSE (for a value of a real type, see 4.5.7).  The membership
  1944. test not in gives the complementary result to the membership test in.
  1945.  
  1946. Examples:
  1947.  
  1948.     X /= Y
  1949.  
  1950.     "" < "A" and "A" < "AA"     --  TRUE
  1951.     "AA" < "B" and "A" < "A  "  --  TRUE
  1952.  
  1953.     MY_CAR = null              -- true if MY_CAR has been set to null (see 3.8.1)
  1954.     MY_CAR = YOUR_CAR          -- true if we both share the same car
  1955.     MY_CAR.all = YOUR_CAR.all  -- true if the two cars are identical
  1956.  
  1957.     N not in 1 .. 10     -- range membership test
  1958.     TODAY in MON .. FRI  -- range membership test
  1959.     TODAY in WEEKDAY     -- subtype membership test (see 3.5.1)
  1960.     ARCHIVE in DISK_UNIT -- subtype membership test (see 3.7.3)
  1961.  
  1962. Notes:
  1963.  
  1964. No exception is ever raised by a predefined relational  operator  or  by  a
  1965. membership  test,  but  an exception can be raised by the evaluation of the
  1966. operands.
  1967.  
  1968. If a record type has components that depend on discriminants, two values of
  1969. this type have matching components if and only if their  discriminants  are
  1970. equal.   Two  nonnull  arrays  have  matching components if and only if the
  1971. value of the attribute LENGTH(N) for each index position N is the same  for
  1972. both.
  1973.  
  1974.  
  1975.  
  1976.  
  1977.                                   4 - 29
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986. References:   access  value 3.8, array type 3.6, base type 3.3, belong to a
  1987. subtype 3.3, boolean predefined type 3.5.3, bound of a range 3.5, component
  1988. 3.3, component identifier 3.7, component  type  3.3,  composite  type  3.3,
  1989. designate  3.8, dimension 3.6, discrete type 3.5, evaluation 4.5, exception
  1990. 11, index 3.6, index range 3.6, limited type 7.4.4, null access value  3.8,
  1991. null  array  3.6.1,  null record 3.7, object 3.2.1, operation 3.3, operator
  1992. 4.5, predefined operator 4.5, raising of exceptions 11, range  3.5,  record
  1993. type  3.7,  scalar  type  3.5,  simple  expression  4.4,  subcomponent 3.3,
  1994. successor 3.5.5, type 3.3, type mark 3.3.2
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.                                   4 - 30
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052. 4.5.3  Binary Adding Operators
  2053.  
  2054.  
  2055. The binary adding operators + and -  are predefined for  any  numeric  type
  2056. and  have  their  conventional  meaning.   The  catenation  operators & are
  2057. predefined for any one-dimensional array type that is not limited.
  2058.  
  2059.     Operator  Operation    Left operand type    Right operand type   Result type
  2060.  
  2061.     +         addition     any numeric type     same numeric type    same numeric type
  2062.  
  2063.     -         subtraction  any numeric type     same numeric type    same numeric type
  2064.  
  2065.     &         catenation   any array type       same array type      same array type
  2066.                            any array type       the component type   same array type
  2067.                            the component type   any array type       same array type
  2068.                            the component type   the component type   any array type
  2069.  
  2070. For real types, the accuracy of the result is  determined  by  the  operand
  2071. type (see 4.5.7).
  2072.  
  2073. If  both  operands are one-dimensional arrays, the result of the catenation
  2074. is a one-dimensional array whose length is the sum of the  lengths  of  its
  2075. operands,  and whose components comprise the components of the left operand
  2076. followed by the components of the right operand.  The lower bound  of  this
  2077. result is the lower bound of the left operand, unless the left operand is a
  2078. null  array,  in  which  case  the  result  of  the catenation is the right
  2079. operand.
  2080.  
  2081. If either operand is of the component type of an array type, the result  of
  2082. the  catenation is given by the above rules, using in place of this operand
  2083. an array having this operand as its only component  and  having  the  lower
  2084. bound of the index subtype of the array type as its lower bound.
  2085.  
  2086. The  exception  CONSTRAINT_ERROR is raised by catenation if the upper bound
  2087. of the result exceeds the range of the index subtype, unless the result  is
  2088. a  null  array.   This  exception  is  also raised if any operand is of the
  2089. component type but has a value  that  does  not  belong  to  the  component
  2090. subtype.
  2091.  
  2092. Examples:
  2093.  
  2094.     Z + 0.1      --  Z must be of a real type
  2095.  
  2096.     "A" & "BCD"  --  catenation of two string literals
  2097.     'A' & "BCD"  --  catenation of a character literal and a string literal
  2098.     'A' & 'A'    --  catenation of two character literals
  2099.  
  2100. References:   array  type  3.6,  character literal 2.5, component type 3.3,
  2101. constraint_error exception 11.1, dimension 3.6, index subtype  3.6,  length
  2102. of  an array 3.6.2, limited type 7.4.4, null array 3.6.1, numeric type 3.5,
  2103. operation 3.3, operator 4.5, predefined operator 4.5, raising of exceptions
  2104. 11, range of an index subtype 3.6.1, real type 3.5.6, string  literal  2.6,
  2105. type 3.3
  2106.  
  2107.  
  2108.  
  2109.                                   4 - 31
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118. 4.5.4  Unary Adding Operators
  2119.  
  2120.  
  2121. The  unary adding operators + and - are predefined for any numeric type and
  2122. have their conventional meaning.  For each of these operators, the  operand
  2123. and the result have the same type.
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.                                   4 - 32
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.     Operator   Operation   Operand type       Result type
  2185.  
  2186.     +          identity    any numeric type   same numeric type
  2187.  
  2188.     -          negation    any numeric type   same numeric type
  2189.  
  2190. References:   numeric  type  3.5,  operation  3.3, operator 4.5, predefined
  2191. operator 4.5, type 3.3
  2192.  
  2193.  
  2194.  
  2195. 4.5.5  Multiplying Operators
  2196.  
  2197.  
  2198. The operators * and / are predefined for any integer and any floating point
  2199. type and have their conventional meaning;  the operators mod  and  rem  are
  2200. predefined for any integer type.  For each of these operators, the operands
  2201. and  the  result  have  the  same base type.  For floating point types, the
  2202. accuracy of the result is determined by the operand type (see 4.5.7).
  2203.  
  2204.     Operator   Operation           Operand type              Result type
  2205.  
  2206.     *          multiplication      any integer type          same integer type
  2207.                                    any floating point type   same floating point type
  2208.  
  2209.     /          integer division    any integer type          same integer type
  2210.                floating division   any floating point type   same floating point type
  2211.  
  2212.     mod        modulus             any integer type          same integer type
  2213.  
  2214.     rem        remainder           any integer type          same integer type
  2215.  
  2216. Integer division and remainder are defined by the relation
  2217.  
  2218.     A = (A/B)*B + (A rem B)
  2219.  
  2220. where (A rem B) has the sign of A and  an  absolute  value  less  than  the
  2221. absolute value of B.  Integer division satisfies the identity
  2222.  
  2223.     (-A)/B = -(A/B) = A/(-B)
  2224.  
  2225. The  result of the modulus operation is such that (A mod B) has the sign of
  2226. B and an absolute value less than the absolute value of  B;   in  addition,
  2227. for some integer value N, this result must satisfy the relation
  2228.  
  2229.     A = B*N + (A mod B)
  2230.  
  2231. For  each  fixed  point  type,  the  following  multiplication and division
  2232. operators, with an operand of the predefined type INTEGER, are  predefined.
  2233.  
  2234.     Operator   Operation        Left operand type     Right operand type      Result type
  2235.  
  2236.     *          multiplication   any fixed point type  INTEGER                same as left
  2237.                                 INTEGER               any fixed point type   same as right
  2238.  
  2239.  
  2240.  
  2241.                                   4 - 33
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.     /          division         any fixed point type  INTEGER                same as left
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.                                   4 - 34
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316. Integer  multiplication  of  fixed  point  values is equivalent to repeated
  2317. addition.  Division of a fixed point value by an integer does not involve a
  2318. change in type but is approximate (see 4.5.7).
  2319.  
  2320. Finally, the following multiplication and division operators  are  declared
  2321. in  the  predefined package STANDARD.  These two special operators apply to
  2322. operands of all fixed point types (it is a consequence of other rules  that
  2323. they cannot be renamed or given as generic actual parameters).
  2324.  
  2325.     Operator   Operation        Left operand type      Right operand type     Result type
  2326.  
  2327.     *          multiplication   any fixed point type   any fixed point type   universal_fixed
  2328.  
  2329.     /          division         any fixed point type   any fixed point type   universal_fixed
  2330.  
  2331. Multiplication of operands of the same or of different fixed point types is
  2332. exact  and  delivers  a result of the anonymous predefined fixed point type
  2333. universal_fixed whose delta is arbitrarily small.  The result of  any  such
  2334. multiplication  must  always  be explicitly converted to some numeric type.
  2335. This ensures explicit control of the accuracy of the computation.  The same
  2336. considerations apply to division of a fixed point value  by  another  fixed
  2337. point  value.  No other operators are defined for the type universal_fixed.
  2338.  
  2339. The exception NUMERIC_ERROR is raised by integer division, rem, and mod  if
  2340. the right operand is zero.
  2341.  
  2342.  
  2343. Examples:
  2344.  
  2345.     I : INTEGER := 1;
  2346.     J : INTEGER := 2;
  2347.     K : INTEGER := 3;
  2348.  
  2349.     X : REAL digits 6 := 1.0;             --     see 3.5.7
  2350.     Y : REAL digits 6 := 2.0;
  2351.  
  2352.     F : FRACTION delta 0.0001 := 0.1;     --     see 3.5.9
  2353.     G : FRACTION delta 0.0001 := 0.1;
  2354.  
  2355.  
  2356.     Expression        Value     Result Type
  2357.  
  2358.     I*J               2         same as I and J, that is, INTEGER
  2359.     K/J               1         same as K and J, that is, INTEGER
  2360.     K mod J           1         same as K and J, that is, INTEGER
  2361.  
  2362.     X/Y               0.5       same as X and Y, that is, REAL
  2363.     F/2               0.05      same as F, that is, FRACTION
  2364.  
  2365.     3*F               0.3       same as F, that is, FRACTION
  2366.     F*G               0.01      universal_fixed, conversion needed
  2367.     FRACTION(F*G)     0.01      FRACTION, as stated by the conversion
  2368.     REAL(J)*Y         4.0       REAL, the type of both operands after conversion of J
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                                   4 - 35
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382. Notes:
  2383.  
  2384. For positive A and B, A/B is the quotient and A rem B is the remainder when
  2385. A  is  divided  by  B.   The  following  relations are satisfied by the rem
  2386. operator:
  2387.  
  2388.     A    rem (-B) =   A rem B
  2389.     (-A) rem   B  = -(A rem B)
  2390.  
  2391. For any integer K, the following identity holds:
  2392.  
  2393.       A  mod   B  =  (A + K*B) mod B
  2394.  
  2395. The  relations  between  integer  division,  remainder,  and  modulus   are
  2396. illustrated by the following table:
  2397.  
  2398.  
  2399.     A      B   A/B   A rem B  A mod B     A     B    A/B   A rem B   A mod B
  2400.  
  2401.     10     5     2      0         0      -10     5    -2       0           0
  2402.     11     5     2      1         1      -11     5    -2      -1           4
  2403.     12     5     2      2         2      -12     5    -2      -2           3
  2404.     13     5     2      3         3      -13     5    -2      -3           2
  2405.     14     5     2      4         4      -14     5    -2      -4           1
  2406.  
  2407.     10    -5    -2      0         0      -10    -5     2       0         0
  2408.     11    -5    -2      1        -4      -11    -5     2      -1        -1
  2409.     12    -5    -2      2        -3      -12    -5     2      -2        -2
  2410.     13    -5    -2      3        -2      -13    -5     2      -3        -3
  2411.     14    -5    -2      4        -1      -14    -5     2      -4        -4
  2412.  
  2413. References:   actual parameter 6.4.1, base type 3.3, declaration 3.1, delta
  2414. of a fixed point type 3.5.9, fixed point type 3.5.9,  floating  point  type
  2415. 3.5.7,  generic  formal  subprogram  12.1, integer type 3.5.4, numeric type
  2416. 3.5, numeric_error exception 11.1,  predefined  operator  4.5,  raising  of
  2417. exceptions  11,  renaming declaration 8.5, standard predefined package 8.6,
  2418. type conversion 4.6
  2419.  
  2420.  
  2421.  
  2422. 4.5.6  Highest Precedence Operators
  2423.  
  2424.  
  2425. The highest precedence unary operator abs is  predefined  for  any  numeric
  2426. type.   The  highest  precedence  unary  operator not is predefined for any
  2427. boolean type and any one-dimensional array type  whose  components  have  a
  2428. boolean type.
  2429.  
  2430.     Operator   Operation          Operand type                  Result type
  2431.  
  2432.     abs        absolute value     any numeric type              same numeric type
  2433.  
  2434.     not        logical negation   any boolean type              same boolean type
  2435.                                   array of boolean components   same array type
  2436.  
  2437.  
  2438.  
  2439.                                   4 - 36
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448. The  operator  not  that  applies  to  a  one-dimensional  array of boolean
  2449. components yields a one-dimensional boolean array  with  the  same  bounds;
  2450. each  component  of  the  result  is  obtained  by  logical negation of the
  2451. corresponding component of the operand (that is, the component that has the
  2452. same index value).
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.                                   4 - 37
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514. The highest precedence exponentiating operator ** is  predefined  for  each
  2515. integer  type  and  for each floating point type.  In either case the right
  2516. operand, called the exponent, is of the predefined type INTEGER.
  2517.  
  2518.     Operator  Operation       Left operand type        Right operand type      Result type
  2519.  
  2520.     **        exponentiation  any integer type         INTEGER                 same as left
  2521.                               any floating point type  INTEGER                 same as left
  2522.  
  2523. Exponentiation  with  a  positive  exponent  is  equivalent   to   repeated
  2524. multiplication  of the left operand by itself, as indicated by the exponent
  2525. and from left to right.  For an operand  of  a  floating  point  type,  the
  2526. exponent  can be negative, in which case the value is the reciprocal of the
  2527. value with the  positive  exponent.   Exponentiation  by  a  zero  exponent
  2528. delivers  the  value  one.   Exponentiation of a value of a floating  point
  2529. type is approximate (see 4.5.7).  Exponentiation of an integer  raises  the
  2530. exception CONSTRAINT_ERROR for a negative exponent.
  2531.  
  2532. References:   array  type 3.6, boolean type 3.5.3, bound of an array 3.6.1,
  2533. component of an array 3.6, constraint_error exception 11.1,  dimensionality
  2534. 3.6,   floating   point   type   3.5.9,  index  3.6,  integer  type  3.5.4,
  2535. multiplication  operation  4.5.5,  predefined  operator  4.5,  raising   of
  2536. exceptions 11
  2537.  
  2538.  
  2539.  
  2540. 4.5.7  Accuracy of Operations with Real Operands
  2541.  
  2542.  
  2543. A  real  subtype  specifies  a  set  of  model  numbers.  Both the accuracy
  2544. required from any basic or predefined operation giving a real  result,  and
  2545. the  result of any predefined relation between real operands are defined in
  2546. terms of these model numbers.
  2547.  
  2548. A model interval of a subtype  is  any  interval  whose  bounds  are  model
  2549. numbers  of  the  subtype.  The model interval associated with a value that
  2550. belongs to a real subtype is the smallest model interval (of  the  subtype)
  2551. that  includes  the  value.   (The  model  interval associated with a model
  2552. number of a subtype consists of that number only.)
  2553.  
  2554. For any basic operation or predefined operator that yields a  result  of  a
  2555. real  subtype,  the  required  bounds  on  the  result are given by a model
  2556. interval defined as follows:
  2557.  
  2558.   -  The result model interval is  the  smallest  model  interval  (of  the
  2559.      result  subtype)  that includes the minimum and the maximum of all the
  2560.      values obtained by applying the (exact) mathematical  operation,  when
  2561.      each  operand is given any value of the model interval (of the operand
  2562.      subtype) defined for the operand.
  2563.  
  2564.   -  The model interval of an operand that  is  itself  the  result  of  an
  2565.      operation,  other  than  an  implicit  conversion, is the result model
  2566.      interval of this operation.
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                   4 - 38
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.   -  The model interval of an operand whose value is obtained  by  implicit
  2581.      conversion  of a universal expression is the model interval associated
  2582.      with this value within the operand subtype.
  2583.  
  2584. The result model interval is undefined if the absolute value of one of  the
  2585. above  mathematical  results  exceeds the largest safe number of the result
  2586. type.  Whenever the result  model  interval  is  undefined,  it  is  highly
  2587. desirable  that the exception NUMERIC_ERROR be raised if the implementation
  2588. cannot produce an actual result that is in the range of safe numbers.  This
  2589. is, however, not required by the language rules, in recognition of the fact
  2590. that certain target machines do  not  permit  easy  detection  of  overflow
  2591. situations.  The value of the attribute MACHINE_OVERFLOWS indicates whether
  2592. the   target   machine  raises  the  exception  NUMERIC_ERROR  in  overflow
  2593. situations (see 13.7.3).
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.  
  2606.  
  2607.  
  2608.  
  2609.  
  2610.  
  2611.  
  2612.  
  2613.  
  2614.  
  2615.  
  2616.  
  2617.  
  2618.  
  2619.  
  2620.  
  2621.  
  2622.  
  2623.  
  2624.  
  2625.  
  2626.  
  2627.  
  2628.  
  2629.  
  2630.  
  2631.  
  2632.  
  2633.  
  2634.  
  2635.  
  2636.  
  2637.                                   4 - 39
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646. The safe numbers of a real type are defined (see 3.5.6) as  a  superset  of
  2647. the  model  numbers,  for  which  error bounds follow the same rules as for
  2648. model numbers.  Any definition given in this  section  in  terms  of  model
  2649. intervals  can  therefore be extended to safe intervals of safe numbers.  A
  2650. consequence of this extension is that an implementation is not  allowed  to
  2651. raise  the  exception  NUMERIC_ERROR  when  the  result  interval is a safe
  2652. interval.
  2653.  
  2654. For the result of exponentiation, the model interval defining the bounds on
  2655. the result is obtained by applying the  above  rules  to  the  sequence  of
  2656. multiplications  defined  by the exponent, and to the final division in the
  2657. case of a negative exponent.
  2658.  
  2659. For the result of a relation between two real operands, consider  for  each
  2660. operand  the  model  interval  (of  the  operand  subtype)  defined for the
  2661. operand;  the result can be any value obtained by applying the mathematical
  2662. comparison to values arbitrarily chosen in the corresponding operand  model
  2663. intervals.   If  either or both of the operand model intervals is undefined
  2664. (and if neither of the operand evaluations raises an  exception)  then  the
  2665. result  of  the  comparison  is  allowed to be any possible value (that is,
  2666. either TRUE or FALSE).
  2667.  
  2668. The result of a membership test is defined in terms of comparisons  of  the
  2669. operand  value  with  the lower and upper bounds of the given range or type
  2670. mark (the usual rules apply to these comparisons).
  2671.  
  2672. Note:
  2673.  
  2674. For a floating point type the numbers 15.0, 3.0, and 5.0 are  always  model
  2675. numbers.  Hence X/Y where X equals 15.0 and Y equals 3.0 yields exactly 5.0
  2676. according to the above rules.  In the general case, division does not yield
  2677. model numbers and in consequence one cannot assume that (1.0/X)*X = 1.0.
  2678.  
  2679. References:   attribute 4.1.4, basic operation 3.3.3, bound of a range 3.5,
  2680. error bound 3.5.6, exponentiation  operation  4.5.6,  false  boolean  value
  2681. 3.5.3,  floating  point  type  3.5.9,  machine_overflows  attribute 13.7.1,
  2682. membership test 4.5.2, model number 3.5.6, multiplication operation  4.5.5,
  2683. numeric_error  exception  11.1,  predefined  operation  3.3.3,  raising  of
  2684. exceptions 11,  range  3.5,  real  type  3.5.6,  relation  4.4,  relational
  2685. operator  4.5.2  4.5,  safe  number  3.5.6, subtype 3.3, true boolean value
  2686. 3.5.3, type conversion 4.6, type mark 3.3.2, universal expression 4.10
  2687.  
  2688.  
  2689.  
  2690. 4.6  Type Conversions
  2691.  
  2692.  
  2693. The evaluation of an  explicit type  conversion  evaluates  the  expression
  2694. given  as  the  operand,  and  converts  the resulting value to a specified
  2695. target type.  Explicit type conversions are allowed between closely related
  2696. types as defined below.
  2697.  
  2698.     type_conversion ::= type_mark(expression)
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                   4 - 40
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712. The target type of a type conversion is the base type  of  the  type  mark.
  2713. The  type  of  the  operand  of  a  type  conversion  must  be determinable
  2714. independently of the context (in particular, independently  of  the  target
  2715. type).   Furthermore, the operand of a type conversion is not allowed to be
  2716. a literal null, an allocator,  an  aggregate,  or  a  string  literal;   an
  2717. expression  enclosed  by  parentheses  is  allowed as the operand of a type
  2718. conversion only if the expression alone is allowed.
  2719.  
  2720. A conversion to a subtype consists of  a  conversion  to  the  target  type
  2721. followed  by  a  check  that  the  result  of the conversion belongs to the
  2722. subtype.  A conversion of an operand of a given type to the type itself  is
  2723. allowed.
  2724.  
  2725.  
  2726.  
  2727.  
  2728.  
  2729.  
  2730.  
  2731.  
  2732.  
  2733.  
  2734.  
  2735.  
  2736.  
  2737.  
  2738.  
  2739.  
  2740.  
  2741.  
  2742.  
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750.  
  2751.  
  2752.  
  2753.  
  2754.  
  2755.  
  2756.  
  2757.  
  2758.  
  2759.  
  2760.  
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.  
  2767.  
  2768.  
  2769.                                   4 - 41
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778. The  other  allowed  explicit  type conversions correspond to the following
  2779. three cases:
  2780.  
  2781. (a)  Numeric types
  2782.  
  2783.      The operand can be of any numeric type;  the value of the  operand  is
  2784.      converted  to  the target type which must also be a numeric type.  For
  2785.      conversions involving real types, the result is within the accuracy of
  2786.      the specified subtype (see 4.5.7).  The conversion of a real value  to
  2787.      an  integer  type  rounds  to  the nearest integer;  if the operand is
  2788.      halfway between two integers (within the accuracy of the real subtype)
  2789.      rounding may be either up or down.
  2790.  
  2791. (b)  Derived types
  2792.  
  2793.      The conversion is allowed if one of the target type  and  the  operand
  2794.      type  is  derived  from the other, directly or indirectly, or if there
  2795.      exists a third type from which both types  are  derived,  directly  or
  2796.      indirectly.
  2797.  
  2798. (c)  Array types
  2799.  
  2800.      The  conversion is allowed if the operand type and the target type are
  2801.      array types that satisfy the following conditions:   both  types  must
  2802.      have the same dimensionality;  for each index position the index types
  2803.      must  either  be  the  same  or  be  convertible  to  each other;  the
  2804.      component types must be the same;  finally, if the component type is a
  2805.      type with discriminants or an access type, the component subtypes must
  2806.      be either both constrained or both unconstrained.  If  the  type  mark
  2807.      denotes  an  unconstrained  array type, then, for each index position,
  2808.      the bounds of the result are obtained by converting the bounds of  the
  2809.      operand  to  the  corresponding index type of the target type.  If the
  2810.      type mark denotes a constrained array subtype, then the bounds of  the
  2811.      result  are those imposed by the type mark.  In either case, the value
  2812.      of each component of the result is that of the matching  component  of
  2813.      the operand (see 4.5.2).
  2814.  
  2815. In  the  case  of  conversions  of  numeric  types  and  derived types, the
  2816. exception CONSTRAINT_ERROR is raised by the evaluation of a type conversion
  2817. if the result of the conversion fails to satisfy a  constraint  imposed  by
  2818. the type mark.
  2819.  
  2820. In  the  case  of  array  types, a check is made that any constraint on the
  2821. component subtype is the same for the operand array type as for the  target
  2822. array  type.   If  the type mark denotes an unconstrained array type and if
  2823. the operand is not a null array, then, for each index position, a check  is
  2824. made  that  the  bounds  of  the  result  belong to the corresponding index
  2825. subtype of the target type.  If the type mark denotes a  constrained  array
  2826. subtype,  a check is made that for each component of the operand there is a
  2827. matching component of the target subtype, and vice  versa.   The  exception
  2828. CONSTRAINT_ERROR is raised if any of these checks fails.
  2829.  
  2830. If a conversion is allowed from one type to another, the reverse conversion
  2831. is  also allowed. This reverse conversion is used where an actual parameter
  2832. of mode in out or out has the form of a type  conversion  of  a  (variable)
  2833.  
  2834.  
  2835.                                   4 - 42
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844. name as explained in section 6.4.1.
  2845.  
  2846. Apart  from  the  explicit  type conversions, the only allowed form of type
  2847. conversion  is  the  implicit  conversion  of   a   value   of   the   type
  2848. universal_integer or universal_real into another numeric type.  An implicit
  2849. conversion of an operand of type universal_integer to another integer type,
  2850. or  of  an operand of type universal_real to another real type, can only be
  2851. applied if the operand is either a numeric literal, a named number,  or  an
  2852. attribute;   such  an  operand is called a convertible universal operand in
  2853. this section.  An implicit conversion of a convertible universal operand is
  2854. applied if and only if the innermost complete context (see 8.7)  determines
  2855. a unique (numeric) target type for the implicit conversion, and there is no
  2856. legal interpretation of this context without this conversion.
  2857.  
  2858.  
  2859.  
  2860.  
  2861.  
  2862.  
  2863.  
  2864.  
  2865.  
  2866.  
  2867.  
  2868.  
  2869.  
  2870.  
  2871.  
  2872.  
  2873.  
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.                                   4 - 43
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910. Notes:
  2911.  
  2912. The  rules  for  implicit  conversions imply that no implicit conversion is
  2913. ever applied to the operand of an  explicit  type  conversion.   Similarly,
  2914. implicit  conversions  are  not  applied  if  both operands of a predefined
  2915. relational operator are convertible universal operands.
  2916.  
  2917. The language allows implicit subtype conversions in the case of array types
  2918. (see 5.2.1).  An explicit type conversion can have the effect of  a  change
  2919. of  representation (in particular see 13.6).  Explicit conversions are also
  2920. used for actual parameters (see 6.4).
  2921.  
  2922. Examples of numeric type conversion:
  2923.  
  2924.     REAL(2*J)      --  value is converted to floating point
  2925.     INTEGER(1.6)   --  value is 2
  2926.     INTEGER(-0.4)  --  value is 0
  2927.  
  2928. Example of conversion between derived types:
  2929.  
  2930.     type A_FORM is new B_FORM;
  2931.  
  2932.     X : A_FORM;
  2933.     Y : B_FORM;
  2934.  
  2935.     X := A_FORM(Y);
  2936.     Y := B_FORM(X);  --  the reverse conversion
  2937.  
  2938. Examples of conversions between array types:
  2939.  
  2940.     type SEQUENCE is array (INTEGER range <>) of INTEGER;
  2941.     subtype DOZEN is SEQUENCE(1 .. 12);
  2942.     LEDGER : array(1 .. 100) of INTEGER;
  2943.  
  2944.     SEQUENCE(LEDGER)            --  bounds are those of LEDGER
  2945.     SEQUENCE(LEDGER(31 .. 42))  --  bounds are 31 and 42
  2946.     DOZEN(LEDGER(31 .. 42))     --  bounds are those of DOZEN
  2947.  
  2948. Examples of implicit conversions:
  2949.  
  2950.     X : INTEGER := 2;
  2951.  
  2952.     X + 1 + 2              -- implicit conversion of each integer literal
  2953.     1 + 2 + X              -- implicit conversion of each integer literal
  2954.     X + (1 + 2)            -- implicit conversion of each integer literal
  2955.  
  2956.     2 = (1 + 1)            -- no implicit conversion:  the type is universal_integer
  2957.     A'LENGTH = B'LENGTH    -- no implicit conversion:  the type is universal_integer
  2958.     C : constant := 3 + 2; -- no implicit conversion:  the type is universal_integer
  2959.  
  2960.     X = 3 and 1 = 2        -- implicit conversion of 3, but not of 1 and 2
  2961.  
  2962. References:  actual parameter 6.4.1, array type 3.6, attribute 4.1.4,  base
  2963. type 3.3, belong to a subtype 3.3, component 3.3, constrained array subtype
  2964. 3.6,  constraint_error  exception  11.1,  derived  type 3.4, dimension 3.6,
  2965.  
  2966.  
  2967.                                   4 - 44
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976. expression 4.4, floating point type 3.5.7, index 3.6,  index  subtype  3.6,
  2977. index  type  3.6,  integer  type 3.5.4, matching component 4.5.2, mode 6.1,
  2978. name 4.1, named number 3.2, null array 3.6.1, numeric literal 2.4,  numeric
  2979. type  3.5,  raising of exceptions 11, real type 3.5.6, representation 13.1,
  2980. statement 5, subtype 3.3, type 3.3, type mark  3.3.2,  unconstrained  array
  2981. type 3.6, universal_integer type 3.5.4, universal_real type 3.5.6, variable
  2982. 3.2.1
  2983.  
  2984.  
  2985.  
  2986.  
  2987.  
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.  
  3017.  
  3018.  
  3019.  
  3020.  
  3021.  
  3022.  
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.  
  3031.  
  3032.  
  3033.                                   4 - 45
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042. 4.7  Qualified Expressions
  3043.  
  3044.  
  3045. A  qualified  expression is used to state explicitly the type, and possibly
  3046. the subtype, of an operand that is the given expression or aggregate.
  3047.  
  3048.     qualified_expression ::=
  3049.        type_mark'(expression) | type_mark'aggregate
  3050.  
  3051. The operand must have the same type as the base type of the type mark.  The
  3052. value of  a  qualified  expression  is  the  value  of  the  operand.   The
  3053. evaluation  of a qualified expression evaluates the operand and checks that
  3054. its value belongs to the subtype denoted by the type mark.   The  exception
  3055. CONSTRAINT_ERROR is raised if this check fails.
  3056.  
  3057. Examples:
  3058.  
  3059.     type MASK is (FIX, DEC, EXP, SIGNIF);
  3060.     type CODE is (FIX, CLA, DEC, TNZ, SUB);
  3061.  
  3062.     PRINT (MASK'(DEC));  --  DEC is of type MASK
  3063.     PRINT (CODE'(DEC));  --  DEC is of type CODE
  3064.  
  3065.     for J in CODE'(FIX) .. CODE'(DEC) loop ... -- qualification needed for either FIX or DEC
  3066.     for J in CODE range FIX .. DEC loop ...    -- qualification unnecessary
  3067.     for J in CODE'(FIX) .. DEC loop ...        -- qualification unnecessary for DEC
  3068.  
  3069.     DOZEN'(1 | 3 | 5 | 7 => 2, others => 0) -- see 4.6
  3070.  
  3071. Notes:
  3072.  
  3073. Whenever  the type of an enumeration literal or aggregate is not known from
  3074. the context,  a  qualified  expression  can  be  used  to  state  the  type
  3075. explicitly.   For  example,  an  overloaded  enumeration  literal  must  be
  3076. qualified in the  following  cases:   when  given  as  a  parameter   in  a
  3077. subprogram  call  to  an  overloaded  subprogram  that  cannot otherwise be
  3078. identified on the basis of  remaining  parameter  or  result  types,  in  a
  3079. relational  expression  where  both  operands  are  overloaded  enumeration
  3080. literals, or in an array or loop parameter  range  where  both  bounds  are
  3081. overloaded  enumeration  literals.   Explicit qualification is also used to
  3082. specify which one of a set of overloaded parameterless functions is  meant,
  3083. or to constrain a value to a given subtype.
  3084.  
  3085. References:  aggregate 4.3, array 3.6, base type 3.3, bound of a range 3.5,
  3086. constraint_error  exception  11.1,  context  of  overload  resolution  8.7,
  3087. enumeration literal 3.5.1, expression 4.4,  function  6.5,  loop  parameter
  3088. 5.5,  overloading  8.5,  raising of exceptions 11, range 3.3, relation 4.4,
  3089. subprogram 6, subprogram call 6.4, subtype 3.3, type 3.3, type mark 3.3.2
  3090.  
  3091.  
  3092.  
  3093. 4.8  Allocators
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.                                   4 - 46
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108. The evaluation of an allocator creates an object and yields an access value
  3109. that designates the object.
  3110.  
  3111.     allocator ::=
  3112.        new subtype_indication | new qualified_expression
  3113.  
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119.  
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.  
  3128.  
  3129.  
  3130.  
  3131.  
  3132.  
  3133.  
  3134.  
  3135.  
  3136.  
  3137.  
  3138.  
  3139.  
  3140.  
  3141.  
  3142.  
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150.  
  3151.  
  3152.  
  3153.  
  3154.  
  3155.  
  3156.  
  3157.  
  3158.  
  3159.  
  3160.  
  3161.  
  3162.  
  3163.  
  3164.  
  3165.                                   4 - 47
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174. The type of the object created by an allocator is the base type of the type
  3175. mark given in either the subtype indication or  the  qualified  expression.
  3176. For  an  allocator with a qualified expression, this expression defines the
  3177. initial value of the created object.  The type of the access value returned
  3178. by an allocator must be determinable solely from the context, but using the
  3179. fact that the value  returned  is  of  an  access  type  having  the  named
  3180. designated type.
  3181.  
  3182. The  only  allowed  forms  of  constraint  in  the subtype indication of an
  3183. allocator are index and discriminant constraints.  If an allocator includes
  3184. a subtype indication and if the type of the object created is an array type
  3185. or a type with discriminants that do not have default expressions, then the
  3186. subtype indication must either denote a constrained subtype, or include  an
  3187. explicit index or discriminant constraint.
  3188.  
  3189. If  the  type  of  the  created  object  is  an  array  type or a type with
  3190. discriminants, then the created  object  is  always  constrained.   If  the
  3191. allocator  includes a subtype indication, the created object is constrained
  3192. either by the subtype or  by  the  default  discriminant  values.   If  the
  3193. allocator   includes   a   qualified  expression,  the  created  object  is
  3194. constrained by the bounds or discriminants of the initial value.  For other
  3195. types, the subtype of the created object is  the  subtype  defined  by  the
  3196. subtype indication of the access type definition.
  3197.  
  3198. For  the  evaluation  of  an  allocator,  the  elaboration  of  the subtype
  3199. indication or the evaluation  of  the  qualified  expression  is  performed
  3200. first.  The new object is then created.  Initializations are then performed
  3201. as  for  a  declared  object (see 3.2.1);  the initialization is considered
  3202. explicit in the case of a qualified expression;   any  initializations  are
  3203. implicit  in  the  case  of a subtype indication.  Finally, an access value
  3204. that designates the created object is returned.
  3205.  
  3206. An implementation must guarantee that any object created by the  evaluation
  3207. of  an allocator remains allocated for as long as this object or one of its
  3208. subcomponents is accessible directly or indirectly, that is, as long as  it
  3209. can  be  denoted  by  some  name.   Moreover,  if  an  object or one of its
  3210. subcomponents belongs to a task type, it is considered to be accessible  as
  3211. long  as  the task is not terminated.  An implementation may (but need not)
  3212. reclaim the storage occupied by an object created  by  an  allocator,  once
  3213. this object has become inaccessible.
  3214.  
  3215. When  an  application  needs  closer  control  over  storage allocation for
  3216. objects designated by values  of  an  access  type,  such  control  may  be
  3217. achieved by one or more of the following means:
  3218.  
  3219. (a)  The total amount of storage available for the collection of objects of
  3220.      an access type can be set by means of a length clause (see 13.2).
  3221.  
  3222. (b)  The  pragma  CONTROLLED  informs  the  implementation  that  automatic
  3223.      storage  reclamation  must  not be performed for objects designated by
  3224.      values of the access type, except upon  leaving  the  innermost  block
  3225.      statement, subprogram body, or task body that encloses the access type
  3226.      declaration, or after leaving the main program.
  3227.  
  3228.  
  3229.  
  3230.  
  3231.                                   4 - 48
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.         pragma CONTROLLED (access_type_simple_name);
  3241.  
  3242.      A  pragma  CONTROLLED  for  a given access type is allowed at the same
  3243.      places as a representation clause  for  the  type  (see  13.1).   This
  3244.      pragma is not allowed for a derived type.
  3245.  
  3246. (c)  The explicit deallocation of the object designated by an access  value
  3247.      can  be  achieved  by calling a procedure obtained by instantiation of
  3248.      the predefined generic library procedure  UNCHECKED_DEALLOCATION  (see
  3249.      13.10.1).
  3250.  
  3251. The  exception  STORAGE_ERROR  is  raised  by  an allocator if there is not
  3252. enough storage.  Note also  that  the  exception  CONSTRAINT_ERROR  can  be
  3253. raised by the evaluation of the qualified expression, by the elaboration of
  3254. the subtype indication, or by the initialization.
  3255.  
  3256.  
  3257.  
  3258.  
  3259.  
  3260.  
  3261.  
  3262.  
  3263.  
  3264.  
  3265.  
  3266.  
  3267.  
  3268.  
  3269.  
  3270.  
  3271.  
  3272.  
  3273.  
  3274.  
  3275.  
  3276.  
  3277.  
  3278.  
  3279.  
  3280.  
  3281.  
  3282.  
  3283.  
  3284.  
  3285.  
  3286.  
  3287.  
  3288.  
  3289.  
  3290.  
  3291.  
  3292.  
  3293.  
  3294.  
  3295.  
  3296.  
  3297.                                   4 - 49
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306. Examples (for access types declared in section 3.8):
  3307.  
  3308.  
  3309.     new CELL'(0, null, null)                          -- initialized explicitly
  3310.     new CELL'(VALUE => 0, SUCC => null, PRED => null) -- initialized explicitly
  3311.     new CELL                                          -- not initialized
  3312.  
  3313.     new MATRIX(1 .. 10, 1 .. 20)                      -- the bounds only are given
  3314.     new MATRIX'(1 .. 10 => (1 .. 20 => 0.0))          -- initialized explicitly
  3315.  
  3316.     new BUFFER(100)                                   -- the discriminant only is given
  3317.  
  3318.     new BUFFER'(SIZE => 80, POS => 0, VALUE => (1 .. 80 => 'A')) -- initialized explicitly
  3319.  
  3320. References:  access type 3.8, access type definition 3.8, access value 3.8,
  3321. array  type  3.6,  block statement 5.6, bound of an array 3.6.1, collection
  3322. 3.8, constrained subtype 3.3, constraint  3.3,  constraint_error  exception
  3323. 11.1,  context of overload resolution 8.7, derived type 3.4, designate 3.8,
  3324. discriminant  3.3,  discriminant   constraint   3.7.2,   elaboration   3.9,
  3325. evaluation  of  a  qualified  expression 4.7, generic procedure 12.1, index
  3326. constraint 3.6.1, initial value 3.2.1, initialization 3.2.1,  instantiation
  3327. 12.3,  length  clause 13.2, library unit 10.1, main program 10.1, name 4.1,
  3328. object 3.2.1, object declaration 3.2.1, pragma 2.8, procedure 6,  qualified
  3329. expression  4.7,  raising  of  exceptions  11,  representation clause 13.1,
  3330. simple name 4.1, storage_error exception 11.1, subcomponent 3.3, subprogram
  3331. body 6.3, subtype 3.3, subtype indication 3.3.2, task body 9.1,  task  type
  3332. 9.2, terminated task 9.4, type 3.3, type declaration 3.3.1, type mark 3.3.2
  3333. type with discriminants 3.3
  3334.  
  3335.  
  3336.  
  3337. 4.9  Static Expressions and Static Subtypes
  3338.  
  3339.  
  3340. Certain  expressions  of  a  scalar type are said to be static.  Similarly,
  3341. certain discrete ranges are said to  be  static,  and  the  type  marks  of
  3342. certain scalar subtypes are said to denote static subtypes.
  3343.  
  3344. An  expression  of  a scalar type is said to be static if and only if every
  3345. primary is one of those listed in (a) through  (h)  below,  every  operator
  3346. denotes  a  predefined  operator,  and  the  evaluation  of  the expression
  3347. delivers a value (that is, it does not raise an exception):
  3348.  
  3349. (a)  An enumeration literal (including a character literal).
  3350.  
  3351. (b)  A numeric literal.
  3352.  
  3353. (c)  A named number.
  3354.  
  3355. (d)  A constant explicitly declared by a constant declaration with a static
  3356.      subtype, and initialized with a static expression.
  3357.  
  3358. (e)  A function call whose function name is an operator symbol that denotes
  3359.      a predefined operator, including a function name that is  an  expanded
  3360.      name;  each actual parameter must also be a static expression.
  3361.  
  3362.  
  3363.                                   4 - 50
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372. (f)  A language-defined attribute of a static subtype;   for  an  attribute
  3373.      that  is  a  function,  the  actual  parameter  must  also be a static
  3374.      expression.
  3375.  
  3376.  
  3377.  
  3378.  
  3379.  
  3380.  
  3381.  
  3382.  
  3383.  
  3384.  
  3385.  
  3386.  
  3387.  
  3388.  
  3389.  
  3390.  
  3391.  
  3392.  
  3393.  
  3394.  
  3395.  
  3396.  
  3397.  
  3398.  
  3399.  
  3400.  
  3401.  
  3402.  
  3403.  
  3404.  
  3405.  
  3406.  
  3407.  
  3408.  
  3409.  
  3410.  
  3411.  
  3412.  
  3413.  
  3414.  
  3415.  
  3416.  
  3417.  
  3418.  
  3419.  
  3420.  
  3421.  
  3422.  
  3423.  
  3424.  
  3425.  
  3426.  
  3427.  
  3428.  
  3429.                                   4 - 51
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438. (g)  A qualified expression whose type mark denotes a  static  subtype  and
  3439.      whose operand is a static expression.
  3440.  
  3441. (h)  A static expression enclosed in parentheses.
  3442.  
  3443. A  static  range  is a range whose bounds are static expressions.  A static
  3444. range constraint is a range constraint whose range  is  static.   A  static
  3445. subtype is either a scalar base type, other than a generic formal type;  or
  3446. a  scalar  subtype  formed  by imposing on a static subtype either a static
  3447. range constraint, or a floating  or  fixed  point  constraint  whose  range
  3448. constraint,  if any, is static.  A static discrete range is either a static
  3449. subtype or  a  static  range.   A  static  index  constraint  is  an  index
  3450. constraint  for which each index subtype of the corresponding array type is
  3451. static, and in which each discrete range is static.  A static  discriminant
  3452. constraint  is  a  discriminant  constraint  for  which the subtype of each
  3453. discriminant is static, and in which each expression is static.
  3454.  
  3455. Notes:
  3456.  
  3457. The accuracy of the evaluation of a static expression having a real type is
  3458. defined by the rules given in section 4.5.7.  If the result is not a  model
  3459. number  (or  a  safe  number)  of  the  type,  the  value  obtained by this
  3460. evaluation at compilation time need not be the same as the value that would
  3461. be obtained by an evaluation at run time.
  3462.  
  3463. Array attributes are not static:  in particular, the RANGE attribute is not
  3464. static.
  3465.  
  3466. References:  actual parameter 6.4.1, attribute 4.1.4, base type 3.3,  bound
  3467. of a range 3.5, character literal 2.5, constant 3.2.1, constant declaration
  3468. 3.2.1,  discrete  range  3.6, discrete type 3.5, enumeration literal 3.5.1,
  3469. exception 11, expression 4.4, function 6.5, generic actual parameter  12.3,
  3470. generic  formal  type  12.1.2,  implicit declaration 3.1, initialize 3.2.1,
  3471. model number 3.5.6, named  number  3.2,  numeric  literal  2.4,  predefined
  3472. operator  4.5,  qualified  expression  4.7, raising of exceptions 11, range
  3473. constraint 3.5, safe number 3.5.6, scalar type 3.5, subtype 3.3, type  mark
  3474. 3.3.2
  3475.  
  3476.  
  3477.  
  3478. 4.10  Universal Expressions
  3479.  
  3480.  
  3481. A  universal_expression  is  either an expression that delivers a result of
  3482. type  universal_integer  or  one   that   delivers   a   result   of   type
  3483. universal_real.
  3484.  
  3485. The  same  operations  are predefined for the type universal_integer as for
  3486. any integer  type.   The  same  operations  are  predefined  for  the  type
  3487. universal_real  as  for  any  floating  point  type.   In  addition,  these
  3488. operations include the following multiplication and division operators:
  3489.  
  3490.     Operator  Operation       Left operand type  Right operand type  Result type
  3491.  
  3492.  
  3493.  
  3494.  
  3495.                                   4 - 52
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.     *         multiplication  universal_real     universal_integer   universal_real
  3505.                               universal_integer  universal_real      universal_real
  3506.  
  3507.     /         division        universal_real     universal_integer   universal_real
  3508.  
  3509. The  accuracy  of  the  evaluation  of  a  universal  expression  of   type
  3510. universal_real  is at least as good as that of the most accurate predefined
  3511. floating  point  type  supported  by   the   implementation,   apart   from
  3512. universal_real  itself.  Furthermore, if a universal expression is a static
  3513. expression, then the evaluation must be exact.
  3514.  
  3515.  
  3516.  
  3517.  
  3518.  
  3519.  
  3520.  
  3521.  
  3522.  
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.  
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.                                   4 - 53
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570. For the evaluation of an operation of a nonstatic universal expression,  an
  3571. implementation  is allowed to raise the exception NUMERIC_ERROR only if the
  3572. result of the operation is a real value whose absolute  value  exceeds  the
  3573. largest  safe  number  of  the most accurate predefined floating point type
  3574. (excluding universal_real), or an integer value greater than SYSTEM.MAX_INT
  3575. or less than SYSTEM.MIN_INT.
  3576.  
  3577. Note:
  3578.  
  3579. It is a consequence of the  above  rules  that  the  type  of  a  universal
  3580. expression   is   universal_integer  if  every  primary  contained  in  the
  3581. expression is of this type (excluding actual parameters of attributes  that
  3582. are  functions,  and  excluding right operands of exponentiation operators)
  3583. and that otherwise the type is universal_real.
  3584.  
  3585. Examples:
  3586.  
  3587.     1 + 1       -- 2
  3588.     abs(-10)*3  -- 30
  3589.  
  3590.     KILO : constant := 1000;
  3591.     MEGA : constant := KILO*KILO;   -- 1_000_000
  3592.     LONG : constant := FLOAT'DIGITS*2;
  3593.  
  3594.     HALF_PI    : constant := PI/2;           -- see 3.2.2
  3595.     DEG_TO_RAD : constant := HALF_PI/90;
  3596.     RAD_TO_DEG : constant := 1.0/DEG_TO_RAD; -- equivalent to 1.0/((3.14159_26536/2)/90)
  3597.  
  3598. References:  actual parameter 6.4.1,  attribute  4.1.4,  evaluation  of  an
  3599. expression  4.5,  floating  point  type  3.5.9,  function 6.5, integer type
  3600. 3.5.4, multiplying operator 4.5 4.5.5, predefined operation 3.3.3,  primary
  3601. 4.4,   real   type   3.5.6,   safe   number   3.5.6,  system.max_int  13.7,
  3602. system.min_int 13.7, type 3.3, universal_integer type 3.5.4, universal_real
  3603. type 3.5.6
  3604.  
  3605.  
  3606.  
  3607.  
  3608.  
  3609.  
  3610.  
  3611.  
  3612.  
  3613.  
  3614.  
  3615.  
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621.  
  3622.  
  3623.  
  3624.  
  3625.  
  3626.  
  3627.                                   4 - 54
  3628.  
  3629.  
  3630.  
  3631.  
  3632.