home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / docs / rm / aarm.doc next >
Encoding:
Text File  |  1996-04-29  |  1.9 MB  |  42,837 lines

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                   INTERNATIONAL STANDARD ISO/IEC 8652:1995(E)
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. INFORMATION TECHNOLOGY -- PROGRAMMING LANGUAGES -- ADA
  23.  
  24. [Revision of first edition (ISO 8652:1987)]
  25.  
  26.                                   ANNOTATED
  27.                             ADA REFERENCE MANUAL
  28.  
  29.  
  30.                        Language and Standard Libraries
  31.  
  32.                                 Version 5.95
  33.                               25 November 1994
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. Copyright (C) 1992,1993,1994,1995  Intermetrics, Inc.
  43.  
  44. This copyright is assigned to the U.S. Government.  All rights reserved.
  45.  
  46. This document may be copied, in whole or in part, in any form or by any
  47. means, as is or with alterations, provided that (1) alterations are clearly
  48. marked as alterations and (2) this copyright notice is included unmodified in
  49. any copy.  Compiled copies of standard library units and examples need not
  50. contain this copyright notice so long as the notice is included in all copies
  51. of source code and documentation.
  52. INTERNATIONAL ORGANIZATION FOR STANDARDIZATION
  53. INTERNATIONAL ELECTROTECHNICAL COMMISSION
  54. Foreword
  55.  
  56.  
  57. 1   ISO (the International Organization for Standardization) and IEC (the
  58. International Electrotechnical Commission) form the specialized system for
  59. worldwide standardization.  National bodies that are members of ISO or IEC
  60. participate in the development of International Standards through technical
  61. committees established by the respective organization to deal with particular
  62. fields of technical activity.  ISO and IEC technical committees collaborate
  63. in fields of mutual interest.  Other international organizations,
  64. governmental and non-governmental, in liaison with ISO and IEC, also take
  65. part in the work.
  66.  
  67. 2   In the field of information technology, ISO and IEC have established a
  68. joint technical committee, ISO/IEC JTC 1.  Draft International Standards
  69. adopted by the joint technical committee are circulated to national bodies
  70. for voting.  Publication as an International Standard requires approval by at
  71. least 75 % of the national bodies casting a vote.
  72.  
  73. 3   International Standard ISO/IEC 8652 was prepared by Joint Technical
  74. Committee ISO/IEC JTC 1, Information Technology.
  75.  
  76. 4   This second edition cancels and replaces the first edition (ISO
  77. 8652:1987), of which it constitutes a technical revision.
  78.  
  79. 5   Annexes A to J form an integral part of this International Standard.
  80. Annexes K to P are for information only.
  81.  
  82.         5.a   Change:  Changed Annex letters as per instructions from ISO.
  83.  
  84.         5.b   Discussion:  This document is the Annotated Ada Reference
  85.         Manual (AARM).  It contains the entire text of the Ada 9X standard
  86.         (ISO/IEC 8652:1995(E)), plus various annotations.  It is intended
  87.         primarily for compiler writers, validation test writers, and other
  88.         language lawyers.  The annotations include detailed rationale for
  89.         individual rules and explanations of some of the more arcane
  90.         interactions among the rules.
  91. Introduction
  92.  
  93.  
  94. 1   This is the Annotated Ada Reference Manual.
  95.  
  96. 2   Other available Ada documents include:
  97.  
  98.     3  Rationale for the Ada Programming Language -- 1995 edition, which
  99.        gives an introduction to the new features of Ada, and explains
  100.        the rationale behind them.  Programmers should read this first.
  101.  
  102.     4  The Ada Reference Manual (RM).  This is the International
  103.        Standard -- ISO/IEC 8652:1995(E).
  104.  
  105.     5  Changes to Ada -- 1987 to 1995.  This document lists in detail
  106.        the changes made to the 1987 edition of the standard.
  107.  
  108.  
  109. Design Goals
  110.  
  111. 6   Ada was originally designed with three overriding concerns:  program
  112. reliability and maintenance, programming as a human activity, and efficiency.
  113. This revision to the language was designed to provide greater flexibility and
  114. extensibility, additional control over storage management and synchroniza-
  115. tion, and standardized packages oriented toward supporting important
  116. application areas, while at the same time retaining the original emphasis on
  117. reliability, maintainability, and efficiency.
  118.  
  119. 7   The need for languages that promote reliability and simplify maintenance
  120. is well established.  Hence emphasis was placed on program readability over
  121. ease of writing.  For example, the rules of the language require that program
  122. variables be explicitly declared and that their type be specified.  Since the
  123. type of a variable is invariant, compilers can ensure that operations on
  124. variables are compatible with the properties intended for objects of the
  125. type.  Furthermore, error-prone notations have been avoided, and the syntax
  126. of the language avoids the use of encoded forms in favor of more English-like
  127. constructs.  Finally, the language offers support for separate compilation of
  128. program units in a way that facilitates program development and maintenance,
  129. and which provides the same degree of checking between units as within a
  130. unit.
  131.  
  132. 8   Concern for the human programmer was also stressed during the design.
  133. Above all, an attempt was made to keep to a relatively small number of
  134. underlying concepts integrated in a consistent and systematic way while
  135. continuing to avoid the pitfalls of excessive involution.  The design
  136. especially aims to provide language constructs that correspond intuitively to
  137. the normal expectations of users.
  138.  
  139. 9   Like many other human activities, the development of programs is becoming
  140. ever more decentralized and distributed.  Consequently, the ability to
  141. assemble a program from independently produced software components continues
  142. to be a central idea in the design.  The concepts of packages, of private
  143. types, and of generic units are directly related to this idea, which has
  144. ramifications in many other aspects of the language.  An allied concern is
  145. the maintenance of programs to match changing requirements; type extension
  146. and the hierarchical library enable a program to be modified while minimizing
  147. disturbance to existing tested and trusted components.
  148.  
  149. 10   No language can avoid the problem of efficiency.  Languages that require
  150. over-elaborate compilers, or that lead to the inefficient use of storage or
  151. execution time, force these inefficiencies on all machines and on all
  152. programs.  Every construct of the language was examined in the light of
  153. present implementation techniques.  Any proposed construct whose
  154. implementation was unclear or that required excessive machine resources was
  155. rejected.
  156.  
  157.  
  158. Language Summary
  159.  
  160. 11   An Ada program is composed of one or more program units.  Program units
  161. may be subprograms (which define executable algorithms), packages (which
  162. define collections of entities), task units (which define concurrent
  163. computations), protected units (which define operations for the coordinated
  164. sharing of data between tasks), or generic units (which define parameterized
  165. forms of packages and subprograms).  Each program unit normally consists of
  166. two parts:  a specification, containing the information that must be visible
  167. to other units, and a body, containing the implementation details, which need
  168. not be visible to other units.  Most program units can be compiled
  169. separately.
  170.  
  171. 12   This distinction of the specification and body, and the ability to
  172. compile units separately, allows a program to be designed, written, and
  173. tested as a set of largely independent software components.
  174.  
  175. 13   An Ada program will normally make use of a library of program units of
  176. general utility.  The language provides means whereby individual
  177. organizations can construct their own libraries.  All libraries are
  178. structured in a hierarchical manner; this enables the logical decomposition
  179. of a subsystem into individual components.  The text of a separately compiled
  180. program unit must name the library units it requires.
  181.  
  182. 14   Program Units
  183.  
  184. 15   A subprogram is the basic unit for expressing an algorithm.  There are
  185. two kinds of subprograms: procedures and functions.  A procedure is the means
  186. of invoking a series of actions.  For example, it may read data, update
  187. variables, or produce some output.  It may have parameters, to provide a
  188. controlled means of passing information between the procedure and the point
  189. of call.  A function is the means of invoking the computation of a value.  It
  190. is similar to a procedure, but in addition will return a result.
  191.  
  192. 16   A package is the basic unit for defining a collection of logically
  193. related entities.  For example, a package can be used to define a set of type
  194. declarations and associated operations.  Portions of a package can be hidden
  195. from the user, thus allowing access only to the logical properties expressed
  196. by the package specification.
  197.  
  198. 17   Subprogram and package units may be compiled separately and arranged in
  199. hierarchies of parent and child units giving fine control over visibility of
  200. the logical properties and their detailed implementation.
  201.  
  202. 18   A task unit is the basic unit for defining a task whose sequence of
  203. actions may be executed concurrently with those of other tasks.  Such tasks
  204. may be implemented on multicomputers, multiprocessors, or with interleaved
  205. execution on a single processor.  A task unit may define either a single
  206. executing task or a task type permitting the creation of any number of
  207. similar tasks.
  208.  
  209. 19   A protected unit is the basic unit for defining protected operations for
  210. the coordinated use of data shared between tasks.  Simple mutual exclusion is
  211. provided automatically, and more elaborate sharing protocols can be defined.
  212. A protected operation can either be a subprogram or an entry.  A protected
  213. entry specifies a Boolean expression (an entry barrier) that must be true
  214. before the body of the entry is executed.  A protected unit may define a
  215. single protected object or a protected type permitting the creation of
  216. several similar objects.
  217.  
  218. 20   Declarations and Statements
  219.  
  220. 21   The body of a program unit generally contains two parts: a declarative
  221. part, which defines the logical entities to be used in the program unit, and
  222. a sequence of statements, which defines the execution of the program unit.
  223.  
  224. 22   The declarative part associates names with declared entities.  For
  225. example, a name may denote a type, a constant, a variable, or an exception.
  226. A declarative part also introduces the names and parameters of other nested
  227. subprograms, packages, task units, protected units, and generic units to be
  228. used in the program unit.
  229.  
  230. 23   The sequence of statements describes a sequence of actions that are to
  231. be performed.  The statements are executed in succession (unless a transfer
  232. of control causes execution to continue from another place).
  233.  
  234. 24   An assignment statement changes the value of a variable.  A procedure
  235. call invokes execution of a procedure after associating any actual parameters
  236. provided at the call with the corresponding formal parameters.
  237.  
  238. 25   Case statements and if statements allow the selection of an enclosed
  239. sequence of statements based on the value of an expression or on the value of
  240. a condition.
  241.  
  242. 26   The loop statement provides the basic iterative mechanism in the
  243. language.  A loop statement specifies that a sequence of statements is to be
  244. executed repeatedly as directed by an iteration scheme, or until an exit
  245. statement is encountered.
  246.  
  247. 27   A block statement comprises a sequence of statements preceded by the
  248. declaration of local entities used by the statements.
  249.  
  250. 28   Certain statements are associated with concurrent execution.  A delay
  251. statement delays the execution of a task for a specified duration or until a
  252. specified time.  An entry call statement is written as a procedure call
  253. statement; it requests an operation on a task or on a protected object,
  254. blocking the caller until the operation can be performed.  A called task may
  255. accept an entry call by executing a corresponding accept statement, which
  256. specifies the actions then to be performed as part of the rendezvous with the
  257. calling task.  An entry call on a protected object is processed when the
  258. corresponding entry barrier evaluates to true, whereupon the body of the
  259. entry is executed.  The requeue statement permits the provision of a service
  260. as a number of related activities with preference control.  One form of the
  261. select statement allows a selective wait for one of several alternative
  262. rendezvous.  Other forms of the select statement allow conditional or timed
  263. entry calls and the asynchronous transfer of control in response to some
  264. triggering event.
  265.  
  266. 29   Execution of a program unit may encounter error situations in which
  267. normal program execution cannot continue.  For example, an arithmetic
  268. computation may exceed the maximum allowed value of a number, or an attempt
  269. may be made to access an array component by using an incorrect index value.
  270. To deal with such error situations, the statements of a program unit can be
  271. textually followed by exception handlers that specify the actions to be taken
  272. when the error situation arises.  Exceptions can be raised explicitly by a
  273. raise statement.
  274.  
  275. 30   Data Types
  276.  
  277. 31   Every object in the language has a type, which characterizes a set of
  278. values and a set of applicable operations.  The main classes of types are
  279. elementary types (comprising enumeration, numeric, and access types) and
  280. composite types (including array and record types).
  281.  
  282. 32   An enumeration type defines an ordered set of distinct enumeration
  283. literals, for example a list of states or an alphabet of characters.  The
  284. enumeration types Boolean, Character, and Wide_Character are predefined.
  285.  
  286. 33   Numeric types provide a means of performing exact or approximate
  287. numerical computations.  Exact computations use integer types, which denote
  288. sets of consecutive integers.  Approximate computations use either fixed
  289. point types, with absolute bounds on the error, or floating point types, with
  290. relative bounds on the error.  The numeric types Integer, Float, and Duration
  291. are predefined.
  292.  
  293. 34   Composite types allow definitions of structured objects with related
  294. components.  The composite types in the language include arrays and records.
  295. An array is an object with indexed components of the same type.  A record is
  296. an object with named components of possibly different types.  Task and
  297. protected types are also forms of composite types.  The array types String
  298. and Wide_String are predefined.
  299.  
  300. 35   Record, task, and protected types may have special components called
  301. discriminants which parameterize the type.  Variant record structures that
  302. depend on the values of discriminants can be defined within a record type.
  303.  
  304. 36   Access types allow the construction of linked data structures.  A value
  305. of an access type represents a reference to an object declared as aliased or
  306. to an object created by the evaluation of an allocator.  Several variables of
  307. an access type may designate the same object, and components of one object
  308. may designate the same or other objects.  Both the elements in such linked
  309. data structures and their relation to other elements can be altered during
  310. program execution.  Access types also permit references to subprograms to be
  311. stored, passed as parameters, and ultimately dereferenced as part of an
  312. indirect call.
  313.  
  314. 37   Private types permit restricted views of a type.  A private type can be
  315. defined in a package so that only the logically necessary properties are made
  316. visible to the users of the type.  The full structural details that are
  317. externally irrelevant are then only available within the package and any
  318. child units.
  319.  
  320. 38   From any type a new type may be defined by derivation.  A type, together
  321. with its derivatives (both direct and indirect) form a derivation class.
  322. Class-wide operations may be defined that accept as a parameter an operand of
  323. any type in a derivation class.  For record and private types, the
  324. derivatives may be extensions of the parent type.  Types that support these
  325. object-oriented capabilities of class-wide operations and type extension must
  326. be tagged, so that the specific type of an operand within a derivation class
  327. can be identified at run time.  When an operation of a tagged type is applied
  328. to an operand whose specific type is not known until run time, implicit
  329. dispatching is performed based on the tag of the operand.
  330.  
  331. 39   The concept of a type is further refined by the concept of a subtype,
  332. whereby a user can constrain the set of allowed values of a type.  Subtypes
  333. can be used to define subranges of scalar types, arrays with a limited set of
  334. index values, and records and private types with particular discriminant
  335. values.
  336.  
  337. 40   Other Facilities
  338.  
  339. 41   Representation clauses can be used to specify the mapping between types
  340. and features of an underlying machine.  For example, the user can specify
  341. that objects of a given type must be represented with a given number of bits,
  342. or that the components of a record are to be represented using a given
  343. storage layout.  Other features allow the controlled use of low level,
  344. nonportable, or implementation-dependent aspects, including the direct
  345. insertion of machine code.
  346.  
  347. 42   The predefined environment of the language provides for input-output and
  348. other capabilities (such as string manipulation and random number generation)
  349. by means of standard library packages.  Input-output is supported for values
  350. of user-defined as well as of predefined types.  Standard means of
  351. representing values in display form are also provided.  Other standard
  352. library packages are defined in annexes of the standard to support systems
  353. with specialized requirements.
  354.  
  355. 43   Finally, the language provides a powerful means of parameterization of
  356. program units, called generic program units.  The generic parameters can be
  357. types and subprograms (as well as objects and packages) and so allow general
  358. algorithms and data structures to be defined that are applicable to all types
  359. of a given class.
  360.  
  361.  
  362. Language Changes
  363.  
  364. 44   This International Standard replaces the first edition of 1987.  In this
  365. edition, the following major language changes have been incorporated:
  366.  
  367.    45  Support for standard 8-bit and 16-bit character sets.  See
  368.        Section 2, 3.5.2, 3.6.3, A.1, A.3, and A.4.
  369.  
  370.    46  Object-oriented programming with run-time polymorphism.  See the
  371.        discussions of classes, derived types, tagged types, record
  372.        extensions, and private extensions in clauses 3.4, 3.9, and 7.3.
  373.        See also the new forms of generic formal parameters that are
  374.        allowed by 12.5.1, ``Formal Private and Derived Types'' and 12.7,
  375.        ``Formal Packages''.
  376.  
  377.    47  Access types have been extended to allow an access value to
  378.        designate a subprogram or an object declared by an object
  379.        declaration (as opposed to just a heap-allocated object).  See
  380.        3.10.
  381.  
  382.    48  Efficient data-oriented synchronization is provided via protected
  383.        types.  See Section 9.
  384.  
  385.    49  The library units of a library may be organized into a hierarchy
  386.        of parent and child units.  See Section 10.
  387.  
  388.    50  Additional support has been added for interfacing to other
  389.        languages.  See Annex B.
  390.  
  391.    51  The Specialized Needs Annexes have been added to provide specific
  392.        support for certain application areas:
  393.  
  394.           52  Annex C, ``Systems Programming''
  395.  
  396.           53  Annex D, ``Real-Time Systems''
  397.  
  398.           54  Annex E, ``Distributed Systems''
  399.  
  400.           55  Annex F, ``Information Systems''
  401.  
  402.           56  Annex G, ``Numerics''
  403.  
  404.           57  Annex H, ``Safety and Security''
  405.  
  406. 58   For a more detailed list of changes, see the Changes to Ada -- 1987 to
  407. 1995 document.
  408. Instructions for Comment Submission
  409.  
  410. 59   {instructions for comment submission} {comments, instructions for
  411. submission} Informal comments on this International Standard may be sent via
  412. e-mail to ada-comment@sei.cmu.edu.  If appropriate, the Project Editor will
  413. initiate a Technical Corrigendum to be issued for the standard.
  414.  
  415. 60   Comments should use the following format:
  416.  
  417. 61
  418.          !topic Title summarizing comment
  419.          !reference RM95-ss.ss(pp)
  420.          !from Author Name yy-mm-dd
  421.          !keywords keywords related to topic
  422.          !discussion
  423.  
  424.          text of discussion
  425.  
  426.         61.a   Change:  Removed ";5.95" from the !reference line.
  427.  
  428. 62   where ss.ss is the section, clause or subclause number, pp is the
  429. paragraph number where applicable, and yy-mm-dd is the date the comment was
  430. sent.  The date is optional, as is the !keywords line.
  431.  
  432. 63   Multiple comments per e-mail message are acceptable.  Please use a
  433. descriptive ``Subject'' in your e-mail message.
  434.  
  435. 64   When correcting typographical errors or making minor wording
  436. suggestions, please put the correction directly as the topic of the comment;
  437. use square brackets [ ] to indicate text to be omitted and curly braces { }
  438. to indicate text to be added, and provide enough context to make the nature
  439. of the suggestion self-evident or put additional information in the body of
  440. the comment, for example:
  441.  
  442. 65
  443.          !topic [c]{C}haracter
  444.          !topic it[']s meaning is not defined
  445.  
  446. 66   Formal requests for interpretations and for reporting defects in this
  447. International Standard may be made in accordance with the ISO/IEC JTC1
  448. Directives and the ISO/IEC JTC1/SC22 policy for interpretations.  ISO Member
  449. Bodies may submit a Defect Report to ISO for resolution under the JTC1 and
  450. JTC1/SC22 procedures.  A response will be provided and, if appropriate, a
  451. Technical Corrigendum will be issued through JTC1.
  452. Acknowledgements
  453.  
  454. 67   This International Standard was prepared by the Ada 9X Mapping/Revision
  455. Team based at Intermetrics, Inc., which has included:  W. Carlson, Program
  456. Manager; T. Taft, Technical Director; J. Barnes (consultant); B. Brosgol
  457. (consultant); R. Duff (Oak Tree Software); M. Edwards; C. Garrity;
  458. R. Hilliard; O. Pazy (consultant); D. Rosenfeld; L. Shafer; W. White;
  459. M. Woodger.
  460.  
  461. 68   The following consultants to the Ada 9X Project contributed to the
  462. Specialized Needs Annexes:  T. Baker (Real-Time/Systems Programming -- SEI,
  463. FSU); K. Dritz (Numerics -- Argonne National Laboratory); A. Gargaro
  464. (Distributed Systems -- Computer Sciences); J. Goodenough (Real-Time/Systems
  465. Programming -- SEI); J. McHugh (Secure Systems -- consultant); B. Wichmann
  466. (Safety-Critical Systems -- NPL: UK).
  467.  
  468. 69   This work was regularly reviewed by the Ada 9X Distinguished Reviewers
  469. and the members of the Ada 9X Rapporteur Group (XRG):  E. Ploedereder,
  470. Chairman of DRs and XRG (University of Stuttgart: Germany); B. Bardin
  471. (Hughes); J. Barnes (consultant: UK); B. Brett (DEC); B. Brosgol
  472. (consultant); R. Brukardt (RR Software); N. Cohen (IBM); R. Dewar (NYU);
  473. G. Dismukes (TeleSoft); A. Evans (consultant); A. Gargaro (Computer
  474. Sciences); M. Gerhardt (ESL); J. Goodenough (SEI); S. Heilbrunner (University
  475. of Salzburg: Austria); P. Hilfinger (UC/Berkeley); B. Kaellberg (CelsiusTech:
  476. Sweden); M. Kamrad II (Unisys); J. van Katwijk (Delft University of
  477. Technology: The Netherlands); V. Kaufman (Russia); P. Kruchten (Rational);
  478. R. Landwehr (CCI: Germany); C. Lester (Portsmouth Polytechnic: UK);
  479. L. Mansson (TELIA Research: Sweden); S. Michell (Multiprocessor Toolsmiths:
  480. Canada); M. Mills (US Air Force); D. Pogge (US Navy); K. Power (Boeing);
  481. O. Roubine (Verdix: France); A. Strohmeier (Swiss Fed Inst of Technology:
  482. Switzerland); W. Taylor (consultant: UK); J. Tokar (Tartan); E. Vasilescu
  483. (Grumman); J. Vladik (Prospeks s.r.o.:  Czech Republic); S. Van Vlierberghe
  484. (OFFIS: Belgium).
  485.  
  486.         69.a   Change:  Various changes at the request of some people
  487.         mentioned above, and Chris Anderson.
  488.  
  489. 70   Other valuable feedback influencing the revision process was provided by
  490. the Ada 9X Language Precision Team (Odyssey Research Associates), the Ada 9X
  491. User/Implementer Teams (AETECH, Tartan, TeleSoft), the Ada 9X Implementation
  492. Analysis Team (New York University) and the Ada community-at-large.
  493.  
  494. 71   Special thanks go to R. Mathis, Convenor of ISO/IEC JTC1/SC22 Working
  495. Group 9.
  496.  
  497. 72   The Ada 9X Project was sponsored by the Ada Joint Program Office.
  498. Christine M. Anderson at the Air Force Phillips Laboratory (Kirtland AFB, NM)
  499. was the project manager.
  500. Changes Since Version 5.0
  501.  
  502. 73   Changes since version 5.0 of 3 June 1994 are marked with change bars.
  503. Thick change bars, like the one next to this paragraph, indicate changes that
  504. might affect an implementation.
  505.  
  506. 74   Thin change bars, like the one next to this paragraph, indicate changes,
  507. such as minor wording changes, that would be unlikely to affect an
  508. implementation.  Change bars are not included in the ASCII version.
  509.  
  510. 75   There are some formatting changes that are not marked.  In addition, we
  511. have made no attempt to mark changes in summary material, such as the Index
  512. or the Informative Annexes; the change bars found in those places are
  513. incomplete.
  514.  
  515. 76   The document submitted to ISO for publication as the International
  516. Standard is the same as this version, except:
  517.  
  518.    77  This list of ``Changes Since Version 5.0'' is not included in the
  519.        International Standard.
  520.  
  521.    78  The International Standard does not have change bars.
  522.  
  523.    79  The list of changes in the Index is not included in the
  524.        International Standard.
  525.  
  526.    80  The ``Acknowledgements'' page is not included in the
  527.        International Standard.
  528.  
  529.    81  The text in the running headers and footers on each page is
  530.        slightly different in the International Standard.
  531.  
  532.    82  The title page(s) are different in the International Standard.
  533.  
  534.    83  This document is formatted for 8.5-by-11-inch paper, whereas the
  535.        International Standard is formatted for A4 paper (210-by-297mm);
  536.        thus, the page breaks are in different places.
  537.  
  538. 84   Additional formatting changes may be required by ISO before final
  539. publication of the International Standard.
  540.  
  541. 85   These are the changes marked with thick change bars:
  542.  
  543.    86  An implementation of floating point may support infinities and
  544.        NaNs in Wide_Value, Value, and Get (see 3.5 and A.10.9).
  545.  
  546.    87  The Wide_Width attribute is added (see 3.5).
  547.  
  548.    88  An implementation requirement on System.Max_Binary_Modulus was
  549.        added, so at least 16-bit binary modular types have to be
  550.        supported (see 3.5.4).
  551.  
  552.    89  S'Base'Digits now yields the requested decimal precision of the
  553.        base subtype (see 3.5.7 and 3.5.8).
  554.  
  555.    90  An abstract subprogram (or primitive function with controlling
  556.        result) need not be overridden for a generic formal tagged
  557.        nonabstract type (see 3.9.3).
  558.  
  559.    91  A generic formal object of a tagged type is aliased (see 3.10 and
  560.        3.10.2).
  561.  
  562.    92  An incomplete type is now allowed in an access_to_subprogram_
  563.        definition (see 3.10.1).
  564.  
  565.    93  The accessibility rules have been rewritten.  The intended effect
  566.        has not changed, but the wording is quite different.  See 3.10.2.
  567.        See also 3.9.1, 4.6, 6.5, 7.6.1, and 9.5.4.  As part of this
  568.        change, the definition of the term ``master'' was slightly
  569.        changed (see 7.6.1, 9.3, 9.8, and 10.2).
  570.  
  571.    94  The rule about taking 'Access of a discriminant-dependent
  572.        component has been changed to match the corresponding rule for
  573.        renaming.  The rule about P'Access when P is within a generic has
  574.        been changed to refer to the generic body instead of the generic
  575.        unit.  See 3.10.2.
  576.  
  577.    95  The static expression rules were clarified, and a few bugs were
  578.        fixed (see 4.9).
  579.  
  580.    96  The rule about multiple access paths has been clarified (see
  581.        6.2).
  582.  
  583.    97  An inherited subprogram of a generic formal tagged type with
  584.        unknown discriminants is now defined to be intrinsic.  In
  585.        addition, operators defined in language-defined library units may
  586.        be intrinsic.  See 6.3.1.  Ada.Decimal.Divide is also intrinsic
  587.        (see F.2).
  588.  
  589.    98  The definition of subtype conformance no longer includes a
  590.        special case for convention Intrinsic.  Instead, the special case
  591.        has been moved to the relevant specific rules.  See 6.3.1.  See
  592.        also 3.9.2, 3.10.2, 8.5.4, 12.3, and 13.3.
  593.  
  594.    99  The definition of full conformance was corrected to include
  595.        character_literals.  The relationship with functional vs.
  596.        operator notation was clarified in the AARM.  See 6.3.1.
  597.  
  598.   100  The rule about when copy-in is required for composite out
  599.        parameters passed by copy was corrected (see 6.4.1).
  600.  
  601.   101  The rule about when a full view has to be limited was clarified.
  602.        Some bugs were fixed in the rules about correspondence of
  603.        discriminants between partial and full views.  See 7.3.
  604.  
  605.   102  Ada.Finalization is now preelaborated (see 7.6).
  606.  
  607.   103  The Implementation Permission to omit code for (e.g.) ``X := X;''
  608.        was clarified (see 7.6).
  609.  
  610.   104  Things like ``X: T'Class renames Y;'', where Y is of type T, are
  611.        now illegal (see 8.5.1).  An analogous change was made to generic
  612.        formal objects of mode in out (see 12.4).
  613.  
  614.   105  The visible part of a task or protected unit includes the
  615.        discriminant part, if any (see 9.1 and 9.4).
  616.  
  617.   106  The definition of when a task doing an entry call is ``blocked''
  618.        has been clarified (see 9.5.3).
  619.  
  620.   107  A library unit subprogram renaming declaration is always a
  621.        renaming-as-declaration, never a renaming-as-body (see 10.1.1).
  622.  
  623.   108  The rules about children of generic packages were changed.  See
  624.        10.1.1.  See also 8.3, 10.1.2, 10.1.6, and 12.2.
  625.  
  626.   109  An AARM annotation was added clarifying the intent that it is
  627.        illegal for a library subprogram_body with no corresponding
  628.        subprogram_declaration to mention one of its siblings in a with_
  629.        clause if the sibling is a private library unit (see 10.1.2).
  630.  
  631.   110  Library unit names must be unique (see 10.1.4).
  632.  
  633.   111  Exception_Name(Constraint_Error'Identity) returns "Constraint_
  634.        Error".  Information is not duplicated among Exception_Name,
  635.        Exception_Message, and Exception_Information.  See 11.4.1.
  636.  
  637.   112  Legality Rules are re-checked in the formal part of an instance
  638.        (see 12.3).
  639.  
  640.   113  The rules for discriminant matching in formal private and derived
  641.        types were corrected (see 12.5.1).
  642.  
  643.   114  Changes were made to the semantics of the Size attribute and
  644.        clause, and some advice that appeared only in Implementation
  645.        Notes in the AARM was moved to Implementation Advice in the RM95
  646.        (see 13.3).
  647.  
  648.   115  An implementation is allowed (but not required) to declare
  649.        packages System and System.Storage_Elements pure (see 13.7 and
  650.        13.7.1).
  651.  
  652.   116  Address_To_Access_Conversions is now a library package instead of
  653.        a nested package, and is preelaborated (see 13.7.2).
  654.  
  655.   117  Unchecked_Conversion is declared pure (see 13.9).
  656.  
  657.   118  The rules for dereferencing access values designating nonexistent
  658.        objects were corrected (see 13.9.1 and 13.11.2).
  659.  
  660.   119  Unchecked_Deallocation is preelaborated (see 13.11.2).
  661.  
  662.   120  The external representation used by 'Write and 'Read has been
  663.        decoupled from the internal representation implied by
  664.        representation items, and the legality rules for representation
  665.        clauses for the stream-related have changed (see 13.13.2 and
  666.        13.3).
  667.  
  668.   121  Added an AARM annotation clarifying that an implementation may,
  669.        for example, define the Small of type Duration (see A.1).
  670.  
  671.   122  The package Ada.Characters.Handling is specified with pragma
  672.        Preelaborate, rather than with pragma Pure (see A.3.2).
  673.  
  674.   123  Wording of the Wide_Character test functions has been revised to
  675.        avoid overspecification of the relationship between Character and
  676.        Wide_Character ranges (see A.3.2).
  677.  
  678.   124  Names for the control character positions in Characters.Latin_1
  679.        have been corrected (see A.3.3).
  680.  
  681.   125  The package Strings.Unbounded is specified with pragma
  682.        Preelaborate (see A.4.5).
  683.  
  684.   126  The package Strings.Maps.Constants is now a child of
  685.        Strings.Maps, and analogously Strings.Wide_Maps.Wide_Constants is
  686.        now a child of Strings.Wide_Maps; the types of the parameters and
  687.        results for several of the Wide_String handling functions have
  688.        been corrected (see A.4.6 and A.4.7).
  689.  
  690.   127  The Set_Input, Set_Output, and Set_Error procedures that take a
  691.        parameter of type File_Access have been removed from Text_IO (see
  692.        A.10.1).
  693.  
  694.   128  Input-output for numeric types has been revised with respect to
  695.        the treatment of signs for input with modular types, the
  696.        treatment of signed zeros and other special values for floating
  697.        point input-output, and rounding and accuracy requirements for
  698.        real output (see A.10.8 and A.10.9).
  699.  
  700.   129  The effect of enumeration output for a character type has been
  701.        clarified (see A.10.10).
  702.  
  703.   130  Preinstantiations of the numeric IO packages are provided for the
  704.        predefined numeric types (see A.10.8, A.10.9, and A.11).
  705.  
  706.   131  Added the package Wide_Text_IO.Text_Streams (see A.12.3).
  707.  
  708.   132  Renamed items in package Command_Line (see A.15).
  709.  
  710.   133  An AARM-only annotation has been added advising the
  711.        implementation on the names to choose for IEEE floating point
  712.        types (see B.2).
  713.  
  714.   134  The packages Interfaces.C, Interfaces.C.Strings, and
  715.        Interfaces.C.Pointers include several small enhancements (see
  716.        B.3, B.3.1, and B.3.2).
  717.  
  718.   135  Corrected a parameter type in Decimal_Conversions (see B.4).
  719.  
  720.   136  The semantics of pragma Discard_Names has been corrected (see
  721.        C.5).
  722.  
  723.   137  Implementation permissions related to blocking have been added to
  724.        D.2.1 and D.2.2.
  725.  
  726.   138  The restrictions on remote types library units now apply only to
  727.        the declaration and not to the body.  Remote access types may now
  728.        be declared in remote types packages.  See Annex E.
  729.  
  730.   139  The implementation model in the AARM for remote procedure calls
  731.        has been clarified (see E.4).
  732.  
  733.   140  Added a partition id parameter to Establish_RPC_Receiver (see
  734.        E.5).
  735.  
  736.   141  Added an AARM note on the intent of the support for decimal
  737.        Machine_Radix (see F.1).
  738.  
  739.   142  Removed incorrect restriction on the form of a picture string
  740.        (see F.3.1).
  741.  
  742.   143  Removed obsolete declaration from Text_IO.Editing (see F.3.3).
  743.  
  744.   144  Revised the description of the model-oriented attributes for
  745.        floating point types (see G.2.2).
  746.  
  747.   145  Revised the treatment of conversion of fixed point multiplication
  748.        and division to an integer result (see G.2.3).
  749.  
  750.   146  Corrected some bugs in the rules of J.3, ``Reduced Accuracy
  751.        Subtypes''.
  752.  
  753.  
  754.  
  755.     ----------------------
  756.     INTERNATIONAL STANDARD
  757.     ----------------------
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769. Information technology -- Programming
  770. Languages -- Ada --
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.                              Section 1: General
  780.  
  781.  
  782. 1   Ada is a programming language designed to support the construction of
  783. long-lived, highly reliable software systems.  The language includes
  784. facilities to define packages of related types, objects, and operations.  The
  785. packages may be parameterized and the types may be extended to support the
  786. construction of libraries of reusable, adaptable software components.  The
  787. operations may be implemented as subprograms using conventional sequential
  788. control structures, or as entries that include synchronization of concurrent
  789. threads of control as part of their invocation.  The language treats
  790. modularity in the physical sense as well, with a facility to support separate
  791. compilation.
  792.  
  793. 2   The language includes a complete facility for the support of real-time,
  794. concurrent programming.  Errors can be signaled as exceptions and handled
  795. explicitly.  The language also covers systems programming; this requires
  796. precise control over the representation of data and access to
  797. system-dependent properties.  Finally, a predefined environment of standard
  798. packages is provided, including facilities for, among others, input-output,
  799. string manipulation, numeric elementary functions, and random number
  800. generation.
  801.  
  802.         2.a   Discussion:  This Annotated Ada Reference Manual (AARM)
  803.         contains the entire text of the Ada Reference Manual (RM9X), plus
  804.         certain annotations.  The annotations give a more in-depth analysis
  805.         of the language.  They describe the reason for each non-obvious rule,
  806.         and point out interesting ramifications of the rules and interactions
  807.         among the rules (interesting to language lawyers, that is).
  808.         Differences between Ada 83 and Ada 9X are listed.  (The text you are
  809.         reading now is an annotation.)
  810.  
  811.         2.b   The AARM stresses detailed correctness and uniformity over
  812.         readability and understandability.  We're not trying to make the
  813.         language ``appear'' simple here; on the contrary, we're trying to
  814.         expose hidden complexities, so we can more easily detect language
  815.         bugs.  The RM9X, on the other hand, is intended to be a more readable
  816.         document for programmers.
  817.  
  818.         2.c   The annotations in the AARM are as follows:
  819.  
  820.           2.d  Text that is logically redundant is shown [in square
  821.                brackets, like this].  Technically, such text could be
  822.                written as a Note in the RM9X, since it is really a
  823.                theorem that can be proven from the non-redundant rules
  824.                of the language.  We use the square brackets instead when
  825.                it seems to make the RM9X more readable.
  826.  
  827.           2.e  The rules of the language (and some AARM-only text) are
  828.                categorized, and placed under certain sub-headings that
  829.                indicate the category.  For example, the distinction
  830.                between Name Resolution Rules and Legality Rules is
  831.                particularly important, as explained in 8.6.
  832.  
  833.           2.f  Text under the following sub-headings appears in both
  834.                documents:
  835.  
  836.                  2.g  The unlabeled text at the beginning of each clause
  837.                       or subclause,
  838.                  2.h  Syntax,
  839.                  2.i  Name Resolution Rules,
  840.                  2.j  Legality Rules,
  841.                  2.k  Static Semantics,
  842.                  2.l  Post-Compilation Rules,
  843.                  2.m  Dynamic Semantics,
  844.                  2.n  Bounded (Run-Time) Errors,
  845.                  2.o  Erroneous Execution,
  846.                  2.p  Implementation Requirements,
  847.                  2.q  Documentation Requirements,
  848.                  2.r  Metrics,
  849.                  2.s  Implementation Permissions,
  850.                  2.t  Implementation Advice,
  851.                  2.u  NOTES,
  852.                  2.v  Examples.
  853.  
  854.           2.w  Text under the following sub-headings does not appear in
  855.                the RM9X:
  856.  
  857.                  2.x  Language Design Principles,
  858.                  2.y  Inconsistencies With Ada 83,
  859.                  2.z  Incompatibilities With Ada 83,
  860.                 2.aa  Extensions to Ada 83,
  861.                 2.bb  Wording Changes From Ada 83.
  862.  
  863.          2.cc  The AARM also includes the following kinds of
  864.                annotations.  These do not necessarily annotate the
  865.                immediately preceding rule, although they often do.
  866.  
  867.         2.dd   Reason:  An explanation of why a certain rule is necessary, or
  868.         why it is worded in a certain way.
  869.  
  870.         2.ee   Ramification:  An obscure ramification of the rules that is of
  871.         interest only to language lawyers.  (If a ramification of the rules
  872.         is of interest to programmers, then it appears under NOTES.)
  873.  
  874.         2.ff   Proof:  An informal proof explaining how a given Note or
  875.         [marked-as-redundant] piece of text follows from the other rules of
  876.         the language.
  877.  
  878.         2.gg   Implementation Note:  A hint about how to implement a feature,
  879.         or a particular potential pitfall that an implementer needs to be
  880.         aware of.
  881.  
  882.         2.hh   Change:  Changes to the Ada Reference Manual are annotated
  883.         with one of these when more explanation is needed than the comment
  884.         that triggered the change.  Changes are also marked with the database
  885.         number of the comment that triggered the change, like this:
  886.         {95-9999.a} , unless the change is a spelling or grammar correction,
  887.         a correction of Ada syntax in an example, a font change, a change to
  888.         the index or other summary material, or a change that appears only in
  889.         the AARM.  Changes are also marked with change bars, even if there is
  890.         no corresponding comment in the database.  However, changes to the
  891.         index or other summary material are not always marked with change
  892.         bars.
  893.  
  894.         2.ii   Discussion:  Other annotations not covered by the above.
  895.  
  896.         2.jj   To be honest:  A rule that is considered logically necessary
  897.         to the definition of the language, but which is so obscure or
  898.         pedantic that only a language lawyer would care.  These are the only
  899.         annotations that could be considered part of the language definition.
  900.  
  901.         2.kk   Glossary entry:  The text of a Glossary entry -- this text
  902.         will also appear in Annex N, ``Glossary''.
  903.  
  904.         2.ll   Discussion:  In general, RM9X text appears in the normal font,
  905.         whereas AARM-only text appears in a smaller font.  Notes also appear
  906.         in the smaller font, as recommended by ISO/IEC style guidelines.  Ada
  907.         examples are also usually printed in a smaller font.
  908.  
  909.         2.mm   If you have trouble finding things, be sure to use the index.
  910.         {italics, like this} Each defined term appears there, and also in
  911.         italics, like this.  Syntactic categories defined in BNF are also
  912.         indexed.
  913.  
  914.         2.nn   A definition marked ``[distributed]'' is the main definition
  915.         for a term whose complete definition is given in pieces distributed
  916.         throughout the document.  The pieces are marked ``[partial]'' or with
  917.         a phrase explaining what cases the partial definition applies to.
  918.  
  919.  
  920.  
  921. 1.1 Scope
  922.  
  923. 1   This International Standard specifies the form and meaning of programs
  924. written in Ada.  Its purpose is to promote the portability of Ada programs to
  925. a variety of data processing systems.
  926.  
  927.  
  928.  
  929. 1.1.1 Extent
  930.  
  931. 1   This International Standard specifies:
  932.  
  933.     2  The form of a program written in Ada;
  934.  
  935.     3  The effect of translating and executing such a program;
  936.  
  937.     4  The manner in which program units may be combined to form Ada
  938.        programs;
  939.  
  940.     5  The language-defined library units that a conforming implemen-
  941.        tation is required to supply;
  942.  
  943.     6  The permissible variations within the standard, and the manner in
  944.        which they are to be documented;
  945.  
  946.     7  Those violations of the standard that a conforming implementation
  947.        is required to detect, and the effect of attempting to translate
  948.        or execute a program containing such violations;
  949.  
  950.     8  Those violations of the standard that a conforming implementation
  951.        is not required to detect.
  952.  
  953. 9   This International Standard does not specify:
  954.  
  955.    10  The means whereby a program written in Ada is transformed into
  956.        object code executable by a processor;
  957.  
  958.    11  The means whereby translation or execution of programs is invoked
  959.        and the executing units are controlled;
  960.  
  961.    12  The size or speed of the object code, or the relative execution
  962.        speed of different language constructs;
  963.  
  964.    13  The form or contents of any listings produced by implementations;
  965.        in particular, the form or contents of error or warning messages;
  966.  
  967.    14  The effect of unspecified execution.
  968.  
  969.    15  The size of a program or program unit that will exceed the
  970.        capacity of a particular conforming implementation.
  971.  
  972.  
  973.  
  974. 1.1.2 Structure
  975.  
  976. 1   This International Standard contains thirteen sections, fourteen annexes,
  977. and an index.
  978.  
  979. 2   {core language} The core of the Ada language consists of:
  980.  
  981.     3  Sections 1 through 13
  982.  
  983.     4  Annex A, ``Predefined Language Environment''
  984.  
  985.     5  Annex B, ``Interface to Other Languages''
  986.  
  987.     6  Annex J, ``Obsolescent Features''
  988.  
  989. 7   {Specialized Needs Annexes} {Annex (Specialized Needs)} {application
  990. areas} The following Specialized Needs Annexes define features that are
  991. needed by certain application areas:
  992.  
  993.     8  Annex C, ``Systems Programming''
  994.  
  995.     9  Annex D, ``Real-Time Systems''
  996.  
  997.    10  Annex E, ``Distributed Systems''
  998.  
  999.    11  Annex F, ``Information Systems''
  1000.  
  1001.    12  Annex G, ``Numerics''
  1002.  
  1003.    13  Annex H, ``Safety and Security''
  1004.  
  1005. 14   {normative} {Annex (normative)} The core language and the Specialized
  1006. Needs Annexes are normative, except that the material in each of the items
  1007. listed below is informative:
  1008.  
  1009.    15  Text under a NOTES or Examples heading.
  1010.  
  1011.    16  Each clause or subclause whose title starts with the word
  1012.        ``Example'' or ``Examples''.
  1013.  
  1014. 17   All implementations shall conform to the core language.  In addition, an
  1015. implementation may conform separately to one or more Specialized Needs
  1016. Annexes.
  1017.  
  1018. 18   {informative} {non-normative: see informative} {Annex (informative)} The
  1019. following Annexes are informative:
  1020.  
  1021.    19  Annex K, ``Language-Defined Attributes''
  1022.  
  1023.    20  Annex L, ``Language-Defined Pragmas''
  1024.  
  1025.    21  Annex M, ``Implementation-Defined Characteristics''
  1026.  
  1027.    22  Annex N, ``Glossary''
  1028.  
  1029.    23  Annex P, ``Syntax Summary''
  1030.  
  1031.         23.a   Discussion:  The idea of the Specialized Needs Annexes is that
  1032.         implementations can choose to target certain application areas.  For
  1033.         example, an implementation specifically targeted to embedded machines
  1034.         might support the application-specific features for Real-time
  1035.         Systems, but not the application-specific features for Information
  1036.         Systems.
  1037.  
  1038.         23.b   The Specialized Needs Annexes extend the core language only in
  1039.         ways that users, implementations, and standards bodies are allowed to
  1040.         extend the language; for example, via additional library units,
  1041.         attributes, representation items (see 13.1), pragmas, and constraints
  1042.         on semantic details that are left unspecified by the core language.
  1043.         Many implementations already provide much of the functionality
  1044.         defined by Specialized Needs Annexes; our goal is to increase
  1045.         uniformity among implementations by defining standard ways of
  1046.         providing the functionality.
  1047.  
  1048.         23.c   We recommend that the validation procedures allow implemen-
  1049.         tations to validate the core language, plus any set of the
  1050.         Specialized Needs Annexes.  We recommend that implementations not be
  1051.         allowed to validate a portion of one of the Specialized Needs
  1052.         Annexes, although implementations can, of course, provide unvalidated
  1053.         support for such portions.  We have designed the Specialized Needs
  1054.         Annexes assuming that this recommendation is followed.  Thus, our
  1055.         decisions about what to include and what not to include in those
  1056.         annexes are based on the assumption that each annex is validated in
  1057.         an ``all-or-nothing'' manner.
  1058.  
  1059.         23.d   An implementation may, of course, support extensions that are
  1060.         different from (but possibly related to) those defined by one of the
  1061.         Specialized Needs Annexes.  We recommend that, where appropriate,
  1062.         implementations do this by adding library units that are children of
  1063.         existing language-defined library packages.
  1064.  
  1065.         23.e   An implementation should not provide extensions that conflict
  1066.         with those defined in the Specialized Needs Annexes, in the following
  1067.         sense:  Suppose an implementation supports a certain error-free
  1068.         program that uses only functionality defined in the core and in the
  1069.         Specialized Needs Annexes.  The implementation should ensure that
  1070.         that program will still be error free in some possible full
  1071.         implementation of all of the Specialized Needs Annexes, and that the
  1072.         semantics of the program will not change.  For example, an
  1073.         implementation should not provide a package with the same name as one
  1074.         defined in one of the Specialized Needs Annexes, but that behaves
  1075.         differently, even if that implementation does not claim conformance
  1076.         to that Annex.
  1077.  
  1078.         23.f   Note that the Specialized Needs Annexes do not conflict with
  1079.         each other; it is the intent that a single implementation can conform
  1080.         to all of them.
  1081.  
  1082. 24   Each section is divided into clauses and subclauses that have a common
  1083. structure.  Each section, clause, and subclause first introduces its subject.
  1084. After the introductory text, text is labeled with the following headings:
  1085.  
  1086.  
  1087.                          Language Design Principles
  1088.  
  1089.         24.a   These are not rules of the language, but guiding principles or
  1090.         goals used in defining the rules of the language.  In some cases, the
  1091.         goal is only partially met; such cases are explained.
  1092.  
  1093.         24.b   This is not part of the definition of the language, and does
  1094.         not appear in the RM9X.
  1095.                                    Syntax
  1096.  
  1097.     25   {syntax (under Syntax heading)} {grammar (under Syntax heading)}
  1098.     {context free grammar (under Syntax heading)} {BNF (Backus-Naur Form)
  1099.     (under Syntax heading)} {Backus-Naur Form (BNF) (under Syntax heading)}
  1100.     Syntax rules (indented).
  1101.  
  1102.  
  1103.                             Name Resolution Rules
  1104.  
  1105. 26   {name resolution rules} {overloading rules} {resolution rules}
  1106. Compile-time rules that are used in name resolution, including overload
  1107. resolution.
  1108.  
  1109.         26.a   Discussion:  These rules are observed at compile time.  (We
  1110.         say ``observed'' rather than ``checked,'' because these rules are not
  1111.         individually checked.  They are really just part of the Legality
  1112.         Rules in Section 8 that require exactly one interpretation of each
  1113.         constituent of a complete context.)  The only rules used in overload
  1114.         resolution are the Syntax Rules and the Name Resolution Rules.
  1115.  
  1116.         26.b   When dealing with non-overloadable declarations it sometimes
  1117.         makes no semantic difference whether a given rule is a Name
  1118.         Resolution Rule or a Legality Rule, and it is sometimes difficult to
  1119.         decide which it should be.  We generally make a given rule a Name
  1120.         Resolution Rule only if it has to be.  For example, ``The name, if
  1121.         any, in a raise_statement shall be the name of an exception.''  is
  1122.         under ``Legality Rules.''
  1123.  
  1124.  
  1125.                                Legality Rules
  1126.  
  1127. 27   {legality rules} {compile-time error} {error (compile-time)} Rules that
  1128. are enforced at compile time.  {legal (construct)} {illegal (construct)} A
  1129. construct is legal if it obeys all of the Legality Rules.
  1130.  
  1131.         27.a   Discussion:  These rules are not used in overload resolution.
  1132.  
  1133.         27.b   Note that run-time errors are always attached to exceptions;
  1134.         for example, it is not ``illegal'' to divide by zero, it just raises
  1135.         an exception.
  1136.  
  1137.  
  1138.                               Static Semantics
  1139.  
  1140. 28   {static semantics} {compile-time semantics} A definition of the
  1141. compile-time effect of each construct.
  1142.  
  1143.         28.a   Discussion:  The most important compile-time effects represent
  1144.         the effects on the symbol table associated with declarations
  1145.         (implicit or explicit).  In addition, we use this heading as a bit of
  1146.         a grab bag for equivalences, package specifications, etc.  For
  1147.         example, this is where we put statements like so-and-so is equivalent
  1148.         to such-and-such.  (We ought to try to really mean it when we say
  1149.         such things!)  Similarly, statements about magically-generated
  1150.         implicit declarations go here.  These rules are generally written as
  1151.         statements of fact about the semantics, rather than as a
  1152.         you-shall-do-such-and-such sort of thing.
  1153.  
  1154.  
  1155.                            Post-Compilation Rules
  1156.  
  1157. 29   {post-compilation rules} {post-compilation error} {post-compilation
  1158. rules} {link-time error: see post-compilation error} {error (link-time)}
  1159. Rules that are enforced before running a partition.  {legal (partition)}
  1160. {illegal (partition)} A partition is legal if its compilation units are legal
  1161. and it obeys all of the Post-Compilation Rules.
  1162.  
  1163.         29.a   Discussion:  It is not specified exactly when these rules are
  1164.         checked, so long as they are checked for any given partition before
  1165.         that partition starts running.  An implementation may choose to check
  1166.         some such rules at compile time, and reject compilation_units
  1167.         accordingly.  Alternatively, an implementation may check such rules
  1168.         when the partition is created (usually known as ``link time''), or
  1169.         when the partition is mapped to a particular piece of hardware (but
  1170.         before the partition starts running).
  1171.  
  1172.  
  1173.                               Dynamic Semantics
  1174.  
  1175. 30   {dynamic semantics} {run-time semantics} {run-time error} {error
  1176. (run-time)} A definition of the run-time effect of each construct.
  1177.  
  1178.         30.a   Discussion:  This heading describes what happens at run time.
  1179.         Run-time checks, which raise exceptions upon failure, are described
  1180.         here.  Each item that involves a run-time check is marked with the
  1181.         name of the check -- these are the same check names that are used in
  1182.         a pragma Suppress.  Principle: Every check should have a name, usable
  1183.         in a pragma Suppress.
  1184.  
  1185.  
  1186.                           Bounded (Run-Time) Errors
  1187.  
  1188. 31   {bounded error} {bounded error} Situations that result in bounded
  1189. (run-time) errors (see 1.1.5).
  1190.  
  1191.         31.a   Discussion:  The ``bounds'' of each such error are described
  1192.         here -- that is, we characterize the set of all possible behaviors
  1193.         that can result from a bounded error occurring at run time.
  1194.  
  1195.  
  1196.                              Erroneous Execution
  1197.  
  1198. 32   {erroneous execution} {erroneous execution} Situations that result in
  1199. erroneous execution (see 1.1.5).
  1200.  
  1201.  
  1202.                          Implementation Requirements
  1203.  
  1204. 33   {implementation requirements} Additional requirements for conforming
  1205. implementations.
  1206.  
  1207.         33.a   Discussion:  ...as opposed to rules imposed on the programmer.
  1208.         An example might be, ``The smallest representable duration,
  1209.         Duration'Small, shall not be greater than twenty milliseconds.''
  1210.  
  1211.         33.b   It's really just an issue of how the rule is worded.  We could
  1212.         write the same rule as ``The smallest representable duration is an
  1213.         implementation-defined value less than or equal to 20 milliseconds''
  1214.         and then it would be under ``Static Semantics.''
  1215.  
  1216.  
  1217.                          Documentation Requirements
  1218.  
  1219. 34   {documentation requirements} {documentation requirements} Documentation
  1220. requirements for conforming implementations.
  1221.  
  1222.         34.a   Discussion:  These requirements are beyond those that are
  1223.         implicitly specified by the phrase ``implementation defined''.  The
  1224.         latter require documentation as well, but we don't repeat these cases
  1225.         under this heading.  Usually this heading is used for when the
  1226.         description of the documentation requirement is longer and does not
  1227.         correspond directly to one, narrow normative sentence.
  1228.  
  1229.  
  1230.                                    Metrics
  1231.  
  1232. 35   {metrics} {metrics} Metrics that are specified for the time/space
  1233. properties of the execution of certain language constructs.
  1234.  
  1235.  
  1236.                          Implementation Permissions
  1237.  
  1238. 36   {implementation permissions} Additional permissions given to the
  1239. implementer.
  1240.  
  1241.         36.a   Discussion:  For example, ``The implementation is allowed to
  1242.         impose further restrictions on the record aggregates allowed in code
  1243.         statements.''  When there are restrictions on the permission, those
  1244.         restrictions are given here also.  For example, ``An implementation
  1245.         is allowed to restrict the kinds of subprograms that are allowed to
  1246.         be main subprograms.  However, it shall support at least
  1247.         parameterless procedures.''  -- we don't split this up between here
  1248.         and ``Implementation Requirements.''
  1249.  
  1250.  
  1251.                             Implementation Advice
  1252.  
  1253. 37   {implementation advice} {advice} Optional advice given to the
  1254. implementer.  The word ``should'' is used to indicate that the advice is a
  1255. recommendation, not a requirement.  It is implementation defined whether or
  1256. not a given recommendation is obeyed.
  1257.  
  1258.         37.a   Implementation defined:  Whether or not each recommendation
  1259.         given in Implementation Advice is followed.
  1260.  
  1261.         37.b   Discussion:  The advice generally shows the intended
  1262.         implementation, but the implementer is free to ignore it.  The
  1263.         implementer is the sole arbiter of whether or not the advice has been
  1264.         obeyed, if not, whether the reason is a good one, and whether the
  1265.         required documentation is sufficient.  {ACVC [Ada Compiler Validation
  1266.         Capability]} {Ada Compiler Validation Capability [ACVC]} It would be
  1267.         wrong for the ACVC to enforce any of this advice.
  1268.  
  1269.         37.c   For example, ``Whenever possible, the implementation should
  1270.         choose a value no greater than fifty microseconds for the smallest
  1271.         representable duration, Duration'Small.''
  1272.  
  1273.         37.d   We use this heading, for example, when the rule is so low
  1274.         level or implementation-oriented as to be untestable.  We also use
  1275.         this heading when we wish to encourage implementations to behave in a
  1276.         certain way in most cases, but we do not wish to burden
  1277.         implementations by requiring the behavior.
  1278.  
  1279.  
  1280.      NOTES
  1281. 38   (1) {notes} Notes emphasize consequences of the rules described in the
  1282.      (sub)clause or elsewhere.  This material is informative.
  1283.  
  1284.  
  1285.                                   Examples
  1286.  
  1287. 39   Examples illustrate the possible forms of the constructs described.
  1288. This material is informative.
  1289.  
  1290.         39.a   Discussion:
  1291.  
  1292.  
  1293.         The next three headings list all language changes between Ada 83 and
  1294.         Ada 9X.  Language changes are any change that changes the set of text
  1295.         strings that are legal Ada programs, or changes the meaning of any
  1296.         legal program.  Wording changes, such as changes in terminology, are
  1297.         not language changes.  Each language change falls into one of the
  1298.         following three categories:
  1299.  
  1300.  
  1301.                          Inconsistencies With Ada 83
  1302.  
  1303.         39.b   {inconsistencies with Ada 83} {inconsistencies with Ada 83}
  1304.         This heading lists all of the upward inconsistencies between Ada 83
  1305.         and Ada 9X.  Upward inconsistencies are situations in which a legal
  1306.         Ada 83 program is a legal Ada 9X program with different semantics.
  1307.         This type of upward incompatibility is the worst type for users, so
  1308.         we only tolerate it in rare situations.
  1309.  
  1310.         39.c   (Note that the semantics of a program is not the same thing as
  1311.         the behavior of the program.  Because of Ada's indeterminacy, the
  1312.         ``semantics'' of a given feature describes a set of behaviors that
  1313.         can be exhibited by that feature.  The set can contain more than one
  1314.         allowed behavior.  Thus, when we ask whether the semantics changes,
  1315.         we are asking whether the set of behaviors changes.)
  1316.  
  1317.         39.d   This is not part of the definition of the language, and does
  1318.         not appear in the RM9X.
  1319.  
  1320.                         Incompatibilities With Ada 83
  1321.  
  1322.         39.e   {incompatibilities with Ada 83} {incompatibilities with Ada
  1323.         83} This heading lists all of the upward incompatibilities between
  1324.         Ada 83 and Ada 9X, except for the ones listed under ``Inconsistencies
  1325.         With Ada 83'' above.  These are the situations in which a legal Ada
  1326.         83 program is illegal in Ada 9X.  We do not generally consider a
  1327.         change that turns erroneous execution into an exception, or into an
  1328.         illegality, to be upwardly incompatible.
  1329.  
  1330.         39.f   This is not part of the definition of the language, and does
  1331.         not appear in the RM9X.
  1332.  
  1333.                             Extensions to Ada 83
  1334.  
  1335.         39.g   {extensions to Ada 83} {extensions to Ada 83} This heading is
  1336.         used to list all upward compatible language changes; that is,
  1337.         language extensions.  These are the situations in which a legal Ada
  1338.         9X program is not a legal Ada 83 program.  The vast majority of
  1339.         language changes fall into this category.
  1340.  
  1341.         39.h   This is not part of the definition of the language, and does
  1342.         not appear in the RM9X.
  1343.  
  1344.  
  1345.  
  1346.         39.i   As explained above, the next heading does not represent any
  1347.         language change:
  1348.  
  1349.                          Wording Changes From Ada 83
  1350.  
  1351.         39.j   {wording changes from Ada 83} This heading lists some of the
  1352.         non-semantic changes between RM83 and the RM9X.  It is incomplete; we
  1353.         have not attempted to list all wording changes, but only the
  1354.         ``interesting'' ones.
  1355.  
  1356.         39.k   This is not part of the definition of the language, and does
  1357.         not appear in the RM9X.
  1358.  
  1359.  
  1360.  
  1361. 1.1.3 Conformity of an Implementation with the Standard
  1362.  
  1363.                          Implementation Requirements
  1364.  
  1365. 1   {conformance (of an implementation with the Standard)} A conforming
  1366. implementation shall:
  1367.  
  1368.         1.a   Discussion:  {implementation} The implementation is the
  1369.         software and hardware that implements the language.  This includes
  1370.         compiler, linker, operating system, hardware, etc.
  1371.  
  1372.         1.b   We first define what it means to ``conform'' in general --
  1373.         basically, the implementation has to properly implement the normative
  1374.         rules given throughout the standard.  Then we define what it means to
  1375.         conform to a Specialized Needs Annex -- the implementation must
  1376.         support the core features plus the features of that Annex.  Finally,
  1377.         we define what it means to ``conform to the Standard'' -- this
  1378.         requires support for the core language, and allows partial (but not
  1379.         conflicting) support for the Specialized Needs Annexes.
  1380.  
  1381.     2  Translate and correctly execute legal programs written in Ada,
  1382.        provided that they are not so large as to exceed the capacity of
  1383.        the implementation;
  1384.  
  1385.     3  Identify all programs or program units that are so large as to
  1386.        exceed the capacity of the implementation (or raise an
  1387.        appropriate exception at run time);
  1388.  
  1389.  3.a    Implementation defined:  Capacity limitations of the
  1390.         implementation.
  1391.  
  1392.     4  Identify all programs or program units that contain errors whose
  1393.        detection is required by this International Standard;
  1394.  
  1395.  4.a    Discussion:  Note that we no longer use the term ``rejection''
  1396.         of programs or program units.  We require that programs or
  1397.         program units with errors or that exceed some capacity limit be
  1398.         ``identified.''  The way in which errors or capacity problems
  1399.         are reported is not specified.
  1400.  
  1401.  4.b    An implementation is allowed to use standard error-recovery
  1402.         techniques.  We do not disallow such techniques from being used
  1403.         across compilation_unit or compilation boundaries.
  1404.  
  1405.  4.c    See also the Implementation Requirements of 10.2, which disallow
  1406.         the execution of illegal partitions.  {94-4712.a}
  1407.  
  1408.     5  Supply all language-defined library units required by this
  1409.        International Standard;
  1410.  
  1411.  5.a    Implementation Note:  An implementation cannot add to or modify
  1412.         the visible part of a language-defined library unit, except
  1413.         where such permission is explicitly granted, unless such
  1414.         modifications are semantically neutral with respect to the
  1415.         client compilation units of the library unit.  An implementation
  1416.         defines the contents of the private part and body of
  1417.         language-defined library units.
  1418.  
  1419.  5.b    An implementation can add with_clauses and use_clauses, since
  1420.         these modifications are semantically neutral to clients.  (The
  1421.         implementation might need with_clauses in order to implement the
  1422.         private part, for example.)  Similarly, an implementation can
  1423.         add a private part even in cases where a private part is not
  1424.         shown in the standard.  Explicit declarations can be provided
  1425.         implicitly or by renaming, provided the changes are semantically
  1426.         neutral.
  1427.  
  1428.  5.c    {italics (implementation-defined)} Wherever in the standard the
  1429.         text of a language-defined library unit contains an italicized
  1430.         phrase starting with ``implementation-defined'', the
  1431.         implementation's version will replace that phrase with some
  1432.         implementation-defined text that is syntactically legal at that
  1433.         place, and follows any other applicable rules.
  1434.  
  1435.  5.d    Note that modifications are permitted, even if there are other
  1436.         tools in the environment that can detect the changes (such as a
  1437.         program library browser), so long as the modifications make no
  1438.         difference with respect to the static or dynamic semantics of
  1439.         the resulting programs, as defined by the standard.
  1440.  
  1441.     6  Contain no variations except those explicitly permitted by this
  1442.        International Standard, or those that are impossible or
  1443.        impractical to avoid given the implementation's execution
  1444.        environment;
  1445.  
  1446.  6.a    Implementation defined:  Variations from the standard that are
  1447.         impractical to avoid given the implementation's execution
  1448.         environment.
  1449.  
  1450.  6.b    Reason:  The ``impossible or impractical'' wording comes from
  1451.         AI-325.  It takes some judgement and common sense to interpret
  1452.         this.  Restricting compilation units to less than 4 lines is
  1453.         probably unreasonable, whereas restricting them to less than 4
  1454.         billion lines is probably reasonable (at least given today's
  1455.         technology).  We do not know exactly where to draw the line, so
  1456.         we have to make the rule vague.
  1457.  
  1458.     7  Specify all such variations in the manner prescribed by this
  1459.        International Standard.  {94-4485.d} {94-4749.a}
  1460.  
  1461. 8   {external effect (of the execution of an Ada program)} {effect
  1462. (external)} The external effect of the execution of an Ada program is defined
  1463. in terms of its interactions with its external environment.  {external
  1464. interaction} The following are defined as external interactions:
  1465.  
  1466.     9  Any interaction with an external file (see A.7);
  1467.  
  1468.    10  The execution of certain code_statements (see 13.8); which code_
  1469.        statements cause external interactions is implementation defined.
  1470.  
  1471.  10.a   Implementation defined:  Which code_statements cause external
  1472.         interactions.
  1473.  
  1474.    11  Any call on an imported subprogram (see Annex B), including any
  1475.        parameters passed to it;
  1476.  
  1477.    12  Any result returned or exception propagated from a main
  1478.        subprogram (see 10.2) or an exported subprogram (see Annex B) to
  1479.        an external caller;
  1480.  
  1481.  12.a   Discussion:  By ``result returned'' we mean to include function
  1482.         results and values returned in [in] out parameters.
  1483.  
  1484.    13  [Any read or update of an atomic or volatile object (see C.6);]
  1485.  
  1486.    14  The values of imported and exported objects (see Annex B) at the
  1487.        time of any other interaction with the external environment.
  1488.  
  1489.  14.a   To be honest:  Also other uses of imported and exported
  1490.         entities, as defined by the implementation, if the
  1491.         implementation supports such pragmas.
  1492.  
  1493. 15   A conforming implementation of this International Standard shall produce
  1494. for the execution of a given Ada program a set of interactions with the
  1495. external environment whose order and timing are consistent with the
  1496. definitions and requirements of this International Standard for the semantics
  1497. of the given program.
  1498.  
  1499.         15.a   Ramification:  There is no need to produce any of the
  1500.         ``internal effects'' defined for the semantics of the program -- all
  1501.         of these can be optimized away -- so long as an appropriate sequence
  1502.         of external interactions is produced.
  1503.  
  1504.         15.b   Discussion:  See also 11.6 which specifies various liberties
  1505.         associated with optimizations in the presence of language-defined
  1506.         checks, that could change the external effects that might be
  1507.         produced.  These alternative external effects are still consistent
  1508.         with the standard, since 11.6 is part of the standard.
  1509.  
  1510.         15.c   Note also that we only require ``an appropriate sequence of
  1511.         external interactions'' rather than ``the same sequence...''  An
  1512.         optimizer may cause a different sequence of external interactions to
  1513.         be produced than would be produced without the optimizer, so long as
  1514.         the new sequence still satisfies the requirements of the standard.
  1515.         For example, optimization might affect the relative rate of progress
  1516.         of two concurrent tasks, thereby altering the order in which two
  1517.         external interactions occur.
  1518.  
  1519.         15.d   Note that RM83 explicitly mentions the case of an ``exact
  1520.         effect'' of a program, but since so few programs have their effects
  1521.         defined that exactly, we don't even mention this ``special'' case.
  1522.         In particular, almost any program that uses floating point or tasking
  1523.         has to have some level of inexactness in the specification of its
  1524.         effects.  And if one includes aspects of the timing of the external
  1525.         interactions in the external effect of the program (as is appropriate
  1526.         for a real-time language), no ``exact effect'' can be specified.  For
  1527.         example, if two external interactions initiated by a single task are
  1528.         separated by a ``delay 1.0;'' then the language rules imply that the
  1529.         two external interactions have to be separated in time by at least
  1530.         one second, as defined by the clock associated with the delay_
  1531.         relative_statement.  This in turn implies that the time at which an
  1532.         external interaction occurs is part of the characterization of the
  1533.         external interaction, at least in some cases, again making the
  1534.         specification of the required ``exact effect'' impractical.
  1535.  
  1536. 16   An implementation that conforms to this Standard shall support each
  1537. capability required by the core language as specified.  In addition, an
  1538. implementation that conforms to this Standard may conform to one or more
  1539. Specialized Needs Annexes (or to none).  Conformance to a Specialized Needs
  1540. Annex means that each capability required by the Annex is provided as
  1541. specified.
  1542.  
  1543.         16.a   Discussion:  The last sentence defines what it means to say
  1544.         that an implementation conforms to a Specialized Needs Annex, namely,
  1545.         only by supporting all capabilities required by the Annex.
  1546.  
  1547. 17   An implementation conforming to this International Standard may provide
  1548. additional attributes, library units, and pragmas.  However, it shall not
  1549. provide any attribute, library unit, or pragma having the same name as an
  1550. attribute, library unit, or pragma (respectively) specified in a Specialized
  1551. Needs Annex unless the provided construct is either as specified in the
  1552. Specialized Needs Annex or is more limited in capability than that required
  1553. by the Annex.  A program that attempts to use an unsupported capability of an
  1554. Annex shall either be identified by the implementation before run time or
  1555. shall raise an exception at run time.
  1556.  
  1557.         17.a   Discussion:  The last sentence of the preceding paragraph
  1558.         defines what an implementation is allowed to do when it does not
  1559.         "conform" to a Specialized Needs Annex.  In particular, the sentence
  1560.         forbids implementations from providing a construct with the same name
  1561.         as a corresponding construct in a Specialized Needs Annex but with a
  1562.         different syntax (e.g., an extended syntax) or quite different
  1563.         semantics.  The phrase concerning "more limited in capability" is
  1564.         intended to give permission to provide a partial implementation, such
  1565.         as not implementing a subprogram in a package or having a restriction
  1566.         not permitted by an implementation that conforms to the Annex.  For
  1567.         example, a partial implementation of the package Ada.Decimal might
  1568.         have Decimal.Max_Decimal_Digits as 15 (rather than the required 18).
  1569.         This allows a partial implementation to grow to a fully conforming
  1570.         implementation.
  1571.  
  1572.         17.b   A restricted implementation might be restricted by not
  1573.         providing some subprograms specified in one of the packages defined
  1574.         by an Annex.  In this case, a program that tries to use the missing
  1575.         subprogram will usually fail to compile.  Alternatively, the
  1576.         implementation might declare the subprogram as abstract, so it cannot
  1577.         be called.  {Program_Error (raised by failure of run-time check)}
  1578.         Alternatively, a subprogram body might be implemented just to raise
  1579.         Program_Error.  The advantage of this approach is that a program to
  1580.         be run under a fully conforming Annex implementation can be checked
  1581.         syntactically and semantically under an implementation that only
  1582.         partially supports the Annex.  Finally, an implementation might
  1583.         provide a package declaration without the corresponding body, so that
  1584.         programs can be compiled, but partitions cannot be built and
  1585.         executed.
  1586.  
  1587.         17.c   To ensure against wrong answers being delivered by a partial
  1588.         implementation, implementers are required to raise an exception when
  1589.         a program attempts to use an unsupported capability and this can be
  1590.         detected only at run time.  For example, a partial implementation of
  1591.         Ada.Decimal might require the length of the Currency string to be 1,
  1592.         and hence, an exception would be raised if a subprogram were called
  1593.         in the package Edited_Output with a length greater than 1.
  1594.  
  1595.  
  1596.                          Documentation Requirements
  1597.  
  1598. 18   {documentation requirements} {implementation defined} {unspecified}
  1599. {specified (not!)} {implementation-dependent: see unspecified} {documentation
  1600. (required of an implementation)} Certain aspects of the semantics are defined
  1601. to be either implementation defined or unspecified.  In such cases, the set
  1602. of possible effects is specified, and the implementation may choose any
  1603. effect in the set.  Implementations shall document their behavior in
  1604. implementation-defined situations, but documentation is not required for
  1605. unspecified situations.  The implementation-defined characteristics are
  1606. summarized in Annex M.
  1607.  
  1608.         18.a   Discussion:  We used to use the term ``implementation
  1609.         dependent'' instead of ``unspecified''.  However, that sounded too
  1610.         much like ``implementation defined''.  Furthermore, the term
  1611.         ``unspecified'' is used in the ANSI C and POSIX standards for this
  1612.         purpose, so that is another advantage.  We also use ``not specified''
  1613.         and ``not specified by the language'' as synonyms for
  1614.         ``unspecified.''  The documentation requirement is the only
  1615.         difference between implementation defined and unspecified.
  1616.  
  1617.         18.b   Note that the ``set of possible effects'' can be ``all
  1618.         imaginable effects'', as is the case with erroneous execution.
  1619.  
  1620. 19   The implementation may choose to document implementation-defined
  1621. behavior either by documenting what happens in general, or by providing some
  1622. mechanism for the user to determine what happens in a particular case.
  1623.  
  1624.         19.a   Discussion:  For example, if the standard says that library
  1625.         unit elaboration order is implementation defined, the implementation
  1626.         might describe (in its user's manual) the algorithm it uses to
  1627.         determine the elaboration order.  On the other hand, the
  1628.         implementation might provide a command that produces a description of
  1629.         the elaboration order for a partition upon request from the user.  It
  1630.         is also acceptable to provide cross references to existing
  1631.         documentation (for example, a hardware manual), where appropriate.
  1632.  
  1633.         19.b   Note that dependence of a program on implementation-defined or
  1634.         unspecified functionality is not defined to be an error; it might
  1635.         cause the program to be less portable, however.
  1636.  
  1637.  
  1638.                             Implementation Advice
  1639.  
  1640. 20   {Program_Error (raised by failure of run-time check)} If an
  1641. implementation detects the use of an unsupported Specialized Needs Annex
  1642. feature at run time, it should raise Program_Error if feasible.
  1643.  
  1644.         20.a   Reason:  The reason we don't require Program_Error is that
  1645.         there are situations where other exceptions might make sense.  For
  1646.         example, if the Real Time Systems Annex requires that the range of
  1647.         System.Priority include at least 30 values, an implementation could
  1648.         conform to the Standard (but not to the Annex) if it supported only
  1649.         12 values.  Since the rules of the language require Constraint_Error
  1650.         to be raised for out-of-range values, we cannot require Program_Error
  1651.         to be raised instead.
  1652.  
  1653. 21   If an implementation wishes to provide implementation-defined extensions
  1654. to the functionality of a language-defined library unit, it should normally
  1655. do so by adding children to the library unit.
  1656.  
  1657.         21.a   Implementation Note:  If an implementation has support code
  1658.         (``run-time system code'') that is needed for the execution of
  1659.         user-defined code, it can put that support code in child packages of
  1660.         System.  Otherwise, it has to use some trick to avoid polluting the
  1661.         user's namespace.  It is important that such tricks not be available
  1662.         to user-defined code (not in the standard mode, at least) -- that
  1663.         would defeat the purpose.
  1664.  
  1665.  
  1666.      NOTES
  1667. 22   (2) The above requirements imply that an implementation conforming to
  1668.      this Standard may support some of the capabilities required by a
  1669.      Specialized Needs Annex without supporting all required capabilities.
  1670.  
  1671.    22.a   Discussion:  A conforming implementation can partially support a
  1672.         Specialized Needs Annex.  Such an implementation does not conform to
  1673.         the Annex, but it does conform to the Standard.
  1674.  
  1675.  
  1676.  
  1677. 1.1.4 Method of Description and Syntax Notation
  1678.  
  1679. 1   The form of an Ada program is described by means of a context-free syntax
  1680. together with context-dependent requirements expressed by narrative rules.
  1681.  
  1682. 2   The meaning of Ada programs is described by means of narrative rules
  1683. defining both the effects of each construct and the composition rules for
  1684. constructs.
  1685.  
  1686. 3   {syntax (notation)} {grammar (notation)} {context free grammar
  1687. (notation)} {BNF (Backus-Naur Form) (notation)} {Backus-Naur Form (BNF)
  1688. (notation)} The context-free syntax of the language is described using a
  1689. simple variant of Backus-Naur Form.  In particular:
  1690.  
  1691.     4  Lower case words in a sans-serif font, some containing embedded
  1692.        underlines, are used to denote syntactic categories, for example:
  1693.  
  1694. 5          case_statement
  1695.  
  1696.     6  Boldface words are used to denote reserved words, for example:
  1697.  
  1698. 7          array
  1699.  
  1700.     8  Square brackets enclose optional items.  Thus the two following
  1701.        rules are equivalent.
  1702.  
  1703. 9          return_statement ::= return [expression];
  1704.            return_statement ::= return; | return expression;
  1705.  
  1706.    10  Curly brackets enclose a repeated item.  The item may appear zero
  1707.        or more times; the repetitions occur from left to right as with
  1708.        an equivalent left-recursive rule.  Thus the two following rules
  1709.        are equivalent.
  1710.  
  1711. 11         term ::= factor {multiplying_operator factor}
  1712.            term ::= factor | term multiplying_operator factor
  1713.  
  1714.    12  A vertical line separates alternative items unless it occurs
  1715.        immediately after an opening curly bracket, in which case it
  1716.        stands for itself:
  1717.  
  1718. 13         constraint ::= scalar_constraint | composite_constraint
  1719.            discrete_choice_list ::= discrete_choice {| discrete_choice}
  1720.  
  1721.    14  {italics (syntax rules)} If the name of any syntactic category
  1722.        starts with an italicized part, it is equivalent to the category
  1723.        name without the italicized part.  The italicized part is
  1724.        intended to convey some semantic information.  For example
  1725.        subtype_name and task_name are both equivalent to name alone.
  1726.  
  1727.         14.a   Discussion:  {LR(1)} {ambiguous grammar} {grammar (resolution
  1728.         of ambiguity)} {grammar (ambiguous)} The grammar given in the RM9X is
  1729.         not LR(1).  In fact, it is ambiguous; the ambiguities are resolved by
  1730.         the overload resolution rules (see 8.6).
  1731.  
  1732.         14.b   We often use ``if'' to mean ``if and only if'' in definitions.
  1733.         For example, if we define ``photogenic'' by saying, ``A type is
  1734.         photogenic if it has the following properties...,'' we mean that a
  1735.         type is photogenic if and only if it has those properties.  It is
  1736.         usually clear from the context, and adding the ``and only if'' seems
  1737.         too cumbersome.
  1738.  
  1739.         14.c   When we say, for example, ``a declarative_item of a
  1740.         declarative_part'', we are talking about a declarative_item
  1741.         immediately within that declarative_part.  When we say ``a
  1742.         declarative_item in, or within, a declarative_part'', we are talking
  1743.         about a declarative_item anywhere in the declarative_part, possibly
  1744.         deeply nested within other declarative_parts.  (This notation doesn't
  1745.         work very well for names, since the name ``of'' something also has
  1746.         another meaning.)
  1747.  
  1748.         14.d   When we refer to the name of a language-defined entity (for
  1749.         example, Duration), we mean the language-defined entity even in
  1750.         programs where the declaration of the language-defined entity is
  1751.         hidden by another declaration.  For example, when we say that the
  1752.         expected type for the expression of a delay_relative_statement is
  1753.         Duration, we mean the language-defined type Duration that is declared
  1754.         in Standard, not some type Duration the user might have declared.
  1755.  
  1756. 15   {syntactic category} A syntactic category is a nonterminal in the
  1757. grammar defined in BNF under ``Syntax.''  Names of syntactic categories are
  1758. set in a different font, like_this.
  1759.  
  1760. 16   {Construct} [glossary entry]A construct is a piece of text (explicit or
  1761. implicit) that is an instance of a syntactic category defined under
  1762. ``Syntax.''
  1763.  
  1764.         16.a   Ramification:  For example, an expression is a construct.  A
  1765.         declaration is a construct, whereas the thing declared by a
  1766.         declaration is an ``entity.''
  1767.  
  1768.         16.b   Discussion:  ``Explicit'' and ``implicit'' don't mean exactly
  1769.         what you might think they mean:  The text of an instance of a generic
  1770.         is considered explicit, even though it does not appear explicitly (in
  1771.         the non-technical sense) in the program text, and even though its
  1772.         meaning is not defined entirely in terms of that text.
  1773.  
  1774. 17   {constituent (of a construct)} A constituent of a construct is the
  1775. construct itself, or any construct appearing within it.
  1776.  
  1777. 18   {arbitrary order} Whenever the run-time semantics defines certain
  1778. actions to happen in an arbitrary order, this means that the implementation
  1779. shall arrange for these actions to occur in a way that is equivalent to some
  1780. sequential order, following the rules that result from that sequential order.
  1781. When evaluations are defined to happen in an arbitrary order, with conversion
  1782. of the results to some subtypes, or with some run-time checks, the
  1783. evaluations, conversions, and checks may be arbitrarily interspersed, so long
  1784. as each expression is evaluated before converting or checking its value.
  1785. {type conversion [arbitrary order]} {conversion [arbitrary order]} [Note that
  1786. the effect of a program can depend on the order chosen by the implementation.
  1787. This can happen, for example, if two actual parameters of a given call have
  1788. side effects.]
  1789.  
  1790.         18.a   Discussion:  Programs will be more portable if their external
  1791.         effect does not depend on the particular order chosen by an
  1792.         implementation.
  1793.  
  1794.         18.b   Ramification:  Additional reordering permissions are given in
  1795.         11.6, ``Exceptions and Optimization''.
  1796.  
  1797.         18.c   There is no requirement that the implementation always choose
  1798.         the same order in a given kind of situation.  In fact, the
  1799.         implementation is allowed to choose a different order for two
  1800.         different executions of the same construct.  However, we expect most
  1801.         implementations will behave in a relatively predictable manner in
  1802.         most situations.
  1803.  
  1804.         18.d   Reason:  The ``sequential order'' wording is intended to allow
  1805.         the programmer to rely on ``benign'' side effects.  For example, if F
  1806.         is a function that returns a unique integer by incrementing some
  1807.         global and returning the result, a call such as P(F, F) is OK if the
  1808.         programmer cares only that the two results of F are unique; the two
  1809.         calls of F cannot be executed in parallel, unless the compiler can
  1810.         prove that parallel execution is equivalent to some sequential order.
  1811.  
  1812.  
  1813.      NOTES
  1814. 19   (3) The syntax rules describing structured constructs are presented in a
  1815.      form that corresponds to the recommended paragraphing.  For example, an
  1816.      if_statement is defined as:
  1817.  
  1818. 20       if_statement ::=
  1819.              if condition then
  1820.                sequence_of_statements
  1821.             {elsif condition then
  1822.                sequence_of_statements}
  1823.             [else
  1824.                sequence_of_statements]
  1825.              end if;
  1826.  
  1827. 21   (4) The line breaks and indentation in the syntax rules indicate the
  1828.      recommended line breaks and indentation in the corresponding constructs.
  1829.      The preferred places for other line breaks are after semicolons.
  1830.  
  1831.  
  1832.  
  1833. 1.1.5 Classification of Errors
  1834.  
  1835.                          Implementation Requirements
  1836.  
  1837. 1   The language definition classifies errors into several different
  1838. categories:
  1839.  
  1840.     2   Errors that are required to be detected prior to run time by
  1841.        every Ada implementation;
  1842.  
  1843.        3   These errors correspond to any violation of a rule given in
  1844.        this International Standard, other than those listed below.  In
  1845.        particular, violation of any rule that uses the terms shall,
  1846.        allowed, permitted, legal, or illegal belongs to this category.
  1847.        Any program that contains such an error is not a legal Ada
  1848.        program; on the other hand, the fact that a program is legal does
  1849.        not mean, per se, that the program is free from other forms of
  1850.        error.
  1851.  
  1852.        4   {compile-time error} {error (compile-time)} {link-time error:
  1853.        see post-compilation error} {error (link-time)} The rules are
  1854.        further classified as either compile time rules, or post
  1855.        compilation rules, depending on whether a violation has to be
  1856.        detected at the time a compilation unit is submitted to the
  1857.        compiler, or may be postponed until the time a compilation unit
  1858.        is incorporated into a partition of a program.
  1859.  
  1860.         4.a   Ramification:  See, for example, 10.1.3, ``Subunits of
  1861.         Compilation Units'', for some errors that are detected only
  1862.         after compilation.  Implementations are allowed, but not
  1863.         required, to detect post compilation rules at compile time when
  1864.         possible.
  1865.  
  1866.     5   Errors that are required to be detected at run time by the
  1867.        execution of an Ada program;
  1868.  
  1869.        6   {run-time error} {error (run-time)} The corresponding error
  1870.        situations are associated with the names of the predefined
  1871.        exceptions.  Every Ada compiler is required to generate code that
  1872.        raises the corresponding exception if such an error situation
  1873.        arises during program execution.  [If such an error situation is
  1874.        certain to arise in every execution of a construct, then an
  1875.        implementation is allowed (although not required) to report this
  1876.        fact at compilation time.]  {94-4776.a}
  1877.  
  1878.     7   Bounded errors;
  1879.  
  1880.        8   The language rules define certain kinds of errors that need
  1881.        not be detected either prior to or during run time, but if not
  1882.        detected, the range of possible effects shall be bounded.
  1883.        {bounded error} The errors of this category are called bounded
  1884.        errors.  {Program_Error (raised by failure of run-time check)}
  1885.        The possible effects of a given bounded error are specified for
  1886.        each such error, but in any case one possible effect of a bounded
  1887.        error is the raising of the exception Program_Error.
  1888.  
  1889.     9   Erroneous execution.
  1890.  
  1891.        10   {erroneous execution} In addition to bounded errors, the
  1892.        language rules define certain kinds of errors as leading to
  1893.        erroneous execution.  Like bounded errors, the implementation
  1894.        need not detect such errors either prior to or during run time.
  1895.        Unlike bounded errors, there is no language-specified bound on
  1896.        the possible effect of erroneous execution; the effect is in
  1897.        general not predictable.
  1898.  
  1899.         10.a   Ramification:  Executions are erroneous, not programs or
  1900.         parts of programs.  Once something erroneous happens, the
  1901.         execution of the entire program is erroneous from that point on,
  1902.         and potentially before given possible reorderings permitted by
  1903.         11.6 and elsewhere.  We cannot limit it to just one partition,
  1904.         since partitions are not required to live in separate address
  1905.         spaces.  (But implementations are encouraged to limit it as much
  1906.         as possible.)
  1907.  
  1908.         10.b   Suppose a program contains a pair of things that will be
  1909.         executed ``in an arbitrary order.''  It is possible that one
  1910.         order will result in something sensible, whereas the other order
  1911.         will result in erroneous execution.  If the implementation
  1912.         happens to choose the first order, then the execution is not
  1913.         erroneous.  This may seem odd, but it is not harmful.
  1914.  
  1915.         10.c   Saying that something is erroneous is semantically
  1916.         equivalent to saying that the behavior is unspecified.  However,
  1917.         ``erroneous'' has a slightly more disapproving flavor.
  1918.  
  1919.  
  1920.                          Implementation Permissions
  1921.  
  1922. 11   [{mode of operation (nonstandard)} {nonstandard mode} An implementation
  1923. may provide nonstandard modes of operation.  Typically these modes would be
  1924. selected by a pragma or by a command line switch when the compiler is
  1925. invoked.  When operating in a nonstandard mode, the implementation may reject
  1926. compilation_units that do not conform to additional requirements associated
  1927. with the mode, such as an excessive number of warnings or violation of coding
  1928. style guidelines.  Similarly, in a nonstandard mode, the implementation may
  1929. apply special optimizations or alternative algorithms that are only
  1930. meaningful for programs that satisfy certain criteria specified by the
  1931. implementation.  {mode of operation (standard)} {standard mode} In any case,
  1932. an implementation shall support a standard mode that conforms to the
  1933. requirements of this International Standard; in particular, in the standard
  1934. mode, all legal compilation_units shall be accepted.]
  1935.  
  1936.         11.a   Discussion:  These permissions are designed to authorize
  1937.         explicitly the support for alternative modes.  Of course, nothing we
  1938.         say can prevent them anyway, but this (redundant) paragraph is
  1939.         designed to indicate that such alternative modes are in some sense
  1940.         ``approved'' and even encouraged where they serve the specialized
  1941.         needs of a given user community, so long as the standard mode,
  1942.         designed to foster maximum portability, is always available.
  1943.  
  1944.  
  1945.                             Implementation Advice
  1946.  
  1947. 12   {Program_Error (raised by failure of run-time check)} If an
  1948. implementation detects a bounded error or erroneous execution, it should
  1949. raise Program_Error.
  1950.  
  1951.  
  1952.                          Wording Changes From Ada 83
  1953.  
  1954.         12.a   Some situations that are erroneous in Ada 83 are no longer
  1955.         errors at all.  For example, depending on the parameter passing
  1956.         mechanism when unspecified is possibly non-portable, but not
  1957.         erroneous.
  1958.  
  1959.         12.b   Other situations that are erroneous in Ada 83 are changed to
  1960.         be bounded errors.  In particular, evaluating an uninitialized scalar
  1961.         variable is a bounded error.  {Program_Error (raised by failure of
  1962.         run-time check)} The possible results are to raise Program_Error (as
  1963.         always), or to produce a machine-representable value (which might not
  1964.         be in the subtype of the variable).  {Constraint_Error (raised by
  1965.         failure of run-time check)} Violating a Range_Check or Overflow_Check
  1966.         raises Constraint_Error, even if the value came from an uninitialized
  1967.         variable.  This means that optimizers can no longer ``assume'' that
  1968.         all variables are initialized within their subtype's range.
  1969.         Violating a check that is suppressed remains erroneous.
  1970.  
  1971.         12.c   The ``incorrect order dependences'' category of errors is
  1972.         removed.  All such situations are simply considered potential
  1973.         non-portabilities.  This category was removed due to the difficulty
  1974.         of defining what it means for two executions to have a ``different
  1975.         effect.''  For example, if a function with a side-effect is called
  1976.         twice in a single expression, it is not in principle possible for the
  1977.         compiler to decide whether the correctness of the resulting program
  1978.         depends on the order of execution of the two function calls.  A
  1979.         compile time warning might be appropriate, but raising of Program_
  1980.         Error at run time would not be.
  1981.  
  1982.  
  1983.  
  1984. 1.2 Normative References
  1985.  
  1986. 1   {references} {bibliography} The following standards contain provisions
  1987. which, through reference in this text, constitute provisions of this
  1988. International Standard.  At the time of publication, the editions indicated
  1989. were valid.  All standards are subject to revision, and parties to agreements
  1990. based on this International Standard are encouraged to investigate the
  1991. possibility of applying the most recent editions of the standards indicated
  1992. below.  Members of IEC and ISO maintain registers of currently valid
  1993. International Standards.
  1994.  
  1995. 2   {ISO/IEC 646:1991} {646:1991, ISO/IEC standard} {character set standard
  1996. (7-bit)} ISO/IEC 646:1991, Information technology -- ISO 7-bit coded
  1997. character set for information interchange.
  1998.  
  1999. 3   {ISO/IEC 1539:1991} {1539:1991, ISO/IEC standard} {FORTRAN standard}
  2000. ISO/IEC 1539:1991, Information technology -- Programming languages --
  2001. FORTRAN.
  2002.  
  2003. 4   {ISO 1989:1985} {1989:1985, ISO standard} {COBOL standard} ISO 1989:1985,
  2004. Programming languages -- COBOL.
  2005.  
  2006. 5   {ISO/IEC 6429:1992} {6429:1992, ISO/IEC standard} {character set standard
  2007. (control functions)} ISO/IEC 6429:1992, Information technology -- Control
  2008. functions for coded graphic character sets.
  2009.  
  2010. 6   {ISO/IEC 8859-1:1987} {8859-1:1987, ISO/IEC standard} {character set
  2011. standard (8-bit)} ISO/IEC 8859-1:1987, Information processing -- 8-bit
  2012. single-byte coded character sets -- Part 1: Latin alphabet No. 1.
  2013.  
  2014. 7   {ISO/IEC 9899:1990} {9899:1990, ISO/IEC standard} {C standard} ISO/IEC
  2015. 9899:1990, Programming languages -- C.
  2016.  
  2017. 8   {ISO/IEC 10646-1:1993} {10646-1:1993, ISO/IEC standard} {character set
  2018. standard (16-bit)} ISO/IEC 10646-1:1993, Information technology -- Universal
  2019. Multiple-Octet Coded Character Set (UCS) -- Part 1: Architecture and Basic
  2020. Multilingual Plane.  {94-4485.f}
  2021.  
  2022.         8.a   Discussion:  {POSIX} POSIX, Portable Operating System Interface
  2023.         (POSIX) -- Part 1: System Application Program Interface (API) [C
  2024.         Language], The Institute of Electrical and Electronics Engineers,
  2025.         1990.
  2026.  
  2027.  
  2028.  
  2029. 1.3 Definitions
  2030.  
  2031. 1   {italics (terms introduced or defined)} Terms are defined throughout this
  2032. International Standard, indicated by italic type.  Terms explicitly defined
  2033. in this International Standard are not to be presumed to refer implicitly to
  2034. similar terms defined elsewhere.  Terms not defined in this International
  2035. Standard are to be interpreted according to the Webster's Third New
  2036. International Dictionary of the English Language.  Informal descriptions of
  2037. some terms are also given in Annex N, ``Glossary''.
  2038.  
  2039.         1.a   Discussion:  The index contains an entry for every defined
  2040.         term.
  2041.  
  2042.         1.b   Glossary entry:  Each term defined in Annex N is marked like
  2043.         this.
  2044.  
  2045.  
  2046.         1.c   Discussion:  Here are some AARM-only definitions:  {Ada
  2047.         Rapporteur Group (ARG)} {ARG} The Ada Rapporteur Group (ARG)
  2048.         interprets the RM83.  {Ada Issue (AI)} {AI} An Ada Issue (AI) is a
  2049.         numbered ruling from the ARG.  {Ada Commentary Integration Document
  2050.         (ACID)} {ACID} The Ada Commentary Integration Document (ACID) is an
  2051.         edition of RM83 in which clearly marked insertions and deletions
  2052.         indicate the effect of integrating the approved AIs.  {Uniformity
  2053.         Rapporteur Group (URG)} {URG} The Uniformity Rapporteur Group (URG)
  2054.         issues recommendations intended to increase uniformity across Ada
  2055.         implementations.  {Uniformity Issue (UI)} {UI} A Uniformity Issue
  2056.         (UI) is a numbered recommendation from the URG.
  2057.  
  2058.  
  2059.  
  2060.                          Section 2: Lexical Elements
  2061.  
  2062.  
  2063. 1   [The text of a program consists of the texts of one or more compilations.
  2064. The text of a compilation is a sequence of lexical elements, each composed of
  2065. characters; the rules of composition are given in this section.  Pragmas,
  2066. which provide certain information for the compiler, are also described in
  2067. this section.]
  2068.  
  2069.  
  2070.  
  2071. 2.1 Character Set
  2072.  
  2073. 1   {character set} The only characters allowed outside of comments are the
  2074. graphic_characters and format_effectors.
  2075.  
  2076.         1.a   Ramification:  Any character, including an other_control_
  2077.         function, is allowed in a comment.
  2078.  
  2079.         1.b   Note that this rule doesn't really have much force, since the
  2080.         implementation can represent characters in the source in any way it
  2081.         sees fit.  For example, an implementation could simply define that
  2082.         what seems to be a non-graphic, non-format-effector character is
  2083.         actually a representation of the space character.
  2084.  
  2085.         1.c   Discussion:  It is our intent to follow the terminology of ISO
  2086.         10646 BMP where appropriate, and to remain compatible with the
  2087.         character classifications defined in A.3, ``Character Handling''.
  2088.         Note that our definition for graphic_character is more inclusive than
  2089.         that of ISO 10646-1.
  2090.                                    Syntax
  2091.  
  2092. 2   character ::= graphic_character | format_effector | other_control_function
  2093.  
  2094. 3   graphic_character ::= identifier_letter | digit | space_character | special\
  2095. _character
  2096.  
  2097.  
  2098.                               Static Semantics
  2099.  
  2100. 4   The character repertoire for the text of an Ada program consists of the
  2101. collection of characters called the Basic Multilingual Plane (BMP) of the ISO
  2102. 10646 Universal Multiple-Octet Coded Character Set, plus a set of format_
  2103. effectors and, in comments only, a set of other_control_functions; the coded
  2104. representation for these characters is implementation defined [(it need not
  2105. be a representation defined within ISO-10646-1)].
  2106.  
  2107.         4.a   Implementation defined:  The coded representation for the text
  2108.         of an Ada program.
  2109.  
  2110. 5   The description of the language definition in this International Standard
  2111. uses the graphic symbols defined for Row 00: Basic Latin and Row 00: Latin-1
  2112. Supplement of the ISO 10646 BMP; these correspond to the graphic symbols of
  2113. ISO 8859-1 (Latin-1); no graphic symbols are used in this International
  2114. Standard for characters outside of Row 00 of the BMP.  The actual set of
  2115. graphic symbols used by an implementation for the visual representation of
  2116. the text of an Ada program is not specified.  {unspecified [partial]}
  2117.  
  2118. 6   The categories of characters are defined as follows:
  2119.  
  2120. 7   {identifier_letter} identifier_letter
  2121.                 upper_case_identifier_letter | lower_case_identifier_letter
  2122.  
  2123. 7.a     Discussion:  We use identifier_letter instead of simply letter
  2124.         because ISO 10646 BMP includes many other characters that would
  2125.         generally be considered "letters."
  2126.  
  2127. 8   {upper_case_identifier_letter} upper_case_identifier_letter
  2128.                 Any character of Row 00 of ISO 10646 BMP whose name begins
  2129.                 ``Latin Capital Letter''.
  2130.  
  2131. 9   {lower_case_identifier_letter} lower_case_identifier_letter
  2132.                 Any character of Row 00 of ISO 10646 BMP whose name begins
  2133.                 ``Latin Small Letter''.
  2134.  
  2135. 10  {digit} digit
  2136.                 One of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.
  2137.  
  2138. 11  {space_character} space_character
  2139.                 The character of ISO 10646 BMP named ``Space''.
  2140.  
  2141. 12  {special_character} special_character
  2142.                 Any character of the ISO 10646 BMP that is not reserved for a
  2143.                 control function, and is not the space_character, an
  2144.                 identifier_letter, or a digit.
  2145.  
  2146. 12.a    Ramification:  Note that the no break space and soft hyphen are
  2147.         special_characters, and therefore graphic_characters.  They are not
  2148.         the same characters as space and hyphen-minus.
  2149.  
  2150. 13  {format_effector} format_effector
  2151.                 The control functions of ISO 6429 called character tabulation
  2152.                 (HT), line tabulation (VT), carriage return (CR), line feed
  2153.                 (LF), and form feed (FF).  {control character: see also
  2154.                 format_effector}
  2155.  
  2156. 14  {other_control_function} other_control_function
  2157.                 Any control function, other than a format_effector, that is
  2158.                 allowed in a comment; the set of other_control_functions
  2159.                 allowed in comments is implementation defined.
  2160.  
  2161. 14.a    Implementation defined:  The control functions allowed in comments.
  2162.  
  2163.                 {control character: see also other_control_function}
  2164.  
  2165. 15   {names of special_characters} {special_character (names)} The following
  2166. names are used when referring to certain special_characters:  {quotation
  2167. mark} {number sign} {ampersand} {apostrophe} {tick} {left parenthesis} {right
  2168. parenthesis} {asterisk} {multiply} {plus sign} {comma} {hyphen-minus} {minus}
  2169. {full stop} {dot} {point} {solidus} {divide} {colon} {semicolon} {less-than
  2170. sign} {equals sign} {greater-than sign} {low line} {underline} {vertical
  2171. line} {left square bracket} {right square bracket} {left curly bracket}
  2172. {right curly bracket}
  2173.  
  2174.         15.a   Discussion:  These are the ones that play a special role in
  2175.         the syntax of Ada 9X, or in the syntax rules; we don't bother to
  2176.         define names for all characters.  The first name given is the name
  2177.         from ISO 10646-1; the subsequent names, if any, are those used within
  2178.         the standard, depending on context.
  2179.  
  2180.     symbol     name                       symbol     name
  2181.  
  2182.       "        quotation mark               :        colon
  2183.       #        number sign                  ;        semicolon
  2184.       &        ampersand                    <        less-than sign
  2185.       '        apostrophe, tick             =        equals sign
  2186.       (        left parenthesis             >        greater-than sign
  2187.       )        right parenthesis            _        low line, underline
  2188.       *        asterisk, multiply           |        vertical line
  2189.       +        plus sign                    [        left square bracket
  2190.       ,        comma                        ]        right square bracket
  2191.       -        hyphen-minus, minus          {        left curly bracket
  2192.       .        full stop, dot, point        }        right curly bracket
  2193.       /        solidus, divide
  2194.  
  2195.  
  2196.  
  2197.                          Implementation Permissions
  2198.  
  2199. 16   In a nonstandard mode, the implementation may support a different
  2200. character repertoire[; in particular, the set of characters that are
  2201. considered identifier_letters can be extended or changed to conform to local
  2202. conventions].
  2203.  
  2204.         16.a   Ramification:  If an implementation supports other character
  2205.         sets, it defines which characters fall into each category, such as
  2206.         ``identifier_letter,'' and what the corresponding rules of this
  2207.         section are, such as which characters are allowed in the text of a
  2208.         program.
  2209.  
  2210.  
  2211.      NOTES
  2212. 17   (1) Every code position of ISO 10646 BMP that is not reserved for a
  2213.      control function is defined to be a graphic_character by this
  2214.      International Standard.  This includes all code positions other than
  2215.      0000 - 001F, 007F - 009F, and FFFE - FFFF.
  2216.  
  2217. 18   (2) The language does not specify the source representation of programs.
  2218.  
  2219.    18.a   Discussion:  Any source representation is valid so long as the
  2220.         implementer can produce an (information-preserving) algorithm for
  2221.         translating both directions between the representation and the
  2222.         standard character set.  (For example, every character in the
  2223.         standard character set has to be representable, even if the output
  2224.         devices attached to a given computer cannot print all of those
  2225.         characters properly.)  From a practical point of view, every
  2226.         implementer will have to provide some way to process the ACVC.  It is
  2227.         the intent to allow source representations, such as parse trees, that
  2228.         are not even linear sequences of characters.  It is also the intent
  2229.         to allow different fonts:  reserved words might be in bold face, and
  2230.         that should be irrelevant to the semantics.
  2231.  
  2232.  
  2233.                             Extensions to Ada 83
  2234.  
  2235.         18.b   {extensions to Ada 83} Ada 9X allows 8-bit and 16-bit
  2236.         characters, as well as implementation-specified character sets.
  2237.  
  2238.                          Wording Changes From Ada 83
  2239.  
  2240.         18.c   The syntax rules in this clause are modified to remove the
  2241.         emphasis on basic characters vs. others.  (In this day and age, there
  2242.         is no need to point out that you can write programs without using
  2243.         (for example) lower case letters.)  In particular, character
  2244.         (representing all characters usable outside comments) is added, and
  2245.         basic_graphic_character, other_special_character, and basic_character
  2246.         are removed.  Special_character is expanded to include Ada 83's
  2247.         other_special_character, as well as new 8-bit characters not present
  2248.         in Ada 83.  Note that the term ``basic letter'' is used in A.3,
  2249.         ``Character Handling'' to refer to letters without diacritical marks.
  2250.  
  2251.         18.d   Character names now come from ISO 10646.
  2252.  
  2253.         18.e   We use identifier_letter rather than letter since ISO 10646
  2254.         BMP includes many "letters' that are not permitted in identifiers (in
  2255.         the standard mode).
  2256.  
  2257.  
  2258.  
  2259. 2.2 Lexical Elements, Separators, and Delimiters
  2260.  
  2261.                               Static Semantics
  2262.  
  2263. 1   {text of a program} The text of a program consists of the texts of one or
  2264. more compilations.  {lexical element} {token: see lexical element} The text
  2265. of each compilation is a sequence of separate lexical elements.  Each lexical
  2266. element is formed from a sequence of characters, and is either a delimiter,
  2267. an identifier, a reserved word, a numeric_literal, a character_literal, a
  2268. string_literal, or a comment.  The meaning of a program depends only on the
  2269. particular sequences of lexical elements that form its compilations,
  2270. excluding comments.
  2271.  
  2272. 2   The text of a compilation is divided into {line} lines.  {end of a line}
  2273. In general, the representation for an end of line is implementation defined.
  2274.  
  2275.         2.a   Implementation defined:  The representation for an end of line.
  2276.  
  2277. However, a sequence of one or more format_effectors other than character
  2278. tabulation (HT) signifies at least one end of line.
  2279.  
  2280. 3   {separator} [In some cases an explicit separator is required to separate
  2281. adjacent lexical elements.]  A separator is any of a space character, a
  2282. format effector, or the end of a line, as follows:
  2283.  
  2284.         3.a   Discussion:  It might be useful to define ``white space'' and
  2285.         use it here.
  2286.  
  2287.     4  A space character is a separator except within a comment, a
  2288.        string_literal, or a character_literal.
  2289.  
  2290.     5  Character tabulation (HT) is a separator except within a comment.
  2291.  
  2292.     6  The end of a line is always a separator.
  2293.  
  2294. 7   One or more separators are allowed between any two adjacent lexical
  2295. elements, before the first of each compilation, or after the last.  At least
  2296. one separator is required between an identifier, a reserved word, or a
  2297. numeric_literal and an adjacent identifier, reserved word, or numeric_
  2298. literal.
  2299.  
  2300. 8   {delimiter} A delimiter is either one of the following special characters
  2301.  
  2302. 9   &    '    (    )    *    +    ,    -    .    /    :    ;    <    =    >    |
  2303.  
  2304. 10   {compound delimiter} or one of the following compound delimiters each
  2305. composed of two adjacent special characters
  2306.  
  2307. 11  =>    ..    **    :=    /=    >=    <=    <<    >>    <>
  2308.  
  2309. 12   Each of the special characters listed for single character delimiters is
  2310. a single delimiter except if this character is used as a character of a
  2311. compound delimiter, or as a character of a comment, string_literal,
  2312. character_literal, or numeric_literal.
  2313.  
  2314. 13   The following names are used when referring to compound delimiters:
  2315.  
  2316. 14  delimiter     name
  2317.  
  2318.        =>                       arrow
  2319.        ..                       double dot
  2320.        **                       double star, exponentiate
  2321.        :=                       assignment (pronounced: ``becomes'')
  2322.        /=                       inequality (pronounced: ``not equal'')
  2323.        >=                       greater than or equal
  2324.        <=                       less than or equal
  2325.        <<                       left label bracket
  2326.        >>                       right label bracket
  2327.        <>                       box
  2328.  
  2329.  
  2330.                          Implementation Requirements
  2331.  
  2332. 15   An implementation shall support lines of at least 200 characters in
  2333. length, not counting any characters used to signify the end of a line.  An
  2334. implementation shall support lexical elements of at least 200 characters in
  2335. length.  The maximum supported line length and lexical element length are
  2336. implementation defined.
  2337.  
  2338.         15.a   Implementation defined:  Maximum supported line length and
  2339.         lexical element length.
  2340.  
  2341.         15.b   Discussion:  From URG recommendation.
  2342.  
  2343.  
  2344.  
  2345. 2.3 Identifiers
  2346.  
  2347. 1   Identifiers are used as names.
  2348.  
  2349.  
  2350.                                    Syntax
  2351.  
  2352. 2   identifier ::=
  2353.        identifier_letter {[underline] letter_or_digit}
  2354.  
  2355. 3   letter_or_digit ::= identifier_letter | digit
  2356.  
  2357.     4   An identifier shall not be a reserved word.
  2358.  
  2359.  
  2360.                               Static Semantics
  2361.  
  2362. 5   All characters of an identifier are significant, including any underline
  2363. character.  {case insensitive} Identifiers differing only in the use of
  2364. corresponding upper and lower case letters are considered the same.
  2365.  
  2366.         5.a   Discussion:  Two of the letters of ISO 8859-1 appear only as
  2367.         lower case, "sharp s" and "y with diaeresis."  These two letters have
  2368.         no corresponding upper case letter (in particular, they are not
  2369.         considered equivalent to one another).
  2370.  
  2371.  
  2372.                          Implementation Permissions
  2373.  
  2374. 6   In a nonstandard mode, an implementation may support other upper/lower
  2375. case equivalence rules for identifiers[, to accommodate local conventions].
  2376.  
  2377.  
  2378.                                   Examples
  2379.  
  2380. 7   Examples of identifiers:
  2381.  
  2382. 8   Count      X    Get_Symbol   Ethelyn   Marion
  2383.  
  2384.     Snobol_4   X1   Page_Count    Store_Next_Item
  2385.  
  2386.  
  2387.                          Wording Changes From Ada 83
  2388.  
  2389.         8.a   We no longer include reserved words as identifiers.  This is
  2390.         not a language change.  In Ada 83, identifier included reserved
  2391.         words.  However, this complicated several other rules (for example,
  2392.         regarding implementation-defined attributes and pragmas, etc.).  We
  2393.         now explicitly allow certain reserved words for attribute
  2394.         designators, to make up for the loss.
  2395.  
  2396.         8.b   Ramification:  Because syntax rules are relevant to overload
  2397.         resolution, it means that if it looks like a reserved word, it is not
  2398.         an identifier.  As a side effect, implementations cannot use reserved
  2399.         words as implementation-defined attributes or pragma names.
  2400.  
  2401.  
  2402.  
  2403. 2.4 Numeric Literals
  2404.  
  2405. 1   {literal (numeric)} There are two kinds of numeric_literals, real
  2406. literals and integer literals.  {real literal} A real literal is a numeric_
  2407. literal that includes a point; {integer literal} an integer literal is a
  2408. numeric_literal without a point.
  2409.  
  2410.  
  2411.                                    Syntax
  2412.  
  2413. 2   numeric_literal ::= decimal_literal | based_literal
  2414.  
  2415.  
  2416.      NOTES
  2417. 3    (3) The type of an integer literal is universal_integer.  The type of a
  2418.      real literal is universal_real.
  2419.  
  2420.  
  2421.  
  2422. 2.4.1 Decimal Literals
  2423.  
  2424. 1   {literal (decimal)} A decimal_literal is a numeric_literal in the
  2425. conventional decimal notation (that is, the base is ten).
  2426.  
  2427.  
  2428.                                    Syntax
  2429.  
  2430. 2   decimal_literal ::= numeral [.numeral] [exponent]
  2431.  
  2432. 3   numeral ::= digit {[underline] digit}
  2433.  
  2434. 4   exponent ::= E [+] numeral | E - numeral
  2435.  
  2436.     5   An exponent for an integer literal shall not have a minus sign.
  2437.  
  2438.         5.a   Ramification:  Although this rule is in this subclause, it
  2439.         applies also to the next subclause.
  2440.  
  2441.  
  2442.                               Static Semantics
  2443.  
  2444. 6   An underline character in a numeric_literal does not affect its meaning.
  2445. The letter E of an exponent can be written either in lower case or in upper
  2446. case, with the same meaning.
  2447.  
  2448.         6.a   Ramification:  Although these rules are in this subclause, they
  2449.         apply also to the next subclause.
  2450.  
  2451. 7   An exponent indicates the power of ten by which the value of the decimal_
  2452. literal without the exponent is to be multiplied to obtain the value of the
  2453. decimal_literal with the exponent.
  2454.  
  2455.  
  2456.                                   Examples
  2457.  
  2458. 8   Examples of decimal literals:
  2459.  
  2460. 9
  2461.     12        0      1E6    123_456           --  integer literals
  2462.  
  2463.     12.0      0.0    0.456  3.14159_26        --  real literals
  2464.  
  2465.  
  2466.                          Wording Changes From Ada 83
  2467.  
  2468.         9.a   We have changed the syntactic category name integer to be
  2469.         numeral.  We got this idea from ACID.  It avoids the confusion
  2470.         between this and integers.  (Other places don't offer similar
  2471.         confusions.  For example, a string_literal is different from a
  2472.         string.)
  2473.  
  2474.  
  2475.  
  2476. 2.4.2 Based Literals
  2477.  
  2478. 1   [{literal (based)} {binary literal} {base 2 literal} {binary (literal)}
  2479. {octal literal} {base 8 literal} {octal (literal)} {hexadecimal literal}
  2480. {base 16 literal} {hexadecimal (literal)} A based_literal is a numeric_
  2481. literal expressed in a form that specifies the base explicitly.]
  2482.  
  2483.  
  2484.                                    Syntax
  2485.  
  2486. 2   based_literal ::=
  2487.        base # based_numeral [.based_numeral] # [exponent]
  2488. 3   base ::= numeral
  2489.  
  2490. 4   based_numeral ::=
  2491.        extended_digit {[underline] extended_digit}
  2492.  
  2493. 5   extended_digit ::= digit | A | B | C | D | E | F
  2494.  
  2495.  
  2496.                                Legality Rules
  2497.  
  2498. 6   {base} The base (the numeric value of the decimal numeral preceding the
  2499. first #) shall be at least two and at most sixteen.  The extended_digits A
  2500. through F represent the digits ten through fifteen, respectively.  The value
  2501. of each extended_digit of a based_literal shall be less than the base.
  2502.  
  2503.  
  2504.                               Static Semantics
  2505.  
  2506. 7   The conventional meaning of based notation is assumed.  An exponent
  2507. indicates the power of the base by which the value of the based_literal
  2508. without the exponent is to be multiplied to obtain the value of the based_
  2509. literal with the exponent.  The base and the exponent, if any, are in decimal
  2510. notation.
  2511.  
  2512. 8   The extended_digits A through F can be written either in lower case or in
  2513. upper case, with the same meaning.
  2514.  
  2515.  
  2516.                                   Examples
  2517.  
  2518. 9   Examples of based literals:
  2519.  
  2520. 10
  2521.     2#1111_1111#   16#FF#       016#0ff#                    --  integer literal\
  2522. s of value 255
  2523.     16#E#E1        2#1110_0000#                             --  integer literal\
  2524. s of value 224
  2525.     16#F.FF#E+2    2#1.1111_1111_1110#E11                   --  real literals o\
  2526. f value 4095.0
  2527.  
  2528.  
  2529.                          Wording Changes From Ada 83
  2530.  
  2531.         10.a   The rule about which letters are allowed is now encoded in
  2532.         BNF, as suggested by Mike Woodger.  This is clearly more readable.
  2533.  
  2534.  
  2535.  
  2536. 2.5 Character Literals
  2537.  
  2538. 1   [A character_literal is formed by enclosing a graphic character between
  2539. two apostrophe characters.]
  2540.  
  2541.  
  2542.                                    Syntax
  2543.  
  2544. 2   character_literal ::= 'graphic_character'
  2545.  
  2546.  
  2547.      NOTES
  2548. 3    (4) A character_literal is an enumeration literal of a character type.
  2549.      See 3.5.2.
  2550.  
  2551.  
  2552.                                   Examples
  2553.  
  2554. 4   Examples of character literals:
  2555.  
  2556. 5   'A'     '*'     '''     ' '
  2557.  
  2558.  
  2559.                          Wording Changes From Ada 83
  2560.  
  2561.         5.a   The definitions of the values of literals are in Sections 3 and
  2562.         4, rather than here, since it requires knowledge of types.
  2563.  
  2564.  
  2565.  
  2566. 2.6 String Literals
  2567.  
  2568. 1   [A string_literal is formed by a sequence of graphic characters (possibly
  2569. none) enclosed between two quotation marks used as string brackets.  They are
  2570. used to represent operator_symbols (see 6.1), values of a string type (see
  2571. 4.2), and array subaggregates (see 4.3.3).  {quoted string: see string_
  2572. literal}]
  2573.  
  2574.  
  2575.                                    Syntax
  2576.  
  2577. 2   string_literal ::= "{string_element}"
  2578.  
  2579. 3   string_element ::= "" | non_quotation_mark_graphic_character
  2580.  
  2581.     4   A string_element is either a pair of quotation marks (""), or a
  2582.     single graphic_character other than a quotation mark.
  2583.  
  2584.  
  2585.                               Static Semantics
  2586.  
  2587. 5   {sequence of characters (of a string_literal)} The sequence of characters
  2588. of a string_literal is formed from the sequence of string_elements between
  2589. the bracketing quotation marks, in the given order, with a string_element
  2590. that is "" becoming a single quotation mark in the sequence of characters,
  2591. and any other string_element being reproduced in the sequence.
  2592.  
  2593. 6   {null string literal} A null string literal is a string_literal with no
  2594. string_elements between the quotation marks.
  2595.  
  2596.  
  2597.      NOTES
  2598. 7    (5) An end of line cannot appear in a string_literal.
  2599.  
  2600.  
  2601.                                   Examples
  2602.  
  2603. 8   Examples of string literals:
  2604.  
  2605. 9
  2606.     "Message of the day:"
  2607.  
  2608.     ""                           --  a null string literal
  2609.     " "   "A"   """"             --  three string literals of length 1
  2610.  
  2611.     "Characters such as $, %, and } are allowed in string literals"
  2612.  
  2613.  
  2614.                          Wording Changes From Ada 83
  2615.  
  2616.         9.a   The wording has been changed to be strictly lexical.  No
  2617.         mention is made of string or character values, since string_literals
  2618.         are also used to represent operator_symbols, which don't have a
  2619.         defined value.
  2620.  
  2621.         9.b   The syntax is described differently.
  2622.  
  2623.  
  2624.  
  2625. 2.7 Comments
  2626.  
  2627. 1   A comment starts with two adjacent hyphens and extends up to the end of
  2628. the line.
  2629.  
  2630.  
  2631.                                    Syntax
  2632.  
  2633. 2   comment ::= --{non_end_of_line_character}
  2634.  
  2635.     3   A comment may appear on any line of a program.
  2636.  
  2637.  
  2638.                               Static Semantics
  2639.  
  2640. 4   The presence or absence of comments has no influence on whether a program
  2641. is legal or illegal.  Furthermore, comments do not influence the meaning of a
  2642. program; their sole purpose is the enlightenment of the human reader.
  2643.  
  2644.  
  2645.                                   Examples
  2646.  
  2647. 5   Examples of comments:
  2648.  
  2649. 6   --  the last sentence above echoes the Algol 68 report
  2650.  
  2651.     end;  --  processing of Line is complete
  2652.  
  2653.     --  a long comment may be split onto
  2654.     --  two or more consecutive lines
  2655.  
  2656.     ----------------  the first two hyphens start the comment
  2657.  
  2658.  
  2659.  
  2660. 2.8 Pragmas
  2661.  
  2662. 1   {Pragma} [glossary entry]A pragma is a compiler directive.  There are
  2663. language-defined pragmas that give instructions for optimization, listing
  2664. control, etc.  An implementation may support additional (implementation-
  2665. defined) pragmas.
  2666.  
  2667.  
  2668.                                    Syntax
  2669.  
  2670. 2   pragma ::=
  2671.        pragma identifier [(pragma_argument_association {, pragma_argument_assoc\
  2672. iation})];
  2673.  
  2674. 3   pragma_argument_association ::=
  2675.          [pragma_argument_identifier =>] name
  2676.        | [pragma_argument_identifier =>] expression
  2677.  
  2678.     4   In a pragma, any pragma_argument_associations without a pragma_
  2679.     argument_identifier shall precede any associations with a pragma_
  2680.     argument_identifier.
  2681.  
  2682.     5   Pragmas are only allowed at the following places in a program:
  2683.  
  2684.         6  After a semicolon delimiter, but not within a formal_part or
  2685.            discriminant_part.
  2686.  
  2687.         7  At any place where the syntax rules allow a construct defined
  2688.            by a syntactic category whose name ends with "declaration",
  2689.            "statement", "clause", or "alternative", or one of the
  2690.            syntactic categories variant or exception_handler; but not in
  2691.            place of such a construct.  Also at any place where a
  2692.            compilation_unit would be allowed.
  2693.  
  2694.     8   Additional syntax rules and placement restrictions exist for specific
  2695.     pragmas.
  2696.  
  2697.  
  2698.         8.a   Discussion:  The above rule is written in text, rather than in
  2699.         BNF; the syntactic category pragma is not used in any BNF syntax
  2700.         rule.
  2701.  
  2702.         8.b   Ramification:  A pragma is allowed where a generic_formal_
  2703.         parameter_declaration is allowed.
  2704.  
  2705.  
  2706. 9   {name (of a pragma)} {pragma name} The name of a pragma is the identifier
  2707. following the reserved word pragma.  {pragma argument} {argument of a pragma}
  2708. The name or expression of a pragma_argument_association is a pragma argument.
  2709.  
  2710. 10   {identifier specific to a pragma} {pragma, identifier specific to} An
  2711. identifier specific to a pragma is an identifier that is used in a pragma
  2712. argument with special meaning for that pragma.
  2713.  
  2714.         10.a   To be honest:  Whenever the syntax rules for a given pragma
  2715.         allow "identifier" as an argument of the pragma, that identifier is
  2716.         an identifier specific to that pragma.
  2717.  
  2718.  
  2719.                               Static Semantics
  2720.  
  2721. 11   If an implementation does not recognize the name of a pragma, then it
  2722. has no effect on the semantics of the program.  Inside such a pragma, the
  2723. only rules that apply are the Syntax Rules.
  2724.  
  2725.         11.a   To be honest:  This rule takes precedence over any other rules
  2726.         that imply otherwise.
  2727.  
  2728.         11.b   Ramification:  Note well: this rule applies only to pragmas
  2729.         whose name is not recognized.  If anything else is wrong with a
  2730.         pragma (at compile time), the pragma is illegal.  This is true
  2731.         whether the pragma is language defined or implementation defined.
  2732.  
  2733.         11.c   For example, an expression in an unrecognized pragma does not
  2734.         cause freezing, even though the rules in 13.14, ``Freezing Rules''
  2735.         say it does; the above rule overrules those other rules.  On the
  2736.         other hand, an expression in a recognized pragma causes freezing,
  2737.         even if this makes something illegal.
  2738.  
  2739.         11.d   For another example, an expression that would be ambiguous is
  2740.         not illegal if it is inside an unrecognized pragma.
  2741.  
  2742.         11.e   Note, however, that implementations have to recognize pragma
  2743.         Inline(Foo) and freeze things accordingly, even if they choose to
  2744.         never do inlining.
  2745.  
  2746.         11.f   Obviously, the contradiction needs to be resolved one way or
  2747.         the other.  The reasons for resolving it this way are:  The
  2748.         implementation is simple -- the compiler can just ignore the pragma
  2749.         altogether.  The interpretation of constructs appearing inside
  2750.         implementation-defined pragmas is implementation defined.  For
  2751.         example: ``pragma Mumble(X);''.  If the current implementation has
  2752.         never heard of Mumble, then it doesn't know whether X is a name, an
  2753.         expression, or an identifier specific to the pragma Mumble.
  2754.  
  2755.         11.g   To be honest:  The syntax of individual pragmas overrides the
  2756.         general syntax for pragma.
  2757.  
  2758.         11.h   Ramification:  Thus, an identifier specific to a pragma is not
  2759.         a name, syntactically; if it were, the visibility rules would be
  2760.         invoked, which is not what we want.
  2761.  
  2762.         11.i   This also implies that named associations do not allow one to
  2763.         give the arguments in an arbitrary order -- the order given in the
  2764.         syntax rule for each individual pragma must be obeyed.  However, it
  2765.         is generally possible to leave out earlier arguments when later ones
  2766.         are given; for example, this is allowed by the syntax rule for pragma
  2767.         Import (see B.1, ``Interfacing Pragmas'').  As for subprogram calls,
  2768.         positional notation precedes named notation.
  2769.  
  2770.         11.j   Note that Ada 83 had no pragmas for which the order of named
  2771.         associations mattered, since there was never more than one argument
  2772.         that allowed named associations.
  2773.  
  2774.         11.k   To be honest:  The interpretation of the arguments of
  2775.         implementation-defined pragmas is implementation defined.  However,
  2776.         the syntax rules have to be obeyed.
  2777.  
  2778.  
  2779.                               Dynamic Semantics
  2780.  
  2781. 12   {execution [pragma]} {elaboration [pragma]} Any pragma that appears at
  2782. the place of an executable construct is executed.  Unless otherwise specified
  2783. for a particular pragma, this execution consists of the evaluation of each
  2784. evaluable pragma argument in an arbitrary order.
  2785.  
  2786.         12.a   Ramification:  For a pragma that appears at the place of an
  2787.         elaborable construct, execution is elaboration.
  2788.  
  2789.         12.b   An identifier specific to a pragma is neither a name nor an
  2790.         expression -- such identifiers are not evaluated (unless an
  2791.         implementation defines them to be evaluated in the case of an
  2792.         implementation-defined pragma).
  2793.  
  2794.         12.c   The ``unless otherwise specified'' part allows us (and
  2795.         implementations) to make exceptions, so a pragma can contain an
  2796.         expression that is not evaluated.  Note that pragmas in type_
  2797.         definitions may contain expressions that depend on discriminants.
  2798.  
  2799.         12.d   When we wish to define a pragma with some run-time effect, we
  2800.         usually make sure that it appears in an executable context;
  2801.         otherwise, special rules are needed to define the run-time effect and
  2802.         when it happens.
  2803.  
  2804.  
  2805.                          Implementation Requirements
  2806.  
  2807. 13   The implementation shall give a warning message for an unrecognized
  2808. pragma name.
  2809.  
  2810.         13.a   Ramification:  An implementation is also allowed to have modes
  2811.         in which a warning message is suppressed, or in which the presence of
  2812.         an unrecognized pragma is a compile-time error.
  2813.  
  2814.  
  2815.                          Implementation Permissions
  2816.  
  2817. 14   An implementation may provide implementation-defined pragmas; the name
  2818. of an implementation-defined pragma shall differ from those of the
  2819. language-defined pragmas.
  2820.  
  2821.         14.a   Implementation defined:  Implementation-defined pragmas.
  2822.  
  2823.         14.b   Ramification:  The semantics of implementation-defined
  2824.         pragmas, and any associated rules (such as restrictions on their
  2825.         placement or arguments), are, of course, implementation defined.
  2826.         Implementation-defined pragmas may have run-time effects.
  2827.  
  2828. 15   An implementation may ignore an unrecognized pragma even if it violates
  2829. some of the Syntax Rules, if detecting the syntax error is too complex.
  2830.  
  2831.         15.a   Reason:  Many compilers use extra post-parsing checks to
  2832.         enforce the syntax rules, since the Ada syntax rules are not LR(k)
  2833.         (for any k).  (The grammar is ambiguous, in fact.)  This paragraph
  2834.         allows them to ignore an unrecognized pragma, without having to
  2835.         perform such post-parsing checks.
  2836.  
  2837.  
  2838.                             Implementation Advice
  2839.  
  2840. 16   Normally, implementation-defined pragmas should have no semantic effect
  2841. for error-free programs; that is, if the implementation-defined pragmas are
  2842. removed from a working program, the program should still be legal, and should
  2843. still have the same semantics.
  2844.  
  2845.         16.a   Ramification:  Note that ``semantics'' is not the same as
  2846.         ``effect;'' as explained in 1.1.3, the semantics defines a set of
  2847.         possible effects.
  2848.  
  2849.         16.b   Note that adding a pragma to a program might cause an error
  2850.         (either at compile time or at run time).  On the other hand, if the
  2851.         language-specified semantics for a feature are in part implementation
  2852.         defined, it makes sense to support pragmas that control the feature,
  2853.         and that have real semantics; thus, this paragraph is merely a
  2854.         recommendation.
  2855.  
  2856. 17   Normally, an implementation should not define pragmas that can make an
  2857. illegal program legal, except as follows:
  2858.  
  2859.    18  A pragma used to complete a declaration, such as a pragma Import;
  2860.  
  2861.    19  A pragma used to configure the environment by adding, removing,
  2862.        or replacing library_items.
  2863.  
  2864.         19.a   Ramification:  For example, it is OK to support Interface,
  2865.         System_Name, Storage_Unit, and Memory_Size pragmas for upward
  2866.         compatibility reasons, even though all of these pragmas can make an
  2867.         illegal program legal.  (The latter three can affect legality in a
  2868.         rather subtle way:  They affect the value of named numbers in System,
  2869.         and can therefore affect the legality in cases where static
  2870.         expressions are required.)
  2871.  
  2872.         19.b   On the other hand, adding implementation-defined pragmas to a
  2873.         legal program can make it illegal.  For example, a common kind of
  2874.         implementation-defined pragma is one that promises some property that
  2875.         allows more efficient code to be generated.  If the promise is a lie,
  2876.         it is best if the user gets an error message.
  2877.  
  2878.  
  2879.                         Incompatibilities With Ada 83
  2880.  
  2881.         19.c   {incompatibilities with Ada 83} In Ada 83, ``bad'' pragmas are
  2882.         ignored.  In Ada 9X, they are illegal, except in the case where the
  2883.         name of the pragma itself is not recognized by the implementation.
  2884.  
  2885.                             Extensions to Ada 83
  2886.  
  2887.         19.d   {extensions to Ada 83} Implementation-defined pragmas may
  2888.         affect the legality of a program.
  2889.                          Wording Changes From Ada 83
  2890.  
  2891.         19.e   Implementation-defined pragmas may affect the run-time
  2892.         semantics of the program.  This was always true in Ada 83 (since it
  2893.         was not explicitly forbidden by RM83), but it was not clear, because
  2894.         there was no definition of ``executing'' or ``elaborating'' a pragma.
  2895.  
  2896.                                    Syntax
  2897.  
  2898.     20   The forms of List, Page, and Optimize pragmas are as follows:
  2899.  
  2900.  
  2901. 21    pragma List(identifier);
  2902.  
  2903. 22    pragma Page;
  2904.  
  2905. 23    pragma Optimize(identifier);
  2906.  
  2907.     24   [Other pragmas are defined throughout this International Standard,
  2908.     and are summarized in Annex L.]
  2909.  
  2910.         24.a   Ramification:  The language-defined pragmas are supported by
  2911.         every implementation, although ``supporting'' some of them (for
  2912.         example, Inline) requires nothing more than checking the arguments,
  2913.         since they act only as advice to the implementation.
  2914.  
  2915.  
  2916.                               Static Semantics
  2917.  
  2918. 25   A pragma List takes one of the identifiers On or Off as the single
  2919. argument.  This pragma is allowed anywhere a pragma is allowed.  It specifies
  2920. that listing of the compilation is to be continued or suspended until a List
  2921. pragma with the opposite argument is given within the same compilation.  The
  2922. pragma itself is always listed if the compiler is producing a listing.
  2923.  
  2924. 26   A pragma Page is allowed anywhere a pragma is allowed.  It specifies
  2925. that the program text which follows the pragma should start on a new page (if
  2926. the compiler is currently producing a listing).
  2927.  
  2928. 27   A pragma Optimize takes one of the identifiers Time, Space, or Off as
  2929. the single argument.  This pragma is allowed anywhere a pragma is allowed,
  2930. and it applies until the end of the immediately enclosing declarative region,
  2931. or for a pragma at the place of a compilation_unit, to the end of the
  2932. compilation.  {94-4761.d} It gives advice to the implementation as to whether
  2933. time or space is the primary optimization criterion, or that optional
  2934. optimizations should be turned off.  [It is implementation defined how this
  2935. advice is followed.]
  2936.  
  2937.         27.a   Implementation defined:  Effect of pragma Optimize.
  2938.  
  2939.         27.b   Discussion:  For example, a compiler might use Time vs. Space
  2940.         to control whether generic instantiations are implemented with a
  2941.         macro-expansion model, versus a shared-generic-body model.
  2942.  
  2943.         27.c   We don't define what constitutes an ``optimization'' -- in
  2944.         fact, it cannot be formally defined in the context of Ada.  One
  2945.         compiler might call something an optional optimization, whereas
  2946.         another compiler might consider that same thing to be a normal part
  2947.         of code generation.  Thus, the programmer cannot rely on this pragma
  2948.         having any particular portable effect on the generated code.  Some
  2949.         compilers might even ignore the pragma altogether.
  2950.  
  2951.  
  2952.                                   Examples
  2953.  
  2954. 28   Examples of pragmas:
  2955.  
  2956. 29  pragma List(Off); -- turn off listing generation
  2957.     pragma Optimize(Off); -- turn off optional optimizations
  2958.     pragma Inline(Set_Mask); -- generate code for Set_Mask inline
  2959.     pragma Suppress(Range_Check, On => Index); -- turn off range checking on In\
  2960. dex
  2961.  
  2962.  
  2963.                             Extensions to Ada 83
  2964.  
  2965.         29.a   {extensions to Ada 83} The Optimize pragma now allows the
  2966.         identifier Off to request that normal optimization be turned off.
  2967.  
  2968.         29.b   An Optimize pragma may appear anywhere pragmas are allowed.
  2969.  
  2970.                          Wording Changes From Ada 83
  2971.  
  2972.         29.c   We now describe the pragmas Page, List, and Optimize here, to
  2973.         act as examples, and to remove the normative material from Annex L,
  2974.         ``Language-Defined Pragmas'', so it can be entirely an informative
  2975.         annex.
  2976. 2.9 Reserved Words
  2977.  
  2978.                                    Syntax
  2979.  
  2980. 1
  2981.     2   {reserved word} The following are the reserved words (ignoring
  2982.     upper/lower case distinctions):
  2983.  
  2984.  
  2985.         2.a   Discussion:  Reserved words have special meaning in the syntax.
  2986.         In addition, certain reserved words are used as attribute names.
  2987.  
  2988.         2.b   The syntactic category identifier no longer allows reserved
  2989.         words.  We have added the few reserved words that are legal
  2990.         explicitly to the syntax for attribute_reference.  Allowing
  2991.         identifier to include reserved words has been a source of confusion
  2992.         for some users, and differs from the way they are treated in the C
  2993.         and Pascal language definitions.
  2994.  
  2995.  
  2996.      abort          else           new            return
  2997.      abs            elsif          not            reverse
  2998.      abstract       end            null
  2999.      accept         entry                         select
  3000.      access         exception                     separate
  3001.      aliased        exit           of             subtype
  3002.      all                           or
  3003.      and            for            others         tagged
  3004.      array          function       out            task
  3005.      at                                           terminate
  3006.                     generic        package        then
  3007.      begin          goto           pragma         type
  3008.      body                          private
  3009.                     if             procedure
  3010.      case           in             protected      until
  3011.      constant       is                            use
  3012.                                    raise
  3013.      declare                       range          when
  3014.      delay          limited        record         while
  3015.      delta          loop           rem            with
  3016.      digits                        renames
  3017.      do             mod            requeue        xor
  3018.  
  3019.  
  3020.      NOTES
  3021. 3    (6) The reserved words appear in lower case boldface in this
  3022.      International Standard, except when used in the designator of an
  3023.      attribute (see 4.1.4).  Lower case boldface is also used for a reserved
  3024.      word in a string_literal used as an operator_symbol.  This is merely a
  3025.      convention -- programs may be written in whatever typeface is desired
  3026.      and available.  {94-4493.d}
  3027.  
  3028.  
  3029.                         Incompatibilities With Ada 83
  3030.  
  3031.         3.a   {incompatibilities with Ada 83} The following words are not
  3032.         reserved in Ada 83, but are reserved in Ada 9X: abstract, aliased,
  3033.         protected, requeue, tagged, until.
  3034.  
  3035.                          Wording Changes From Ada 83
  3036.  
  3037.         3.b   The clause entitled ``Allowed Replacements of Characters'' has
  3038.         been moved to Annex J, ``Obsolescent Features''.
  3039.  
  3040.  
  3041.  
  3042.                       Section 3: Declarations and Types
  3043.  
  3044.  
  3045. 1   This section describes the types in the language and the rules for
  3046. declaring constants, variables, and named numbers.
  3047.  
  3048.  
  3049.  
  3050. 3.1 Declarations
  3051.  
  3052. 1   {entity [partial]} The language defines several kinds of named entities
  3053. that are declared by declarations.  {name [partial]} The entity's name is
  3054. defined by the declaration, usually by a defining_identifier, but sometimes
  3055. by a defining_character_literal or defining_operator_symbol.
  3056.  
  3057. 2   There are several forms of declaration.  A basic_declaration is a form of
  3058. declaration defined as follows.
  3059.  
  3060.  
  3061.                                    Syntax
  3062.  
  3063. 3   basic_declaration ::=
  3064.          type_declaration                 | subtype_declaration
  3065.        | object_declaration               | number_declaration
  3066.        | subprogram_declaration           | abstract_subprogram_declaration
  3067.        | package_declaration              | renaming_declaration
  3068.        | exception_declaration            | generic_declaration
  3069.        | generic_instantiation
  3070.  
  3071. 4   defining_identifier ::= identifier
  3072.  
  3073.  
  3074.                               Static Semantics
  3075.  
  3076. 5   {Declaration} [glossary entry]A declaration is a language construct that
  3077. associates a name with (a view of) an entity.  {explicit declaration}
  3078. {implicit declaration} A declaration may appear explicitly in the program
  3079. text (an explicit declaration), or may be supposed to occur at a given place
  3080. in the text as a consequence of the semantics of another construct (an
  3081. implicit declaration).
  3082.  
  3083.         5.a   Discussion:  An implicit declaration generally declares a
  3084.         predefined or inherited operation associated with the definition of a
  3085.         type.  This term is used primarily when allowing explicit
  3086.         declarations to override implicit declarations, as part of a type
  3087.         declaration.
  3088.  
  3089. 6   {declaration} Each of the following is defined to be a declaration:  any
  3090. basic_declaration; an enumeration_literal_specification; a discriminant_
  3091. specification; a component_declaration; a loop_parameter_specification; a
  3092. parameter_specification; a subprogram_body; an entry_declaration; an entry_
  3093. index_specification; a choice_parameter_specification; a generic_formal_
  3094. parameter_declaration.
  3095.  
  3096.         6.a   Discussion:  This list (when basic_declaration is expanded out)
  3097.         contains all syntactic categories that end in "_declaration" or
  3098.         "_specification", except for program unit _specifications.  Moreover,
  3099.         it contains subprogram_body.  A subprogram_body is a declaration,
  3100.         whether or not it completes a previous declaration.  This is a bit
  3101.         strange, subprogram_body is not part of the syntax of basic_
  3102.         declaration or library_unit_declaration.  A renaming-as-body is
  3103.         considered a declaration.  An accept_statement is not considered a
  3104.         declaration.  Completions are sometimes declarations, and sometimes
  3105.         not.
  3106.  
  3107. 7   {Definition} [glossary entry]{view} All declarations contain a definition
  3108. for a view of an entity.  A view consists of an identification of the entity
  3109. (the entity of the view), plus view-specific characteristics that affect the
  3110. use of the entity through that view (such as mode of access to an object,
  3111. formal parameter names and defaults for a subprogram, or visibility to
  3112. components of a type).  In most cases, a declaration also contains the
  3113. definition for the entity itself (a renaming_declaration is an example of a
  3114. declaration that does not define a new entity, but instead defines a view of
  3115. an existing entity (see 8.5)).
  3116.  
  3117.         7.a   Glossary entry:  {View} (See Definition.)
  3118.  
  3119.         7.b   Discussion:  Most declarations define a view (of some entity)
  3120.         whose view-specific characteristics are unchanging for the life of
  3121.         the view.  However, subtypes are somewhat unusual in that they
  3122.         inherit characteristics from whatever view of their type is currently
  3123.         visible.  Hence, a subtype is not a view of a type; it is more of an
  3124.         indirect reference.  By contrast, a private type provides a single,
  3125.         unchanging (partial) view of its full type.
  3126.  
  3127. 8   {scope [informal definition]} For each declaration, the language rules
  3128. define a certain region of text called the scope of the declaration (see
  3129. 8.2).  Most declarations associate an identifier with a declared entity.
  3130. Within its scope, and only there, there are places where it is possible to
  3131. use the identifier to refer to the declaration, the view it defines, and the
  3132. associated entity; these places are defined by the visibility rules (see
  3133. 8.3).  {name (of (a view of) an entity)} At such places the identifier is
  3134. said to be a name of the entity (the direct_name or selector_name); {denote
  3135. [informal definition]} the name is said to denote the declaration, the view,
  3136. and the associated entity (see 8.6).  {declare} The declaration is said to
  3137. declare the name, the view, and in most cases, the entity itself.
  3138.  
  3139. 9   As an alternative to an identifier, an enumeration literal can be
  3140. declared with a character_literal as its name (see 3.5.1), and a function can
  3141. be declared with an operator_symbol as its name (see 6.1).
  3142.  
  3143. 10   {defining name} The syntax rules use the terms defining_identifier,
  3144. defining_character_literal, and defining_operator_symbol for the defining
  3145. occurrence of a name; these are collectively called defining names.  {usage
  3146. name} The terms direct_name and selector_name are used for usage occurrences
  3147. of identifiers, character_literals, and operator_symbols.  These are
  3148. collectively called usage names.
  3149.  
  3150.         10.a   To be honest:  The terms identifier, character_literal, and
  3151.         operator_symbol are used directly in contexts where the normal
  3152.         visibility rules do not apply (such as the identifier that appears
  3153.         after the end of a task_body).  Analogous conventions apply to the
  3154.         use of designator, which is the collective term for identifier and
  3155.         operator_symbol.
  3156.  
  3157.  
  3158.                               Dynamic Semantics
  3159.  
  3160. 11   {execution [distributed]} The process by which a construct achieves its
  3161. run-time effect is called execution.  {elaboration [distributed]} {evaluation
  3162. [distributed]} This process is also called elaboration for declarations and
  3163. evaluation for expressions.  One of the terms execution, elaboration, or
  3164. evaluation is defined by this International Standard for each construct that
  3165. has a run-time effect.
  3166.  
  3167.         11.a   Glossary entry:  {Execution} The process by which a construct
  3168.         achieves its run-time effect is called execution.  {elaboration}
  3169.         {evaluation} Execution of a declaration is also called elaboration.
  3170.         Execution of an expression is also called evaluation.
  3171.  
  3172.         11.b   To be honest:  The term elaboration is also used for the
  3173.         execution of certain constructs that are not declarations, and the
  3174.         term evaluation is used for the execution of certain constructs that
  3175.         are not expressions.  For example, subtype_indications are
  3176.         elaborated, and ranges are evaluated.
  3177.  
  3178.         11.c   For bodies, execution and elaboration are both explicitly
  3179.         defined.  When we refer specifically to the execution of a body, we
  3180.         mean the explicit definition of execution for that kind of body, not
  3181.         its elaboration.
  3182.  
  3183.         11.d   Discussion:  Technically, "the execution of a declaration" and
  3184.         "the elaboration of a declaration" are synonymous.  We use the term
  3185.         "elaboration" of a construct when we know the construct is
  3186.         elaborable.  When we are talking about more arbitrary constructs, we
  3187.         use the term "execution".  For example, we use the term "erroneous
  3188.         execution", to refer to any erroneous execution, including erroneous
  3189.         elaboration or evaluation.
  3190.  
  3191.         11.e   When we explicitly define evaluation or elaboration for a
  3192.         construct, we are implicitly defining execution of that construct.
  3193.  
  3194.         11.f   We also use the term "execution" for things like statements,
  3195.         which are executable, but neither elaborable nor evaluable.  We
  3196.         considered using the term "execution" only for non-elaborable,
  3197.         non-evaluable constructs, and defining the term "action" to mean what
  3198.         we have defined "execution" to mean.  We rejected this idea because
  3199.         we thought three terms that mean the same thing was enough -- four
  3200.         would be overkill.  Thus, the term "action" is used only informally
  3201.         in the standard (except where it is defined as part of a larger term,
  3202.         such as "protected action").
  3203.  
  3204.         11.g   To be honest:  {elaborable} A construct is elaborable if
  3205.         elaboration is defined for it.  {evaluable} A construct is evaluable
  3206.         if evaluation is defined for it.  {executable} A construct is
  3207.         executable if execution is defined for it.
  3208.  
  3209.         11.h   Discussion:  Don't confuse ``elaborable'' with
  3210.         ``preelaborable'' (defined in 10.2.1).
  3211.  
  3212.         11.i   Evaluation of an evaluable construct produces a result that is
  3213.         either a value, a denotation, or a range.  The following are
  3214.         evaluable:  expression; name prefix; range; entry_list_iterator; and
  3215.         possibly discrete_range.  The last one is curious -- RM83 uses the
  3216.         term ``evaluation of a discrete_range,'' but never defines it.  One
  3217.         might presume that the evaluation of a discrete_range consists of the
  3218.         evaluation of the range or the subtype_indication, depending on what
  3219.         it is.  But subtype_indications are not evaluated; they are
  3220.         elaborated.
  3221.  
  3222.         11.j   Intuitively, an executable construct is one that has a defined
  3223.         run-time effect (which may be null).  Since execution includes
  3224.         elaboration and evaluation as special cases, all elaborable and all
  3225.         evaluable constructs are also executable.  Hence, most constructs in
  3226.         Ada are executable.  An important exception is that the constructs
  3227.         inside a generic unit are not executable directly, but rather are
  3228.         used as a template for (generally) executable constructs in instances
  3229.         of the generic.
  3230.  
  3231.  
  3232.      NOTES
  3233. 12   (1) {declare} At compile time, the declaration of an entity declares the
  3234.      entity.  {create} At run time, the elaboration of the declaration
  3235.      creates the entity.
  3236.  
  3237.    12.a   Ramification:  Syntactic categories for declarations are named
  3238.         either entity_declaration (if they include a trailing semicolon) or
  3239.         entity_specification (if not).
  3240.  
  3241.    12.b   {entity} The various kinds of named entities that can be declared
  3242.         are as follows: an object (including components and parameters), a
  3243.         named number, a type (the name always refers to its first subtype), a
  3244.         subtype, a subprogram (including enumeration literals and operators),
  3245.         a single entry, an entry family, a package, a protected or task unit
  3246.         (which corresponds to either a type or a single object), an
  3247.         exception, a generic unit, a label, and the name of a statement.
  3248.  
  3249.    12.c   Identifiers are also associated with names of pragmas, arguments to
  3250.         pragmas, and with attributes, but these are not user-definable.
  3251.  
  3252.  
  3253.                          Wording Changes From Ada 83
  3254.  
  3255.         12.d   The syntax rule for defining_identifier is new.  It is used
  3256.         for the defining occurrence of an identifier.  Usage occurrences use
  3257.         the direct_name or selector_name syntactic categories.  Each
  3258.         occurrence of an identifier (or simple_name), character_literal, or
  3259.         operator_symbol in the Ada 83 syntax rules is handled as follows in
  3260.         Ada 9X:
  3261.  
  3262.          12.e  It becomes a defining_identifier, defining_character_
  3263.                literal, or defining_operator_symbol (or some syntactic
  3264.                category composed of these), to indicate a defining
  3265.                occurrence;
  3266.  
  3267.          12.f  It becomes a direct_name, in usage occurrences where the
  3268.                usage is required (in Section 8) to be directly visible;
  3269.  
  3270.          12.g  It becomes a selector_name, in usage occurrences where
  3271.                the usage is required (in Section 8) to be visible but
  3272.                not necessarily directly visible;
  3273.  
  3274.          12.h  It remains an identifier, character_literal, or operator_
  3275.                symbol, in cases where the visibility rules do not apply
  3276.                (such as the designator that appears after the end of a
  3277.                subprogram_body).
  3278.  
  3279.         12.i   For declarations that come in ``two parts'' (program unit
  3280.         declaration plus body, private or incomplete type plus full type,
  3281.         deferred constant plus full constant), we consider both to be
  3282.         defining occurrences.  Thus, for example, the syntax for package_body
  3283.         uses defining_identifier after the reserved word body, as opposed to
  3284.         direct_name.
  3285.  
  3286.         12.j   The defining occurrence of a statement name is in its implicit
  3287.         declaration, not where it appears in the program text.  Considering
  3288.         the statement name itself to be the defining occurrence would
  3289.         complicate the visibility rules.
  3290.  
  3291.         12.k   The phrase ``visible by selection'' is not used in Ada 9X.  It
  3292.         is subsumed by simply ``visible'' and the Name Resolution Rules for
  3293.         selector_names.
  3294.  
  3295.         12.l   (Note that in Ada 9X, a declaration is visible at all places
  3296.         where one could have used a selector_name, not just at places where a
  3297.         selector_name was actually used.  Thus, the places where a
  3298.         declaration is directly visible are a subset of the places where it
  3299.         is visible.  See Section 8 for details.)
  3300.  
  3301.         12.m   We use the term ``declaration'' to cover _specifications that
  3302.         declare (views of) objects, such as parameter_specifications.  In Ada
  3303.         83, these are referred to as a ``form of declaration,'' but it is not
  3304.         entirely clear that they are considered simply ``declarations.''
  3305.  
  3306.         12.n   RM83 contains an incomplete definition of "elaborated" in this
  3307.         clause:  it defines "elaborated" for declarations, declarative_parts,
  3308.         declarative_items and compilation_units, but "elaboration" is defined
  3309.         elsewhere for various other constructs.  To make matters worse, Ada
  3310.         9X has a different set of elaborable constructs.  Instead of
  3311.         correcting the list, it is more maintainable to refer to the term
  3312.         "elaborable," which is defined in a distributed manner.
  3313.  
  3314.         12.o   RM83 uses the term ``has no other effect'' to describe an
  3315.         elaboration that doesn't do anything except change the state from
  3316.         not-yet-elaborated to elaborated.  This was a confusing wording,
  3317.         because the answer to ``other than what?'' was to be found many pages
  3318.         away.  In Ada 9X, we change this wording to ``has no effect'' (for
  3319.         things that truly do nothing at run time), and ``has no effect other
  3320.         than to establish that so-and-so can happen without failing the
  3321.         Elaboration_Check'' (for things where it matters).
  3322.  
  3323.         12.p   We make it clearer that the term "execution" covers
  3324.         elaboration and evaluation as special cases.  This was implied in
  3325.         RM83.  For example, "erroneous execution" can include any execution,
  3326.         and RM83-9.4(3) has, "The task designated by any other task object
  3327.         depends on the master whose execution creates the task object;" the
  3328.         elaboration of the master's declarative_part is doing the task
  3329.         creation.
  3330.  
  3331.  
  3332.  
  3333. 3.2 Types and Subtypes
  3334.  
  3335.                               Static Semantics
  3336.  
  3337. 1   {type} {primitive operation [partial]} A type is characterized by a set
  3338. of values, and a set of primitive operations which implement the fundamental
  3339. aspects of its semantics.  {object [partial]} An object of a given type is a
  3340. run-time entity that contains (has) a value of the type.
  3341.  
  3342.         1.a   Glossary entry:  {Type} Each object has a type.  A type has an
  3343.         associated set of values, and a set of primitive operations which
  3344.         implement the fundamental aspects of its semantics.  Types are
  3345.         grouped into classes.  The types of a given class share a set of
  3346.         primitive operations.  {closed under derivation} Classes are closed
  3347.         under derivation; that is, if a type is in a class, then all of its
  3348.         derivatives are in that class.
  3349.  
  3350.         1.b   Glossary entry:  {Subtype} A subtype is a type together with a
  3351.         constraint, which constrains the values of the subtype to satisfy a
  3352.         certain condition.  The values of a subtype are a subset of the
  3353.         values of its type.
  3354.  
  3355. 2   {class (of types)} Types are grouped into classes of types, reflecting
  3356. the similarity of their values and primitive operations.  {language-defined
  3357. class (of types)} There exist several language-defined classes of types (see
  3358. NOTES below).  {elementary type} Elementary types are those whose values are
  3359. logically indivisible; {composite type} {component} composite types are those
  3360. whose values are composed of component values.  {aggregate: see also
  3361. composite type}
  3362.  
  3363.         2.a   Glossary entry:  {Class} {closed under derivation} A class is a
  3364.         set of types that is closed under derivation, which means that if a
  3365.         given type is in the class, then all types derived from that type are
  3366.         also in the class.  The set of types of a class share common
  3367.         properties, such as their primitive operations.
  3368.  
  3369.         2.b   Glossary entry:  {Elementary type} An elementary type does not
  3370.         have components.
  3371.  
  3372.         2.c   Glossary entry:  {Composite type} A composite type has
  3373.         components.
  3374.         2.d   Glossary entry:  {Scalar type} A scalar type is either a
  3375.         discrete type or a real type.
  3376.  
  3377.         2.e   Glossary entry:  {Access type} An access type has values that
  3378.         designate aliased objects.  Access types correspond to ``pointer
  3379.         types'' or ``reference types'' in some other languages.
  3380.  
  3381.         2.f   Glossary entry:  {Discrete type} A discrete type is either an
  3382.         integer type or an enumeration type.  Discrete types may be used, for
  3383.         example, in case_statements and as array indices.
  3384.  
  3385.         2.g   Glossary entry:  {Real type} A real type has values that are
  3386.         approximations of the real numbers.  Floating point and fixed point
  3387.         types are real types.
  3388.  
  3389.         2.h   Glossary entry:  {Integer type} Integer types comprise the
  3390.         signed integer types and the modular types.  A signed integer type
  3391.         has a base range that includes both positive and negative numbers,
  3392.         and has operations that may raise an exception when the result is
  3393.         outside the base range.  A modular type has a base range whose lower
  3394.         bound is zero, and has operations with ``wraparound'' semantics.
  3395.         Modular types subsume what are called ``unsigned types'' in some
  3396.         other languages.
  3397.  
  3398.         2.i   Glossary entry:  {Enumeration type} An enumeration type is
  3399.         defined by an enumeration of its values, which may be named by
  3400.         identifiers or character literals.
  3401.  
  3402.         2.j   Glossary entry:  {Character type} A character type is an
  3403.         enumeration type whose values include characters.
  3404.  
  3405.         2.k   Glossary entry:  {Record type} A record type is a composite
  3406.         type consisting of zero or more named components, possibly of
  3407.         different types.
  3408.  
  3409.         2.l   Glossary entry:  {Record extension} A record extension is a
  3410.         type that extends another type by adding additional components.
  3411.  
  3412.         2.m   Glossary entry:  {Array type} An array type is a composite type
  3413.         whose components are all of the same type.  Components are selected
  3414.         by indexing.
  3415.  
  3416.         2.n   Glossary entry:  {Task type} A task type is a composite type
  3417.         whose values are tasks, which are active entities that may execute
  3418.         concurrently with other tasks.  The top-level task of a partition is
  3419.         called the environment task.
  3420.  
  3421.         2.o   Glossary entry:  {Protected type} A protected type is a
  3422.         composite type whose components are protected from concurrent access
  3423.         by multiple tasks.
  3424.  
  3425.         2.p   Glossary entry:  {Private type} A private type is a partial
  3426.         view of a type whose full view is hidden from its clients.
  3427.  
  3428.         2.q   Glossary entry:  {Private extension} A private extension is
  3429.         like a record extension, except that the components of the extension
  3430.         part are hidden from its clients.
  3431.  
  3432. 3   {scalar type} The elementary types are the scalar types (discrete and
  3433. real) and the access types (whose values provide access to objects or
  3434. subprograms).  {discrete type} {enumeration type} Discrete types are either
  3435. integer types or are defined by enumeration of their values (enumeration
  3436. types).  {real type} Real types are either floating point types or fixed
  3437. point types.
  3438.  
  3439. 4   The composite types are the record types, record extensions, array types,
  3440. task types, and protected types.  {private type} {private extension} A
  3441. private type or private extension represents a partial view (see 7.3) of a
  3442. type, providing support for data abstraction.  A partial view is a composite
  3443. type.
  3444.  
  3445.         4.a   To be honest:  The set of all record types do not form a class
  3446.         (because tagged record types can have private extensions), though the
  3447.         set of untagged record types do.  In any case, what record types had
  3448.         in common in Ada 83 (component selection) is now a property of the
  3449.         composite class, since all composite types (other than array types)
  3450.         can have discriminants.  Similarly, the set of all private types do
  3451.         not form a class (because tagged private types can have record
  3452.         extensions), though the set of untagged private types do.
  3453.         Nevertheless, the set of untagged private types is not particularly
  3454.         ``interesting'' -- more interesting is the set of all nonlimited
  3455.         types, since that is what a generic formal (nonlimited) private type
  3456.         matches.
  3457.  
  3458. 5   {discriminant} Certain composite types (and partial views thereof) have
  3459. special components called discriminants whose values affect the presence,
  3460. constraints, or initialization of other components.  Discriminants can be
  3461. thought of as parameters of the type.
  3462.  
  3463. 6   {subcomponent} The term subcomponent is used in this International
  3464. Standard in place of the term component to indicate either a component, or a
  3465. component of another subcomponent.  Where other subcomponents are excluded,
  3466. the term component is used instead.  {part (of an object or value)}
  3467. Similarly, a part of an object or value is used to mean the whole object or
  3468. value, or any set of its subcomponents.
  3469.  
  3470.         6.a   Discussion:  The definition of ``part'' here is designed to
  3471.         simplify rules elsewhere.  By design, the intuitive meaning of
  3472.         ``part'' will convey the correct result to the casual reader, while
  3473.         this formalistic definition will answer the concern of the
  3474.         compiler-writer.
  3475.  
  3476.         6.b   We use the term ``part'' when talking about the parent part,
  3477.         ancestor part, or extension part of a type extension.  In contexts
  3478.         such as these, the part might represent an empty set of subcomponents
  3479.         (e.g. in a null record extension, or a nonnull extension of a null
  3480.         record).  We also use ``part'' when specifying rules such as those
  3481.         that apply to an object with a ``controlled part'' meaning that it
  3482.         applies if the object as a whole is controlled, or any subcomponent
  3483.         is.
  3484.  
  3485. 7   {constraint [partial]} The set of possible values for an object of a
  3486. given type can be subjected to a condition that is called a constraint {null
  3487. constraint} (the case of a null constraint that specifies no restriction is
  3488. also included)[; the rules for which values satisfy a given kind of
  3489. constraint are given in 3.5 for range_constraints, 3.6.1 for index_
  3490. constraints, and 3.7.1 for discriminant_constraints].
  3491.  
  3492. 8   {subtype} A subtype of a given type is a combination of the type, a
  3493. constraint on values of the type, and certain attributes specific to the
  3494. subtype.  The given type is called the type of the subtype.  Similarly, the
  3495. associated constraint is called the constraint of the subtype.  The set of
  3496. values of a subtype consists of the values of its type that satisfy its
  3497. constraint.  {belong (to a subtype)} Such values belong to the subtype.
  3498.  
  3499.         8.a   Discussion:  We make a strong distinction between a type and
  3500.         its subtypes.  In particular, a type is not a subtype of itself.
  3501.         There is no constraint associated with a type (not even a null one),
  3502.         and type-related attributes are distinct from subtype-specific
  3503.         attributes.
  3504.  
  3505.         8.b   Discussion:  We no longer use the term "base type."  All types
  3506.         were "base types" anyway in Ada 83, so the term was redundant, and
  3507.         occasionally confusing.  In the RM9X we say simply "the type of the
  3508.         subtype" instead of "the base type of the subtype."
  3509.  
  3510.         8.c   Ramification:  The value subset for a subtype might be empty,
  3511.         and need not be a proper subset.
  3512.  
  3513.         8.d   To be honest:  Any name of a class of types (such as
  3514.         ``discrete'' or ``real''), or other category of types (such as
  3515.         ``limited'' or ``incomplete'') is also used to qualify its subtypes,
  3516.         as well as its objects, values, declarations, and definitions, such
  3517.         as an ``integer type declaration'' or an ``integer value.''  In
  3518.         addition, if a term such as ``parent subtype'' or ``index subtype''
  3519.         is defined, then the corresponding term for the type of the subtype
  3520.         is ``parent type'' or ``index type.''
  3521.  
  3522.         8.e   Discussion:  We use these corresponding terms without
  3523.         explicitly defining them, when the meaning is obvious.
  3524.  
  3525. 9   {constrained} {unconstrained} {constrained (subtype)} {unconstrained
  3526. (subtype)} A subtype is called an unconstrained subtype if its type has
  3527. unknown discriminants, or if its type allows range, index, or discriminant
  3528. constraints, but the subtype does not impose such a constraint; otherwise,
  3529. the subtype is called a constrained subtype (since it has no unconstrained
  3530. characteristics).
  3531.  
  3532.         9.a   Discussion:  In an earlier version of Ada 9X, "constrained"
  3533.         meant "has a non-null constraint."  However, we changed to this
  3534.         definition since we kept having to special case composite
  3535.         non-array/non-discriminated types.  It also corresponds better to the
  3536.         (now obsolescent) attribute 'Constrained.
  3537.  
  3538.         9.b   For scalar types, ``constrained'' means ``has a non-null
  3539.         constraint''.  For composite types, in implementation terms,
  3540.         ``constrained'' means that the size of all objects of the subtype is
  3541.         the same, assuming a typical implementation model.
  3542.  
  3543.         9.c   Class-wide subtypes are always unconstrained.
  3544.  
  3545.  
  3546.      NOTES
  3547. 10   (2) Any set of types that is closed under derivation (see 3.4) can be
  3548.      called a ``class'' of types.  However, only certain classes are used in
  3549.      the description of the rules of the language -- generally those that
  3550.      have their own particular set of primitive operations (see 3.2.3), or
  3551.      that correspond to a set of types that are matched by a given kind of
  3552.      generic formal type (see 12.5).  {language-defined class [partial]} The
  3553.      following are examples of ``interesting'' language-defined classes:
  3554.      elementary, scalar, discrete, enumeration, character, boolean, integer,
  3555.      signed integer, modular, real, floating point, fixed point, ordinary
  3556.      fixed point, decimal fixed point, numeric, access, access-to-object,
  3557.      access-to-subprogram, composite, array, string, (untagged) record,
  3558.      tagged, task, protected, nonlimited.  Special syntax is provided to
  3559.      define types in each of these classes.
  3560.  
  3561.         10.a   Discussion:  {value} A value is a run-time entity with a given
  3562.         type which can be assigned to an object of an appropriate subtype of
  3563.         the type.  {operation} An operation is a program entity that operates
  3564.         on zero or more operands to produce an effect, or yield a result, or
  3565.         both.
  3566.  
  3567.         10.b   Ramification:  Note that a type's class depends on the place
  3568.         of the reference -- a private type is composite outside and possibly
  3569.         elementary inside.  It's really the view that is elementary or
  3570.         composite.  Note that although private types are composite, there are
  3571.         some properties that depend on the corresponding full view -- for
  3572.         example, parameter passing modes, and the constraint checks that
  3573.         apply in various places.
  3574.  
  3575.         10.c   Not every property of types represents a class.  For example,
  3576.         the set of all abstract types does not form a class, because this set
  3577.         is not closed under derivation.
  3578.  
  3579.         10.d   The set of limited types forms a class in the sense that it is
  3580.         closed under derivation, but the more interesting class, from the
  3581.         point of generic formal type matching, is the set of all types,
  3582.         limited and nonlimited, since that is what matches a generic formal
  3583.         ``limited'' private type.  Note also that a limited type can ``become
  3584.         nonlimited'' under certain circumstances, which makes ``limited''
  3585.         somewhat problematic as a class of types.
  3586.  
  3587.      11   These language-defined classes are organized like this:
  3588.  
  3589. 12
  3590.          all types
  3591.             elementary
  3592.                scalar
  3593.                   discrete
  3594.                      enumeration
  3595.                         character
  3596.                         boolean
  3597.                         other enumeration
  3598.                      integer
  3599.                         signed integer
  3600.                         modular integer
  3601.                   real
  3602.                      floating point
  3603.                      fixed point
  3604.                         ordinary fixed point
  3605.                         decimal fixed point
  3606.                access
  3607.                   access-to-object
  3608.                   access-to-subprogram
  3609.             composite
  3610.                array
  3611.                   string
  3612.                   other array
  3613.                untagged record
  3614.                tagged
  3615.                task
  3616.                protected
  3617.  
  3618.      13   The classes ``numeric'' and ``nonlimited'' represent other
  3619.      classification dimensions and do not fit into the above strictly
  3620.      hierarchical picture.
  3621.  
  3622.  
  3623.                          Wording Changes From Ada 83
  3624.  
  3625.         13.a   This clause and its subclauses now precede the clause and
  3626.         subclauses on objects and named numbers, to cut down on the number of
  3627.         forward references.
  3628.  
  3629.         13.b   We have dropped the term "base type" in favor of simply "type"
  3630.         (all types in Ada 83 were "base types" so it wasn't clear when it was
  3631.         appropriate/necessary to say "base type").  Given a subtype S of a
  3632.         type T, we call T the "type of the subtype S."
  3633.  
  3634.  
  3635.  
  3636. 3.2.1 Type Declarations
  3637.  
  3638. 1   A type_declaration declares a type and its first subtype.
  3639.  
  3640.  
  3641.                                    Syntax
  3642.  
  3643. 2   type_declaration ::=  full_type_declaration
  3644.        | incomplete_type_declaration
  3645.        | private_type_declaration
  3646.        | private_extension_declaration
  3647.  
  3648. 3   full_type_declaration ::=
  3649.          type defining_identifier [known_discriminant_part] is type_definition;
  3650.        | task_type_declaration
  3651.        | protected_type_declaration
  3652.  
  3653. 4   type_definition ::=
  3654.          enumeration_type_definition | integer_type_definition
  3655.        | real_type_definition        | array_type_definition
  3656.        | record_type_definition      | access_type_definition
  3657.        | derived_type_definition
  3658.  
  3659.  
  3660.                                Legality Rules
  3661.  
  3662. 5   A given type shall not have a subcomponent whose type is the given type
  3663. itself.
  3664.  
  3665.  
  3666.                               Static Semantics
  3667.  
  3668. 6   {first subtype} The defining_identifier of a type_declaration denotes the
  3669. first subtype of the type.  The known_discriminant_part, if any, defines the
  3670. discriminants of the type (see 3.7, ``Discriminants'').  The remainder of the
  3671. type_declaration defines the remaining characteristics of (the view of) the
  3672. type.
  3673.  
  3674. 7   {named type} A type defined by a type_declaration is a named type; such a
  3675. type has one or more nameable subtypes.  {anonymous type} Certain other forms
  3676. of declaration also include type definitions as part of the declaration for
  3677. an object (including a parameter or a discriminant).  The type defined by
  3678. such a declaration is anonymous -- it has no nameable subtypes.  {italics
  3679. (pseudo-names of anonymous types)} For explanatory purposes, this
  3680. International Standard sometimes refers to an anonymous type by a
  3681. pseudo-name, written in italics, and uses such pseudo-names at places where
  3682. the syntax normally requires an identifier.  For a named type whose first
  3683. subtype is T, this International Standard sometimes refers to the type of T
  3684. as simply ``the type T.''
  3685.  
  3686.         7.a   Ramification:  The only user-defined types that can be
  3687.         anonymous in the above sense are array, access, task, and protected
  3688.         types.  An anonymous array, task, or protected type can be defined as
  3689.         part of an object_declaration.  An anonymous access type can be
  3690.         defined as part of a parameter or discriminant specification.
  3691.  
  3692. 8   {full type} A named type that is declared by a full_type_declaration, or
  3693. an anonymous type that is defined as part of declaring an object of the type,
  3694. is called a full type.  {full type definition} The type_definition, task_
  3695. definition, protected_definition, or access_definition that defines a full
  3696. type is called a full type definition.[Types declared by other forms of type_
  3697. declaration are not separate types; they are partial or incomplete views of
  3698. some full type.]
  3699.  
  3700.         8.a   To be honest:  Class-wide, universal, and root numeric types
  3701.         are full types.
  3702.  
  3703. 9   {predefined operator [partial]} The definition of a type implicitly
  3704. declares certain predefined operators that operate on the type, according to
  3705. what classes the type belongs, as specified in 4.5, ``Operators and
  3706. Expression Evaluation''.
  3707.  
  3708.         9.a   Discussion:  We no longer talk about the implicit declaration
  3709.         of basic operations.  These are treated like an if_statement -- they
  3710.         don't need to be declared, but are still applicable to only certain
  3711.         classes of types.
  3712.  
  3713. 10   {predefined type} The predefined types [(for example the types Boolean,
  3714. Wide_Character, Integer, root_integer, and universal_integer)] are the types
  3715. that are defined in [a predefined library package called] Standard[; this
  3716. package also includes the [(implicit)] declarations of their predefined
  3717. operators].  [The package Standard is described in A.1.]
  3718.  
  3719.         10.a   Ramification:  We use the term ``predefined'' to refer to
  3720.         entities declared in the visible part of Standard, to implicitly
  3721.         declared operators of a type whose semantics are defined by the
  3722.         language, to Standard itself, and to the ``predefined environment''.
  3723.         We do not use this term to refer to library packages other than
  3724.         Standard.  For example Text_IO is a language-defined package, not a
  3725.         predefined package, and Text_IO.Put_Line is not a predefined
  3726.         operation.
  3727.  
  3728.  
  3729.                               Dynamic Semantics
  3730.  
  3731. 11   {elaboration [full_type_declaration]} The elaboration of a full_type_
  3732. declaration consists of the elaboration of the full type definition.
  3733. {elaboration [full type definition]} Each elaboration of a full type
  3734. definition creates a distinct type and its first subtype.
  3735.  
  3736.         11.a   Reason:  The creation is associated with the type definition,
  3737.         rather than the type declaration, because there are types that are
  3738.         created by full type definitions that are not immediately contained
  3739.         within a type declaration (e.g.  an array object declaration, a
  3740.         singleton task declaration, etc.).
  3741.  
  3742.         11.b   Ramification:  Any implicit declarations that occur
  3743.         immediately following the full type definition are elaborated where
  3744.         they (implicitly) occur.
  3745.  
  3746.  
  3747.                                   Examples
  3748.  
  3749. 12   Examples of type definitions:
  3750.  
  3751. 13  (White, Red, Yellow, Green, Blue, Brown, Black)
  3752.     range 1 .. 72
  3753.     array(1 .. 10) of Integer
  3754.  
  3755. 14   Examples of type declarations:
  3756.  
  3757. 15  type Color  is (White, Red, Yellow, Green, Blue, Brown, Black);
  3758.     type Column is range 1 .. 72;
  3759.     type Table  is array(1 .. 10) of Integer;
  3760.  
  3761.  
  3762.      NOTES
  3763. 16   (3) Each of the above examples declares a named type.  The identifier
  3764.      given denotes the first subtype of the type.  Other named subtypes of
  3765.      the type can be declared with subtype_declarations (see 3.2.2).
  3766.      Although names do not directly denote types, a phrase like ``the type
  3767.      Column'' is sometimes used in this International Standard to refer to
  3768.      the type of Column, where Column denotes the first subtype of the type.
  3769.      For an example of the definition of an anonymous type, see the
  3770.      declaration of the array Color_Table in 3.3.1; its type is anonymous --
  3771.      it has no nameable subtypes.
  3772.                          Wording Changes From Ada 83
  3773.  
  3774.         16.a   The syntactic category full_type_declaration now includes task
  3775.         and protected type declarations.
  3776.  
  3777.         16.b   We have generalized the concept of first-named subtype (now
  3778.         called simply ``first subtype'') to cover all kinds of types, for
  3779.         uniformity of description elsewhere.  RM83 defined first-named
  3780.         subtype in Section 13.  We define first subtype here, because it is
  3781.         now a more fundamental concept.  We renamed the term, because in Ada
  3782.         9X some first subtypes have no name.
  3783.  
  3784.         16.c   We no longer elaborate discriminant_parts, because there is
  3785.         nothing to do, and it was complex to say that you only wanted to
  3786.         elaborate it once for a private or incomplete type.  This is also
  3787.         consistent with the fact that subprogram specifications are not
  3788.         elaborated (neither in Ada 83 nor in Ada 9X).  Note, however, that an
  3789.         access_definition appearing in a discriminant_part is elaborated when
  3790.         an object with such a discriminant is created.
  3791.  
  3792.  
  3793.  
  3794. 3.2.2 Subtype Declarations
  3795.  
  3796. 1   A subtype_declaration declares a subtype of some previously declared
  3797. type, as defined by a subtype_indication.
  3798.  
  3799.  
  3800.                                    Syntax
  3801.  
  3802. 2   subtype_declaration ::=
  3803.        subtype defining_identifier is subtype_indication;
  3804.  
  3805. 3   subtype_indication ::=  subtype_mark [constraint]
  3806.  
  3807. 4   subtype_mark ::= subtype_name
  3808.  
  3809.         4.a   Ramification:  Note that name includes attribute_reference;
  3810.         thus, S'Base can be used as a subtype_mark.
  3811.  
  3812.         4.b   Reason:  We considered changing subtype_mark to subtype_name.
  3813.         However, existing users are used to the word "mark," so we're keeping
  3814.         it.
  3815.  
  3816. 5   constraint ::= scalar_constraint | composite_constraint
  3817.  
  3818. 6   scalar_constraint ::=
  3819.          range_constraint | digits_constraint | delta_constraint
  3820.  
  3821. 7   composite_constraint ::=
  3822.          index_constraint | discriminant_constraint
  3823.  
  3824.  
  3825.                             Name Resolution Rules
  3826.  
  3827. 8   A subtype_mark shall resolve to denote a subtype.  {determines (a type by
  3828. a subtype_mark)} The type determined by a subtype_mark is the type of the
  3829. subtype denoted by the subtype_mark.
  3830.  
  3831.         8.a   Ramification:  Types are never directly named; all subtype_
  3832.         marks denote subtypes -- possibly an unconstrained (base) subtype,
  3833.         but never the type.  When we use the term anonymous type we really
  3834.         mean a type with no namable subtypes.
  3835.  
  3836.  
  3837.                               Dynamic Semantics
  3838.  
  3839. 9   {elaboration [subtype_declaration]} The elaboration of a subtype_
  3840. declaration consists of the elaboration of the subtype_indication.
  3841. {elaboration [subtype_indication]} The elaboration of a subtype_indication
  3842. creates a new subtype.  If the subtype_indication does not include a
  3843. constraint, the new subtype has the same (possibly null) constraint as that
  3844. denoted by the subtype_mark.  The elaboration of a subtype_indication that
  3845. includes a constraint proceeds as follows:
  3846.  
  3847.    10  The constraint is first elaborated.
  3848.  
  3849.    11  {Range_Check [partial]} {check, language-defined (Range_Check)} A
  3850.        check is then made that the constraint is compatible with the
  3851.        subtype denoted by the subtype_mark.
  3852.  
  3853.  11.a   Ramification:  The checks associated with constraint
  3854.         compatibility are all Range_Checks.  Discriminant_Checks and
  3855.         Index_Checks are associated only with checks that a value
  3856.         satisfies a constraint.
  3857.  
  3858. 12   The condition imposed by a constraint is the condition obtained after
  3859. elaboration of the constraint.  {compatibility (constraint with a subtype)
  3860. [distributed]} The rules defining compatibility are given for each form of
  3861. constraint in the appropriate subclause.  These rules are such that if a
  3862. constraint is compatible with a subtype, then the condition imposed by the
  3863. constraint cannot contradict any condition already imposed by the subtype on
  3864. its values.  {Constraint_Error (raised by failure of run-time check)} The
  3865. exception Constraint_Error is raised if any check of compatibility fails.
  3866.  
  3867.         12.a   To be honest:  The condition imposed by a constraint is named
  3868.         after it -- a range_constraint imposes a range constraint, etc.
  3869.  
  3870.         12.b   Ramification:  A range_constraint causes freezing of its type.
  3871.         Other constraints do not.
  3872.  
  3873.  
  3874.      NOTES
  3875. 13   (4) A scalar_constraint may be applied to a subtype of an appropriate
  3876.      scalar type (see 3.5, 3.5.9, and J.3), even if the subtype is already
  3877.      constrained.  On the other hand, a composite_constraint may be applied
  3878.      to a composite subtype (or an access-to-composite subtype) only if the
  3879.      composite subtype is unconstrained (see 3.6.1 and 3.7.1).
  3880.  
  3881.  
  3882.                                   Examples
  3883.  
  3884. 14   Examples of subtype declarations:
  3885.  
  3886. 15  subtype Rainbow   is Color range Red .. Blue;        --  see 3.2.1
  3887.     subtype Red_Blue  is Rainbow;
  3888.     subtype Int       is Integer;
  3889.     subtype Small_Int is Integer range -10 .. 10;
  3890.     subtype Up_To_K   is Column range 1 .. K;            --  see 3.2.1
  3891.     subtype Square    is Matrix(1 .. 10, 1 .. 10);       --  see 3.6
  3892.     subtype Male      is Person(Sex => M);               --  see 3.10.1
  3893.  
  3894.  
  3895.                         Incompatibilities With Ada 83
  3896.  
  3897.         15.a   {incompatibilities with Ada 83} In Ada 9X, all range_
  3898.         constraints cause freezing of their type.  Hence, a type-related
  3899.         representation item for a scalar type has to precede any range_
  3900.         constraints whose type is the scalar type.
  3901.  
  3902.                          Wording Changes From Ada 83
  3903.  
  3904.         15.b   Subtype_marks allow only subtype names now, since types are
  3905.         never directly named.  There is no need for RM83-3.3.2(3), which says
  3906.         a subtype_mark can denote both the type and the subtype; in Ada 9X,
  3907.         you denote an unconstrained (base) subtype if you want, but never the
  3908.         type.
  3909.  
  3910.         15.c   The syntactic category type_mark is now called subtype_mark,
  3911.         since it always denotes a subtype.
  3912.  
  3913.  
  3914.  
  3915. 3.2.3 Classification of Operations
  3916.  
  3917.                               Static Semantics
  3918.  
  3919. 1   {operates on a type} An operation operates on a type T if it yields a
  3920. value of type T, if it has an operand whose expected type (see 8.6) is T, or
  3921. if it has an access parameter (see 6.1) designating T.  {predefined operation
  3922. (of a type)} A predefined operator, or other language-defined operation such
  3923. as assignment or a membership test, that operates on a type, is called a
  3924. predefined operation of the type.  {primitive operations (of a type)} The
  3925. primitive operations of a type are the predefined operations of the type,
  3926. plus any user-defined primitive subprograms.
  3927.  
  3928.         1.a   Glossary entry:  {Primitive operations} The primitive
  3929.         operations of a type are the operations (such as subprograms)
  3930.         declared together with the type declaration.  They are inherited by
  3931.         other types in the same class of types.  For a tagged type, the
  3932.         primitive subprograms are dispatching subprograms, providing run-time
  3933.         polymorphism.  A dispatching subprogram may be called with statically
  3934.         tagged operands, in which case the subprogram body invoked is
  3935.         determined at compile time.  Alternatively, a dispatching subprogram
  3936.         may be called using a dispatching call, in which case the subprogram
  3937.         body invoked is determined at run time.
  3938.  
  3939.         1.b   To be honest:  Protected subprograms are not considered to be
  3940.         ``primitive subprograms,'' even though they are subprograms, and they
  3941.         are inherited by derived types.
  3942.  
  3943.         1.c   Discussion:  We use the term ``primitive subprogram'' in most
  3944.         of the rest of the manual.  The term ``primitive operation'' is used
  3945.         mostly in conceptual discussions.
  3946.  
  3947. 2   {primitive subprograms (of a type)} The primitive subprograms of a
  3948. specific type are defined as follows:
  3949.  
  3950.     3  The predefined operators of the type (see 4.5);
  3951.  
  3952.     4  For a derived type, the inherited (see 3.4) user-defined
  3953.        subprograms;
  3954.  
  3955.     5  For an enumeration type, the enumeration literals (which are
  3956.        considered parameterless functions -- see 3.5.1);
  3957.  
  3958.     6  For a specific type declared immediately within a package_
  3959.        specification, any subprograms (in addition to the enumeration
  3960.        literals) that are explicitly declared immediately within the
  3961.        same package_specification and that operate on the type;
  3962.  
  3963.     7  {override (a primitive subprogram)} Any subprograms not covered
  3964.        above [that are explicitly declared immediately within the same
  3965.        declarative region as the type] and that override (see 8.3) other
  3966.        implicitly declared primitive subprograms of the type.
  3967.        {94-4450.a} {94-4451.a} {94-4453.a}
  3968.  
  3969.         7.a   Discussion:  In Ada 83, only subprograms declared in the
  3970.         visible part were ``primitive'' (i.e.  derivable).  In Ada 9X, mostly
  3971.         because of child library units, we include all operations declared in
  3972.         the private part as well, and all operations that override implicit
  3973.         declarations.
  3974.  
  3975.         7.b   Ramification:  It is possible for a subprogram to be primitive
  3976.         for more than one type, though it is illegal for a subprogram to be
  3977.         primitive for more than one tagged type.  See 3.9.
  3978.  
  3979.         7.c   Discussion:  The order of the implicit declarations when there
  3980.         are both predefined operators and inherited subprograms is described
  3981.         in 3.4, ``Derived Types and Classes''.
  3982.  
  3983. 8   {primitive operator (of a type)} A primitive subprogram whose designator
  3984. is an operator_symbol is called a primitive operator.
  3985.  
  3986.  
  3987.                         Incompatibilities With Ada 83
  3988.  
  3989.         8.a   {incompatibilities with Ada 83} The attribute S'Base is no
  3990.         longer defined for non-scalar subtypes.  Since this was only
  3991.         permitted as the prefix of another attribute, and there are no
  3992.         interesting non-scalar attributes defined for an unconstrained
  3993.         composite or access subtype, this should not affect any existing
  3994.         programs.
  3995.  
  3996.                             Extensions to Ada 83
  3997.  
  3998.         8.b   {extensions to Ada 83} The primitive subprograms (derivable
  3999.         subprograms) include subprograms declared in the private part of a
  4000.         package specification as well, and those that override implicitly
  4001.         declared subprograms, even if declared in a body.
  4002.  
  4003.                          Wording Changes From Ada 83
  4004.  
  4005.         8.c   We have dropped the confusing term operation of a type in favor
  4006.         of the more useful primitive operation of a type and the phrase
  4007.         operates on a type.
  4008.  
  4009.         8.d   The description of S'Base has been moved to 3.5, ``Scalar
  4010.         Types'' because it is now defined only for scalar types.
  4011.  
  4012.  
  4013.  
  4014. 3.3 Objects and Named Numbers
  4015.  
  4016. 1   [Objects are created at run time and contain a value of a given type.
  4017. {creation (of an object)} An object can be created and initialized as part of
  4018. elaborating a declaration, evaluating an allocator, aggregate, or function_
  4019. call, or passing a parameter by copy.  Prior to reclaiming the storage for an
  4020. object, it is finalized if necessary (see 7.6.1).]
  4021.  
  4022.  
  4023.                               Static Semantics
  4024.  
  4025. 2   {object} All of the following are objects:
  4026.  
  4027.         2.a   Glossary entry:  {Object} An object is either a constant or a
  4028.         variable.  An object contains a value.  An object is created by an
  4029.         object_declaration or by an allocator.  A formal parameter is (a view
  4030.         of) an object.  A subcomponent of an object is an object.
  4031.  
  4032.     3  the entity declared by an object_declaration;
  4033.  
  4034.     4  a formal parameter of a subprogram, entry, or generic subprogram;
  4035.  
  4036.     5  a generic formal object;
  4037.  
  4038.     6  a loop parameter;
  4039.  
  4040.     7  a choice parameter of an exception_handler;
  4041.  
  4042.     8  an entry index of an entry_body;
  4043.  
  4044.     9  the result of dereferencing an access-to-object value (see 4.1);
  4045.  
  4046.    10  the result of evaluating a function_call (or the equivalent
  4047.        operator invocation -- see 6.6);
  4048.  
  4049.    11  the result of evaluating an aggregate;
  4050.  
  4051.    12  a component, slice, or view conversion of another object.
  4052.  
  4053. 13   {constant} {variable} {constant object} {variable object} {constant
  4054. view} {variable view} An object is either a constant object or a variable
  4055. object.  The value of a constant object cannot be changed between its
  4056. initialization and its finalization, whereas the value of a variable object
  4057. can be changed.  Similarly, a view of an object is either a constant or a
  4058. variable.  All views of a constant object are constant.  A constant view of a
  4059. variable object cannot be used to modify the value of the variable.  The
  4060. terms constant and variable by themselves refer to constant and variable
  4061. views of objects.
  4062.  
  4063. 14   {read (the value of an object)} The value of an object is read when the
  4064. value of any part of the object is evaluated, or when the value of an
  4065. enclosing object is evaluated.  {update (the value of an object)} The value
  4066. of a variable is updated when an assignment is performed to any part of the
  4067. variable, or when an assignment is performed to an enclosing object.
  4068.  
  4069.         14.a   Ramification:  Reading and updating are intended to include
  4070.         read/write references of any kind, even if they are not associated
  4071.         with the evaluation of a particular construct.  Consider, for
  4072.         example, the expression ``X.all(F)'', where X is an access-to-array
  4073.         object, and F is a function.  The implementation is allowed to first
  4074.         evaluate ``X.all'' and then F. Finally, a read is performed to get
  4075.         the value of the F'th component of the array.  Note that the array is
  4076.         not necessarily read as part of the evaluation of ``X.all''.  This is
  4077.         important, because if F were to free X using Unchecked_Deallocation,
  4078.         we want the execution of the final read to be erroneous.
  4079.  
  4080. 15   Whether a view of an object is constant or variable is determined by the
  4081. definition of the view.  The following (and no others) represent constants:
  4082.  
  4083.    16  an object declared by an object_declaration with the reserved
  4084.        word constant;
  4085.  
  4086.    17  a formal parameter or generic formal object of mode in;
  4087.  
  4088.    18  a discriminant;
  4089.  
  4090.    19  a loop parameter, choice parameter, or entry index;
  4091.  
  4092.    20  the dereference of an access-to-constant value;
  4093.  
  4094.    21  the result of evaluating a function_call or an aggregate;
  4095.  
  4096.    22  a selected_component, indexed_component, slice, or view
  4097.        conversion of a constant.
  4098.  
  4099.  22.a   To be honest:  A noninvertible view conversion to a general
  4100.         access type is also defined to be a constant -- see 4.6.
  4101.  
  4102. 23   {nominal subtype} At the place where a view of an object is defined, a
  4103. nominal subtype is associated with the view.  {actual subtype} {subtype (of
  4104. an object): see actual subtype of an object} The object's actual subtype
  4105. (that is, its subtype) can be more restrictive than the nominal subtype of
  4106. the view; it always is if the nominal subtype is an indefinite subtype.
  4107. {indefinite subtype} {definite subtype} A subtype is an indefinite subtype if
  4108. it is an unconstrained array subtype, or if it has unknown discriminants or
  4109. unconstrained discriminants without defaults (see 3.7); otherwise the subtype
  4110. is a definite subtype [(all elementary subtypes are definite subtypes)].[A
  4111. class-wide subtype is defined to have unknown discriminants, and is therefore
  4112. an indefinite subtype.  An indefinite subtype does not by itself provide
  4113. enough information to create an object; an additional constraint or explicit
  4114. initialization expression is necessary (see 3.3.1).  A component cannot have
  4115. an indefinite nominal subtype.  {94-4799.a}]
  4116.  
  4117. 24   {named number} A named number provides a name for a numeric value known
  4118. at compile time.  It is declared by a number_declaration.
  4119.  
  4120.  
  4121.      NOTES
  4122. 25   (5) A constant cannot be the target of an assignment operation, nor be
  4123.      passed as an in out or out parameter, between its initialization and
  4124.      finalization, if any.
  4125.  
  4126. 26   (6) The nominal and actual subtypes of an elementary object are always
  4127.      the same.  For a discriminated or array object, if the nominal subtype
  4128.      is constrained then so is the actual subtype.
  4129.  
  4130.  
  4131.                             Extensions to Ada 83
  4132.  
  4133.         26.a   {extensions to Ada 83} There are additional kinds of objects
  4134.         (choice parameters and entry indices of entry bodies).
  4135.  
  4136.         26.b   The result of a function and of evaluating an aggregate are
  4137.         considered (constant) objects.  This is necessary to explain the
  4138.         action of finalization on such things.  Because a function_call is
  4139.         also syntactically a name (see 4.1), the result of a function_call
  4140.         can be renamed, thereby allowing repeated use of the result without
  4141.         calling the function again.
  4142.  
  4143.                          Wording Changes From Ada 83
  4144.  
  4145.         26.c   This clause and its subclauses now follow the clause and
  4146.         subclauses on types and subtypes, to cut down on the number of
  4147.         forward references.
  4148.  
  4149.         26.d   The term nominal subtype is new.  It is used to distinguish
  4150.         what is known at compile time about an object's constraint, versus
  4151.         what its "true" run-time constraint is.
  4152.  
  4153.         26.e   The terms definite and indefinite (which apply to subtypes)
  4154.         are new.  They are used to aid in the description of generic formal
  4155.         type matching, and to specify when an explicit initial value is
  4156.         required in an object_declaration.
  4157.  
  4158.         26.f   We have moved the syntax for object_declaration and number_
  4159.         declaration down into their respective subclauses, to keep the syntax
  4160.         close to the description of the associated semantics.
  4161.  
  4162.         26.g   We talk about variables and constants here, since the
  4163.         discussion is not specific to object_declarations, and it seems
  4164.         better to have the list of the kinds of constants juxtaposed with the
  4165.         kinds of objects.
  4166.  
  4167.         26.h   We no longer talk about indirect updating due to parameter
  4168.         passing.  Parameter passing is handled in 6.2 and 6.4.1 in a way that
  4169.         there is no need to mention it here in the definition of read and
  4170.         update.  Reading and updating now includes the case of evaluating or
  4171.         assigning to an enclosing object.
  4172. 3.3.1 Object Declarations
  4173.  
  4174. 1   {stand-alone object} {explicit initial value} {initialization expression}
  4175. An object_declaration declares a stand-alone object with a given nominal
  4176. subtype and, optionally, an explicit initial value given by an initialization
  4177. expression.  {anonymous array type} {anonymous task type} {anonymous
  4178. protected type} For an array, task, or protected object, the object_
  4179. declaration may include the definition of the (anonymous) type of the object.
  4180.  
  4181.  
  4182.                                    Syntax
  4183.  
  4184. 2   object_declaration ::=
  4185.         defining_identifier_list : [aliased] [constant] subtype_indication [:= \
  4186. expression];
  4187.       | defining_identifier_list : [aliased] [constant] array_type_definition [\
  4188. := expression];
  4189.       | single_task_declaration
  4190.       | single_protected_declaration
  4191.  
  4192. 3   defining_identifier_list ::=
  4193.       defining_identifier {, defining_identifier}
  4194.  
  4195.  
  4196.                             Name Resolution Rules
  4197.  
  4198. 4   {expected type [object_declaration initialization expression]} For an
  4199. object_declaration with an expression following the compound delimiter :=,
  4200. the type expected for the expression is that of the object.  {initialization
  4201. expression} This expression is called the initialization expression.
  4202. {constructor: see initialization expression}
  4203.  
  4204.  
  4205.                                Legality Rules
  4206.  
  4207. 5   An object_declaration without the reserved word constant declares a
  4208. variable object.  If it has a subtype_indication or an array_type_definition
  4209. that defines an indefinite subtype, then there shall be an initialization
  4210. expression.  An initialization expression shall not be given if the object is
  4211. of a limited type.
  4212.  
  4213.  
  4214.                               Static Semantics
  4215.  
  4216. 6   An object_declaration with the reserved word constant declares a constant
  4217. object.  {full constant declaration} If it has an initialization expression,
  4218. then it is called a full constant declaration.  {deferred constant
  4219. declaration} Otherwise it is called a deferred constant declaration.  The
  4220. rules for deferred constant declarations are given in clause 7.4.  The rules
  4221. for full constant declarations are given in this subclause.
  4222.  
  4223. 7   Any declaration that includes a defining_identifier_list with more than
  4224. one defining_identifier is equivalent to a series of declarations each
  4225. containing one defining_identifier from the list, with the rest of the text
  4226. of the declaration copied for each declaration in the series, in the same
  4227. order as the list.  The remainder of this International Standard relies on
  4228. this equivalence; explanations are given for declarations with a single
  4229. defining_identifier.
  4230.  
  4231. 8   {nominal subtype} The subtype_indication or full type definition of an
  4232. object_declaration defines the nominal subtype of the object.  The object_
  4233. declaration declares an object of the type of the nominal subtype.
  4234.  
  4235.         8.a   Discussion:  The phrase ``full type definition'' here includes
  4236.         the case of an anonymous array, task, or protected type.
  4237.  
  4238.  
  4239.                               Dynamic Semantics
  4240.  
  4241. 9   {constraint (of an object)} If a composite object declared by an object_
  4242. declaration has an unconstrained nominal subtype, then if this subtype is
  4243. indefinite or the object is constant or aliased (see 3.10) the actual subtype
  4244. of this object is constrained.  The constraint is determined by the bounds or
  4245. discriminants (if any) of its initial value; {constrained by its initial
  4246. value} the object is said to be constrained by its initial value.  {actual
  4247. subtype (of an object)} {subtype (of an object): see actual subtype of an
  4248. object} [In the case of an aliased object, this initial value may be either
  4249. explicit or implicit; in the other cases, an explicit initial value is
  4250. required.]  {94-4858.a} When not constrained by its initial value, the actual
  4251. and nominal subtypes of the object are the same.  {constrained (object)}
  4252. {unconstrained (object)} If its actual subtype is constrained, the object is
  4253. called a constrained object.
  4254.  
  4255. 10   {implicit initial values (for a subtype)} For an object_declaration
  4256. without an initialization expression, any initial values for the object or
  4257. its subcomponents are determined by the implicit initial values defined for
  4258. its nominal subtype, as follows:
  4259.  
  4260.    11  The implicit initial value for an access subtype is the null
  4261.        value of the access type.
  4262.  
  4263.    12  The implicit initial (and only) value for each discriminant of a
  4264.        constrained discriminated subtype is defined by the subtype.
  4265.  
  4266.    13  For a (definite) composite subtype, the implicit initial value of
  4267.        each component with a default_expression is obtained by
  4268.        evaluation of this expression and conversion to the component's
  4269.        nominal subtype (which might raise Constraint_Error -- see 4.6,
  4270.        ``Type Conversions''), unless the component is a discriminant of
  4271.        a constrained subtype (the previous case), or is in an excluded
  4272.        variant (see 3.8.1).  {implicit subtype conversion [component
  4273.        defaults]} For each component that does not have a default_
  4274.        expression, any implicit initial values are those determined by
  4275.        the component's nominal subtype.
  4276.  
  4277.    14  For a protected or task subtype, there is an implicit component
  4278.        (an entry queue) corresponding to each entry, with its implicit
  4279.        initial value being an empty queue.
  4280.  
  4281.  14.a   Implementation Note:  The implementation may add implicit
  4282.         components for its own use, which might have implicit initial
  4283.         values.  For a task subtype, such components might represent the
  4284.         state of the associated thread of control.  For a type with
  4285.         dynamic-sized components, such implicit components might be used
  4286.         to hold the offset to some explicit component.
  4287.  
  4288. 15   {elaboration [object_declaration]} The elaboration of an object_
  4289. declaration proceeds in the following sequence of steps:
  4290.  
  4291.    16  The subtype_indication, array_type_definition, single_task_
  4292.        declaration, or single_protected_declaration is first elaborated.
  4293.        This creates the nominal subtype (and the anonymous type in the
  4294.        latter three cases).
  4295.  
  4296.    17  If the object_declaration includes an initialization expression,
  4297.        the (explicit) initial value is obtained by evaluating the
  4298.        expression and converting it to the nominal subtype (which might
  4299.        raise Constraint_Error -- see 4.6).  {implicit subtype conversion
  4300.        [initialization expression]}
  4301.  
  4302.    18  The object is created, and, if there is not an initialization
  4303.        expression, any per-object expressions (see 3.8) are evaluated
  4304.        and any implicit initial values for the object or for its
  4305.        subcomponents are obtained as determined by the nominal subtype.
  4306.  
  4307.  18.a   Discussion:  For a per-object constraint that contains some
  4308.         per-object expressions and some non-per-object expressions, the
  4309.         values used for the constraint consist of the values of the
  4310.         non-per-object expressions evaluated at the point of the type_
  4311.         declaration, and the values of the per-object expressions
  4312.         evaluated at the point of the creation of the object.
  4313.  
  4314.  18.b   The elaboration of per-object constraints was presumably
  4315.         performed as part of the dependent compatibility check in Ada
  4316.         83.  If the object is of a limited type with an access
  4317.         discriminant, the access_definition is elaborated at this time
  4318.         (see 3.7).
  4319.  
  4320.  18.c   Reason:  The reason we say that evaluating an explicit
  4321.         initialization expression happens before creating the object is
  4322.         that in some cases it is impossible to know the size of the
  4323.         object being created until its initial value is known, as in
  4324.         ``X: String := Func_Call(...);''.  The implementation can create
  4325.         the object early in the common case where the size can be known
  4326.         early, since this optimization is semantically neutral.
  4327.  
  4328.    19  {initialization (of an object)} {assignment operation (during
  4329.        elaboration of an object_declaration)} Any initial values
  4330.        (whether explicit or implicit) are assigned to the object or to
  4331.        the corresponding subcomponents.  As described in 5.2 and 7.6,
  4332.        Initialize and Adjust procedures can be called.  {constructor:
  4333.        see initialization}
  4334.  
  4335.  19.a   Ramification:  Since the initial values have already been
  4336.         converted to the appropriate nominal subtype, the only
  4337.         Constraint_Errors that might occur as part of these assignments
  4338.         are for values outside their base range that are used to
  4339.         initialize unconstrained numeric subcomponents.  See 3.5.
  4340.  
  4341. 20   For the third step above, the object creation and any elaborations and
  4342. evaluations are performed in an arbitrary order, except that if the default_
  4343. expression for a discriminant is evaluated to obtain its initial value, then
  4344. this evaluation is performed before that of the default_expression for any
  4345. component that depends on the discriminant, and also before that of any
  4346. default_expression that includes the name of the discriminant.  The
  4347. evaluations of the third step and the assignments of the fourth step are
  4348. performed in an arbitrary order, except that each evaluation is performed
  4349. before the resulting value is assigned.
  4350.  
  4351.         20.a   Reason:  For example:
  4352.  
  4353. 20.b        type R(D : Integer := F) is
  4354.                 record
  4355.                     S : String(1..D) := (others => G);
  4356.                 end record;
  4357.  
  4358. 20.c        X : R;
  4359.  
  4360.         20.d   For the elaboration of the declaration of X, it is important
  4361.         that F be evaluated before the aggregate.
  4362.  
  4363. 21   [There is no implicit initial value defined for a scalar subtype.]
  4364. {uninitialized variables [partial]} In the absence of an explicit
  4365. initialization, a newly created scalar object might have a value that does
  4366. not belong to its subtype (see 13.9.1 and H.1).
  4367.  
  4368.         21.a   To be honest:  It could even be represented by a bit pattern
  4369.         that doesn't actually represent any value of the type at all, such as
  4370.         an invalid internal code for an enumeration type, or a NaN for a
  4371.         floating point type.  It is a generally a bounded error to reference
  4372.         scalar objects with such ``invalid representations'', as explained in
  4373.         13.9.1, ``Data Validity''.
  4374.         21.b   Ramification:  There is no requirement that two objects of the
  4375.         same scalar subtype have the same implicit initial ``value'' (or
  4376.         representation).  It might even be the case that two elaborations of
  4377.         the same object_declaration produce two different initial values.
  4378.         However, any particular uninitialized object is default-initialized
  4379.         to a single value (or invalid representation).  Thus, multiple reads
  4380.         of such an uninitialized object will produce the same value each time
  4381.         (if the implementation chooses not to detect the error).
  4382.  
  4383.  
  4384.      NOTES
  4385. 22   (7) Implicit initial values are not defined for an indefinite subtype,
  4386.      because if an object's nominal subtype is indefinite, an explicit
  4387.      initial value is required.  {94-4799.a}
  4388.  
  4389. 23   (8) {stand-alone constant} {stand-alone variable} As indicated above, a
  4390.      stand-alone object is an object declared by an object_declaration.
  4391.      Similar definitions apply to ``stand-alone constant'' and ``stand-alone
  4392.      variable.''  A subcomponent of an object is not a stand-alone object,
  4393.      nor is an object that is created by an allocator.  An object declared by
  4394.      a loop_parameter_specification, parameter_specification, entry_index_
  4395.      specification, choice_parameter_specification, or a formal_object_
  4396.      declaration is not called a stand-alone object.
  4397.  
  4398. 24   (9) The type of a stand-alone object cannot be abstract (see 3.9.3).
  4399.  
  4400.  
  4401.                                   Examples
  4402.  
  4403. 25   Example of a multiple object declaration:
  4404.  
  4405. 26  --  the multiple object declaration
  4406.  
  4407. 27  John, Paul : Person_Name := new Person(Sex => M);  --  see 3.10.1
  4408.  
  4409. 28  --  is equivalent to the two single object declarations in the order given
  4410.  
  4411. 29  John : Person_Name := new Person(Sex => M);
  4412.     Paul : Person_Name := new Person(Sex => M);
  4413.  
  4414. 30   Examples of variable declarations:
  4415.  
  4416. 31  Count, Sum  : Integer;
  4417.     Size        : Integer range 0 .. 10_000 := 0;
  4418.     Sorted      : Boolean := False;
  4419.     Color_Table : array(1 .. Max) of Color;
  4420.     Option      : Bit_Vector(1 .. 10) := (others => True);
  4421.     Hello       : constant String := "Hi, world.";
  4422.  
  4423. 32   Examples of constant declarations:
  4424.  
  4425. 33  Limit     : constant Integer := 10_000;
  4426.     Low_Limit : constant Integer := Limit/10;
  4427.     Tolerance : constant Real := Dispersion(1.15);
  4428.  
  4429.  
  4430.                             Extensions to Ada 83
  4431.  
  4432.         33.a   {extensions to Ada 83} The syntax rule for object_declaration
  4433.         is modified to allow the aliased reserved word.
  4434.  
  4435.         33.b   A variable declared by an object_declaration can be
  4436.         constrained by its initial value; that is, a variable of a nominally
  4437.         unconstrained array subtype, or discriminated type without defaults,
  4438.         can be declared so long as it has an explicit initial value.  In Ada
  4439.         83, this was permitted for constants, and for variables created by
  4440.         allocators, but not for variables declared by object_declarations.
  4441.         This is particularly important for tagged class-wide types, since
  4442.         there is no way to constrain them explicitly, and so an initial value
  4443.         is the only way to provide a constraint.  It is also important for
  4444.         generic formal private types with unknown discriminants.
  4445.  
  4446.         33.c   We now allow an unconstrained_array_definition in an object_
  4447.         declaration.  This allows an object of an anonymous array type to
  4448.         have its bounds determined by its initial value.  This is for
  4449.         uniformity: If one can write ``X: constant array(Integer range 1..10)
  4450.         of Integer := ...;'' then it makes sense to also allow ``X: constant
  4451.         array(Integer range <>) of Integer := ...;''.  (Note that if
  4452.         anonymous array types are ever sensible, a common situation is for a
  4453.         table implemented as an array.  Tables are often constant, and for
  4454.         constants, there's usually no point in forcing the user to count the
  4455.         number of elements in the value.)
  4456.  
  4457.                          Wording Changes From Ada 83
  4458.  
  4459.         33.d   We have moved the syntax for object_declarations into this
  4460.         subclause.
  4461.  
  4462.         33.e   Deferred constants no longer have a separate syntax rule, but
  4463.         rather are incorporated in object_declaration as constants declared
  4464.         without an initialization expression.
  4465.  
  4466.  
  4467.  
  4468. 3.3.2 Number Declarations
  4469.  
  4470. 1   A number_declaration declares a named number.
  4471.  
  4472.         1.a   Discussion:  {static} If a value or other property of a
  4473.         construct is required to be static that means it is required to be
  4474.         determined prior to execution.  A static expression is an expression
  4475.         whose value is computed at compile time and is usable in contexts
  4476.         where the actual value might affect the legality of the construct.
  4477.         This is fully defined in clause 4.9.
  4478.  
  4479.  
  4480.                                    Syntax
  4481.  
  4482. 2   number_declaration ::=
  4483.          defining_identifier_list : constant := static_expression;
  4484.  
  4485.  
  4486.                             Name Resolution Rules
  4487.  
  4488. 3   {expected type [number_declaration expression]} The static_expression
  4489. given for a number_declaration is expected to be of any numeric type.
  4490.  
  4491.  
  4492.                                Legality Rules
  4493.  
  4494. 4   The static_expression given for a number declaration shall be a static
  4495. expression, as defined by clause 4.9.
  4496.  
  4497.  
  4498.                               Static Semantics
  4499.  
  4500. 5   The named number denotes a value of type universal_integer if the type of
  4501. the static_expression is an integer type.  The named number denotes a value
  4502. of type universal_real if the type of the static_expression is a real type.
  4503.  
  4504. 6   The value denoted by the named number is the value of the
  4505. static_expression, converted to the corresponding universal type.  {implicit
  4506. subtype conversion [named number value]}
  4507.  
  4508.  
  4509.                               Dynamic Semantics
  4510.  
  4511. 7   {elaboration [number_declaration]} The elaboration of a number_
  4512. declaration has no effect.
  4513.  
  4514.         7.a   Proof:  Since the static_expression was evaluated at compile
  4515.         time.
  4516.  
  4517.  
  4518.                                   Examples
  4519.  
  4520. 8   Examples of number declarations:
  4521.  
  4522. 9   Two_Pi        : constant := 2.0*Ada.Numerics.Pi;   -- a real number (see A.\
  4523. 5)
  4524.  
  4525. 10  Max           : constant := 500;                   -- an integer number
  4526.     Max_Line_Size : constant := Max/6                  -- the integer 83
  4527.     Power_16      : constant := 2**16;                 -- the integer 65_536
  4528.     One, Un, Eins : constant := 1;                     -- three different names\
  4529.  for 1
  4530.  
  4531.  
  4532.                             Extensions to Ada 83
  4533.  
  4534.         10.a   {extensions to Ada 83} We now allow a static expression of any
  4535.         numeric type to initialize a named number.  For integer types, it was
  4536.         possible in Ada 83 to use 'Pos to define a named number, but there
  4537.         was no way to use a static expression of some non-universal real type
  4538.         to define a named number.  This change is upward compatible because
  4539.         of the preference rule for the operators of the root numeric types.
  4540.  
  4541.                          Wording Changes From Ada 83
  4542.  
  4543.         10.b   We have moved the syntax rule into this subclause.
  4544.  
  4545.         10.c   AI-00263 describes the elaboration of a number declaration in
  4546.         words similar to that of an object_declaration.  However, since there
  4547.         is no expression to be evaluated and no object to be created, it
  4548.         seems simpler to say that the elaboration has no effect.
  4549.  
  4550.  
  4551.  
  4552. 3.4 Derived Types and Classes
  4553.  
  4554. 1   {derived type} A derived_type_definition defines a new type (and its
  4555. first subtype) whose characteristics are derived from those of a parent type.
  4556.  
  4557.         1.a   Glossary entry:  {Derived type} A derived type is a type
  4558.         defined in terms of another type, which is the parent type of the
  4559.         derived type.  Each class containing the parent type also contains
  4560.         the derived type.  The derived type inherits properties such as
  4561.         components and primitive operations from the parent.  A type together
  4562.         with the types derived from it (directly or indirectly) form a
  4563.         derivation class.
  4564.  
  4565. {inheritance: see derived types and classes}
  4566.  
  4567.  
  4568.                                    Syntax
  4569.  
  4570. 2   derived_type_definition ::= [abstract] new parent_subtype_indication [recor\
  4571. d_extension_part]
  4572.  
  4573.  
  4574.                                Legality Rules
  4575. 3   {parent subtype} {parent type} The parent_subtype_indication defines the
  4576. parent subtype; its type is the parent type.
  4577.  
  4578. 4   A type shall be completely defined (see 3.11.1) prior to being specified
  4579. as the parent type in a derived_type_definition -- [the full_type_
  4580. declarations for the parent type and any of its subcomponents have to precede
  4581. the derived_type_definition.]
  4582.  
  4583.         4.a   Discussion:  This restriction does not apply to the ancestor
  4584.         type of a private extension -- see 7.3; such a type need not be
  4585.         completely defined prior to the private_extension_declaration.
  4586.         However, the restriction does apply to record extensions, so the
  4587.         ancestor type will have to be completely defined prior to the full_
  4588.         type_declaration corresponding to the private_extension_declaration.
  4589.  
  4590.         4.b   Reason:  We originally hoped we could relax this restriction.
  4591.         However, we found it too complex to specify the rules for a type
  4592.         derived from an incompletely defined limited type that subsequently
  4593.         became nonlimited.
  4594.  
  4595. 5   {record extension} If there is a record_extension_part, the derived type
  4596. is called a record extension of the parent type.  A record_extension_part
  4597. shall be provided if and only if the parent type is a tagged type.
  4598.  
  4599.         5.a   Implementation Note:  We allow a record extension to inherit
  4600.         discriminants; a previous version of Ada 9X did not.  If the parent
  4601.         subtype is unconstrained, it can be implemented as though its
  4602.         discriminants were repeated in a new known_discriminant_part and then
  4603.         used to constrain the old ones one-for-one.  However, in an extension
  4604.         aggregate, the discriminants in this case do not appear in the
  4605.         component association list.
  4606.  
  4607.         5.b   Ramification:  This rule needs to be rechecked in the visible
  4608.         part of an instance of a generic unit.
  4609.  
  4610.  
  4611.                               Static Semantics
  4612.  
  4613. 6   {constrained (subtype)} {unconstrained (subtype)} The first subtype of
  4614. the derived type is unconstrained if a known_discriminant_part is provided in
  4615. the declaration of the derived type, or if the parent subtype is
  4616. unconstrained.  {corresponding constraint} Otherwise, the constraint of the
  4617. first subtype corresponds to that of the parent subtype in the following
  4618. sense: it is the same as that of the parent subtype except that for a range
  4619. constraint (implicit or explicit), the value of each bound of its range is
  4620. replaced by the corresponding value of the derived type.
  4621.  
  4622.         6.a   Discussion:  A digits_constraint in a subtype_indication for a
  4623.         decimal fixed point subtype always imposes a range constraint,
  4624.         implicitly if there is no explicit one given.  See 3.5.9, ``Fixed
  4625.         Point Types''.
  4626.  
  4627. 7   The characteristics of the derived type are defined as follows:
  4628.  
  4629.     8  Each class of types that includes the parent type also includes
  4630.        the derived type.
  4631.  
  4632.  8.a    Discussion:  This is inherent in our notion of a ``class'' of
  4633.         types.  It is not mentioned in the initial definition of
  4634.         ``class'' since at that point type derivation has not been
  4635.         defined.  In any case, this rule ensures that every class of
  4636.         types is closed under derivation.
  4637.  
  4638.     9  If the parent type is an elementary type or an array type, then
  4639.        the set of possible values of the derived type is a copy of the
  4640.        set of possible values of the parent type.  For a scalar type,
  4641.        the base range of the derived type is the same as that of the
  4642.        parent type.
  4643.  
  4644.  9.a    Discussion:  The base range of a type defined by an integer_
  4645.         type_definition or a real_type_definition is determined by the
  4646.         _definition, and is not necessarily the same as that of the
  4647.         corresponding root numeric type from which the newly defined
  4648.         type is implicitly derived.  Treating numerics types as
  4649.         implicitly derived from one of the two root numeric types is
  4650.         simply to link them into a type hierarchy; such an implicit
  4651.         derivation does not follow all the rules given here for an
  4652.         explicit derived_type_definition.
  4653.  
  4654.    10  If the parent type is a composite type other than an array type,
  4655.        then the components, protected subprograms, and entries that are
  4656.        declared for the derived type are as follows:
  4657.  
  4658.           11  The discriminants specified by a new known_discriminant_
  4659.               part, if there is one; otherwise, each discriminant of the
  4660.               parent type (implicitly declared in the same order with
  4661.               the same specifications) -- {inherited discriminant}
  4662.               {inherited component} in the latter case, the dis-
  4663.               criminants are said to be inherited, or if unknown in the
  4664.               parent, are also unknown in the derived type;
  4665.  
  4666.           12  Each nondiscriminant component, entry, and protected
  4667.               subprogram of the parent type, implicitly declared in the
  4668.               same order with the same declarations; {inherited
  4669.               component} {inherited protected subprogram} {inherited
  4670.               entry} these components, entries, and protected sub-
  4671.               programs are said to be inherited;
  4672.  
  4673.  12.a   Ramification:  The profiles of entries and protected subprograms
  4674.         do not change upon type derivation, although the type of the
  4675.         ``implicit'' parameter identified by the prefix of the name in a
  4676.         call does.
  4677.  
  4678.  12.b   To be honest:  Any name in the parent type_declaration that
  4679.         denotes the current instance of the type is replaced with a name
  4680.         denoting the current instance of the derived type, converted to
  4681.         the parent type.  {94-4535.d} {94-4537.b}
  4682.  
  4683.           13  Each component declared in a record_extension_part, if
  4684.               any.
  4685.  
  4686.        14   Declarations of components, protected subprograms, and
  4687.        entries, whether implicit or explicit, occur immediately within
  4688.        the declarative region of the type, in the order indicated above,
  4689.        following the parent subtype_indication.
  4690.  
  4691.         14.a   Discussion:  The order of declarations within the region
  4692.         matters for record_aggregates and extension_aggregates.
  4693.  
  4694.         14.b   Ramification:  In most cases, these things are implicitly
  4695.         declared immediately following the parent subtype_indication.
  4696.         However, 7.3.1, ``Private Operations'' defines some cases in
  4697.         which they are implicitly declared later, and some cases in
  4698.         which the are not declared at all.
  4699.  
  4700.         14.c   Discussion:  The place of the implicit declarations of
  4701.         inherited components matters for visibility -- they are not
  4702.         visible in the known_discriminant_part nor in the parent
  4703.         subtype_indication, but are usually visible within the record_
  4704.         extension_part, if any (although there are restrictions on their
  4705.         use).  Note that a discriminant specified in a new known_
  4706.         discriminant_part is not considered ``inherited'' even if it has
  4707.         the same name and subtype as a discriminant of the parent type.
  4708.  
  4709.    15  The derived type is limited if and only if the parent type is
  4710.        limited.
  4711.  
  4712.  15.a   To be honest:  The derived type can become nonlimited if the
  4713.         derivation takes place in the visible part of a child package,
  4714.         and the parent type is nonlimited as viewed from the private
  4715.         part of the child package -- see 7.5.
  4716.  
  4717.    16  [For each predefined operator of the parent type, there is a
  4718.        corresponding predefined operator of the derived type.]
  4719.  
  4720.  16.a   Proof:  This is a ramification of the fact that each class that
  4721.         includes the parent type also includes the derived type, and the
  4722.         fact that the set of predefined operators that is defined for a
  4723.         type, as described in 4.5, is determined by the classes to which
  4724.         it belongs.
  4725.  
  4726.  16.b   Reason:  Predefined operators are handled separately because
  4727.         they follow a slightly different rule than user-defined
  4728.         primitive subprograms.  In particular the systematic replacement
  4729.         described below does not apply fully to the relational operators
  4730.         for Boolean and the exponentiation operator for Integer.  The
  4731.         relational operators for a type derived from Boolean still
  4732.         return Standard.Boolean.  The exponentiation operator for a type
  4733.         derived from Integer still expects Standard.Integer for the
  4734.         right operand.  In addition, predefined operators "reemerge"
  4735.         when a type is the actual type corresponding to a generic formal
  4736.         type, so they need to be well defined even if hidden by
  4737.         user-defined primitive subprograms.
  4738.  
  4739.    17  {inherited subprogram} For each user-defined primitive subprogram
  4740.        (other than a user-defined equality operator -- see below) of the
  4741.        parent type that already exists at the place of the derived_type_
  4742.        definition, there exists a corresponding inherited primitive
  4743.        subprogram of the derived type with the same defining name.
  4744.        {equality operator (special inheritance rule for tagged types)}
  4745.        Primitive user-defined equality operators of the parent type are
  4746.        also inherited by the derived type, except when the derived type
  4747.        is a nonlimited record extension, and the inherited operator
  4748.        would have a profile that is type conformant with the profile of
  4749.        the corresponding predefined equality operator; in this case, the
  4750.        user-defined equality operator is not inherited, but is rather
  4751.        incorporated into the implementation of the predefined equality
  4752.        operator of the record extension (see 4.5.2).  {type conformance
  4753.        [partial]}
  4754.  
  4755.         17.a   Ramification:  We say ``...already exists...'' rather
  4756.         than ``is visible'' or ``has been declared'' because there are
  4757.         certain operations that are declared later, but still exist at
  4758.         the place of the derived_type_definition, and there are
  4759.         operations that are never declared, but still exist.  These
  4760.         cases are explained in 7.3.1.
  4761.  
  4762.         17.b   Note that nonprivate extensions can appear only after the
  4763.         last primitive subprogram of the parent -- the freezing rules
  4764.         ensure this.
  4765.  
  4766.         17.c   Reason:  A special case is made for the equality
  4767.         operators on nonlimited record extensions because their
  4768.         predefined equality operators are already defined in terms of
  4769.         the primitive equality operator of their parent type (and of the
  4770.         tagged components of the extension part).  Inheriting the
  4771.         parent's equality operator as is would be undesirable, because
  4772.         it would ignore any components of the extension part.  On the
  4773.         other hand, if the parent type is limited, then any user-defined
  4774.         equality operator is inherited as is, since there is no
  4775.         predefined equality operator to take its place.
  4776.  
  4777.         17.d   Ramification:  Because user-defined equality operators
  4778.         are not inherited by record extensions, the formal parameter
  4779.         names of = and /= revert to Left and Right, even if different
  4780.         formal parameter names were used in the user-defined equality
  4781.         operators of the parent type.
  4782.  
  4783.        18   The profile of an inherited subprogram (including an
  4784.        inherited enumeration literal) is obtained from the profile of
  4785.        the corresponding (user-defined) primitive subprogram of the
  4786.        parent type, after systematic replacement of each subtype of its
  4787.        profile (see 6.1) that is of the parent type with a corresponding
  4788.        subtype of the derived type.  {corresponding subtype} For a given
  4789.        subtype of the parent type, the corresponding subtype of the
  4790.        derived type is defined as follows:
  4791.  
  4792.           19  If the declaration of the derived type has neither a
  4793.               known_discriminant_part nor a record_extension_part, then
  4794.               the corresponding subtype has a constraint that
  4795.               corresponds (as defined above for the first subtype of the
  4796.               derived type) to that of the given subtype.
  4797.  
  4798.           20  If the derived type is a record extension, then the
  4799.               corresponding subtype is the first subtype of the derived
  4800.               type.
  4801.  
  4802.           21  If the derived type has a new known_discriminant_part but
  4803.               is not a record extension, then the corresponding subtype
  4804.               is constrained to those values that when converted to the
  4805.               parent type belong to the given subtype (see 4.6).
  4806.               {implicit subtype conversion [derived type discriminants]}
  4807.  
  4808.  21.a   Reason:  An inherited subprogram of an untagged type has an
  4809.         Intrinsic calling convention, which precludes the use of the
  4810.         Access attribute.  We preclude 'Access because correctly
  4811.         performing all required constraint checks on an indirect call to
  4812.         such an inherited subprogram was felt to impose an undesirable
  4813.         implementation burden.
  4814.  
  4815.        22   The same formal parameters have default_expressions in the
  4816.        profile of the inherited subprogram.  [Any type mismatch due to
  4817.        the systematic replacement of the parent type by the derived type
  4818.        is handled as part of the normal type conversion associated with
  4819.        parameter passing -- see 6.4.1.]
  4820.  
  4821.         22.a   Reason:  We don't introduce the type conversion
  4822.         explicitly here since conversions to record extensions or on
  4823.         access parameters are not generally legal.  Furthermore, any
  4824.         type conversion would just be "undone" since the parent's
  4825.         subprogram is ultimately being called anyway.
  4826.  
  4827. 23   If a primitive subprogram of the parent type is visible at the place of
  4828. the derived_type_definition, then the corresponding inherited subprogram is
  4829. implicitly declared immediately after the derived_type_definition.  Other-
  4830. wise, the inherited subprogram is implicitly declared later or not at all, as
  4831. explained in 7.3.1.
  4832.  
  4833. 24   {derived type [partial]} A derived type can also be defined by a
  4834. private_extension_declaration (see 7.3) or a formal_derived_type_definition
  4835. (see 12.5.1).  Such a derived type is a partial view of the corresponding
  4836. full or actual type.
  4837.  
  4838. 25   All numeric types are derived types, in that they are implicitly derived
  4839. from a corresponding root numeric type (see 3.5.4 and 3.5.6).
  4840.  
  4841.  
  4842.                               Dynamic Semantics
  4843.  
  4844. 26   {elaboration [derived_type_definition]} The elaboration of a derived_
  4845. type_definition creates the derived type and its first subtype, and consists
  4846. of the elaboration of the subtype_indication and the record_extension_part,
  4847. if any.  If the subtype_indication depends on a discriminant, then only those
  4848. expressions that do not depend on a discriminant are evaluated.  {94-4535.c}
  4849.  
  4850. 27   {execution [call on an inherited subprogram]} For the execution of a
  4851. call on an inherited subprogram, a call on the corresponding primitive
  4852. subprogram of the parent type is performed; the normal conversion of each
  4853. actual parameter to the subtype of the corresponding formal parameter (see
  4854. 6.4.1) performs any necessary type conversion as well.  If the result type of
  4855. the inherited subprogram is the derived type, the result of calling the
  4856. parent's subprogram is converted to the derived type.  {implicit subtype
  4857. conversion [result of inherited function]}
  4858.  
  4859.         27.a   Discussion:  If an inherited function returns the derived
  4860.         type, and the type is a record extension, then the inherited function
  4861.         is abstract, and (unless overridden) cannot be called except via a
  4862.         dispatching call.  See 3.9.3.
  4863.  
  4864.  
  4865.      NOTES
  4866. 28   (10) {closed under derivation} Classes are closed under derivation --
  4867.      any class that contains a type also contains its derivatives.
  4868.      Operations available for a given class of types are available for the
  4869.      derived types in that class.
  4870.  
  4871. 29   (11) Evaluating an inherited enumeration literal is equivalent to
  4872.      evaluating the corresponding enumeration literal of the parent type, and
  4873.      then converting the result to the derived type.  This follows from their
  4874.      equivalence to parameterless functions.  {implicit subtype conversion
  4875.      [inherited enumeration literal]}
  4876.  
  4877. 30   (12) A generic subprogram is not a subprogram, and hence cannot be a
  4878.      primitive subprogram and cannot be inherited by a derived type.  On the
  4879.      other hand, an instance of a generic subprogram can be a primitive
  4880.      subprogram, and hence can be inherited.
  4881.  
  4882. 31   (13) If the parent type is an access type, then the parent and the
  4883.      derived type share the same storage pool; there is a null access value
  4884.      for the derived type and it is the implicit initial value for the type.
  4885.      See 3.10.
  4886.  
  4887. 32   (14) If the parent type is a boolean type, the predefined relational
  4888.      operators of the derived type deliver a result of the predefined type
  4889.      Boolean (see 4.5.2).  If the parent type is an integer type, the right
  4890.      operand of the predefined exponentiation operator is of the predefined
  4891.      type Integer (see 4.5.6).
  4892.  
  4893. 33   (15) Any discriminants of the parent type are either all inherited, or
  4894.      completely replaced with a new set of discriminants.
  4895.  
  4896. 34   (16) For an inherited subprogram, the subtype of a formal parameter of
  4897.      the derived type need not have any value in common with the first
  4898.      subtype of the derived type.
  4899.  
  4900.    34.a   Proof:  This happens when the parent subtype is constrained to a
  4901.         range that does not overlap with the range of a subtype of the parent
  4902.         type that appears in the profile of some primitive subprogram of the
  4903.         parent type.  For example:
  4904.  
  4905. 34.b        type T1 is range 1..100;
  4906.             subtype S1 is T1 range 1..10;
  4907.             procedure P(X : in S1);  -- P is a primitive subprogram
  4908.             type T2 is new T1 range 11..20;
  4909.             -- implicitly declared:
  4910.             -- procedure P(X : in T2'Base range 1..10);
  4911.             --      X cannot be in T2'First .. T2'Last
  4912.  
  4913. 35   (17) If the reserved word abstract is given in the declaration of a
  4914.      type, the type is abstract (see 3.9.3).
  4915.  
  4916.  
  4917.                                   Examples
  4918.  
  4919. 36   Examples of derived type declarations:
  4920.  
  4921. 37  type Local_Coordinate is new Coordinate;   --  two different types
  4922.     type Midweek is new Day range Tue .. Thu;  --  see 3.5.1
  4923.     type Counter is new Positive;              --  same range as Positive
  4924.  
  4925. 38  type Special_Key is new Key_Manager.Key;   --  see 7.3.1
  4926.       -- the inherited subprograms have the following specifications:
  4927.       --         procedure Get_Key(K : out Special_Key);
  4928.       --         function "<"(X,Y : Special_Key) return Boolean;
  4929.  
  4930.  
  4931.                          Inconsistencies With Ada 83
  4932.  
  4933.         38.a   {inconsistencies with Ada 83} When deriving from a
  4934.         (nonprivate, nonderived) type in the same visible part in which it is
  4935.         defined, if a predefined operator had been overridden prior to the
  4936.         derivation, the derived type will inherit the user-defined operator
  4937.         rather than the predefined operator.  The work-around (if the new
  4938.         behavior is not the desired behavior) is to move the definition of
  4939.         the derived type prior to the overriding of any predefined operators.
  4940.  
  4941.                         Incompatibilities With Ada 83
  4942.  
  4943.         38.b   {incompatibilities with Ada 83} When deriving from a
  4944.         (nonprivate, nonderived) type in the same visible part in which it is
  4945.         defined, a primitive subprogram of the parent type declared before
  4946.         the derived type will be inherited by the derived type.  This can
  4947.         cause upward incompatibilities in cases like this:
  4948.  
  4949. 38.c           package P is
  4950.                   type T is (A, B, C, D);
  4951.                   function F( X : T := A ) return Integer;
  4952.                   type NT is new T;
  4953.                   -- inherits F as
  4954.                   -- function F( X : NT := A ) return Integer;
  4955.                   -- in Ada 9X only
  4956.                   ...
  4957.                end P;
  4958.                ...
  4959.                use P;  -- Only one declaration of F from P is use-visible in
  4960.                        -- Ada 83;  two declarations of F are use-visible in
  4961.                        -- Ada 9X.
  4962.             begin
  4963.                ...
  4964.                if F > 1 then ... -- legal in Ada 83, ambiguous in Ada 9X
  4965.  
  4966.                             Extensions to Ada 83
  4967.  
  4968.         38.d   {extensions to Ada 83} The syntax for a derived_type_
  4969.         definition is amended to include an optional record_extension_part
  4970.         (see 3.9.1).
  4971.  
  4972.         38.e   A derived type may override the discriminants of the parent by
  4973.         giving a new discriminant_part.  {94-4535.a}
  4974.  
  4975.         38.f   The parent type in a derived_type_definition may be a derived
  4976.         type defined in the same visible part.
  4977.  
  4978.         38.g   When deriving from a type in the same visible part in which it
  4979.         is defined, the primitive subprograms declared prior to the
  4980.         derivation are inherited as primitive subprograms of the derived
  4981.         type.  See 3.2.3.
  4982.  
  4983.                          Wording Changes From Ada 83
  4984.  
  4985.         38.h   We now talk about the classes to which a type belongs, rather
  4986.         than a single class.
  4987.  
  4988.         38.i   As explained in Section 13, the concept of "storage pool"
  4989.         replaces the Ada 83 concept of "collection."  These concepts are
  4990.         similar, but not the same.
  4991.  
  4992.  
  4993.  
  4994. 3.4.1 Derivation Classes
  4995.  
  4996. 1   In addition to the various language-defined classes of types, types can
  4997. be grouped into derivation classes.
  4998.  
  4999.  
  5000.                               Static Semantics
  5001.  
  5002. 2   {derived from (directly or indirectly)} A derived type is derived from
  5003. its parent type directly; it is derived indirectly from any type from which
  5004. its parent type is derived.  {derivation class (for a type)} {root type (of a
  5005. class)} {rooted at a type} The derivation class of types for a type T (also
  5006. called the class rooted at T) is the set consisting of T (the root type of
  5007. the class) and all types derived from T (directly or indirectly) plus any
  5008. associated universal or class-wide types (defined below).
  5009.  
  5010.         2.a   Discussion:  Note that the definition of ``derived from'' is a
  5011.         recursive definition.  We don't define a root type for all
  5012.         interesting language-defined classes, though presumably we could.
  5013.  
  5014.         2.b   To be honest:  By the class-wide type ``associated'' with a
  5015.         type T, we mean the type T'Class.  Similarly, the universal type
  5016.         associated with root_integer, root_real, and root_fixed are
  5017.         universal_integer, universal_real, and universal_fixed, respectively.
  5018.  
  5019. 3   Every type is either a specific type, a class-wide type, or a universal
  5020. type.  {specific type} A specific type is one defined by a type_declaration,
  5021. a formal_type_declaration, or a full type definition embedded in a
  5022. declaration for an object.  Class-wide and universal types are implicitly
  5023. defined, to act as representatives for an entire class of types, as follows:
  5024.  
  5025.         3.a   To be honest:  The root types root_integer, root_real, and
  5026.         root_fixed are also specific types.  They are declared in the
  5027.         specification of package Standard.
  5028.  
  5029. 4   {class-wide type} Class-wide types
  5030.                 Class-wide types are defined for [(and belong to)] each
  5031.                 derivation class rooted at a tagged type (see 3.9).  Given a
  5032.                 subtype S of a tagged type T, S'Class is the subtype_mark for
  5033.                 a corresponding subtype of the tagged class-wide type
  5034.                 T'Class.  Such types are called ``class-wide'' because when a
  5035.                 formal parameter is defined to be of a class-wide type
  5036.                 T'Class, an actual parameter of any type in the derivation
  5037.                 class rooted at T is acceptable (see 8.6).
  5038.  
  5039.                 5   {first subtype} The set of values for a class-wide type
  5040.                 T'Class is the discriminated union of the set of values of
  5041.                 each specific type in the derivation class rooted at T (the
  5042.                 tag acts as the implicit discriminant -- see 3.9).
  5043.                 Class-wide types have no primitive subprograms of their own.
  5044.                 However, as explained in 3.9.2, operands of a class-wide type
  5045.                 T'Class can be used as part of a dispatching call on a
  5046.                 primitive subprogram of the type T.  The only components
  5047.                 [(including discriminants)] of T'Class that are visible are
  5048.                 those of T.  If S is a first subtype, then S'Class is a first
  5049.                 subtype.
  5050.  
  5051.         5.a   Reason:  We want S'Class to be a first subtype when S is, so
  5052.         that an attribute_definition_clause like ``for S'Class'Output use
  5053.         ...;'' will be legal.
  5054.  
  5055. 6   {universal type} Universal types
  5056.                 Universal types are defined for [(and belong to)] the
  5057.                 integer, real, and fixed point classes, and are referred to
  5058.                 in this standard as respectively, universal_integer,
  5059.                 universal_real, and universal_fixed.  These are analogous to
  5060.                 class-wide types for these language-defined numeric classes.
  5061.                 As with class-wide types, if a formal parameter is of a
  5062.                 universal type, then an actual parameter of any type in the
  5063.                 corresponding class is acceptable.  In addition, a value of a
  5064.                 universal type (including an integer or real numeric_literal)
  5065.                 is ``universal'' in that it is acceptable where some
  5066.                 particular type in the class is expected (see 8.6).
  5067.  
  5068.                 7   The set of values of a universal type is the
  5069.                 undiscriminated union of the set of values possible for any
  5070.                 definable type in the associated class.  Like class-wide
  5071.                 types, universal types have no primitive subprograms of their
  5072.                 own.  However, their ``universality'' allows them to be used
  5073.                 as operands with the primitive subprograms of any type in the
  5074.                 corresponding class.
  5075.  
  5076.         7.a   Discussion:  A class-wide type is only class-wide in one
  5077.         direction, from specific to class-wide, whereas a universal type is
  5078.         class-wide (universal) in both directions, from specific to universal
  5079.         and back.
  5080.  
  5081.         7.b   We considered defining class-wide or perhaps universal types
  5082.         for all derivation classes, not just tagged classes and these three
  5083.         numeric classes.  However, this was felt to overly weaken the
  5084.         strong-typing model in some situations.  Tagged types preserve strong
  5085.         type distinctions thanks to the run-time tag.  Class-wide or
  5086.         universal types for untagged types would weaken the compile-time type
  5087.         distinctions without providing a compensating run-time-checkable
  5088.         distinction.
  5089.  
  5090.         7.c   We considered defining standard names for the universal numeric
  5091.         types so they could be used in formal parameter specifications.
  5092.         However, this was felt to impose an undue implementation burden for
  5093.         some implementations.
  5094.  
  5095.         7.d   To be honest:  Formally, the set of values of a universal type
  5096.         is actually a copy of the undiscriminated union of the values of the
  5097.         types in its class.  This is because we want each value to have
  5098.         exactly one type, with explicit or implicit conversion needed to go
  5099.         between types.  An alternative, consistent model would be to
  5100.         associate a class, rather than a particular type, with a value, even
  5101.         though any given expression would have a particular type.  In that
  5102.         case, implicit type conversions would not generally need to change
  5103.         the value, although an associated subtype conversion might need to.
  5104.  
  5105. 8   {root_integer [partial]} {root_real [partial]} The integer and real
  5106. numeric classes each have a specific root type in addition to their universal
  5107. type, named respectively root_integer and root_real.
  5108.  
  5109. 9   {cover (a type)} A class-wide or universal type is said to cover all of
  5110. the types in its class.  A specific type covers only itself.
  5111.  
  5112. 10   {descendant (of a type)} A specific type T2 is defined to be a
  5113. descendant of a type T1 if T2 is the same as T1, or if T2 is derived
  5114. (directly or indirectly) from T1.  A class-wide type T2'Class is defined to
  5115. be a descendant of type T1 if T2 is a descendant of T1.  Similarly, the
  5116. universal types are defined to be descendants of the root types of their
  5117. classes.  {ancestor (of a type)} If a type T2 is a descendant of a type T1,
  5118. then T1 is called an ancestor of T2.  {ultimate ancestor (of a type)}
  5119. {ancestor (ultimate)} The ultimate ancestor of a type is the ancestor of the
  5120. type that is not a descendant of any other type.
  5121.  
  5122.         10.a   Ramification:  A specific type is a descendant of itself.
  5123.         Class-wide types are considered descendants of the corresponding
  5124.         specific type, and do not have any descendants of their own.
  5125.  
  5126.         10.b   A specific type is an ancestor of itself.  The root of a
  5127.         derivation class is an ancestor of all types in the class, including
  5128.         any class-wide types in the class.
  5129.  
  5130.         10.c   Discussion:  The terms root, parent, ancestor, and ultimate
  5131.         ancestor are all related.  For example:
  5132.  
  5133.          10.d  Each type has at most one parent, and one or more
  5134.                ancestor types; each type has exactly one ultimate
  5135.                ancestor.  In Ada 83, the term ``parent type'' was
  5136.                sometimes used more generally to include any ancestor
  5137.                type (e.g. RM83-9.4(14)).  In Ada 9X, we restrict parent
  5138.                to mean the immediate ancestor.
  5139.  
  5140.          10.e  A class of types has at most one root type; a derivation
  5141.                class has exactly one root type.
  5142.  
  5143.          10.f  The root of a class is an ancestor of all of the types in
  5144.                the class (including itself).
  5145.  
  5146.          10.g  The type root_integer is the root of the integer class,
  5147.                and is the ultimate ancestor of all integer types.  A
  5148.                similar statement applies to root_real.
  5149.  
  5150. 11   {inherited (from an ancestor type)} An inherited component [(including
  5151. an inherited discriminant)] of a derived type is inherited from a given
  5152. ancestor of the type if the corresponding component was inherited by each
  5153. derived type in the chain of derivations going back to the given ancestor.
  5154.  
  5155.  
  5156.      NOTES
  5157. 12   (18) Because operands of a universal type are acceptable to the
  5158.      predefined operators of any type in their class, ambiguity can result.
  5159.      For universal_integer and universal_real, this potential ambiguity is
  5160.      resolved by giving a preference (see 8.6) to the predefined operators of
  5161.      the corresponding root types (root_integer and root_real, respectively).
  5162.      Hence, in an apparently ambiguous expression like
  5163.  
  5164. 13       1 + 4 < 7
  5165.  
  5166.      14   where each of the literals is of type universal_integer, the
  5167.      predefined operators of root_integer will be preferred over those of
  5168.      other specific integer types, thereby resolving the ambiguity.
  5169.  
  5170.         14.a   Ramification:  Except for this preference, a root numeric type
  5171.         is essentially like any other specific type in the associated numeric
  5172.         class.  In particular, the result of a predefined operator of a root
  5173.         numeric type is not ``universal'' (implicitly convertible) even if
  5174.         both operands were.
  5175.  
  5176.  
  5177.  
  5178. 3.5 Scalar Types
  5179.  
  5180. 1   {scalar type} Scalar types comprise enumeration types, integer types, and
  5181. real types.  {discrete type} Enumeration types and integer types are called
  5182. discrete types; {position number} each value of a discrete type has a
  5183. position number which is an integer value.  {numeric type} Integer types and
  5184. real types are called numeric types.  [All scalar types are ordered, that is,
  5185. all relational operators are predefined for their values.]
  5186.  
  5187.  
  5188.                                    Syntax
  5189.  
  5190. 2   range_constraint ::=  range range
  5191.  
  5192. 3   range ::=  range_attribute_reference
  5193.        | simple_expression .. simple_expression
  5194.  
  5195.  
  5196.         3.a   Discussion:  These need to be simple_expressions rather than
  5197.         more general expressions because ranges appear in membership tests
  5198.         and other contexts where expression .. expression would be ambiguous.
  5199.  
  5200. 4   {range} {lower bound (of a range)} {upper bound (of a range)} {type of a
  5201. range} A range has a lower bound and an upper bound and specifies a subset of
  5202. the values of some scalar type (the type of the range).  A range with lower
  5203. bound L and upper bound R is described by ``L .. R''.  {null range} If R is
  5204. less than L, then the range is a null range, and specifies an empty set of
  5205. values.  Otherwise, the range specifies the values of the type from the lower
  5206. bound to the upper bound, inclusive.  {belong (to a range)} A value belongs
  5207. to a range if it is of the type of the range, and is in the subset of values
  5208. specified by the range.  {satisfies [a range constraint]} A value satisfies a
  5209. range constraint if it belongs to the associated range.  {included (one range
  5210. in another)} One range is included in another if all values that belong to
  5211. the first range also belong to the second.
  5212.  
  5213.  
  5214.                             Name Resolution Rules
  5215.  
  5216. 5   {expected type [range_constraint range]} For a subtype_indication
  5217. containing a range_constraint, either directly or as part of some other
  5218. scalar_constraint, the type of the range shall resolve to that of the type
  5219. determined by the subtype_mark of the subtype_indication.  {expected type
  5220. [range simple_expressions]} For a range of a given type, the simple_
  5221. expressions of the range (likewise, the simple_expressions of the equivalent
  5222. range for a range_attribute_reference) are expected to be of the type of the
  5223. range.
  5224.  
  5225.         5.a   Discussion:  In Ada 9X, constraints only appear within subtype_
  5226.         indications; things that look like constraints that appear in type
  5227.         declarations are called something else like range_specifications.
  5228.  
  5229.         5.b   We say "the expected type is ..." or "the type is expected to
  5230.         be ..."  depending on which reads better.  They are fundamentally
  5231.         equivalent, and both feed into the type resolution rules of clause
  5232.         8.6.
  5233.  
  5234.         5.c   In some cases, it doesn't work to use expected types.  For
  5235.         example, in the above rule, we say that the ``type of the range shall
  5236.         resolve to ...''  rather than ``the expected type for the range is
  5237.         ...''.  We then use ``expected type'' for the bounds.  If we used
  5238.         ``expected'' at both points, there would be an ambiguity, since one
  5239.         could apply the rules of 8.6 either on determining the type of the
  5240.         range, or on determining the types of the individual bounds.  It is
  5241.         clearly important to allow one bound to be of a universal type, and
  5242.         the other of a specific type, so we need to use ``expected type'' for
  5243.         the bounds.  Hence, we used ``shall resolve to'' for the type of the
  5244.         range as a whole.  There are other situations where ``expected type''
  5245.         is not quite right, and we use ``shall resolve to'' instead.
  5246.  
  5247.  
  5248.                               Static Semantics
  5249.  
  5250. 6   {base range (of a scalar type) [distributed]} The base range of a scalar
  5251. type is the range of finite values of the type that can be represented in
  5252. every unconstrained object of the type; it is also the range supported at a
  5253. minimum for intermediate values during the evaluation of expressions
  5254. involving predefined operators of the type.
  5255.  
  5256.         6.a   Implementation Note:  Note that in some machine architectures
  5257.         intermediates in an expression (particularly if static), and
  5258.         register-resident variables might accommodate a wider range.  The
  5259.         base range does not include the values of this wider range that are
  5260.         not assignable without overflow to memory-resident objects.
  5261.  
  5262.         6.b   Ramification:  {base range [of an enumeration type]} The base
  5263.         range of an enumeration type is the range of values of the
  5264.         enumeration type.
  5265.  
  5266.         6.c   Reason:  If the representation supports infinities, the base
  5267.         range is nevertheless restricted to include only the representable
  5268.         finite values, so that 'Base'First and 'Base'Last are always
  5269.         guaranteed to be finite.
  5270.  
  5271.         6.d   To be honest:  By a "value that can be assigned without
  5272.         overflow" we don't mean to restrict ourselves to values that can be
  5273.         represented exactly.  Values between machine representable values can
  5274.         be assigned, but on subsequent reading, a slightly different value
  5275.         might be retrieved, as (partially) determined by the number of digits
  5276.         of precision of the type.
  5277.  
  5278. 7   {constrained (subtype)} {unconstrained (subtype)} [A constrained scalar
  5279. subtype is one to which a range constraint applies.]  {range (of a scalar
  5280. subtype)} The range of a constrained scalar subtype is the range associated
  5281. with the range constraint of the subtype.  The range of an unconstrained
  5282. scalar subtype is the base range of its type.
  5283.  
  5284.  
  5285.                               Dynamic Semantics
  5286.  
  5287. 8   {compatibility [range with a scalar subtype]} A range is compatible with
  5288. a scalar subtype if and only if it is either a null range or each bound of
  5289. the range belongs to the range of the subtype.  {compatibility [range_
  5290. constraint with a scalar subtype]} A range_constraint is compatible with a
  5291. scalar subtype if and only if its range is compatible with the subtype.
  5292.  
  5293.         8.a   Ramification:  Only range_constraints (explicit or implicit)
  5294.         impose conditions on the values of a scalar subtype.  The other
  5295.         scalar_constraints, digit_constraints and delta_constraints impose
  5296.         conditions on the subtype denoted by the subtype_mark in a subtype_
  5297.         indication, but don't impose a condition on the values of the subtype
  5298.         being defined.  Therefore, a scalar subtype is not called constrained
  5299.         if all that applies to it is a digits_constraint.  Decimal subtypes
  5300.         are subtle, because a digits_constraint without a range_constraint
  5301.         nevertheless includes an implicit range_constraint.
  5302.  
  5303. 9   {elaboration [range_constraint]} The elaboration of a range_constraint
  5304. consists of the evaluation of the range.  {evaluation [range]} The evaluation
  5305. of a range determines a lower bound and an upper bound.  If simple_
  5306. expressions are given to specify bounds, the evaluation of the range
  5307. evaluates these simple_expressions in an arbitrary order, and converts them
  5308. to the type of the range.  {implicit subtype conversion [bounds of a range]}
  5309. If a range_attribute_reference is given, the evaluation of the range consists
  5310. of the evaluation of the range_attribute_reference.
  5311.  
  5312. 10   Attributes
  5313.  
  5314. 11   For every scalar subtype S, the following attributes are defined:
  5315.  
  5316. 12  S'First
  5317.                 S'First denotes the lower bound of the range of S. The value
  5318.                 of this attribute is of the type of S.
  5319.  
  5320. 12.a    Ramification:  Evaluating S'First never raises Constraint_Error.
  5321.  
  5322. 13  S'Last
  5323.                 S'Last denotes the upper bound of the range of S. The value
  5324.                 of this attribute is of the type of S.
  5325.  
  5326. 13.a    Ramification:  Evaluating S'Last never raises Constraint_Error.
  5327.  
  5328. 14  S'Range
  5329.                 S'Range is equivalent to the range S'First .. S'Last.
  5330.  
  5331. 15  {base subtype (of a type)} S'Base
  5332.                 S'Base denotes an unconstrained subtype of the type of
  5333.                 S. This unconstrained subtype is called the base subtype of
  5334.                 the type.
  5335.  
  5336. 16  S'Min
  5337.                 S'Min denotes a function with the following specification:
  5338.  
  5339. 17                  function S'Min(Left, Right : S'Base)
  5340.                       return S'Base
  5341.  
  5342.                 18   The function returns the lesser of the values of the two
  5343.                 parameters.
  5344.  
  5345. 18.a    Discussion:  {italics (formal parameters of attribute functions)} The
  5346.         formal parameter names are italicized because they cannot be used in
  5347.         calls -- see 6.4.  Such a specification cannot be written by the user
  5348.         because an attribute_reference is not permitted as the designator of
  5349.         a user-defined function, nor can its formal parameters be anonymous.
  5350.  
  5351. 19  S'Max
  5352.                 S'Max denotes a function with the following specification:
  5353.  
  5354. 20                  function S'Max(Left, Right : S'Base)
  5355.                       return S'Base
  5356.  
  5357.                 21   The function returns the greater of the values of the
  5358.                 two parameters.
  5359.  
  5360. 22  S'Succ
  5361.                 S'Succ denotes a function with the following specification:
  5362.  
  5363. 23                  function S'Succ(Arg : S'Base)
  5364.                       return S'Base
  5365.  
  5366.                 24   {Constraint_Error (raised by failure of run-time check)}
  5367.                 For an enumeration type, the function returns the value whose
  5368.                 position number is one more than that of the value of Arg;
  5369.                 {Range_Check [partial]} {check, language-defined (Range_
  5370.                 Check)} Constraint_Error is raised if there is no such value
  5371.                 of the type.  For an integer type, the function returns the
  5372.                 result of adding one to the value of Arg.  For a fixed point
  5373.                 type, the function returns the result of adding small to the
  5374.                 value of Arg.  For a floating point type, the function
  5375.                 returns the machine number (as defined in 3.5.7) immediately
  5376.                 above the value of Arg; {Range_Check [partial]} {check,
  5377.                 language-defined (Range_Check)} Constraint_Error is raised if
  5378.                 there is no such machine number.
  5379.  
  5380. 24.a    Ramification:  S'Succ for a modular integer subtype wraps around if
  5381.         the value of Arg is S'Base'Last.  S'Succ for a signed integer subtype
  5382.         might raise Constraint_Error if the value of Arg is S'Base'Last, or
  5383.         it might return the out-of-base-range value S'Base'Last+1, as is
  5384.         permitted for all predefined numeric operations.
  5385.  
  5386. 25  S'Pred
  5387.                 S'Pred denotes a function with the following specification:
  5388.  
  5389. 26                  function S'Pred(Arg : S'Base)
  5390.                       return S'Base
  5391.  
  5392.                 27   {Constraint_Error (raised by failure of run-time check)}
  5393.                 For an enumeration type, the function returns the value whose
  5394.                 position number is one less than that of the value of Arg;
  5395.                 {Range_Check [partial]} {check, language-defined (Range_
  5396.                 Check)} Constraint_Error is raised if there is no such value
  5397.                 of the type.  For an integer type, the function returns the
  5398.                 result of subtracting one from the value of Arg.  For a fixed
  5399.                 point type, the function returns the result of subtracting
  5400.                 small from the value of Arg.  For a floating point type, the
  5401.                 function returns the machine number (as defined in 3.5.7)
  5402.                 immediately below the value of Arg; {Range_Check [partial]}
  5403.                 {check, language-defined (Range_Check)} Constraint_Error is
  5404.                 raised if there is no such machine number.
  5405.  
  5406. 27.a    Ramification:  S'Pred for a modular integer subtype wraps around if
  5407.         the value of Arg is S'Base'First.  S'Pred for a signed integer
  5408.         subtype might raise Constraint_Error if the value of Arg is
  5409.         S'Base'First, or it might return the out-of-base-range value
  5410.         S'Base'First-1, as is permitted for all predefined numeric
  5411.         operations.
  5412.  
  5413. 28  S'Wide_Image
  5414.                 S'Wide_Image denotes a function with the following
  5415.                 specification:
  5416.  
  5417. 29                  function S'Wide_Image(Arg : S'Base)
  5418.                       return Wide_String
  5419.  
  5420.                 30   {image (of a value)} The function returns an image of
  5421.                 the value of Arg, that is, a sequence of characters
  5422.                 representing the value in display form.  The lower bound of
  5423.                 the result is one.
  5424.  
  5425.                 31   The image of an integer value is the corresponding
  5426.                 decimal literal, without underlines, leading zeros, exponent,
  5427.                 or trailing spaces, but with a single leading character that
  5428.                 is either a minus sign or a space.
  5429.  
  5430.         31.a   Implementation Note:  If the machine supports negative zeros
  5431.         for signed integer types, it is not specified whether "-0" or " 0"
  5432.         should be returned for negative zero.  We don't have enough
  5433.         experience with such machines to know what is appropriate, and what
  5434.         other languages do.  In any case, the implementation should be
  5435.         consistent.
  5436.  
  5437.                 32   {nongraphic character} The image of an enumeration value
  5438.                 is either the corresponding identifier in upper case or the
  5439.                 corresponding character literal (including the two
  5440.                 apostrophes); neither leading nor trailing spaces are
  5441.                 included.  For a nongraphic character (a value of a character
  5442.                 type that has no enumeration literal associated with it), the
  5443.                 result is a corresponding language-defined or implementation-
  5444.                 defined name in upper case (for example, the image of the
  5445.                 nongraphic character identified as nul is ``NUL'' -- the
  5446.                 quotes are not part of the image).
  5447.  
  5448.         32.a   Implementation Note:  For an enumeration type T that has
  5449.         ``holes'' (caused by an enumeration_representation_clause), {Program_
  5450.         Error (raised by failure of run-time check)} T'Wide_Image should
  5451.         raise Program_Error if the value is one of the holes (which is a
  5452.         bounded error anyway, since holes can be generated only via
  5453.         uninitialized variables and similar things.
  5454.  
  5455.                 33   The image of a floating point value is a decimal real
  5456.                 literal best approximating the value (rounded away from zero
  5457.                 if halfway between) with a single leading character that is
  5458.                 either a minus sign or a space, a single digit (that is
  5459.                 nonzero unless the value is zero), a decimal point,
  5460.                 S'Digits-1 (see 3.5.8) digits after the decimal point (but
  5461.                 one if S'Digits is one), an upper case E, the sign of the
  5462.                 exponent (either + or -), and two or more digits (with
  5463.                 leading zeros if necessary) representing the exponent.  If
  5464.                 S'Signed_Zeros is True, then the leading character is a minus
  5465.                 sign for a negatively signed zero.  {94-4526.b}
  5466.  
  5467.         33.a   To be honest:  Leading zeros are present in the exponent only
  5468.         if necessary to make the exponent at least two digits.
  5469.  
  5470.         33.b   Reason:  This image is intended to conform to that produced by
  5471.         Text_IO.Float_IO.Put in its default format.
  5472.  
  5473.         33.c   Implementation Note:  The rounding direction is specified here
  5474.         to ensure portability of output results.
  5475.  
  5476.                 34   The image of a fixed point value is a decimal real
  5477.                 literal best approximating the value (rounded away from zero
  5478.                 if halfway between) with a single leading character that is
  5479.                 either a minus sign or a space, one or more digits before the
  5480.                 decimal point (with no redundant leading zeros), a decimal
  5481.                 point, and S'Aft (see 3.5.10) digits after the decimal point.
  5482.  
  5483.         34.a   Reason:  This image is intended to conform to that produced by
  5484.         Text_IO.Fixed_IO.Put.
  5485.  
  5486.         34.b   Implementation Note:  The rounding direction is specified here
  5487.         to ensure portability of output results.
  5488.  
  5489.         34.c   Implementation Note:  For a machine that supports negative
  5490.         zeros, it is not specified whether "-0.000" or " 0.000" is returned.
  5491.         See corresponding comment above about integer types with signed
  5492.         zeros.
  5493.  
  5494. 35  S'Image
  5495.                 S'Image denotes a function with the following specification:
  5496.  
  5497. 36                  function S'Image(Arg : S'Base)
  5498.                       return String
  5499.  
  5500.                 37   The function returns an image of the value of Arg as a
  5501.                 String.  The lower bound of the result is one.  The image has
  5502.                 the same sequence of graphic characters as that defined for
  5503.                 S'Wide_Image if all the graphic characters are defined in
  5504.                 Character; otherwise the sequence of characters is
  5505.                 implementation defined (but no shorter than that of S'Wide_
  5506.                 Image for the same value of Arg).
  5507.  
  5508.         37.a   Implementation defined:  The sequence of characters of the
  5509.         value returned by S'Image when some of the graphic characters of
  5510.         S'Wide_Image are not defined in Character.
  5511.  
  5512. 38  S'Wide_Width
  5513.                 S'Wide_Width denotes the maximum length of a Wide_String
  5514.                 returned by S'Wide_Image over all values of the subtype S. It
  5515.                 denotes zero for a subtype that has a null range.  Its type
  5516.                 is universal_integer.
  5517.  
  5518. 38.a    Change:  Added Wide_Width attribute as per WG9 resolution.
  5519.  
  5520. 39  S'Width
  5521.                 S'Width denotes the maximum length of a String returned by
  5522.                 S'Image over all values of the subtype S. It denotes zero for
  5523.                 a subtype that has a null range.  Its type is universal_
  5524.                 integer.
  5525.  
  5526. 40  S'Wide_Value
  5527.                 S'Wide_Value denotes a function with the following
  5528.                 specification:
  5529.  
  5530. 41                  function S'Wide_Value(Arg : Wide_String)
  5531.                       return S'Base
  5532.  
  5533.                 42   This function returns a value given an image of the
  5534.                 value as a Wide_String, ignoring any leading or trailing
  5535.                 spaces.
  5536.  
  5537.                 43   {evaluation [Wide_Value]} {Constraint_Error (raised by
  5538.                 failure of run-time check)} For the evaluation of a call on
  5539.                 S'Wide_Value for an enumeration subtype S, if the sequence of
  5540.                 characters of the parameter (ignoring leading and trailing
  5541.                 spaces) has the syntax of an enumeration literal and if it
  5542.                 corresponds to a literal of the type of S (or corresponds to
  5543.                 the result of S'Wide_Image for a nongraphic character of the
  5544.                 type), the result is the corresponding enumeration value;
  5545.                 {Range_Check [partial]} {check, language-defined (Range_
  5546.                 Check)} otherwise Constraint_Error is raised.
  5547.  
  5548.         43.a   Discussion:  It's not crystal clear that Range_Check is
  5549.         appropriate here, but it doesn't seem worthwhile to invent a whole
  5550.         new check name just for this weird case, so we decided to lump it in
  5551.         with Range_Check.
  5552.  
  5553.                 44   {Constraint_Error (raised by failure of run-time check)}
  5554.                 For the evaluation of a call on S'Wide_Value (or S'Value) for
  5555.                 an integer subtype S, if the sequence of characters of the
  5556.                 parameter (ignoring leading and trailing spaces) has the
  5557.                 syntax of an integer literal, with an optional leading sign
  5558.                 character (plus or minus for a signed type; only plus for a
  5559.                 modular type), and the corresponding numeric value belongs to
  5560.                 the base range of the type of S, then that value is the
  5561.                 result; {Range_Check [partial]} {check, language-defined
  5562.                 (Range_Check)} otherwise Constraint_Error is raised.
  5563.  
  5564.         44.a   Change:  Changed the syntax accepted by Wide_Value for modular
  5565.         types to match Modular_IO.Get; the intent is that these be the same.
  5566.         In particular, the number can have a plus sign or no sign; it cannot
  5567.         have a minus sign.
  5568.  
  5569.         44.b   Discussion:  We considered allowing 'Value to return a
  5570.         representable but out-of-range value without a Constraint_Error.
  5571.         However, we currently require (see 4.9) in an assignment_statement
  5572.         like "X := <numeric_literal>;" that the value of the numeric-literal
  5573.         be in X's base range (at compile time), so it seems unfriendly and
  5574.         confusing to have a different range allowed for 'Value.  Furthermore,
  5575.         for modular types, without the requirement for being in the base
  5576.         range, 'Value would have to handle arbitrarily long literals (since
  5577.         overflow never occurs for modular types).
  5578.  
  5579.                 45   For the evaluation of a call on S'Wide_Value (or
  5580.                 S'Value) for a real subtype S, if the sequence of characters
  5581.                 of the parameter (ignoring leading and trailing spaces) has
  5582.                 the syntax of one of the following:
  5583.  
  5584.                    46  numeric_literal
  5585.  
  5586.                    47  numeral.[exponent]
  5587.  
  5588.                    48  .numeral[exponent]
  5589.  
  5590.                    49  base#based_numeral.#[exponent]
  5591.  
  5592.                    50  base#.based_numeral#[exponent]
  5593.  
  5594.                 51   {Constraint_Error (raised by failure of run-time check)}
  5595.                 with an optional leading sign character (plus or minus), and
  5596.                 if the corresponding numeric value belongs to the base range
  5597.                 of the type of S, then that value is the result; {Range_Check
  5598.                 [partial]} {check, language-defined (Range_Check)} otherwise
  5599.                 Constraint_Error is raised.  The sign of a zero value is
  5600.                 preserved (positive if none has been specified) if S'Signed_
  5601.                 Zeros is True.  {94-4526.b}
  5602.  
  5603. 52  S'Value
  5604.                 S'Value denotes a function with the following specification:
  5605.  
  5606. 53                  function S'Value(Arg : String)
  5607.                       return S'Base
  5608.  
  5609.                 54   This function returns a value given an image of the
  5610.                 value as a String, ignoring any leading or trailing spaces.
  5611.  
  5612.                 55   {evaluation [Value]} {Constraint_Error (raised by
  5613.                 failure of run-time check)} For the evaluation of a call on
  5614.                 S'Value for an enumeration subtype S, if the sequence of
  5615.                 characters of the parameter (ignoring leading and trailing
  5616.                 spaces) has the syntax of an enumeration literal and if it
  5617.                 corresponds to a literal of the type of S (or corresponds to
  5618.                 the result of S'Image for a value of the type), the result is
  5619.                 the corresponding enumeration value; {Range_Check [partial]}
  5620.                 {check, language-defined (Range_Check)} otherwise Constraint_
  5621.                 Error is raised.  For a numeric subtype S, the evaluation of
  5622.                 a call on S'Value with Arg of type String is equivalent to a
  5623.                 call on S'Wide_Value for a corresponding Arg of type Wide_
  5624.                 String.
  5625.  
  5626.         55.a   Reason:  S'Value is subtly different from S'Wide_Value for
  5627.         enumeration subtypes since S'Image might produce a different sequence
  5628.         of characters than S'Wide_Image if the enumeration literal uses
  5629.         characters outside of the predefined type Character.  That is why we
  5630.         don't just define S'Value in terms of S'Wide_Value for enumeration
  5631.         subtypes.  S'Value and S'Wide_Value for numeric subtypes yield the
  5632.         same result given the same sequence of characters.
  5633.  
  5634.  
  5635.                          Implementation Permissions
  5636.  
  5637. 56   An implementation may extend the Wide_Value, [Value, Wide_Image, and
  5638. Image] attributes of a floating point type to support special values such as
  5639. infinities and NaNs.  {94-4526.c} {94-4893.d} {94-4901.a}
  5640.  
  5641.         56.a   Proof:  The permission is really only necessary for Wide_
  5642.         Value, because Value is defined in terms of Wide_Value, and because
  5643.         the behavior of Wide_Image and Image is already unspecified for
  5644.         things like infinities and NaNs.
  5645.  
  5646.         56.b   Reason:  This is to allow implementations to define full
  5647.         support for IEEE arithmetic.  See also the similar permission for Get
  5648.         in A.10.9.
  5649.  
  5650.  
  5651.      NOTES
  5652. 57   (19) The evaluation of S'First or S'Last never raises an exception.  If
  5653.      a scalar subtype S has a nonnull range, S'First and S'Last belong to
  5654.      this range.  These values can, for example, always be assigned to a
  5655.      variable of subtype S.
  5656.  
  5657.    57.a   Discussion:  This paragraph addresses an issue that came up with
  5658.         Ada 83, where for fixed point types, the end points of the range
  5659.         specified in the type definition were not necessarily within the base
  5660.         range of the type.  However, it was later clarified (and we reconfirm
  5661.         it in 3.5.9, ``Fixed Point Types'') that the First and Last
  5662.         attributes reflect the true bounds chosen for the type, not the
  5663.         bounds specified in the type definition (which might be outside the
  5664.         ultimately chosen base range).
  5665.  
  5666. 58   (20) For a subtype of a scalar type, the result delivered by the
  5667.      attributes Succ, Pred, and Value might not belong to the subtype;
  5668.      similarly, the actual parameters of the attributes Succ, Pred, and Image
  5669.      need not belong to the subtype.
  5670.  
  5671. 59   (21) For any value V (including any nongraphic character) of an
  5672.      enumeration subtype S, S'Value(S'Image(V)) equals V, as does S'Wide_
  5673.      Value(S'Wide_Image(V)).  Neither expression ever raises Constraint_
  5674.      Error.
  5675.  
  5676.  
  5677.                                   Examples
  5678.  
  5679. 60   Examples of ranges:
  5680.  
  5681. 61  -10 .. 10
  5682.     X .. X + 1
  5683.     0.0 .. 2.0*Pi
  5684.     Red .. Green     -- see 3.5.1
  5685.     1 .. 0           -- a null range
  5686.     Table'Range      -- a range attribute reference (see 3.6)
  5687.  
  5688. 62   Examples of range constraints:
  5689.  
  5690. 63  range -999.0 .. +999.0
  5691.     range S'First+1 .. S'Last-1
  5692.  
  5693.  
  5694.                         Incompatibilities With Ada 83
  5695.  
  5696.         63.a   {incompatibilities with Ada 83} S'Base is no longer defined
  5697.         for nonscalar types.  One conceivable existing use of S'Base for
  5698.         nonscalar types is S'Base'Size where S is a generic formal private
  5699.         type.  However, that is not generally useful because the actual
  5700.         subtype corresponding to S might be a constrained array or
  5701.         discriminated type, which would mean that S'Base'Size might very well
  5702.         overflow (for example, S'Base'Size where S is a constrained subtype
  5703.         of String will generally be 8 * (Integer'Last + 1)).  For derived
  5704.         discriminated types that are packed, S'Base'Size might not even be
  5705.         well defined if the first subtype is constrained, thereby allowing
  5706.         some amount of normally required ``dope'' to have been squeezed out
  5707.         in the packing.  Hence our conclusion is that S'Base'Size is not
  5708.         generally useful in a generic, and does not justify keeping the
  5709.         attribute Base for nonscalar types just so it can be used as a
  5710.         prefix.
  5711.  
  5712.                             Extensions to Ada 83
  5713.  
  5714.         63.b   {extensions to Ada 83} The attribute S'Base for a scalar
  5715.         subtype is now permitted anywhere a subtype_mark is permitted.
  5716.         S'Base'First .. S'Base'Last is the base range of the type.  Using an
  5717.         attribute_definition_clause, one cannot specify any subtype-specific
  5718.         attributes for the subtype denoted by S'Base (the base subtype).
  5719.  
  5720.         63.c   The attribute S'Range is now allowed for scalar subtypes.
  5721.  
  5722.         63.d   The attributes S'Min and S'Max are now defined, and made
  5723.         available for all scalar types.
  5724.  
  5725.         63.e   The attributes S'Succ, S'Pred, S'Image, S'Value, and S'Width
  5726.         are now defined for real types as well as discrete types.
  5727.  
  5728.         63.f   Wide_String versions of S'Image and S'Value are defined.
  5729.         These are called S'Wide_Image and S'Wide_Value to avoid introducing
  5730.         ambiguities involving uses of these attributes with string literals.
  5731.  
  5732.                          Wording Changes From Ada 83
  5733.  
  5734.         63.g   We now use the syntactic category range_attribute_reference
  5735.         since it is now syntactically distinguished from other attribute
  5736.         references.
  5737.  
  5738.         63.h   The definition of S'Base has been moved here from 3.3.3 since
  5739.         it now applies only to scalar types.
  5740.  
  5741.         63.i   More explicit rules are provided for nongraphic characters.
  5742.  
  5743.  
  5744.  
  5745. 3.5.1 Enumeration Types
  5746.  
  5747. 1   [{enumeration type} An enumeration_type_definition defines an enumeration
  5748. type.]
  5749.  
  5750.  
  5751.                                    Syntax
  5752.  
  5753. 2   enumeration_type_definition ::=
  5754.        (enumeration_literal_specification {, enumeration_literal_specification})
  5755.  
  5756. 3   enumeration_literal_specification ::=  defining_identifier | defining_chara\
  5757. cter_literal
  5758.  
  5759. 4   defining_character_literal ::= character_literal
  5760.  
  5761.  
  5762.                                Legality Rules
  5763.  
  5764. 5   [The defining_identifiers and defining_character_literals listed in an
  5765. enumeration_type_definition shall be distinct.]
  5766.  
  5767.         5.a   Proof:  This is a ramification of the normal disallowance of
  5768.         homographs explicitly declared immediately in the same declarative
  5769.         region.
  5770.  
  5771.  
  5772.                               Static Semantics
  5773. 6   {enumeration literal} Each enumeration_literal_specification is the
  5774. explicit declaration of the corresponding enumeration literal: it declares a
  5775. parameterless function, whose defining name is the defining_identifier or
  5776. defining_character_literal, and whose result type is the enumeration type.
  5777.  
  5778.         6.a   Reason:  This rule defines the profile of the enumeration
  5779.         literal, which is used in the various types of conformance.
  5780.  
  5781.         6.b   Ramification:  The parameterless function associated with an
  5782.         enumeration literal is fully defined by the enumeration_type_
  5783.         definition; a body is not permitted for it, and it never fails the
  5784.         Elaboration_Check when called.
  5785.  
  5786. 7   Each enumeration literal corresponds to a distinct value of the
  5787. enumeration type, and to a distinct position number.  {position number [of an
  5788. enumeration value]} The position number of the value of the first listed
  5789. enumeration literal is zero; the position number of the value of each
  5790. subsequent enumeration literal is one more than that of its predecessor in
  5791. the list.
  5792.  
  5793. 8   [The predefined order relations between values of the enumeration type
  5794. follow the order of corresponding position numbers.]
  5795.  
  5796. 9   [{overloaded [enumeration literal]} If the same defining_identifier or
  5797. defining_character_literal is specified in more than one enumeration_type_
  5798. definition, the corresponding enumeration literals are said to be overloaded.
  5799. At any place where an overloaded enumeration literal occurs in the text of a
  5800. program, the type of the enumeration literal has to be determinable from the
  5801. context (see 8.6).]
  5802.  
  5803.  
  5804.                               Dynamic Semantics
  5805.  
  5806. 10   {elaboration [enumeration_type_definition]} {constrained (subtype)}
  5807. {unconstrained (subtype)} The elaboration of an enumeration_type_definition
  5808. creates the enumeration type and its first subtype, which is constrained to
  5809. the base range of the type.
  5810.  
  5811.         10.a   Ramification:  The first subtype of a discrete type is always
  5812.         constrained, except in the case of a derived type whose parent
  5813.         subtype is Whatever'Base.
  5814.  
  5815. 11   When called, the parameterless function associated with an enumeration
  5816. literal returns the corresponding value of the enumeration type.
  5817.  
  5818.  
  5819.      NOTES
  5820. 12   (22) If an enumeration literal occurs in a context that does not
  5821.      otherwise suffice to determine the type of the literal, then
  5822.      qualification by the name of the enumeration type is one way to resolve
  5823.      the ambiguity (see 4.7).
  5824.  
  5825.  
  5826.                                   Examples
  5827.  
  5828. 13   Examples of enumeration types and subtypes:
  5829.  
  5830. 14  type Day    is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
  5831.     type Suit   is (Clubs, Diamonds, Hearts, Spades);
  5832.     type Gender is (M, F);
  5833.     type Level  is (Low, Medium, Urgent);
  5834.     type Color  is (White, Red, Yellow, Green, Blue, Brown, Black);
  5835.     type Light  is (Red, Amber, Green); -- Red and Green are overloaded
  5836.  
  5837. 15  type Hexa   is ('A', 'B', 'C', 'D', 'E', 'F');
  5838.     type Mixed  is ('A', 'B', '*', B, None, '?', '%');
  5839.  
  5840. 16  subtype Weekday is Day   range Mon .. Fri;
  5841.     subtype Major   is Suit  range Hearts .. Spades;
  5842.     subtype Rainbow is Color range Red .. Blue;  --  the Color Red, not the Lig\
  5843. ht
  5844.  
  5845.  
  5846.                          Wording Changes From Ada 83
  5847.  
  5848.         16.a   The syntax rule for defining_character_literal is new.  It is
  5849.         used for the defining occurrence of a character_literal, analogously
  5850.         to defining_identifier.  Usage occurrences use the name or selector_
  5851.         name syntactic categories.
  5852.  
  5853.         16.b   We emphasize the fact that an enumeration literal denotes a
  5854.         function, which is called to produce a value.
  5855.  
  5856.  
  5857.  
  5858. 3.5.2 Character Types
  5859.  
  5860.                               Static Semantics
  5861.  
  5862. 1   {character type} An enumeration type is said to be a character type if at
  5863. least one of its enumeration literals is a character_literal.
  5864.  
  5865. 2   {Latin-1} {BMP} {ISO 10646} {Character} The predefined type Character is
  5866. a character type whose values correspond to the 256 code positions of Row 00
  5867. (also known as Latin-1) of the ISO 10646 Basic Multilingual Plane (BMP).
  5868. Each of the graphic characters of Row 00 of the BMP has a corresponding
  5869. character_literal in Character.  Each of the nongraphic positions of Row 00
  5870. (0000-001F and 007F-009F) has a corresponding language-defined name, which is
  5871. not usable as an enumeration literal, but which is usable with the attributes
  5872. (Wide_)Image and (Wide_)Value; these names are given in the definition of
  5873. type Character in A.1, ``The Package Standard'', but are set in italics.
  5874. {italics (nongraphic characters)}
  5875.  
  5876. 3   {Wide_Character} {BMP} {ISO 10646} The predefined type Wide_Character is
  5877. a character type whose values correspond to the 65536 code positions of the
  5878. ISO 10646 Basic Multilingual Plane (BMP).  Each of the graphic characters of
  5879. the BMP has a corresponding character_literal in Wide_Character.  The first
  5880. 256 values of Wide_Character have the same character_literal or
  5881. language-defined name as defined for Character.  The last 2 values of Wide_
  5882. Character correspond to the nongraphic positions FFFE and FFFF of the BMP,
  5883. and are assigned the language-defined names FFFE and FFFF.  As with the other
  5884. language-defined names for nongraphic characters, the names FFFE and FFFF are
  5885. usable only with the attributes (Wide_)Image and (Wide_)Value; they are not
  5886. usable as enumeration literals.  All other values of Wide_Character are
  5887. considered graphic characters, and have a corresponding character_literal.
  5888.  
  5889.         3.a   Reason:  The language-defined names are not usable as
  5890.         enumeration literals to avoid "polluting" the name space.  Since
  5891.         Wide_Character is defined in Standard, if the names FFFE and FFFF
  5892.         were usable as enumeration literals, they would hide other
  5893.         nonoverloadable declarations with the same names in use-d packages.
  5894.  
  5895.         3.b   ISO 10646 has not defined the meaning of all of the code
  5896.         positions from 0100 through FFFD, but they are all considered graphic
  5897.         characters by Ada to simplify the implementation, and to allow for
  5898.         revisions to ISO 10646.  In ISO 10646, FFFE and FFFF are special, and
  5899.         will never be associated with graphic characters in any revision.
  5900.  
  5901.  
  5902.                          Implementation Permissions
  5903.  
  5904. 4   {localization} In a nonstandard mode, an implementation may provide other
  5905. interpretations for the predefined types Character and Wide_Character[, to
  5906. conform to local conventions].
  5907.  
  5908.  
  5909.                             Implementation Advice
  5910.  
  5911. 5   {localization} If an implementation supports a mode with alternative
  5912. interpretations for Character and Wide_Character, the set of graphic
  5913. characters of Character should nevertheless remain a proper subset of the set
  5914. of graphic characters of Wide_Character.  Any character set ``localizations''
  5915. should be reflected in the results of the subprograms defined in the
  5916. language-defined package Characters.Handling (see A.3) available in such a
  5917. mode.  In a mode with an alternative interpretation of Character, the
  5918. implementation should also support a corresponding change in what is a legal
  5919. identifier_letter.
  5920.  
  5921.  
  5922.      NOTES
  5923. 6    (23) The language-defined library package Characters.Latin_1 (see A.3.3)
  5924.      includes the declaration of constants denoting control characters, lower
  5925.      case characters, and special characters of the predefined type
  5926.      Character.
  5927.  
  5928.    6.a   To be honest:  The package ASCII does the same, but only for the
  5929.         first 128 characters of Character.  Hence, it is an obsolescent
  5930.         package, and we no longer mention it here.
  5931.  
  5932. 7    (24) A conventional character set such as EBCDIC can be declared as a
  5933.      character type; the internal codes of the characters can be specified by
  5934.      an enumeration_representation_clause as explained in clause 13.4.
  5935.  
  5936.  
  5937.                                   Examples
  5938.  
  5939. 8   Example of a character type:
  5940.  
  5941. 9   type Roman_Digit is ('I', 'V', 'X', 'L', 'C', 'D', 'M');
  5942.  
  5943.  
  5944.                          Inconsistencies With Ada 83
  5945.  
  5946.         9.a   {inconsistencies with Ada 83} The declaration of Wide_Character
  5947.         in package Standard hides use-visible declarations with the same
  5948.         defining identifier.  In the unlikely event that an Ada 83 program
  5949.         had depended on such a use-visible declaration, and the program
  5950.         remains legal after the substitution of Standard.Wide_Character, the
  5951.         meaning of the program will be different.
  5952.  
  5953.                         Incompatibilities With Ada 83
  5954.  
  5955.         9.b   {incompatibilities with Ada 83} The presence of Wide_Character
  5956.         in package Standard means that an expression such as
  5957.  
  5958. 9.c         'a' = 'b'
  5959.  
  5960.         9.d   is ambiguous in Ada 9X, whereas in Ada 83 both literals could
  5961.         be resolved to be of type Character.
  5962.  
  5963.         9.e   The change in visibility rules (see 4.2) for character literals
  5964.         means that additional qualification might be necessary to resolve
  5965.         expressions involving overloaded subprograms and character literals.
  5966.  
  5967.                             Extensions to Ada 83
  5968.  
  5969.         9.f   {extensions to Ada 83} The type Character has been extended to
  5970.         have 256 positions, and the type Wide_Character has been added.  Note
  5971.         that this change was already approved by the ARG for Ada 83
  5972.         conforming compilers.
  5973.  
  5974.         9.g   The rules for referencing character literals are changed (see
  5975.         4.2), so that the declaration of the character type need not be
  5976.         directly visible to use its literals, similar to null and string
  5977.         literals.  Context is used to resolve their type.
  5978.  
  5979.  
  5980.  
  5981. 3.5.3 Boolean Types
  5982.  
  5983.                               Static Semantics
  5984.  
  5985. 1   {Boolean} There is a predefined enumeration type named Boolean, [declared
  5986. in the visible part of package Standard].  {False} {True} It has the two
  5987. enumeration literals False and True ordered with the relation False < True.
  5988. {boolean type} Any descendant of the predefined type Boolean is called a
  5989. boolean type.
  5990.  
  5991.         1.a   Implementation Note:  An implementation is not required to
  5992.         support enumeration representation clauses on boolean types that
  5993.         impose an unacceptable implementation burden.  See 13.4,
  5994.         ``Enumeration Representation Clauses''.  However, it is generally
  5995.         straightforward to support representations where False is zero and
  5996.         True is 2**n - 1 for some n.
  5997.  
  5998.  
  5999.  
  6000. 3.5.4 Integer Types
  6001.  
  6002. 1   {integer type} {signed integer type} {modular type} An integer_type_
  6003. definition defines an integer type; it defines either a signed integer type,
  6004. or a modular integer type.  The base range of a signed integer type includes
  6005. at least the values of the specified range.  A modular type is an integer
  6006. type with all arithmetic modulo a specified positive modulus; such a type
  6007. corresponds to an unsigned type with wrap-around semantics.  {unsigned type:
  6008. see modular type}
  6009.  
  6010.  
  6011.                                    Syntax
  6012.  
  6013. 2   integer_type_definition ::= signed_integer_type_definition | modular_type_d\
  6014. efinition
  6015.  
  6016. 3   signed_integer_type_definition ::= range static_simple_expression .. static\
  6017. _simple_expression
  6018.  
  6019.         3.a   Discussion:  We don't call this a range_constraint, because it
  6020.         is rather different -- not only is it required to be static, but the
  6021.         associated overload resolution rules are different than for normal
  6022.         range constraints.  A similar comment applies to real_range_
  6023.         specification.  This used to be integer_range_specification but when
  6024.         we added support for modular types, it seemed overkill to have three
  6025.         levels of syntax rules, and just calling these signed_integer_range_
  6026.         specification and modular_range_specification loses the fact that
  6027.         they are defining different classes of types, which is important for
  6028.         the generic type matching rules.
  6029.  
  6030. 4   modular_type_definition ::= mod static_expression
  6031.  
  6032.  
  6033.                             Name Resolution Rules
  6034.  
  6035. 5   {expected type [signed_integer_type_definition simple_expression]} Each
  6036. simple_expression in a signed_integer_type_definition is expected to be of
  6037. any integer type; they need not be of the same type.  {expected type
  6038. [modular_type_definition expression]} The expression in a modular_type_
  6039. definition is likewise expected to be of any integer type.
  6040.  
  6041.  
  6042.                                Legality Rules
  6043.  
  6044. 6   The simple_expressions of a signed_integer_type_definition shall be
  6045. static, and their values shall be in the range System.Min_Int .. System.Max_
  6046. Int.
  6047.  
  6048. 7   {modulus (of a modular type)} {Max_Binary_Modulus} {Max_Nonbinary_
  6049. Modulus} The expression of a modular_type_definition shall be static, and its
  6050. value (the modulus) shall be positive, and shall be no greater than
  6051. System.Max_Binary_Modulus if a power of 2, or no greater than System.Max_
  6052. Nonbinary_Modulus if not.
  6053.  
  6054.         7.a   Reason:  For a 2's-complement machine, supporting nonbinary
  6055.         moduli greater than System.Max_Int can be quite difficult, whereas
  6056.         essentially any binary moduli are straightforward to support, up to
  6057.         2*System.Max_Int+2, so this justifies having two separate limits.
  6058.  
  6059.  
  6060.                               Static Semantics
  6061.  
  6062. 8   The set of values for a signed integer type is the (infinite) set of
  6063. mathematical integers[, though only values of the base range of the type are
  6064. fully supported for run-time operations].  The set of values for a modular
  6065. integer type are the values from 0 to one less than the modulus, inclusive.
  6066.  
  6067. 9   {base range [of a signed integer type]} A signed_integer_type_definition
  6068. defines an integer type whose base range includes at least the values of the
  6069. simple_expressions and is symmetric about zero, excepting possibly an extra
  6070. negative value.  {constrained (subtype)} {unconstrained (subtype)} A signed_
  6071. integer_type_definition also defines a constrained first subtype of the type,
  6072. with a range whose bounds are given by the values of the simple_expressions,
  6073. converted to the type being defined.  {implicit subtype conversion [bounds of
  6074. signed integer type]}
  6075.  
  6076.         9.a   Implementation Note:  The base range of a signed integer type
  6077.         might be much larger than is necessary to satisfy the aboved
  6078.         requirements.
  6079.  
  6080. 10   {base range [of a modular type]} A modular_type_definition defines a
  6081. modular type whose base range is from zero to one less than the given
  6082. modulus.  {constrained (subtype)} {unconstrained (subtype)} A modular_type_
  6083. definition also defines a constrained first subtype of the type with a range
  6084. that is the same as the base range of the type.
  6085.  
  6086. 11   {Integer} There is a predefined signed integer subtype named Integer[,
  6087. declared in the visible part of package Standard].  It is constrained to the
  6088. base range of its type.
  6089.  
  6090.         11.a   Reason:  Integer is a constrained subtype, rather than an
  6091.         unconstrained subtype.  This means that on assignment to an object of
  6092.         subtype Integer, a range check is required.  On the other hand, an
  6093.         object of subtype Integer'Base is unconstrained, and no range check
  6094.         (only overflow check) is required on assignment.  For example, if the
  6095.         object is held in an extended-length register, its value might be
  6096.         outside of Integer'First .. Integer'Last.  All parameter and result
  6097.         subtypes of the predefined integer operators are of such
  6098.         unconstrained subtypes, allowing extended-length registers to be used
  6099.         as operands or for the result.  In an earlier version of Ada 9X,
  6100.         Integer was unconstrained.  However, the fact that certain
  6101.         Constraint_Errors might be omitted or appear elsewhere was felt to be
  6102.         an undesirable upward inconsistency in this case.  Note that for
  6103.         Float, the opposite conclusion was reached, partly because of the
  6104.         high cost of performing range checks when not actually necessary.
  6105.         Objects of subtype Float are unconstrained, and no range checks, only
  6106.         overflow checks, are performed for them.
  6107.  
  6108. 12   {Natural} {Positive} Integer has two predefined subtypes, [declared in
  6109. the visible part of package Standard:]
  6110.  
  6111. 13  subtype Natural  is Integer range 0 .. Integer'Last;
  6112.     subtype Positive is Integer range 1 .. Integer'Last;
  6113.  
  6114. 14   {root_integer} {Min_Int} {Max_Int} A type defined by an integer_type_
  6115. definition is implicitly derived from root_integer, an anonymous predefined
  6116. (specific) integer type, whose base range is System.Min_Int .. System.Max_
  6117. Int.  However, the base range of the new type is not inherited from root_
  6118. integer, but is instead determined by the range or modulus specified by the
  6119. integer_type_definition.  {universal_integer [partial]} {integer literals}
  6120. [Integer literals are all of the type universal_integer, the universal type
  6121. (see 3.4.1) for the class rooted at root_integer, allowing their use with the
  6122. operations of any integer type.]
  6123.  
  6124.         14.a   Discussion:  This implicit derivation is not considered
  6125.         exactly equivalent to explicit derivation via a derived_type_
  6126.         definition.  In particular, integer types defined via a derived_type_
  6127.         definition inherit their base range from their parent type.  A type
  6128.         defined by an integer_type_definition does not necessarily inherit
  6129.         its base range from root_integer.  It is not specified whether the
  6130.         implicit derivation from root_integer is direct or indirect, not that
  6131.         it really matters.  All we want is for all integer types to be
  6132.         descendants of root_integer.
  6133.  
  6134.         14.b   Implementation Note:  It is the intent that even nonstandard
  6135.         integer types (see below) will be descendants of root_integer, even
  6136.         though they might have a base range that exceeds that of root_
  6137.         integer.  This causes no problem for static calculations, which are
  6138.         performed without range restrictions (see 4.9).  However for run-time
  6139.         calculations, it is possible that Constraint_Error might be raised
  6140.         when using an operator of root_integer on the result of 'Val applied
  6141.         to a value of a nonstandard integer type.
  6142.  
  6143. 15   {position number [of an integer value]} The position number of an
  6144. integer value is equal to the value.
  6145.  
  6146. 16   For every modular subtype S, the following attribute is defined:
  6147.  
  6148. 17  S'Modulus
  6149.                 S'Modulus yields the modulus of the type of S, as a value of
  6150.                 the type universal_integer.
  6151.  
  6152.  
  6153.                               Dynamic Semantics
  6154.  
  6155. 18   {elaboration [integer_type_definition]} The elaboration of an integer_
  6156. type_definition creates the integer type and its first subtype.
  6157.  
  6158. 19   For a modular type, if the result of the execution of a predefined
  6159. operator (see 4.5) is outside the base range of the type, the result is
  6160. reduced modulo the modulus of the type to a value that is within the base
  6161. range of the type.
  6162.  
  6163. 20   {Overflow_Check [partial]} {check, language-defined (Overflow_Check)}
  6164. {Constraint_Error (raised by failure of run-time check)} For a signed integer
  6165. type, the exception Constraint_Error is raised by the execution of an
  6166. operation that cannot deliver the correct result because it is outside the
  6167. base range of the type.[{Division_Check [partial]} {check, language-defined
  6168. (Division_Check)} {Constraint_Error (raised by failure of run-time check)}
  6169. For any integer type, Constraint_Error is raised by the operators "/", "rem",
  6170. and "mod" if the right operand is zero.]
  6171.                          Implementation Requirements
  6172.  
  6173. 21   {Integer} In an implementation, the range of Integer shall include the
  6174. range -2**15+1 .. +2**15-1.
  6175.  
  6176. 22   {Long_Integer} If Long_Integer is predefined for an implementation, then
  6177. its range shall include the range -2**31+1 .. +2**31-1.
  6178.  
  6179. 23   System.Max_Binary_Modulus shall be at least 2**16.  {94-4776.b}
  6180. {94-4789.a} {94-4790.a}
  6181.  
  6182.  
  6183.                          Implementation Permissions
  6184.  
  6185. 24   For the execution of a predefined operation of a signed integer type,
  6186. the implementation need not raise Constraint_Error if the result is outside
  6187. the base range of the type, so long as the correct result is produced.
  6188.  
  6189.         24.a   Discussion:  Constraint_Error is never raised for operations
  6190.         on modular types, except for divide-by-zero (and rem/mod-by-zero).
  6191.  
  6192. 25   {Long_Integer} {Short_Integer} An implementation may provide additional
  6193. predefined signed integer types[, declared in the visible part of Standard],
  6194. whose first subtypes have names of the form Short_Integer, Long_Integer,
  6195. Short_Short_Integer, Long_Long_Integer, etc.  Different predefined integer
  6196. types are allowed to have the same base range.  However, the range of Integer
  6197. should be no wider than that of Long_Integer.  Similarly, the range of Short_
  6198. Integer (if provided) should be no wider than Integer.  Corresponding
  6199. recommendations apply to any other predefined integer types.  There need not
  6200. be a named integer type corresponding to each distinct base range supported
  6201. by an implementation.  The range of each first subtype should be the base
  6202. range of its type.
  6203.  
  6204.         25.a   Implementation defined:  The predefined integer types declared
  6205.         in Standard.
  6206.  
  6207. 26   {nonstandard integer type} An implementation may provide nonstandard
  6208. integer types, descendants of root_integer that are declared outside of the
  6209. specification of package Standard, which need not have all the standard
  6210. characteristics of a type defined by an integer_type_definition.  For
  6211. example, a nonstandard integer type might have an asymmetric base range or it
  6212. might not be allowed as an array or loop index (a very long integer).  Any
  6213. type descended from a nonstandard integer type is also nonstandard.  An
  6214. implementation may place arbitrary restrictions on the use of such types; it
  6215. is implementation defined whether operators that are predefined for ``any
  6216. integer type'' are defined for a particular nonstandard integer type.  [In
  6217. any case, such types are not permitted as explicit_generic_actual_parameters
  6218. for formal scalar types -- see 12.5.2.]
  6219.  
  6220.         26.a   Implementation defined:  Any nonstandard integer types and the
  6221.         operators defined for them.
  6222.  
  6223. 27   {one's complement [modular types]} For a one's complement machine, the
  6224. high bound of the base range of a modular type whose modulus is one less than
  6225. a power of 2 may be equal to the modulus, rather than one less than the
  6226. modulus.  It is implementation defined for which powers of 2, if any, this
  6227. permission is exercised.
  6228.  
  6229.  
  6230.                             Implementation Advice
  6231.  
  6232. 28   {Long_Integer} An implementation should support Long_Integer in addition
  6233. to Integer if the target machine supports 32-bit (or longer) arithmetic.  No
  6234. other named integer subtypes are recommended for package Standard.  Instead,
  6235. appropriate named integer subtypes should be provided in the library package
  6236. Interfaces (see B.2).
  6237.  
  6238.         28.a   Implementation Note:  To promote portability, implementations
  6239.         should explicitly declare the integer (sub)types Integer and Long_
  6240.         Integer in Standard, and leave other predefined integer types
  6241.         anonymous.  For implementations that already support Byte_Integer,
  6242.         etc., upward compatibility argues for keeping such declarations in
  6243.         Standard during the transition period, but perhaps generating a
  6244.         warning on use.  A separate package Interfaces in the predefined
  6245.         environment is available for pre-declaring types such as Integer_8,
  6246.         Integer_16, etc.  See B.2.  In any case, if the user declares a
  6247.         subtype (first or not) whose range fits in, for example, a byte, the
  6248.         implementation can store variables of the subtype in a single byte,
  6249.         even if the base range of the type is wider.
  6250.  
  6251. 29   {two's complement [modular types]} An implementation for a two's
  6252. complement machine should support modular types with a binary modulus up to
  6253. System.Max_Int*2+2.  An implementation should support a nonbinary modulus up
  6254. to Integer'Last.
  6255.  
  6256.         29.a   Reason:  Modular types provide bit-wise "and", "or", "xor",
  6257.         and "not" operations.  It is important for systems programming that
  6258.         these be available for all integer types of the target hardware.
  6259.  
  6260.         29.b   Ramification:  Note that on a one's complement machine, the
  6261.         largest supported modular type would normally have a nonbinary
  6262.         modulus.  On a two's complement machine, the largest supported
  6263.         modular type would normally have a binary modulus.
  6264.  
  6265.         29.c   Implementation Note:  Supporting a nonbinary modulus greater
  6266.         than Integer'Last can impose an undesirable implementation burden on
  6267.         some machines.
  6268.  
  6269.  
  6270.      NOTES
  6271. 30   (25) {universal_integer} {integer literals} Integer literals are of the
  6272.      anonymous predefined integer type universal_integer.  Other integer
  6273.      types have no literals.  However, the overload resolution rules (see
  6274.      8.6, ``The Context of Overload Resolution'') allow expressions of the
  6275.      type universal_integer whenever an integer type is expected.
  6276.  
  6277. 31   (26) The same arithmetic operators are predefined for all signed integer
  6278.      types defined by a signed_integer_type_definition (see 4.5, ``Operators
  6279.      and Expression Evaluation'').  For modular types, these same operators
  6280.      are predefined, plus bit-wise logical operators (and, or, xor, and not).
  6281.      In addition, for the unsigned types declared in the language-defined
  6282.      package Interfaces (see B.2), functions are defined that provide
  6283.      bit-wise shifting and rotating.
  6284.  
  6285. 32   (27) Modular types match a generic_formal_parameter_declaration of the
  6286.      form "type T is mod <>;"; signed integer types match "type T is range
  6287.      <>;" (see 12.5.2).
  6288.  
  6289.  
  6290.                                   Examples
  6291.  
  6292. 33   Examples of integer types and subtypes:
  6293.  
  6294. 34  type Page_Num  is range 1 .. 2_000;
  6295.     type Line_Size is range 1 .. Max_Line_Size;
  6296.  
  6297. 35  subtype Small_Int   is Integer   range -10 .. 10;
  6298.     subtype Column_Ptr  is Line_Size range 1 .. 10;
  6299.     subtype Buffer_Size is Integer   range 0 .. Max;
  6300.  
  6301. 36  type Byte        is mod 256; -- an unsigned byte
  6302.     type Hash_Index  is mod 97;  -- modulus is prime
  6303.  
  6304.  
  6305.                             Extensions to Ada 83
  6306.  
  6307.         36.a   {extensions to Ada 83} An implementation is allowed to support
  6308.         any number of distinct base ranges for integer types, even if fewer
  6309.         integer types are explicitly declared in Standard.
  6310.  
  6311.         36.b   Modular (unsigned, wrap-around) types are new.
  6312.  
  6313.                          Wording Changes From Ada 83
  6314.  
  6315.         36.c   Ada 83's integer types are now called "signed" integer types,
  6316.         to contrast them with "modular" integer types.
  6317.  
  6318.         36.d   Standard.Integer, Standard.Long_Integer, etc., denote con-
  6319.         strained subtypes of predefined integer types, consistent with the
  6320.         Ada 9X model that only subtypes have names.
  6321.  
  6322.         36.e   We now impose minimum requirements on the base range of
  6323.         Integer and Long_Integer.
  6324.  
  6325.         36.f   We no longer explain integer type definition in terms of an
  6326.         equivalence to a normal type derivation, except to say that all
  6327.         integer types are by definition implicitly derived from root_integer.
  6328.         This is for various reasons.
  6329.  
  6330.         36.g   First of all, the equivalence with a type derivation and a
  6331.         subtype declaration was not perfect, and was the source of various
  6332.         AIs (for example, is the conversion of the bounds static?  Is a
  6333.         numeric type a derived type with respect to other rules of the
  6334.         language?)
  6335.  
  6336.         36.h   Secondly, we don't want to require that every integer size
  6337.         supported shall have a corresponding named type in Standard.  Adding
  6338.         named types to Standard creates nonportabilities.
  6339.  
  6340.         36.i   Thirdly, we don't want the set of types that match a formal
  6341.         derived type "type T is new Integer;" to depend on the particular
  6342.         underlying integer representation chosen to implement a given
  6343.         user-defined integer type.  Hence, we would have needed anonymous
  6344.         integer types as parent types for the implicit derivation anyway.  We
  6345.         have simply chosen to identify only one anonymous integer type --
  6346.         root_integer, and stated that every integer type is derived from it.
  6347.  
  6348.         36.j   Finally, the ``fiction'' that there were distinct preexisting
  6349.         predefined types for every supported representation breaks down for
  6350.         fixed point with arbitrary smalls, and was never exploited for
  6351.         enumeration types, array types, etc.  Hence, there seems little
  6352.         benefit to pushing an explicit equivalence between integer type
  6353.         definition and normal type derivation.
  6354.  
  6355.  
  6356.  
  6357. 3.5.5 Operations of Discrete Types
  6358.  
  6359.                               Static Semantics
  6360.  
  6361. 1   For every discrete subtype S, the following attributes are defined:
  6362.  
  6363. 2   S'Pos
  6364.                 S'Pos denotes a function with the following specification:
  6365.  
  6366. 3                   function S'Pos(Arg : S'Base)
  6367.                       return universal_integer
  6368.  
  6369.                 4   This function returns the position number of the value of
  6370.                 Arg, as a value of type universal_integer.
  6371.  
  6372. 5   S'Val
  6373.                 S'Val denotes a function with the following specification:
  6374.  
  6375. 6                   function S'Val(Arg : universal_integer)
  6376.                       return S'Base
  6377.  
  6378.                 7   {evaluation [Val]} {Constraint_Error (raised by failure
  6379.                 of run-time check)} This function returns a value of the type
  6380.                 of S whose position number equals the value of Arg.  {Range_
  6381.                 Check [partial]} {check, language-defined (Range_Check)} For
  6382.                 the evaluation of a call on S'Val, if there is no value in
  6383.                 the base range of its type with the given position number,
  6384.                 Constraint_Error is raised.
  6385.  
  6386. 7.a     Ramification:  By the overload resolution rules, a formal parameter
  6387.         of type universal_integer allows an actual parameter of any integer
  6388.         type.
  6389.  
  6390. 7.b     Reason:  We considered allowing S'Val for a signed integer subtype S
  6391.         to return an out-of-range value, but since checks were required for
  6392.         enumeration and modular types anyway, the allowance didn't seem worth
  6393.         the complexity of the rule.
  6394.  
  6395.  
  6396.                             Implementation Advice
  6397.  
  6398. 8   For the evaluation of a call on S'Pos for an enumeration subtype, if the
  6399. value of the operand does not correspond to the internal code for any
  6400. enumeration literal of its type [(perhaps due to an uninitialized variable)],
  6401. then the implementation should raise Program_Error.  {Program_Error (raised
  6402. by failure of run-time check)} This is particularly important for enumeration
  6403. types with noncontiguous internal codes specified by an enumeration_
  6404. representation_clause.
  6405.  
  6406.         8.a   Reason:  We say Program_Error here, rather than Constraint_
  6407.         Error, because the main reason for such values is uninitialized
  6408.         variables, and the normal way to indicate such a use (if detected) is
  6409.         to raise Program_Error.  (Other reasons would involve the misuse of
  6410.         low-level features such as Unchecked_Conversion.)
  6411.  
  6412.  
  6413.      NOTES
  6414. 9    (28) Indexing and loop iteration use values of discrete types.
  6415.  
  6416. 10   (29) {predefined operations [of a discrete type]} The predefined
  6417.      operations of a discrete type include the assignment operation,
  6418.      qualification, the membership tests, and the relational operators; for a
  6419.      boolean type they include the short-circuit control forms and the
  6420.      logical operators; for an integer type they include type conversion to
  6421.      and from other numeric types, as well as the binary and unary adding
  6422.      operators - and +, the multiplying operators, the unary operator abs,
  6423.      and the exponentiation operator.  {94-4693.v} The assignment operation
  6424.      is described in 5.2.  The other predefined operations are described in
  6425.      Section 4.
  6426.  
  6427. 11   (30) As for all types, objects of a discrete type have Size and Address
  6428.      attributes (see 13.3).
  6429.  
  6430. 12   (31) For a subtype of a discrete type, the result delivered by the
  6431.      attribute Val might not belong to the subtype; similarly, the actual
  6432.      parameter of the attribute Pos need not belong to the subtype.  The
  6433.      following relations are satisfied (in the absence of an exception) by
  6434.      these attributes:
  6435.  
  6436. 13       S'Val(S'Pos(X)) = X
  6437.          S'Pos(S'Val(N)) = N
  6438.  
  6439.  
  6440.                                   Examples
  6441.  
  6442. 14   Examples of attributes of discrete subtypes:
  6443.  
  6444. 15  --  For the types and subtypes declared in subclause 3.5.1 the following ho\
  6445. ld:
  6446.  
  6447. 16  --  Color'First   = White,   Color'Last   = Black
  6448.     --  Rainbow'First = Red,     Rainbow'Last = Blue
  6449.  
  6450. 17  --  Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown
  6451.     --  Color'Pos(Blue)  = Rainbow'Pos(Blue)  = 4
  6452.     --  Color'Val(0)     = Rainbow'Val(0)     = White
  6453.  
  6454.  
  6455.                             Extensions to Ada 83
  6456.  
  6457.         17.a   {extensions to Ada 83} The attributes S'Succ, S'Pred, S'Width,
  6458.         S'Image, and S'Value have been generalized to apply to real types as
  6459.         well (see 3.5, ``Scalar Types'').
  6460.  
  6461.  
  6462.  
  6463. 3.5.6 Real Types
  6464.  
  6465. 1   {real type} Real types provide approximations to the real numbers, with
  6466. relative bounds on errors for floating point types, and with absolute bounds
  6467. for fixed point types.
  6468.  
  6469.  
  6470.                                    Syntax
  6471.  
  6472. 2   real_type_definition ::=
  6473.        floating_point_definition | fixed_point_definition
  6474.  
  6475.  
  6476.                               Static Semantics
  6477.  
  6478. 3   {root_real} A type defined by a real_type_definition is implicitly
  6479. derived from root_real, an anonymous predefined (specific) real type.
  6480. [Hence, all real types, whether floating point or fixed point, are in the
  6481. derivation class rooted at root_real.]
  6482.  
  6483.         3.a   Ramification:  It is not specified whether the derivation from
  6484.         root_real is direct or indirect, not that it really matters.  All we
  6485.         want is for all real types to be descendants of root_real.
  6486.  
  6487. 4   [{universal_real [partial]} {real literals} Real literals are all of the
  6488. type universal_real, the universal type (see 3.4.1) for the class rooted at
  6489. root_real, allowing their use with the operations of any real type.
  6490. {universal_fixed [partial]} Certain multiplying operators have a result type
  6491. of universal_fixed (see 4.5.5), the universal type for the class of fixed
  6492. point types, allowing the result of the multiplication or division to be used
  6493. where any specific fixed point type is expected.]
  6494.  
  6495.  
  6496.                               Dynamic Semantics
  6497.  
  6498. 5   {elaboration [real_type_definition]} The elaboration of a real_type_
  6499. definition consists of the elaboration of the floating_point_definition or
  6500. the fixed_point_definition.
  6501.  
  6502.  
  6503.                          Implementation Requirements
  6504.  
  6505. 6   An implementation shall perform the run-time evaluation of a use of a
  6506. predefined operator of root_real with an accuracy at least as great as that
  6507. of any floating point type definable by a floating_point_definition.
  6508.  
  6509.         6.a   Ramification:  Static calculations using the operators of root_
  6510.         real are exact, as for all static calculations.  See 4.9.
  6511.  
  6512.         6.b   Implementation Note:  The Digits attribute of the type used to
  6513.         represent root_real at run time is at least as great as that of any
  6514.         other floating point type defined by a floating_point_definition, and
  6515.         its safe range includes that of any such floating point type with the
  6516.         same Digits attribute.  On some machines, there might be real types
  6517.         with less accuracy but a wider range, and hence run-time calculations
  6518.         with root_real might not be able to accommodate all values that can
  6519.         be represented at run time in such floating point or fixed point
  6520.         types.
  6521.  
  6522.  
  6523.                          Implementation Permissions
  6524.  
  6525. 7   [For the execution of a predefined operation of a real type, the
  6526. implementation need not raise Constraint_Error if the result is outside the
  6527. base range of the type, so long as the correct result is produced, or the
  6528. Machine_Overflows attribute of the type is false (see G.2).]
  6529.  
  6530. 8   {nonstandard real type}
  6531.  
  6532.         8.a   Implementation defined:  Any nonstandard real types and the
  6533.         operators defined for them.
  6534.  
  6535. An implementation may provide nonstandard real types, descendants of root_
  6536. real that are declared outside of the specification of package Standard,
  6537. which need not have all the standard characteristics of a type defined by a
  6538. real_type_definition.  For example, a nonstandard real type might have an
  6539. asymmetric or unsigned base range, or its predefined operations might wrap
  6540. around or ``saturate'' rather than overflow (modular or saturating
  6541. arithmetic), or it might not conform to the accuracy model (see G.2).  Any
  6542. type descended from a nonstandard real type is also nonstandard.  An
  6543. implementation may place arbitrary restrictions on the use of such types; it
  6544. is implementation defined whether operators that are predefined for ``any
  6545. real type'' are defined for a particular nonstandard real type.  [In any
  6546. case, such types are not permitted as explicit_generic_actual_parameters for
  6547. formal scalar types -- see 12.5.2.]
  6548.  
  6549.  
  6550.      NOTES
  6551. 9    (32) As stated, real literals are of the anonymous predefined real type
  6552.      universal_real.  Other real types have no literals.  However, the
  6553.      overload resolution rules (see 8.6) allow expressions of the type
  6554.      universal_real whenever a real type is expected.
  6555.  
  6556.  
  6557.                          Wording Changes From Ada 83
  6558.  
  6559.         9.a   The syntax rule for real_type_definition is modified to use the
  6560.         new syntactic categories floating_point_definition and fixed_point_
  6561.         definition, instead of floating_point_constraint and fixed_point_
  6562.         constraint, because the semantics of a type definition are
  6563.         significantly different than the semantics of a constraint.
  6564.  
  6565.         9.b   All discussion of model numbers, safe ranges, and machine
  6566.         numbers is moved to 3.5.7, 3.5.8, and G.2.  Values of a fixed point
  6567.         type are now described as being multiples of the small of the fixed
  6568.         point type, and we have no need for model numbers, safe ranges, etc.
  6569.         for fixed point types.
  6570. 3.5.7 Floating Point Types
  6571.  
  6572. 1   {floating point type} For floating point types, the error bound is
  6573. specified as a relative precision by giving the required minimum number of
  6574. significant decimal digits.
  6575.  
  6576.  
  6577.                                    Syntax
  6578.  
  6579. 2   floating_point_definition ::=
  6580.       digits static_expression [real_range_specification]
  6581.  
  6582. 3   real_range_specification ::=
  6583.       range static_simple_expression .. static_simple_expression
  6584.  
  6585.  
  6586.                             Name Resolution Rules
  6587.  
  6588. 4   {requested decimal precision (of a floating point type)} The requested
  6589. decimal precision, which is the minimum number of significant decimal digits
  6590. required for the floating point type, is specified by the value of the
  6591. expression given after the reserved word digits.  {expected type [requested
  6592. decimal precision]} This expression is expected to be of any integer type.
  6593.  
  6594. 5   {expected type [real_range_specification bounds]} Each simple_expression
  6595. of a real_range_specification is expected to be of any real type[; the types
  6596. need not be the same].
  6597.  
  6598.  
  6599.                                Legality Rules
  6600.  
  6601. 6   {Max_Base_Digits} The requested decimal precision shall be specified by a
  6602. static expression whose value is positive and no greater than System.Max_
  6603. Base_Digits.  Each simple_expression of a real_range_specification shall also
  6604. be static.  {Max_Digits} If the real_range_specification is omitted, the
  6605. requested decimal precision shall be no greater than System.Max_Digits.
  6606.  
  6607.         6.a   Reason:  We have added Max_Base_Digits to package System.  It
  6608.         corresponds to the requested decimal precision of root_real.
  6609.         System.Max_Digits corresponds to the maximum value for Digits that
  6610.         may be specified in the absence of a real_range_specification, for
  6611.         upward compatibility.  These might not be the same if root_real has a
  6612.         base range that does not include +/- 10.0**(4*Max_Base_Digits).
  6613.  
  6614. 7   A floating_point_definition is illegal if the implementation does not
  6615. support a floating point type that satisfies the requested decimal precision
  6616. and range.
  6617.  
  6618.         7.a   Implementation defined:  What combinations of requested decimal
  6619.         precision and range are supported for floating point types.
  6620.  
  6621.  
  6622.                               Static Semantics
  6623.  
  6624. 8   The set of values for a floating point type is the (infinite) set of
  6625. rational numbers.  {machine numbers (of a floating point type)} The machine
  6626. numbers of a floating point type are the values of the type that can be
  6627. represented exactly in every unconstrained variable of the type.  {base range
  6628. [of a floating point type]} The base range (see 3.5) of a floating point type
  6629. is symmetric around zero, except that it can include some extra negative
  6630. values in some implementations.
  6631.  
  6632.         8.a   Implementation Note:  For example, if a 2's complement
  6633.         representation is used for the mantissa rather than a sign-mantissa
  6634.         or 1's complement representation, then there is usually one extra
  6635.         negative machine number.
  6636.  
  6637.         8.b   To be honest:  If the Signed_Zeros attribute is True, then
  6638.         minus zero could in a sense be considered a value of the type.
  6639.         However, for most purposes, minus zero behaves the same as plus zero.
  6640.         {94-4448.a} {94-4889.e}
  6641.  
  6642. 9   {base decimal precision (of a floating point type)} The base decimal
  6643. precision of a floating point type is the number of decimal digits of
  6644. precision representable in objects of the type.  {safe range (of a floating
  6645. point type)} The safe range of a floating point type is that part of its base
  6646. range for which the accuracy corresponding to the base decimal precision is
  6647. preserved by all predefined operations.
  6648.  
  6649.         9.a   Implementation Note:  In most cases, the safe range and base
  6650.         range are the same.  However, for some hardware, values near the
  6651.         boundaries of the base range might result in excessive inaccuracies
  6652.         or spurious overflows when used with certain predefined operations.
  6653.         For such hardware, the safe range would omit such values.
  6654.  
  6655. 10   {base decimal precision [of a floating point type]} A floating_point_
  6656. definition defines a floating point type whose base decimal precision is no
  6657. less than the requested decimal precision.  {94-4935.a} {94-4913.f} {safe
  6658. range [of a floating point type]} {base range [of a floating point type]} If
  6659. a real_range_specification is given, the safe range of the floating point
  6660. type (and hence, also its base range) includes at least the values of the
  6661. simple expressions given in the real_range_specification.  If a real_range_
  6662. specification is not given, the safe (and base) range of the type includes at
  6663. least the values of the range -10.0**(4*D) .. +10.0**(4*D) where D is the
  6664. requested decimal precision.  [The safe range might include other values as
  6665. well.  The attributes Safe_First and Safe_Last give the actual bounds of the
  6666. safe range.]
  6667.  
  6668. 11   A floating_point_definition also defines a first subtype of the type.
  6669. {constrained (subtype)} {unconstrained (subtype)} If a real_range_
  6670. specification is given, then the subtype is constrained to a range whose
  6671. bounds are given by a conversion of the values of the simple_expressions of
  6672. the real_range_specification to the type being defined.  {implicit subtype
  6673. conversion [bounds of a floating point type]} Otherwise, the subtype is
  6674. unconstrained.
  6675.  
  6676. 12   {Float} There is a predefined, unconstrained, floating point subtype
  6677. named Float[, declared in the visible part of package Standard].
  6678.  
  6679.  
  6680.                               Dynamic Semantics
  6681.  
  6682. 13   {elaboration [floating_point_definition]} [The elaboration of a
  6683. floating_point_definition creates the floating point type and its first
  6684. subtype.]
  6685.  
  6686.  
  6687.                          Implementation Requirements
  6688.  
  6689. 14   {Float} In an implementation that supports floating point types with 6
  6690. or more digits of precision, the requested decimal precision for Float shall
  6691. be at least 6.
  6692.  
  6693. 15   {Long_Float} If Long_Float is predefined for an implementation, then its
  6694. requested decimal precision shall be at least 11.
  6695.  
  6696.  
  6697.                          Implementation Permissions
  6698.  
  6699. 16   {Short_Float} {Long_Float} An implementation is allowed to provide
  6700. additional predefined floating point types[, declared in the visible part of
  6701. Standard], whose (unconstrained) first subtypes have names of the form Short_
  6702. Float, Long_Float, Short_Short_Float, Long_Long_Float, etc.  Different
  6703. predefined floating point types are allowed to have the same base decimal
  6704. precision.  However, the precision of Float should be no greater than that of
  6705. Long_Float.  Similarly, the precision of Short_Float (if provided) should be
  6706. no greater than Float.  Corresponding recommendations apply to any other
  6707. predefined floating point types.  There need not be a named floating point
  6708. type corresponding to each distinct base decimal precision supported by an
  6709. implementation.
  6710.  
  6711.         16.a   Implementation defined:  The predefined floating point types
  6712.         declared in Standard.
  6713.  
  6714.  
  6715.                             Implementation Advice
  6716.  
  6717. 17   {Long_Float} An implementation should support Long_Float in addition to
  6718. Float if the target machine supports 11 or more digits of precision.  No
  6719. other named floating point subtypes are recommended for package Standard.
  6720. Instead, appropriate named floating point subtypes should be provided in the
  6721. library package Interfaces (see B.2).
  6722.  
  6723.         17.a   Implementation Note:  To promote portability, implementations
  6724.         should explicitly declare the floating point (sub)types Float and
  6725.         Long_Float in Standard, and leave other predefined float types
  6726.         anonymous.  For implementations that already support Short_Float,
  6727.         etc., upward compatibility argues for keeping such declarations in
  6728.         Standard during the transition period, but perhaps generating a
  6729.         warning on use.  A separate package Interfaces in the predefined
  6730.         environment is available for pre-declaring types such as Float_32,
  6731.         IEEE_Float_64, etc.  See B.2.
  6732.  
  6733.  
  6734.      NOTES
  6735. 18   (33) If a floating point subtype is unconstrained, then assignments to
  6736.      variables of the subtype involve only Overflow_Checks, never Range_
  6737.      Checks.
  6738.  
  6739.  
  6740.                                   Examples
  6741.  
  6742. 19   Examples of floating point types and subtypes:
  6743.  
  6744. 20  type Coefficient is digits 10 range -1.0 .. 1.0;
  6745.  
  6746. 21  type Real is digits 8;
  6747.     type Mass is digits 7 range 0.0 .. 1.0E35;
  6748.  
  6749. 22  subtype Probability is Real range 0.0 .. 1.0;   --   a subtype with a small\
  6750. er range
  6751.  
  6752.  
  6753.                          Inconsistencies With Ada 83
  6754.  
  6755.         22.a   {inconsistencies with Ada 83} No Range_Checks, only Overflow_
  6756.         Checks, are performed on variables (or parameters) of an
  6757.         unconstrained floating point subtype.  This is upward compatible for
  6758.         programs that do not raise Constraint_Error.  For those that do raise
  6759.         Constraint_Error, it is possible that the exception will be raised at
  6760.         a later point, or not at all, if extended range floating point
  6761.         registers are used to hold the value of the variable (or parameter).
  6762.  
  6763.         22.b   Reason:  This change was felt to be justified by the
  6764.         possibility of improved performance on machines with extended-range
  6765.         floating point registers.  An implementation need not take advantage
  6766.         of this relaxation in the range checking; it can hide completely the
  6767.         use of extended range registers if desired, presumably at some
  6768.         run-time expense.
  6769.                          Wording Changes From Ada 83
  6770.  
  6771.         22.c   The syntax rules for floating_point_constraint and floating_
  6772.         accuracy_definition are removed.  The syntax rules for floating_
  6773.         point_definition and real_range_specification are new.
  6774.  
  6775.         22.d   A syntax rule for digits_constraint is given in 3.5.9, ``Fixed
  6776.         Point Types''.  In J.3 we indicate that a digits_constraint may be
  6777.         applied to a floating point subtype_mark as well (to be compatible
  6778.         with Ada 83's floating_point_constraint).
  6779.  
  6780.         22.e   Discussion of model numbers is postponed to 3.5.8 and G.2.
  6781.         The concept of safe numbers has been replaced by the concept of the
  6782.         safe range of values.  The bounds of the safe range are given by
  6783.         T'Safe_First .. T'Safe_Last, rather than -T'Safe_Large ..  T'Safe_
  6784.         Large, since on some machines the safe range is not perfectly
  6785.         symmetric.  The concept of machine numbers is new, and is relevant to
  6786.         the definition of Succ and Pred for floating point numbers.
  6787.  
  6788.  
  6789.  
  6790. 3.5.8 Operations of Floating Point Types
  6791.  
  6792.                               Static Semantics
  6793.  
  6794. 1   The following attribute is defined for every floating point subtype S:
  6795.  
  6796.         1.a   Change:  Editorial change -- plural to singular in above
  6797.         phrase.
  6798.  
  6799. 2   S'Digits
  6800.                 S'Digits denotes the requested decimal precision for the
  6801.                 subtype S. The value of this attribute is of the type
  6802.                 universal_integer.  The requested decimal precision of the
  6803.                 base subtype of a floating point type T is defined to be the
  6804.                 largest value of d for which ceiling(d * log(10) /
  6805.                 log(T'Machine_Radix)) + 1 <= T'Model_Mantissa.  {94-4935.a}
  6806.                 {94-4913.f}
  6807.  
  6808.  
  6809.      NOTES
  6810. 3    (34) {predefined operations [of a floating point type]} The predefined
  6811.      operations of a floating point type include the assignment operation,
  6812.      qualification, the membership tests, and explicit conversion to and from
  6813.      other numeric types.  They also include the relational operators and the
  6814.      following predefined arithmetic operators:  the binary and unary adding
  6815.      operators - and +, certain multiplying operators, the unary operator
  6816.      abs, and the exponentiation operator.  {94-4693.v}
  6817.  
  6818. 4    (35) As for all types, objects of a floating point type have Size and
  6819.      Address attributes (see 13.3).  Other attributes of floating point types
  6820.      are defined in A.5.3.
  6821.  
  6822.  
  6823.  
  6824. 3.5.9 Fixed Point Types
  6825.  
  6826. 1   {fixed point type} {ordinary fixed point type} {decimal fixed point type}
  6827. A fixed point type is either an ordinary fixed point type, or a decimal fixed
  6828. point type.  {delta (of a fixed point type)} The error bound of a fixed point
  6829. type is specified as an absolute value, called the delta of the fixed point
  6830. type.
  6831.  
  6832.  
  6833.                                    Syntax
  6834.  
  6835. 2   fixed_point_definition ::= ordinary_fixed_point_definition | decimal_fixed_\
  6836. point_definition
  6837.  
  6838. 3   ordinary_fixed_point_definition ::=
  6839.        delta static_expression  real_range_specification
  6840.  
  6841. 4   decimal_fixed_point_definition ::=
  6842.        delta static_expression digits static_expression [real_range_specificati\
  6843. on]
  6844.  
  6845. 5   digits_constraint ::=
  6846.        digits static_expression [range_constraint]
  6847.  
  6848.  
  6849.                             Name Resolution Rules
  6850.  
  6851. 6   {expected type [fixed point type delta]} For a type defined by a fixed_
  6852. point_definition, the delta of the type is specified by the value of the
  6853. expression given after the reserved word delta; this expression is expected
  6854. to be of any real type.  {expected type [decimal fixed point type digits]}
  6855. {digits (of a decimal fixed point subtype)} {decimal fixed point type} For a
  6856. type defined by a decimal_fixed_point_definition (a decimal fixed point
  6857. type), the number of significant decimal digits for its first subtype (the
  6858. digits of the first subtype) is specified by the expression given after the
  6859. reserved word digits; this expression is expected to be of any integer type.
  6860.  
  6861.  
  6862.                                Legality Rules
  6863.  
  6864. 7   In a fixed_point_definition or digits_constraint, the expressions given
  6865. after the reserved words delta and digits shall be static; their values shall
  6866. be positive.
  6867.  
  6868. 8   {small (of a fixed point type)} The set of values of a fixed point type
  6869. comprise the integral multiples of a number called the small of the type.
  6870. {ordinary fixed point type} For a type defined by an ordinary_fixed_point_
  6871. definition (an ordinary fixed point type), the small may be specified by an
  6872. attribute_definition_clause (see 13.3); if so specified, it shall be no
  6873. greater than the delta of the type.  If not specified, the small of an
  6874. ordinary fixed point type is an implementation-defined power of two less than
  6875. or equal to the delta.
  6876.  
  6877.         8.a   Implementation defined:  The small of an ordinary fixed point
  6878.         type.
  6879.  
  6880. 9   For a decimal fixed point type, the small equals the delta; the delta
  6881. shall be a power of 10.  If a real_range_specification is given, both bounds
  6882. of the range shall be in the range -(10**digits-1)*delta ..
  6883. +(10**digits-1)*delta.
  6884.  
  6885. 10   A fixed_point_definition is illegal if the implementation does not
  6886. support a fixed point type with the given small and specified range or
  6887. digits.
  6888.  
  6889.         10.a   Implementation defined:  What combinations of small, range,
  6890.         and digits are supported for fixed point types.
  6891.  
  6892. 11   For a subtype_indication with a digits_constraint, the subtype_mark
  6893. shall denote a decimal fixed point subtype.
  6894.  
  6895.         11.a   To be honest:  Or, as an obsolescent feature, a floating point
  6896.         subtype is permitted -- see J.3.
  6897.  
  6898.  
  6899.                               Static Semantics
  6900.  
  6901. 12   {base range [of a fixed point type]} The base range (see 3.5) of a fixed
  6902. point type is symmetric around zero, except possibly for an extra negative
  6903. value in some implementations.
  6904.  
  6905. 13   {base range [of an ordinary fixed point type]} An ordinary_fixed_point_
  6906. definition defines an ordinary fixed point type whose base range includes at
  6907. least all multiples of small that are between the bounds specified in the
  6908. real_range_specification.  The base range of the type does not necessarily
  6909. include the specified bounds themselves.  {constrained (subtype)}
  6910. {unconstrained (subtype)} An ordinary_fixed_point_definition also defines a
  6911. constrained first subtype of the type, with each bound of its range given by
  6912. the closer to zero of:
  6913.  
  6914.    14  the value of the conversion to the fixed point type of the
  6915.        corresponding expression of the real_range_specification;
  6916.        {implicit subtype conversion [bounds of a fixed point type]}
  6917.  
  6918.    15  the corresponding bound of the base range.
  6919.  
  6920. 16   {base range [of a decimal fixed point type]} A decimal_fixed_point_
  6921. definition defines a decimal fixed point type whose base range includes at
  6922. least the range -(10**digits-1)*delta .. +(10**digits-1)*delta.  {constrained
  6923. (subtype)} {unconstrained (subtype)} A decimal_fixed_point_definition also
  6924. defines a constrained first subtype of the type.  If a real_range_
  6925. specification is given, the bounds of the first subtype are given by a
  6926. conversion of the values of the expressions of the real_range_specification.
  6927. {implicit subtype conversion [bounds of a decimal fixed point type]}
  6928. Otherwise, the range of the first subtype is -(10**digits-1)*delta ..
  6929. +(10**digits-1)*delta.
  6930.  
  6931.  
  6932.                               Dynamic Semantics
  6933.  
  6934. 17   {elaboration [fixed_point_definition]} The elaboration of a fixed_point_
  6935. definition creates the fixed point type and its first subtype.
  6936.  
  6937. 18   For a digits_constraint on a decimal fixed point subtype with a given
  6938. delta, if it does not have a range_constraint, then it specifies an implicit
  6939. range -(10**D-1)*delta .. +(10**D-1)*delta, where D is the value of the
  6940. expression.  {compatibility (digits_constraint with a decimal fixed point
  6941. subtype)} A digits_constraint is compatible with a decimal fixed point
  6942. subtype if the value of the expression is no greater than the digits of the
  6943. subtype, and if it specifies (explicitly or implicitly) a range that is
  6944. compatible with the subtype.
  6945.  
  6946.         18.a   Discussion:  Except for the requirement that the digits
  6947.         specified be no greater than the digits of the subtype being
  6948.         constrained, a digits_constraint is essentially equivalent to a
  6949.         range_constraint.
  6950.  
  6951.         18.b   Consider the following example:
  6952.  
  6953. 18.c        type D is delta 0.01 digits 7 range -0.00 .. 9999.99;
  6954.  
  6955.         18.d   The compatibility rule implies that the digits_constraint
  6956.         "digits 6" specifies an implicit range of "- 99.9999 .. 99.9999".
  6957.         Thus, "digits 6" is not compatible with the constraint of D, but
  6958.         "digits 6 range 0.00 .. 9999.99" is compatible.  {94-4502.a}
  6959.  
  6960.         18.e   A value of a scalar type belongs to a constrained subtype of
  6961.         the type if it belongs to the range of the subtype.  Attributes like
  6962.         Digits and Delta have no affect on this fundamental rule.  So the
  6963.         obsolescent forms of digits_constraints and delta_constraints that
  6964.         are called ``accuracy constraints'' in RM83 don't really represent
  6965.         constraints on the values of the subtype, but rather primarily affect
  6966.         compatibility of the ``constraint'' with the subtype being
  6967.         ``constrained.''  In this sense, they might better be called
  6968.         ``subtype assertions'' rather than ``constraints.''
  6969.  
  6970.         18.f   Note that the digits_constraint on a decimal fixed point
  6971.         subtype is a combination of an assertion about the digits of the
  6972.         subtype being further constrained, and a constraint on the range of
  6973.         the subtype being defined, either explicit or implicit.
  6974.  
  6975. 19   {elaboration [digits_constraint]} The elaboration of a digits_constraint
  6976. consists of the elaboration of the range_constraint, if any.  {Range_Check
  6977. [partial]} {check, language-defined (Range_Check)} If a range_constraint is
  6978. given, a check is made that the bounds of the range are both in the range
  6979. -(10**D-1)*delta .. +(10**D-1)*delta, where D is the value of the (static)
  6980. expression given after the reserved word digits.  {Constraint_Error (raised
  6981. by failure of run-time check)} If this check fails, Constraint_Error is
  6982. raised.
  6983.  
  6984.  
  6985.                          Implementation Requirements
  6986.  
  6987. 20   The implementation shall support at least 24 bits of precision
  6988. (including the sign bit) for fixed point types.
  6989.  
  6990.         20.a   Reason:  This is sufficient to represent Standard.Duration
  6991.         with a small no more than 50 milliseconds.
  6992.  
  6993.  
  6994.                          Implementation Permissions
  6995.  
  6996. 21   Implementations are permitted to support only smalls that are a power of
  6997. two.  In particular, all decimal fixed point type declarations can be
  6998. disallowed.  Note however that conformance with the Information Systems Annex
  6999. requires support for decimal smalls, and decimal fixed point type
  7000. declarations with digits up to at least 18.
  7001.  
  7002.         21.a   Implementation Note:  The accuracy requirements for
  7003.         multiplication, division, and conversion (see G.2.1, ``Model of
  7004.         Floating Point Arithmetic'') are such that support for arbitrary
  7005.         smalls should be practical without undue implementation effort.
  7006.         Therefore, implementations should support fixed point types with
  7007.         arbitrary values for small (within reason).  One reasonable
  7008.         limitation would be to limit support to fixed point types that can be
  7009.         converted to the most precise floating point type without loss of
  7010.         precision (so that Fixed_IO is implementable in terms of Float_IO).
  7011.  
  7012.  
  7013.      NOTES
  7014. 22   (36)  The base range of an ordinary fixed point type need not include
  7015.      the specified bounds themselves so that the range specification can be
  7016.      given in a natural way, such as:
  7017.  
  7018. 23       type Fraction is delta 2.0**(-15) range -1.0 .. 1.0;
  7019.  
  7020.      24   With 2's complement hardware, such a type could have a signed
  7021.      16-bit representation, using 1 bit for the sign and 15 bits for
  7022.      fraction, resulting in a base range of -1.0 .. 1.0-2.0**(-15).
  7023.  
  7024.  
  7025.                                   Examples
  7026.  
  7027. 25   Examples of fixed point types and subtypes:
  7028.  
  7029. 26  type Volt is delta 0.125 range 0.0 .. 255.0;
  7030.  
  7031. 27    --  A pure fraction which requires all the available
  7032.       --  space in a word can be declared as the type Fraction:
  7033.     type Fraction is delta System.Fine_Delta range -1.0 .. 1.0;
  7034.       --  Fraction'Last = 1.0 - System.Fine_Delta
  7035.  
  7036. 28  type Money is delta 0.01 digits 15;  -- decimal fixed point
  7037.     subtype Salary is Money digits 10;
  7038.       -- Money'Last = 10.0**13 - 0.01, Salary'Last = 10.0**8 - 0.01
  7039.  
  7040.  
  7041.                          Inconsistencies With Ada 83
  7042.  
  7043.         28.a   {inconsistencies with Ada 83} In Ada 9X, S'Small always equals
  7044.         S'Base'Small, so if an implementation chooses a small for a fixed
  7045.         point type smaller than required by the delta, the value of S'Small
  7046.         in Ada 9X might not be the same as it was in Ada 83.
  7047.  
  7048.                             Extensions to Ada 83
  7049.  
  7050.         28.b   {extensions to Ada 83} Decimal fixed point types are new,
  7051.         though their capabilities are essentially similar to that available
  7052.         in Ada 83 with a fixed point type whose small equals its delta equals
  7053.         a power of 10.  However, in the Information Systems Annex, additional
  7054.         requirements are placed on the support of decimal fixed point types
  7055.         (e.g. a minimum of 18 digits of precision).
  7056.  
  7057.                          Wording Changes From Ada 83
  7058.  
  7059.         28.c   The syntax rules for fixed_point_constraint and fixed_
  7060.         accuracy_definition are removed.  The syntax rule for fixed_point_
  7061.         definition is new.  A syntax rule for delta_constraint is included in
  7062.         the Obsolescent features (to be compatible with Ada 83's fixed_point_
  7063.         constraint).
  7064.  
  7065.  
  7066.  
  7067. 3.5.10 Operations of Fixed Point Types
  7068.  
  7069.                               Static Semantics
  7070.  
  7071. 1   The following attributes are defined for every fixed point subtype S:
  7072.  
  7073. 2   S'Small
  7074.                 S'Small denotes the small of the type of S. The value of this
  7075.                 attribute is of the type universal_real.  {specifiable [of
  7076.                 Small for fixed point types]} {Small clause} Small may be
  7077.                 specified for nonderived fixed point types via an attribute_
  7078.                 definition_clause (see 13.3); the expression of such a clause
  7079.                 shall be static.
  7080.  
  7081. 3   S'Delta
  7082.                 S'Delta denotes the delta of the fixed point subtype S. The
  7083.                 value of this attribute is of the type universal_real.
  7084.  
  7085. 3.a     Reason:  The delta is associated with the subtype as opposed to the
  7086.         type, because of the possibility of an (obsolescent) delta_
  7087.         constraint.
  7088.  
  7089. 4   S'Fore
  7090.                 S'Fore yields the minimum number of characters needed before
  7091.                 the decimal point for the decimal representation of any value
  7092.                 of the subtype S, assuming that the representation does not
  7093.                 include an exponent, but includes a one-character prefix that
  7094.                 is either a minus sign or a space.  (This minimum number does
  7095.                 not include superfluous zeros or underlines, and is at least
  7096.                 2.)  The value of this attribute is of the type universal_
  7097.                 integer.
  7098.  
  7099. 5   S'Aft
  7100.                 S'Aft yields the number of decimal digits needed after the
  7101.                 decimal point to accommodate the delta of the subtype S,
  7102.                 unless the delta of the subtype S is greater than 0.1, in
  7103.                 which case the attribute yields the value one.  [(S'Aft is
  7104.                 the smallest positive integer N for which (10**N)*S'Delta is
  7105.                 greater than or equal to one.)]  The value of this attribute
  7106.                 is of the type universal_integer.
  7107.  
  7108. 6   The following additional attributes are defined for every decimal fixed
  7109. point subtype S:
  7110.  
  7111. 7   S'Digits
  7112.                 S'Digits denotes the digits of the decimal fixed point
  7113.                 subtype S, which corresponds to the number of decimal digits
  7114.                 that are representable in objects of the subtype.  The value
  7115.                 of this attribute is of the type universal_integer.  Its
  7116.                 value is determined as follows:  {94-4768.k} {digits (of a
  7117.                 decimal fixed point subtype)}
  7118.  
  7119.                     8  For a first subtype or a subtype defined by a
  7120.                        subtype_indication with a digits_constraint, the
  7121.                        digits is the value of the expression given after
  7122.                        the reserved word digits;
  7123.  
  7124.                     9  For a subtype defined by a subtype_indication
  7125.                        without a digits_constraint, the digits of the
  7126.                        subtype is the same as that of the subtype
  7127.                        denoted by the subtype_mark in the subtype_
  7128.                        indication.
  7129.  
  7130.  9.a    Implementation Note:  Although a decimal subtype can be both
  7131.         range-constrained and digits-constrained, the digits constraint
  7132.         is intended to control the Size attribute of the subtype.  For
  7133.         decimal types, Size can be important because input/output of
  7134.         decimal types is so common.
  7135.  
  7136.                    10  The digits of a base subtype is the largest
  7137.                        integer D such that the range -(10**D-1)*delta ..
  7138.                        +(10**D-1)*delta is included in the base range of
  7139.                        the type.
  7140.  
  7141.  10.a   Change:  Made 3.5.10(10);5.7 into a bullet under S'Digits, rather
  7142.         than separately listing it under S'Base'Digits, as per WG9
  7143.         resolution.
  7144.  
  7145. 11  S'Scale
  7146.                 S'Scale denotes the scale of the subtype S, defined as the
  7147.                 value N such that S'Delta = 10.0**(-N).  {scale (of a decimal
  7148.                 fixed point subtype)} [The scale indicates the position of
  7149.                 the point relative to the rightmost significant digits of
  7150.                 values of subtype S.]  The value of this attribute is of the
  7151.                 type universal_integer.
  7152.  
  7153. 11.a    Ramification:  S'Scale is negative if S'Delta is greater than one.
  7154.         By contrast, S'Aft is always positive.
  7155.  
  7156. 12  S'Round
  7157.                 S'Round denotes a function with the following specification:
  7158.  
  7159. 13                  function S'Round(X : universal_real)
  7160.                       return S'Base
  7161.  
  7162.                 14   The function returns the value obtained by rounding X
  7163.                 (away from 0, if X is midway between two values of the type
  7164.                 of S).
  7165.      NOTES
  7166. 15   (37) All subtypes of a fixed point type will have the same value for the
  7167.      Delta attribute, in the absence of delta_constraints (see J.3).
  7168.  
  7169. 16   (38) S'Scale is not always the same as S'Aft for a decimal subtype; for
  7170.      example, if S'Delta = 1.0 then S'Aft is 1 while S'Scale is 0.
  7171.  
  7172. 17   (39) {predefined operations [of a fixed point type]} The predefined
  7173.      operations of a fixed point type include the assignment operation,
  7174.      qualification, the membership tests, and explicit conversion to and from
  7175.      other numeric types.  They also include the relational operators and the
  7176.      following predefined arithmetic operators:  the binary and unary adding
  7177.      operators - and +, multiplying operators, and the unary operator abs.
  7178.  
  7179. 18   (40) As for all types, objects of a fixed point type have Size and
  7180.      Address attributes (see 13.3).  Other attributes of fixed point types
  7181.      are defined in A.5.4.
  7182.  
  7183.  
  7184.  
  7185. 3.6 Array Types
  7186.  
  7187. 1   {array} {array type} An array object is a composite object consisting of
  7188. components which all have the same subtype.  The name for a component of an
  7189. array uses one or more index values belonging to specified discrete types.
  7190. The value of an array object is a composite value consisting of the values of
  7191. the components.
  7192.  
  7193.  
  7194.                                    Syntax
  7195.  
  7196. 2   array_type_definition ::=
  7197.        unconstrained_array_definition | constrained_array_definition
  7198.  
  7199. 3   unconstrained_array_definition ::=
  7200.        array(index_subtype_definition {, index_subtype_definition}) of componen\
  7201. t_definition
  7202.  
  7203. 4   index_subtype_definition ::= subtype_mark range <>
  7204.  
  7205. 5   constrained_array_definition ::=
  7206.        array (discrete_subtype_definition {, discrete_subtype_definition}) of c\
  7207. omponent_definition
  7208.  
  7209. 6   discrete_subtype_definition ::= discrete_subtype_indication | range
  7210.  
  7211. 7   component_definition ::= [aliased] subtype_indication
  7212.  
  7213.  
  7214.                             Name Resolution Rules
  7215.  
  7216. 8   {expected type [discrete_subtype_definition range]} For a discrete_
  7217. subtype_definition that is a range, the range shall resolve to be of some
  7218. specific discrete type[; which discrete type shall be determined without
  7219. using any context other than the bounds of the range itself (plus the
  7220. preference for root_integer -- see 8.6).]
  7221.  
  7222.  
  7223.                                Legality Rules
  7224.  
  7225. 9   {index subtype} Each index_subtype_definition or discrete_subtype_
  7226. definition in an array_type_definition defines an index subtype; {index type}
  7227. its type (the index type) shall be discrete.
  7228.  
  7229.         9.a   Discussion:  {index (of an array)} An index is a discrete
  7230.         quantity used to select along a given dimension of an array.  A
  7231.         component is selected by specifying corresponding values for each of
  7232.         the indices.
  7233.  
  7234. 10   {component subtype} The subtype defined by the subtype_indication of a
  7235. component_definition (the component subtype) shall be a definite subtype.
  7236.  
  7237.         10.a   Ramification:  This applies to all uses of component_
  7238.         definition, including in record_type_definitions and protected_
  7239.         definitions.
  7240.  
  7241. 11   Within the definition of a nonlimited composite type (or a limited
  7242. composite type that later in its immediate scope becomes nonlimited -- see
  7243. 7.3.1 and 7.5), if a component_definition contains the reserved word aliased
  7244. and the type of the component is discriminated, then the nominal subtype of
  7245. the component shall be constrained.
  7246.  
  7247.         11.a   Reason:  If we allowed the subtype to be unconstrained, then
  7248.         the discriminants might change because of an assignment to the
  7249.         containing (nonlimited) object, thus causing a potential violation of
  7250.         an access subtype constraint of an access value designating the
  7251.         aliased component.
  7252.  
  7253.         11.b   Note that the rule elsewhere defining all aliased
  7254.         discriminated objects to be constrained does not help -- that rule
  7255.         prevents assignments to the component itself from doing any harm, but
  7256.         not assignments to the containing object.  {94-4858.a}
  7257.  
  7258.         11.c   We allow this for components within limited types since
  7259.         assignment to the enclosing object is not a problem.  Furthermore, it
  7260.         is important to be able to use a default expression for a
  7261.         discriminant in arrays of limited components, since that is the only
  7262.         way to give the components different values for their discriminants.
  7263.         For example:
  7264.  
  7265. 11.d        protected type Counter_Type(Initial_Value : Integer := 1) is
  7266.                procedure Get_Next(Next_Value : out Integer);
  7267.                  -- Returns the next value on each call, bumping Count
  7268.                  -- before returning.
  7269.             private
  7270.                Count : Integer := Initial_Value;
  7271.             end Counter_Type;
  7272.             protected body Counter_Type is ...
  7273.  
  7274. 11.e        function Next_Id(Counter : access Counter_Type) return Integer is
  7275.                 Result : Integer;
  7276.             begin
  7277.                 Counter.Get_Next(Result);
  7278.                 return Result;
  7279.             end Next_Id;
  7280.  
  7281. 11.f        C : aliased Counter_Type;
  7282.             task type T(Who_Am_I : Integer := Next_Id(C'Access));
  7283.             task body T is ...
  7284.  
  7285. 11.g        Task_Array : array(1..100) of aliased T;
  7286.               -- Array of task elements, each with its own unique ID.
  7287.               -- We specify "aliased" so we can use Task_Array(I)'Access.
  7288.               -- This is safe because Task_Array is of a limited type,
  7289.               -- so there is no way an assignment to it could change
  7290.               -- the discriminants of one of its components.
  7291.  
  7292.         11.h   Ramification:  Note that this rule applies to array components
  7293.         and record components, but not to protected type components (since
  7294.         they are always limited).
  7295.  
  7296.  
  7297.                               Static Semantics
  7298.  
  7299. 12   {dimensionality (of an array)} {one-dimensional array} {multi-
  7300. dimensional array} An array is characterized by the number of indices (the
  7301. dimensionality of the array), the type and position of each index, the lower
  7302. and upper bounds for each index, and the subtype of the components.  The
  7303. order of the indices is significant.
  7304.  
  7305. 13   A one-dimensional array has a distinct component for each possible index
  7306. value.  A multidimensional array has a distinct component for each possible
  7307. sequence of index values that can be formed by selecting one value for each
  7308. index position (in the given order).  The possible values for a given index
  7309. are all the values between the lower and upper bounds, inclusive; {index
  7310. range} this range of values is called the index range.  {bounds (of an
  7311. array)} The bounds of an array are the bounds of its index ranges.  {length
  7312. (of a dimension of an array)} The length of a dimension of an array is the
  7313. number of values of the index range of the dimension (zero for a null range).
  7314. {length (of a one-dimensional array)} The length of a one-dimensional array
  7315. is the length of its only dimension.
  7316.  
  7317. 14   An array_type_definition defines an array type and its first subtype.
  7318. For each object of this array type, the number of indices, the type and
  7319. position of each index, and the subtype of the components are as in the type
  7320. definition[; the values of the lower and upper bounds for each index belong
  7321. to the corresponding index subtype of its type, except for null arrays (see
  7322. 3.6.1)].
  7323.  
  7324. 15   {constrained (subtype)} {unconstrained (subtype)} An unconstrained_
  7325. array_definition defines an array type with an unconstrained first subtype.
  7326. Each index_subtype_definition defines the corresponding index subtype to be
  7327. the subtype denoted by the subtype_mark.[{box [compound delimiter]} The
  7328. compound delimiter <> (called a box) of an index_subtype_definition stands
  7329. for an undefined range (different objects of the type need not have the same
  7330. bounds).]
  7331.  
  7332. 16   {constrained (subtype)} {unconstrained (subtype)} A constrained_array_
  7333. definition defines an array type with a constrained first subtype.  Each
  7334. discrete_subtype_definition defines the corresponding index subtype, as well
  7335. as the corresponding index range for the constrained first subtype.
  7336. {constraint [of a first array subtype]} The constraint of the first subtype
  7337. consists of the bounds of the index ranges.
  7338.  
  7339.         16.a   Discussion:  Although there is no namable unconstrained array
  7340.         subtype in this case, the predefined slicing and concatenation
  7341.         operations can operate on and yield values that do not necessarily
  7342.         belong to the first array subtype.  This is also true for Ada 83.
  7343.  
  7344. 17   The discrete subtype defined by a discrete_subtype_definition is either
  7345. that defined by the subtype_indication, or a subtype determined by the range
  7346. as follows:
  7347.  
  7348.    18  If the type of the range resolves to root_integer, then the
  7349.        discrete_subtype_definition defines a subtype of the predefined
  7350.        type Integer with bounds given by a conversion to Integer of the
  7351.        bounds of the range; {implicit subtype conversion [bounds of a
  7352.        range]}
  7353.  
  7354.  18.a   Reason:  This ensures that indexing over the discrete subtype
  7355.         can be performed with regular Integers, rather than only
  7356.         universal_integers.
  7357.  
  7358.  18.b   Discussion:  We considered doing this by simply creating a
  7359.         ``preference'' for Integer when resolving the range.
  7360.         {Beaujolais effect [partial]} However, this can introduce
  7361.         Beaujolais effects when the simple_expressions involve calls on
  7362.         functions visible due to use clauses.
  7363.  
  7364.    19  Otherwise, the discrete_subtype_definition defines a subtype of
  7365.        the type of the range, with the bounds given by the range.
  7366.  
  7367. 20   {nominal subtype [of a component]} The component_definition of an array_
  7368. type_definition defines the nominal subtype of the components.  If the
  7369. reserved word aliased appears in the component_definition, then each
  7370. component of the array is aliased (see 3.10).
  7371.  
  7372.         20.a   Ramification:  In this case, the nominal subtype cannot be an
  7373.         unconstrained discriminated subtype.  See 3.8.
  7374.  
  7375.  
  7376.                               Dynamic Semantics
  7377.  
  7378. 21   {elaboration [array_type_definition]} The elaboration of an array_type_
  7379. definition creates the array type and its first subtype, and consists of the
  7380. elaboration of any discrete_subtype_definitions and the component_definition.
  7381.  
  7382. 22   {elaboration [discrete_subtype_definition]} The elaboration of a
  7383. discrete_subtype_definition creates the discrete subtype, and consists of the
  7384. elaboration of the subtype_indication or the evaluation of the range.
  7385. {elaboration [component_definition]} The elaboration of a component_
  7386. definition in an array_type_definition consists of the elaboration of the
  7387. subtype_indication.  The elaboration of any discrete_subtype_definitions and
  7388. the elaboration of the component_definition are performed in an arbitrary
  7389. order.
  7390.  
  7391.  
  7392.      NOTES
  7393. 23   (41) All components of an array have the same subtype.  In particular,
  7394.      for an array of components that are one-dimensional arrays, this means
  7395.      that all components have the same bounds and hence the same length.
  7396.  
  7397. 24   (42) Each elaboration of an array_type_definition creates a distinct
  7398.      array type.  A consequence of this is that each object whose object_
  7399.      declaration contains an array_type_definition is of its own unique type.
  7400.  
  7401.  
  7402.                                   Examples
  7403.  
  7404. 25   Examples of type declarations with unconstrained array definitions:
  7405.  
  7406. 26  type Vector     is array(Integer  range <>) of Real;
  7407.     type Matrix     is array(Integer  range <>, Integer range <>) of Real;
  7408.     type Bit_Vector is array(Integer  range <>) of Boolean;
  7409.     type Roman      is array(Positive range <>) of Roman_Digit; -- see 3.5.2
  7410.  
  7411. 27   Examples of type declarations with constrained array definitions:
  7412.  
  7413. 28  type Table    is array(1 .. 10) of Integer;
  7414.     type Schedule is array(Day) of Boolean;
  7415.     type Line     is array(1 .. Max_Line_Size) of Character;
  7416.  
  7417. 29   Examples of object declarations with array type definitions:
  7418.  
  7419. 30  Grid : array(1 .. 80, 1 .. 100) of Boolean;
  7420.     Mix  : array(Color range Red .. Green) of Boolean;
  7421.     Page : array(Positive range <>) of Line :=  --  an array of arrays
  7422.       (1 | 50  => Line'(1 | Line'Last => '+', others => '-'),  -- see 4.3.3
  7423.        2 .. 49 => Line'(1 | Line'Last => '|', others => ' '));
  7424.         -- Page is constrained by its initial value to (1..50)
  7425.  
  7426.  
  7427.                             Extensions to Ada 83
  7428.  
  7429.         30.a   {extensions to Ada 83} The syntax rule for component_
  7430.         definition is modified to allow the reserved word aliased.
  7431.  
  7432.         30.b   The syntax rules for unconstrained_array_definition and
  7433.         constrained_array_definition are modified to use component_definition
  7434.         (instead of component_subtype_indication).  The effect of this change
  7435.         is to allow the reserved word aliased before the component subtype_
  7436.         indication.
  7437.  
  7438.         30.c   A range in a discrete_subtype_definition may use arbitrary
  7439.         universal expressions for each bound (e.g. -1 .. 3+5), rather than
  7440.         strictly "implicitly convertible" operands.  The subtype defined will
  7441.         still be a subtype of Integer.
  7442.  
  7443.                          Wording Changes From Ada 83
  7444.  
  7445.         30.d   We introduce a new syntactic category, discrete_subtype_
  7446.         definition, as distinct from discrete_range.  These two constructs
  7447.         have the same syntax, but their semantics are quite different (one
  7448.         defines a subtype, with a preference for Integer subtypes, while the
  7449.         other just selects a subrange of an existing subtype).  We use this
  7450.         new syntactic category in for loops and entry families.
  7451.  
  7452.         30.e   The syntax for index_constraint and discrete_range have been
  7453.         moved to their own subclause, since they are no longer used here.
  7454.  
  7455.         30.f   The syntax rule for component_definition (formerly component_
  7456.         subtype_definition) is moved here from RM83-3.7.
  7457.  
  7458.  
  7459.  
  7460. 3.6.1 Index Constraints and Discrete Ranges
  7461.  
  7462. 1   An index_constraint determines the range of possible values for every
  7463. index of an array subtype, and thereby the corresponding array bounds.
  7464.  
  7465.  
  7466.                                    Syntax
  7467.  
  7468. 2   index_constraint ::=  (discrete_range {, discrete_range})
  7469.  
  7470. 3   discrete_range ::= discrete_subtype_indication | range
  7471.  
  7472.  
  7473.                             Name Resolution Rules
  7474.  
  7475. 4   {type of a discrete_range} The type of a discrete_range is the type of
  7476. the subtype defined by the subtype_indication, or the type of the range.
  7477. {expected type [index_constraint discrete_range]} For an index_constraint,
  7478. each discrete_range shall resolve to be of the type of the corresponding
  7479. index.
  7480.  
  7481.         4.a   Discussion:  In Ada 9X, index_constraints only appear in a
  7482.         subtype_indication; they no longer appear in constrained_array_
  7483.         definitions.
  7484.  
  7485.  
  7486.                                Legality Rules
  7487.  
  7488. 5   An index_constraint shall appear only in a subtype_indication whose
  7489. subtype_mark denotes either an unconstrained array subtype, or an
  7490. unconstrained access subtype whose designated subtype is an unconstrained
  7491. array subtype; in either case, the index_constraint shall provide a discrete_
  7492. range for each index of the array type.
  7493.  
  7494.  
  7495.                               Static Semantics
  7496.  
  7497. 6   {bounds (of a discrete_range)} A discrete_range defines a range whose
  7498. bounds are given by the range, or by the range of the subtype defined by the
  7499. subtype_indication.
  7500.  
  7501.  
  7502.                               Dynamic Semantics
  7503.  
  7504. 7   {compatibility [index constraint with a subtype]} An index_constraint is
  7505. compatible with an unconstrained array subtype if and only if the index range
  7506. defined by each discrete_range is compatible (see 3.5) with the corresponding
  7507. index subtype.  {null array} If any of the discrete_ranges defines a null
  7508. range, any array thus constrained is a null array, having no components.
  7509. {satisfies [an index constraint]} An array value satisfies an index_
  7510. constraint if at each index position the array value and the index_constraint
  7511. have the same index bounds.
  7512.  
  7513.         7.a   Ramification:  There is no need to define compatibility with a
  7514.         constrained array subtype, because one is not allowed to constrain it
  7515.         again.
  7516.  
  7517. 8   {elaboration [index_constraint]} The elaboration of an index_constraint
  7518. consists of the evaluation of the discrete_range(s), in an arbitrary order.
  7519. {evaluation [discrete_range]} The evaluation of a discrete_range consists of
  7520. the elaboration of the subtype_indication or the evaluation of the range.
  7521.  
  7522.  
  7523.      NOTES
  7524. 9    (43) The elaboration of a subtype_indication consisting of a subtype_
  7525.      mark followed by an index_constraint checks the compatibility of the
  7526.      index_constraint with the subtype_mark (see 3.2.2).
  7527.  
  7528. 10   (44) Even if an array value does not satisfy the index constraint of an
  7529.      array subtype, Constraint_Error is not raised on conversion to the array
  7530.      subtype, so long as the length of each dimension of the array value and
  7531.      the array subtype match.  See 4.6.
  7532.  
  7533.  
  7534.                                   Examples
  7535.  
  7536. 11   Examples of array declarations including an index constraint:
  7537.  
  7538. 12  Board     : Matrix(1 .. 8,  1 .. 8);  --  see 3.6
  7539.     Rectangle : Matrix(1 .. 20, 1 .. 30);
  7540.     Inverse   : Matrix(1 .. N,  1 .. N);  --  N need not be static
  7541.  
  7542. 13  Filter    : Bit_Vector(0 .. 31);
  7543.  
  7544. 14   Example of array declaration with a constrained array subtype:
  7545.  
  7546. 15  My_Schedule : Schedule;  --  all arrays of type Schedule have the same boun\
  7547. ds
  7548.  
  7549. 16   Example of record type with a component that is an array:
  7550.  
  7551. 17  type Var_Line(Length : Natural) is
  7552.        record
  7553.           Image : String(1 .. Length);
  7554.        end record;
  7555.  
  7556. 18  Null_Line : Var_Line(0);  --  Null_Line.Image is a null array
  7557.  
  7558.  
  7559.                             Extensions to Ada 83
  7560.  
  7561.         18.a   {extensions to Ada 83} We allow the declaration of a variable
  7562.         with a nominally unconstrained array subtype, so long as it has an
  7563.         initialization expression to determine its bounds.
  7564.                          Wording Changes From Ada 83
  7565.  
  7566.         18.b   We have moved the syntax for index_constraint and discrete_
  7567.         range here since they are no longer used in constrained_array_
  7568.         definitions.  We therefore also no longer have to describe the
  7569.         (special) semantics of index_constraints and discrete_ranges that
  7570.         appear in constrained_array_definitions.
  7571.  
  7572.         18.c   The rules given in RM83-3.6.1(5,7-10), which define the bounds
  7573.         of an array object, are redundant with rules given elsewhere, and so
  7574.         are not repeated here.  RM83-3.6.1(6), which requires that the
  7575.         (nominal) subtype of an array variable be constrained, no longer
  7576.         applies, so long as the variable is explicitly initialized.
  7577.  
  7578.  
  7579.  
  7580. 3.6.2 Operations of Array Types
  7581.  
  7582.                                Legality Rules
  7583.  
  7584. 1   [The argument N used in the attribute_designators for the N-th dimension
  7585. of an array shall be a static expression of some integer type.]  The value of
  7586. N shall be positive (nonzero) and no greater than the dimensionality of the
  7587. array.
  7588.  
  7589.  
  7590.                               Static Semantics
  7591.  
  7592. 2   The following attributes are defined for a prefix A that is of an array
  7593. type [(after any implicit dereference)], or denotes a constrained array
  7594. subtype:
  7595.  
  7596.         2.a   Ramification:  These attributes are not defined if A is a
  7597.         subtype-mark for an access-to-array subtype.  They are defined (by
  7598.         implicit dereference) for access-to-array values.
  7599.  
  7600. 3   A'First
  7601.                 A'First denotes the lower bound of the first index range; its
  7602.                 type is the corresponding index type.
  7603.  
  7604. 4   A'First(N)
  7605.                 A'First(N) denotes the lower bound of the N-th index range;
  7606.                 its type is the corresponding index type.
  7607.  
  7608. 5   A'Last
  7609.                 A'Last denotes the upper bound of the first index range; its
  7610.                 type is the corresponding index type.
  7611.  
  7612. 6   A'Last(N)
  7613.                 A'Last(N) denotes the upper bound of the N-th index range;
  7614.                 its type is the corresponding index type.
  7615.  
  7616. 7   A'Range
  7617.                 A'Range is equivalent to the range A'First .. A'Last, except
  7618.                 that the prefix A is only evaluated once.
  7619.  
  7620. 8   A'Range(N)
  7621.                 A'Range(N) is equivalent to the range A'First(N) ..
  7622.                 A'Last(N), except that the prefix A is only evaluated once.
  7623.  
  7624. 9   A'Length
  7625.                 A'Length denotes the number of values of the first index
  7626.                 range (zero for a null range); its type is universal_integer.
  7627.  
  7628. 10  A'Length(N)
  7629.                 A'Length(N) denotes the number of values of the N-th index
  7630.                 range (zero for a null range); its type is universal_integer.
  7631.  
  7632.  
  7633.                             Implementation Advice
  7634.  
  7635. 11   An implementation should normally represent multidimensional arrays in
  7636. row-major order, consistent with the notation used for multidimensional array
  7637. aggregates (see 4.3.3).  However, if a pragma Convention(Fortran, ...)
  7638. applies to a multidimensional array type, then column-major order should be
  7639. used instead (see B.5, ``Interfacing with Fortran'').
  7640.  
  7641.  
  7642.      NOTES
  7643. 12   (45) The attribute_references A'First and A'First(1) denote the same
  7644.      value.  A similar relation exists for the attribute_references A'Last,
  7645.      A'Range, and A'Length.  The following relation is satisfied (except for
  7646.      a null array) by the above attributes if the index type is an integer
  7647.      type:
  7648.  
  7649. 13       A'Length(N) = A'Last(N) - A'First(N) + 1
  7650.  
  7651. 14   (46) An array type is limited if its component type is limited (see
  7652.      7.5).
  7653.  
  7654. 15   (47) {predefined operations [of an array type]} The predefined
  7655.      operations of an array type include the membership tests, qualification,
  7656.      and explicit conversion.  If the array type is not limited, they also
  7657.      include assignment and the predefined equality operators.  For a
  7658.      one-dimensional array type, they include the predefined concatenation
  7659.      operators (if nonlimited) and, if the component type is discrete, the
  7660.      predefined relational operators; if the component type is boolean, the
  7661.      predefined logical operators are also included.
  7662.  
  7663. 16   (48) A component of an array can be named with an indexed_component.  A
  7664.      value of an array type can be specified with an array_aggregate, unless
  7665.      the array type is limited.  For a one-dimensional array type, a slice of
  7666.      the array can be named; also, string literals are defined if the
  7667.      component type is a character type.
  7668.  
  7669.  
  7670.                                   Examples
  7671.  
  7672. 17   Examples (using arrays declared in the examples of subclause 3.6.1):
  7673.  
  7674. 18  --  Filter'First       =    0   Filter'Last        =  31   Filter'Length  =\
  7675.   32
  7676.     --  Rectangle'Last(1)  =   20   Rectangle'Last(2)  =  30
  7677.  
  7678.  
  7679.  
  7680. 3.6.3 String Types
  7681.  
  7682.                               Static Semantics
  7683.  
  7684. 1   {string type} A one-dimensional array type whose component type is a
  7685. character type is called a string type.
  7686.  
  7687. 2   [There are two predefined string types, String and Wide_String, each
  7688. indexed by values of the predefined subtype Positive; these are declared in
  7689. the visible part of package Standard:
  7690.  
  7691. 3   subtype Positive is Integer range 1 .. Integer'Last;
  7692.  
  7693. 4   type String is array(Positive range <>) of Character;
  7694.     type Wide_String is array(Positive range <>) of Wide_Character;
  7695.  
  7696. ]
  7697.  
  7698.  
  7699.      NOTES
  7700. 5    (49) String literals (see 2.6 and 4.2) are defined for all string types.
  7701.      The concatenation operator & is predefined for string types, as for all
  7702.      nonlimited one-dimensional array types.  The ordering operators <, <=,
  7703.      >, and >= are predefined for string types, as for all one-dimensional
  7704.      discrete array types; these ordering operators correspond to
  7705.      lexicographic order (see 4.5.2).
  7706.  
  7707.  
  7708.                                   Examples
  7709.  
  7710. 6   Examples of string objects:
  7711.  
  7712. 7   Stars      : String(1 .. 120) := (1 .. 120 => '*' );
  7713.     Question   : constant String  := "How many characters?";
  7714.                                                    --  Question'First = 1, Ques\
  7715. tion'Last = 20
  7716.                                                    --  Question'Length = 20 (th\
  7717. e number of characters)
  7718.  
  7719. 8   Ask_Twice  : String  := Question & Question;   --  constrained to (1..40)
  7720.     Ninety_Six : constant Roman   := "XCVI";      --  see 3.5.2 and 3.6
  7721.  
  7722.  
  7723.                          Inconsistencies With Ada 83
  7724.  
  7725.         8.a   {inconsistencies with Ada 83} The declaration of Wide_String in
  7726.         Standard hides a use-visible declaration with the same defining_
  7727.         identifier.  In rare cases, this might result in an inconsistency
  7728.         between Ada 83 and Ada 9X.
  7729.  
  7730.                         Incompatibilities With Ada 83
  7731.  
  7732.         8.b   {incompatibilities with Ada 83} Because both String and Wide_
  7733.         String are always directly visible, an expression like
  7734.  
  7735. 8.c         "a" < "bc"
  7736.  
  7737.         8.d   is now ambiguous, whereas in Ada 83 both string literals could
  7738.         be resolved to type String.
  7739.  
  7740.                             Extensions to Ada 83
  7741.  
  7742.         8.e   {extensions to Ada 83} The type Wide_String is new (though it
  7743.         was approved by ARG for Ada 83 compilers as well).
  7744.  
  7745.                          Wording Changes From Ada 83
  7746.  
  7747.         8.f   We define the term string type as a natural analogy to the term
  7748.         character type.
  7749.  
  7750.  
  7751.  
  7752. 3.7 Discriminants
  7753.  
  7754. 1   [{discriminant} {type parameter: see discriminant} {parameter: see also
  7755. discriminant} A composite type (other than an array type) can have
  7756. discriminants, which parameterize the type.  A known_discriminant_part
  7757. specifies the discriminants of a composite type.  A discriminant of an object
  7758. is a component of the object, and is either of a discrete type or an access
  7759. type.  An unknown_discriminant_part in the declaration of a partial view of a
  7760. type specifies that the discriminants of the type are unknown for the given
  7761. view; all subtypes of such a partial view are indefinite subtypes.]
  7762.  
  7763.         1.a   Glossary entry:  {Discriminant} A discriminant is a parameter
  7764.         of a composite type.  It can control, for example, the bounds of a
  7765.         component of the type if that type is an array type.  A discriminant
  7766.         of a task type can be used to pass data to a task of the type upon
  7767.         creation.
  7768.  
  7769.         1.b   Discussion:  {unknown discriminants [partial]} {discriminants
  7770.         [unknown]} A type, and all of its subtypes, have unknown
  7771.         discriminants when the number or names of the discriminants, if any,
  7772.         are unknown at the point of the type declaration.  A discriminant_
  7773.         part of (<>) is used to indicate unknown discriminants.
  7774.  
  7775.  
  7776.                                    Syntax
  7777.  
  7778. 2   discriminant_part ::= unknown_discriminant_part | known_discriminant_part
  7779.  
  7780. 3   unknown_discriminant_part ::= (<>)
  7781.  
  7782. 4   known_discriminant_part ::=
  7783.        (discriminant_specification {; discriminant_specification})
  7784.  
  7785. 5   discriminant_specification ::=
  7786.        defining_identifier_list : subtype_mark [:= default_expression]
  7787.      | defining_identifier_list : access_definition [:= default_expression]
  7788.  
  7789. 6   default_expression ::= expression
  7790.  
  7791.  
  7792.                             Name Resolution Rules
  7793.  
  7794. 7   {expected type [discriminant default_expression]} The expected type for
  7795. the default_expression of a discriminant_specification is that of the
  7796. corresponding discriminant.
  7797.  
  7798.  
  7799.                                Legality Rules
  7800.  
  7801. 8   A known_discriminant_part is only permitted in a declaration for a
  7802. composite type that is not an array type [(this includes generic formal
  7803. types)]; {discriminated type} a type declared with a known_discriminant_part
  7804. is called a discriminated type, as is a type that inherits (known)
  7805. discriminants.
  7806.  
  7807.         8.a   Implementation Note:  Discriminants on array types were
  7808.         considered, but were omitted to ease (existing) implementations.
  7809.  
  7810.         8.b   Discussion:  Note that the above definition for ``discriminated
  7811.         type'' does not include types declared with an unknown_discriminant_
  7812.         part.  This seems consistent with Ada 83, where such types (in a
  7813.         generic formal part) would not be considered discriminated types.
  7814.         Furthermore, the full type for a type with unknown discriminants need
  7815.         not even be composite, much less have any discriminants.
  7816.  
  7817. 9   The subtype of a discriminant may be defined by a subtype_mark, in which
  7818. case the subtype_mark shall denote a discrete or access subtype, or it may be
  7819. defined by an access_definition [(in which case the subtype_mark of the
  7820. access_definition may denote any kind of subtype)].  {access discriminant} A
  7821. discriminant that is defined by an access_definition is called an access
  7822. discriminant and is of an anonymous general access-to-variable type whose
  7823. designated subtype is denoted by the subtype_mark of the access_definition.
  7824.  
  7825.         9.a   Reason:  In an earlier version of Ada 9X, we allowed access
  7826.         discriminants on nonlimited types, but this created unpleasant
  7827.         complexities.  It turned out to be simpler and more uniform to allow
  7828.         discriminants of a named access type on any discriminated type, and
  7829.         keep access discriminants just for limited types.
  7830.  
  7831.         9.b   Note that discriminants of a named access type are not
  7832.         considered ``access discriminants.''  Similarly, ``access parameter''
  7833.         only refers to a formal parameter defined by an access_definition.
  7834.  
  7835. 10   A discriminant_specification for an access discriminant shall appear
  7836. only in the declaration for a task or protected type, or for a type with the
  7837. reserved word limited in its [(full)] definition or in that of one of its
  7838. ancestors.  In addition to the places where Legality Rules normally apply
  7839. (see 12.3), this rule applies also in the private part of an instance of a
  7840. generic unit.
  7841.  
  7842.         10.a   Discussion:  This rule implies that a type can have an access
  7843.         discriminant if the type is limited, but not if the only reason it's
  7844.         limited is because of a limited component.  Compare with the
  7845.         definition of limited type in 7.5.
  7846.  
  7847.         10.b   Ramification:  It is a consequence of this rule that only a
  7848.         return-by-reference type can have an access discriminant (see 6.5).
  7849.         This is important to avoid dangling references to local variables.
  7850.  
  7851.         10.c   Reason:  We also considered the following rules:
  7852.  
  7853.          10.d  If a type has an access discriminant, this automatically
  7854.                makes it limited, just like having a limited component
  7855.                automatically makes a type limited.  This was rejected
  7856.                because it decreases program readability, and because it
  7857.                seemed error prone (two bugs in a previous version of the
  7858.                RM9X were attributable to this rule).
  7859.  
  7860.          10.e  A type with an access discriminant shall be limited.
  7861.                This is equivalent to the rule we actually chose, except
  7862.                that it allows a type to have an access discriminant if
  7863.                it is limited just because of a limited component.  For
  7864.                example, any record containing a task would be allowed to
  7865.                have an access discriminant, whereas the actual rule
  7866.                requires ``limited record''.  This rule was also rejected
  7867.                due to readability concerns, and because would interact
  7868.                badly with the rules for limited types that ``become
  7869.                nonlimited''.
  7870.  
  7871. 11   Default_expressions shall be provided either for all or for none of the
  7872. discriminants of a known_discriminant_part.  No default_expressions are
  7873. permitted in a known_discriminant_part in a declaration of a tagged type [or
  7874. a generic formal type].
  7875.  
  7876.         11.a   Reason:  The all-or-none rule is related to the rule that a
  7877.         discriminant constraint shall specify values for all discriminants.
  7878.         One could imagine a different rule that allowed a constraint to
  7879.         specify only some of the discriminants, with the others provided by
  7880.         default.  Having defaults for discriminants has a special
  7881.         significance -- it allows objects of the type to be unconstrained,
  7882.         with the discriminants alterable as part of assigning to the object.
  7883.  
  7884.         11.b   Defaults for discriminants of tagged types are disallowed so
  7885.         that every object of a tagged type is constrained, either by an
  7886.         explicit constraint, or by its initial discriminant values.
  7887.         {94-4858.a} This substantially simplifies the semantic rules and the
  7888.         implementation of inherited dispatching operations.  For generic
  7889.         formal types, the restriction simplifies the type matching rules.  If
  7890.         one simply wants a "default" value for the discriminants, a
  7891.         constrained subtype can be declared for future use.
  7892.  
  7893. 12   For a type defined by a derived_type_definition, if a known_
  7894. discriminant_part is provided in its declaration, then:
  7895.  
  7896.    13  The parent subtype shall be constrained;
  7897.  
  7898.    14  If the parent type is not a tagged type, then each discriminant
  7899.        of the derived type shall be used in the constraint defining the
  7900.        parent subtype;
  7901.  
  7902.  14.a   Implementation Note:  This ensures that the new discriminant can
  7903.         share storage with an existing discriminant.
  7904.  
  7905.    15  If a discriminant is used in the constraint defining the parent
  7906.        subtype, the subtype of the discriminant shall be statically
  7907.        compatible (see 4.9.1) with the subtype of the corresponding
  7908.        parent discriminant.
  7909.  
  7910.  15.a   Reason:  This ensures that on conversion (or extension via an
  7911.         extension aggregate) to a distantly related type, if the
  7912.         discriminants satisfy the target type's requirements they
  7913.         satisfy all the intermediate types' requirements as well.
  7914.  
  7915.  15.b   Ramification:  There is no requirement that the new discriminant
  7916.         have the same (or any) default_expression as the parent's
  7917.         discriminant.
  7918.  
  7919. 16   The type of the default_expression, if any, for an access discriminant
  7920. shall be convertible to the anonymous access type of the discriminant (see
  7921. 4.6).  {convertible [required]}
  7922.  
  7923.         16.a   Ramification:  This requires convertibility of the designated
  7924.         subtypes.
  7925.  
  7926.  
  7927.                               Static Semantics
  7928.  
  7929. 17   A discriminant_specification declares a discriminant; the subtype_mark
  7930. denotes its subtype unless it is an access discriminant, in which case the
  7931. discriminant's subtype is the anonymous access-to-variable subtype defined by
  7932. the access_definition.
  7933.  
  7934. 18   [For a type defined by a derived_type_definition, each discriminant of
  7935. the parent type is either inherited, constrained to equal some new
  7936. discriminant of the derived type, or constrained to the value of an
  7937. expression.]  {corresponding discriminants} When inherited or constrained to
  7938. equal some new discriminant, the parent discriminant and the discriminant of
  7939. the derived type are said to correspond.  Two discriminants also correspond
  7940. if there is some common discriminant to which they both correspond.  A
  7941. discriminant corresponds to itself as well.  {specified discriminant} If a
  7942. discriminant of a parent type is constrained to a specific value by a
  7943. derived_type_definition, then that discriminant is said to be specified by
  7944. that derived_type_definition.
  7945.  
  7946.         18.a   Ramification:  The correspondence relationship is transitive,
  7947.         symmetric, and reflexive.  That is, if A corresponds to B, and B
  7948.         corresponds to C, then A, B, and C each corresponds to A, B, and C in
  7949.         all combinations.
  7950.  
  7951. 19   {depend on a discriminant (for a constraint or component_definition)} A
  7952. constraint that appears within the definition of a discriminated type depends
  7953. on a discriminant of the type if it names the discriminant as a bound or
  7954. discriminant value.  A component_definition depends on a discriminant if its
  7955. constraint depends on the discriminant, or on a discriminant that corresponds
  7956. to it.
  7957.  
  7958.         19.a   Ramification:  A constraint in a task_body is not considered
  7959.         to depend on a discriminant of the task type, even if it names it.
  7960.         It is only the constraints in the type definition itself that are
  7961.         considered dependents.  Similarly for protected types.
  7962.  
  7963. 20   {depend on a discriminant (for a component)} A component depends on a
  7964. discriminant if:
  7965.    21  Its component_definition depends on the discriminant; or
  7966.  
  7967.  21.a   Ramification:  A component does not depend on a discriminant
  7968.         just because its default_expression refers to the discriminant.
  7969.  
  7970.    22  It is declared in a variant_part that is governed by the
  7971.        discriminant; or
  7972.  
  7973.    23  It is a component inherited as part of a derived_type_definition,
  7974.        and the constraint of the parent_subtype_indication depends on
  7975.        the discriminant; or
  7976.  
  7977.  23.a   Reason:  When the parent subtype depends on a discriminant, the
  7978.         parent part of the derived type is treated like a
  7979.         discriminant-dependent component.
  7980.  
  7981.  23.b   Ramification:  Because of this rule, we don't really need to
  7982.         worry about ``corresponding'' discriminants, since all the
  7983.         inherited components will be discriminant-dependent if there is
  7984.         a new known_discriminant_part whose discriminants are used to
  7985.         constrain the old discriminants.
  7986.  
  7987.    24  It is a subcomponent of a component that depends on the
  7988.        discriminant.
  7989.  
  7990.         24.a   Reason:  The concept of discriminant-dependent (sub)components
  7991.         is primarily used in various rules that disallow renaming or 'Access,
  7992.         or specify that certain discriminant-changing assignments are
  7993.         erroneous.  The goal is to allow implementations to move around or
  7994.         change the size of discriminant-dependent subcomponents upon a
  7995.         discriminant-changing assignment to an enclosing object.  The above
  7996.         definition specifies that all subcomponents of a discriminant-
  7997.         dependent component or parent part are themselves discriminant-
  7998.         dependent, even though their presence or size does not in fact depend
  7999.         on a discriminant.  This is because it is likely that they will move
  8000.         in a discriminant-changing assignment if they are a component of one
  8001.         of several discriminant-dependent parts of the same record.
  8002.  
  8003. 25   Each value of a discriminated type includes a value for each component
  8004. of the type that does not depend on a discriminant[; this includes the
  8005. discriminants themselves].  The values of discriminants determine which other
  8006. component values are present in the value of the discriminated type.
  8007.  
  8008.         25.a   To be honest:  Which values are present might depend on
  8009.         discriminants of some ancestor type that are constrained in an
  8010.         intervening derived_type_definition.  That's why we say "values of
  8011.         discriminants" instead of "values of the discriminants" -- a subtle
  8012.         point.
  8013.  
  8014. 26   {known discriminants} {discriminants (known)} {constrained (subtype)}
  8015. {unconstrained (subtype)} A type declared with a known_discriminant_part is
  8016. said to have known discriminants; its first subtype is unconstrained.
  8017. {unknown discriminants} {discriminants (unknown)} A type declared with an
  8018. unknown_discriminant_part is said to have unknown discriminants.  A type
  8019. declared without a discriminant_part has no discriminants, unless it is a
  8020. derived type; if derived, such a type has the same sort of discriminants
  8021. (known, unknown, or none) as its parent (or ancestor) type.  A tagged
  8022. class-wide type also has unknown discriminants.  {class-wide type}
  8023. {indefinite subtype} [Any subtype of a type with unknown discriminants is an
  8024. unconstrained and indefinite subtype (see 3.2 and 3.3).]  {94-4610.a}
  8025.  
  8026.         26.a   Discussion:  An unknown_discriminant_part ``(<>)'' is only
  8027.         permitted in the declaration of a (generic or nongeneric) private
  8028.         type, private extension, or formal derived type.  Hence, only such
  8029.         types, descendants thereof, and class-wide types can have unknown
  8030.         discriminants.  An unknown_discriminant_part is used to indicate that
  8031.         the corresponding actual or full type might have discriminants
  8032.         without defaults, or be an unconstrained array subtype.  Tagged
  8033.         class-wide types are also considered to have unknown discriminants
  8034.         because discriminants can be added by type extensions, so the total
  8035.         number of discriminants of any given value of a tagged class-wide
  8036.         type is not known at compile time.
  8037.  
  8038.         26.b   A subtype with unknown discriminants is indefinite, and hence
  8039.         an object of such a subtype needs explicit initialization.  If the
  8040.         subtype is limited, no (stand-alone) objects can be declared since
  8041.         initialization is not permitted (though formal parameters are
  8042.         permitted, and objects of the actual/full type will generally be
  8043.         declarable).  A limited private type with unknown discriminants is
  8044.         ``extremely'' limited; such a type is useful for keeping complete
  8045.         control over object creation within the package declaring the type.
  8046.  
  8047.         26.c   A partial view of a type might have unknown discriminants,
  8048.         while the full view of the same type might have known, unknown, or no
  8049.         discriminants,
  8050.  
  8051.  
  8052.                               Dynamic Semantics
  8053.  
  8054. 27   An access_definition is elaborated when the value of a corresponding
  8055. access discriminant is defined, either by evaluation of its default_
  8056. expression or by elaboration of a discriminant_constraint.  [The elaboration
  8057. of an access_definition creates the anonymous access type.  When the
  8058. expression defining the access discriminant is evaluated, it is converted to
  8059. this anonymous access type (see 4.6).]  {implicit subtype conversion [access
  8060. discriminant]}
  8061.  
  8062.         27.a   Ramification:  This conversion raises Constraint_Error if the
  8063.         initial value is null, or, for an object created by an allocator of
  8064.         an access type T, if the initial value is an access parameter that
  8065.         designates a view whose accessibility level is deeper than that of
  8066.         T. {94-4715.a}
  8067.  
  8068.  
  8069.      NOTES
  8070. 28   (50) If a discriminated type has default_expressions for its
  8071.      discriminants, then unconstrained variables of the type are permitted,
  8072.      and the values of the discriminants can be changed by an assignment to
  8073.      such a variable.  If defaults are not provided for the discriminants,
  8074.      then all variables of the type are constrained, either by explicit
  8075.      constraint or by their initial value; the values of the discriminants of
  8076.      such a variable cannot be changed after initialization.
  8077.  
  8078.    28.a   Discussion:  This connection between discriminant defaults and
  8079.         unconstrained variables can be a source of confusion.  For Ada 9X, we
  8080.         considered various ways to break the connection between defaults and
  8081.         unconstrainedness, but ultimately gave up for lack of a sufficiently
  8082.         simple and intuitive alternative.
  8083.  
  8084.    28.b   {mutable} An unconstrained discriminated subtype with defaults is
  8085.         called a mutable subtype, and a variable of such a subtype is called
  8086.         a mutable variable, because the discriminants of such a variable can
  8087.         change.  There are no mutable arrays (that is, the bounds of an array
  8088.         object can never change), because there is no way in the language to
  8089.         define default values for the bounds.  Similarly, there are no
  8090.         mutable class-wide subtypes, because there is no way to define the
  8091.         default tag, and defaults for discriminants are not allowed in the
  8092.         tagged case.  Mutable tags would also require a way for the maximum
  8093.         possible size of such a class-wide subtype to be known.  (In some
  8094.         implementations, all mutable variables are allocated with the maximum
  8095.         possible size.  This approach is appropriate for real-time
  8096.         applications where implicit use of the heap is inappropriate.)
  8097.         {94-4799.a} {94-4801.a} {94-4806.a} {94-4874.a} {94-4882.a}
  8098.  
  8099. 29   (51) The default_expression for a discriminant of a type is evaluated
  8100.      when an object of an unconstrained subtype of the type is created.
  8101.  
  8102. 30   (52) Assignment to a discriminant of an object (after its
  8103.      initialization) is not allowed, since the name of a discriminant is a
  8104.      constant; neither assignment_statements nor assignments inherent in
  8105.      passing as an in out or out parameter are allowed.  Note however that
  8106.      the value of a discriminant can be changed by assigning to the enclosing
  8107.      object, presuming it is an unconstrained variable.
  8108.  
  8109.    30.a   Discussion:  An unknown_discriminant_part is permitted only in the
  8110.         declaration of a private type (including generic formal private),
  8111.         private extension, or generic formal derived type.  These are the
  8112.         things that will have a corresponding completion or generic actual,
  8113.         which will either define the discriminants, or say there are none.
  8114.         The (<>) indicates that the actual/full subtype might be an
  8115.         indefinite subtype.  An unknown_discriminant_part is not permitted in
  8116.         a normal untagged derived type declaration, because there is no
  8117.         separate full type declaration for such a type.  Note that (<>)
  8118.         allows unconstrained array bounds; those are somewhat like
  8119.         undefaulted discriminants.
  8120.  
  8121.    30.b   For a derived type, either the discriminants are inherited as is,
  8122.         or completely respecified in a new discriminant_part.  In this latter
  8123.         case, each discriminant of the parent type shall be constrained,
  8124.         either to a specific value, or to equal one of the new discriminants.
  8125.         Constraining a parent type's discriminant to equal one of the new
  8126.         discriminants is like a renaming of the discriminant, except that the
  8127.         subtype of the new discriminant can be more restrictive than that of
  8128.         the parent's one.  In any case, the new discriminant can share
  8129.         storage with the parent's discriminant.
  8130.  
  8131. 31   (53) A discriminant that is of a named access type is not called an
  8132.      access discriminant; that term is used only for discriminants defined by
  8133.      an access_definition.
  8134.  
  8135.  
  8136.                                   Examples
  8137.  
  8138. 32   Examples of discriminated types:
  8139.  
  8140. 33  type Buffer(Size : Buffer_Size := 100)  is        -- see 3.5.4
  8141.        record
  8142.           Pos   : Buffer_Size := 0;
  8143.           Value : String(1 .. Size);
  8144.        end record;
  8145.  
  8146. 34  type Matrix_Rec(Rows, Columns : Integer) is
  8147.        record
  8148.           Mat : Matrix(1 .. Rows, 1 .. Columns);       -- see 3.6
  8149.        end record;
  8150.  
  8151. 35  type Square(Side : Integer) is new Matrix_Rec(Rows => Side, Columns => Side\
  8152. );
  8153.  
  8154. 36  type Double_Square(Number : Integer) is
  8155.        record
  8156.           Left  : Square(Number);
  8157.           Right : Square(Number);
  8158.        end record;
  8159.  
  8160. 37  type Item(Number : Positive) is
  8161.        record
  8162.           Content : Integer;
  8163.           --  no component depends on the discriminant
  8164.        end record;
  8165.                             Extensions to Ada 83
  8166.  
  8167.         37.a   {extensions to Ada 83} The syntax for a discriminant_
  8168.         specification is modified to allow an access discriminant, with a
  8169.         type specified by an access_definition (see 3.10).
  8170.  
  8171.         37.b   Discriminants are allowed on all composite types other than
  8172.         array types.
  8173.  
  8174.         37.c   Discriminants may be of an access type.
  8175.  
  8176.                          Wording Changes From Ada 83
  8177.  
  8178.         37.d   Discriminant_parts are not elaborated, though an access_
  8179.         definition is elaborated when the discriminant is initialized.
  8180.  
  8181.  
  8182.  
  8183. 3.7.1 Discriminant Constraints
  8184.  
  8185. 1   A discriminant_constraint specifies the values of the discriminants for a
  8186. given discriminated type.
  8187.  
  8188.  
  8189.                          Language Design Principles
  8190.  
  8191.         1.a   The rules in this clause are intentionally parallel to those
  8192.         given in Record Aggregates.
  8193.  
  8194.                                    Syntax
  8195.  
  8196. 2   discriminant_constraint ::=
  8197.        (discriminant_association {, discriminant_association})
  8198.  
  8199. 3   discriminant_association ::=
  8200.        [discriminant_selector_name {| discriminant_selector_name} =>] expression
  8201.  
  8202.     4   {named discriminant association} A discriminant_association is said
  8203.     to be named if it has one or more discriminant_selector_names;
  8204.     {positional discriminant association} it is otherwise said to be
  8205.     positional.  In a discriminant_constraint, any positional associations
  8206.     shall precede any named associations.
  8207.  
  8208.  
  8209.                             Name Resolution Rules
  8210.  
  8211. 5   Each selector_name of a named discriminant_association shall resolve to
  8212. denote a discriminant of the subtype being constrained; {associated
  8213. discriminants (of a named discriminant_association)} the discriminants so
  8214. named are the associated discriminants of the named association.  {associated
  8215. discriminants (of a positional discriminant_association)} For a positional
  8216. association, the associated discriminant is the one whose discriminant_
  8217. specification occurred in the corresponding position in the known_
  8218. discriminant_part that defined the discriminants of the subtype being
  8219. constrained.
  8220.  
  8221. 6   {expected type [discriminant_association expression]} The expected type
  8222. for the expression in a discriminant_association is that of the associated
  8223. discriminant(s).
  8224.  
  8225.  
  8226.                                Legality Rules
  8227.  
  8228. 7   A discriminant_constraint is only allowed in a subtype_indication whose
  8229. subtype_mark denotes either an unconstrained discriminated subtype, or an
  8230. unconstrained access subtype whose designated subtype is an unconstrained
  8231. discriminated subtype.
  8232.  
  8233. 8   A named discriminant_association with more than one selector_name is
  8234. allowed only if the named discriminants are all of the same type.  A
  8235. discriminant_constraint shall provide exactly one value for each discriminant
  8236. of the subtype being constrained.
  8237.  
  8238. 9   The expression associated with an access discriminant shall be of a type
  8239. convertible to the anonymous access type.  {convertible [required]}
  8240.  
  8241.         9.a   Ramification:  This implies both convertibility of designated
  8242.         types, and static accessibility.  This implies that if an object of
  8243.         type T with an access discriminant is created by an allocator for an
  8244.         access type A, then it requires that the type of the expression
  8245.         associated with the access discriminant have an accessibility level
  8246.         that is not statically deeper than that of A. This is to avoid
  8247.         dangling references.  {94-4715.a}
  8248.  
  8249.  
  8250.                               Dynamic Semantics
  8251.  
  8252. 10   {compatibility [discriminant constraint with a subtype]} A discriminant_
  8253. constraint is compatible with an unconstrained discriminated subtype if each
  8254. discriminant value belongs to the subtype of the corresponding discriminant.
  8255.  
  8256.         10.a   Ramification:  The "dependent compatibility check" has been
  8257.         eliminated in Ada 9X.  Any checking on subcomponents is performed
  8258.         when (and if) an object is created.
  8259.  
  8260.         10.b   Discussion:  There is no need to define compatibility with a
  8261.         constrained discriminated subtype, because one is not allowed to
  8262.         constrain it again.
  8263.  
  8264. 11   {satisfies [a discriminant constraint]} A composite value satisfies a
  8265. discriminant constraint if and only if each discriminant of the composite
  8266. value has the value imposed by the discriminant constraint.
  8267.  
  8268. 12   {elaboration [discriminant_constraint]} For the elaboration of a
  8269. discriminant_constraint, the expressions in the discriminant_associations are
  8270. evaluated in an arbitrary order and converted to the type of the associated
  8271. discriminant (which might raise Constraint_Error -- see 4.6); the expression
  8272. of a named association is evaluated (and converted) once for each associated
  8273. discriminant.  {implicit subtype conversion [discriminant values]} The result
  8274. of each evaluation and conversion is the value imposed by the constraint for
  8275. the associated discriminant.
  8276.  
  8277.         12.a   Reason:  We convert to the type, not the subtype, so that the
  8278.         definition of compatibility of discriminant constraints is not
  8279.         vacuous.
  8280.  
  8281.  
  8282.      NOTES
  8283. 13   (54) The rules of the language ensure that a discriminant of an object
  8284.      always has a value, either from explicit or implicit initialization.
  8285.  
  8286.    13.a   Discussion:  Although it is illegal to constrain a class-wide
  8287.         tagged subtype, it is possible to have a partially constrained
  8288.         class-wide subtype: If the subtype S is defined by T(A => B), then
  8289.         S'Class is partially constrained in the sense that objects of subtype
  8290.         S'Class have to have discriminants corresponding to A equal to B, but
  8291.         there can be other discriminants defined in extensions that are not
  8292.         constrained to any particular value.
  8293.  
  8294.  
  8295.                                   Examples
  8296.  
  8297. 14   Examples (using types declared above in clause 3.7):
  8298.  
  8299. 15  Large   : Buffer(200);  --  constrained, always 200 characters
  8300.                             --   (explicit discriminant value)
  8301.     Message : Buffer;       --  unconstrained, initially 100 characters
  8302.                             --   (default discriminant value)
  8303.     Basis   : Square(5);    --  constrained, always 5 by 5
  8304.     Illegal : Square;       --  illegal, a Square has to be constrained
  8305.  
  8306.  
  8307.                          Inconsistencies With Ada 83
  8308.  
  8309.         15.a   {inconsistencies with Ada 83} Dependent compatibility checks
  8310.         are no longer performed on subtype declaration.  Instead they are
  8311.         deferred until object creation (see 3.3.1).  This is upward
  8312.         compatible for a program that does not raise Constraint_Error.
  8313.  
  8314.                          Wording Changes From Ada 83
  8315.  
  8316.         15.b   Everything in RM83-3.7.2(7-12), which specifies the initial
  8317.         values for discriminants, is now redundant with 3.3.1, 6.4.1, 8.5.1,
  8318.         and 12.4.  Therefore, we don't repeat it here.  Since the material is
  8319.         largely intuitive, but nevertheless complicated to state formally, it
  8320.         doesn't seem worth putting it in a "NOTE."
  8321.  
  8322.  
  8323.  
  8324. 3.7.2 Operations of Discriminated Types
  8325.  
  8326. 1   [If a discriminated type has default_expressions for its discriminants,
  8327. then unconstrained variables of the type are permitted, and the discriminants
  8328. of such a variable can be changed by assignment to the variable.  For a
  8329. formal parameter of such a type, an attribute is provided to determine
  8330. whether the corresponding actual parameter is constrained or unconstrained.]
  8331.  
  8332.  
  8333.                               Static Semantics
  8334.  
  8335. 2   For a prefix A that is of a discriminated type [(after any implicit
  8336. dereference)], the following attribute is defined:
  8337.  
  8338. 3   A'Constrained
  8339.                 Yields the value True if A denotes a constant, a value, or a
  8340.                 constrained variable, and False otherwise.
  8341.  
  8342. 3.a     Implementation Note:  This attribute is primarily used on parameters,
  8343.         to determine whether the discriminants can be changed as part of an
  8344.         assignment.  The Constrained attribute is statically True for in
  8345.         parameters.  For in out and out parameters of a discriminated type,
  8346.         the value of this attribute needs to be passed as an implicit
  8347.         parameter, in general.  However, if the type does not have defaults
  8348.         for its discriminants, the attribute is statically True, so no
  8349.         implicit parameter is needed.  Parameters of a limited type with
  8350.         defaulted discriminants need this implicit parameter, unless there
  8351.         are no nonlimited views, because they might be passed to a subprogram
  8352.         whose body has visibility on a nonlimited view of the type, and hence
  8353.         might be able to assign to the object and change its discriminants.
  8354.  
  8355.  
  8356.                              Erroneous Execution
  8357.  
  8358. 4   {erroneous execution} The execution of a construct is erroneous if the
  8359. construct has a constituent that is a name denoting a subcomponent that
  8360. depends on discriminants, and the value of any of these discriminants is
  8361. changed by this execution between evaluating the name and the last use
  8362. (within this execution) of the subcomponent denoted by the name.
  8363.         4.a   Ramification:  This rule applies to assignment_statements,
  8364.         calls (except when the discriminant-dependent subcomponent is an in
  8365.         parameter passed by copy), indexed_components, and slices.  Ada 83
  8366.         only covered the first two cases.  AI-00585 pointed out the situation
  8367.         with the last two cases.  The cases of object_renaming_declarations
  8368.         and generic formal in out objects are handled differently, by
  8369.         disallowing the situation at compile time.
  8370.  
  8371.  
  8372.                             Extensions to Ada 83
  8373.  
  8374.         4.b   {extensions to Ada 83} For consistency with other attributes,
  8375.         we are allowing the prefix of Constrained to be a value as well as an
  8376.         object of a discriminated type, and also an implicit dereference.
  8377.         These extensions are not important capabilities, but there seems no
  8378.         reason to make this attribute different from other similar
  8379.         attributes.  We are curious what most Ada 83 compilers do with
  8380.         F(1).X'Constrained.
  8381.  
  8382.         4.c   We now handle in a general way the cases of erroneousness
  8383.         identified by AI-585, where the prefix of an indexed_component or
  8384.         slice is discriminant-dependent, and the evaluation of the index or
  8385.         discrete range changes the value of a discriminant.
  8386.  
  8387.                          Wording Changes From Ada 83
  8388.  
  8389.         4.d   We have moved all discussion of erroneous use of names that
  8390.         denote discriminant-dependent subcomponents to this subclause.  In
  8391.         Ada 83, it used to appear separately under assignment_statements and
  8392.         subprogram calls.
  8393.  
  8394.  
  8395.  
  8396. 3.8 Record Types
  8397.  
  8398. 1   {record} {record type} A record object is a composite object consisting
  8399. of named components.  The value of a record object is a composite value
  8400. consisting of the values of the components.  {structure: see record type}
  8401.  
  8402.  
  8403.                                    Syntax
  8404.  
  8405. 2   record_type_definition ::= [[abstract] tagged] [limited] record_definition
  8406.  
  8407. 3   record_definition ::=
  8408.         record
  8409.            component_list
  8410.         end record
  8411.       | null record
  8412.  
  8413. 4   component_list ::=
  8414.           component_item {component_item}
  8415.        | {component_item} variant_part
  8416.        |  null;
  8417.  
  8418. 5   component_item ::= component_declaration | representation_clause
  8419.  
  8420. 6   component_declaration ::=
  8421.        defining_identifier_list : component_definition [:= default_expression];
  8422.  
  8423.  
  8424.                             Name Resolution Rules
  8425.  
  8426. 7   {expected type [component_declaration default_expression]} The expected
  8427. type for the default_expression, if any, in a component_declaration is the
  8428. type of the component.
  8429.  
  8430.  
  8431.                                Legality Rules
  8432.  
  8433. 8   A default_expression is not permitted if the component is of a limited
  8434. type.
  8435.  
  8436. 9   {components [of a record type]} Each component_declaration declares a
  8437. component of the record type.  Besides components declared by component_
  8438. declarations, the components of a record type include any components declared
  8439. by discriminant_specifications of the record type declaration.  [The
  8440. identifiers of all components of a record type shall be distinct.]
  8441.  
  8442.         9.a   Proof:  The identifiers of all components of a record type have
  8443.         to be distinct because they are all declared immediately within the
  8444.         same declarative region.  See Section 8.
  8445.  
  8446. 10   Within a type_declaration, a name that denotes a component, protected
  8447. subprogram, or entry of the type is allowed only in the following cases:
  8448. {94-4663.a} {94-4664.a}
  8449.  
  8450.    11  A name that denotes any component, protected subprogram, or entry
  8451.        is allowed within a representation item that occurs within the
  8452.        declaration of the composite type.
  8453.  
  8454.    12  A name that denotes a noninherited discriminant is allowed within
  8455.        the declaration of the type, but not within the discriminant_
  8456.        part.  If the discriminant is used to define the constraint of a
  8457.        component, the bounds of an entry family, or the constraint of
  8458.        the parent subtype in a derived_type_definition then its name
  8459.        shall appear alone as a direct_name (not as part of a larger
  8460.        expression or expanded name).
  8461.  
  8462.  12.a   Reason:  This restriction simplifies implementation, and allows
  8463.         the outer discriminant and the inner discriminant or bound to
  8464.         possibly share storage.
  8465.  
  8466.  12.b   Ramification:  Other rules prevent such a discriminant from
  8467.         being an inherited one.
  8468.  
  8469.        A discriminant shall not be used to define the constraint of a
  8470.        scalar component.
  8471.  
  8472.  12.c   Reason:  This restriction is inherited from Ada 83.  The
  8473.         restriction is not really necessary from a language design point
  8474.         of view, but we did not remove it, in order to avoid unnecessary
  8475.         changes to existing compilers.
  8476.  
  8477.  12.d   Discussion:  Note that a discriminant can be used to define the
  8478.         constraint for a component that is of an access-to-composite
  8479.         type.
  8480.  
  8481.  12.e   Reason:  The above rules, and a similar one in 6.1 for formal
  8482.         parameters, are intended to allow initializations of components
  8483.         or parameters to occur in an arbitrary order -- whatever order
  8484.         is most efficient, since one default_expression cannot depend on
  8485.         the value of another one.  It also prevent circularities.
  8486.  
  8487.  12.f   Ramification:  Inherited discriminants are not allowed to be
  8488.         denoted, except within representation items.  However, the
  8489.         discriminant_selector_name of the parent subtype_indication is
  8490.         allowed to denote a discriminant of the parent.
  8491.  
  8492. 13   If the name of the current instance of a type (see 8.6) is used to
  8493. define the constraint of a component, then it shall appear as a direct_name
  8494. that is the prefix of an attribute_reference whose result is of an access
  8495. type, and the attribute_reference shall appear alone.
  8496.  
  8497.         13.a   Reason:  This rule allows T'Access or T'Unchecked_Access, but
  8498.         disallows, for example, a range constraint (1..T'Size).  Allowing
  8499.         things like (1..T'Size) would mean that a per-object constraint could
  8500.         affect the size of the object, which would be bad.
  8501.  
  8502.  
  8503.                               Static Semantics
  8504.  
  8505. 14   {nominal subtype [of a record component]} The component_definition of a
  8506. component_declaration defines the (nominal) subtype of the component.  If the
  8507. reserved word aliased appears in the component_definition, then the component
  8508. is aliased (see 3.10).
  8509.  
  8510.         14.a   Ramification:  In this case, the nominal subtype cannot be an
  8511.         unconstrained discriminated subtype.  See 3.6.
  8512.  
  8513. 15   {null record} If the component_list of a record type is defined by the
  8514. reserved word null and there are no discriminants, then the record type has
  8515. no components and all records of the type are null records.  A record_
  8516. definition of null record is equivalent to record null; end record.
  8517.  
  8518.         15.a   Ramification:  This short-hand is available both for declaring
  8519.         a record type and a record extension -- see 3.9.1.
  8520.  
  8521.  
  8522.                               Dynamic Semantics
  8523.  
  8524. 16   {elaboration [record_type_definition]} The elaboration of a record_type_
  8525. definition creates the record type and its first subtype, and consists of the
  8526. elaboration of the record_definition.  {elaboration [record_definition]} The
  8527. elaboration of a record_definition consists of the elaboration of its
  8528. component_list, if any.
  8529.  
  8530. 17   {elaboration [component_list]} The elaboration of a component_list
  8531. consists of the elaboration of the component_items and variant_part, if any,
  8532. in the order in which they appear.  {elaboration [component_declaration]} The
  8533. elaboration of a component_declaration consists of the elaboration of the
  8534. component_definition.
  8535.  
  8536.         17.a   Discussion:  If the defining_identifier_list has more than one
  8537.         defining_identifier, we presume here that the transformation
  8538.         explained in 3.3.1 has already taken place.  Alternatively, we could
  8539.         say that the component_definition is elaborated once for each
  8540.         defining_identifier in the list.
  8541.  
  8542. 18   {per-object expression} {per-object constraint} {entry index subtype}
  8543. Within the definition of a composite type, if a component_definition or
  8544. discrete_subtype_definition (see 9.5.2) includes a name that denotes a
  8545. discriminant of the type, or that is an attribute_reference whose prefix
  8546. denotes the current instance of the type, the expression containing the name
  8547. is called a per-object expression, and the constraint being defined is called
  8548. a per-object constraint.
  8549.  
  8550.         18.a   Discussion:  The evaluation of other expressions that appear
  8551.         in component_definitions and discrete_subtype_definitions is per-
  8552.         formed when the type definition is elaborated.  The evaluation of
  8553.         expressions that appear as default_expressions is postponed until an
  8554.         object is created.  Expressions in representation items that appear
  8555.         within a composite type definition are evaluated according to the
  8556.         rules of the particular representation item.
  8557.  
  8558. {elaboration [component_definition]} For the elaboration of a component_
  8559. definition of a component_declaration, if the constraint of the subtype_
  8560. indication is not a per-object constraint, then the subtype_indication is
  8561. elaborated.  On the other hand, if the constraint is a per-object constraint,
  8562. then the elaboration consists of the evaluation of any included expression
  8563. that is not part of a per-object expression.
  8564.  
  8565.  
  8566.      NOTES
  8567. 19   (55) A component_declaration with several identifiers is equivalent to a
  8568.      sequence of single component_declarations, as explained in 3.3.1.
  8569.  
  8570. 20   (56) The default_expression of a record component is only evaluated upon
  8571.      the creation of a default-initialized object of the record type
  8572.      (presuming the object has the component, if it is in a variant_part --
  8573.      see 3.3.1).
  8574.  
  8575. 21   (57) The subtype defined by a component_definition (see 3.6) has to be a
  8576.      definite subtype.
  8577.  
  8578. 22   (58) If a record type does not have a variant_part, then the same
  8579.      components are present in all values of the type.
  8580.  
  8581. 23   (59) A record type is limited if it has the reserved word limited in its
  8582.      definition, or if any of its components are limited (see 7.5).
  8583.  
  8584. 24   (60) {predefined operations [of a record type]} The predefined
  8585.      operations of a record type include membership tests, qualification, and
  8586.      explicit conversion.  If the record type is nonlimited, they also
  8587.      include assignment and the predefined equality operators.
  8588.  
  8589. 25   (61) A component of a record can be named with a selected_component.  A
  8590.      value of a record can be specified with a record_aggregate, unless the
  8591.      record type is limited.
  8592.  
  8593.  
  8594.                                   Examples
  8595.  
  8596. 26   Examples of record type declarations:
  8597.  
  8598. 27  type Date is
  8599.        record
  8600.           Day   : Integer range 1 .. 31;
  8601.           Month : Month_Name;
  8602.           Year  : Integer range 0 .. 4000;
  8603.        end record;
  8604.  
  8605. 28  type Complex is
  8606.        record
  8607.           Re : Real := 0.0;
  8608.           Im : Real := 0.0;
  8609.        end record;
  8610.  
  8611. 29   Examples of record variables:
  8612.  
  8613. 30  Tomorrow, Yesterday : Date;
  8614.     A, B, C : Complex;
  8615.  
  8616. 31  -- both components of A, B, and C are implicitly initialized to zero
  8617.  
  8618.  
  8619.                             Extensions to Ada 83
  8620.  
  8621.         31.a   {extensions to Ada 83} The syntax rule for component_
  8622.         declaration is modified to use component_definition (instead of
  8623.         component_subtype_definition).  The effect of this change is to allow
  8624.         the reserved word aliased before the component_subtype_definition.
  8625.  
  8626.         31.b   A short-hand is provided for defining a null record type (and
  8627.         a null record extension), as these will be more common for abstract
  8628.         root types (and derived types without additional components).
  8629.  
  8630.         31.c   The syntax rule for record_type_definition is modified to
  8631.         allow the reserved words tagged and limited.  Tagging is new.
  8632.         Limitedness is now orthogonal to privateness.  In Ada 83 the syntax
  8633.         implied that limited private was sort of more private than private.
  8634.         However, limitedness really has nothing to do with privateness;
  8635.         limitedness simply indicates the lack of assignment capabilities, and
  8636.         makes perfect sense for nonprivate types such as record types.
  8637.  
  8638.                          Wording Changes From Ada 83
  8639.  
  8640.         31.d   The syntax rules now allow representation_clauses to appear in
  8641.         a record_definition.  This is not a language extension, because
  8642.         Legality Rules prevent all language-defined representation clauses
  8643.         from appearing there.  However, an implementation-defined attribute_
  8644.         definition_clause could appear there.  The reason for this change is
  8645.         to allow the rules for representation_clauses and representation
  8646.         pragmas to be as similar as possible.
  8647.  
  8648.  
  8649.  
  8650. 3.8.1 Variant Parts and Discrete Choices
  8651.  
  8652. 1   A record type with a variant_part specifies alternative lists of
  8653. components.  Each variant defines the components for the value or values of
  8654. the discriminant covered by its discrete_choice_list.
  8655.  
  8656.         1.a   Discussion:  {cover a value [distributed]} Discrete_choice_
  8657.         lists and discrete_choices are said to cover values as defined below;
  8658.         which discrete_choice_list covers a value determines which of various
  8659.         alternatives is chosen.  These are used in variant_parts, array_
  8660.         aggregates, and case_statements.
  8661.  
  8662.  
  8663.                          Language Design Principles
  8664.  
  8665.         1.b   The definition of ``cover'' in this subclause and the rules
  8666.         about discrete choices are designed so that they are also appropriate
  8667.         for array aggregates and case statements.
  8668.  
  8669.         1.c   The rules of this subclause intentionally parallel those for
  8670.         case statements.
  8671.  
  8672.                                    Syntax
  8673.  
  8674. 2   variant_part ::=
  8675.        case discriminant_direct_name is
  8676.            variant
  8677.           {variant}
  8678.        end case;
  8679.  
  8680. 3   variant ::=
  8681.        when discrete_choice_list =>
  8682.           component_list
  8683.  
  8684. 4   discrete_choice_list ::= discrete_choice {| discrete_choice}
  8685.  
  8686. 5   discrete_choice ::= expression | discrete_range | others
  8687.  
  8688.  
  8689.                             Name Resolution Rules
  8690.  
  8691. 6   {discriminant (of a variant_part)} The discriminant_direct_name shall
  8692. resolve to denote a discriminant (called the discriminant of the variant_
  8693. part) specified in the known_discriminant_part of the full_type_declaration
  8694. that contains the variant_part.  {expected type [variant_part discrete_
  8695. choice]} The expected type for each discrete_choice in a variant is the type
  8696. of the discriminant of the variant_part.
  8697.  
  8698.         6.a   Ramification:  A full_type_declaration with a variant_part has
  8699.         to have a (new) known_discriminant_part; the discriminant of the
  8700.         variant_part cannot be an inherited discriminant.
  8701.  
  8702.  
  8703.                                Legality Rules
  8704.  
  8705. 7   The discriminant of the variant_part shall be of a discrete type.
  8706.  
  8707.         7.a   Ramification:  It shall not be of an access type, named or
  8708.         anonymous.
  8709.  
  8710. 8   The expressions and discrete_ranges given as discrete_choices in a
  8711. variant_part shall be static.  The discrete_choice others shall appear alone
  8712. in a discrete_choice_list, and such a discrete_choice_list, if it appears,
  8713. shall be the last one in the enclosing construct.
  8714.  
  8715. 9   {cover a value [by a discrete_choice]} A discrete_choice is defined to
  8716. cover a value in the following cases:
  8717.  
  8718.    10  A discrete_choice that is an expression covers a value if the
  8719.        value equals the value of the expression converted to the
  8720.        expected type.
  8721.  
  8722.    11  A discrete_choice that is a discrete_range covers all values
  8723.        (possibly none) that belong to the range.
  8724.  
  8725.    12  The discrete_choice others covers all values of its expected type
  8726.        that are not covered by previous discrete_choice_lists of the
  8727.        same construct.
  8728.  
  8729.  12.a   Ramification:  For case_statements, this includes values outside
  8730.         the range of the static subtype (if any) to be covered by the
  8731.         choices.  It even includes values outside the base range of the
  8732.         case expression's type, since values of numeric types (and
  8733.         undefined values of any scalar type?)  can be outside their base
  8734.         range.
  8735.  
  8736. 13   {cover a value [by a discrete_choice_list]} A discrete_choice_list
  8737. covers a value if one of its discrete_choices covers the value.
  8738.  
  8739. 14   The possible values of the discriminant of a variant_part shall be
  8740. covered as follows:
  8741.  
  8742.    15  If the discriminant is of a static constrained scalar subtype,
  8743.        then each non-others discrete_choice shall cover only values in
  8744.        that subtype, and each value of that subtype shall be covered by
  8745.        some discrete_choice [(either explicitly or by others)];
  8746.  
  8747.    16  If the type of the discriminant is a descendant of a generic
  8748.        formal scalar type then the variant_part shall have an others
  8749.        discrete_choice;
  8750.  
  8751.  16.a   Reason:  The base range is not known statically in this case.
  8752.  
  8753.    17  Otherwise, each value of the base range of the type of the
  8754.        discriminant shall be covered [(either explicitly or by others)].
  8755.  
  8756. 18   Two distinct discrete_choices of a variant_part shall not cover the same
  8757. value.
  8758.  
  8759.  
  8760.                               Static Semantics
  8761. 19   If the component_list of a variant is specified by null, the variant has
  8762. no components.
  8763.  
  8764. 20   {govern a variant_part} {govern a variant} The discriminant of a
  8765. variant_part is said to govern the variant_part and its variants.  In
  8766. addition, the discriminant of a derived type governs a variant_part and its
  8767. variants if it corresponds (see 3.7) to the discriminant of the variant_part.
  8768.  
  8769.  
  8770.                               Dynamic Semantics
  8771.  
  8772. 21   A record value contains the values of the components of a particular
  8773. variant only if the value of the discriminant governing the variant is
  8774. covered by the discrete_choice_list of the variant.  This rule applies in
  8775. turn to any further variant that is, itself, included in the component_list
  8776. of the given variant.
  8777.  
  8778. 22   {elaboration [variant_part]} The elaboration of a variant_part consists
  8779. of the elaboration of the component_list of each variant in the order in
  8780. which they appear.
  8781.  
  8782.  
  8783.                                   Examples
  8784.  
  8785. 23   Example of record type with a variant part:
  8786.  
  8787. 24  type Device is (Printer, Disk, Drum);
  8788.     type State  is (Open, Closed);
  8789.  
  8790. 25  type Peripheral(Unit : Device := Disk) is
  8791.        record
  8792.           Status : State;
  8793.           case Unit is
  8794.              when Printer =>
  8795.                 Line_Count : Integer range 1 .. Page_Size;
  8796.              when others =>
  8797.                 Cylinder   : Cylinder_Index;
  8798.                 Track      : Track_Number;
  8799.              end case;
  8800.           end record;
  8801.  
  8802. 26   Examples of record subtypes:
  8803.  
  8804. 27  subtype Drum_Unit is Peripheral(Drum);
  8805.     subtype Disk_Unit is Peripheral(Disk);
  8806.  
  8807. 28   Examples of constrained record variables:
  8808.  
  8809. 29  Writer   : Peripheral(Unit  => Printer);
  8810.     Archive  : Disk_Unit;
  8811.  
  8812.  
  8813.                             Extensions to Ada 83
  8814.  
  8815.         29.a   {extensions to Ada 83} In Ada 83, the discriminant of a
  8816.         variant_part is not allowed to be of a generic formal type.  This
  8817.         restriction is removed in Ada 9X; an others discrete_choice is
  8818.         required in this case.
  8819.  
  8820.                          Wording Changes From Ada 83
  8821.  
  8822.         29.b   The syntactic category choice is removed.  The syntax rules
  8823.         for variant, array_aggregate, and case_statement now use discrete_
  8824.         choice_list or discrete_choice instead.  The syntax rule for record_
  8825.         aggregate now defines its own syntax for named associations.
  8826.  
  8827.         29.c   We have added the term Discrete Choice to the title since this
  8828.         is where they are talked about.  This is analogous to the name of the
  8829.         subclause "Index Constraints and Discrete Ranges" in the clause on
  8830.         Array Types.
  8831.  
  8832.         29.d   The rule requiring that the discriminant denote a discriminant
  8833.         of the type being defined seems to have been left implicit in RM83.
  8834.  
  8835.  
  8836.  
  8837. 3.9 Tagged Types and Type Extensions
  8838.  
  8839. 1   [{dispatching operation [partial]} {polymorphism} {dynamic binding: see
  8840. dispatching operation} {generic unit: see also dispatching operation}
  8841. {variant: see also tagged type} Tagged types and type extensions support
  8842. object-oriented programming, based on inheritance with extension and run-time
  8843. polymorphism via dispatching operations.  {object-oriented programming (OOP):
  8844. see tagged types and type extensions} {OOP (object-oriented programming): see
  8845. tagged types and type extensions} {inheritance: see also tagged types and
  8846. type extension}]
  8847.  
  8848.  
  8849.                          Language Design Principles
  8850.  
  8851.         1.a   The intended implementation model is for a tag to be
  8852.         represented as a pointer to a statically allocated and link-time
  8853.         initialized type descriptor.  The type descriptor contains the
  8854.         address of the code for each primitive operation of the type.  It
  8855.         probably also contains other information, such as might make
  8856.         membership tests convenient and efficient.
  8857.  
  8858.         1.b   The primitive operations of a tagged type are known at its
  8859.         first freezing point; the type descriptor is laid out at that point.
  8860.         It contains linker symbols for each primitive operation; the linker
  8861.         fills in the actual addresses.
  8862.  
  8863.         1.c   Other implementation models are possible.
  8864.  
  8865.         1.d   The rules ensure that ``dangling dispatching'' is impossible;
  8866.         that is, when a dispatching call is made, there is always a body to
  8867.         execute.  This is different from some other object-oriented
  8868.         languages, such as Smalltalk, where it is possible to get a run-time
  8869.         error from a missing method.
  8870.  
  8871.         1.e   Dispatching calls should be efficient, and should have a
  8872.         bounded worst-case execution time.  This is important in a language
  8873.         intended for real-time applications.  In the intended implementation
  8874.         model, a dispatching call involves calling indirect through the
  8875.         appropriate slot in the dispatch table.  No complicated "method
  8876.         lookup" is involved.
  8877.  
  8878.         1.f   The programmer should have the choice at each call site of a
  8879.         dispatching operation whether to do a dispatching call or a
  8880.         statically determined call (i.e. whether the body executed should be
  8881.         determined at run time or at compile time).
  8882.  
  8883.         1.g   The same body should be executed for a call where the tag is
  8884.         statically determined to be T'Tag as for a dispatching call where the
  8885.         tag is found at run time to be T'Tag.  This allows one to test a
  8886.         given tagged type with statically determined calls, with some
  8887.         confidence that run-time dispatching will produce the same behavior.
  8888.  
  8889.         1.h   All views of a type should share the same type descriptor and
  8890.         the same tag.
  8891.  
  8892.         1.i   The visibility rules determine what is legal at compile time;
  8893.         they have nothing to do with what bodies can be executed at run time.
  8894.         Thus, it is possible to dispatch to a subprogram whose declaration is
  8895.         not visible at the call site.  In fact, this is one of the primary
  8896.         facts that gives object-oriented programming its power.  The
  8897.         subprogram that ends up being dispatched to by a given call might
  8898.         even be designed long after the call site has been coded and
  8899.         compiled.
  8900.  
  8901.         1.j   Given that Ada has overloading, determining whether a given
  8902.         subprogram overrides another is based both on the names and the type
  8903.         profiles of the operations.
  8904.  
  8905.         1.k   When a type extension is declared, if there is any place within
  8906.         its immediate scope where a certain subprogram of the parent is
  8907.         visible, then a matching subprogram should override.  If there is no
  8908.         such place, then a matching subprogram should be totally unrelated,
  8909.         and occupy a different slot in the type descriptor.  This is
  8910.         important to preserve the privacy of private parts; when an operation
  8911.         declared in a private part is inherited, the inherited version can be
  8912.         overridden only in that private part, in the package body, and in any
  8913.         children of the package.
  8914.  
  8915.         1.l   If an implementation shares code for instances of generic
  8916.         bodies, it should be allowed to share type descriptors of tagged
  8917.         types declared in the generic body, so long as they are not
  8918.         extensions of types declared in the specification of the generic
  8919.         unit.
  8920.  
  8921.                               Static Semantics
  8922.  
  8923. 2   {tagged type} A record type or private type that has the reserved word
  8924. tagged in its declaration is called a tagged type.  [When deriving from a
  8925. tagged type, additional components may be defined.  As for any derived type,
  8926. additional primitive subprograms may be defined, and inherited primitive
  8927. subprograms may be overridden.]  {type extension} {extension (of a type)} The
  8928. derived type is called an extension of the ancestor type, or simply a type
  8929. extension.  {extension (of a record type)} {private extension} {extension (of
  8930. a private type)} Every type extension is also a tagged type, and is either a
  8931. record extension or a private extension of some other tagged type.  A record
  8932. extension is defined by a derived_type_definition with a record_extension_
  8933. part.  A private extension, which is a partial view of a record extension,
  8934. can be declared in the visible part of a package (see 7.3) or in a generic
  8935. formal part (see 12.5.1).
  8936.  
  8937.         2.a   Glossary entry:  {Tagged type} The objects of a tagged type
  8938.         have a run-time type tag, which indicates the specific type with
  8939.         which the object was originally created.  An operand of a class-wide
  8940.         tagged type can be used in a dispatching call; the tag indicates
  8941.         which subprogram body to invoke.  Nondispatching calls, in which the
  8942.         subprogram body to invoke is determined at compile time, are also
  8943.         allowed.  Tagged types may be extended with additional components.
  8944.  
  8945.         2.b   Ramification:  If a tagged type is declared other than in a
  8946.         package_specification, it is impossible to add new primitive
  8947.         subprograms for that type, although it can inherit primitive
  8948.         subprograms, and those can be overridden.  If the user incorrectly
  8949.         thinks a certain subprogram is primitive when it is not, and tries to
  8950.         call it with a dispatching call, an error message will be given at
  8951.         the call site.
  8952.  
  8953.         2.c   Note that the accessibility rules imply that a tagged type
  8954.         declared in a library package_specification cannot be extended in a
  8955.         nested subprogram or task body.
  8956.  
  8957. 3   {tag of an object} An object of a tagged type has an associated
  8958. (run-time) tag that identifies the specific tagged type used to create the
  8959. object originally.  [The tag of an operand of a class-wide tagged type
  8960. T'Class controls which subprogram body is to be executed when a primitive
  8961. subprogram of type T is applied to the operand (see 3.9.2); {dispatching}
  8962. using a tag to control which body to execute is called dispatching.]  {type
  8963. tag: see tag} {run-time type: see tag} {type: see also tag} {class: see also
  8964. tag}
  8965.  
  8966. 4   The tag of a specific tagged type identifies the full_type_declaration of
  8967. the type.  If a declaration for a tagged type occurs within a generic_
  8968. package_declaration, then the corresponding type declarations in distinct
  8969. instances of the generic package are associated with distinct tags.  For a
  8970. tagged type that is local to a generic package body, the language does not
  8971. specify whether repeated instantiations of the generic body result in
  8972. distinct tags.
  8973.  
  8974.         4.a   Reason:  This eases generic code sharing.
  8975.  
  8976.         4.b   Implementation Note:  The language does not specify whether
  8977.         repeated elaborations of the same full_type_declaration correspond to
  8978.         distinct tags.  In most cases, we expect that all elaborations will
  8979.         correspond to the same tag, since the tag will frequently be the
  8980.         address (or index) of a statically allocated type descriptor.
  8981.         However, with shared generics, the type descriptor might have to be
  8982.         allocated on a per-instance basis, which in some implementation
  8983.         models implies per-elaboration of the instantiation.
  8984.  
  8985. 5   The following language-defined library package exists:
  8986.  
  8987. 6   package Ada.Tags is
  8988.         type Tag is private;
  8989.  
  8990. 7       function Expanded_Name(T : Tag) return String;
  8991.         function External_Tag(T : Tag) return String;
  8992.         function Internal_Tag(External : String) return Tag;
  8993.  
  8994. 8       Tag_Error : exception;
  8995.  
  8996. 9   private
  8997.        ... -- not specified by the language
  8998.     end Ada.Tags;
  8999.  
  9000.         9.a   Reason:  Tag is a nonlimited, definite subtype, because it
  9001.         needs the equality operators, so that tag checking makes sense.
  9002.         Also, equality, assignment, and object declaration are all useful
  9003.         capabilities for this subtype.
  9004.  
  9005.         9.b   For an object X and a type T, ``X'Tag = T'Tag'' is not needed,
  9006.         because a membership test can be used.  However, comparing the tags
  9007.         of two objects cannot be done via membership.  This is one reason to
  9008.         allow equality for type Tag.
  9009.  
  9010. 10   The function Expanded_Name returns the full expanded name of the first
  9011. subtype of the specific type identified by the tag, in upper case, starting
  9012. with a root library unit.  The result is implementation defined if the type
  9013. is declared within an unnamed block_statement.
  9014.  
  9015.         10.a   To be honest:  This name, as well as each prefix of it, does
  9016.         not denote a renaming_declaration.
  9017.  
  9018.         10.b   Implementation defined:  The result of Tags.Expanded_Name for
  9019.         types declared within an unnamed block_statement.
  9020.  
  9021. 11   The function External_Tag returns a string to be used in an external
  9022. representation for the given tag.  The call External_Tag(S'Tag) is equivalent
  9023. to the attribute_reference S'External_Tag (see 13.3).
  9024.  
  9025.         11.a   Reason:  It might seem redundant to provide both the function
  9026.         External_Tag and the attribute External_Tag.  The function is needed
  9027.         because the attribute can't be applied to values of type Tag.  The
  9028.         attribute is needed so that it can be specifiable via an attribute_
  9029.         definition_clause.
  9030.  
  9031. 12   The function Internal_Tag returns the tag that corresponds to the given
  9032. external tag, or raises Tag_Error if the given string is not the external tag
  9033. for any specific type of the partition.
  9034.  
  9035. 13   For every subtype S of a tagged type T (specific or class-wide), the
  9036. following attributes are defined:
  9037.  
  9038. 14  S'Class
  9039.                 S'Class denotes a subtype of the class-wide type (called
  9040.                 T'Class in this International Standard) for the class rooted
  9041.                 at T (or if S already denotes a class-wide subtype, then
  9042.                 S'Class is the same as S).
  9043.  
  9044.                 15   {unconstrained (subtype)} {constrained (subtype)}
  9045.                 S'Class is unconstrained.  However, if S is constrained, then
  9046.                 the values of S'Class are only those that when converted to
  9047.                 the type T belong to S.
  9048.  
  9049. 15.a    Ramification:  This attribute is defined for both specific and
  9050.         class-wide subtypes.  The definition is such that S'Class'Class is
  9051.         the same as S'Class.
  9052.  
  9053. 15.b    Note that if S is constrained, S'Class is only partially constrained,
  9054.         since there might be additional discriminants added in descendants of
  9055.         T which are not constrained.
  9056.  
  9057. 15.c    Reason:  The Class attribute is not defined for untagged subtypes
  9058.         (except for incomplete types and private types whose full view is
  9059.         tagged -- see 3.10.1 and 7.3.1) so as to preclude implicit conversion
  9060.         in the absence of run-time type information.  If it were defined for
  9061.         untagged subtypes, it would correspond to the concept of universal
  9062.         types provided for the predefined numeric classes.
  9063.  
  9064. 16  S'Tag
  9065.                 S'Tag denotes the tag of the type T (or if T is class-wide,
  9066.                 the tag of the root type of the corresponding class).  The
  9067.                 value of this attribute is of type Tag.
  9068.  
  9069. 16.a    Reason:  S'Class'Tag equals S'Tag, to avoid generic contract model
  9070.         problems when S'Class is the actual type associated with a generic
  9071.         formal derived type.
  9072.  
  9073. 17   Given a prefix X that is of a class-wide tagged type [(after any
  9074. implicit dereference)], the following attribute is defined:
  9075.  
  9076. 18  X'Tag
  9077.                 X'Tag denotes the tag of X. The value of this attribute is of
  9078.                 type Tag.
  9079.  
  9080. 18.a    Reason:  X'Tag is not defined if X is of a specific type.  This is
  9081.         primarily to avoid confusion that might result about whether the Tag
  9082.         attribute should reflect the tag of the type of X, or the tag of
  9083.         X. No such confusion is possible if X is of a class-wide type.
  9084.  
  9085.  
  9086.                               Dynamic Semantics
  9087.  
  9088. 19   The tag associated with an object of a tagged type is determined as
  9089. follows:
  9090.  
  9091.    20  {tag of an object [stand-alone object, component, or aggregate]}
  9092.        The tag of a stand-alone object, a component, or an aggregate of
  9093.        a specific tagged type T identifies T.
  9094.  
  9095.  20.a   Discussion:  The tag of a formal parameter of type T is not
  9096.         necessarily the tag of T, if, for example, the actual was a type
  9097.         conversion.
  9098.  
  9099.    21  {tag of an object [object created by an allocator]} The tag of an
  9100.        object created by an allocator for an access type with a specific
  9101.        designated tagged type T, identifies T.
  9102.  
  9103.  21.a   Discussion:  The tag of an object designated by a value of such
  9104.         an access type might not be T, if, for example, the access value
  9105.         is the result of a type conversion.
  9106.  
  9107.    22  {tag of an object [class-wide object]} The tag of an object of a
  9108.        class-wide tagged type is that of its initialization expression.
  9109.  
  9110.  22.a   Ramification:  The tag of an object (even a class-wide one)
  9111.         cannot be changed after it is initialized, since a
  9112.         ``class-wide'' assignment_statement raises Constraint_Error if
  9113.         the tags don't match, and a ``specific'' assignment_statement
  9114.         does not affect the tag.
  9115.  
  9116.    23  {tag of an object [returned by a function]} The tag of the result
  9117.        returned by a function whose result type is a specific tagged
  9118.        type T identifies T.
  9119.  
  9120.  23.a   Implementation Note:  This requires a run-time check for limited
  9121.         tagged types, since they are returned "by-reference."  For a
  9122.         nonlimited type, a new anonymous object with the appropriate tag
  9123.         is created as part of the function return, and then assigned the
  9124.         value of the return expression.  See 6.5, ``Return Statements''.
  9125.  
  9126.    24  {tag of an object [returned by a function]} The tag of the result
  9127.        returned by a function with a class-wide result type is that of
  9128.        the return expression.
  9129.  
  9130. 25   {tag of an object [preserved by type conversion and parameter passing]}
  9131. The tag is preserved by type conversion and by parameter passing.  The tag of
  9132. a value is the tag of the associated object (see 6.2).  {94-4774.a}
  9133. {94-4842.a}
  9134.  
  9135.  
  9136.                          Implementation Permissions
  9137.  
  9138. 26   The implementation of the functions in Ada.Tags may raise Tag_Error if
  9139. no specific type corresponding to the tag passed as a parameter exists in the
  9140. partition at the time the function is called.
  9141.  
  9142.         26.a   Reason:  In most implementations, repeated elaborations of the
  9143.         same type_declaration will all produce the same tag.  In such an
  9144.         implementation, Tag_Error will be raised in cases where the internal
  9145.         or external tag was passed from a different partition.  However, some
  9146.         implementations might create a new tag value at run time for each
  9147.         elaboration of a type_declaration.  In that case, Tag_Error could
  9148.         also be raised if the created type no longer exists because the
  9149.         subprogram containing it has returned, for example.  We don't require
  9150.         the latter behavior; hence the word ``may'' in this rule.
  9151.  
  9152.  
  9153.      NOTES
  9154. 27   (62) A type declared with the reserved word tagged should normally be
  9155.      declared in a package_specification, so that new primitive subprograms
  9156.      can be declared for it.
  9157.  
  9158. 28   (63) Once an object has been created, its tag never changes.
  9159.  
  9160. 29   (64) Class-wide types are defined to have unknown discriminants (see
  9161.      3.7).  This means that objects of a class-wide type have to be
  9162.      explicitly initialized (whether created by an object_declaration or an
  9163.      allocator), and that aggregates have to be explicitly qualified with a
  9164.      specific type when their expected type is class-wide.
  9165.  
  9166. 30   (65) If S denotes an untagged private type whose full type is tagged,
  9167.      then S'Class is also allowed before the full type definition, but only
  9168.      in the private part of the package in which the type is declared (see
  9169.      7.3.1).  Similarly, the Class attribute is defined for incomplete types
  9170.      whose full type is tagged, but only within the library unit in which the
  9171.      incomplete type is declared (see 3.10.1).
  9172.  
  9173.  
  9174.                                   Examples
  9175.  
  9176. 31   Examples of tagged record types:
  9177.  
  9178. 32  type Point is tagged
  9179.       record
  9180.         X, Y : Real := 0.0;
  9181.       end record;
  9182.  
  9183. 33  type Expression is tagged null record;
  9184.       -- Components will be added by each extension
  9185.  
  9186.  
  9187.                             Extensions to Ada 83
  9188.  
  9189.         33.a   {extensions to Ada 83} Tagged types are a new concept.
  9190.  
  9191.  
  9192.  
  9193. 3.9.1 Type Extensions
  9194.  
  9195. 1   [{type extension} {extension (of a type)} {record extension} {extension
  9196. (of a record type)} {private extension} {extension (of a private type)} Every
  9197. type extension is a tagged type, and is either a record extension or a
  9198. private extension of some other tagged type.]
  9199.  
  9200.  
  9201.                          Language Design Principles
  9202.  
  9203.         1.a   We want to make sure that we can extend a generic formal tagged
  9204.         type, without knowing its discriminants.
  9205.  
  9206.         1.b   We don't want to allow components in an extension aggregate to
  9207.         depend on discriminants inherited from the parent value, since such
  9208.         dependence requires staticness in aggregates, at least for variants.
  9209.  
  9210.                                    Syntax
  9211.  
  9212. 2   record_extension_part ::= with record_definition
  9213.  
  9214.  
  9215.                                Legality Rules
  9216.  
  9217. 3   The parent type of a record extension shall not be a class-wide type.  If
  9218. the parent type is nonlimited, then each of the components of the record_
  9219. extension_part shall be nonlimited.  {accessibility rule [record extension]}
  9220. The accessibility level (see 3.10.2) of a record extension shall not be
  9221. statically deeper than that of its parent type.  {94-4715.a} {generic
  9222. contract issue [partial]} In addition to the places where Legality Rules
  9223. normally apply (see 12.3), these rules apply also in the private part of an
  9224. instance of a generic unit.
  9225.  
  9226.         3.a   Reason:  If the parent is a limited formal type, then the
  9227.         actual might be nonlimited.
  9228.  
  9229.         3.b   A similar accessibility rule is not needed for private
  9230.         extensions, because in a package, the rule will apply to the full_
  9231.         type_declaration, and for a generic formal private extension, the
  9232.         actual is all that matters.
  9233.  
  9234. 4   A type extension shall not be declared in a generic body if the parent
  9235. type is declared outside that body.
  9236.  
  9237.         4.a   Reason:  This paragraph ensures that a dispatching call will
  9238.         never attempt to execute an inaccessible subprogram body.
  9239.  
  9240.         4.b   The part about generic bodies is necessary in order to preserve
  9241.         the contract model.
  9242.  
  9243.         4.c   Since a generic unit can be instantiated at a deeper
  9244.         accessibility level than the generic unit, it is necessary to prevent
  9245.         type extensions whose parent is declared outside the generic unit.
  9246.         The same is true if the parent is a formal of the generic unit.  If
  9247.         the parent is declared in the generic_declaration (but is not a
  9248.         formal), we don't run afoul of the accessibility rules, because we
  9249.         know that the instance declaration and body will be at the same
  9250.         accessibility level.  However, we still have a problem in that case,
  9251.         because it might have an unknown number of abstract subprograms, as
  9252.         in the following example:
  9253.  
  9254. 4.d         package P is
  9255.                 type T is tagged null record;
  9256.                 function F return T; -- Inherited versions will be abstract.
  9257.             end P;
  9258.  
  9259. 4.e         generic
  9260.                 type TT is tagged private;
  9261.             package Gp is
  9262.                 type NT is abstract new TT with null record;
  9263.                 procedure Q(X : in NT) is abstract;
  9264.             end Gp;
  9265.  
  9266. 4.f         package body Gp is
  9267.                 type NT2 is new NT with null record; -- Illegal!
  9268.                 procedure Q(X : in NT2) is begin null; end Q;
  9269.                 -- Is this legal or not?  Can't decide because
  9270.                 -- we don't know whether TT had any functions that go abstract
  9271.                 -- on extension.
  9272.             end Gp;
  9273.  
  9274. 4.g         package I is new Gp(TT => P.T);
  9275.  
  9276.         4.h   I.NT is an abstract type with two abstract subprograms:  F
  9277.         (inherited as abstract) and Q (explicitly declared as abstract).  But
  9278.         the generic body doesn't know about F, so we don't know that it needs
  9279.         to be overridden to make a nonabstract extension of NT.  Furthermore,
  9280.         a formal tagged limited private type can be extended with limited
  9281.         components, but the actual might not be limited, which would allow
  9282.         assignment of limited types, which is bad.  Hence, we have to
  9283.         disallow this case as well.
  9284.  
  9285.         4.i   If TT were declared as abstract, then we could have the same
  9286.         problem with abstract procedures.
  9287.  
  9288.         4.j   We considered disallowing all tagged types in a generic body,
  9289.         for simplicity.  We decided not to go that far, in order to avoid
  9290.         unnecessary restrictions.
  9291.  
  9292.         4.k   {accessibility rule [not part of generic contract]} We also
  9293.         considered trying make the accessibility level part of the contract;
  9294.         i.e. invent some way of saying (in the generic_declaration) ``all
  9295.         instances of this generic unit will have the same accessibility level
  9296.         as the generic_declaration.''  Unfortunately, that doesn't solve the
  9297.         part of the problem having to do with abstract types.
  9298.  
  9299.         4.l   Children of generic units obviate the need for extension in the
  9300.         body somewhat.
  9301.  
  9302.  
  9303.                               Dynamic Semantics
  9304.  
  9305. 5   {elaboration [record_extension_part]} The elaboration of a record_
  9306. extension_part consists of the elaboration of the record_definition.
  9307.  
  9308.  
  9309.      NOTES
  9310. 6    (66) The term ``type extension'' refers to a type as a whole.  The term
  9311.      ``extension part'' refers to the piece of text that defines the
  9312.      additional components (if any) the type extension has relative to its
  9313.      specified ancestor type.
  9314.  
  9315.    6.a   Discussion:  We considered other terminology, such as ``extended
  9316.         type.''  However, the terms ``private extended type'' and ``record
  9317.         extended type'' did not convey the proper meaning.  Hence, we have
  9318.         chosen to uniformly use the term ``extension'' as the type resulting
  9319.         from extending a type, with ``private extension'' being one produced
  9320.         by privately extending the type, and ``record extension'' being one
  9321.         produced by extending the type with an additional record-like set of
  9322.         components.  Note also that the term ``type extension'' refers to the
  9323.         result of extending a type in the language Oberon as well (though
  9324.         there the term ``extended type'' is also used, interchangeably,
  9325.         perhaps because Oberon doesn't have the concept of a ``private
  9326.         extension'').
  9327.  
  9328. 7    (67) The accessibility rules imply that a tagged type declared in a
  9329.      library package_specification can be extended only at library level or
  9330.      as a generic formal.  When the extension is declared immediately within
  9331.      a package_body, primitive subprograms are inherited and are overridable,
  9332.      but new primitive subprograms cannot be added.
  9333.  
  9334. 8    (68) A name that denotes a component (including a discriminant) of the
  9335.      parent type is not allowed within the record_extension_part.  Similarly,
  9336.      a name that denotes a component defined within the record_extension_part
  9337.      is not allowed within the record_extension_part.  It is permissible to
  9338.      use a name that denotes a discriminant of the record extension,
  9339.      providing there is a new known_discriminant_part in the enclosing type
  9340.      declaration.  (The full rule is given in 3.8.)
  9341.  
  9342.    8.a   Reason:  The restriction against depending on discriminants of the
  9343.         parent is to simplify the definition of extension aggregates.  The
  9344.         restriction against using parent components in other ways is
  9345.         methodological; it presumably simplifies implementation as well.
  9346.  
  9347. 9    (69) Each visible component of a record extension has to have a unique
  9348.      name, whether the component is (visibly) inherited from the parent type
  9349.      or declared in the record_extension_part (see 8.3).
  9350.  
  9351.  
  9352.                                   Examples
  9353.  
  9354. 10   Examples of record extensions (of types defined above in 3.9):
  9355. {94-4514.a}
  9356.  
  9357. 11  type Painted_Point is new Point with
  9358.       record
  9359.         Paint : Color := White;
  9360.       end record;
  9361.         -- Components X and Y are inherited
  9362.  
  9363. 12  Origin : constant Painted_Point := (X | Y => 0.0, Paint => Black);
  9364.  
  9365. 13  type Literal is new Expression with
  9366.       record                 -- a leaf in an Expression tree
  9367.         Value : Real;
  9368.       end record;
  9369.  
  9370. 14  type Expr_Ptr is access all Expression'Class;
  9371.                                    -- see 3.10
  9372.  
  9373. 15  type Binary_Operation is new Expression with
  9374.       record                 -- an internal node in an Expression tree
  9375.         Left, Right : Expr_Ptr;
  9376.       end record;
  9377.  
  9378. 16  type Addition is new Binary_Operation with null record;
  9379.     type Subtraction is new Binary_Operation with null record;
  9380.       -- No additional components needed for these extensions
  9381.  
  9382. 17  Tree : Expr_Ptr :=         -- A tree representation of ``5.0 + (13.0-7.0)''
  9383.        new Addition'(
  9384.           Left  => new Literal'(Value => 5.0),
  9385.           Right => new Subtraction'(
  9386.              Left  => new Literal'(Value => 13.0),
  9387.              Right => new Literal'(Value => 7.0)));
  9388.  
  9389.  
  9390.                             Extensions to Ada 83
  9391.  
  9392.         17.a   {extensions to Ada 83} Type extension is a new concept.
  9393.  
  9394.  
  9395.  
  9396. 3.9.2 Dispatching Operations of Tagged Types
  9397.  
  9398. 1   {dispatching operation [distributed]} {dispatching call (on a dispatching
  9399. operation)} {nondispatching call (on a dispatching operation)} {statically
  9400. determined tag} {dynamically determined tag} {polymorphism} {run-time
  9401. polymorphism} {controlling tag (for a call on a dispatching operation)} The
  9402. primitive subprograms of a tagged type are called dispatching operations.  [A
  9403. dispatching operation can be called using a statically determined controlling
  9404. tag, in which case the body to be executed is determined at compile time.
  9405. Alternatively, the controlling tag can be dynamically determined, in which
  9406. case the call dispatches to a body that is determined at run time;] such a
  9407. call is termed a dispatching call.  [As explained below, the properties of
  9408. the operands and the context of a particular call on a dispatching operation
  9409. determine how the controlling tag is determined, and hence whether or not the
  9410. call is a dispatching call.  Run-time polymorphism is achieved when a
  9411. dispatching operation is called by a dispatching call.]  {object-oriented
  9412. programming (OOP): see dispatching operations of tagged types} {OOP
  9413. (object-oriented programming): see dispatching operations of tagged types}
  9414. {message: see dispatching call} {method: see dispatching subprogram} {virtual
  9415. function: see dispatching subprogram}
  9416.  
  9417.  
  9418.                          Language Design Principles
  9419.  
  9420.         1.a   The controlling tag determination rules are analogous to the
  9421.         overload resolution rules, except they deal with run-time type
  9422.         identification (tags) rather than compile-time type resolution.  As
  9423.         with overload resolution, controlling tag determination may depend on
  9424.         operands or result context.
  9425.  
  9426.                               Static Semantics
  9427.  
  9428. 2   {call on a dispatching operation} {dispatching operation} A call on a
  9429. dispatching operation is a call whose name or prefix denotes the declaration
  9430. of a primitive subprogram of a tagged type, that is, a dispatching operation.
  9431.  
  9432.         2.a   Ramification:  This definition implies that a call through the
  9433.         dereference of an access-to-subprogram value is never considered a
  9434.         call on a dispatching operation.  Note also that if the prefix
  9435.         denotes a renaming_declaration, the place where the renaming occurs
  9436.         determines whether it is primitive; the thing being renamed is
  9437.         irrelevant.
  9438.  
  9439. {controlling operand} A controlling operand in a call on a dispatching
  9440. operation of a tagged type T is one whose corresponding formal parameter is
  9441. of type T or is of an anonymous access type with designated type T;
  9442. {controlling formal parameter} the corresponding formal parameter is called a
  9443. controlling formal parameter.  If the controlling formal parameter is an
  9444. access parameter, the controlling operand is the object designated by the
  9445. actual parameter, rather than the actual parameter itself.  {controlling
  9446. result} If the call is to a (primitive) function with result type T, then the
  9447. call has a controlling result -- the context of the call can control the
  9448. dispatching.
  9449.  
  9450. 3   A name or expression of a tagged type is either statically tagged,
  9451. dynamically tagged, or tag indeterminate, according to whether, when used as
  9452. a controlling operand, the tag that controls dispatching is determined
  9453. statically by the operand's (specific) type, dynamically by its tag at run
  9454. time, or from context.  A qualified_expression or parenthesized expression is
  9455. statically, dynamically, or indeterminately tagged according to its operand.
  9456. For other kinds of names and expressions, this is determined as follows:
  9457.  
  9458.     4  {statically tagged} The name or expression is statically tagged
  9459.        if it is of a specific tagged type and, if it is a call with a
  9460.        controlling result, it has at least one statically tagged
  9461.        controlling operand;
  9462.  
  9463.  4.a    Discussion:  It is illegal to have both statically tagged and
  9464.         dynamically tagged controlling operands in the same call -- see
  9465.         below.
  9466.  
  9467.     5  {dynamically tagged} The name or expression is dynamically tagged
  9468.        if it is of a class-wide type, or it is a call with a controlling
  9469.        result and at least one dynamically tagged controlling operand;
  9470.  
  9471.     6  {tag indeterminate} The name or expression is tag indeterminate
  9472.        if it is a call with a controlling result, all of whose
  9473.        controlling operands (if any) are tag indeterminate.
  9474.  
  9475. 7   [A type_conversion is statically or dynamically tagged according to
  9476. whether the type determined by the subtype_mark is specific or class-wide,
  9477. respectively.]  For a controlling operand that is designated by an actual
  9478. parameter, the controlling operand is statically or dynamically tagged
  9479. according to whether the designated type of the actual parameter is specific
  9480. or class-wide, respectively.
  9481.  
  9482.         7.a   Ramification:  A type_conversion is never tag indeterminate,
  9483.         even if its operand is.  A designated object is never tag
  9484.         indeterminate.
  9485.  
  9486.  
  9487.                                Legality Rules
  9488.  
  9489. 8   A call on a dispatching operation shall not have both dynamically tagged
  9490. and statically tagged controlling operands.
  9491.  
  9492.         8.a   Reason:  This restriction is intended to minimize confusion
  9493.         between whether the dynamically tagged operands are implicitly
  9494.         converted to, or tag checked against the specific type of the
  9495.         statically tagged operand(s).
  9496.  
  9497. 9   If the expected type for an expression or name is some specific tagged
  9498. type, then the expression or name shall not be dynamically tagged unless it
  9499. is a controlling operand in a call on a dispatching operation.  Similarly, if
  9500. the expected type for an expression is an anonymous access-to-specific tagged
  9501. type, then the expression shall not be of an access-to-class-wide type unless
  9502. it designates a controlling operand in a call on a dispatching operation.
  9503.  
  9504.         9.a   Reason:  This prevents implicit "truncation" of a
  9505.         dynamically-tagged value to the specific type of the target
  9506.         object/formal.  An explicit conversion is required to request this
  9507.         truncation.
  9508.  
  9509.         9.b   Ramification:  This rule applies to all expressions or names
  9510.         with a specific expected type, not just those that are actual
  9511.         parameters to a dispatching call.  This rule does not apply to a
  9512.         membership test whose expression is class-wide, since any type that
  9513.         covers the tested type is explicitly allowed.  See 4.5.2.
  9514.  
  9515. 10   In the declaration of a dispatching operation of a tagged type,
  9516. everywhere a subtype of the tagged type appears as a subtype of the profile
  9517. (see 6.1), it shall statically match the first subtype of the tagged type.
  9518. {statically matching [required]} If the dispatching operation overrides an
  9519. inherited subprogram, it shall be subtype conformant with the inherited
  9520. subprogram.  {subtype conformance (required)} A dispatching operation shall
  9521. not be of convention Intrinsic.  {94-4774.b} If a dispatching operation
  9522. overrides the predefined equals operator, then it shall be of convention Ada
  9523. [(either explicitly or by default -- see 6.3.1)].
  9524.  
  9525.         10.a   Reason:  These rules ensure that constraint checks can be
  9526.         performed by the caller in a dispatching call, and parameter passing
  9527.         conventions match up properly.  A special rule on aggregates prevents
  9528.         values of a tagged type from being created that are outside of its
  9529.         first subtype.
  9530.  
  9531. 11   The default_expression for a controlling formal parameter of a
  9532. dispatching operation shall be tag indeterminate.  A controlling formal
  9533. parameter that is an access parameter shall not have a default_expression.
  9534.  
  9535.         11.a   Reason:  The first part ensures that the default_expression
  9536.         always produces the "correct" tag when called with or without
  9537.         dispatching, or when inherited by a descendant.  If it were
  9538.         statically tagged, the default would be useless for a dispatching
  9539.         call; if it were dynamically tagged, the default would be useless for
  9540.         a nondispatching call.
  9541.  
  9542.         11.b   The second part is consistent with the first part, since
  9543.         designated objects are never tag-indeterminate.
  9544.  
  9545. 12   A given subprogram shall not be a dispatching operation of two or more
  9546. distinct tagged types.
  9547.  
  9548.         12.a   Reason:  This restriction minimizes confusion since multiple
  9549.         dispatching is not provided.  The normal solution is to replace all
  9550.         but one of the tagged types with their class-wide types.
  9551.  
  9552. 13   The explicit declaration of a primitive subprogram of a tagged type
  9553. shall occur before the type is frozen (see 13.14).  [For example, new
  9554. dispatching operations cannot be added after objects or values of the type
  9555. exist, nor after deriving a record extension from it, nor after a body.]
  9556.  
  9557.         13.a   Change:  Rule moved here from 13.14, ``Freezing Rules'', as
  9558.         per WG9 resolution.
  9559.         13.b   Reason:  This rule is needed because (1) we don't want people
  9560.         dispatching to things that haven't been declared yet, and (2) we want
  9561.         to allow tagged type descriptors to be static (allocated statically,
  9562.         and initialized to link-time-known symbols).  Suppose T2 inherits
  9563.         primitive P from T1, and then overrides P. Suppose P is called before
  9564.         the declaration of the overriding P. What should it dispatch to?  If
  9565.         the answer is the new P, we've violated the first principle above.
  9566.         If the answer is the old P, we've violated the second principle.  (A
  9567.         call to the new one necessarily raises Program_Error, but that's
  9568.         beside the point.)
  9569.  
  9570.         13.c   Note that a call upon a dispatching operation of type T will
  9571.         freeze T.
  9572.  
  9573.         13.d   We considered applying this rule to all derived types, for
  9574.         uniformity.  However, that would be upward incompatible, so we
  9575.         rejected the idea.  As in Ada 83, for an untagged type, the above
  9576.         call upon P will call the old P (which is arguably confusing).
  9577.  
  9578.         13.e   Implementation Note:  Because of this rule, the type
  9579.         descriptor can be created (presumably containing linker symbols
  9580.         pointing at the not-yet-compiled bodies) at the first freezing point
  9581.         of the type.  It also prevents, for a tagged type declared in a
  9582.         package_specification, overriding in the body or by a child
  9583.         subprogram.
  9584.  
  9585.         13.f   Ramification:  A consequence is that for a derived_type_
  9586.         declaration in a declarative_part, only the first primitive
  9587.         subprogram can be declared by a subprogram_body.
  9588.  
  9589.  
  9590.                               Dynamic Semantics
  9591.  
  9592. 14   {execution [call on a dispatching operation]} {controlling tag value}
  9593. For the execution of a call on a dispatching operation of a type T, the
  9594. controlling tag value determines which subprogram body is executed.  The
  9595. controlling tag value is defined as follows:
  9596.  
  9597.    15  {statically determined tag [partial]} If one or more controlling
  9598.        operands are statically tagged, then the controlling tag value is
  9599.        statically determined to be the tag of T.
  9600.  
  9601.    16  If one or more controlling operands are dynamically tagged, then
  9602.        the controlling tag value is not statically determined, but is
  9603.        rather determined by the tags of the controlling operands.  {Tag_
  9604.        Check [partial]} {check, language-defined (Tag_Check)} If there
  9605.        is more than one dynamically tagged controlling operand, a check
  9606.        is made that they all have the same tag.  {Constraint_Error
  9607.        (raised by failure of run-time check)} If this check fails,
  9608.        Constraint_Error is raised unless the call is a function_call
  9609.        whose name denotes the declaration of an equality operator
  9610.        (predefined or user defined) that returns Boolean, in which case
  9611.        the result of the call is defined to indicate inequality, and no
  9612.        subprogram_body is executed.  This check is performed prior to
  9613.        evaluating any tag-indeterminate controlling operands.
  9614.  
  9615.  16.a   Reason:  Tag mismatch is considered an error (except for "=" and
  9616.         "/=") since the corresponding primitive subprograms in each
  9617.         specific type expect all controlling operands to be of the same
  9618.         type.  For tag mismatch with an equality operator, rather than
  9619.         raising an exception, "=" returns False and "/=" returns True.
  9620.         No equality operator is actually invoked, since there is no
  9621.         common tag value to control the dispatch.  Equality is a special
  9622.         case to be consistent with the existing Ada 83 principle that
  9623.         equality comparisons, even between objects with different
  9624.         constraints, never raise Constraint_Error.
  9625.  
  9626.    17  If all of the controlling operands are tag-indeterminate, then:
  9627.  
  9628.           18  If the call has a controlling result and is itself a
  9629.               (possibly parenthesized or qualified) controlling operand
  9630.               of an enclosing call on a dispatching operation of type T,
  9631.               then its controlling tag value is determined by the
  9632.               controlling tag value of this enclosing call;
  9633.  
  9634.           19  {statically determined tag [partial]} Otherwise, the
  9635.               controlling tag value is statically determined to be the
  9636.               tag of type T.
  9637.  
  9638.  19.a   Ramification:  This includes the cases of a tag-indeterminate
  9639.         procedure call, and a tag-indeterminate function_call that is
  9640.         used to initialize a class-wide formal parameter or class-wide
  9641.         object.
  9642.  
  9643. 20   For the execution of a call on a dispatching operation, the body
  9644. executed is the one for the corresponding primitive subprogram of the
  9645. specific type identified by the controlling tag value.  The body for an
  9646. explicitly declared dispatching operation is the corresponding explicit body
  9647. for the subprogram.  The body for an implicitly declared dispatching
  9648. operation that is overridden is the body for the overriding subprogram, [even
  9649. if the overriding occurs in a private part.]  The body for an inherited
  9650. dispatching operation that is not overridden is the body of the corresponding
  9651. subprogram of the parent or ancestor type.
  9652.  
  9653.         20.a   To be honest:  In the unusual case in which a dispatching
  9654.         subprogram is explicitly declared (overridden) by a body (with no
  9655.         preceding subprogram_declaration), the body for that dispatching
  9656.         subprogram is that body; that is, the ``corresponding explicit body''
  9657.         in the above rule is the body itself.
  9658.  
  9659.         20.b   Reason:  The wording of the above rule is intended to ensure
  9660.         that the same body is executed for a given tag, whether that tag is
  9661.         determined statically or dynamically.  For a type declared in a
  9662.         package, it doesn't matter whether a given subprogram is overridden
  9663.         in the visible part or the private part, and it doesn't matter
  9664.         whether the call is inside or outside the package.  {94-5001.b} For
  9665.         example:
  9666.  
  9667. 20.c        package P1 is
  9668.                 type T1 is tagged null record;
  9669.                 procedure Op_A(Arg : in T1);
  9670.                 procedure Op_B(Arg : in T1);
  9671.             end P1;
  9672.  
  9673. 20.d        with P1; use P1;
  9674.             package P2 is
  9675.                 type T2 is new T1 with null record;
  9676.                 procedure Op_A(Param : in T2);
  9677.             private
  9678.                 procedure Op_B(Param : in T2);
  9679.             end P2;
  9680.  
  9681. 20.e        with P1; with P2;
  9682.             procedure Main is
  9683.                 X : T2;
  9684.                 Y : T1'Class := X;
  9685.             begin
  9686.                 P2.Op_A(Param => X); -- Nondispatching call.
  9687.                 P1.Op_A(Arg => Y); -- Dispatching call.
  9688.                 P2.Op_B(Arg => X); -- Nondispatching call.
  9689.                 P1.Op_B(Arg => Y); -- Dispatching call.
  9690.             end Main;
  9691.  
  9692.         20.f   The two calls to Op_A both execute the body of Op_A that has
  9693.         to occur in the body of package P2.  Similarly, the two calls to Op_B
  9694.         both execute the body of Op_B that has to occur in the body of
  9695.         package P2, even though Op_B is overridden in the private part of P2.
  9696.         Note, however, that the formal parameter names are different for
  9697.         P2.Op_A versus P2.Op_B.  The overriding declaration for P2.Op_B is
  9698.         not visible in Main, so the name in the call actually denotes the
  9699.         implicit declaration of Op_B inherited from T1.
  9700.  
  9701.         20.g   If a call occurs in the program text before an overriding,
  9702.         which can happen only if the call is part of a default expression,
  9703.         the overriding will still take effect for that call.  {94-4457.a}
  9704.         {94-4814.a}
  9705.  
  9706.         20.h   Implementation Note:  Even when a tag is not statically
  9707.         determined, a compiler might still be able to figure it out and
  9708.         thereby avoid the overhead of run-time dispatching.
  9709.  
  9710.  
  9711.      NOTES
  9712. 21   (70) The body to be executed for a call on a dispatching operation is
  9713.      determined by the tag; it does not matter whether that tag is determined
  9714.      statically or dynamically, and it does not matter whether the
  9715.      subprogram's declaration is visible at the place of the call.
  9716.      {94-4457.a} {94-4814.a}
  9717.  
  9718. 22   (71) This subclause covers calls on primitive subprograms of a tagged
  9719.      type.  Rules for tagged type membership tests are described in 4.5.2.
  9720.      Controlling tag determination for an assignment_statement is described
  9721.      in 5.2.
  9722.  
  9723. 23   (72) A dispatching call can dispatch to a body whose declaration is not
  9724.      visible at the place of the call.
  9725.  
  9726. 24   (73) A call through an access-to-subprogram value is never a dispatching
  9727.      call, even if the access value designates a dispatching operation.
  9728.      Similarly a call whose prefix denotes a subprogram_renaming_declaration
  9729.      cannot be a dispatching call unless the renaming itself is the
  9730.      declaration of a primitive subprogram.
  9731.  
  9732.  
  9733.                             Extensions to Ada 83
  9734.  
  9735.         24.a   {extensions to Ada 83} The concept of dispatching operations
  9736.         is new.
  9737.  
  9738.  
  9739.  
  9740. 3.9.3 Abstract Types and Subprograms
  9741.  
  9742. 1   [{abstract type} {abstract data type (ADT): see also abstract type} {ADT
  9743. (abstract data type): see also abstract type} {concrete type: see nonabstract
  9744. type} An abstract type is a tagged type intended for use as a parent type for
  9745. type extensions, but which is not allowed to have objects of its own.
  9746. {abstract subprogram} {concrete subprogram: see nonabstract subprogram} An
  9747. abstract subprogram is a subprogram that has no body, but is intended to be
  9748. overridden at some point when inherited.  Because objects of an abstract type
  9749. cannot be created, a dispatching call to an abstract subprogram always
  9750. dispatches to some overriding body.]
  9751.  
  9752.  
  9753.                          Language Design Principles
  9754.  
  9755.         1.a   An abstract subprogram has no body, so the rules in this clause
  9756.         are designed to ensure (at compile time) that the body will never be
  9757.         invoked.  We do so primarily by disallowing the creation of values of
  9758.         the abstract type.  Therefore, since type conversion and parameter
  9759.         passing don't change the tag, we know we will never get a class-wide
  9760.         value with a tag identifying an abstract type.  This means that we
  9761.         only have to disallow nondispatching calls on abstract subprograms
  9762.         (dispatching calls will never reach them).
  9763.  
  9764.                                Legality Rules
  9765.  
  9766. 2   {abstract type} {type (abstract)} An abstract type is a specific type
  9767. that has the reserved word abstract in its declaration.  Only a tagged type
  9768. is allowed to be declared abstract.
  9769.  
  9770.         2.a   Ramification:  Untagged types are never abstract, even though
  9771.         they can have primitive abstract subprograms.  Such subprograms
  9772.         cannot be called, unless they also happen to be dispatching
  9773.         operations of some tagged type, and then only via a dispatching call.
  9774.  
  9775.         2.b   Class-wide types are never abstract.  If T is abstract, then it
  9776.         is illegal to declare a stand-alone object of type T, but it is OK to
  9777.         declare a stand-alone object of type T'Class; the latter will get a
  9778.         tag from its initial value, and this tag will necessarily be
  9779.         different from T'Tag.
  9780.  
  9781. 3   {abstract subprogram} {subprogram (abstract)} A subprogram declared by an
  9782. abstract_subprogram_declaration (see 6.1) is an abstract subprogram.  If it
  9783. is a primitive subprogram of a tagged type, then the tagged type shall be
  9784. abstract.
  9785.  
  9786.         3.a   Ramification:  Note that for a private type, this applies to
  9787.         both views.  The following is illegal:
  9788.  
  9789. 3.b         package P is
  9790.                 type T is abstract tagged private;
  9791.                 function Foo (X : T) return Boolean is abstract; -- Illegal!
  9792.             private
  9793.                 type T is tagged null record; -- Illegal!
  9794.                 X : T;
  9795.                 Y : Boolean := Foo (T'Class (X));
  9796.             end P;
  9797.  
  9798.         3.c   The full view of T is not abstract, but has an abstract
  9799.         operation Foo, which is illegal.  The two lines marked "-- Illegal!"
  9800.         are illegal when taken together.  {94-4936.a} {94-4949.a}
  9801.  
  9802.         3.d   Reason:  We considered disallowing untagged types from having
  9803.         abstract primitive subprograms.  However, we rejected that plan,
  9804.         because it introduced some silly anomalies, and because such
  9805.         subprograms are harmless (if not terribly useful).  For example:
  9806.  
  9807. 3.e         package P is
  9808.                type Field_Size is range 0..100;
  9809.                type T is abstract tagged null record;
  9810.                procedure Print(X : in T; F : in Field_Size := 0) is abstract;
  9811.               . . .
  9812.             package Q is
  9813.                type My_Field_Size is new Field_Size;
  9814.                -- implicit declaration of Print(X : T; F : My_Field_Size := 0) \
  9815. is abstract;
  9816.             end Q;
  9817.  
  9818.         3.f   It seemed silly to make the derivative of My_Field_Size
  9819.         illegal, just because there was an implicitly declared abstract
  9820.         subprogram that was not primitive on some tagged type.  Other rules
  9821.         could be formulated to solve this problem, but the current ones seem
  9822.         like the simplest.
  9823.  
  9824. 4   For a derived type, if the parent or ancestor type has an abstract
  9825. primitive subprogram, or a primitive function with a controlling result,
  9826. then:
  9827.  
  9828.     5  If the derived type is abstract or untagged, the inherited
  9829.        subprogram is abstract.
  9830.  
  9831.  5.a    Ramification:  Note that it is possible to override a concrete
  9832.         subprogram with an abstract one.
  9833.  
  9834.     6  Otherwise, the subprogram shall be overridden with a nonabstract
  9835.        subprogram; [for a type declared in the visible part of a
  9836.        package, the overriding may be either in the visible or the
  9837.        private part.]  However, if the type is a generic formal type,
  9838.        the subprogram need not be overridden for the formal type itself;
  9839.        [a nonabstract version will necessarily be provided by the actual
  9840.        type.]  {94-4833.a} {94-4834.a}
  9841.  
  9842.  6.a    Reason:  A function that returns the parent type becomes
  9843.         abstract for an abstract type extension (if not overridden)
  9844.         because conversion from a parent type to a type extension is not
  9845.         defined, and function return semantics is defined in terms of
  9846.         conversion.  (Note that parameters of mode in out or out do not
  9847.         have this problem, because the tag of the actual is not
  9848.         changed.)
  9849.  
  9850.  6.b    Note that the overriding required above can be in the private
  9851.         part, which allows the following:
  9852.  
  9853. 6.c         package Pack1 is
  9854.                 type Ancestor is abstract ...;
  9855.                 procedure Do_Something(X : in Ancestor) is abstract;
  9856.             end Pack1;
  9857.  
  9858. 6.d         with Pack1; use Pack1;
  9859.             package Pack2 is
  9860.                 type T1 is new Ancestor with record ...;
  9861.                     -- A concrete type.
  9862.                 procedure Do_Something(X : in T1); -- Have to override.
  9863.             end Pack2;
  9864.  
  9865. 6.e         with Pack1; use Pack1;
  9866.             with Pack2; use Pack2;
  9867.             package Pack3 is
  9868.                 type T2 is new Ancestor with private;
  9869.                     -- A concrete type.
  9870.             private
  9871.                 type T2 is new T1 with -- Parent different from ancestor.
  9872.                   record ... end record;
  9873.                 -- Here, we inherit Pack2.Do_Something.
  9874.             end Pack3;
  9875.  
  9876.  6.f    T2 inherits an abstract Do_Something, but T is not abstract, so
  9877.         Do_Something has to be overridden.  However, it is OK to
  9878.         override it in the private part.  In this case, we override it
  9879.         by inheriting a concrete version from a different type.
  9880.         Nondispatching calls to Pack3.Do_Something are allowed both
  9881.         inside and outside package Pack3.
  9882.  
  9883. 7   A call on an abstract subprogram shall be a dispatching call;
  9884. [nondispatching calls to an abstract subprogram are not allowed.]
  9885.  
  9886.         7.a   Ramification:  If an abstract subprogram is not a dispatching
  9887.         operation of some tagged type, then it cannot be called at all.
  9888.  
  9889. 8   The type of an aggregate, or of an object created by an object_
  9890. declaration or an allocator, or a generic formal object of mode in, shall not
  9891. be abstract.  The type of the target of an assignment operation (see 5.2)
  9892. shall not be abstract.  The type of a component shall not be abstract.  If
  9893. the result type of a function is abstract, then the function shall be
  9894. abstract.
  9895.  
  9896.         8.a   Reason:  This ensures that values of an abstract type cannot be
  9897.         created, which ensures that a dispatching call to an abstract
  9898.         subprogram will not try to execute the nonexistent body.
  9899.  
  9900.         8.b   Generic formal objects of mode in are like constants; therefore
  9901.         they should be forbidden for abstract types.  Generic formal objects
  9902.         of mode in out are like renamings; therefore, abstract types are OK
  9903.         for them, though probably not terribly useful.
  9904.  
  9905. 9   If a partial view is not abstract, the corresponding full view shall not
  9906. be abstract.  If a generic formal type is abstract, then for each primitive
  9907. subprogram of the formal that is not abstract, the corresponding primitive
  9908. subprogram of the actual shall not be abstract.
  9909.  
  9910.         9.a   Discussion:  By contrast, we allow the actual type to be
  9911.         nonabstract even if the formal type is declared abstract.  Hence, the
  9912.         most general formal tagged type possible is "type T(<>) is abstract
  9913.         tagged limited private;".
  9914.  
  9915.         9.b   For an abstract private extension declared in the visible part
  9916.         of a package, it is only possible for the full type to be nonabstract
  9917.         if the private extension has no abstract dispatching operations.
  9918.  
  9919. 10   For an abstract type declared in a visible part, an abstract primitive
  9920. subprogram shall not be declared in the private part, unless it is overriding
  9921. an abstract subprogram implicitly declared in the visible part.  For a tagged
  9922. type declared in a visible part, a primitive function with a controlling
  9923. result shall not be declared in the private part, unless it is overriding a
  9924. function implicitly declared in the visible part.
  9925.  
  9926.         10.a   Reason:  The ``visible part'' could be that of a package or a
  9927.         generic package.  This rule is needed because a non-abstract type
  9928.         extension declared outside the package would not know about any
  9929.         abstract primitive subprograms or primitive functions with
  9930.         controlling results declared in the private part, and wouldn't know
  9931.         that they need to be overridden with non-abstract subprograms.  The
  9932.         rule applies to a tagged record type or record extension declared in
  9933.         a visible part, just as to a tagged private type or private
  9934.         extension.  The rule applies to explicitly and implicitly declared
  9935.         abstract subprograms:
  9936.  
  9937. 10.b        package Pack is
  9938.                 type T is abstract new T1 with private;
  9939.             private
  9940.                 type T is abstract new T2 with record ... end record;
  9941.                 ...
  9942.             end Pack;
  9943.  
  9944.         10.c   The above example would be illegal if T1 has a non-abstract
  9945.         primitive procedure P, but T2 overrides P with an abstract one; the
  9946.         private part should override P with a non-abstract version.  On the
  9947.         other hand, if the P were abstract for both T1 and T2, the example
  9948.         would be legal as is.
  9949.  
  9950. 11   A generic actual subprogram shall not be an abstract subprogram.  The
  9951. prefix of an attribute_reference for the Access, Unchecked_Access, or Address
  9952. attributes shall not denote an abstract subprogram.
  9953.  
  9954.         11.a   Ramification:  An abstract_subprogram_declaration is not
  9955.         syntactically a subprogram_declaration.  Nonetheless, an abstract
  9956.         subprogram is a subprogram, and an abstract_subprogram_declaration is
  9957.         a declaration of a subprogram.
  9958.  
  9959.         11.b   The part about generic actual subprograms includes those given
  9960.         by default.
  9961.  
  9962.  
  9963.      NOTES
  9964. 12   (74) Abstractness is not inherited; to declare an abstract type, the
  9965.      reserved word abstract has to be used in the declaration of the type
  9966.      extension.
  9967.  
  9968.    12.a   Ramification:  A derived type can be abstract even if its parent is
  9969.         not.  Similarly, an inherited concrete subprogram can be overridden
  9970.         with an abstract subprogram.
  9971.  
  9972. 13   (75) A class-wide type is never abstract.  Even if a class is rooted at
  9973.      an abstract type, the class-wide type for the class is not abstract, and
  9974.      an object of the class-wide type can be created; the tag of such an
  9975.      object will identify some nonabstract type in the class.
  9976.  
  9977.  
  9978.                                   Examples
  9979.  
  9980. 14   Example of an abstract type representing a set of natural numbers:
  9981.  
  9982. 15  package Sets is
  9983.         subtype Element_Type is Natural;
  9984.         type Set is abstract tagged null record;
  9985.         function Empty return Set is abstract;
  9986.         function Union(Left, Right : Set) return Set is abstract;
  9987.         function Intersection(Left, Right : Set) return Set is abstract;
  9988.         function Unit_Set(Element : Element_Type) return Set is abstract;
  9989.         procedure Take(Element : out Element_Type; From : in out Set) is abstra\
  9990. ct;
  9991.     end Sets;
  9992.  
  9993.  
  9994.      NOTES
  9995. 16   (76) Notes on the example:  Given the above abstract type, one could
  9996.      then derive various (nonabstract) extensions of the type, representing
  9997.      alternative implementations of a set.  One might use a bit vector, but
  9998.      impose an upper bound on the largest element representable, while
  9999.      another might use a hash table, trading off space for flexibility.
  10000.  
  10001.    16.a   Discussion:  One way to export a type from a package with some
  10002.         components visible and some components private is as follows:
  10003.  
  10004. 16.b        package P is
  10005.                 type Public_Part is abstract tagged
  10006.                     record
  10007.                         ...
  10008.                     end record;
  10009.                 type T is new Public_Part with private;
  10010.                 ...
  10011.             private
  10012.                 type T is new Public_Part with
  10013.                     record
  10014.                         ...
  10015.                     end record;
  10016.             end P;
  10017.  
  10018.    16.c   The fact that Public_Part is abstract tells clients they have to
  10019.         create objects of type T instead of Public_Part.  Note that the
  10020.         public part has to come first; it would be illegal to declare a
  10021.         private type Private_Part, and then a record extension T of it,
  10022.         unless T were in the private part after the full declaration of
  10023.         Private_Part, but then clients of the package would not have
  10024.         visibility to T.
  10025.  
  10026.  
  10027.  
  10028. 3.10 Access Types
  10029.  
  10030. 1   {access type} {access value} {designate} A value of an access type (an
  10031. access value) provides indirect access to the object or subprogram it
  10032. designates.  Depending on its type, an access value can designate either
  10033. subprograms, objects created by allocators (see 4.8), or more generally
  10034. aliased objects of an appropriate type.  {pointer: see access value} {pointer
  10035. type: see access type}
  10036.  
  10037.         1.a   Discussion:  A name denotes an entity; an access value
  10038.         designates an entity.  The ``dereference'' of an access value X,
  10039.         written ``X.all'', is a name that denotes the entity designated by X.
  10040.  
  10041.  
  10042.                          Language Design Principles
  10043.  
  10044.         1.b   Access values should always be well defined (barring uses of
  10045.         certain unchecked features of Section 13).  In particular,
  10046.         uninitialized access variables should be prevented by compile-time
  10047.         rules.
  10048.  
  10049.                                    Syntax
  10050.  
  10051. 2   access_type_definition ::=
  10052.         access_to_object_definition
  10053.       | access_to_subprogram_definition
  10054.  
  10055. 3   access_to_object_definition ::=
  10056.         access [general_access_modifier] subtype_indication
  10057.  
  10058. 4   general_access_modifier ::= all | constant
  10059.  
  10060. 5   access_to_subprogram_definition ::=
  10061.         access [protected] procedure parameter_profile
  10062.       | access [protected] function  parameter_and_result_profile
  10063.  
  10064. 6   access_definition ::= access subtype_mark
  10065.  
  10066.  
  10067.                               Static Semantics
  10068.  
  10069. 7   {access-to-object type} {access-to-subprogram type} {pool-specific access
  10070. type} {general access type} There are two kinds of access types,
  10071. access-to-object types, whose values designate objects, and
  10072. access-to-subprogram types, whose values designate subprograms.  {storage
  10073. pool} Associated with an access-to-object type is a storage pool; several
  10074. access types may share the same storage pool.  {pool element} A storage pool
  10075. is an area of storage used to hold dynamically allocated objects (called pool
  10076. elements) created by allocators[; storage pools are described further in
  10077. 13.11, ``Storage Management''].
  10078.  
  10079. 8   {pool-specific access type} {general access type} Access-to-object types
  10080. are further subdivided into pool-specific access types, whose values can
  10081. designate only the elements of their associated storage pool, and general
  10082. access types, whose values can designate the elements of any storage pool, as
  10083. well as aliased objects created by declarations rather than allocators, and
  10084. aliased subcomponents of other objects.
  10085.  
  10086.         8.a   Implementation Note:  The value of an access type will
  10087.         typically be a machine address.  However, a value of a pool-specific
  10088.         access type can be represented as an offset (or index) relative to
  10089.         its storage pool, since it can point only to the elements of that
  10090.         pool.
  10091.  
  10092. 9   {aliased} A view of an object is defined to be aliased if it is defined
  10093. by an object_declaration or component_definition with the reserved word
  10094. aliased, or by a renaming of an aliased view.  In addition, the dereference
  10095. of an access-to-object value denotes an aliased view, as does a view
  10096. conversion (see 4.6) of an aliased view.  Finally, the current instance of a
  10097. limited type, and a formal parameter or generic formal object of a tagged
  10098. type are defined to be aliased.  {94-4978.a} [Aliased views are the ones that
  10099. can be designated by an access value.]  {constrained (object)} {unconstrained
  10100. (object)} {constrained by its initial value} If the view defined by an
  10101. object_declaration is aliased, and the type of the object has discriminants,
  10102. then the object is constrained; if its nominal subtype is unconstrained, then
  10103. the object is constrained by its initial value.  [Similarly, if the object
  10104. created by an allocator has discriminants, the object is constrained, either
  10105. by the designated subtype, or by its initial value.]  {94-4858.a}
  10106.  
  10107.         9.a   Glossary entry:  {Aliased} An aliased view of an object is one
  10108.         that can be designated by an access value.  Objects allocated by
  10109.         allocators are aliased.  Objects can also be explicitly declared as
  10110.         aliased with the reserved word aliased.  The Access attribute can be
  10111.         used to create an access value designating an aliased object.
  10112.  
  10113.         9.b   Ramification:  The current instance of a nonlimited type is not
  10114.         aliased.
  10115.  
  10116.         9.c   The object created by an allocator is aliased, but not its
  10117.         subcomponents, except of course for those that themselves have
  10118.         aliased in their component_definition.
  10119.  
  10120.         9.d   The renaming of an aliased object is aliased.
  10121.  
  10122.         9.e   Slices are never aliased.  See 4.1.2 for more discussion.
  10123.  
  10124.         9.f   Reason:  The current instance of a limited type is defined to
  10125.         be aliased so that an access discriminant of a component can be
  10126.         initialized with T'Access inside the definition of T.
  10127.  
  10128.         9.g   A formal parameter of a tagged type is defined to be aliased so
  10129.         that a (tagged) parameter X may be passed to an access parameter P by
  10130.         using P => X'Access.  Access parameters are most important for tagged
  10131.         types because of dispatching-on-access-parameters (see 3.9.2).  By
  10132.         restricting this to formal parameters, we minimize problems
  10133.         associated with allowing components that are not declared aliased to
  10134.         be pointed-to from within the same record.
  10135.  
  10136.         9.h   A view conversion of an aliased view is aliased so that the
  10137.         type of an access parameter can be changed without first converting
  10138.         to a named access type.  For example:
  10139.  
  10140. 9.i         type T1 is tagged ...;
  10141.             procedure P(X : access T1);
  10142.  
  10143. 9.j         type T2 is new T1 with ...;
  10144.             procedure P(X : access T2) is
  10145.             begin
  10146.                 P(T1(X.all)'Access);  -- hand off to T1's P
  10147.                 . . .      -- now do extra T2-specific processing
  10148.             end P;
  10149.  
  10150.         9.k   The rule about objects with discriminants is necessary because
  10151.         values of a constrained access subtype can designate an object whose
  10152.         nominal subtype is unconstrained; without this rule, a check on every
  10153.         use of such values would be required to ensure that the discriminants
  10154.         of the object had not changed.  With this rule (among others), we
  10155.         ensure that if there might exist aliased views of a discriminated
  10156.         object, then the object is necessarily constrained.  Note that this
  10157.         rule is necessary only for untagged types, since a discriminant of a
  10158.         tagged type can't have a default, so all tagged discriminated objects
  10159.         are always constrained anyway.
  10160.  
  10161.         9.l   We considered making more kinds of objects aliased by default.
  10162.         In particular, any object of a by-reference type will pretty much
  10163.         have to be allocated at an addressable location, so it can be passed
  10164.         by reference without using bit-field pointers.  Therefore, one might
  10165.         wish to allow the Access and and Unchecked_Access attributes for such
  10166.         objects.  However, private parts are transparent to the definition of
  10167.         ``by-reference type'', so if we made all objects of a by-reference
  10168.         type aliased, we would be violating the privacy of private parts.
  10169.         Instead, we would have to define a concept of ``visibly
  10170.         by-reference'' and base the rule on that.  This seemed to complicate
  10171.         the rules more than it was worth, especially since there is no way to
  10172.         declare an untagged limited private type to be by-reference, since
  10173.         the full type might by nonlimited.
  10174.  
  10175.         9.m   Discussion:  Note that we do not use the term ``aliased'' to
  10176.         refer to formal parameters that are referenced through multiple
  10177.         access paths (see 6.2).
  10178.  
  10179. 10   An access_to_object_definition defines an access-to-object type and its
  10180. first subtype; {designated subtype (of a named access type)} {designated type
  10181. (of a named access type)} the subtype_indication defines the designated
  10182. subtype of the access type.  If a general_access_modifier appears, then the
  10183. access type is a general access type.  {access-to-constant type} If the
  10184. modifier is the reserved word constant, then the type is an
  10185. access-to-constant type[; a designated object cannot be updated through a
  10186. value of such a type].  {access-to-variable type} If the modifier is the
  10187. reserved word all, then the type is an access-to-variable type[; a designated
  10188. object can be both read and updated through a value of such a type].  If no
  10189. general_access_modifier appears in the access_to_object_definition, the
  10190. access type is a pool-specific access-to-variable type.
  10191.  
  10192.         10.a   To be honest:  The type of the designated subtype is called
  10193.         the designated type.
  10194.  
  10195.         10.b   Reason:  The modifier all was picked to suggest that values of
  10196.         a general access type could point into ``all'' storage pools, as well
  10197.         as to objects declared aliased, and that ``all'' access (both read
  10198.         and update) to the designated object was provided.  We couldn't think
  10199.         of any use for pool-specific access-to-constant types, so any access
  10200.         type defined with the modifier constant is considered a general
  10201.         access type, and can point into any storage pool or at other
  10202.         (appropriate) aliased objects.
  10203.  
  10204.         10.c   Implementation Note:  The predefined generic Unchecked_
  10205.         Deallocation can be instantiated for any named access-to-variable
  10206.         type.  There is no (language-defined) support for deallocating
  10207.         objects designated by a value of an access-to-constant type.  Because
  10208.         of this, an allocator for an access-to-constant type can allocate out
  10209.         of a storage pool with no support for deallocation.  Frequently, the
  10210.         allocation can be done at link-time, if the size and initial value
  10211.         are known then.
  10212.  
  10213.         10.d   Discussion:  For the purpose of generic formal type matching,
  10214.         the relevant subclasses of access types are access-to-subprogram
  10215.         types, access-to-constant types, and (named) access-to-variable
  10216.         types, with its subclass (named) general access-to-variable types.
  10217.         Pool-specific access-to-variable types are not a separately matchable
  10218.         subclass of types, since they don't have any ``extra'' operations
  10219.         relative to all (named) access-to-variable types.
  10220.  
  10221. 11   {access-to-subprogram type} An access_to_subprogram_definition defines
  10222. an access-to-subprogram type and its first subtype; {designated profile (of
  10223. an access-to-subprogram type)} the parameter_profile or parameter_and_result_
  10224. profile defines the designated profile of the access type.  {calling
  10225. convention (associated with a designated profile)} There is a calling
  10226. convention associated with the designated profile[; only subprograms with
  10227. this calling convention can be designated by values of the access type.]  By
  10228. default, the calling convention is ``protected'' if the reserved word
  10229. protected appears, and ``Ada'' otherwise.  [See Annex B for how to override
  10230. this default.]
  10231.  
  10232.         11.a   Ramification:  The calling convention protected is in italics
  10233.         to emphasize that it cannot be specified explicitly by the user.
  10234.         This is a consequence of it being a reserved word.
  10235.  
  10236.         11.b   Implementation Note:  For an access-to-subprogram type, the
  10237.         representation of an access value might include implementation-
  10238.         defined information needed to support up-level references -- for
  10239.         example, a static link.  The accessibility rules (see 3.10.2) ensure
  10240.         that in a "global-display-based" implementation model (as opposed to
  10241.         a static-link-based model), an access-to-(unprotected)-subprogram
  10242.         value need consist only of the address of the subprogram.  The global
  10243.         display is guaranteed to be properly set up any time the designated
  10244.         subprogram is called.  Even in a static-link-based model, the only
  10245.         time a static link is definitely required is for an
  10246.         access-to-subprogram type declared in a scope nested at least two
  10247.         levels deep within subprogram or task bodies, since values of such a
  10248.         type might designate subprograms nested a smaller number of levels.
  10249.         For the normal case of an access-to-subprogram type declared at the
  10250.         outermost (library) level, a code address by itself should be
  10251.         sufficient to represent the access value in many implementations.
  10252.  
  10253.         11.c   For access-to-protected-subprogram, the access values will
  10254.         necessarily include both an address (or other identification) of the
  10255.         code of the subprogram, as well as the address of the associated
  10256.         protected object.  This could be thought of as a static link, but it
  10257.         will be needed even for global-display-based implementation models.
  10258.         It corresponds to the value of the ``implicit parameter'' that is
  10259.         passed into every call of a protected operation, to identify the
  10260.         current instance of the protected type on which they are to operate.
  10261.  
  10262.         11.d   Any Elaboration_Check is performed when a call is made through
  10263.         an access value, rather than when the access value is first "created"
  10264.         via a 'Access.  For implementation models that normally put that
  10265.         check at the call-site, an access value will have to point to a
  10266.         separate entry point that does the check.  Alternatively, the access
  10267.         value could point to a "subprogram descriptor" that consisted of two
  10268.         words (or perhaps more), the first being the address of the code, the
  10269.         second being the elaboration bit.  Or perhaps more efficiently, just
  10270.         the address of the code, but using the trick that the descriptor is
  10271.         initialized to point to a Raise-Program-Error routine initially, and
  10272.         then set to point to the "real" code when the body is elaborated.
  10273.  
  10274.         11.e   For implementations that share code between generic
  10275.         instantiations, the extra level of indirection suggested above to
  10276.         support Elaboration_Checks could also be used to provide a pointer to
  10277.         the per-instance data area normally required when calling shared
  10278.         code.  The trick would be to put a pointer to the per-instance data
  10279.         area into the subprogram descriptor, and then make sure that the
  10280.         address of the subprogram descriptor is loaded into a "known"
  10281.         register whenever an indirect call is performed.  Once inside the
  10282.         shared code, the address of the per-instance data area can be
  10283.         retrieved out of the subprogram descriptor, by indexing off the
  10284.         "known" register.
  10285.  
  10286.         11.f   Essentially the same implementation issues arise for calls on
  10287.         dispatching operations of tagged types, except that the static link
  10288.         is always known "statically."
  10289.  
  10290.         11.g   Note that access parameters of an anonymous access-to-
  10291.         subprogram type are not permitted.  If there were such parameters,
  10292.         full ``downward'' closures would be required, meaning that in an
  10293.         implementation that uses a per-task (global) display, the display
  10294.         would have to be passed as a hidden parameter, and reconstructed at
  10295.         the point of call.  This was felt to be an undue implementation
  10296.         burden, given that an equivalent (actually, more general) capability
  10297.         is available via formal subprogram parameters to a generic.
  10298.  
  10299. 12   {anonymous access type} {designated subtype (of an anonymous access
  10300. type)} {designated type (of an anonymous access type)} An access_definition
  10301. defines an anonymous general access-to-variable type; the subtype_mark
  10302. denotes its designated subtype.  [An access_definition is used in the
  10303. specification of an access discriminant (see 3.7) or an access parameter (see
  10304. 6.1).]
  10305.  
  10306. 13   {null value (of an access type)} For each (named) access type, there is
  10307. a literal null which has a null access value designating no entity at all.
  10308. [The null value of a named access type is the default initial value of the
  10309. type.]  Other values of an access type are obtained by evaluating an
  10310. attribute_reference for the Access or Unchecked_Access attribute of an
  10311. aliased view of an object or non-intrinsic subprogram, or, in the case of a
  10312. named access-to-object type, an allocator[, which returns an access value
  10313. designating a newly created object (see 3.10.2)].
  10314.  
  10315.         13.a   Ramification:  A value of an anonymous access type (that is,
  10316.         the value of an access parameter or access discriminant) cannot be
  10317.         null.
  10318.  
  10319.         13.b   Reason:  Access parameters allow dispatching on the tag of the
  10320.         object designated by the actual parameter (which gets converted to
  10321.         the anonymous access type as part of the call).  In order for
  10322.         dispatching to work properly, there had better be such an object.
  10323.         Hence, the type conversion will raise Constraint_Error if the value
  10324.         of the actual parameter is null.
  10325.  
  10326. 14   {constrained [subtype]} {unconstrained [subtype]} [All subtypes of an
  10327. access-to-subprogram type are constrained.]  The first subtype of a type
  10328. defined by an access_type_definition or an access_to_object_definition is
  10329. unconstrained if the designated subtype is an unconstrained array or
  10330. discriminated type; otherwise it is constrained.
  10331.  
  10332.         14.a   Proof:  The Legality Rules on range_constraints (see 3.5) do
  10333.         not permit the subtype_mark of the subtype_indication to denote an
  10334.         access-to-scalar type, only a scalar type.  The Legality Rules on
  10335.         index_constraints (see 3.6.1) and discriminant_constraints (see
  10336.         3.7.1) both permit access-to-composite types in a subtype_indication
  10337.         with such _constraints.  Note that an access-to-access-to-composite
  10338.         is never permitted in a subtype_indication with a constraint.
  10339.  
  10340.         14.b   Reason:  Only composite_constraints are permitted for an
  10341.         access type, and only on access-to-composite types.  A constraint on
  10342.         an access-to-scalar or access-to-access type might be violated due to
  10343.         assignments via other access paths that were not so constrained.  By
  10344.         contrast, if the designated subtype is an array or discriminated
  10345.         type, the constraint could not be violated by unconstrained
  10346.         assignments, since array objects are always constrained, and aliased
  10347.         discriminated objects are also constrained (by fiat, see Static
  10348.         Semantics).
  10349.  
  10350.  
  10351.                               Dynamic Semantics
  10352.  
  10353. 15   {compatibility [composite_constraint with an access subtype]} A
  10354. composite_constraint is compatible with an unconstrained access subtype if it
  10355. is compatible with the designated subtype.  {satisfies [for an access value]}
  10356. An access value satisfies a composite_constraint of an access subtype if it
  10357. equals the null value of its type or if it designates an object whose value
  10358. satisfies the constraint.
  10359.  
  10360. 16   {elaboration [access_type_definition]} The elaboration of an access_
  10361. type_definition creates the access type and its first subtype.  For an
  10362. access-to-object type, this elaboration includes the elaboration of the
  10363. subtype_indication, which creates the designated subtype.
  10364.  
  10365. 17   {elaboration [access_definition]} The elaboration of an access_
  10366. definition creates an anonymous general access-to-variable type [(this
  10367. happens as part of the initialization of an access parameter or access
  10368. discriminant)].
  10369.  
  10370.  
  10371.      NOTES
  10372. 18   (77) Access values are called ``pointers'' or ``references'' in some
  10373.      other languages.
  10374.  
  10375. 19   (78) Each access-to-object type has an associated storage pool; several
  10376.      access types can share the same pool.  An object can be created in the
  10377.      storage pool of an access type by an allocator (see 4.8) for the access
  10378.      type.  A storage pool (roughly) corresponds to what some other languages
  10379.      call a ``heap.''  See 13.11 for a discussion of pools.
  10380.  
  10381. 20   (79) Only index_constraints and discriminant_constraints can be applied
  10382.      to access types (see 3.6.1 and 3.7.1).
  10383.  
  10384.  
  10385.                                   Examples
  10386.  
  10387. 21   Examples of access-to-object types:
  10388.  
  10389. 22  type Peripheral_Ref is access Peripheral;  --  see 3.8.1
  10390.     type Binop_Ptr is access all Binary_Operation'Class;
  10391.                                                -- general access-to-class-wide,\
  10392.  see 3.9.1
  10393.  
  10394. 23   Example of an access subtype:
  10395.  
  10396. 24  subtype Drum_Ref is Peripheral_Ref(Drum);  --  see 3.8.1
  10397.  
  10398. 25   Example of an access-to-subprogram type:
  10399.  
  10400. 26  type Message_Procedure is access procedure (M : in String := "Error!");
  10401.     procedure Default_Message_Procedure(M : in String);
  10402.     Give_Message : Message_Procedure := Default_Message_Procedure'Access;
  10403.     ...
  10404.     procedure Other_Procedure(M : in String);
  10405.     ...
  10406.     Give_Message := Other_Procedure'Access;
  10407.     ...
  10408.     Give_Message("File not found.");  -- call with parameter (.all is optional)
  10409.     Give_Message.all;                 -- call with no parameters
  10410.  
  10411.  
  10412.                             Extensions to Ada 83
  10413.  
  10414.         26.a   {extensions to Ada 83} The syntax for access_type_definition
  10415.         is changed to support general access types (including access-to-
  10416.         constants) and access-to-subprograms.  The syntax rules for general_
  10417.         access_modifier and access_definition are new.
  10418.  
  10419.                          Wording Changes From Ada 83
  10420.  
  10421.         26.b   We use the term "storage pool" to talk about the data area
  10422.         from which allocation takes place.  The term "collection" is no
  10423.         longer used.  ("Collection" and "storage pool" are not the same thing
  10424.         because multiple unrelated access types can share the same storage
  10425.         pool; see 13.11 for more discussion.)
  10426.  
  10427.  
  10428.  
  10429. 3.10.1 Incomplete Type Declarations
  10430.  
  10431. 1   There are no particular limitations on the designated type of an access
  10432. type.  In particular, the type of a component of the designated type can be
  10433. another access type, or even the same access type.  This permits mutually
  10434. dependent and recursive access types.  An incomplete_type_declaration can be
  10435. used to introduce a type to be used as a designated type, while deferring its
  10436. full definition to a subsequent full_type_declaration.
  10437.  
  10438.  
  10439.                                    Syntax
  10440.  
  10441. 2   incomplete_type_declaration ::= type defining_identifier [discriminant_part\
  10442. ];
  10443.  
  10444.  
  10445.                                Legality Rules
  10446.  
  10447. 3   {requires a completion [incomplete_type_declaration]} An incomplete_type_
  10448. declaration requires a completion, which shall be a full_type_declaration.
  10449. [If the incomplete_type_declaration occurs immediately within either the
  10450. visible part of a package_specification or a declarative_part, then the full_
  10451. type_declaration shall occur later and immediately within this visible part
  10452. or declarative_part.  If the incomplete_type_declaration occurs immediately
  10453. within the private part of a given package_specification, then the full_type_
  10454. declaration shall occur later and immediately within either the private part
  10455. itself, or the declarative_part of the corresponding package_body.]
  10456.  
  10457.         3.a   Proof:  This is implied by the next AARM-only rule, plus the
  10458.         rules in 3.11.1, ``Completions of Declarations'' which require a
  10459.         completion to appear later and immediately within the same
  10460.         declarative region.
  10461.  
  10462.         3.b   To be honest:  If the incomplete_type_declaration occurs
  10463.         immediately within the visible part of a package_specification, then
  10464.         the full_type_declaration shall occur immediately within this visible
  10465.         part.
  10466.  
  10467.         3.c   To be honest:  If the implementation supports it, an
  10468.         incomplete_type_declaration can be completed by a pragma Import.
  10469.  
  10470. 4   If an incomplete_type_declaration has a known_discriminant_part, then a
  10471. full_type_declaration that completes it shall have a fully conforming
  10472. (explicit) known_discriminant_part (see 6.3.1).  {full conformance
  10473. (required)} [If an incomplete_type_declaration has no discriminant_part (or
  10474. an unknown_discriminant_part), then a corresponding full_type_declaration is
  10475. nevertheless allowed to have discriminants, either explicitly, or inherited
  10476. via derivation.]
  10477.  
  10478. 5   The only allowed uses of a name that denotes an incomplete_type_
  10479. declaration are as follows:
  10480.  
  10481.         5.a   Discussion:  No need to say "prior to the end of the full_type_
  10482.         declaration" since the name would not denote the incomplete_type_
  10483.         declaration after the end of the full_type_declaration.  Also, with
  10484.         child library units, it would not be well defined whether they come
  10485.         before or after the full_type_declaration for deferred incomplete
  10486.         types.
  10487.  
  10488.     6  as the subtype_mark in the subtype_indication of an access_to_
  10489.        object_definition; [the only form of constraint allowed in this
  10490.        subtype_indication is a discriminant_constraint;]
  10491.  
  10492.  6.a    Implementation Note:  We now allow discriminant_constraints even
  10493.         if the full type is deferred to the package body.  However,
  10494.         there is no particular implementation burden because we have
  10495.         dropped the concept of the dependent compatibility check.  In
  10496.         other words, we have effectively repealed AI-00007.
  10497.  
  10498.     7  as the subtype_mark defining the subtype of a parameter or result
  10499.        of an access_to_subprogram_definition; {94-4618.a}
  10500.  
  10501.  7.a    Reason:  This allows, for example, a record to have a component
  10502.         designating a subprogram that takes that same record type as a
  10503.         parameter.
  10504.  
  10505.     8  as the subtype_mark in an access_definition;
  10506.  
  10507.     9  as the prefix of an attribute_reference whose attribute_
  10508.        designator is Class; such an attribute_reference is similarly
  10509.        restricted to the uses allowed here; when used in this way, the
  10510.        corresponding full_type_declaration shall declare a tagged type,
  10511.        and the attribute_reference shall occur in the same library unit
  10512.        as the incomplete_type_declaration.
  10513.  
  10514.  9.a    Reason:  This is to prevent children from imposing requirements
  10515.         on their ancestor library units for deferred incomplete types.
  10516.  
  10517. 10   A dereference (whether implicit or explicit -- see 4.1) shall not be of
  10518. an incomplete type.
  10519.  
  10520.  
  10521.                               Static Semantics
  10522.  
  10523. 11   {incomplete type} An incomplete_type_declaration declares an incomplete
  10524. type and its first subtype; the first subtype is unconstrained if a known_
  10525. discriminant_part appears.
  10526.  
  10527.         11.a   Reason:  If an unknown_discriminant_part or no discriminant_
  10528.         part appears, then the constrainedness of the first subtype doesn't
  10529.         matter for any other rules or semantics, so we don't bother defining
  10530.         it.  The case with a known_discriminant_part is the only case in
  10531.         which a constraint could later be given in a subtype_indication
  10532.         naming the incomplete type.
  10533.  
  10534.  
  10535.                               Dynamic Semantics
  10536.  
  10537. 12   {elaboration [incomplete_type_declaration]} The elaboration of an
  10538. incomplete_type_declaration has no effect.
  10539.  
  10540.         12.a   Reason:  An incomplete type has no real existence, so it
  10541.         doesn't need to be "created" in the usual sense we do for other
  10542.         types.  It is roughly equivalent to a "forward;" declaration in
  10543.         Pascal.  Private types are different, because they have a different
  10544.         set of characteristics from their full type.
  10545.  
  10546.  
  10547.      NOTES
  10548. 13   (80) {completion legality [partial]} Within a declarative_part, an
  10549.      incomplete_type_declaration and a corresponding full_type_declaration
  10550.      cannot be separated by an intervening body.  This is because a type has
  10551.      to be completely defined before it is frozen, and a body freezes all
  10552.      types declared prior to it in the same declarative_part (see 13.14).
  10553.  
  10554.  
  10555.                                   Examples
  10556.  
  10557. 14   Example of a recursive type:
  10558.  
  10559. 15  type Cell;  --  incomplete type declaration
  10560.     type Link is access Cell;
  10561. 16  type Cell is
  10562.        record
  10563.           Value  : Integer;
  10564.           Succ   : Link;
  10565.           Pred   : Link;
  10566.        end record;
  10567.  
  10568. 17  Head   : Link  := new Cell'(0, null, null);
  10569.     Next   : Link  := Head.Succ;
  10570.  
  10571. 18   Examples of mutually dependent access types:
  10572.  
  10573. 19  type Person(<>);    -- incomplete type declaration
  10574.     type Car;           -- incomplete type declaration
  10575.  
  10576. 20  type Person_Name is access Person;
  10577.     type Car_Name    is access all Car;
  10578.  
  10579. 21  type Car is
  10580.        record
  10581.           Number  : Integer;
  10582.           Owner   : Person_Name;
  10583.        end record;
  10584.  
  10585. 22  type Person(Sex : Gender) is
  10586.        record
  10587.           Name     : String(1 .. 20);
  10588.           Birth    : Date;
  10589.           Age      : Integer range 0 .. 130;
  10590.           Vehicle  : Car_Name;
  10591.           case Sex is
  10592.              when M => Wife           : Person_Name(Sex => F);
  10593.              when F => Husband        : Person_Name(Sex => M);
  10594.           end case;
  10595.        end record;
  10596.  
  10597. 23  My_Car, Your_Car, Next_Car : Car_Name := new Car;  -- see 4.8
  10598.     George : Person_Name := new Person(M);
  10599.        ...
  10600.     George.Vehicle := Your_Car;
  10601.  
  10602.  
  10603.                             Extensions to Ada 83
  10604.  
  10605.         23.a   {extensions to Ada 83} The full_type_declaration that
  10606.         completes an incomplete_type_declaration may have a known_
  10607.         discriminant_part even if the incomplete_type_declaration does not.
  10608.  
  10609.         23.b   A discriminant_constraint may be applied to an incomplete
  10610.         type, even if it its completion is deferred to the package body,
  10611.         because there is no ``dependent compatibility check'' required any
  10612.         more.  Of course, the constraint can be specified only if a known_
  10613.         discriminant_part was given in the incomplete_type_declaration.  As
  10614.         mentioned in the previous paragraph, that is no longer required even
  10615.         when the full type has discriminants.
  10616.  
  10617.                          Wording Changes From Ada 83
  10618.  
  10619.         23.c   Dereferences producing incomplete types were not explicitly
  10620.         disallowed in RM83, though AI-00039 indicated that it was not
  10621.         strictly necessary since troublesome cases would result in
  10622.         Constraint_Error at run time, since the access value would
  10623.         necessarily be null.  However, this introduces an undesirable
  10624.         implementation burden, as illustrated by Example 4 of AI-00039:
  10625.  
  10626. 23.d        package Pack is
  10627.                 type Pri is private;
  10628.             private
  10629.                 type Sep;
  10630.                 type Pri is access Sep;
  10631.                 X : Pri;
  10632.             end Pack;
  10633.  
  10634. 23.e        package body Pack is -- Could be separately compiled!
  10635.                 type Sep is ...;
  10636.                 X := new Sep;
  10637.             end Pack;
  10638.  
  10639. 23.f        pragma Elaborate(Pack);
  10640.             private package Pack.Child is
  10641.                 I : Integer := X.all'Size; -- Legal, by AI-00039.
  10642.             end Pack.Child;
  10643.  
  10644.         23.g   Generating code for the above example could be a serious
  10645.         implementation burden, since it would require all aliased objects to
  10646.         store size dope, and for that dope to be in the same format for all
  10647.         kinds of types (or some other equivalently inefficient implemen-
  10648.         tation).  On the contrary, most implementations allocate dope
  10649.         differently (or not at all) for different designated subtypes.
  10650.  
  10651.  
  10652.  
  10653. 3.10.2 Operations of Access Types
  10654.  
  10655. 1   [The attribute Access is used to create access values designating aliased
  10656. objects and non-intrinsic subprograms.  The ``accessibility'' rules prevent
  10657. dangling references (in the absence of uses of certain unchecked features --
  10658. see Section 13).  ]{94-4715.a} {94-4570.a} {94-4724.a} {94-4725.a}
  10659. {94-4780.a}
  10660.  
  10661.  
  10662.                          Language Design Principles
  10663.  
  10664.         1.a   It should be possible for an access value to designate an
  10665.         object declared by an object declaration, or a subcomponent thereof.
  10666.         In implementation terms, this means pointing at stack-allocated and
  10667.         statically allocated data structures.  However, dangling references
  10668.         should be prevented, primarily via compile-time rules, so long as
  10669.         features like Unchecked_Access and Unchecked_Deallocation are not
  10670.         used.
  10671.  
  10672.         1.b   In order to create such access values, we require that the
  10673.         access type be a general access type, that the designated object be
  10674.         aliased, and that the accessibility rules be obeyed.
  10675.  
  10676.                             Name Resolution Rules
  10677.  
  10678. 2   {expected type [access attribute_reference]} For an attribute_reference
  10679. with attribute_designator Access (or Unchecked_Access -- see 13.10), the
  10680. expected type shall be a single access type[; the prefix of such an
  10681. attribute_reference is never interpreted as an implicit_dereference].
  10682. {expected profile [Access attribute_reference prefix]} If the expected type
  10683. is an access-to-subprogram type, then the expected profile of the prefix is
  10684. the designated profile of the access type.
  10685.  
  10686.         2.a   Discussion:  Saying that the expected type shall be a "single
  10687.         access type" is our "new" way of saying that the type has to be
  10688.         determinable from context using only the fact that it is an access
  10689.         type.  See 4.2 and 8.6.  Specifying the expected profile only implies
  10690.         type conformance.  The more stringent subtype conformance is required
  10691.         by a Legality Rule.  This is the only Resolution Rule that applies to
  10692.         the name in a prefix of an attribute_reference.  In all other cases,
  10693.         the name has to be resolved without using context.  See 4.1.4.
  10694.  
  10695.  
  10696.                               Static Semantics
  10697.  
  10698. 3   {accessibility level} {level (accessibility)} {deeper (accessibility
  10699. level)} {depth (accessibility level)} {dangling references (prevention via
  10700. accessibility rules)} {lifetime} [The accessibility rules, which prevent
  10701. dangling references, are written in terms of accessibility levels, which
  10702. reflect the run-time nesting of masters.  As explained in 7.6.1, a master is
  10703. the execution of a task_body, a block_statement, a subprogram_body, an entry_
  10704. body, or an accept_statement.  An accessibility level is deeper than another
  10705. if it is more deeply nested at run time.  {94-4746.} For example, an object
  10706. declared local to a called subprogram has a deeper accessibility level than
  10707. an object declared local to the calling subprogram.  The accessibility rules
  10708. for access types require that the accessibility level of an object designated
  10709. by an access value be no deeper than that of the access type.  This ensures
  10710. that the object will live at least as long as the access type, which in turn
  10711. ensures that the access value cannot later designate an object that no longer
  10712. exists.  The Unchecked_Access attribute may be used to circumvent the
  10713. accessibility rules.]
  10714.  
  10715. 4   {statically deeper} {deeper (statically)} [A given accessibility level is
  10716. said to be statically deeper than another if the given level is known at
  10717. compile time (as defined below) to be deeper than the other for all possible
  10718. executions.  In most cases, accessibility is enforced at compile time by
  10719. Legality Rules.  Run-time accessibility checks are also used, since the
  10720. Legality Rules do not cover certain cases involving access parameters and
  10721. generic packages.]  {94-4857.a} {94-4918.a}
  10722.  
  10723. 5   Each master, and each entity and view created by it, has an accessibility
  10724. level:
  10725.  
  10726.     6  The accessibility level of a given master is deeper than that of
  10727.        each dynamically enclosing master, and deeper than that of each
  10728.        master upon which the task executing the given master directly
  10729.        depends (see 9.3).
  10730.  
  10731.     7  An entity or view created by a declaration has the same
  10732.        accessibility level as the innermost enclosing master, except in
  10733.        the cases of renaming and derived access types described below.
  10734.        A parameter of a master has the same accessibility level as the
  10735.        master.
  10736.  
  10737.     8  The accessibility level of a view of an object or subprogram
  10738.        defined by a renaming_declaration is the same as that of the
  10739.        renamed view.
  10740.  
  10741.     9  The accessibility level of a view conversion is the same as that
  10742.        of the operand.  {94-4745.a}
  10743.  
  10744.    10  For a function whose result type is a return-by-reference type,
  10745.        the accessibility level of the result object is the same as that
  10746.        of the master that elaborated the function body.  For any other
  10747.        function, the accessibility level of the result object is that of
  10748.        the execution of the called function.
  10749.  
  10750.    11  The accessibility level of a derived access type is the same as
  10751.        that of its ultimate ancestor.
  10752.  
  10753.    12  The accessibility level of the anonymous access type of an access
  10754.        discriminant is the same as that of the containing object or
  10755.        associated constrained subtype.
  10756.  
  10757.    13  The accessibility level of the anonymous access type of an access
  10758.        parameter is the same as that of the view designated by the
  10759.        actual.  If the actual is an allocator, this is the accessibility
  10760.        level of the execution of the called subprogram.
  10761.  
  10762.    14  The accessibility level of an object created by an allocator is
  10763.        the same as that of the access type.
  10764.  
  10765.    15  The accessibility level of a view of an object or subprogram
  10766.        denoted by a dereference of an access value is the same as that
  10767.        of the access type.
  10768.  
  10769.    16  The accessibility level of a component, protected subprogram, or
  10770.        entry of (a view of) a composite object is the same as that of
  10771.        (the view of) the composite object.
  10772.  
  10773. 17   {statically deeper} {deeper (statically)} One accessibility level is
  10774. defined to be statically deeper than another in the following cases:
  10775.  
  10776.    18  For a master that is statically nested within another master, the
  10777.        accessibility level of the inner master is statically deeper than
  10778.        that of the outer master.
  10779.  
  10780.  18.a   To be honest:  Strictly speaking, this should talk about the
  10781.         constructs (such as subprogram_bodies) being statically nested
  10782.         within one another; the masters are really the executions of
  10783.         those constructs.
  10784.  
  10785.  18.b   To be honest:  If a given accessibility level is statically
  10786.         deeper than another, then each level defined to be the same as
  10787.         the given level is statically deeper than each level defined to
  10788.         be the same as the other level.
  10789.  
  10790.    19  The statically deeper relationship does not apply to the
  10791.        accessibility level of the anonymous type of an access parameter;
  10792.        that is, such an accessibility level is not considered to be
  10793.        statically deeper, nor statically shallower, than any other.
  10794.  
  10795.    20  For determining whether one level is statically deeper than
  10796.        another when within a generic package body, the generic package
  10797.        is presumed to be instantiated at the same level as where it was
  10798.        declared; run-time checks are needed in the case of more deeply
  10799.        nested instantiations.  {94-4857.a} {94-4918.a}
  10800.  
  10801.    21  For determining whether one level is statically deeper than
  10802.        another when within the declarative region of a type_declaration,
  10803.        the current instance of the type is presumed to be an object
  10804.        created at a deeper level than that of the type.  {94-4857.b}
  10805.        {94-4927.a}
  10806.  
  10807.  21.a   Ramification:  In other words, the rules are checked at compile
  10808.         time of the type_declaration, in an assume-the-worst manner.
  10809.  
  10810. 22   {library level} {level (library)} The accessibility level of all library
  10811. units is called the library level; a library-level declaration or entity is
  10812. one whose accessibility level is the library level.
  10813.  
  10814.         22.a   Ramification:  Library_unit_declarations are library level.
  10815.         Nested declarations are library level if they are nested only within
  10816.         packages (possibly more than one), and not within subprograms, tasks,
  10817.         etc.
  10818.  
  10819.         22.b   To be honest:  The definition of the accessibility level of
  10820.         the anonymous type of an access parameter cheats a bit, since it
  10821.         refers to the view designated by the actual, but access values
  10822.         designate objects, not views of objects.  What we really mean is the
  10823.         view that ``would be'' denoted by an expression ``X.all'', where X is
  10824.         the actual, even though such an expression is a figment of our
  10825.         imagination.  The definition is intended to be equivalent to the
  10826.         following more verbose version:  The accessibility level of the
  10827.         anonymous type of an access parameter is as follows:
  10828.  
  10829.          22.c  if the actual is an expression of a named access type --
  10830.                the accessibility level of that type;
  10831.  
  10832.          22.d  if the actual is an allocator -- the accessibility level
  10833.                of the execution of the called subprogram;
  10834.  
  10835.          22.e  if the actual is a reference to the Access attribute --
  10836.                the accessibility level of the view denoted by the
  10837.                prefix;
  10838.  
  10839.          22.f  if the actual is a reference to the Unchecked_Access
  10840.                attribute -- library accessibility level;
  10841.  
  10842.          22.g  if the actual is an access parameter -- the accessibility
  10843.                level of its type.
  10844.  
  10845.         22.h   Note that the allocator case is explicitly mentioned in the
  10846.         RM9X, because otherwise the definition would be circular:  the level
  10847.         of the anonymous type is that of the view designated by the actual,
  10848.         which is that of the access type.
  10849.  
  10850.         22.i   Discussion:  A deeper accessibility level implies a shorter
  10851.         maximum lifetime.  Hence, when a rule requires X to have a level that
  10852.         is ``not deeper than'' Y's level, this requires that X has a lifetime
  10853.         at least as long as Y. (We say ``maximum lifetime'' here, because the
  10854.         accessibility level really represents an upper bound on the lifetime;
  10855.         an object created by an allocator can have its lifetime prematurely
  10856.         ended by an instance of Unchecked_Deallocation.)
  10857.  
  10858.         22.j   Package elaborations are not masters, and are therefore
  10859.         invisible to the accessibility rules:  an object declared immediately
  10860.         within a package has the same accessibility level as an object
  10861.         declared immediately within the declarative region containing the
  10862.         package.  This is true even in the body of a package; it jibes with
  10863.         the fact that objects declared in a package_body live as long as
  10864.         objects declared outside the package, even though the body objects
  10865.         are not visible outside the package.
  10866.  
  10867.         22.k   Note that the level of the view denoted by X.all can be
  10868.         different from the level of the object denoted by X.all.  The former
  10869.         is determined by the type of X; the latter is determined either by
  10870.         the type of the allocator, or by the master in which the object was
  10871.         declared.  The former is used in several Legality Rules and run-time
  10872.         checks; the latter is used to define when X.all gets finalized.  The
  10873.         level of a view reflects what we can conservatively ``know'' about
  10874.         the object of that view; for example, due to type_conversions, an
  10875.         access value might designate an object that was allocated by an
  10876.         allocator for a different access type.
  10877.  
  10878.         22.l   Similarly, the level of the view denoted by X.all.Comp can be
  10879.         different from the level of the object denoted by X.all.Comp.
  10880.  
  10881.         22.m   If Y is statically deeper than X, this implies that Y will be
  10882.         (dynamically) deeper than X in all possible executions.
  10883.  
  10884.         22.n   Most accessibility checking is done at compile time; the rules
  10885.         are stated in terms of ``statically deeper than''.  The exceptions
  10886.         are:
  10887.  
  10888.          22.o  Checks involving access parameters.  The fact that
  10889.                ``statically deeper than'' is not defined for the
  10890.                anonymous access type of an access parameter implies that
  10891.                any rule saying ``shall not be statically deeper than''
  10892.                does not apply to such a type, nor to anything defined to
  10893.                have ``the same'' level as such a type.
  10894.  
  10895.          22.p  Checks involving entities and views within generic
  10896.                packages.  This is because an instantiation can be at a
  10897.                level that is more deeply nested than the generic package
  10898.                itself.  In implementations that use a macro-expansion
  10899.                model of generics, these violations can be detected at
  10900.                macro-expansion time.  For implementations that share
  10901.                generics, run-time code is needed to detect the error.
  10902.  
  10903.          22.q  Checks during function return.
  10904.  
  10905.         22.r   Note that run-time checks are not required for access
  10906.         discriminants, because their accessibility is determined statically
  10907.         by the accessibility level of the enclosing object.
  10908.  
  10909.         22.s   The accessibility level of the result object of a function
  10910.         reflects the time when that object will be finalized; we don't allow
  10911.         pointers to the object to survive beyond that time.  {94-4857.a}
  10912.         {94-4918.a}
  10913.  
  10914.         22.t   We sometimes use the terms ``accessible'' and ``inaccessible''
  10915.         to mean that something has an accessibility level that is not deeper,
  10916.         or deeper, respectively, than something else.
  10917.  
  10918.         22.u   Implementation Note:  If an accessibility Legality Rule is
  10919.         satisfied, then the corresponding run-time check (if any) cannot fail
  10920.         (and a reasonable implementation will not generate any checking code)
  10921.         unless access parameters or shared generic bodies are involved.
  10922.  
  10923.         22.v   Accessibility levels are defined in terms of the relations
  10924.         ``the same as'' and ``deeper than''.  To make the discussion more
  10925.         concrete, we can assign actual numbers to each level.  Here, we
  10926.         assume that library-level accessibility is level 0, and each level
  10927.         defined as ``deeper than'' is one level deeper.  Thus, a subprogram
  10928.         directly called from the environment task (such as the main
  10929.         subprogram) would be at level 1, and so on.
  10930.  
  10931.         22.w   Accessibility is not enforced at compile time for access
  10932.         parameters.  The ``obvious'' implementation of the run-time checks
  10933.         would be inefficient, and would involve distributed overhead;
  10934.         therefore, an efficient method is given below.  The ``obvious''
  10935.         implementation would be to pass the level of the caller at each
  10936.         subprogram call, task creation, etc.  This level would be incremented
  10937.         by 1 for each dynamically nested master.  An Accessibility_Check
  10938.         would be implemented as a simple comparison -- checking that X is not
  10939.         deeper than Y would involve checking that X <= Y.
  10940.  
  10941.         22.x   A more efficient method is based on passing static nesting
  10942.         levels (within constructs that correspond at run time to masters --
  10943.         packages don't count).  Whenever an access parameter is passed, an
  10944.         implicit extra parameter is passed with it.  The extra parameter
  10945.         represents (in an indirect way) the accessibility level of the
  10946.         anonymous access type, and, therefore, the level of the view denoted
  10947.         by a dereference of the access parameter.  This is analogous to the
  10948.         implicit ``Constrained'' bit associated with certain formal
  10949.         parameters of an unconstrained but definite composite subtype.  In
  10950.         this method, we avoid distributed overhead:  it is not necessary to
  10951.         pass any extra information to subprograms that have no access
  10952.         parameters.  For anything other than an access parameter and its
  10953.         anonymous type, the static nesting level is known at compile time,
  10954.         and is defined analogously to the RM9X definition of accessibility
  10955.         level (e.g. derived access types get their nesting level from their
  10956.         parent).  Checking ``not deeper than'' is a "<=" test on the levels.
  10957.  
  10958.         22.y   For each access parameter, the static depth passed depends on
  10959.         the actual, as follows:
  10960.          22.z  If the actual is an expression of a named access type,
  10961.                pass the static nesting level of that type.
  10962.  
  10963.          22.aa  If the actual is an allocator, pass the static nesting
  10964.                level of the caller, plus one.
  10965.  
  10966.          22.bb  If the actual is a reference to the Access attribute,
  10967.                pass the level of the view denoted by the prefix.
  10968.  
  10969.          22.cc  If the actual is a reference to the Unchecked_Access
  10970.                attribute, pass 0 (the library accessibility level).
  10971.  
  10972.          22.dd  If the actual is an access parameter, usually just pass
  10973.                along the level passed in.  However, if the static
  10974.                nesting level of the formal (access) parameter is greater
  10975.                than the static nesting level of the actual (access)
  10976.                parameter, the level to be passed is the minimum of the
  10977.                static nesting level of the access parameter and the
  10978.                actual level passed in.
  10979.  
  10980.         22.ee   For the Accessibility_Check associated with a type_conversion
  10981.         of an access parameter of a given subprogram to a named access type,
  10982.         if the target type is statically nested within the subprogram, do
  10983.         nothing; the check can't fail in this case.  Otherwise, check that
  10984.         the value passed in is <= the static nesting depth of the target
  10985.         type.  The other Accessibility_Checks are handled in a similar
  10986.         manner.
  10987.  
  10988.         22.ff   This method, using statically known values most of the time,
  10989.         is efficient, and, more importantly, avoids distributed overhead.
  10990.  
  10991.         22.gg   Discussion:  Examples of accessibility:
  10992.  
  10993. 22.hh       package body Lib_Unit is
  10994.                 type T is tagged ...;
  10995.                 type A0 is access all T;
  10996.                 Global: A0 := ...;
  10997.                 procedure P(X: T) is
  10998.                     Y: aliased T;
  10999.                     type A1 is access all T;
  11000.                     Ptr0: A0 := Global; -- OK.
  11001.                     Ptr1: A1 := X'Access; -- OK.
  11002.                 begin
  11003.                     Ptr1 := Y'Access; -- OK;
  11004.                     Ptr0 := A0(Ptr1); -- Illegal type conversion!
  11005.                     Ptr0 := X'Access; -- Illegal reference to Access attribute!
  11006.                     Ptr0 := Y'Access; -- Illegal reference to Access attribute!
  11007.                     Global := Ptr0; -- OK.
  11008.                 end P;
  11009.             end Lib_Unit;
  11010.  
  11011.         22.ii   The above illegal statements are illegal because the
  11012.         accessibility level of X and Y are statically deeper than the
  11013.         accessibility level of A0.  In every possible execution of any
  11014.         program including this library unit, if P is called, the
  11015.         accessibility level of X will be (dynamically) deeper than that of
  11016.         A0.  Note that the accessibility levels of X and Y are the same.
  11017.  
  11018.         22.jj   Here's an example involving access parameters:
  11019.  
  11020. 22.kk       procedure Main is
  11021.                 type Level_1_Type is access all Integer;
  11022.  
  11023. 22.ll           procedure P(X: access Integer) is
  11024.                     type Nested_Type is access all Integer;
  11025.                 begin
  11026.                     ... Nested_Type(X) ... -- (1)
  11027.                     ... Level_1_Type(X) ... -- (2)
  11028.                 end P;
  11029.  
  11030. 22.mm           procedure Q(X: access Integer) is
  11031.                     procedure Nested(X: access Integer) is
  11032.                     begin
  11033.                         P(X);
  11034.                     end Nested;
  11035.                 begin
  11036.                     Nested(X);
  11037.                 end Q;
  11038.  
  11039. 22.nn           procedure R is
  11040.                     Level_2: aliased Integer;
  11041.                 begin
  11042.                     Q(Level_2'Access); -- (3)
  11043.                 end R;
  11044.  
  11045. 22.oo           Level_1: aliased Integer;
  11046.             begin
  11047.                 Q(Level_1'Access); -- (4)
  11048.                 R;
  11049.             end Main;
  11050.  
  11051.         22.pp   The run-time Accessibility_Check at (1) can never fail, and
  11052.         no code should be generated to check it.  The check at (2) will fail
  11053.         when called from (3), but not when called from (4).
  11054.  
  11055.         22.qq   Within a type_declaration, the rules are checked in an
  11056.         assume-the-worst manner.  For example:
  11057.  
  11058. 22.rr       package P is
  11059.                 type Int_Ptr is access all Integer;
  11060.                 type Rec(D: access Integer) is limited private;
  11061.             private
  11062.                 type Rec_Ptr is access all Rec;
  11063.                 function F(X: Rec_Ptr) return Boolean;
  11064.                 function G(X: access Rec) return Boolean;
  11065.                 type Rec(D: access Integer) is
  11066.                     record
  11067.                         C1: Int_Ptr := Int_Ptr(D); -- Illegal!
  11068.                         C2: Rec_Ptr := Rec'Access; -- Illegal!
  11069.                         C3: Boolean := F(Rec'Access); -- Illegal!
  11070.                         C4: Boolean := G(Rec'Access);
  11071.                     end record;
  11072.             end P;
  11073.  
  11074.         22.ss   C1, C2, and C3 are all illegal, because one might declare an
  11075.         object of type Rec at a more deeply nested place than the declaration
  11076.         of the type.  C4 is legal, but the accessibility level of the object
  11077.         will be passed to function G, and constraint checks within G will
  11078.         prevent it from doing any evil deeds.
  11079.  
  11080.         22.tt   Note that we cannot defer the checks on C1, C2, and C3 until
  11081.         compile-time of the object creation, because that would cause
  11082.         violation of the privacy of private parts.  Furthermore, the problems
  11083.         might occur within a task or protected body, which the compiler can't
  11084.         see while compiling an object creation.
  11085.  
  11086. 23   The following attribute is defined for a prefix X that denotes an
  11087. aliased view of an object:
  11088.  
  11089. 24  X'Access
  11090.                 X'Access yields an access value that designates the object
  11091.                 denoted by X. The type of X'Access is an access-to-object
  11092.                 type, as determined by the expected type.  The expected type
  11093.                 shall be a general access type.  {Unchecked_Access attribute:
  11094.                 see also Access attribute} X shall denote an aliased view of
  11095.                 an object[, including possibly the current instance (see 8.6)
  11096.                 of a limited type within its definition, or a formal
  11097.                 parameter or generic formal object of a tagged type].
  11098.                 {94-4978.a} The view denoted by the prefix X shall satisfy
  11099.                 the following additional requirements, presuming the expected
  11100.                 type for X'Access is the general access type A:
  11101.  
  11102.                    25  If A is an access-to-variable type, then the view
  11103.                        shall be a variable; [on the other hand, if A is
  11104.                        an access-to-constant type, the view may be
  11105.                        either a constant or a variable.]
  11106.  
  11107.  25.a   Discussion:  The current instance of a limited type is
  11108.         considered a variable.
  11109.  
  11110.                    26  The view shall not be a subcomponent that depends
  11111.                        on discriminants of a variable whose nominal
  11112.                        subtype is unconstrained, unless this subtype is
  11113.                        indefinite, or the variable is aliased.
  11114.  
  11115.  26.a   Change:  Fixed this rule to match the rule for renaming (see 8.5.1,
  11116.         ``Object Renaming Declarations'').
  11117.  
  11118.  26.b   Discussion:  This restriction is intended to be similar to the
  11119.         restriction on renaming discriminant-dependent subcomponents.
  11120.  
  11121.  26.c   Reason:  This prevents references to subcomponents that might
  11122.         disappear or move or change constraints after creating the
  11123.         reference.
  11124.  
  11125.  26.d   Implementation Note:  There was some thought to making this
  11126.         restriction more stringent, roughly:  "X shall not denote a
  11127.         subcomponent of a variable with discriminant-dependent
  11128.         subcomponents, if the nominal subtype of the variable is an
  11129.         unconstrained definite subtype."  This was because in some
  11130.         implementations, it is not just the discriminant-dependent
  11131.         subcomponents that might move as the result of an assignment
  11132.         that changed the discriminants of the enclosing object.
  11133.         However, it was decided not to make this change because a
  11134.         reasonable implementation strategy was identified to avoid such
  11135.         problems, as follows:
  11136.  
  11137.          26.e  Place non-discriminant-dependent components with any
  11138.                aliased parts at offsets preceding any discriminant-
  11139.                dependent components in a discriminated record type with
  11140.                defaulted discriminants.
  11141.  
  11142.          26.f  Preallocate the maximum space for unconstrained
  11143.                discriminated variables with aliased subcomponents,
  11144.                rather than allocating the initial size and moving them
  11145.                to a larger (heap-resident) place if they grow as the
  11146.                result of an assignment.
  11147.  
  11148.  26.g   Note that for objects of a by-reference type, it is not an error
  11149.         for a programmer to take advantage of the fact that such objects
  11150.         are passed by reference.  Therefore, the above approach is also
  11151.         necessary for discriminated record types with components of a
  11152.         by-reference type.
  11153.  
  11154.  26.h   To make the above strategy work, it is important that a
  11155.         component of a derived type is defined to be discriminant-
  11156.         dependent if it is inherited and the parent subtype constraint
  11157.         is defined in terms of a discriminant of the derived type (see
  11158.         3.7).
  11159.  
  11160.                    27  If the designated type of A is tagged, then the
  11161.                        type of the view shall be covered by the
  11162.                        designated type; if A's designated type is not
  11163.                        tagged, then the type of the view shall be the
  11164.                        same, and either A's designated subtype shall
  11165.                        statically match the nominal subtype of the view,
  11166.                        or the designated subtype shall be discriminated
  11167.                        and unconstrained; {statically matching
  11168.                        [required]}
  11169.  
  11170.  27.a   Implementation Note:  This ensures that the dope for an aliased
  11171.         array object can always be stored contiguous with it, but need
  11172.         not be if its nominal subtype is constrained.
  11173.  
  11174.                    28  The accessibility level of the view shall not be
  11175.                        statically deeper than that of the access type A.
  11176.                        {94-4715.a} In addition to the places where
  11177.                        Legality Rules normally apply (see 12.3), this
  11178.                        rule applies also in the private part of an
  11179.                        instance of a generic unit.  {accessibility rule
  11180.                        [Access attribute]} {generic contract issue
  11181.                        [partial]}
  11182.  
  11183.  28.a   Ramification:  In an instance body, a run-time check applies.
  11184.  
  11185.  28.b   If A is an anonymous access type, then the view can never have a
  11186.         deeper accessibility level than A, except when X'Access is used
  11187.         to initialize an access discriminant of an object created by an
  11188.         allocator.  The latter case is illegal if the accessibility
  11189.         level of X is statically deeper than that of the access type of
  11190.         the allocator; a run-time check is needed in the case where the
  11191.         initial value comes from an access parameter.  {94-4715.a}
  11192.  
  11193.                 29   {Accessibility_Check [partial]} {check, language-defined
  11194.                 (Accessibility_Check)} {Program_Error (raised by failure of
  11195.                 run-time check)} A check is made that the accessibility level
  11196.                 of X is not deeper than that of the access type A.
  11197.                 {94-4715.a} If this check fails, Program_Error is raised.
  11198.  
  11199.         29.a   Ramification:  The check is needed for access parameters and
  11200.         in instance bodies.
  11201.  
  11202.         29.b   Implementation Note:  This check requires that some indication
  11203.         of lifetime is passed as an implicit parameter along with access
  11204.         parameters.  No such requirement applies to access discriminants,
  11205.         since the checks associated with them are all compile-time checks.
  11206.  
  11207.                 30   {implicit subtype conversion [Access attribute]} If the
  11208.                 nominal subtype of X does not statically match the designated
  11209.                 subtype of A, a view conversion of X to the designated
  11210.                 subtype is evaluated (which might raise Constraint_Error --
  11211.                 see 4.6) and the value of X'Access designates that view.
  11212.  
  11213. 31   The following attribute is defined for a prefix P that denotes a
  11214. subprogram:
  11215.  
  11216. 32  P'Access
  11217.                 P'Access yields an access value that designates the
  11218.                 subprogram denoted by P. The type of P'Access is an
  11219.                 access-to-subprogram type (S), as determined by the expected
  11220.                 type.  {accessibility rule [Access attribute]} The
  11221.                 accessibility level of P shall not be statically deeper than
  11222.                 that of S.  {94-4715.a} {generic contract issue [partial]} In
  11223.                 addition to the places where Legality Rules normally apply
  11224.                 (see 12.3), this rule applies also in the private part of an
  11225.                 instance of a generic unit.  The profile of P shall be
  11226.                 subtype-conformant with the designated profile of S, and
  11227.                 shall not be Intrinsic.  {94-4774.b} {subtype conformance
  11228.                 (required)} If the subprogram denoted by P is declared within
  11229.                 a generic body, S shall be declared within the generic body.
  11230.                 {94-4692.a} {94-4702.a} {94-4706.a} {94-4708.a}
  11231.  
  11232. 32.a    Discussion:  The part about generic bodies is worded in terms of the
  11233.         denoted subprogram, not the denoted view; this implies that renaming
  11234.         is invisible to this part of the rule.  This rule is partly to
  11235.         prevent contract model problems with respect to the accessibility
  11236.         rules, and partly to ease shared-generic-body implementations, in
  11237.         which a subprogram declared in an instance needs to have a different
  11238.         calling convention from other subprograms with the same profile.
  11239.  
  11240. 32.b    Overload resolution ensures only that the profile is type-conformant.
  11241.         This rule specifies that subtype conformance is required (which also
  11242.         requires matching calling conventions).  P cannot denote an entry
  11243.         because access-to-subprogram types never have the entry calling
  11244.         convention.  P cannot denote an enumeration literal or an attribute
  11245.         function because these have intrinsic calling conventions.
  11246.  
  11247.  
  11248.      NOTES
  11249. 33   (81) The Unchecked_Access attribute yields the same result as the Access
  11250.      attribute for objects, but has fewer restrictions (see 13.10).  There
  11251.      are other predefined operations that yield access values:  an allocator
  11252.      can be used to create an object, and return an access value that
  11253.      designates it (see 4.8); evaluating the literal null yields a null
  11254.      access value that designates no entity at all (see 4.2).
  11255.  
  11256. 34   (82) {predefined operations [of an access type]} The predefined
  11257.      operations of an access type also include the assignment operation,
  11258.      qualification, and membership tests.  Explicit conversion is allowed
  11259.      between general access types with matching designated subtypes; explicit
  11260.      conversion is allowed between access-to-subprogram types with subtype
  11261.      conformant profiles (see 4.6).  {subtype conformance [partial]} Named
  11262.      access types have predefined equality operators; anonymous access types
  11263.      do not (see 4.5.2).
  11264.  
  11265.    34.a   Reason:  By not having equality operators for anonymous access
  11266.         types, we eliminate the need to specify exactly where the predefined
  11267.         operators for anonymous access types would be defined, as well as the
  11268.         need for an implementer to insert an implicit declaration for "=",
  11269.         etc. at the appropriate place in their symbol table.  Note that
  11270.         'Access and ".all" are defined, and ":=" is defined though useless
  11271.         since all instances are constant.  The literal null is also defined
  11272.         for the purposes of overload resolution, but is disallowed by a
  11273.         Legality Rule of this subclause.
  11274.  
  11275. 35   (83) The object or subprogram designated by an access value can be named
  11276.      with a dereference, either an explicit_dereference or an implicit_
  11277.      dereference.  See 4.1.
  11278.  
  11279. 36   (84) A call through the dereference of an access-to-subprogram value is
  11280.      never a dispatching call.
  11281.  
  11282.    36.a   Proof:  See 3.9.2.
  11283.  
  11284. 37   (85) {downward closure} {closure (downward)} The accessibility rules
  11285.      imply that it is not possible to use the Access attribute to implement
  11286.      ``downward closures'' -- that is, to pass a more-nested subprogram as a
  11287.      parameter to a less-nested subprogram, as might be desired for example
  11288.      for an iterator abstraction.  Instead, downward closures can be
  11289.      implemented using generic formal subprograms (see 12.6).  Note that
  11290.      Unchecked_Access is not allowed for subprograms.
  11291.  
  11292. 38   (86) Note that using an access-to-class-wide tagged type with a
  11293.      dispatching operation is a potentially more structured alternative to
  11294.      using an access-to-subprogram type.
  11295.  
  11296. 39   (87) An implementation may consider two access-to-subprogram values to
  11297.      be unequal, even though they designate the same subprogram.  This might
  11298.      be because one points directly to the subprogram, while the other points
  11299.      to a special prologue that performs an Elaboration_Check and then jumps
  11300.      to the subprogram.  See 4.5.2.
  11301.  
  11302.    39.a   Ramification:  If equality of access-to-subprogram values is
  11303.         important to the logic of a program, a reference to the Access
  11304.         attribute of a subprogram should be evaluated only once and stored in
  11305.         a global constant for subsequent use and equality comparison.
  11306.  
  11307.  
  11308.                                   Examples
  11309.  
  11310. 40   Example of use of the Access attribute:
  11311.  
  11312. 41  Martha : Person_Name := new Person(F);       -- see 3.10.1
  11313.     Cars   : array (1..2) of aliased Car;
  11314.        ...
  11315.     Martha.Vehicle := Cars(1)'Access;
  11316.     George.Vehicle := Cars(2)'Access;
  11317.  
  11318.  
  11319.                             Extensions to Ada 83
  11320.  
  11321.         41.a   {extensions to Ada 83} We no longer make things like 'Last and
  11322.         ".component" (basic) operations of an access type that need to be
  11323.         "declared" somewhere.  Instead, implicit dereference in a prefix
  11324.         takes care of them all.  This means that there should never be a case
  11325.         when X.all'Last is legal while X'Last is not.  See AI-00154.
  11326.  
  11327.  
  11328.  
  11329. 3.11 Declarative Parts
  11330.  
  11331. 1   [A declarative_part contains declarative_items (possibly none).]
  11332.  
  11333.  
  11334.                                    Syntax
  11335.  
  11336. 2   declarative_part ::= {declarative_item}
  11337.  
  11338. 3   declarative_item ::=
  11339.         basic_declarative_item | body
  11340.  
  11341. 4   basic_declarative_item ::=
  11342.         basic_declaration | representation_clause | use_clause
  11343.  
  11344. 5   body ::= proper_body | body_stub
  11345.  
  11346. 6   proper_body ::=
  11347.         subprogram_body | package_body | task_body | protected_body
  11348.  
  11349.  
  11350.                               Dynamic Semantics
  11351.  
  11352. 7   {elaboration [declarative_part]} The elaboration of a declarative_part
  11353. consists of the elaboration of the declarative_items, if any, in the order in
  11354. which they are given in the declarative_part.
  11355.  
  11356. 8   {elaborated} An elaborable construct is in the elaborated state after the
  11357. normal completion of its elaboration.  Prior to that, it is not yet
  11358. elaborated.
  11359.         8.a   Ramification:  The elaborated state is only important for
  11360.         bodies; certain uses of a body raise an exception if the body is not
  11361.         yet elaborated.
  11362.  
  11363.         8.b   Note that "prior" implies before the start of elaboration, as
  11364.         well as during elaboration.
  11365.  
  11366.         8.c   The use of the term "normal completion" implies that if the
  11367.         elaboration propagates an exception or is aborted, the declaration is
  11368.         not elaborated.  RM83 missed the aborted case.
  11369.  
  11370. 9   {Elaboration_Check [partial]} {check, language-defined (Elaboration_
  11371. Check)} For a construct that attempts to use a body, a check (Elaboration_
  11372. Check) is performed, as follows:
  11373.  
  11374.    10  For a call to a (non-protected) subprogram that has an explicit
  11375.        body, a check is made that the subprogram_body is already
  11376.        elaborated.  This check and the evaluations of any actual
  11377.        parameters of the call are done in an arbitrary order.
  11378.  
  11379.  10.a   Discussion:  AI-00180 specifies that there is no elaboration
  11380.         check for a subprogram defined by a pragma Interface (or
  11381.         equivalently, pragma Import).  AI-00430 specifies that there is
  11382.         no elaboration check for an enumeration literal.  AI-00406
  11383.         specifies that the evaluation of parameters and the elaboration
  11384.         check occur in an arbitrary order.  AI-00406 applies to generic
  11385.         instantiation as well (see below).
  11386.  
  11387.    11  For a call to a protected operation of a protected type (that has
  11388.        a body -- no check is performed if a pragma Import applies to the
  11389.        protected type), a check is made that the protected_body is
  11390.        already elaborated.  This check and the evaluations of any actual
  11391.        parameters of the call are done in an arbitrary order.
  11392.  
  11393.  11.a   Discussion:  A protected type has only one elaboration ``bit,''
  11394.         rather than one for each operation, because one call may result
  11395.         in evaluating the barriers of other entries, and because there
  11396.         are no elaborable declarations between the bodies of the
  11397.         operations.  In fact, the elaboration of a protected_body does
  11398.         not elaborate the enclosed bodies, since they are not considered
  11399.         independently elaborable.
  11400.  
  11401.  11.b   Note that there is no elaboration check when calling a task
  11402.         entry.  Task entry calls are permitted even before the
  11403.         associated task_body has been seen.  Such calls are simply
  11404.         queued until the task is activated and reaches a corresponding
  11405.         accept_statement.  We considered a similar rule for protected
  11406.         entries -- simply queuing all calls until the protected_body was
  11407.         seen, but felt it was not worth the possible implementation
  11408.         overhead, particularly given that there might be multiple
  11409.         instances of the protected type.
  11410.  
  11411.    12  For the activation of a task, a check is made by the activator
  11412.        that the task_body is already elaborated.  If two or more tasks
  11413.        are being activated together (see 9.2), as the result of the
  11414.        elaboration of a declarative_part or the initialization for the
  11415.        object created by an allocator, this check is done for all of
  11416.        them before activating any of them.
  11417.  
  11418.         12.a   Reason:  As specified by AI-00149, the check is done by
  11419.         the activator, rather than by the task itself.  If it were done
  11420.         by the task itself, it would be turned into a Tasking_Error in
  11421.         the activator, and the other tasks would still be activated.
  11422.  
  11423.    13  For the instantiation of a generic unit that has a body, a check
  11424.        is made that this body is already elaborated.  This check and the
  11425.        evaluation of any explicit_generic_actual_parameters of the
  11426.        instantiation are done in an arbitrary order.
  11427.  
  11428. 14   {Program_Error (raised by failure of run-time check)} The exception
  11429. Program_Error is raised if any of these checks fails.
  11430.  
  11431.  
  11432.                             Extensions to Ada 83
  11433.  
  11434.         14.a   {extensions to Ada 83} The syntax for declarative_part is
  11435.         modified to remove the ordering restrictions of Ada 83; that is, the
  11436.         distinction between basic_declarative_items and later_declarative_
  11437.         items within declarative_parts is removed.  This means that things
  11438.         like use_clauses and variable_declarations can be freely intermixed
  11439.         with things like bodies.
  11440.  
  11441.         14.b   The syntax rule for proper_body now allows a protected_body,
  11442.         and the rules for elaboration checks now cover calls on protected
  11443.         operations.
  11444.  
  11445.                          Wording Changes From Ada 83
  11446.  
  11447.         14.c   The syntax rule for later_declarative_item is removed; the
  11448.         syntax rule for declarative_item is new.
  11449.  
  11450.         14.d   RM83 defines ``elaborated'' and ``not yet elaborated'' for
  11451.         declarative_items here, and for other things in 3.1, ``Declara-
  11452.         tions''.  That's no longer necessary, since these terms are fully
  11453.         defined in 3.1.
  11454.  
  11455.         14.e   In RM83, all uses of declarative_part are optional (except for
  11456.         the one in block_statement with a declare) which is sort of strange,
  11457.         since a declarative_part can be empty, according to the syntax.  That
  11458.         is, declarative_parts are sort of ``doubly optional''.  In Ada 9X,
  11459.         these declarative_parts are always required (but can still be empty).
  11460.         To simplify description, we go further and say (see 5.6, ``Block
  11461.         Statements'') that a block_statement without an explicit declarative_
  11462.         part is equivalent to one with an empty one.
  11463.  
  11464.  
  11465.  
  11466. 3.11.1 Completions of Declarations
  11467.  
  11468. 1   Declarations sometimes come in two parts.  {requires a completion} A
  11469. declaration that requires a second part is said to require completion.
  11470. {completion (compile-time concept)} The second part is called the completion
  11471. of the declaration (and of the entity declared), and is either another
  11472. declaration, a body, or a pragma.
  11473.  
  11474.         1.a   Discussion:  Throughout the RM9X, there are rules about
  11475.         completions that define the following:
  11476.  
  11477.           1.b  Which declarations require a corresponding completion.
  11478.  
  11479.           1.c  Which constructs can only serve as the completion of a
  11480.                declaration.
  11481.  
  11482.           1.d  Where the completion of a declaration is allowed to be.
  11483.  
  11484.           1.e  What kinds of completions are allowed to correspond to
  11485.                each kind of declaration that allows one.
  11486.  
  11487.         1.f   Don't confuse this compile-time concept with the run-time
  11488.         concept of completion defined in 7.6.1.
  11489.  
  11490.         1.g   Note that the declaration of a private type (if limited) can be
  11491.         completed with the declaration of a task type, which is then
  11492.         completed with a body.  Thus, a declaration can actually come in
  11493.         three parts.
  11494.  
  11495.  
  11496.                             Name Resolution Rules
  11497.  
  11498. 2   A construct that can be a completion is interpreted as the completion of
  11499. a prior declaration only if:
  11500.  
  11501.     3  The declaration and the completion occur immediately within the
  11502.        same declarative region;
  11503.  
  11504.     4  The defining name or defining_program_unit_name in the completion
  11505.        is the same as in the declaration, or in the case of a pragma,
  11506.        the pragma applies to the declaration;
  11507.  
  11508.     5  If the declaration is overloadable, then the completion either
  11509.        has a type-conformant profile, or is a pragma.  {type conformance
  11510.        (required)}
  11511.  
  11512.  
  11513.                                Legality Rules
  11514.  
  11515. 6   An implicit declaration shall not have a completion.  {requires a
  11516. completion [distributed]} For any explicit declaration that is specified to
  11517. require completion, there shall be a corresponding explicit completion.
  11518.  
  11519.         6.a   Discussion:  The implicit declarations of predefined operators
  11520.         are not allowed to have a completion.  Enumeration literals, although
  11521.         they are subprograms, are not allowed to have a corresponding
  11522.         subprogram_body.  That's because the completion rules are described
  11523.         in terms of constructs (subprogram_declarations) and not entities
  11524.         (subprograms).  When a completion is required, it has to be explicit;
  11525.         the implicit null package_body that Section 7 talks about cannot
  11526.         serve as the completion of a package_declaration if a completion is
  11527.         required.
  11528.  
  11529. 7   At most one completion is allowed for a given declaration.  Additional
  11530. requirements on completions appear where each kind of completion is defined.
  11531.  
  11532.         7.a   Ramification:  A subunit is not a completion; the stub is.
  11533.  
  11534.         7.b   If the completion of a declaration is also a declaration, then
  11535.         that declaration might have a completion, too.  For example, a
  11536.         limited private type can be completed with a task type, which can
  11537.         then be completed with a task body.  This is not a violation of the
  11538.         ``at most one completion'' rule.
  11539.  
  11540. 8   {completely defined} A type is completely defined at a place that is
  11541. after its full type definition (if it has one) and after all of its
  11542. subcomponent types are completely defined.  A type shall be completely
  11543. defined before it is frozen (see 13.14 and 7.3).
  11544.  
  11545.         8.a   Change:  Rule moved here from 13.14, ``Freezing Rules'', as per
  11546.         WG9 resolution.
  11547.  
  11548.         8.b   Reason:  Index types are always completely defined -- no need
  11549.         to mention them.  There is no way for a completely defined type to
  11550.         depend on the value of a (still) deferred constant.
  11551.  
  11552.  
  11553.      NOTES
  11554. 9    (88) Completions are in principle allowed for any kind of explicit
  11555.      declaration.  However, for some kinds of declaration, the only allowed
  11556.      completion is a pragma Import, and implementations are not required to
  11557.      support pragma Import for every kind of entity.
  11558.    9.a   Discussion:  In fact, we expect that implementations will not
  11559.         support pragma Import of things like types -- it's hard to even
  11560.         define the semantics of what it would mean.  Therefore, in practice,
  11561.         not every explicit declaration can have a completion.  In any case,
  11562.         if an implementation chooses to support pragma Import for, say,
  11563.         types, it can place whatever restrictions on the feature it wants to.
  11564.         For example, it might want the pragma to be a freezing point for the
  11565.         type.
  11566.  
  11567. 10   (89) There are rules that prevent premature uses of declarations that
  11568.      have a corresponding completion.  The Elaboration_Checks of 3.11 prevent
  11569.      such uses at run time for subprograms, protected operations, tasks, and
  11570.      generic units.  The rules of 13.14, ``Freezing Rules'' prevent, at
  11571.      compile time, premature uses of other entities such as private types and
  11572.      deferred constants.
  11573.  
  11574.  
  11575.                          Wording Changes From Ada 83
  11576.  
  11577.         10.a   This subclause is new.  It is intended to cover all kinds of
  11578.         completions of declarations, be they a body for a spec, a full type
  11579.         for an incomplete or private type, a full constant declaration for a
  11580.         deferred constant declaration, or a pragma Import for any kind of
  11581.         entity.
  11582.  
  11583.  
  11584.  
  11585.                       Section 4: Names and Expressions
  11586.  
  11587.  
  11588. 1   [The rules applicable to the different forms of name and expression, and
  11589. to their evaluation, are given in this section.]
  11590.  
  11591.  
  11592.  
  11593. 4.1 Names
  11594.  
  11595. 1   [Names can denote declared entities, whether declared explicitly or
  11596. implicitly (see 3.1).  Names can also denote objects or subprograms
  11597. designated by access values; the results of type_conversions or function_
  11598. calls; subcomponents and slices of objects and values; protected subprograms,
  11599. single entries, entry families, and entries in families of entries.  Finally,
  11600. names can denote attributes of any of the foregoing.]
  11601.  
  11602.  
  11603.                                    Syntax
  11604.  
  11605. 2   name ::=
  11606.          direct_name                | explicit_dereference
  11607.        | indexed_component          | slice
  11608.        | selected_component         | attribute_reference
  11609.        | type_conversion            | function_call
  11610.        | character_literal
  11611.  
  11612. 3   direct_name ::= identifier | operator_symbol
  11613.  
  11614.         3.a   Discussion:  character_literal is no longer a direct_name.
  11615.         character_literals are usable even when the corresponding
  11616.         enumeration_type_declaration is not visible.  See 4.2.
  11617.  
  11618. 4   prefix ::= name | implicit_dereference
  11619.  
  11620. 5   explicit_dereference ::= name.all
  11621.  
  11622. 6   implicit_dereference ::= name
  11623.  
  11624.  
  11625. 7   [Certain forms of name (indexed_components, selected_components, slices,
  11626. and attributes) include a prefix that is either itself a name that denotes
  11627. some related entity, or an implicit_dereference of an access value that
  11628. designates some related entity.]
  11629.  
  11630.  
  11631.                             Name Resolution Rules
  11632.  
  11633. 8   {dereference} {expected type [dereference name]} The name in a
  11634. dereference (either an implicit_dereference or an explicit_dereference) is
  11635. expected to be of any access type.
  11636.  
  11637.  
  11638.                               Static Semantics
  11639.  
  11640. 9   {nominal subtype [associated with a dereference]} If the type of the name
  11641. in a dereference is some access-to-object type T, then the dereference
  11642. denotes a view of an object, the nominal subtype of the view being the
  11643. designated subtype of T.
  11644.  
  11645.         9.a   Ramification:  If the value of the name is the result of an
  11646.         access type conversion, the dereference denotes a view created as
  11647.         part of the conversion.  The nominal subtype of the view is not
  11648.         necessarily the same as that used to create the designated object.
  11649.         See 4.6.
  11650.  
  11651.         9.b   To be honest:  {nominal subtype [of a name]} We sometimes refer
  11652.         to the nominal subtype of a particular kind of name rather than the
  11653.         nominal subtype of the view denoted by the name (presuming the name
  11654.         denotes a view of an object).  These two uses of nominal subtype are
  11655.         intended to mean the same thing.
  11656.  
  11657. 10   {profile [associated with a dereference]} If the type of the name in a
  11658. dereference is some access-to-subprogram type S, then the dereference denotes
  11659. a view of a subprogram, the profile of the view being the designated profile
  11660. of S.
  11661.  
  11662.         10.a   Ramification:  This means that the formal parameter names and
  11663.         default expressions to be used in a call whose name or prefix is a
  11664.         dereference are those of the designated profile, which need not be
  11665.         the same as those of the subprogram designated by the access value,
  11666.         since 'Access requires only subtype conformance, not full
  11667.         conformance.
  11668.  
  11669.  
  11670.                               Dynamic Semantics
  11671.  
  11672. 11   {evaluation [name]} The evaluation of a name determines the entity
  11673. denoted by the name.  This evaluation has no other effect for a name that is
  11674. a direct_name or a character_literal.
  11675.  
  11676. 12   {evaluation [name that has a prefix]} [The evaluation of a name that has
  11677. a prefix includes the evaluation of the prefix.]  {evaluation [prefix]} The
  11678. evaluation of a prefix consists of the evaluation of the name or the
  11679. implicit_dereference.  The prefix denotes the entity denoted by the name or
  11680. the implicit_dereference.
  11681.  
  11682. 13   {evaluation [dereference]} The evaluation of a dereference consists of
  11683. the evaluation of the name and the determination of the object or subprogram
  11684. that is designated by the value of the name.  {Access_Check [partial]}
  11685. {check, language-defined (Access_Check)} A check is made that the value of
  11686. the name is not the null access value.  {Constraint_Error (raised by failure
  11687. of run-time check)} Constraint_Error is raised if this check fails.  The
  11688. dereference denotes the object or subprogram designated by the value of the
  11689. name.
  11690.  
  11691.  
  11692.                                   Examples
  11693.  
  11694. 14   Examples of direct names:
  11695.  
  11696. 15
  11697.     Pi             -- the direct name of a number                  (see 3.3.2)
  11698.     Limit          -- the direct name of a constant                (see 3.3.1)
  11699.     Count          -- the direct name of a scalar variable         (see 3.3.1)
  11700.     Board          -- the direct name of an array variable         (see 3.6.1)
  11701.     Matrix         -- the direct name of a type                    (see 3.6)
  11702.     Random         -- the direct name of a function                (see 6.1)
  11703.     Error          -- the direct name of an exception              (see 11.1)
  11704.  
  11705. 16   Examples of dereferences:
  11706.  
  11707. 17
  11708.     Next_Car.all         --  explicit dereference denoting the object designate\
  11709. d by
  11710.                          --  the access variable Next_Car (see 3.10.1)
  11711.     Next_Car.Owner       --  selected component with implicit dereference;
  11712.                          --  same as Next_Car.all.Owner
  11713.  
  11714.  
  11715.                             Extensions to Ada 83
  11716.  
  11717.         17.a   {extensions to Ada 83} Type conversions and function calls are
  11718.         now considered names that denote the result of the operation.  In the
  11719.         case of a type conversion used as an actual parameter or that is of a
  11720.         tagged type, the type conversion is considered a variable if the
  11721.         operand is a variable.  This simplifies the description of
  11722.         "parameters of the form of a type conversion" as well as better
  11723.         supporting an important OOP paradigm that requires the combination of
  11724.         a conversion from a class-wide type to some specific type followed
  11725.         immediately by component selection.  Function calls are considered
  11726.         names so that a type conversion of a function call and the function
  11727.         call itself are treated equivalently in the grammar.  A function call
  11728.         is considered the name of a constant, and can be used anywhere such a
  11729.         name is permitted.  See 6.5.
  11730.  
  11731.         17.b   Type conversions of a tagged type are permitted anywhere their
  11732.         operand is permitted.  That is, if the operand is a variable, then
  11733.         the type conversion can appear on the left-hand side of an
  11734.         assignment_statement.  If the operand is an object, then the type
  11735.         conversion can appear in an object renaming or as a prefix.  See 4.6.
  11736.  
  11737.                          Wording Changes From Ada 83
  11738.  
  11739.         17.c   Everything of the general syntactic form name(...) is now
  11740.         syntactically a name.  In any realistic parser, this would be a
  11741.         necessity since distinguishing among the various name(...) constructs
  11742.         inevitably requires name resolution.  In cases where the construct
  11743.         yields a value rather than an object, the name denotes the value
  11744.         rather than an object.  Names already denote values in Ada 83 with
  11745.         named numbers, components of the result of a function call, etc.
  11746.         This is partly just a wording change, and partly an extension of
  11747.         functionality (see Extensions heading above).
  11748.  
  11749.         17.d   The syntax rule for direct_name is new.  It is used in places
  11750.         where direct visibility is required.  It's kind of like Ada 83's
  11751.         simple_name, but simple_name applied to both direct visibility and
  11752.         visibility by selection, and furthermore, it didn't work right for
  11753.         operator_symbols.  The syntax rule for simple_name is removed, since
  11754.         its use is covered by a combination of direct_name and selector_name.
  11755.         The syntactic categories direct_name and selector_name are similar;
  11756.         it's mainly the visibility rules that distinguish the two.  The
  11757.         introduction of direct_name requires the insertion of one new
  11758.         explicit textual rule: to forbid statement_identifiers from being
  11759.         operator_symbols.  This is the only case where the explicit rule is
  11760.         needed, because this is the only case where the declaration of the
  11761.         entity is implicit.  For example, there is no need to syntactically
  11762.         forbid (say) ``X: "Rem";'', because it is impossible to declare a
  11763.         type whose name is an operator_symbol in the first place.
  11764.  
  11765.         17.e   The syntax rules for explicit_dereference and implicit_
  11766.         dereference are new; this makes other rules simpler, since
  11767.         dereferencing an access value has substantially different semantics
  11768.         from selected_components.  We also use name instead of prefix in the
  11769.         explicit_dereference rule since that seems clearer.  Note that these
  11770.         rules rely on the fact that function calls are now names, so we don't
  11771.         need to use prefix to allow functions calls in front of .all.
  11772.  
  11773.         17.f   Discussion:  Actually, it would be reasonable to allow any
  11774.         primary in front of .all, since only the value is needed, but that
  11775.         would be a bit radical.
  11776.  
  11777.         17.g   We no longer use the term appropriate for a type since we now
  11778.         describe the semantics of a prefix in terms of implicit dereference.
  11779.  
  11780.  
  11781.  
  11782. 4.1.1 Indexed Components
  11783.  
  11784. 1   [An indexed_component denotes either a component of an array or an entry
  11785. in a family of entries.  {array indexing: see indexed_component} ]
  11786.  
  11787.  
  11788.                                    Syntax
  11789.  
  11790. 2   indexed_component ::= prefix(expression {, expression})
  11791.  
  11792.  
  11793.                             Name Resolution Rules
  11794.  
  11795. 3   The prefix of an indexed_component with a given number of expressions
  11796. shall resolve to denote an array (after any implicit dereference) with the
  11797. corresponding number of index positions, or shall resolve to denote an entry
  11798. family of a task or protected object (in which case there shall be only one
  11799. expression).
  11800.  
  11801. 4   {expected type [indexed_component expression]} The expected type for each
  11802. expression is the corresponding index type.
  11803.  
  11804.  
  11805.                               Static Semantics
  11806.  
  11807. 5   When the prefix denotes an array, the indexed_component denotes the
  11808. component of the array with the specified index value(s).  {nominal subtype
  11809. [associated with an indexed_component]} The nominal subtype of the indexed_
  11810. component is the component subtype of the array type.
  11811.  
  11812.         5.a   Ramification:  In the case of an array whose components are
  11813.         aliased, and of an unconstrained discriminated subtype, the
  11814.         components are constrained even though their nominal subtype is
  11815.         unconstrained.  (This is because all aliased discriminated objects
  11816.         are constrained.  See 3.10.2.)  In all other cases, an array
  11817.         component is constrained if and only if its nominal subtype is
  11818.         constrained.
  11819.  
  11820. 6   When the prefix denotes an entry family, the indexed_component denotes
  11821. the individual entry of the entry family with the specified index value.
  11822.  
  11823.  
  11824.                               Dynamic Semantics
  11825.  
  11826. 7   {evaluation [indexed_component]} For the evaluation of an indexed_
  11827. component, the prefix and the expressions are evaluated in an arbitrary
  11828. order.  The value of each expression is converted to the corresponding index
  11829. type.  {implicit subtype conversion [array index]} {Index_Check [partial]}
  11830. {check, language-defined (Index_Check)} A check is made that each index value
  11831. belongs to the corresponding index range of the array or entry family denoted
  11832. by the prefix.  {Constraint_Error (raised by failure of run-time check)}
  11833. Constraint_Error is raised if this check fails.
  11834.  
  11835.  
  11836.                                   Examples
  11837.  
  11838. 8   Examples of indexed components:
  11839.  
  11840. 9
  11841.      My_Schedule(Sat)     --  a component of a one-dimensional array  (see 3.6.\
  11842. 1)
  11843.      Page(10)             --  a component of a one-dimensional array  (see 3.6)
  11844.      Board(M, J + 1)      --  a component of a two-dimensional array  (see 3.6.\
  11845. 1)
  11846.      Page(10)(20)         --  a component of a component              (see 3.6)
  11847.      Request(Medium)      --  an entry in a family of entries         (see 9.1)
  11848.      Next_Frame(L)(M, N)  --  a component of a function call          (see 6.1)
  11849.  
  11850.  
  11851.      NOTES
  11852. 10   (1) Notes on the examples:  Distinct notations are used for components
  11853.      of multidimensional arrays (such as Board) and arrays of arrays (such as
  11854.      Page).  The components of an array of arrays are arrays and can
  11855.      therefore be indexed.  Thus Page(10)(20) denotes the 20th component of
  11856.      Page(10).  In the last example Next_Frame(L) is a function call
  11857.      returning an access value that designates a two-dimensional array.
  11858.  
  11859.  
  11860.  
  11861. 4.1.2 Slices
  11862.  
  11863. 1   [{array slice} A slice denotes a one-dimensional array formed by a
  11864. sequence of consecutive components of a one-dimensional array.  A slice of a
  11865. variable is a variable; a slice of a constant is a constant;] a slice of a
  11866. value is a value.
  11867.  
  11868.  
  11869.                                    Syntax
  11870.  
  11871. 2   slice ::= prefix(discrete_range)
  11872.  
  11873.  
  11874.                             Name Resolution Rules
  11875.  
  11876. 3   The prefix of a slice shall resolve to denote a one-dimensional array
  11877. (after any implicit dereference).
  11878.  
  11879. 4   {expected type [slice discrete_range]} The expected type for the
  11880. discrete_range of a slice is the index type of the array type.
  11881.  
  11882.  
  11883.                               Static Semantics
  11884.  
  11885. 5   A slice denotes a one-dimensional array formed by the sequence of
  11886. consecutive components of the array denoted by the prefix, corresponding to
  11887. the range of values of the index given by the discrete_range.
  11888.  
  11889. 6   The type of the slice is that of the prefix.  Its bounds are those
  11890. defined by the discrete_range.
  11891.  
  11892.  
  11893.                               Dynamic Semantics
  11894.  
  11895. 7   {evaluation [slice]} For the evaluation of a slice, the prefix and the
  11896. discrete_range are evaluated in an arbitrary order.  {Index_Check [partial]}
  11897. {check, language-defined (Index_Check)} {null slice} If the slice is not a
  11898. null slice (a slice where the discrete_range is a null range), then a check
  11899. is made that the bounds of the discrete_range belong to the index range of
  11900. the array denoted by the prefix.  {Constraint_Error (raised by failure of
  11901. run-time check)} Constraint_Error is raised if this check fails.
  11902.  
  11903.  
  11904.      NOTES
  11905. 8    (2) A slice is not permitted as the prefix of an Access attribute_
  11906.      reference, even if the components or the array as a whole are aliased.
  11907.      See 3.10.2.
  11908.  
  11909.    8.a   Proof:  Slices are not aliased, by 3.10, ``Access Types''.
  11910.  
  11911.    8.b   Reason:  This is to ease implementation of general-access-to-array.
  11912.         If slices were aliased, implementations would need to store array
  11913.         dope with the access values, which is not always desirable given
  11914.         access-to-incomplete types completed in a package body.
  11915.  
  11916. 9    (3) For a one-dimensional array A, the slice A(N .. N) denotes an array
  11917.      that has only one component; its type is the type of A. On the other
  11918.      hand, A(N) denotes a component of the array A and has the corresponding
  11919.      component type.
  11920.  
  11921.  
  11922.                                   Examples
  11923.  
  11924. 10   Examples of slices:
  11925.  
  11926. 11
  11927.       Stars(1 .. 15)        --  a slice of 15 characters                  (see \
  11928. 3.6.3)
  11929.       Page(10 .. 10 + Size) --  a slice of 1 + Size components            (see \
  11930. 3.6)
  11931.       Page(L)(A .. B)       --  a slice of the array Page(L)              (see \
  11932. 3.6)
  11933.       Stars(1 .. 0)         --  a null slice                              (see \
  11934. 3.6.3)
  11935.       My_Schedule(Weekday)  --  bounds given by subtype                   (see \
  11936. 3.6.1 and 3.5.1)
  11937.       Stars(5 .. 15)(K)     --  same as Stars(K)                          (see \
  11938. 3.6.3)
  11939.                             --  provided that K is in 5 .. 15
  11940.  
  11941.  
  11942.  
  11943. 4.1.3 Selected Components
  11944.  
  11945. 1   [Selected_components are used to denote components (including
  11946. discriminants), entries, entry families, and protected subprograms; they are
  11947. also used as expanded names as described below.  {dot selection: see
  11948. selected_component}]
  11949.  
  11950.  
  11951.                                    Syntax
  11952.  
  11953. 2   selected_component ::= prefix . selector_name
  11954.  
  11955. 3   selector_name ::= identifier | character_literal | operator_symbol
  11956.  
  11957.  
  11958.                             Name Resolution Rules
  11959.  
  11960. 4   {expanded name} A selected_component is called an expanded name if,
  11961. according to the visibility rules, at least one possible interpretation of
  11962. its prefix denotes a package or an enclosing named construct (directly, not
  11963. through a subprogram_renaming_declaration or generic_renaming_declaration).
  11964.  
  11965.         4.a   Discussion:  See AI-00187.
  11966.  
  11967. 5   A selected_component that is not an expanded name shall resolve to denote
  11968. one of the following:
  11969.  
  11970.         5.a   Ramification:  If the prefix of a selected_component denotes an
  11971.         enclosing named construct, then the selected_component is interpreted
  11972.         only as an expanded name, even if the named construct is a function
  11973.         that could be called without parameters.
  11974.  
  11975.     6  A component [(including a discriminant)]:
  11976.  
  11977.        7   The prefix shall resolve to denote an object or value of some
  11978.        non-array composite type (after any implicit dereference).
  11979.        {94-4493.c} The selector_name shall resolve to denote a
  11980.        discriminant_specification of the type, or, unless the type is a
  11981.        protected type, a component_declaration of the type.  The
  11982.        selected_component denotes the corresponding component of the
  11983.        object or value.
  11984.  
  11985.         7.a   Reason:  The components of a protected object cannot be
  11986.         named except by an expanded name, even from within the
  11987.         corresponding protected body.  The protected body may not
  11988.         reference the the private components of some arbitrary object of
  11989.         the protected type; the protected body may reference components
  11990.         of the current instance only (by an expanded name or a direct_
  11991.         name).
  11992.  
  11993.         7.b   Ramification:  Only the discriminants and components
  11994.         visible at the place of the selected_component can be selected,
  11995.         since a selector_name can only denote declarations that are
  11996.         visible (see 8.3).
  11997.  
  11998.     8  A single entry, an entry family, or a protected subprogram:
  11999.  
  12000.        9   The prefix shall resolve to denote an object or value of some
  12001.        task or protected type (after any implicit dereference).  The
  12002.        selector_name shall resolve to denote an entry_declaration or
  12003.        subprogram_declaration occurring (implicitly or explicitly)
  12004.        within the visible part of that type.  The selected_component
  12005.        denotes the corresponding entry, entry family, or protected
  12006.        subprogram.
  12007.  
  12008.         9.a   Reason:  This explicitly says ``visible part'' because
  12009.         even though the body has visibility on the private part, it
  12010.         cannot call the private operations of some arbitrary object of
  12011.         the task or protected type, only those of the current instance
  12012.         (and expanded name notation has to be used for that).
  12013.  
  12014. 10   An expanded name shall resolve to denote a declaration that occurs
  12015. immediately within a named declarative region, as follows:
  12016.  
  12017.    11  The prefix shall resolve to denote either a package [(including
  12018.        the current instance of a generic package, or a rename of a
  12019.        package)], or an enclosing named construct.
  12020.  
  12021.    12  The selector_name shall resolve to denote a declaration that
  12022.        occurs immediately within the declarative region of the package
  12023.        or enclosing construct [(the declaration shall be visible at the
  12024.        place of the expanded name -- see 8.3)].  The expanded name
  12025.        denotes that declaration.
  12026.  
  12027.  12.a   Ramification:  Hence, a library unit or subunit can use an
  12028.         expanded name to refer to the declarations within the private
  12029.         part of its parent unit, as well as to other children that have
  12030.         been mentioned in with_clauses.
  12031.  
  12032.    13  If the prefix does not denote a package, then it shall be a
  12033.        direct_name or an expanded name, and it shall resolve to denote a
  12034.        program unit (other than a package), the current instance of a
  12035.        type, a block_statement, a loop_statement, or an accept_statement
  12036.        (in the case of an accept_statement or entry_body, no family
  12037.        index is allowed); the expanded name shall occur within the
  12038.        declarative region of this construct.  Further, if this construct
  12039.        is a callable construct and the prefix denotes more than one such
  12040.        enclosing callable construct, then the expanded name is
  12041.        ambiguous, independently of the selector_name.
  12042.  
  12043.  
  12044.                               Dynamic Semantics
  12045.  
  12046. 14   {evaluation [selected_component]} The evaluation of a selected_component
  12047. includes the evaluation of the prefix.
  12048.  
  12049. 15   {Discriminant_Check [partial]} {check, language-defined (Discriminant_
  12050. Check)} For a selected_component that denotes a component of a variant, a
  12051. check is made that the values of the discriminants are such that the value or
  12052. object denoted by the prefix has this component.  {Constraint_Error (raised
  12053. by failure of run-time check)} {Constraint_Error (raised by failure of
  12054. run-time check)} The exception Constraint_Error is raised if this check
  12055. fails.
  12056.  
  12057.  
  12058.                                   Examples
  12059.  
  12060. 16   Examples of selected components:
  12061.  
  12062. 17
  12063.       Tomorrow.Month     --  a record component                             (se\
  12064. e 3.8)
  12065.       Next_Car.Owner     --  a record component                             (se\
  12066. e 3.10.1)
  12067.       Next_Car.Owner.Age --  a record component                             (se\
  12068. e 3.10.1)
  12069.                          --  the previous two lines involve implicit dereferenc\
  12070. es
  12071.       Writer.Unit        --  a record component (a discriminant)            (se\
  12072. e 3.8.1)
  12073.       Min_Cell(H).Value  --  a record component of the result               (se\
  12074. e 6.1)
  12075.                          --  of the function call Min_Cell(H)
  12076.       Control.Seize      --  an entry of a protected object                 (se\
  12077. e 9.4)
  12078.       Pool(K).Write      --  an entry of the task Pool(K)                   (se\
  12079. e 9.4)
  12080.  
  12081. 18   Examples of expanded names:
  12082.  
  12083. 19
  12084.       Key_Manager."<"      --  an operator of the visible part of a package (se\
  12085. e 7.3.1)
  12086.       Dot_Product.Sum      --  a variable declared in a function body       (se\
  12087. e 6.1)
  12088.       Buffer.Pool          --  a variable declared in a protected unit      (se\
  12089. e 9.11)
  12090.       Buffer.Read          --  an entry of a protected unit                 (se\
  12091. e 9.11)
  12092.       Swap.Temp            --  a variable declared in a block statement     (se\
  12093. e 5.6)
  12094.       Standard.Boolean     --  the name of a predefined type                (se\
  12095. e A.1)
  12096.  
  12097.  
  12098.                             Extensions to Ada 83
  12099.  
  12100.         19.a   {extensions to Ada 83} We now allow an expanded name to use a
  12101.         prefix that denotes a rename of a package, even if the selector is
  12102.         for an entity local to the body or private part of the package, so
  12103.         long as the entity is visible at the place of the reference.  This
  12104.         eliminates a preexisting anomaly where references in a package body
  12105.         may refer to declarations of its visible part but not those of its
  12106.         private part or body when the prefix is a rename of the package.
  12107.  
  12108.                          Wording Changes From Ada 83
  12109.  
  12110.         19.b   The syntax rule for selector_name is new.  It is used in
  12111.         places where visibility, but not necessarily direct visibility, is
  12112.         required.  See 4.1, ``Names'' for more information.
  12113.  
  12114.         19.c   The description of dereferencing an access type has been moved
  12115.         to 4.1, ``Names''; name.all is no longer considered a selected_
  12116.         component.
  12117.  
  12118.         19.d   The rules have been restated to be consistent with our new
  12119.         terminology, to accommodate class-wide types, etc.
  12120.  
  12121.  
  12122.  
  12123. 4.1.4 Attributes
  12124.  
  12125. 1   {attribute} [An attribute is a characteristic of an entity that can be
  12126. queried via an attribute_reference or a range_attribute_reference.]
  12127.  
  12128.  
  12129.                                    Syntax
  12130.  
  12131. 2   attribute_reference ::= prefix'attribute_designator
  12132.  
  12133. 3   attribute_designator ::=
  12134.         identifier[(static_expression)]
  12135.       | Access | Delta | Digits
  12136.  
  12137. 4   range_attribute_reference ::= prefix'range_attribute_designator
  12138.  
  12139. 5   range_attribute_designator ::= Range[(static_expression)]
  12140.  
  12141.  
  12142.                             Name Resolution Rules
  12143.  
  12144. 6   In an attribute_reference, if the attribute_designator is for an
  12145. attribute defined for (at least some) objects of an access type, then the
  12146. prefix is never interpreted as an implicit_dereference; otherwise (and for
  12147. all range_attribute_references), if the type of the name within the prefix is
  12148. of an access type, the prefix is interpreted as an implicit_dereference.
  12149. Similarly, if the attribute_designator is for an attribute defined for (at
  12150. least some) functions, then the prefix is never interpreted as a
  12151. parameterless function_call; otherwise (and for all range_attribute_
  12152. references), if the prefix consists of a name that denotes a function, it is
  12153. interpreted as a parameterless function_call.
  12154.  
  12155.         6.a   Discussion:  The first part of this rule is essentially a
  12156.         "preference" against implicit dereference, so that it is possible to
  12157.         ask for, say, 'Size of an access object, without automatically
  12158.         getting the size of the object designated by the access object.  This
  12159.         rule applies to 'Access, 'Unchecked_Access, 'Size, and 'Address, and
  12160.         any other attributes that are defined for at least some access
  12161.         objects.
  12162.  
  12163.         6.b   The second part of this rule implies that, for a parameterless
  12164.         function F, F'Address is the address of F, whereas F'Size is the size
  12165.         of the anonymous constant returned by F.
  12166.  
  12167.         6.c   We normally talk in terms of expected type or profile for name
  12168.         resolution rules, but we don't do this for attributes because certain
  12169.         attributes are legal independent of the type or the profile of the
  12170.         prefix.
  12171.  
  12172. 7   {expected type [attribute_designator expression]} {expected type [range_
  12173. attribute_designator expression]} The expression, if any, in an attribute_
  12174. designator or range_attribute_designator is expected to be of any integer
  12175. type.
  12176.                                Legality Rules
  12177.  
  12178. 8   The expression, if any, in an attribute_designator or range_attribute_
  12179. designator shall be static.
  12180.  
  12181.  
  12182.                               Static Semantics
  12183.  
  12184. 9   An attribute_reference denotes a value, an object, a subprogram, or some
  12185. other kind of program entity.
  12186.  
  12187.         9.a   Ramification:  The attributes defined by the language are
  12188.         summarized in Annex K. Implementations can define additional
  12189.         attributes.
  12190.  
  12191. 10   [A range_attribute_reference X'Range(N) is equivalent to the range
  12192. X'First(N) ..  X'Last(N), except that the prefix is only evaluated once.
  12193. Similarly, X'Range is equivalent to X'First .. X'Last, except that the prefix
  12194. is only evaluated once.]
  12195.  
  12196.  
  12197.                               Dynamic Semantics
  12198.  
  12199. 11   {evaluation [attribute_reference]} {evaluation [range_attribute_
  12200. reference]} The evaluation of an attribute_reference (or range_attribute_
  12201. reference) consists of the evaluation of the prefix.
  12202.  
  12203.  
  12204.                          Implementation Permissions
  12205.  
  12206. 12   An implementation may provide implementation-defined attributes; the
  12207. identifier for an implementation-defined attribute shall differ from those of
  12208. the language-defined attributes.
  12209.  
  12210.         12.a   Implementation defined:  Implementation-defined attributes.
  12211.  
  12212.         12.b   Ramification:  They cannot be reserved words because reserved
  12213.         words are not legal identifiers.
  12214.  
  12215.         12.c   The semantics of implementation-defined attributes, and any
  12216.         associated rules, are, of course, implementation defined.  For
  12217.         example, the implementation defines whether a given implementation-
  12218.         defined attribute can be used in a static expression.  {94-4539.b}
  12219.  
  12220.  
  12221.      NOTES
  12222. 13   (4) Attributes are defined throughout this International Standard, and
  12223.      are summarized in Annex K.
  12224.  
  12225. 14   (5) In general, the name in a prefix of an attribute_reference (or a
  12226.      range_attribute_reference) has to be resolved without using any context.
  12227.      However, in the case of the Access attribute, the expected type for the
  12228.      prefix has to be a single access type, and if it is an
  12229.      access-to-subprogram type (see 3.10.2) then the resolution of the name
  12230.      can use the fact that the profile of the callable entity denoted by the
  12231.      prefix has to be type conformant with the designated profile of the
  12232.      access type.  {type conformance (required)}
  12233.  
  12234.    14.a   Proof:  In the general case, there is no ``expected type'' for the
  12235.         prefix of an attribute_reference.  In the special case of 'Access,
  12236.         there is an ``expected profile'' for the prefix.
  12237.  
  12238.    14.b   Reason:  'Access is a special case, because without it, it would be
  12239.         very difficult to take 'Access of an overloaded subprogram.
  12240.  
  12241.  
  12242.                                   Examples
  12243.  
  12244. 15   Examples of attributes:
  12245.  
  12246. 16
  12247.     Color'First        -- minimum value of the enumeration type Color   (see 3.\
  12248. 5.1)
  12249.     Rainbow'Base'First -- same as Color'First                           (see 3.\
  12250. 5.1)
  12251.     Real'Digits        -- precision of the type Real                    (see 3.\
  12252. 5.7)
  12253.     Board'Last(2)      -- upper bound of the second dimension of Board  (see 3.\
  12254. 6.1)
  12255.     Board'Range(1)     -- index range of the first dimension of Board   (see 3.\
  12256. 6.1)
  12257.     Pool(K)'Terminated -- True if task Pool(K) is terminated            (see 9.\
  12258. 1)
  12259.     Date'Size          -- number of bits for records of type Date       (see 3.\
  12260. 8)
  12261.     Message'Address    -- address of the record variable Message        (see 3.\
  12262. 7.1)
  12263.  
  12264.  
  12265.                             Extensions to Ada 83
  12266.  
  12267.         16.a   {extensions to Ada 83} We now uniformly treat X'Range as
  12268.         X'First..X'Last, allowing its use with scalar subtypes.
  12269.  
  12270.         16.b   We allow any integer type in the static_expression of an
  12271.         attribute designator, not just a value of universal_integer.  The
  12272.         preference rules ensure upward compatibility.
  12273.  
  12274.                          Wording Changes From Ada 83
  12275.  
  12276.         16.c   We use the syntactic category attribute_reference rather than
  12277.         simply "attribute" to avoid confusing the name of something with the
  12278.         thing itself.
  12279.  
  12280.         16.d   The syntax rule for attribute_reference now uses identifier
  12281.         instead of simple_name, because attribute identifiers are not
  12282.         required to follow the normal visibility rules.
  12283.  
  12284.         16.e   We now separate attribute_reference from range_attribute_
  12285.         reference, and enumerate the reserved words that are legal attribute
  12286.         or range attribute designators.  We do this because identifier no
  12287.         longer includes reserved words.
  12288.  
  12289.         16.f   The Ada 9X name resolution rules are a bit more explicit than
  12290.         in Ada 83.  The Ada 83 rule said that the "meaning of the prefix of
  12291.         an attribute must be determinable independently of the attribute
  12292.         designator and independently of the fact that it is the prefix of an
  12293.         attribute."  That isn't quite right since the meaning even in Ada 83
  12294.         embodies whether or not the prefix is interpreted as a parameterless
  12295.         function call, and in Ada 9X, it also embodies whether or not the
  12296.         prefix is interpreted as an implicit_dereference.  So the attribute
  12297.         designator does make a difference -- just not much.
  12298.  
  12299.         16.g   Note however that if the attribute designator is Access, it
  12300.         makes a big difference in the interpretation of the prefix (see
  12301.         3.10.2).
  12302.  
  12303.  
  12304.  
  12305. 4.2 Literals
  12306.  
  12307. 1   [{literal} A literal represents a value literally, that is, by means of
  12308. notation suited to its kind.]  A literal is either a numeric_literal, a
  12309. character_literal, the literal null, or a string_literal.  {constant: see
  12310. also literal}
  12311.  
  12312.         1.a   Discussion:  An enumeration literal that is an identifier
  12313.         rather than a character_literal is not considered a literal in the
  12314.         above sense, because it involves no special notation ``suited to its
  12315.         kind.''  It might more properly be called an enumeration_identifier,
  12316.         except for historical reasons.
  12317.  
  12318.  
  12319.                             Name Resolution Rules
  12320.  
  12321. 2   {expected type [null literal]} The expected type for a literal null shall
  12322. be a single access type.
  12323.  
  12324.         2.a   Discussion:  This new wording ("expected type ... shall be a
  12325.         single ... type") replaces the old "shall be determinable" stuff.  It
  12326.         reflects an attempt to simplify and unify the description of the
  12327.         rules for resolving aggregates, literals, type conversions, etc.  See
  12328.         8.6, ``The Context of Overload Resolution'' for the details.
  12329.  
  12330. 3   {expected type [character_literal]} {expected profile [character_
  12331. literal]} For a name that consists of a character_literal, either its
  12332. expected type shall be a single character type, in which case it is
  12333. interpreted as a parameterless function_call that yields the corresponding
  12334. value of the character type, or its expected profile shall correspond to a
  12335. parameterless function with a character result type, in which case it is
  12336. interpreted as the name of the corresponding parameterless function declared
  12337. as part of the character type's definition (see 3.5.1).  In either case, the
  12338. character_literal denotes the enumeration_literal_specification.
  12339.  
  12340.         3.a   Discussion:  See 4.1.3 for the resolution rules for a selector_
  12341.         name that is a character_literal.
  12342.  
  12343. 4   {expected type [string_literal]} The expected type for a primary that is
  12344. a string_literal shall be a single string type.
  12345.  
  12346.  
  12347.                                Legality Rules
  12348.  
  12349. 5   A character_literal that is a name shall correspond to a defining_
  12350. character_literal of the expected type, or of the result type of the expected
  12351. profile.
  12352.  
  12353. 6   For each character of a string_literal with a given expected string type,
  12354. there shall be a corresponding defining_character_literal of the component
  12355. type of the expected string type.
  12356.  
  12357. 7   A literal null shall not be of an anonymous access type[, since such
  12358. types do not have a null value (see 3.10)].
  12359.  
  12360.         7.a   Reason:  This is a legality rule rather than an overloading
  12361.         rule, to simplify implementations.
  12362.  
  12363.  
  12364.                               Static Semantics
  12365.  
  12366. 8   An integer literal is of type universal_integer.  A real literal is of
  12367. type universal_real.
  12368.  
  12369.  
  12370.                               Dynamic Semantics
  12371.  
  12372. 9   {evaluation [numeric literal]} {evaluation [null literal]} {null access
  12373. value} {null pointer: see null access value} The evaluation of a numeric
  12374. literal, or the literal null, yields the represented value.
  12375.  
  12376. 10   {evaluation [string_literal]} The evaluation of a string_literal that is
  12377. a primary yields an array value containing the value of each character of the
  12378. sequence of characters of the string_literal, as defined in 2.6.  The bounds
  12379. of this array value are determined according to the rules for positional_
  12380. array_aggregates (see 4.3.3), except that for a null string literal, the
  12381. upper bound is the predecessor of the lower bound.
  12382.  
  12383. 11   {Range_Check [partial]} {check, language-defined (Range_Check)} For the
  12384. evaluation of a string_literal of type T, a check is made that the value of
  12385. each character of the string_literal belongs to the component subtype of T.
  12386. For the evaluation of a null string literal, a check is made that its lower
  12387. bound is greater than the lower bound of the base range of the index type.
  12388. {Constraint_Error (raised by failure of run-time check)} The exception
  12389. Constraint_Error is raised if either of these checks fails.
  12390.  
  12391.         11.a   Ramification:  The checks on the characters need not involve
  12392.         more than two checks altogether, since one need only check the
  12393.         characters of the string with the lowest and highest position numbers
  12394.         against the range of the component subtype.
  12395.  
  12396.  
  12397.      NOTES
  12398. 12   (6) Enumeration literals that are identifiers rather than character_
  12399.      literals follow the normal rules for identifiers when used in a name
  12400.      (see 4.1 and 4.1.3).  Character_literals used as selector_names follow
  12401.      the normal rules for expanded names (see 4.1.3).
  12402.  
  12403.  
  12404.                                   Examples
  12405.  
  12406. 13   Examples of literals:
  12407.  
  12408. 14
  12409.     3.14159_26536    --  a real literal
  12410.     1_345            --  an integer literal
  12411.     'A'              --  a character literal
  12412.     "Some Text"      --  a string literal
  12413.  
  12414.  
  12415.                         Incompatibilities With Ada 83
  12416.  
  12417.         14.a   {incompatibilities with Ada 83} Because character_literals are
  12418.         now treated like other literals, in that they are resolved using
  12419.         context rather than depending on direct visibility, additional
  12420.         qualification might be necessary when passing a character_literal to
  12421.         an overloaded subprogram.
  12422.  
  12423.                             Extensions to Ada 83
  12424.  
  12425.         14.b   {extensions to Ada 83} Character_literals are now treated
  12426.         analogously to null and string_literals, in that they are resolved
  12427.         using context, rather than their content; the declaration of the
  12428.         corresponding defining_character_literal need not be directly
  12429.         visible.
  12430.  
  12431.                          Wording Changes From Ada 83
  12432.  
  12433.         14.c   Name Resolution rules for enumeration literals that are not
  12434.         character_literals are not included anymore, since they are neither
  12435.         syntactically nor semantically "literals" but are rather names of
  12436.         parameterless functions.
  12437.  
  12438.  
  12439.  
  12440. 4.3 Aggregates
  12441.  
  12442. 1   [{aggregate} An aggregate combines component values into a composite
  12443. value of an array type, record type, or record extension.]  {literal: see
  12444. also aggregate}
  12445.  
  12446.  
  12447.                                    Syntax
  12448.  
  12449. 2   aggregate ::= record_aggregate | extension_aggregate | array_aggregate
  12450.  
  12451.  
  12452.                             Name Resolution Rules
  12453.  
  12454. 3   {expected type [aggregate]} The expected type for an aggregate shall be a
  12455. single nonlimited array type, record type, or record extension.
  12456.  
  12457.         3.a   Discussion:  See 8.6, ``The Context of Overload Resolution''
  12458.         for the meaning of ``shall be a single ... type.''
  12459.  
  12460.  
  12461.                                Legality Rules
  12462.  
  12463. 4   An aggregate shall not be of a class-wide type.
  12464.  
  12465.         4.a   Ramification:  When the expected type in some context is
  12466.         class-wide, an aggregate has to be explicitly qualified by the
  12467.         specific type of value to be created, so that the expected type for
  12468.         the aggregate itself is specific.
  12469.  
  12470.         4.b   Discussion:  We used to disallow aggregates of a type with
  12471.         unknown discriminants.  However, that was unnecessarily restrictive
  12472.         in the case of an extension aggregate, and irrelevant to a record
  12473.         aggregate (since a type that is legal for a record aggregate could
  12474.         not possibly have unknown discriminants) and to an array aggregate
  12475.         (the only specific types that can have unknown discriminants are
  12476.         private types, private extensions, and types derived from them).
  12477.  
  12478.  
  12479.                               Dynamic Semantics
  12480.  
  12481. 5   {evaluation [aggregate]} For the evaluation of an aggregate, an anonymous
  12482. object is created and values for the components or ancestor part are obtained
  12483. (as described in the subsequent subclause for each kind of the aggregate) and
  12484. assigned into the corresponding components or ancestor part of the anonymous
  12485. object.  {assignment operation (during evaluation of an aggregate)} Obtaining
  12486. the values and the assignments occur in an arbitrary order.  The value of the
  12487. aggregate is the value of this object.
  12488.  
  12489.         5.a   Discussion:  The ancestor part is the set of components
  12490.         inherited from the ancestor type.  The syntactic category ancestor_
  12491.         part is the expression or subtype_mark that specifies how the
  12492.         ancestor part of the anonymous object should be initialized.
  12493.  
  12494.         5.b   Ramification:  The assignment operations do the necessary value
  12495.         adjustment, as described in 7.6.  Note that the value as a whole is
  12496.         not adjusted -- just the subcomponents (and ancestor part, if any).
  12497.         7.6 also describes when this anonymous object is finalized.
  12498.  
  12499.         5.c   If the ancestor_part is a subtype_mark the Initialize procedure
  12500.         for the ancestor type is applied to the ancestor part after
  12501.         default-initializing it, unless the procedure is abstract, as
  12502.         described in 7.6.  The Adjust procedure for the ancestor type is not
  12503.         called in this case, since there is no assignment to the ancestor
  12504.         part as a whole.
  12505.  
  12506. 6   {Discriminant_Check [partial]} {check, language-defined (Discriminant_
  12507. Check)} If an aggregate is of a tagged type, a check is made that its value
  12508. belongs to the first subtype of the type.  {Constraint_Error (raised by
  12509. failure of run-time check)} Constraint_Error is raised if this check fails.
  12510.  
  12511.         6.a   Ramification:  This check ensures that no values of a tagged
  12512.         type are ever outside the first subtype, as required for inherited
  12513.         dispatching operations to work properly (see 3.4).  This check will
  12514.         always succeed if the first subtype is unconstrained.  This check is
  12515.         not extended to untagged types to preserve upward compatibility.
  12516.  
  12517.  
  12518.                             Extensions to Ada 83
  12519.  
  12520.         6.b   {extensions to Ada 83} We now allow extension_aggregates.
  12521.  
  12522.                          Wording Changes From Ada 83
  12523.  
  12524.         6.c   We have adopted new wording for expressing the rule that the
  12525.         type of an aggregate shall be determinable from the outside, though
  12526.         using the fact that it is nonlimited record (extension) or array.
  12527.  
  12528.         6.d   An aggregate now creates an anonymous object.  This is
  12529.         necessary so that controlled types will work (see 7.6).
  12530.  
  12531.  
  12532.  
  12533. 4.3.1 Record Aggregates
  12534.  
  12535. 1   [In a record_aggregate, a value is specified for each component of the
  12536. record or record extension value, using either a named or a positional
  12537. association.]
  12538.  
  12539.  
  12540.                                    Syntax
  12541.  
  12542. 2   record_aggregate ::= (record_component_association_list)
  12543.  
  12544. 3   record_component_association_list ::=
  12545.         record_component_association {, record_component_association}
  12546.       | null record
  12547.  
  12548. 4   record_component_association ::=
  12549.        [ component_choice_list => ] expression
  12550.  
  12551. 5   component_choice_list ::=
  12552.          component_selector_name {| component_selector_name}
  12553.        | others
  12554.  
  12555.     6   {named component association} A record_component_association is a
  12556.     named component association if it has a component_choice_list;
  12557.     {positional component association} otherwise, it is a positional
  12558.     component association.  Any positional component associations shall
  12559.     precede any named component associations.  If there is a named
  12560.     association with a component_choice_list of others, it shall come last.
  12561.  
  12562.         6.a   Discussion:  These rules were implied by the BNF in an early
  12563.         version of the RM9X, but it made the grammar harder to read, and was
  12564.         inconsistent with how we handle discriminant constraints.  Note that
  12565.         for array aggregates we still express some of the rules in the
  12566.         grammar, but array aggregates are significantly different because an
  12567.         array aggregate is either all positional (with a possible others at
  12568.         the end), or all named.
  12569.  
  12570.     7   In the record_component_association_list for a record_aggregate, if
  12571.     there is only one association, it shall be a named association.
  12572.  
  12573.         7.a   Reason:  Otherwise the construct would be interpreted as a
  12574.         parenthesized expression.  This is considered a syntax rule, since it
  12575.         is relevant to overload resolution.  We choose not to express it with
  12576.         BNF so we can share the definition of record_component_association_
  12577.         list in both record_aggregate and extension_aggregate.
  12578.  
  12579.         7.b   Ramification:  The record_component_association_list of an
  12580.         extension_aggregate does not have such a restriction.
  12581.                             Name Resolution Rules
  12582.  
  12583. 8   {expected type [record_aggregate]} The expected type for a record_
  12584. aggregate shall be a single nonlimited record type or record extension.
  12585.  
  12586.         8.a   Ramification:  This rule is used to resolve whether an
  12587.         aggregate is an array_aggregate or a record_aggregate.  The presence
  12588.         of a with is used to resolve between a record_aggregate and an
  12589.         extension_aggregate.
  12590.  
  12591. 9   {needed component (record_aggregate record_component_association_list)}
  12592. For the record_component_association_list of a record_aggregate, all
  12593. components of the composite value defined by the aggregate are needed[; for
  12594. the association list of an extension_aggregate, only those components not
  12595. determined by the ancestor expression or subtype are needed (see 4.3.2).]
  12596. Each selector_name in a record_component_association shall denote a needed
  12597. component [(including possibly a discriminant)].
  12598.  
  12599.         9.a   Ramification:  For the association list of a record_aggregate,
  12600.         ``needed components'' includes every component of the composite
  12601.         value, but does not include those in unchosen variants (see AI-309).
  12602.         If there are variants, then the value specified for the discriminant
  12603.         that governs them determines which variant is chosen, and hence which
  12604.         components are needed.
  12605.  
  12606.         9.b   If an extension defines a new known_discriminant_part, then all
  12607.         of its discriminants are needed in the component association list of
  12608.         an extension aggregate for that type, even if the discriminants have
  12609.         the same names and types as discriminants of the type of the ancestor
  12610.         expression.  This is necessary to ensure that the positions in the
  12611.         record_component_association_list are well defined, and that
  12612.         discriminants that govern variant_parts can be given by static
  12613.         expressions.
  12614.  
  12615. 10   {expected type [record_component_association expression]} The expected
  12616. type for the expression of a record_component_association is the type of the
  12617. associated component(s); {associated components (of a record_component_
  12618. association)} the associated component(s) are as follows:
  12619.  
  12620.    11  For a positional association, the component [(including possibly
  12621.        a discriminant)] in the corresponding relative position (in the
  12622.        declarative region of the type), counting only the needed
  12623.        components;
  12624.  
  12625.  11.a   Ramification:  This means that for an association list of an
  12626.         extension_aggregate, only noninherited components are counted to
  12627.         determine the position.
  12628.  
  12629.    12  For a named association with one or more component_selector_
  12630.        names, the named component(s);
  12631.  
  12632.    13  For a named association with the reserved word others, all needed
  12633.        components that are not associated with some previous
  12634.        association.
  12635.  
  12636.  
  12637.                                Legality Rules
  12638.  
  12639. 14   If the type of a record_aggregate is a record extension, then it shall
  12640. be a descendant of a record type, through one or more record extensions (and
  12641. no private extensions).
  12642.  
  12643. 15   If there are no components needed in a given record_component_
  12644. association_list, then the reserved words null record shall appear rather
  12645. than a list of record_component_associations.
  12646.  
  12647.         15.a   Ramification:  For example, "(null record)" is a record_
  12648.         aggregate for a null record type.  Similarly, "(T'(A) with null
  12649.         record)" is an extension_aggregate for a type defined as a null
  12650.         record extension of T.
  12651.  
  12652. 16   Each record_component_association shall have at least one associated
  12653. component, and each needed component shall be associated with exactly one
  12654. record_component_association.  If a record_component_association has two or
  12655. more associated components, all of them shall be of the same type.
  12656.  
  12657.         16.a   Ramification:  These rules apply to an association with an
  12658.         others choice.
  12659.  
  12660.         16.b   Reason:  Without these rules, there would be no way to know
  12661.         what was the expected type for the expression of the association.
  12662.  
  12663.         16.c   Discussion:  AI-00244 also requires that the expression shall
  12664.         be legal for each associated component.  This is because even though
  12665.         two components have the same type, they might have different
  12666.         subtypes.  Therefore, the legality of the expression, particularly if
  12667.         it is an array aggregate, might differ depending on the associated
  12668.         component's subtype.  However, we have relaxed the rules on array
  12669.         aggregates slightly for Ada 9X, so the staticness of an applicable
  12670.         index constraint has no effect on the legality of the array aggregate
  12671.         to which it applies.  See 4.3.3.  This was the only case (that we
  12672.         know of) where a subtype provided by context affected the legality of
  12673.         an expression.
  12674.  
  12675.         16.d   Ramification:  The rule that requires at least one associated
  12676.         component for each record_component_association implies that there
  12677.         can be no extra associations for components that don't exist in the
  12678.         composite value, or that are already determined by the ancestor
  12679.         expression or subtype of an extension_aggregate.
  12680.  
  12681.         16.e   The second part of the first sentence ensures that no needed
  12682.         components are left out, nor specified twice.
  12683.  
  12684. 17   If the components of a variant_part are needed, then the value of a
  12685. discriminant that governs the variant_part shall be given by a static
  12686. expression.
  12687.  
  12688.         17.a   Ramification:  This expression might either be given within
  12689.         the aggregate itself, or in a constraint on the parent subtype in a
  12690.         derived_type_definition for some ancestor of the type of the
  12691.         aggregate.
  12692.  
  12693.  
  12694.                               Dynamic Semantics
  12695.  
  12696. 18   {evaluation [record_aggregate]} The evaluation of a record_aggregate
  12697. consists of the evaluation of the record_component_association_list.
  12698.  
  12699. 19   {evaluation [record_component_association_list]} For the evaluation of a
  12700. record_component_association_list, any per-object constraints (see 3.8) for
  12701. components specified in the association list are elaborated and any
  12702. expressions are evaluated and converted to the subtype of the associated
  12703. component.  {implicit subtype conversion [expressions in aggregate]}
  12704.  
  12705.         19.a   Ramification:  The conversion might raise Constraint_Error.
  12706.  
  12707.         19.b   Discussion:  This check presumably happened as part of the
  12708.         dependent compatibility check in Ada 83.
  12709.  
  12710. Any constraint elaborations and expression evaluations (and conversions)
  12711. occur in an arbitrary order, except that the expression for a discriminant is
  12712. evaluated (and converted) prior to the elaboration of any per-object
  12713. constraint that depends on it, which in turn occurs prior to the evaluation
  12714. and conversion of the expression for the component with the per-object
  12715. constraint.
  12716.  
  12717. 20   The expression of a record_component_association is evaluated (and
  12718. converted) once for each associated component.
  12719.  
  12720.  
  12721.      NOTES
  12722. 21   (7) For a record_aggregate with positional associations, expressions
  12723.      specifying discriminant values appear first since the known_
  12724.      discriminant_part is given first in the declaration of the type; they
  12725.      have to be in the same order as in the known_discriminant_part.
  12726.  
  12727.  
  12728.                                   Examples
  12729.  
  12730. 22   Example of a record aggregate with positional associations:
  12731.  
  12732. 23  (4, July, 1776)                                       --  see 3.8
  12733.  
  12734. 24   Examples of record aggregates with named associations:
  12735.  
  12736. 25  (Day => 4, Month => July, Year => 1776)
  12737.     (Month => July, Day => 4, Year => 1776)
  12738.  
  12739. 26  (Disk, Closed, Track => 5, Cylinder => 12)            --  see 3.8.1
  12740.     (Unit => Disk, Status => Closed, Cylinder => 9, Track => 1)
  12741.  
  12742. 27   Example of component association with several choices:
  12743.  
  12744. 28  (Value => 0, Succ|Pred => new Cell'(0, null, null))   --  see 3.10.1
  12745.  
  12746. 29   --  The allocator is evaluated twice:  Succ and Pred designate different c\
  12747. ells
  12748.  
  12749. 30   Examples of record aggregates for tagged types (see 3.9 and 3.9.1):
  12750.  
  12751. 31  Expression'(null record)
  12752.     Literal'(Value => 0.0)
  12753.     Painted_Point'(0.0, Pi/2.0, Paint => Red)
  12754.  
  12755.  
  12756.                             Extensions to Ada 83
  12757.  
  12758.         31.a   {extensions to Ada 83} Null record aggregates may now be
  12759.         specified, via "(null record)".  However, this syntax is more useful
  12760.         for null record extensions in extension aggregates.
  12761.  
  12762.                          Wording Changes From Ada 83
  12763.  
  12764.         31.b   Various AIs have been incorporated (AI-189, AI-244, and
  12765.         AI-309).  In particular, Ada 83 did not explicitly disallow extra
  12766.         values in a record aggregate.  Now we do.
  12767.  
  12768.  
  12769.  
  12770. 4.3.2 Extension Aggregates
  12771.  
  12772. 1   [An extension_aggregate specifies a value for a type that is a record
  12773. extension by specifying a value or subtype for an ancestor of the type,
  12774. followed by associations for any components not determined by the ancestor_
  12775. part.]
  12776.  
  12777.  
  12778.                          Language Design Principles
  12779.  
  12780.         1.a   The model underlying this syntax is that a record extension can
  12781.         also be viewed as a regular record type with an ancestor "prefix."
  12782.         The record_component_association_list corresponds to exactly what
  12783.         would be needed if there were no ancestor/prefix type.  The ancestor_
  12784.         part determines the value of the ancestor/prefix.
  12785.  
  12786.                                    Syntax
  12787.  
  12788. 2   extension_aggregate ::=
  12789.         (ancestor_part with record_component_association_list)
  12790.  
  12791. 3   ancestor_part ::= expression | subtype_mark
  12792.  
  12793.  
  12794.                             Name Resolution Rules
  12795.  
  12796. 4   {expected type [extension_aggregate]} The expected type for an extension_
  12797. aggregate shall be a single nonlimited type that is a record extension.
  12798. {expected type [extension_aggregate ancestor expression]} If the ancestor_
  12799. part is an expression, it is expected to be of any nonlimited tagged type.
  12800.  
  12801.         4.a   Reason:  We could have made the expected type T'Class where T
  12802.         is the ultimate ancestor of the type of the aggregate, or we could
  12803.         have made it even more specific than that.  However, if the overload
  12804.         resolution rules get too complicated, the implementation gets more
  12805.         difficult and it becomes harder to produce good error messages.
  12806.  
  12807.  
  12808.                                Legality Rules
  12809.  
  12810. 5   If the ancestor_part is a subtype_mark, it shall denote a specific tagged
  12811. subtype.  The type of the extension_aggregate shall be derived from the type
  12812. of the ancestor_part, through one or more record extensions (and no private
  12813. extensions).
  12814.  
  12815.  
  12816.                               Static Semantics
  12817.  
  12818. 6   {needed component (extension_aggregate record_component_association_
  12819. list)} For the record_component_association_list of an extension_aggregate,
  12820. the only components needed are those of the composite value defined by the
  12821. aggregate that are not inherited from the type of the ancestor_part, plus any
  12822. inherited discriminants if the ancestor_part is a subtype_mark that denotes
  12823. an unconstrained subtype.
  12824.  
  12825.  
  12826.                               Dynamic Semantics
  12827.  
  12828. 7   {evaluation [extension_aggregate]} For the evaluation of an extension_
  12829. aggregate, the record_component_association_list is evaluated.  If the
  12830. ancestor_part is an expression, it is also evaluated; if the ancestor_part is
  12831. a subtype_mark, the components of the value of the aggregate not given by the
  12832. record_component_association_list are initialized by default as for an object
  12833. of the ancestor type.  Any implicit initializations or evaluations are
  12834. performed in an arbitrary order, except that the expression for a
  12835. discriminant is evaluated prior to any other evaluation or initialization
  12836. that depends on it.
  12837.  
  12838. 8   {Discriminant_Check [partial]} {check, language-defined (Discriminant_
  12839. Check)} If the type of the ancestor_part has discriminants that are not
  12840. inherited by the type of the extension_aggregate, then, unless the ancestor_
  12841. part is a subtype_mark that denotes an unconstrained subtype, a check is made
  12842. that each discriminant of the ancestor has the value specified for a
  12843. corresponding discriminant, either in the record_component_association_list,
  12844. or in the derived_type_definition for some ancestor of the type of the
  12845. extension_aggregate.  {Constraint_Error (raised by failure of run-time
  12846. check)} Constraint_Error is raised if this check fails.
  12847.  
  12848.         8.a   Ramification:  Corresponding and specified discriminants are
  12849.         defined in 3.7.  The rules requiring static compatibility between new
  12850.         discriminants of a derived type and the parent discriminant(s) they
  12851.         constrain ensure that at most one check is required per discriminant
  12852.         of the ancestor expression.
  12853.  
  12854.  
  12855.      NOTES
  12856. 9    (8) If all components of the value of the extension_aggregate are
  12857.      determined by the ancestor_part, then the record_component_association_
  12858.      list is required to be simply null record.
  12859.  
  12860. 10   (9) If the ancestor_part is a subtype_mark, then its type can be
  12861.      abstract.  If its type is controlled, then as the last step of
  12862.      evaluating the aggregate, the Initialize procedure of the ancestor type
  12863.      is called, unless the Initialize procedure is abstract (see 7.6).
  12864.  
  12865.  
  12866.                                   Examples
  12867.  
  12868. 11   Examples of extension aggregates (for types defined in 3.9.1):
  12869.  
  12870. 12  Painted_Point'(Point with Red)
  12871.     (Point'(P) with Paint => Black)
  12872.  
  12873. 13  (Expression with Left => 1.2, Right => 3.4)
  12874.     Addition'(Binop with null record)
  12875.                  -- presuming Binop is of type Binary_Operation
  12876.  
  12877.  
  12878.                             Extensions to Ada 83
  12879.  
  12880.         13.a   {extensions to Ada 83} The extension aggregate syntax is new.
  12881.  
  12882.  
  12883.  
  12884. 4.3.3 Array Aggregates
  12885.  
  12886. 1   [In an array_aggregate, a value is specified for each component of an
  12887. array, either positionally or by its index.]  For a positional_array_
  12888. aggregate, the components are given in increasing-index order, with a final
  12889. others, if any, representing any remaining components.  For a named_array_
  12890. aggregate, the components are identified by the values covered by the
  12891. discrete_choices.  {94-4603.a}
  12892.  
  12893.  
  12894.                          Language Design Principles
  12895.  
  12896.         1.a   The rules in this subclause are based on terms and rules for
  12897.         discrete_choice_lists defined in 3.8.1, ``Variant Parts and Discrete
  12898.         Choices''.
  12899.  
  12900.                                    Syntax
  12901.  
  12902. 2   array_aggregate ::=
  12903.       positional_array_aggregate | named_array_aggregate
  12904.  
  12905. 3   positional_array_aggregate ::=
  12906.         (expression, expression {, expression})
  12907.       | (expression {, expression}, others => expression)
  12908.  
  12909. 4   named_array_aggregate ::=
  12910.         (array_component_association {, array_component_association})
  12911.  
  12912. 5   array_component_association ::=
  12913.         discrete_choice_list => expression
  12914.  
  12915.  
  12916. 6   {n-dimensional array_aggregate} An n-dimensional array_aggregate is one
  12917. that is written as n levels of nested array_aggregates (or at the bottom
  12918. level, equivalent string_literals).  {subaggregate (of an array_aggregate)}
  12919. For the multidimensional case (n >= 2) the array_aggregates (or equivalent
  12920. string_literals) at the n-1 lower levels are called subaggregates of the
  12921. enclosing n-dimensional array_aggregate.  {array component expression} The
  12922. expressions of the bottom level subaggregates (or of the array_aggregate
  12923. itself if one-dimensional) are called the array component expressions of the
  12924. enclosing n-dimensional array_aggregate.
  12925.  
  12926.         6.a   Ramification:  Subaggregates do not have a type.  They
  12927.         correspond to part of an array.  For example, with a matrix, a
  12928.         subaggregate would correspond to a single row of the matrix.  The
  12929.         definition of "n-dimensional" array_aggregate applies to sub-
  12930.         aggregates as well as aggregates that have a type.
  12931.  
  12932.         6.b   To be honest:  {others choice} An others choice is the reserved
  12933.         word others as it appears in a positional_array_aggregate or as the
  12934.         discrete_choice of the discrete_choice_list in an array_component_
  12935.         association.
  12936.  
  12937.  
  12938.                             Name Resolution Rules
  12939.  
  12940. 7   {expected type [array_aggregate]} The expected type for an array_
  12941. aggregate (that is not a subaggregate) shall be a single nonlimited array
  12942. type.  {expected type [array_aggregate component expression]} The component
  12943. type of this array type is the expected type for each array component
  12944. expression of the array_aggregate.
  12945.  
  12946.         7.a   Ramification:  We already require a single array or record type
  12947.         or record extension for an aggregate.  The above rule requiring a
  12948.         single nonlimited array type (and similar ones for record and
  12949.         extension aggregates) resolves which kind of aggregate you have.
  12950.  
  12951. 8   {expected type [array_aggregate discrete_choice]} The expected type for
  12952. each discrete_choice in any discrete_choice_list of a named_array_aggregate
  12953. is the type of the corresponding index; {corresponding index (for an array_
  12954. aggregate)} the corresponding index for an array_aggregate that is not a
  12955. subaggregate is the first index of its type; for an (n-m)-dimensional
  12956. subaggregate within an array_aggregate of an n-dimensional type, the
  12957. corresponding index is the index in position m+1.
  12958.  
  12959.  
  12960.                                Legality Rules
  12961.  
  12962. 9   An array_aggregate of an n-dimensional array type shall be written as an
  12963. n-dimensional array_aggregate.
  12964.  
  12965.         9.a   Ramification:  In an m-dimensional array_aggregate [(including
  12966.         a subaggregate)], where m >= 2, each of the expressions has to be an
  12967.         (m-1)-dimensional subaggregate.
  12968.  
  12969. 10   An others choice is allowed for an array_aggregate only if an applicable
  12970. index constraint applies to the array_aggregate.  {applicable index
  12971. constraint} [An applicable index constraint is a constraint provided by
  12972. certain contexts where an array_aggregate is permitted that can be used to
  12973. determine the bounds of the array value specified by the aggregate.]  Each of
  12974. the following contexts (and none other) defines an applicable index
  12975. constraint:
  12976.  
  12977.    11  For an explicit_actual_parameter, an explicit_generic_actual_
  12978.        parameter, the expression of a return_statement, the initializa-
  12979.        tion expression in an object_declaration, or a default_expression
  12980.        [(for a parameter or a component)], when the nominal subtype of
  12981.        the corresponding formal parameter, generic formal parameter,
  12982.        function result, object, or component is a constrained array
  12983.        subtype, the applicable index constraint is the constraint of the
  12984.        subtype;
  12985.  
  12986.    12  For the expression of an assignment_statement where the name
  12987.        denotes an array variable, the applicable index constraint is the
  12988.        constraint of the array variable;
  12989.  
  12990.  12.a   Reason:  This case is broken out because the constraint comes
  12991.         from the actual subtype of the variable (which is always
  12992.         constrained) rather than its nominal subtype (which might be
  12993.         unconstrained).
  12994.  
  12995.    13  For the operand of a qualified_expression whose subtype_mark
  12996.        denotes a constrained array subtype, the applicable index
  12997.        constraint is the constraint of the subtype;
  12998.  
  12999.    14  For a component expression in an aggregate, if the component's
  13000.        nominal subtype is a constrained array subtype, the applicable
  13001.        index constraint is the constraint of the subtype;
  13002.  
  13003.  14.a   Discussion:  Here, the array_aggregate with others is being used
  13004.         within a larger aggregate.
  13005.  
  13006.    15  For a parenthesized expression, the applicable index constraint
  13007.        is that, if any, defined for the expression.
  13008.  
  13009.  15.a   Discussion:  RM83 omitted this case, presumably as an oversight.
  13010.         We want to minimize situations where an expression becomes
  13011.         illegal if parenthesized.
  13012.  
  13013. 16   The applicable index constraint applies to an array_aggregate that
  13014. appears in such a context, as well as to any subaggregates thereof.  In the
  13015. case of an explicit_actual_parameter (or default_expression) for a call on a
  13016. generic formal subprogram, no applicable index constraint is defined.
  13017.  
  13018.         16.a   Reason:  This avoids generic contract model problems, because
  13019.         only mode conformance is required when matching actual subprograms
  13020.         with generic formal subprograms.
  13021.  
  13022. 17   The discrete_choice_list of an array_component_association is allowed to
  13023. have a discrete_choice that is a nonstatic expression or that is a discrete_
  13024. range that defines a nonstatic or null range, only if it is the single
  13025. discrete_choice of its discrete_choice_list, and there is only one array_
  13026. component_association in the array_aggregate.
  13027.  
  13028.         17.a   Discussion:  We now allow a nonstatic others choice even if
  13029.         there are other array component expressions as well.
  13030.  
  13031. 18   In a named_array_aggregate with more than one discrete_choice, no two
  13032. discrete_choices are allowed to cover the same value (see 3.8.1); if there is
  13033. no others choice, the discrete_choices taken together shall exactly cover a
  13034. contiguous sequence of values of the corresponding index type.
  13035.  
  13036.         18.a   Ramification:  This implies that each component must be
  13037.         specified exactly once.  See AI-309.
  13038.  
  13039. 19   A bottom level subaggregate of a multidimensional array_aggregate of a
  13040. given array type is allowed to be a string_literal only if the component type
  13041. of the array type is a character type; each character of such a string_
  13042. literal shall correspond to a defining_character_literal of the component
  13043. type.
  13044.  
  13045.  
  13046.                               Static Semantics
  13047.  
  13048. 20   A subaggregate that is a string_literal is equivalent to one that is a
  13049. positional_array_aggregate of the same length, with each expression being the
  13050. character_literal for the corresponding character of the string_literal.
  13051.  
  13052.  
  13053.                               Dynamic Semantics
  13054.  
  13055. 21   {evaluation [array_aggregate]} The evaluation of an array_aggregate of a
  13056. given array type proceeds in two steps:
  13057.  
  13058.    22  Any discrete_choices of this aggregate and of its subaggregates
  13059.        are evaluated in an arbitrary order, and converted to the
  13060.        corresponding index type; {implicit subtype conversion [choices
  13061.        of aggregate]}
  13062.  
  13063.    23  The array component expressions of the aggregate are evaluated in
  13064.        an arbitrary order and their values are converted to the
  13065.        component subtype of the array type; an array component
  13066.        expression is evaluated once for each associated component.
  13067.        {implicit subtype conversion [expressions of aggregate]}
  13068.  
  13069.         23.a   Ramification:  Subaggregates are not separately evaluated.
  13070.         The conversion of the value of the component expressions to the
  13071.         component subtype might raise Constraint_Error.
  13072.  
  13073. 24   {bounds (of the index range of an array_aggregate)} The bounds of the
  13074. index range of an array_aggregate [(including a subaggregate)] are determined
  13075. as follows:
  13076.  
  13077.    25  For an array_aggregate with an others choice, the bounds are
  13078.        those of the corresponding index range from the applicable index
  13079.        constraint;
  13080.  
  13081.    26  For a positional_array_aggregate [(or equivalent string_literal)]
  13082.        without an others choice, the lower bound is that of the
  13083.        corresponding index range in the applicable index constraint, if
  13084.        defined, or that of the corresponding index subtype, if not; in
  13085.        either case, the upper bound is determined from the lower bound
  13086.        and the number of expressions [(or the length of the string_
  13087.        literal)];
  13088.  
  13089.    27  For a named_array_aggregate without an others choice, the bounds
  13090.        are determined by the smallest and largest index values covered
  13091.        by any discrete_choice_list.
  13092.  
  13093.  27.a   Reason:  We don't need to say that each index value has to be
  13094.         covered exactly once, since that is a ramification of the
  13095.         general rule on aggregates that each component's value has to be
  13096.         specified exactly once.
  13097.  
  13098. 28   {Range_Check [partial]} {check, language-defined (Range_Check)} For an
  13099. array_aggregate, a check is made that the index range defined by its bounds
  13100. is compatible with the corresponding index subtype.
  13101.  
  13102.         28.a   Discussion:  In RM83, this was phrased more explicitly, but
  13103.         once we define "compatibility" between a range and a subtype, it
  13104.         seems to make sense to take advantage of that definition.
  13105.  
  13106.         28.b   Ramification:  The definition of compatibility handles the
  13107.         special case of a null range, which is always compatible with a
  13108.         subtype.  See AI-00313.
  13109.  
  13110. 29   {Index_Check [partial]} {check, language-defined (Index_Check)} For an
  13111. array_aggregate with an others choice, a check is made that no expression is
  13112. specified for an index value outside the bounds determined by the applicable
  13113. index constraint.
  13114.  
  13115.         29.a   Discussion:  RM83 omitted this case, apparently through an
  13116.         oversight.  AI-309 defines this as a dynamic check, even though other
  13117.         Ada 83 rules ensured that this check could be performed statically.
  13118.         We now allow an others choice to be dynamic, even if it is not the
  13119.         only choice, so this check now needs to be dynamic, in some cases.
  13120.         Also, within a generic unit, this would be a nonstatic check in some
  13121.         cases.
  13122.  
  13123. 30   {Index_Check [partial]} {check, language-defined (Index_Check)} For a
  13124. multidimensional array_aggregate, a check is made that all subaggregates that
  13125. correspond to the same index have the same bounds.
  13126.  
  13127.         30.a   Ramification:  No array bounds ``sliding'' is performed on
  13128.         subaggregates.
  13129.  
  13130.         30.b   Reason:  If sliding were performed, it would not be obvious
  13131.         which subaggregate would determine the bounds of the corresponding
  13132.         index.
  13133.  
  13134. 31   {Constraint_Error (raised by failure of run-time check)} The exception
  13135. Constraint_Error is raised if any of the above checks fail.
  13136.  
  13137.  
  13138.      NOTES
  13139. 32   (10) In an array_aggregate, positional notation may only be used with
  13140.      two or more expressions; a single expression in parentheses is
  13141.      interpreted as a parenthesized_expression.  A named_array_aggregate,
  13142.      such as (1 => X), may be used to specify an array with a single
  13143.      component.
  13144.  
  13145.  
  13146.                                   Examples
  13147.  
  13148. 33   Examples of array aggregates with positional associations:
  13149.  
  13150. 34  (7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
  13151.     Table'(5, 8, 4, 1, others => 0)  --  see 3.6
  13152.  
  13153. 35   Examples of array aggregates with named associations:
  13154.  
  13155. 36  (1 .. 5 => (1 .. 8 => 0.0))      --  two-dimensional
  13156.     (1 .. N => new Cell)             --  N new cells, in particular for N = 0
  13157.  
  13158. 37  Table'(2 | 4 | 10 => 1, others => 0)
  13159.     Schedule'(Mon .. Fri => True,  others => False)  --  see 3.6
  13160.     Schedule'(Wed | Sun  => False, others => True)
  13161.     Vector'(1 => 2.5)                                --  single-component vector
  13162.  
  13163. 38   Examples of two-dimensional array aggregates:
  13164.  
  13165. 39  -- Three aggregates for the same value of subtype Matrix(1..2,1..3) (see 3.\
  13166. 6):
  13167.  
  13168. 40  ((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
  13169.     (1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3))
  13170.     (1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3))
  13171.  
  13172. 41   Examples of aggregates as initial values:
  13173.  
  13174. 42  A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0);        -- A(1)=7, A(10)=0{94-4\
  13175. 667.c}
  13176.     B : Table := (2 | 4 | 10 => 1, others => 0);        -- B(1)=0, B(10)=1
  13177.     C : constant Matrix := (1 .. 5 => (1 .. 8 => 0.0)); -- C'Last(1)=5, C'Last(\
  13178. 2)=8
  13179.  
  13180. 43  D : Bit_Vector(M .. N) := (M .. N => True);         -- see 3.6
  13181.     E : Bit_Vector(M .. N) := (others => True);
  13182.     F : String(1 .. 1) := (1 => 'F');  -- a one component aggregate: same as "F"
  13183.                             Extensions to Ada 83
  13184.  
  13185.         43.a   {extensions to Ada 83} We now allow "named with others"
  13186.         aggregates in all contexts where there is an applicable index
  13187.         constraint, effectively eliminating what was RM83-4.3.2(6).  Sliding
  13188.         never occurs on an aggregate with others, because its bounds come
  13189.         from the applicable index constraint, and therefore already match the
  13190.         bounds of the target.
  13191.  
  13192.         43.b   The legality of an others choice is no longer affected by the
  13193.         staticness of the applicable index constraint.  This substantially
  13194.         simplifies several rules, while being slightly more flexible for the
  13195.         user.  It obviates the rulings of AI-244 and AI-310, while taking
  13196.         advantage of the dynamic nature of the "extra values" check required
  13197.         by AI-309.
  13198.  
  13199.         43.c   Named array aggregates are permitted even if the index type is
  13200.         descended from a formal scalar type.  See 4.9 and AI-00190.
  13201.  
  13202.                          Wording Changes From Ada 83
  13203.  
  13204.         43.d   We now separate named and positional array aggregate syntax,
  13205.         since, unlike other aggregates, named and positional associations
  13206.         cannot be mixed in array aggregates (except that an others choice is
  13207.         allowed in a positional array aggregate).
  13208.  
  13209.         43.e   We have also reorganized the presentation to handle
  13210.         multidimensional and one-dimensional aggregates more uniformly, and
  13211.         to incorporate the rulings of AI-19, AI-309, etc.
  13212.  
  13213.  
  13214.  
  13215. 4.4 Expressions
  13216.  
  13217. 1   {expression} An expression is a formula that defines the computation or
  13218. retrieval of a value.  In this International Standard, the term
  13219. ``expression'' refers to a construct of the syntactic category expression or
  13220. of any of the other five syntactic categories defined below.  {and operator}
  13221. {operator (and)} {or operator} {operator (or)} {xor operator} {operator
  13222. (xor)} {and then (short-circuit control form)} {or else (short-circuit
  13223. control form)} {= operator} {operator (=)} {equal operator} {operator
  13224. (equal)} {/= operator} {operator (/=)} {not equal operator} {operator (not
  13225. equal)} {< operator} {operator (<)} {less than operator} {operator (less
  13226. than)} {<= operator} {operator (<=)} {less than or equal operator} {operator
  13227. (less than or equal)} {> operator} {operator (>)} {greater than operator}
  13228. {operator (greater than)} {>= operator} {operator (>=)} {greater than or
  13229. equal operator} {operator (greater than or equal)} {in (membership test)}
  13230. {not in (membership test)} {+ operator} {operator (+)} {plus operator}
  13231. {operator (plus)} {- operator} {operator (-)} {minus operator} {operator
  13232. (minus)} {& operator} {operator (&)} {ampersand operator} {operator
  13233. (ampersand)} {concatenation operator} {operator (concatenation)} {catenation
  13234. operator: see concatenation operator} {* operator} {operator (*)} {multiply
  13235. operator} {operator (multiply)} {times operator} {operator (times)} {/
  13236. operator} {operator (/)} {divide operator} {operator (divide)} {mod operator}
  13237. {operator (mod)} {rem operator} {operator (rem)} {** operator} {operator
  13238. (**)} {exponentiation operator} {operator (exponentiation)} {abs operator}
  13239. {operator (abs)} {absolute value} {not operator} {operator (not)}
  13240.  
  13241.  
  13242.                                    Syntax
  13243.  
  13244. 2   expression ::=
  13245.          relation {and relation} | relation {and then relation}
  13246.        | relation {or relation}  | relation {or else relation}
  13247.        | relation {xor relation}
  13248.  
  13249. 3   relation ::=
  13250.          simple_expression [relational_operator simple_expression]
  13251.        | simple_expression [not] in range
  13252.        | simple_expression [not] in subtype_mark
  13253.  
  13254. 4   simple_expression ::= [unary_adding_operator] term {binary_adding_operator \
  13255. term}
  13256.  
  13257. 5   term ::= factor {multiplying_operator factor}
  13258.  
  13259. 6   factor ::= primary [** primary] | abs primary | not primary
  13260.  
  13261. 7   primary ::=
  13262.        numeric_literal | null | string_literal | aggregate
  13263.      | name | qualified_expression | allocator | (expression)
  13264.  
  13265.  
  13266.                             Name Resolution Rules
  13267.  
  13268. 8   A name used as a primary shall resolve to denote an object or a value.
  13269.  
  13270.         8.a   Discussion:  This replaces RM83-4.4(3).  We don't need to
  13271.         mention named numbers explicitly, because the name of a named number
  13272.         denotes a value.  We don't need to mention attributes explicitly,
  13273.         because attributes now denote (rather than yield) values in general.
  13274.         Also, the new wording allows attributes that denote objects, which
  13275.         should always have been allowed (in case the implementation chose to
  13276.         have such a thing).
  13277.  
  13278.         8.b   Reason:  It might seem odd that this is an overload resolution
  13279.         rule, but it is relevant during overload resolution.  For example, it
  13280.         helps ensure that a primary that consists of only the identifier of a
  13281.         parameterless function is interpreted as a function_call rather than
  13282.         directly as a direct_name.
  13283.  
  13284.  
  13285.                               Static Semantics
  13286.  
  13287. 9   Each expression has a type; it specifies the computation or retrieval of
  13288. a value of that type.
  13289.  
  13290.  
  13291.                               Dynamic Semantics
  13292.  
  13293. 10   {evaluation [primary that is a name]} The value of a primary that is a
  13294. name denoting an object is the value of the object.
  13295.  
  13296.  
  13297.                          Implementation Permissions
  13298.  
  13299. 11   {Overflow_Check [partial]} {check, language-defined (Overflow_Check)}
  13300. {Constraint_Error (raised by failure of run-time check)} For the evaluation
  13301. of a primary that is a name denoting an object of an unconstrained numeric
  13302. subtype, if the value of the object is outside the base range of its type,
  13303. the implementation may either raise Constraint_Error or return the value of
  13304. the object.
  13305.  
  13306.         11.a   Ramification:  This means that if extra-range intermediates
  13307.         are used to hold the value of an object of an unconstrained numeric
  13308.         subtype, a Constraint_Error can be raised on a read of the object,
  13309.         rather than only on an assignment to it.  Similarly, it means that
  13310.         computing the value of an object of such a subtype can be deferred
  13311.         until the first read of the object (presuming no side-effects other
  13312.         than failing an Overflow_Check are possible).  This permission is
  13313.         over and above that provided by clause 11.6, since this allows the
  13314.         Constraint_Error to move to a different handler.
  13315.  
  13316.         11.b   Reason:  This permission is intended to allow extra-range
  13317.         registers to be used efficiently to hold parameters and local
  13318.         variables, even if they might need to be transferred into smaller
  13319.         registers for performing certain predefined operations.
  13320.  
  13321.         11.c   Discussion:  There is no need to mention other kinds of
  13322.         primarys, since any Constraint_Error to be raised can be ``charged''
  13323.         to the evaluation of the particular kind of primary.
  13324.  
  13325.  
  13326.                                   Examples
  13327.  
  13328. 12   Examples of primaries:
  13329.  
  13330. 13  4.0                --  real literal
  13331.     Pi                 --  named number
  13332.     (1 .. 10 => 0)     --  array aggregate
  13333.     Sum                --  variable
  13334.     Integer'Last       --  attribute
  13335.     Sine(X)            --  function call
  13336.     Color'(Blue)       --  qualified expression
  13337.     Real(M*N)          --  conversion
  13338.     (Line_Count + 10)  --  parenthesized expression
  13339.  
  13340. 14   Examples of expressions:
  13341.  
  13342. 15  Volume                      -- primary
  13343.     not Destroyed               -- factor
  13344.     2*Line_Count                -- term
  13345.     -4.0                        -- simple expression
  13346.     -4.0 + A                    -- simple expression
  13347.     B**2 - 4.0*A*C              -- simple expression
  13348.     Password(1 .. 3) = "Bwv"    -- relation
  13349.     Count in Small_Int          -- relation
  13350.     Count not in Small_Int      -- relation
  13351.     Index = 0 or Item_Hit       -- expression
  13352.     (Cold and Sunny) or Warm    -- expression (parentheses are required)
  13353.     A**(B**C)                   -- expression (parentheses are required)
  13354.  
  13355.  
  13356.                             Extensions to Ada 83
  13357.  
  13358.         15.a   {extensions to Ada 83} In Ada 83, out parameters and their
  13359.         nondiscriminant subcomponents are not allowed as primaries.  These
  13360.         restrictions are eliminated in Ada 9X.
  13361.  
  13362.         15.b   In various contexts throughout the language where Ada 83
  13363.         syntax rules had simple_expression, the corresponding Ada 9X syntax
  13364.         rule has expression instead.  This reflects the inclusion of modular
  13365.         integer types, which makes the logical operators "and", "or", and
  13366.         "xor" more useful in expressions of an integer type.  Requiring
  13367.         parentheses to use these operators in such contexts seemed
  13368.         unnecessary and potentially confusing.  Note that the bounds of a
  13369.         range still have to be specified by simple_expressions, since
  13370.         otherwise expressions involving membership tests might be ambiguous.
  13371.         Essentially, the operation ".." is of higher precedence than the
  13372.         logical operators, and hence uses of logical operators still have to
  13373.         be parenthesized when used in a bound of a range.
  13374.  
  13375.  
  13376.  
  13377. 4.5 Operators and Expression Evaluation
  13378.  
  13379. 1   [{precedence of operators} {operator precedence} The language defines the
  13380. following six categories of operators (given in order of increasing
  13381. precedence).  The corresponding operator_symbols, and only those, can be used
  13382. as designators in declarations of functions for user-defined operators.  See
  13383. 6.6, ``Overloading of Operators''.]
  13384.                                    Syntax
  13385.  
  13386. 2   logical_operator                                      ::=  and | or  | xor
  13387.  
  13388. 3   relational_operator                                   ::=  =   | /=  | <   \
  13389. | <= | > | >=
  13390.  
  13391. 4   binary_adding_operator                                ::=  +   | -   | &
  13392.  
  13393. 5   unary_adding_operator                                 ::=  +   | -
  13394.  
  13395. 6   multiplying_operator                                  ::=  *   | /   | mod \
  13396. | rem
  13397.  
  13398. 7   highest_precedence_operator                           ::=  **  | abs | not
  13399.  
  13400.         7.a   Discussion:  Some of the above syntactic categories are not
  13401.         used in other syntax rules.  They are just used for classification.
  13402.         The others are used for both classification and parsing.
  13403.  
  13404.  
  13405.                               Static Semantics
  13406.  
  13407. 8   For a sequence of operators of the same precedence level, the operators
  13408. are associated with their operands in textual order from left to right.
  13409. Parentheses can be used to impose specific associations.
  13410.  
  13411.         8.a   Discussion:  The left-associativity is not directly inherent in
  13412.         the grammar of 4.4, though in 1.1.4 the definition of the metasymbols
  13413.         {} implies left associativity.  So this could be seen as redundant,
  13414.         depending on how literally one interprets the definition of the {}
  13415.         metasymbols.
  13416.  
  13417.         8.b   See the Implementation Permissions below regarding flexibility
  13418.         in reassociating operators of the same precedence.
  13419.  
  13420. 9   {predefined operator} {operator (predefined)} For each form of type
  13421. definition, certain of the above operators are predefined; that is, they are
  13422. implicitly declared immediately after the type definition.  {binary operator}
  13423. {operator (binary)} {unary operator} {operator (unary)} For each such
  13424. implicit operator declaration, the parameters are called Left and Right for
  13425. binary operators; the single parameter is called Right for unary operators.
  13426. [An expression of the form X op Y, where op is a binary operator, is
  13427. equivalent to a function_call of the form "op"(X, Y).  An expression of the
  13428. form op Y, where op is a unary operator, is equivalent to a function_call of
  13429. the form "op"(Y).  The predefined operators and their effects are described
  13430. in subclauses 4.5.1 through 4.5.6.]
  13431.  
  13432.  
  13433.                               Dynamic Semantics
  13434.  
  13435. 10   [{Constraint_Error (raised by failure of run-time check)} The predefined
  13436. operations on integer types either yield the mathematically correct result or
  13437. raise the exception Constraint_Error.  For implementations that support the
  13438. Numerics Annex, the predefined operations on real types yield results whose
  13439. accuracy is defined in Annex G, or raise the exception Constraint_Error.
  13440. {94-4481.a}]
  13441.  
  13442.         10.a   To be honest:  Predefined operations on real types can
  13443.         ``silently'' give wrong results when the Machine_Overflows attribute
  13444.         is false, and the computation overflows.
  13445.  
  13446.  
  13447.                          Implementation Requirements
  13448.  
  13449. 11   {Constraint_Error (raised by failure of run-time check)} The
  13450. implementation of a predefined operator that delivers a result of an integer
  13451. or fixed point type may raise Constraint_Error only if the result is outside
  13452. the base range of the result type.
  13453.  
  13454. 12   {Constraint_Error (raised by failure of run-time check)} The
  13455. implementation of a predefined operator that delivers a result of a floating
  13456. point type may raise Constraint_Error only if the result is outside the safe
  13457. range of the result type.
  13458.  
  13459.         12.a   To be honest:  An exception is made for exponentiation by a
  13460.         negative exponent in 4.5.6.
  13461.  
  13462.  
  13463.                          Implementation Permissions
  13464.  
  13465. 13   For a sequence of predefined operators of the same precedence level (and
  13466. in the absence of parentheses imposing a specific association), an
  13467. implementation may impose any association of the operators with operands so
  13468. long as the result produced is an allowed result for the left-to-right
  13469. association, but ignoring the potential for failure of language-defined
  13470. checks in either the left-to-right or chosen order of association.
  13471.  
  13472.         13.a   Discussion:  Note that the permission to reassociate the
  13473.         operands in any way subject to producing a result allowed for the
  13474.         left-to-right association is not much help for most floating point
  13475.         operators, since reassociation may introduce significantly different
  13476.         round-off errors, delivering a result that is outside the model
  13477.         interval for the left-to-right association.  Similar problems arise
  13478.         for division with integer or fixed point operands.
  13479.  
  13480.         13.b   Note that this permission does not apply to user-defined
  13481.         operators.
  13482.  
  13483.  
  13484.      NOTES
  13485. 14   (11) The two operands of an expression of the form X op Y, where op is a
  13486.      binary operator, are evaluated in an arbitrary order, as for any
  13487.      function_call (see 6.4).
  13488.  
  13489.  
  13490.                                   Examples
  13491.  
  13492. 15   Examples of precedence:
  13493.  
  13494. 16  not Sunny or Warm    --  same as (not Sunny) or Warm
  13495.     X > 4.0 and Y > 0.0  --  same as (X > 4.0) and (Y > 0.0)
  13496.  
  13497. 17  -4.0*A**2            --  same as -(4.0 * (A**2))
  13498.     abs(1 + A) + B       --  same as (abs (1 + A)) + B
  13499.     Y**(-3)              --  parentheses are necessary
  13500.     A / B * C            --  same as (A/B)*C
  13501.     A + (B + C)          --  evaluate B + C before adding it to A
  13502.  
  13503.  
  13504.                          Wording Changes From Ada 83
  13505.  
  13506.         17.a   We don't give a detailed definition of precedence, since it is
  13507.         all implicit in the syntax rules anyway.
  13508.  
  13509.         17.b   The permission to reassociate is moved here from RM83-11.6(5),
  13510.         so it is closer to the rules defining operator association.
  13511.  
  13512.  
  13513.  
  13514. 4.5.1 Logical Operators and Short-circuit Control Forms
  13515.  
  13516.                             Name Resolution Rules
  13517.  
  13518. 1   {short-circuit control form} {and then (short-circuit control form)} {or
  13519. else (short-circuit control form)} An expression consisting of two relations
  13520. connected by and then or or else (a short-circuit control form) shall resolve
  13521. to be of some boolean type; {expected type [short-circuit control form
  13522. relation]} the expected type for both relations is that same boolean type.
  13523.  
  13524.         1.a   Reason:  This rule is written this way so that overload
  13525.         resolution treats the two operands symmetrically; the resolution of
  13526.         overloading present in either one can benefit from the resolution of
  13527.         the other.  Furthermore, the type expected by context can help.
  13528.  
  13529.  
  13530.                               Static Semantics
  13531.  
  13532. 2   {logical operator} {operator (logical)} {and operator} {operator (and)}
  13533. {or operator} {operator (or)} {xor operator} {operator (xor)} The following
  13534. logical operators are predefined for every boolean type T, for every modular
  13535. type T, and for every one-dimensional array type T whose component type is a
  13536. boolean type:  {bit string: see logical operators on boolean arrays}
  13537.  
  13538. 3
  13539.     function "and"(Left, Right : T) return T
  13540.     function "or" (Left, Right : T) return T
  13541.     function "xor"(Left, Right : T) return T
  13542.  
  13543.         3.a   To be honest:  For predefined operators, the parameter and
  13544.         result subtypes shown as T are actually the unconstrained subtype of
  13545.         the type.
  13546.  
  13547. 4   For boolean types, the predefined logical operators and, or, and xor
  13548. perform the conventional operations of conjunction, inclusive disjunction,
  13549. and exclusive disjunction, respectively.
  13550.  
  13551. 5   For modular types, the predefined logical operators are defined on a
  13552. bit-by-bit basis, using the binary representation of the value of the
  13553. operands to yield a binary representation for the result, where zero
  13554. represents False and one represents True.  If this result is outside the base
  13555. range of the type, a final subtraction by the modulus is performed to bring
  13556. the result into the base range of the type.
  13557.  
  13558. 6   The logical operators on arrays are performed on a component-by-component
  13559. basis on matching components (as for equality -- see 4.5.2), using the
  13560. predefined logical operator for the component type.  The bounds of the
  13561. resulting array are those of the left operand.
  13562.  
  13563.  
  13564.                               Dynamic Semantics
  13565.  
  13566. 7   {evaluation [short-circuit control form]} The short-circuit control forms
  13567. and then and or else deliver the same result as the corresponding predefined
  13568. and and or operators for boolean types, except that the left operand is
  13569. always evaluated first, and the right operand is not evaluated if the value
  13570. of the left operand determines the result.
  13571.  
  13572. 8   {Length_Check [partial]} {check, language-defined (Length_Check)} For the
  13573. logical operators on arrays, a check is made that for each component of the
  13574. left operand there is a matching component of the right operand, and vice
  13575. versa.  {Range_Check [partial]} {check, language-defined (Range_Check)} Also,
  13576. a check is made that each component of the result belongs to the component
  13577. subtype.  {Constraint_Error (raised by failure of run-time check)} The
  13578. exception Constraint_Error is raised if either of the above checks fails.
  13579.  
  13580.         8.a   Discussion:  The check against the component subtype is per
  13581.         AI-00535.
  13582.      NOTES
  13583. 9    (12) The conventional meaning of the logical operators is given by the
  13584.      following truth table:
  13585.  
  13586. 10
  13587.                 A               B           (A and B)        (A or B)       (A \
  13588. xor B)
  13589.  
  13590.                  True            True            True            True          \
  13591.   False
  13592.                  True            False           False           True          \
  13593.   True
  13594.                  False           True            False           True          \
  13595.   True
  13596.                  False           False           False           False         \
  13597.   False
  13598.  
  13599.  
  13600.                                   Examples
  13601.  
  13602. 11   Examples of logical operators:
  13603.  
  13604. 12  Sunny or Warm
  13605.     Filter(1 .. 10) and Filter(15 .. 24)   --   see 3.6.1
  13606.  
  13607. 13   Examples of short-circuit control forms:
  13608.  
  13609. 14  Next_Car.Owner /= null and then Next_Car.Owner.Age > 25   --   see 3.10.1
  13610.     N = 0 or else A(N) = Hit_Value
  13611.  
  13612.  
  13613.  
  13614. 4.5.2 Relational Operators and Membership Tests
  13615.  
  13616. 1   [{relational operator} {operator (relational)} {comparison operator: see
  13617. relational operator} {equality operator} {operator (equality)} The equality
  13618. operators = (equals) and /= (not equals) are predefined for nonlimited types.
  13619. {ordering operator} {operator (ordering)} The other relational_operators are
  13620. the ordering operators < (less than), <= (less than or equal), > (greater
  13621. than), and >= (greater than or equal).  {= operator} {operator (=)} {equal
  13622. operator} {operator (equal)} {/= operator} {operator (/=)} {not equal
  13623. operator} {operator (not equal)} {< operator} {operator (<)} {less than
  13624. operator} {operator (less than)} {<= operator} {operator (<=)} {less than or
  13625. equal operator} {operator (less than or equal)} {> operator} {operator (>)}
  13626. {greater than operator} {operator (greater than)} {>= operator} {operator
  13627. (>=)} {greater than or equal operator} {operator (greater than or equal)}
  13628. {discrete array type} The ordering operators are predefined for scalar types,
  13629. and for discrete array types, that is, one-dimensional array types whose
  13630. components are of a discrete type.
  13631.  
  13632.         1.a   Ramification:  The equality operators are not defined for every
  13633.         nonlimited type -- see below for the exact rule.
  13634.  
  13635. 2   {membership test} {in (membership test)} {not in (membership test)} A
  13636. membership test, using in or not in, determines whether or not a value
  13637. belongs to a given subtype or range, or has a tag that identifies a type that
  13638. is covered by a given type.  Membership tests are allowed for all types.]
  13639.  
  13640.  
  13641.                             Name Resolution Rules
  13642.  
  13643. 3   {expected type [membership test simple_expression]} {tested type (of a
  13644. membership test)} The tested type of a membership test is the type of the
  13645. range or the type determined by the subtype_mark.  If the tested type is
  13646. tagged, then the simple_expression shall resolve to be of a type that covers
  13647. or is covered by the tested type; if untagged, the expected type for the
  13648. simple_expression is the tested type.
  13649.  
  13650.         3.a   Reason:  The part of the rule for untagged types is stated in a
  13651.         way that ensures that operands like null are still legal as operands
  13652.         of a membership test.
  13653.  
  13654.         3.b   The significance of ``covers or is covered by'' is that we
  13655.         allow the simple_expression to be of any class-wide type that covers
  13656.         the tested type, not just the one rooted at the tested type.
  13657.  
  13658.  
  13659.                                Legality Rules
  13660.  
  13661. 4   For a membership test, if the simple_expression is of a tagged class-wide
  13662. type, then the tested type shall be (visibly) tagged.
  13663.  
  13664.         4.a   Ramification:  Untagged types covered by the tagged class-wide
  13665.         type are not permitted.  Such types can exist if they are descendants
  13666.         of a private type whose full type is tagged.  This rule is intended
  13667.         to avoid confusion since such derivatives don't have their ``own''
  13668.         tag, and hence are indistinguishable from one another at run time
  13669.         once converted to a covering class-wide type.
  13670.  
  13671.  
  13672.                               Static Semantics
  13673.  
  13674. 5   The result type of a membership test is the predefined type Boolean.
  13675.  
  13676. 6   The equality operators are predefined for every specific type T that is
  13677. not limited, and not an anonymous access type, with the following
  13678. specifications:
  13679.  
  13680. 7   function "=" (Left, Right : T) return Boolean
  13681.     function "/="(Left, Right : T) return Boolean
  13682.  
  13683. 8   The ordering operators are predefined for every specific scalar type T,
  13684. and for every discrete array type T, with the following specifications:
  13685.  
  13686. 9   function "<" (Left, Right : T) return Boolean
  13687.     function "<="(Left, Right : T) return Boolean
  13688.     function ">" (Left, Right : T) return Boolean
  13689.     function ">="(Left, Right : T) return Boolean
  13690.  
  13691.  
  13692.                               Dynamic Semantics
  13693.  
  13694. 10   For discrete types, the predefined relational operators are defined in
  13695. terms of corresponding mathematical operations on the position numbers of the
  13696. values of the operands.
  13697.  
  13698. 11   For real types, the predefined relational operators are defined in terms
  13699. of the corresponding mathematical operations on the values of the operands,
  13700. subject to the accuracy of the type.
  13701.  
  13702.         11.a   Ramification:  For floating point types, the results of
  13703.         comparing nearly equal values depends on the accuracy of the
  13704.         implementation (see G.2.1, ``Model of Floating Point Arithmetic'' for
  13705.         implementations that support the Numerics Annex).  {94-4481.a}
  13706.  
  13707.         11.b   Implementation Note:  On a machine with signed zeros, if the
  13708.         generated code generates both plus zero and minus zero, plus and
  13709.         minus zero must be equal by the predefined equality operators.
  13710.         {94-4539.c}
  13711.  
  13712. 12   Two access-to-object values are equal if they designate the same object,
  13713. or if both are equal to the null value of the access type.
  13714.  
  13715. 13   Two access-to-subprogram values are equal if they are the result of the
  13716. same evaluation of an Access attribute_reference, or if both are equal to the
  13717. null value of the access type.  Two access-to-subprogram values are unequal
  13718. if they designate different subprograms.  {unspecified [partial]} [It is
  13719. unspecified whether two access values that designate the same subprogram but
  13720. are the result of distinct evaluations of Access attribute_references are
  13721. equal or unequal.]
  13722.  
  13723.         13.a   Reason:  This allows each Access attribute_reference for a
  13724.         subprogram to designate a distinct ``wrapper'' subprogram if
  13725.         necessary to support an indirect call.
  13726.  
  13727. 14   {equality operator (special inheritance rule for tagged types)} For a
  13728. type extension, predefined equality is defined in terms of the primitive
  13729. [(possibly user-defined)] equals operator of the parent type and of any
  13730. tagged components of the extension part, and predefined equality for any
  13731. other components not inherited from the parent type.
  13732.  
  13733.         14.a   Ramification:  Two values of a type extension are not equal if
  13734.         there is a variant_part in the extension part and the two values have
  13735.         different variants present.  This is a ramification of the
  13736.         requirement that a discriminant governing such a variant_part has to
  13737.         be a ``new'' discriminant, and so has to be equal in the two values
  13738.         for the values to be equal.  Note that variant_parts in the parent
  13739.         part need not match if the primitive equals operator for the parent
  13740.         type considers them equal.
  13741.  
  13742. 15   For a private type, if its full type is tagged, predefined equality is
  13743. defined in terms of the primitive equals operator of the full type; if the
  13744. full type is untagged, predefined equality for the private type is that of
  13745. its full type.
  13746.  
  13747. 16   {matching components} For other composite types, the predefined equality
  13748. operators [(and certain other predefined operations on composite types -- see
  13749. 4.5.1 and 4.6)] are defined in terms of the corresponding operation on
  13750. matching components, defined as follows:
  13751.  
  13752.    17  For two composite objects or values of the same non-array type,
  13753.        matching components are those that correspond to the same
  13754.        component_declaration or discriminant_specification; {94-4667.f}
  13755.  
  13756.    18  For two one-dimensional arrays of the same type, matching
  13757.        components are those (if any) whose index values match in the
  13758.        following sense: the lower bounds of the index ranges are defined
  13759.        to match, and the successors of matching indices are defined to
  13760.        match;
  13761.  
  13762.    19  For two multidimensional arrays of the same type, matching
  13763.        components are those whose index values match in successive index
  13764.        positions.
  13765.  
  13766. 20   The analogous definitions apply if the types of the two objects or
  13767. values are convertible, rather than being the same.
  13768.  
  13769.         20.a   Discussion:  Ada 83 seems to omit this part of the definition,
  13770.         though it is used in array type conversions.  See 4.6.
  13771.  
  13772. 21   Given the above definition of matching components, the result of the
  13773. predefined equals operator for composite types (other than for those
  13774. composite types covered earlier) is defined as follows:
  13775.  
  13776.    22  If there are no components, the result is defined to be True;
  13777.  
  13778.    23  If there are unmatched components, the result is defined to be
  13779.        False;
  13780.  
  13781.    24  Otherwise, the result is defined in terms of the primitive equals
  13782.        operator for any matching tagged components, and the predefined
  13783.        equals for any matching untagged components.
  13784.  
  13785.  24.a   Reason:  This asymmetry between tagged and untagged components
  13786.         is necessary to preserve upward compatibility and corresponds
  13787.         with the corresponding situation with generics, where the
  13788.         predefined operations ``reemerge'' in a generic for untagged
  13789.         types, but do not for tagged types.  Also, only tagged types
  13790.         support user-defined assignment (see 7.6), so only tagged types
  13791.         can fully handle levels of indirection in the implementation of
  13792.         the type.  For untagged types, one reason for a user-defined
  13793.         equals operator might be to allow values with different bounds
  13794.         or discriminants to compare equal in certain cases.  When such
  13795.         values are matching components, the bounds or discriminants will
  13796.         necessarily match anyway if the discriminants of the enclosing
  13797.         values match.
  13798.  
  13799.         24.b   Ramification:  Two null arrays of the same type are always
  13800.         equal; two null records of the same type are always equal.
  13801.  
  13802.         24.c   Note that if a composite object has a component of a floating
  13803.         point type, and the floating point type has both a plus and minus
  13804.         zero, which are considered equal by the predefined equality, then a
  13805.         block compare cannot be used for the predefined composite equality.
  13806.         Of course, with user-defined equals operators for tagged components,
  13807.         a block compare breaks down anyway, so this is not the only special
  13808.         case that requires component-by-component comparisons.  On a one's
  13809.         complement machine, a similar situation might occur for integer
  13810.         types, since one's complement machines typically have both a plus and
  13811.         minus (integer) zero.
  13812.  
  13813. 25   The predefined "/=" operator gives the complementary result to the
  13814. predefined "=" operator.
  13815.  
  13816.         25.a   Ramification:  Furthermore, if the user defines an "="
  13817.         operator that returns Boolean, then a "/=" operator is implicitly
  13818.         declared in terms of the user-defined "=" operator so as to give the
  13819.         complementary result.  See 6.6.
  13820.  
  13821. 26   {lexicographic order} For a discrete array type, the predefined ordering
  13822. operators correspond to lexicographic order using the predefined order
  13823. relation of the component type:  A null array is lexicographically less than
  13824. any array having at least one component.  In the case of nonnull arrays, the
  13825. left operand is lexicographically less than the right operand if the first
  13826. component of the left operand is less than that of the right; otherwise the
  13827. left operand is lexicographically less than the right operand only if their
  13828. first components are equal and the tail of the left operand is
  13829. lexicographically less than that of the right (the tail consists of the
  13830. remaining components beyond the first and can be null).
  13831.  
  13832. 27   {evaluation [membership test]} For the evaluation of a membership test,
  13833. the simple_expression and the range (if any) are evaluated in an arbitrary
  13834. order.
  13835.  
  13836. 28   A membership test using in yields the result True if:
  13837.  
  13838.    29  The tested type is scalar, and the value of the simple_expression
  13839.        belongs to the given range, or the range of the named subtype; or
  13840.  
  13841.  29.a   Ramification:  The scalar membership test only does a range
  13842.         check.  It does not perform any other check, such as whether a
  13843.         value falls in a ``hole'' of a ``holey'' enumeration type.  The
  13844.         Pos attribute function can be used for that purpose.
  13845.  
  13846.  29.b   Even though Standard.Float is an unconstrained subtype, the test
  13847.         ``X in Float'' will still return False (presuming the evaluation
  13848.         of X does not raise Constraint_Error) when X is outside
  13849.         Float'Range.
  13850.  
  13851.    30  The tested type is not scalar, and the value of the simple_
  13852.        expression satisfies any constraints of the named subtype, and,
  13853.        if the type of the simple_expression is class-wide, the value has
  13854.        a tag that identifies a type covered by the tested type.
  13855.  
  13856.  30.a   Ramification:  Note that the tag is not checked if the simple_
  13857.         expression is of a specific type.
  13858.  
  13859. 31   Otherwise the test yields the result False.
  13860.  
  13861. 32   A membership test using not in gives the complementary result to the
  13862. corresponding membership test using in.
  13863.  
  13864.  
  13865.      NOTES
  13866. 33   (13) No exception is ever raised by a membership test, by a predefined
  13867.      ordering operator, or by a predefined equality operator for an
  13868.      elementary type, but an exception can be raised by the evaluation of the
  13869.      operands.  A predefined equality operator for a composite type can only
  13870.      raise an exception if the type has a tagged part whose primitive equals
  13871.      operator propagates an exception.
  13872.  
  13873. 34   (14) If a composite type has components that depend on discriminants,
  13874.      two values of this type have matching components if and only if their
  13875.      discriminants are equal.  Two nonnull arrays have matching components if
  13876.      and only if the length of each dimension is the same for both.
  13877.  
  13878.  
  13879.                                   Examples
  13880.  
  13881. 35   Examples of expressions involving relational operators and membership
  13882. tests:
  13883.  
  13884. 36  X /= Y
  13885.  
  13886. 37  "" < "A" and "A" < "Aa"     --  True
  13887.     "Aa" < "B" and "A" < "A  "  --  True
  13888.  
  13889. 38  My_Car = null               -- true if My_Car has been set to null (see 3.1\
  13890. 0.1)
  13891.     My_Car = Your_Car           -- true if we both share the same car
  13892.     My_Car.all = Your_Car.all   -- true if the two cars are identical
  13893.  
  13894. 39  N not in 1 .. 10            -- range membership test
  13895.     Today in Mon .. Fri         -- range membership test
  13896.     Today in Weekday            -- subtype membership test (see 3.5.1)
  13897.     Archive in Disk_Unit        -- subtype membership test (see 3.8.1)
  13898.     Tree.all in Addition'Class  -- class membership test (see 3.9.1)
  13899.  
  13900.  
  13901.                             Extensions to Ada 83
  13902.  
  13903.         39.a   {extensions to Ada 83} Membership tests can be used to test
  13904.         the tag of a class-wide value.
  13905.  
  13906.         39.b   Predefined equality for a composite type is defined in terms
  13907.         of the primitive equals operator for tagged components or the parent
  13908.         part.
  13909.  
  13910.                          Wording Changes From Ada 83
  13911.  
  13912.         39.c   The term ``membership test'' refers to the relation "X in S"
  13913.         rather to simply the reserved word in or not in.
  13914.  
  13915.         39.d   We use the term ``equality operator'' to refer to both the =
  13916.         (equals) and /= (not equals) operators.  Ada 83 referred to = as the
  13917.         equality operator, and /= as the inequality operator.  The new
  13918.         wording is more consistent with the ISO 10646 name for "=" (equals
  13919.         sign) and provides a category similar to ``ordering operator'' to
  13920.         refer to both = and /=.
  13921.  
  13922.         39.e   We have changed the term ``catenate'' to ``concatenate''.
  13923.  
  13924.  
  13925.  
  13926. 4.5.3 Binary Adding Operators
  13927.  
  13928.                               Static Semantics
  13929.  
  13930. 1   {binary adding operator} {operator (binary adding)} {+ operator}
  13931. {operator (+)} {plus operator} {operator (plus)} {- operator} {operator (-)}
  13932. {minus operator} {operator (minus)} The binary adding operators + (addition)
  13933. and - (subtraction) are predefined for every specific numeric type T with
  13934. their conventional meaning.  They have the following specifications:
  13935.  
  13936. 2   function "+"(Left, Right : T) return T
  13937.     function "-"(Left, Right : T) return T
  13938.  
  13939. 3   {& operator} {operator (&)} {ampersand operator} {operator (ampersand)}
  13940. {concatenation operator} {operator (concatenation)} {catenation operator: see
  13941. concatenation operator} The concatenation operators & are predefined for
  13942. every nonlimited, one-dimensional array type T with component type C.  They
  13943. have the following specifications:
  13944.  
  13945. 4   function "&"(Left : T; Right : T) return T
  13946.     function "&"(Left : T; Right : C) return T
  13947.     function "&"(Left : C; Right : T) return T
  13948.     function "&"(Left : C; Right : C) return T
  13949.  
  13950.  
  13951.                               Dynamic Semantics
  13952.  
  13953. 5   {evaluation [concatenation]} For the evaluation of a concatenation with
  13954. result type T, if both operands are of type T, the result of the
  13955. concatenation is a one-dimensional array whose length is the sum of the
  13956. lengths of its operands, and whose components comprise the components of the
  13957. left operand followed by the components of the right operand.  If the left
  13958. operand is a null array, the result of the concatenation is the right
  13959. operand.  Otherwise, the lower bound of the result is determined as follows:
  13960.  
  13961.     6  If the ultimate ancestor of the array type was defined by a
  13962.        constrained_array_definition, then the lower bound of the result
  13963.        is that of the index subtype;
  13964.  
  13965.  6.a    Reason:  This rule avoids Constraint_Error when using
  13966.         concatenation on an array type whose first subtype is
  13967.         constrained.
  13968.  
  13969.     7  If the ultimate ancestor of the array type was defined by an
  13970.        unconstrained_array_definition, then the lower bound of the
  13971.        result is that of the left operand.
  13972.  
  13973. 8   [The upper bound is determined by the lower bound and the length.]
  13974. {Index_Check [partial]} {check, language-defined (Index_Check)} A check is
  13975. made that the upper bound of the result of the concatenation belongs to the
  13976. range of the index subtype, unless the result is a null array.  {Constraint_
  13977. Error (raised by failure of run-time check)} Constraint_Error is raised if
  13978. this check fails.
  13979.  
  13980. 9   If either operand is of the component type C, the result of the
  13981. concatenation is given by the above rules, using in place of such an operand
  13982. an array having this operand as its only component (converted to the
  13983. component subtype) and having the lower bound of the index subtype of the
  13984. array type as its lower bound.  {implicit subtype conversion [operand of
  13985. concatenation]}
  13986.         9.a   Ramification:  The conversion might raise Constraint_Error.
  13987.         The conversion provides ``sliding'' for the component in the case of
  13988.         an array-of-arrays, consistent with the normal Ada 9X rules that
  13989.         allow sliding during parameter passing.
  13990.  
  13991. 10   {assignment operation (during evaluation of concatenation)} The result
  13992. of a concatenation is defined in terms of an assignment to an anonymous
  13993. object, as for any function call (see 6.5).
  13994.  
  13995.         10.a   Ramification:  This implies that value adjustment is performed
  13996.         as appropriate -- see 7.6.  We don't bother saying this for other
  13997.         predefined operators, even though they are all function calls,
  13998.         because this is the only one where it matters.  It is the only one
  13999.         that can return a value having controlled parts.
  14000.  
  14001.  
  14002.      NOTES
  14003. 11   (15) As for all predefined operators on modular types, the binary adding
  14004.      operators + and - on modular types include a final reduction modulo the
  14005.      modulus if the result is outside the base range of the type.
  14006.  
  14007.    11.a   Implementation Note:  A full "modulus" operation need not be
  14008.         performed after addition or subtraction of modular types.  For binary
  14009.         moduli, a simple mask is sufficient.  For nonbinary moduli, a check
  14010.         after addition to see if the value is greater than the high bound of
  14011.         the base range can be followed by a conditional subtraction of the
  14012.         modulus.  Conversely, a check after subtraction to see if a "borrow"
  14013.         was performed can be followed by a conditional addition of the
  14014.         modulus.
  14015.  
  14016.  
  14017.                                   Examples
  14018.  
  14019. 12   Examples of expressions involving binary adding operators:
  14020.  
  14021. 13  Z + 0.1      --  Z has to be of a real type
  14022.  
  14023. 14  "A" & "BCD"  --  concatenation of two string literals
  14024.     'A' & "BCD"  --  concatenation of a character literal and a string literal
  14025.     'A' & 'A'    --  concatenation of two character literals
  14026.  
  14027.  
  14028.                          Inconsistencies With Ada 83
  14029.  
  14030.         14.a   {inconsistencies with Ada 83} The lower bound of the result of
  14031.         concatenation, for a type whose first subtype is constrained, is now
  14032.         that of the index subtype.  This is inconsistent with Ada 83, but
  14033.         generally only for Ada 83 programs that raise Constraint_Error.  For
  14034.         example, the concatenation operator in
  14035.  
  14036. 14.b        X : array(1..10) of Integer;
  14037.             begin
  14038.             X := X(6..10) & X(1..5);
  14039.  
  14040.         14.c   would raise Constraint_Error in Ada 83 (because the bounds of
  14041.         the result of the concatenation would be 6..15, which is outside of
  14042.         1..10), but would succeed and swap the halves of X (as expected) in
  14043.         Ada 9X.
  14044.  
  14045.                             Extensions to Ada 83
  14046.  
  14047.         14.d   {extensions to Ada 83} Concatenation is now useful for array
  14048.         types whose first subtype is constrained.  When the result type of a
  14049.         concatenation is such an array type, Constraint_Error is avoided by
  14050.         effectively first sliding the left operand (if nonnull) so that its
  14051.         lower bound is that of the index subtype.
  14052.  
  14053.  
  14054.  
  14055. 4.5.4 Unary Adding Operators
  14056.  
  14057.                               Static Semantics
  14058.  
  14059. 1   {unary adding operator} {operator (unary adding)} {+ operator} {operator
  14060. (+)} {plus operator} {operator (plus)} {- operator} {operator (-)} {minus
  14061. operator} {operator (minus)} The unary adding operators + (identity) and -
  14062. (negation) are predefined for every specific numeric type T with their
  14063. conventional meaning.  They have the following specifications:
  14064.  
  14065. 2   function "+"(Right : T) return T
  14066.     function "-"(Right : T) return T
  14067.  
  14068.  
  14069.      NOTES
  14070. 3    (16) For modular integer types, the unary adding operator -, when given
  14071.      a nonzero operand, returns the result of subtracting the value of the
  14072.      operand from the modulus; for a zero operand, the result is zero.
  14073.  
  14074.  
  14075.  
  14076. 4.5.5 Multiplying Operators
  14077.  
  14078.                               Static Semantics
  14079.  
  14080. 1   {multiplying operator} {operator (multiplying)} {* operator} {operator
  14081. (*)} {multiply operator} {operator (multiply)} {times operator} {operator
  14082. (times)} {/ operator} {operator (/)} {divide operator} {operator (divide)}
  14083. {mod operator} {operator (mod)} {rem operator} {operator (rem)} The
  14084. multiplying operators * (multiplication), / (division), mod (modulus), and
  14085. rem (remainder) are predefined for every specific integer type T:
  14086.  
  14087. 2   function "*"  (Left, Right : T) return T
  14088.     function "/"  (Left, Right : T) return T
  14089.     function "mod"(Left, Right : T) return T
  14090.     function "rem"(Left, Right : T) return T
  14091.  
  14092. 3   Signed integer multiplication has its conventional meaning.
  14093.  
  14094. 4   Signed integer division and remainder are defined by the relation:
  14095.  
  14096. 5   A = (A/B)*B + (A rem B)
  14097.  
  14098. 6   where (A rem B) has the sign of A and an absolute value less than the
  14099. absolute value of B. Signed integer division satisfies the identity:
  14100.  
  14101. 7   (-A)/B = -(A/B) = A/(-B)
  14102.  
  14103. 8   The signed integer modulus operator is defined such that the result of A
  14104. mod B has the sign of B and an absolute value less than the absolute value of
  14105. B; in addition, for some signed integer value N, this result satisfies the
  14106. relation:
  14107.  
  14108. 9   A = B*N + (A mod B)
  14109.  
  14110. 10   [The multiplying operators on modular types are defined in terms of the
  14111. corresponding signed integer operators, followed by a reduction modulo the
  14112. modulus if the result is outside the base range of the type [(which is only
  14113. possible for the "*" operator)].]
  14114.  
  14115.         10.a   Ramification:  The above identity satisfied by signed integer
  14116.         division is not satisfied by modular division because of the
  14117.         difference in effect of negation.
  14118.  
  14119. 11   Multiplication and division operators are predefined for every specific
  14120. floating point type T:
  14121.  
  14122. 12  function "*"(Left, Right : T) return T
  14123.     function "/"(Left, Right : T) return T
  14124.  
  14125. 13   The following multiplication and division operators, with an operand of
  14126. the predefined type Integer, are predefined for every specific fixed point
  14127. type T:
  14128.  
  14129. 14  function "*"(Left : T; Right : Integer) return T
  14130.     function "*"(Left : Integer; Right : T) return T
  14131.     function "/"(Left : T; Right : Integer) return T
  14132.  
  14133. 15   [All of the above multiplying operators are usable with an operand of an
  14134. appropriate universal numeric type.]  The following additional multiplying
  14135. operators for root_real are predefined[, and are usable when both operands
  14136. are of an appropriate universal or root numeric type, and the result is
  14137. allowed to be of type root_real, as in a number_declaration]:
  14138.  
  14139.         15.a   Ramification:  These operators are analogous to the
  14140.         multiplying operators involving fixed or floating point types where
  14141.         root_real substitutes for the fixed or floating point type, and root_
  14142.         integer substitutes for Integer.  Only values of the corresponding
  14143.         universal numeric types are implicitly convertible to these root
  14144.         numeric types, so these operators are really restricted to use with
  14145.         operands of a universal type, or the specified root numeric types.
  14146.  
  14147. 16  function "*"(Left, Right : root_real) return root_real
  14148.     function "/"(Left, Right : root_real) return root_real
  14149.  
  14150. 17  function "*"(Left : root_real; Right : root_integer) return root_real
  14151.     function "*"(Left : root_integer; Right : root_real) return root_real
  14152.     function "/"(Left : root_real; Right : root_integer) return root_real
  14153.  
  14154. 18   Multiplication and division between any two fixed point types are
  14155. provided by the following two predefined operators:
  14156.  
  14157.         18.a   Ramification:  Universal_fixed is the universal type for the
  14158.         class of fixed point types, meaning that these operators take
  14159.         operands of any fixed point types (not necessarily the same) and
  14160.         return a result that is implicitly (or explicitly) convertible to any
  14161.         fixed point type.
  14162.  
  14163. 19  function "*"(Left, Right : universal_fixed) return universal_fixed
  14164.     function "/"(Left, Right : universal_fixed) return universal_fixed
  14165.  
  14166.  
  14167.                                Legality Rules
  14168.  
  14169. 20   The above two fixed-fixed multiplying operators shall not be used in a
  14170. context where the expected type for the result is itself universal_fixed --
  14171. [the context has to identify some other numeric type to which the result is
  14172. to be converted, either explicitly or implicitly].
  14173.  
  14174.         20.a   Discussion:  The small of universal_fixed is infinitesimal; no
  14175.         loss of precision is permitted.  However, fixed-fixed division is
  14176.         impractical to implement when an exact result is required, and
  14177.         multiplication will sometimes result in unanticipated overflows in
  14178.         such circumstances, so we require an explicit conversion to be
  14179.         inserted in expressions like A * B * C if A, B, and C are each of
  14180.         some fixed point type.
  14181.  
  14182.         20.b   On the other hand, X := A * B; is permitted by this rule, even
  14183.         if X, A, and B are all of different fixed point types, since the
  14184.         expected type for the result of the multiplication is the type of X,
  14185.         which is necessarily not universal_fixed.
  14186.                               Dynamic Semantics
  14187.  
  14188. 21   The multiplication and division operators for real types have their
  14189. conventional meaning.[For floating point types, the accuracy of the result is
  14190. determined by the precision of the result type.  For decimal fixed point
  14191. types, the result is truncated toward zero if the mathematical result is
  14192. between two multiples of the small of the specific result type (possibly
  14193. determined by context); for ordinary fixed point types, if the mathematical
  14194. result is between two multiples of the small, it is unspecified which of the
  14195. two is the result.  {unspecified [partial]}]
  14196.  
  14197. 22   {Division_Check [partial]} {check, language-defined (Division_Check)}
  14198. {Constraint_Error (raised by failure of run-time check)} The exception
  14199. Constraint_Error is raised by integer division, rem, and mod if the right
  14200. operand is zero.  [Similarly, for a real type T with T'Machine_Overflows
  14201. True, division by zero raises Constraint_Error.]
  14202.  
  14203.  
  14204.      NOTES
  14205. 23   (17) For positive A and B, A/B is the quotient and A rem B is the
  14206.      remainder when A is divided by B. The following relations are satisfied
  14207.      by the rem operator:
  14208.  
  14209. 24         A  rem (-B) =   A rem B
  14210.          (-A) rem   B  = -(A rem B)
  14211.  
  14212. 25   (18) For any signed integer K, the following identity holds:
  14213.  
  14214. 26       A mod B   =   (A + K*B) mod B
  14215.  
  14216. 27The relations between signed integer  division, remainder, and
  14217.      modulus are  illustrated by the following table:
  14218.  
  14219. 28       A      B   A/B   A rem B  A mod B     A     B    A/B   A rem B   A mod\
  14220.  B
  14221.  
  14222. 29       10     5    2       0        0       -10    5    -2       0         0
  14223.          11     5    2       1        1       -11    5    -2      -1         4
  14224.          12     5    2       2        2       -12    5    -2      -2         3
  14225.          13     5    2       3        3       -13    5    -2      -3         2
  14226.          14     5    2       4        4       -14    5    -2      -4         1
  14227.  
  14228. 30       A      B   A/B   A rem B  A mod B     A     B    A/B   A rem B   A mod\
  14229.  B
  14230.          10    -5   -2       0        0       -10   -5     2       0         0
  14231.          11    -5   -2       1       -4       -11   -5     2      -1        -1
  14232.          12    -5   -2       2       -3       -12   -5     2      -2        -2
  14233.          13    -5   -2       3       -2       -13   -5     2      -3        -3
  14234.          14    -5   -2       4       -1       -14   -5     2      -4        -4
  14235.  
  14236.  
  14237.                                   Examples
  14238.  
  14239. 31   Examples of expressions involving multiplying operators:
  14240.  
  14241. 32  I : Integer := 1;
  14242.     J : Integer := 2;
  14243.     K : Integer := 3;
  14244.  
  14245. 33  X : Real := 1.0;                      --     see 3.5.7
  14246.     Y : Real := 2.0;
  14247.  
  14248. 34  F : Fraction := 0.25;                 --     see 3.5.9
  14249.     G : Fraction := 0.5;
  14250.  
  14251. 35
  14252.     Expression                Value           Result Type
  14253.  
  14254.     I*J                       2               same as I and J, that is, Integer
  14255.     K/J                       1               same as K and J, that is, Integer
  14256.     K mod J                   1               same as K and J, that is, Integer
  14257.  
  14258.     X/Y                       0.5             same as X and Y, that is, Real
  14259.     F/2                       0.125           same as F, that is, Fraction
  14260.  
  14261.     3*F                       0.75            same as F, that is, Fraction
  14262.     0.75*G                    0.375           universal_fixed, implicitly conve\
  14263. rtible
  14264.                                               to any fixed point type
  14265.     Fraction(F*G)             0.125           Fraction, as stated by the conver\
  14266. sion
  14267.     Real(J)*Y                 4.0             Real, the type of both operands a\
  14268. fter
  14269.                                               conversion of J
  14270.  
  14271.  
  14272.                             Extensions to Ada 83
  14273.  
  14274.         35.a   {extensions to Ada 83} Explicit conversion of the result of
  14275.         multiplying or dividing two fixed point numbers is no longer
  14276.         required, provided the context uniquely determines some specific
  14277.         fixed point result type.  This is to improve support for decimal
  14278.         fixed point, where requiring explicit conversion on every fixed-fixed
  14279.         multiply or divide was felt to be inappropriate.
  14280.  
  14281.         35.b   The type universal_fixed is covered by universal_real, so real
  14282.         literals and fixed point operands may be multiplied or divided
  14283.         directly, without any explicit conversions required.
  14284.  
  14285.                          Wording Changes From Ada 83
  14286.  
  14287.         35.c   We have used the normal syntax for function definition rather
  14288.         than a tabular format.
  14289.  
  14290.  
  14291.  
  14292. 4.5.6 Highest Precedence Operators
  14293.  
  14294.                               Static Semantics
  14295.  
  14296. 1   {highest precedence operator} {operator (highest precedence)} {abs
  14297. operator} {operator (abs)} {absolute value} The highest precedence unary
  14298. operator abs (absolute value) is predefined for every specific numeric type
  14299. T, with the following specification:
  14300.  
  14301. 2   function "abs"(Right : T) return T
  14302.  
  14303. 3   {not operator} {operator (not)} {logical operator: see also not operator}
  14304. The highest precedence unary operator not (logical negation) is predefined
  14305. for every boolean type T, every modular type T, and for every one-dimensional
  14306. array type T whose components are of a boolean type, with the following
  14307. specification:
  14308.  
  14309. 4   function "not"(Right : T) return T
  14310.  
  14311. 5   The result of the operator not for a modular type is defined as the
  14312. difference between the high bound of the base range of the type and the value
  14313. of the operand.  [For a binary modulus, this corresponds to a bit-wise
  14314. complement of the binary representation of the value of the operand.]
  14315.  
  14316. 6   The operator not that applies to a one-dimensional array of boolean
  14317. components yields a one-dimensional boolean array with the same bounds; each
  14318. component of the result is obtained by logical negation of the corresponding
  14319. component of the operand (that is, the component that has the same index
  14320. value).  {Range_Check [partial]} {check, language-defined (Range_Check)}
  14321. {Constraint_Error (raised by failure of run-time check)} A check is made that
  14322. each component of the result belongs to the component subtype; the exception
  14323. Constraint_Error is raised if this check fails.
  14324.  
  14325.         6.a   Discussion:  The check against the component subtype is per
  14326.         AI-00535.
  14327.  
  14328. 7   {exponentiation operator} {operator (exponentiation)} {** operator}
  14329. {operator (**)} The highest precedence exponentiation operator ** is
  14330. predefined for every specific integer type T with the following
  14331. specification:  {94-4693.v}
  14332.  
  14333. 8   function "**"(Left : T; Right : Natural) return T
  14334.  
  14335. 9   Exponentiation is also predefined for every specific floating point type
  14336. as well as root_real, with the following specification (where T is root_real
  14337. or the floating point type):
  14338.  
  14339. 10  function "**"(Left : T; Right : Integer'Base) return T
  14340.  
  14341. 11   {exponent} The right operand of an exponentiation is the exponent.  The
  14342. expression X**N with the value of the exponent N positive is equivalent to
  14343. the expression X*X*...X (with N-1 multiplications) except that the
  14344. multiplications are associated in an arbitrary order.  With N equal to zero,
  14345. the result is one.  With the value of N negative [(only defined for a
  14346. floating point operand)], the result is the reciprocal of the result using
  14347. the absolute value of N as the exponent.
  14348.  
  14349.         11.a   Ramification:  The language does not specify the order of
  14350.         association of the multiplications inherent in an exponentiation.
  14351.         For a floating point type, the accuracy of the result might depend on
  14352.         the particular association order chosen.
  14353.  
  14354.  
  14355.                          Implementation Permissions
  14356.  
  14357. 12   {Constraint_Error (raised by failure of run-time check)} The
  14358. implementation of exponentiation for the case of a negative exponent is
  14359. allowed to raise Constraint_Error if the intermediate result of the repeated
  14360. multiplications is outside the safe range of the type, even though the final
  14361. result (after taking the reciprocal) would not be.  (The best machine
  14362. approximation to the final result in this case would generally be 0.0.)
  14363.  
  14364.  
  14365.      NOTES
  14366. 13   (19) {Range_Check [partial]} {check, language-defined (Range_Check)} As
  14367.      implied by the specification given above for exponentiation of an
  14368.      integer type, a check is made that the exponent is not negative.
  14369.      {Constraint_Error (raised by failure of run-time check)} Constraint_
  14370.      Error is raised if this check fails.
  14371.  
  14372.  
  14373.                          Wording Changes From Ada 83
  14374.  
  14375.         13.a   We now show the specification for "**" for integer types with
  14376.         a parameter subtype of Natural rather than Integer for the exponent.
  14377.         This reflects the fact that Constraint_Error is raised if a negative
  14378.         value is provided for the exponent.
  14379.  
  14380.  
  14381.  
  14382. 4.6 Type Conversions
  14383.  
  14384. 1   [Explicit type conversions, both value conversions and view conversions,
  14385. are allowed between closely related types as defined below.  This clause also
  14386. defines rules for value and view conversions to a particular subtype of a
  14387. type, both explicit ones and those implicit in other constructs.  {subtype
  14388. conversion: see type conversion} {type conversion} {conversion} {cast: see
  14389. type conversion} ]{subtype conversion: see also implicit subtype conversion}
  14390. {type conversion, implicit: see implicit subtype conversion}
  14391.                                    Syntax
  14392.  
  14393. 2   type_conversion ::=
  14394.         subtype_mark(expression)
  14395.       | subtype_mark(name)
  14396.  
  14397.  
  14398. 3   {target subtype (of a type_conversion)} The target subtype of a type_
  14399. conversion is the subtype denoted by the subtype_mark.  {operand (of a type_
  14400. conversion)} The operand of a type_conversion is the expression or name
  14401. within the parentheses; {operand type (of a type_conversion)} its type is the
  14402. operand type.
  14403.  
  14404. 4   {convertible} One type is convertible to a second type if a type_
  14405. conversion with the first type as operand type and the second type as target
  14406. type is legal according to the rules of this clause.  Two types are
  14407. convertible if each is convertible to the other.
  14408.  
  14409.         4.a   Ramification:  Note that ``convertible'' is defined in terms of
  14410.         legality of the conversion.  Whether the conversion would raise an
  14411.         exception at run time is irrelevant to this definition.
  14412.  
  14413. 5   {view conversion} {conversion (view)} A type_conversion whose operand is
  14414. the name of an object is called a view conversion if its target type is
  14415. tagged, or if it appears as an actual parameter of mode out or in out; {value
  14416. conversion} {conversion (value)} other type_conversions are called value
  14417. conversions.  {super: see view conversion}
  14418.  
  14419.         5.a   Ramification:  A view conversion to a tagged type can appear in
  14420.         any context that requires an object name, including in an object
  14421.         renaming, the prefix of a selected_component, and if the operand is a
  14422.         variable, on the left side of an assignment_statement.  View
  14423.         conversions to other types only occur as actual parameters.  Allowing
  14424.         view conversions of untagged types in all contexts seemed to incur an
  14425.         undue implementation burden.
  14426.  
  14427.  
  14428.                             Name Resolution Rules
  14429.  
  14430. 6   {expected type [type_conversion operand]} The operand of a type_
  14431. conversion is expected to be of any type.
  14432.  
  14433.         6.a   Discussion:  This replaces the "must be determinable" wording
  14434.         of Ada 83.  This is equivalent to (but hopefully more intuitive than)
  14435.         saying that the operand of a type_conversion is a ``complete
  14436.         context.''
  14437.  
  14438. 7   The operand of a view conversion is interpreted only as a name; the
  14439. operand of a value conversion is interpreted as an expression.
  14440.  
  14441.         7.a   Reason:  This formally resolves the syntactic ambiguity between
  14442.         the two forms of type_conversion, not that it really matters.
  14443.  
  14444.  
  14445.                                Legality Rules
  14446.  
  14447. 8   {type conversion (numeric)} {conversion (numeric)} If the target type is
  14448. a numeric type, then the operand type shall be a numeric type.
  14449.  
  14450. 9   {type conversion (array)} {conversion (array)} If the target type is an
  14451. array type, then the operand type shall be an array type.  Further:
  14452.  
  14453.    10  The types shall have the same dimensionality;
  14454.  
  14455.    11  Corresponding index types shall be convertible; and {convertible
  14456.        [required]}
  14457.  
  14458.    12  The component subtypes shall statically match.  {statically
  14459.        matching [required]}
  14460.  
  14461. 13   {type conversion (access)} {conversion (access)} If the target type is a
  14462. general access type, then the operand type shall be an access-to-object type.
  14463. Further:
  14464.  
  14465.         13.a   Discussion:  The Legality Rules and Dynamic Semantics are
  14466.         worded so that a type_conversion T(X) (where T is an access type) is
  14467.         (almost) equivalent to the attribute_reference X.all'Access, where
  14468.         the result is of type T. The type_conversion accepts a null value,
  14469.         whereas the attribute_reference would raise Constraint_Error.
  14470.  
  14471.    14  If the target type is an access-to-variable type, then the
  14472.        operand type shall be an access-to-variable type;
  14473.  
  14474.  14.a   Ramification:  If the target type is an access-to-constant type,
  14475.         then the operand type can be access-to-constant or
  14476.         access-to-variable.
  14477.  
  14478.    15  If the target designated type is tagged, then the operand
  14479.        designated type shall be convertible to the target designated
  14480.        type; {convertible [required]}
  14481.  
  14482.    16  If the target designated type is not tagged, then the designated
  14483.        types shall be the same, and either the designated subtypes shall
  14484.        statically match or the target designated subtype shall be
  14485.        discriminated and unconstrained; and {statically matching
  14486.        [required]}
  14487.  
  14488.  16.a   Reason:  These rules are designed to ensure that aliased array
  14489.         objects only need "dope" if their nominal subtype is
  14490.         unconstrained, but they can always have dope if required by the
  14491.         run-time model (since no sliding is permitted as part of access
  14492.         type conversion).  By contrast, aliased discriminated objects
  14493.         will always need their discriminants stored with them, even if
  14494.         nominally constrained.  (Here, we are assuming an implementation
  14495.         that represents an access value as a single pointer.)
  14496.  
  14497.    17  {accessibility rule [type conversion]} The accessibility level of
  14498.        the operand type shall not be statically deeper than that of the
  14499.        target type.  {94-4715.a} {generic contract issue [partial]} In
  14500.        addition to the places where Legality Rules normally apply (see
  14501.        12.3), this rule applies also in the private part of an instance
  14502.        of a generic unit.
  14503.  
  14504.  17.a   Ramification:  The access parameter case is handled by a
  14505.         run-time check.  Run-time checks are also done in instance
  14506.         bodies.
  14507.  
  14508. 18   {type conversion (access)} {conversion (access)} If the target type is
  14509. an access-to-subprogram type, then the operand type shall be an
  14510. access-to-subprogram type.  Further:
  14511.  
  14512.    19  The designated profiles shall be subtype-conformant.  {subtype
  14513.        conformance (required)}
  14514.  
  14515.    20  {accessibility rule [type conversion]} The accessibility level of
  14516.        the operand type shall not be statically deeper than that of the
  14517.        target type.  {94-4715.a} {generic contract issue [partial]} In
  14518.        addition to the places where Legality Rules normally apply (see
  14519.        12.3), this rule applies also in the private part of an instance
  14520.        of a generic unit.  If the operand type is declared within a
  14521.        generic body, the target type shall be declared within the
  14522.        generic body.  {94-4692.a} {94-4702.a} {94-4706.a} {94-4708.a}
  14523.  
  14524.  20.a   Reason:  The reason it is illegal to convert from an
  14525.         access-to-subprogram type declared in a generic body to one
  14526.         declared outside that body is that in an implementation that
  14527.         shares generic bodies, procedures declared inside the generic
  14528.         need to have a different calling convention -- they need an
  14529.         extra parameter pointing to the data declared in the current
  14530.         instance.  For procedures declared in the spec, that's OK,
  14531.         because the compiler can know about them at compile time of the
  14532.         instantiation.
  14533.  
  14534. 21   {type conversion (enumeration)} {conversion (enumeration)} {type
  14535. conversion (composite (non-array))} {conversion (composite (non-array))} If
  14536. the target type is not included in any of the above four cases, there shall
  14537. be a type that is an ancestor of both the target type and the operand type.
  14538. Further, if the target type is tagged, then either:
  14539.  
  14540.    22  The operand type shall be covered by or descended from the target
  14541.        type; or
  14542.  
  14543.  22.a   Ramification:  This is a conversion toward the root, which is
  14544.         always safe.
  14545.  
  14546.    23  The operand type shall be a class-wide type that covers the
  14547.        target type.
  14548.  
  14549.  23.a   Ramification:  This is a conversion of a class-wide type toward
  14550.         the leaves, which requires a tag check.  See Dynamic Semantics.
  14551.  
  14552.  23.b   These two rules imply that a conversion from a parent type to a
  14553.         type extension is not permitted, as this would require
  14554.         specifying the values for additional components, in general, and
  14555.         changing the tag.  An extension_aggregate has to be used
  14556.         instead, constructing a new value, rather than converting an
  14557.         existing value.  However, a conversion from the class-wide type
  14558.         rooted at the parent type is permitted; such a conversion just
  14559.         verifies that the operand's tag is a descendant of the target.
  14560.  
  14561. 24   In a view conversion for an untagged type, the target type shall be
  14562. convertible (back) to the operand type.
  14563.  
  14564.         24.a   Reason:  Untagged view conversions appear only as [in] out
  14565.         parameters.  Hence, the reverse conversion must be legal as well.
  14566.         The forward conversion must be legal even if an out parameter,
  14567.         because actual parameters of an access type are always copied in
  14568.         anyway.
  14569.  
  14570.  
  14571.                               Static Semantics
  14572.  
  14573. 25   A type_conversion that is a value conversion denotes the value that is
  14574. the result of converting the value of the operand to the target subtype.
  14575.  
  14576. 26   A type_conversion that is a view conversion denotes a view of the object
  14577. denoted by the operand.  This view is a variable of the target type if the
  14578. operand denotes a variable; otherwise it is a constant of the target type.
  14579.  
  14580. 27   {nominal subtype [associated with a type_conversion]} The nominal
  14581. subtype of a type_conversion is its target subtype.
  14582.  
  14583.  
  14584.                               Dynamic Semantics
  14585.  
  14586. 28   {evaluation [value conversion]} {corresponding value (of the target type
  14587. of a conversion)} {conversion} For the evaluation of a type_conversion that
  14588. is a value conversion, the operand is evaluated, and then the value of the
  14589. operand is converted to a corresponding value of the target type, if any.
  14590. {Range_Check [partial]} {check, language-defined (Range_Check)} {Constraint_
  14591. Error (raised by failure of run-time check)} If there is no value of the
  14592. target type that corresponds to the operand value, Constraint_Error is
  14593. raised[; this can only happen on conversion to a modular type, and only when
  14594. the operand value is outside the base range of the modular type.]  Additional
  14595. rules follow:  {94-4667.l}
  14596.  
  14597.    29  {type conversion (numeric)} {conversion (numeric)} Numeric Type
  14598.        Conversion
  14599.  
  14600.           30  If the target and the operand types are both integer
  14601.               types, then the result is the value of the target type
  14602.               that corresponds to the same mathematical integer as the
  14603.               operand.
  14604.  
  14605.           31  If the target type is a decimal fixed point type, then the
  14606.               result is truncated (toward 0) if the value of the operand
  14607.               is not a multiple of the small of the target type.
  14608.  
  14609.           32  {accuracy} If the target type is some other real type,
  14610.               then the result is within the accuracy of the target type
  14611.               (see G.2, ``Numeric Performance Requirements'', for
  14612.               implementations that support the Numerics Annex).
  14613.               {94-4481.a}
  14614.  
  14615.  32.a   Discussion:  An integer type might have more bits of precision
  14616.         than a real type, so on conversion (of a large integer), some
  14617.         precision might be lost.
  14618.  
  14619.           33  If the target type is an integer type and the operand type
  14620.               is real, the result is rounded to the nearest integer
  14621.               (away from zero if exactly halfway between two integers).
  14622.  
  14623.  33.a   Discussion:  This was implementation defined in Ada 83.  There
  14624.         seems no reason to preserve the nonportability in Ada 9X.
  14625.         Round-away-from-zero is the conventional definition of rounding,
  14626.         and standard Fortran and COBOL both specify rounding away from
  14627.         zero, so for interoperability, it seems important to pick this.
  14628.         This is also the most easily ``undone'' by hand.
  14629.         Round-to-nearest-even is an alternative, but that is quite
  14630.         complicated if not supported by the hardware.  In any case, this
  14631.         operation is not expected to be part of an inner loop, so
  14632.         predictability and portability are judged most important.  We
  14633.         anticipate that a floating point attribute function Unbiased_
  14634.         Rounding will be provided for those applications that require
  14635.         round-to-nearest-even.  ``Deterministic'' rounding is required
  14636.         for static conversions to integer as well.  See 4.9.
  14637.  
  14638.    34  {type conversion (enumeration)} {conversion (enumeration)}
  14639.        Enumeration Type Conversion
  14640.  
  14641.           35  The result is the value of the target type with the same
  14642.               position number as that of the operand value.
  14643.  
  14644.    36  {type conversion (array)} {conversion (array)} Array Type
  14645.        Conversion
  14646.  
  14647.           37  {Length_Check [partial]} {check, language-defined (Length_
  14648.               Check)} If the target subtype is a constrained array
  14649.               subtype, then a check is made that the length of each
  14650.               dimension of the value of the operand equals the length of
  14651.               the corresponding dimension of the target subtype.  The
  14652.               bounds of the result are those of the target subtype.
  14653.  
  14654.           38  {Range_Check [partial]} {check, language-defined (Range_
  14655.               Check)} If the target subtype is an unconstrained array
  14656.               subtype, then the bounds of the result are obtained by
  14657.               converting each bound of the value of the operand to the
  14658.               corresponding index type of the target type.  {implicit
  14659.               subtype conversion [array bounds]} For each nonnull index
  14660.               range, a check is made that the bounds of the range belong
  14661.               to the corresponding index subtype.
  14662.  
  14663.  38.a   Discussion:  Only nonnull index ranges are checked, per
  14664.         AI-00313.
  14665.  
  14666.           39  In either array case, the value of each component of the
  14667.               result is that of the matching component of the operand
  14668.               value (see 4.5.2).
  14669.  
  14670.  39.a   Ramification:  This applies whether or not the component is
  14671.         initialized.
  14672.  
  14673.    40  {type conversion (composite (non-array))} {conversion (composite
  14674.        (non-array))} Composite (Non-Array) Type Conversion
  14675.  
  14676.           41  The value of each nondiscriminant component of the result
  14677.               is that of the matching component of the operand value.
  14678.  
  14679.  41.a   Ramification:  This applies whether or not the component is
  14680.         initialized.
  14681.  
  14682.           42  [The tag of the result is that of the operand.]  {Tag_
  14683.               Check [partial]} {check, language-defined (Tag_Check)} If
  14684.               the operand type is class-wide, a check is made that the
  14685.               tag of the operand identifies a (specific) type that is
  14686.               covered by or descended from the target type.
  14687.  
  14688.  42.a   Ramification:  This check is certain to succeed if the operand
  14689.         type is itself covered by or descended from the target type.
  14690.  
  14691.  42.b   Proof:  The fact that a type_conversion preserves the tag is
  14692.         stated officially in 3.9, ``Tagged Types and Type Extensions''
  14693.  
  14694.           43  For each discriminant of the target type that corresponds
  14695.               to a discriminant of the operand type, its value is that
  14696.               of the corresponding discriminant of the operand value;
  14697.               {Discriminant_Check [partial]} {check, language-defined
  14698.               (Discriminant_Check)} if it corresponds to more than one
  14699.               discriminant of the operand type, a check is made that all
  14700.               these discriminants are equal in the operand value.
  14701.  
  14702.           44  For each discriminant of the target type that corresponds
  14703.               to a discriminant that is specified by the derived_type_
  14704.               definition for some ancestor of the operand type (or if
  14705.               class-wide, some ancestor of the specific type identified
  14706.               by the tag of the operand), its value in the result is
  14707.               that specified by the derived_type_definition.
  14708.  
  14709.  44.a   Ramification:  It is a ramification of the rules for the
  14710.         discriminants of derived types that each discriminant of the
  14711.         result is covered either by this paragraph or the previous one.
  14712.         See 3.7.
  14713.  
  14714.           45  {Discriminant_Check [partial]} {check, language-defined
  14715.               (Discriminant_Check)} For each discriminant of the operand
  14716.               type that corresponds to a discriminant that is specified
  14717.               by the derived_type_definition for some ancestor of the
  14718.               target type, a check is made that in the operand value it
  14719.               equals the value specified for it.
  14720.  
  14721.           46  {Range_Check [partial]} {check, language-defined (Range_
  14722.               Check)} For each discriminant of the result, a check is
  14723.               made that its value belongs to its subtype.
  14724.  
  14725.    47  {type conversion (access)} {conversion (access)} Access Type
  14726.        Conversion
  14727.  
  14728.           48  {Accessibility_Check [partial]} {check, language-defined
  14729.               (Accessibility_Check)} For an access-to-object type, a
  14730.               check is made that the accessibility level of the operand
  14731.               type is not deeper than that of the target type.
  14732.               {94-4715.a}
  14733.  
  14734.  48.a   Ramification:  This check is needed for operands that are access
  14735.         parameters and in instance bodies.
  14736.  
  14737.  48.b   Note that this check can never fail for the implicit conversion
  14738.         to the anonymous type of an access parameter that is done when
  14739.         calling a subprogram with an access parameter.  {94-4715.a}
  14740.  
  14741.           49  {Access_Check [partial]} {check, language-defined (Access_
  14742.               Check)} If the target type is an anonymous access type, a
  14743.               check is made that the value of the operand is not null;
  14744.               if the target is not an anonymous access type, then the
  14745.               result is null if the operand value is null.
  14746.  
  14747.  49.a   Ramification:  A conversion to an anonymous access type happens
  14748.         implicitly as part of initializing an access discriminant or
  14749.         access parameter.
  14750.  
  14751.  49.b   Reason:  As explained in 3.10, ``Access Types'', it is important
  14752.         that a value of an anonymous access type can never be null.
  14753.  
  14754.           50  If the operand value is not null, then the result
  14755.               designates the same object (or subprogram) as is
  14756.               designated by the operand value, but viewed as being of
  14757.               the target designated subtype (or profile); any checks
  14758.               associated with evaluating a conversion to the target
  14759.               designated subtype are performed.
  14760.  
  14761.  50.a   Ramification:  The checks are certain to succeed if the target
  14762.         and operand designated subtypes statically match.
  14763.  
  14764. 51   {Range_Check [partial]} {check, language-defined (Range_Check)}
  14765. {Discriminant_Check [partial]} {check, language-defined (Discriminant_Check)}
  14766. {Index_Check [partial]} {check, language-defined (Index_Check)} After
  14767. conversion of the value to the target type, if the target subtype is
  14768. constrained, a check is performed that the value satisfies this constraint.
  14769.  
  14770.         51.a   Ramification:  The above check is a Range_Check for scalar
  14771.         subtypes, a Discriminant_Check or Index_Check for access subtypes,
  14772.         and a Discriminant_Check for discriminated subtypes.  The Length_
  14773.         Check for an array conversion is performed as part of the conversion
  14774.         to the target type.
  14775.  
  14776. 52   {evaluation [view conversion]} For the evaluation of a view conversion,
  14777. the operand name is evaluated, and a new view of the object denoted by the
  14778. operand is created, whose type is the target type; {Length_Check [partial]}
  14779. {check, language-defined (Length_Check)} {Tag_Check [partial]} {check,
  14780. language-defined (Tag_Check)} {Discriminant_Check [partial]} {check,
  14781. language-defined (Discriminant_Check)} if the target type is composite,
  14782. checks are performed as above for a value conversion.
  14783.  
  14784. 53   The properties of this new view are as follows:
  14785.  
  14786.    54  If the target type is composite, the bounds or discriminants (if
  14787.        any) of the view are as defined above for a value conversion;
  14788.        each nondiscriminant component of the view denotes the matching
  14789.        component of the operand object; the subtype of the view is
  14790.        constrained if either the target subtype or the operand object is
  14791.        constrained, or if the operand type is a descendant of the target
  14792.        type, and has discriminants that were not inherited from the
  14793.        target type;
  14794.  
  14795.    55  If the target type is tagged, then an assignment to the view
  14796.        assigns to the corresponding part of the object denoted by the
  14797.        operand; otherwise, an assignment to the view assigns to the
  14798.        object, after converting the assigned value to the subtype of the
  14799.        object (which might raise Constraint_Error); {implicit subtype
  14800.        conversion [assignment to view conversion]}
  14801.  
  14802.    56  Reading the value of the view yields the result of converting the
  14803.        value of the operand object to the target subtype (which might
  14804.        raise Constraint_Error), except if the object is of an access
  14805.        type and the view conversion is passed as an out parameter; in
  14806.        this latter case, the value of the operand object is used to
  14807.        initialize the formal parameter without checking against any
  14808.        constraint of the target subtype (see 6.4.1).  {implicit subtype
  14809.        conversion [reading a view conversion]}
  14810.  
  14811.  56.a   Reason:  This ensures that even an out parameter of an access
  14812.         type is initialized reasonably.
  14813.  
  14814. 57   {Program_Error (raised by failure of run-time check)} {Constraint_Error
  14815. (raised by failure of run-time check)} If an Accessibility_Check fails,
  14816. Program_Error is raised.  Any other check associated with a conversion raises
  14817. Constraint_Error if it fails.
  14818.  
  14819. 58   Conversion to a type is the same as conversion to an unconstrained
  14820. subtype of the type.
  14821.  
  14822.         58.a   Reason:  This definition is needed because the semantics of
  14823.         various constructs involves converting to a type, whereas an explicit
  14824.         type_conversion actually converts to a subtype.  For example, the
  14825.         evaluation of a range is defined to convert the values of the
  14826.         expressions to the type of the range.
  14827.  
  14828.         58.b   Ramification:  A conversion to a scalar type, or,
  14829.         equivalently, to an unconstrained scalar subtype, can raise
  14830.         Constraint_Error if the value is outside the base range of the type.
  14831.  
  14832.  
  14833.      NOTES
  14834. 59   (20) {implicit subtype conversion [distributed]} In addition to explicit
  14835.      type_conversions, type conversions are performed implicitly in
  14836.      situations where the expected type and the actual type of a construct
  14837.      differ, as is permitted by the type resolution rules (see 8.6).  For
  14838.      example, an integer literal is of the type universal_integer, and is
  14839.      implicitly converted when assigned to a target of some specific integer
  14840.      type.  Similarly, an actual parameter of a specific tagged type is
  14841.      implicitly converted when the corresponding formal parameter is of a
  14842.      class-wide type.
  14843.  
  14844.      60   {implicit subtype conversion [distributed]} {Constraint_Error
  14845.      (raised by failure of run-time check)} Even when the expected and actual
  14846.      types are the same, implicit subtype conversions are performed to adjust
  14847.      the array bounds (if any) of an operand to match the desired target
  14848.      subtype, or to raise Constraint_Error if the (possibly adjusted) value
  14849.      does not satisfy the constraints of the target subtype.
  14850.  
  14851. 61   (21) A ramification of the overload resolution rules is that the operand
  14852.      of an (explicit) type_conversion cannot be the literal null, an
  14853.      allocator, an aggregate, a string_literal, a character_literal, or an
  14854.      attribute_reference for an Access or Unchecked_Access attribute.
  14855.      Similarly, such an expression enclosed by parentheses is not allowed.  A
  14856.      qualified_expression (see 4.7) can be used instead of such a type_
  14857.      conversion.
  14858.  
  14859. 62   (22) The constraint of the target subtype has no effect for a type_
  14860.      conversion of an elementary type passed as an out parameter.  Hence, it
  14861.      is recommended that the first subtype be specified as the target to
  14862.      minimize confusion (a similar recommendation applies to renaming and
  14863.      generic formal in out objects).
  14864.  
  14865.  
  14866.                                   Examples
  14867.  
  14868. 63   Examples of numeric type conversion:
  14869.  
  14870. 64  Real(2*J)      --  value is converted to floating point
  14871.     Integer(1.6)   --  value is 2
  14872.     Integer(-0.4)  --  value is 0
  14873.  
  14874. 65   Example of conversion between derived types:
  14875.  
  14876. 66  type A_Form is new B_Form;
  14877.  
  14878. 67  X : A_Form;
  14879.     Y : B_Form;
  14880.  
  14881. 68  X := A_Form(Y);
  14882.     Y := B_Form(X);  --  the reverse conversion
  14883.  
  14884. 69   Examples of conversions between array types:
  14885.  
  14886. 70  type Sequence is array (Integer range <>) of Integer;
  14887.     subtype Dozen is Sequence(1 .. 12);
  14888.     Ledger : array(1 .. 100) of Integer;
  14889.  
  14890. 71  Sequence(Ledger)            --  bounds are those of Ledger
  14891.     Sequence(Ledger(31 .. 42))  --  bounds are 31 and 42
  14892.     Dozen(Ledger(31 .. 42))     --  bounds are those of Dozen
  14893.  
  14894.  
  14895.                         Incompatibilities With Ada 83
  14896.  
  14897.         71.a   {incompatibilities with Ada 83} A character_literal is not
  14898.         allowed as the operand of a type_conversion, since there are now two
  14899.         character types in package Standard.
  14900.  
  14901.         71.b   The component subtypes have to statically match in an array
  14902.         conversion, rather than being checked for matching constraints at run
  14903.         time.
  14904.  
  14905.         71.c   Because sliding of array bounds is now provided for operations
  14906.         where it was not in Ada 83, programs that used to raise Constraint_
  14907.         Error might now continue executing and produce a reasonable result.
  14908.         This is likely to fix more bugs than it creates.
  14909.  
  14910.                             Extensions to Ada 83
  14911.  
  14912.         71.d   {extensions to Ada 83} A type_conversion is considered the
  14913.         name of an object in certain circumstances (such a type_conversion is
  14914.         called a view conversion).  In particular, as in Ada 83, a type_
  14915.         conversion can appear as an in out or out actual parameter.  In
  14916.         addition, if the target type is tagged and the operand is the name of
  14917.         an object, then so is the type_conversion, and it can be used as the
  14918.         prefix to a selected_component, in an object_renaming_declaration,
  14919.         etc.
  14920.  
  14921.         71.e   We no longer require type-mark conformance between a parameter
  14922.         of the form of a type conversion, and the corresponding formal
  14923.         parameter.  This had caused some problems for inherited subprograms
  14924.         (since there isn't really a type-mark for converted formals), as well
  14925.         as for renamings, formal subprograms, etc.  See AI-245, AI-318,
  14926.         AI-547.
  14927.  
  14928.         71.f   We now specify ``deterministic'' rounding from real to integer
  14929.         types when the value of the operand is exactly between two integers
  14930.         (rounding is away from zero in this case).
  14931.  
  14932.         71.g   ``Sliding'' of array bounds (which is part of conversion to an
  14933.         array subtype) is performed in more cases in Ada 9X than in Ada 83.
  14934.         Sliding is not performed on the operand of a membership test, nor on
  14935.         the operand of a qualified_expression.  It wouldn't make sense on a
  14936.         membership test, and we wish to retain a connection between subtype
  14937.         membership and subtype qualification.  In general, a subtype
  14938.         membership test returns True if and only if a corresponding subtype
  14939.         qualification succeeds without raising an exception.  Other
  14940.         operations that take arrays perform sliding.
  14941.  
  14942.                          Wording Changes From Ada 83
  14943.  
  14944.         71.h   We no longer explicitly list the kinds of things that are not
  14945.         allowed as the operand of a type_conversion, except in a NOTE.
  14946.  
  14947.         71.i   The rules in this clause subsume the rules for "parameters of
  14948.         the form of a type conversion," and have been generalized to cover
  14949.         the use of a type conversion as a name.
  14950.  
  14951.  
  14952.  
  14953. 4.7 Qualified Expressions
  14954.  
  14955. 1   [A qualified_expression is used to state explicitly the type, and to
  14956. verify the subtype, of an operand that is either an expression or an
  14957. aggregate.  {type conversion: see also qualified_expression} ]
  14958.  
  14959.  
  14960.                                    Syntax
  14961.  
  14962. 2   qualified_expression ::=
  14963.        subtype_mark'(expression) | subtype_mark'aggregate
  14964.  
  14965.  
  14966.                             Name Resolution Rules
  14967.  
  14968. 3   {operand [of a qualified_expression]} The operand (the expression or
  14969. aggregate) shall resolve to be of the type determined by the subtype_mark, or
  14970. a universal type that covers it.
  14971.  
  14972.  
  14973.                               Dynamic Semantics
  14974.  
  14975. 4   {evaluation [qualified_expression]} {Range_Check [partial]} {check,
  14976. language-defined (Range_Check)} {Discriminant_Check [partial]} {check,
  14977. language-defined (Discriminant_Check)} {Index_Check [partial]} {check,
  14978. language-defined (Index_Check)} The evaluation of a qualified_expression
  14979. evaluates the operand (and if of a universal type, converts it to the type
  14980. determined by the subtype_mark) and checks that its value belongs to the
  14981. subtype denoted by the subtype_mark.  {implicit subtype conversion
  14982. [qualified_expression]} {Constraint_Error (raised by failure of run-time
  14983. check)} The exception Constraint_Error is raised if this check fails.
  14984.  
  14985.         4.a   Ramification:  This is one of the few contexts in Ada 9X where
  14986.         implicit subtype conversion is not performed prior to a constraint
  14987.         check, and hence no ``sliding'' of array bounds is provided.
  14988.  
  14989.         4.b   Reason:  Implicit subtype conversion is not provided because a
  14990.         qualified_expression with a constrained target subtype is essentially
  14991.         an assertion about the subtype of the operand, rather than a request
  14992.         for conversion.  An explicit type_conversion can be used rather than
  14993.         a qualified_expression if subtype conversion is desired.
  14994.  
  14995.  
  14996.      NOTES
  14997. 5    (23) When a given context does not uniquely identify an expected type, a
  14998.      qualified_expression can be used to do so.  In particular, if an
  14999.      overloaded name or aggregate is passed to an overloaded subprogram, it
  15000.      might be necessary to qualify the operand to resolve its type.
  15001.  
  15002.  
  15003.                                   Examples
  15004.  
  15005. 6   Examples of disambiguating expressions using qualification:
  15006.  
  15007. 7   type Mask is (Fix, Dec, Exp, Signif);
  15008.     type Code is (Fix, Cla, Dec, Tnz, Sub);
  15009.  
  15010. 8   Print (Mask'(Dec));  --  Dec is of type Mask
  15011.     Print (Code'(Dec));  --  Dec is of type Code
  15012.  
  15013. 9   for J in Code'(Fix) .. Code'(Dec) loop ... -- qualification needed for eith\
  15014. er Fix or Dec
  15015.     for J in Code range Fix .. Dec loop ...    -- qualification unnecessary
  15016.     for J in Code'(Fix) .. Dec loop ...        -- qualification unnecessary for\
  15017.  Dec
  15018.  
  15019. 10  Dozen'(1 | 3 | 5 | 7 => 2, others => 0) -- see 4.6
  15020.  
  15021.  
  15022.  
  15023. 4.8 Allocators
  15024.  
  15025. 1   [The evaluation of an allocator creates an object and yields an access
  15026. value that designates the object.  {new: see allocator} {malloc: see
  15027. allocator} {heap management: see also alligator} ]
  15028.  
  15029.  
  15030.                                    Syntax
  15031.  
  15032. 2   allocator ::=
  15033.        new subtype_indication | new qualified_expression
  15034.  
  15035.  
  15036.                             Name Resolution Rules
  15037.  
  15038. 3   {expected type [allocator]} The expected type for an allocator shall be a
  15039. single access-to-object type whose designated type covers the type determined
  15040. by the subtype_mark of the subtype_indication or qualified_expression.
  15041.  
  15042.         3.a   Discussion:  See 8.6, ``The Context of Overload Resolution''
  15043.         for the meaning of ``shall be a single ... type whose ...''
  15044.  
  15045.  
  15046.                                Legality Rules
  15047.  
  15048. 4   {initialized allocator} An initialized allocator is an allocator with a
  15049. qualified_expression.  {uninitialized allocator} An uninitialized allocator
  15050. is one with a subtype_indication.  In the subtype_indication of an
  15051. uninitialized allocator, a constraint is permitted only if the subtype_mark
  15052. denotes an [unconstrained] composite subtype; if there is no constraint, then
  15053. the subtype_mark shall denote a definite subtype.  {94-4759.a} {constructor:
  15054. see initialized alligator}
  15055.  
  15056.         4.a   Ramification:  For example, ... new S'Class ... (with no
  15057.         initialization expression) is illegal, but ... new S'Class'(X) ... is
  15058.         legal, and takes its tag and constraints from the initial value
  15059.         X. (Note that the former case cannot have a constraint.)
  15060.  
  15061. 5   If the type of the allocator is an access-to-constant type, the allocator
  15062. shall be an initialized allocator.  If the designated type is limited, the
  15063. allocator shall be an uninitialized allocator.
  15064.  
  15065.         5.a   Ramification:  For an access-to-constant type whose designated
  15066.         type is limited, allocators are illegal.  The Access attribute is
  15067.         legal for such a type, however.
  15068.  
  15069.  
  15070.                               Static Semantics
  15071.  
  15072. 6   If the designated type of the type of the allocator is elementary, then
  15073. the subtype of the created object is the designated subtype.  If the
  15074. designated type is composite, then the created object is always constrained;
  15075. if the designated subtype is constrained, then it provides the constraint of
  15076. the created object; otherwise, the object is constrained by its initial value
  15077. [(even if the designated subtype is unconstrained with defaults)].
  15078. {constrained by its initial value [partial]}
  15079.  
  15080.         6.a   Discussion:  See AI-00331.
  15081.  
  15082.         6.b   Reason:  All objects created by an allocator are aliased, and
  15083.         all aliased composite objects need to be constrained so that access
  15084.         subtypes work reasonably.
  15085.  
  15086.  
  15087.                               Dynamic Semantics
  15088.  
  15089. 7   {evaluation [allocator]} For the evaluation of an allocator, the
  15090. elaboration of the subtype_indication or the evaluation of the qualified_
  15091. expression is performed first.  {evaluation [initialized allocator]}
  15092. {assignment operation (during evaluation of an initialized allocator)} For
  15093. the evaluation of an initialized allocator, an object of the designated type
  15094. is created and the value of the qualified_expression is converted to the
  15095. designated subtype and assigned to the object.  {implicit subtype conversion
  15096. [initialization expression of allocator]}
  15097.  
  15098.         7.a   Ramification:  The conversion might raise Constraint_Error.
  15099.  
  15100. 8   {evaluation [uninitialized allocator]} For the evaluation of an
  15101. uninitialized allocator:
  15102.  
  15103.     9  {assignment operation (during evaluation of an uninitialized
  15104.        allocator)} If the designated type is elementary, an object of
  15105.        the designated subtype is created and any implicit initial value
  15106.        is assigned;
  15107.  
  15108.    10  {assignment operation (during evaluation of an uninitialized
  15109.        allocator)} If the designated type is composite, an object of the
  15110.        designated type is created with tag, if any, determined by the
  15111.        subtype_mark of the subtype_indication; any per-object con-
  15112.        straints on subcomponents are elaborated and any implicit initial
  15113.        values for the subcomponents of the object are obtained as
  15114.        determined by the subtype_indication and assigned to the
  15115.        corresponding subcomponents.  {Index_Check [partial]} {check,
  15116.        language-defined (Index_Check)} {Discriminant_Check [partial]}
  15117.        {check, language-defined (Discriminant_Check)} A check is made
  15118.        that the value of the object belongs to the designated subtype.
  15119.        {Constraint_Error (raised by failure of run-time check)}
  15120.        Constraint_Error is raised if this check fails.  This check and
  15121.        the initialization of the object are performed in an arbitrary
  15122.        order.
  15123.  
  15124.  10.a   Discussion:  AI-00150.
  15125.  
  15126. 11   [If the created object contains any tasks, they are activated (see
  15127. 9.2).]  Finally, an access value that designates the created object is
  15128. returned.
  15129.  
  15130.  
  15131.      NOTES
  15132. 12   (24) Allocators cannot create objects of an abstract type.  See 3.9.3.
  15133.  
  15134. 13   (25) If any part of the created object is controlled, the initialization
  15135.      includes calls on corresponding Initialize or Adjust procedures.  See
  15136.      7.6.
  15137.  
  15138. 14   (26) As explained in 13.11, ``Storage Management'', the storage for an
  15139.      object allocated by an allocator comes from a storage pool (possibly
  15140.      user defined).  {Storage_Error (raised by failure of run-time check)}
  15141.      The exception Storage_Error is raised by an allocator if there is not
  15142.      enough storage.  Instances of Unchecked_Deallocation may be used to
  15143.      explicitly reclaim storage.
  15144.  
  15145. 15   (27) Implementations are permitted, but not required, to provide garbage
  15146.      collection (see 13.11.3).
  15147.  
  15148.    15.a   Ramification:  Note that in an allocator, the exception Constraint_
  15149.         Error can be raised by the evaluation of the qualified_expression, by
  15150.         the elaboration of the subtype_indication, or by the initialization.
  15151.  
  15152.    15.b   Discussion:  By default, the implementation provides the storage
  15153.         pool.  The user may exercise more control over storage management by
  15154.         associating a user-defined pool with an access type.
  15155.  
  15156.  
  15157.                                   Examples
  15158.  
  15159. 16   Examples of allocators:
  15160.  
  15161. 17  new Cell'(0, null, null)                          -- initialized explicitly\
  15162. , see 3.10.1
  15163.     new Cell'(Value => 0, Succ => null, Pred => null) -- initialized explicitly
  15164.     new Cell                                          -- not initialized
  15165.  
  15166. 18  new Matrix(1 .. 10, 1 .. 20)                      -- the bounds only are gi\
  15167. ven
  15168.     new Matrix'(1 .. 10 => (1 .. 20 => 0.0))          -- initialized explicitly
  15169.  
  15170. 19  new Buffer(100)                                   -- the discriminant only \
  15171. is given
  15172.     new Buffer'(Size => 80, Pos => 0, Value => (1 .. 80 => 'A')) -- initialized\
  15173.  explicitly
  15174.  
  15175. 20  Expr_Ptr'(new Literal)                        -- allocator for access-to-cl\
  15176. ass-wide type, see 3.9.1
  15177.     Expr_Ptr'(new Literal'(Expression with 3.5)) -- initialized explicitly
  15178.  
  15179.  
  15180.                         Incompatibilities With Ada 83
  15181.  
  15182.         20.a   {incompatibilities with Ada 83} The subtype_indication of an
  15183.         uninitialized allocator may not have an explicit constraint if the
  15184.         designated type is an access type.  In Ada 83, this was permitted
  15185.         even though the constraint had no affect on the subtype of the
  15186.         created object.
  15187.  
  15188.                             Extensions to Ada 83
  15189.  
  15190.         20.b   {extensions to Ada 83} Allocators creating objects of type T
  15191.         are now overloaded on access types designating T'Class and all
  15192.         class-wide types that cover T.
  15193.  
  15194.         20.c   Implicit array subtype conversion (sliding) is now performed
  15195.         as part of an initialized allocator.
  15196.                          Wording Changes From Ada 83
  15197.  
  15198.         20.d   We have used a new organization, inspired by the ACID
  15199.         document, that makes it clearer what is the subtype of the created
  15200.         object, and what subtype conversions take place.
  15201.  
  15202.         20.e   Discussion of storage management issues, such as garbage
  15203.         collection and the raising of Storage_Error, has been moved to 13.11,
  15204.         ``Storage Management''.
  15205.  
  15206.  
  15207.  
  15208. 4.9 Static Expressions and Static Subtypes
  15209.  
  15210. 1   Certain expressions of a scalar or string type are defined to be static.
  15211. Similarly, certain discrete ranges are defined to be static, and certain
  15212. scalar and string subtypes are defined to be static subtypes.  [{static}
  15213. Static means determinable at compile time, using the declared properties or
  15214. values of the program entities.]  {constant: see also static}
  15215.  
  15216.         1.a   Discussion:  As opposed to more elaborate data flow analysis,
  15217.         etc.
  15218.  
  15219.  
  15220.                          Language Design Principles
  15221.  
  15222.         1.b   For an expression to be static, it has to be calculable at
  15223.         compile time.
  15224.  
  15225.         1.c   Only scalar and string expressions are static.
  15226.  
  15227.         1.d   To be static, an expression cannot have any nonscalar,
  15228.         nonstring subexpressions (though it can have nonscalar constituent
  15229.         names).  A static scalar expression cannot have any nonscalar
  15230.         subexpressions.  There is one exception -- a membership test for a
  15231.         string subtype can be static, and the result is scalar, even though a
  15232.         subexpression is nonscalar.  {94-4679.a} {94-4684.a} {94-4687.a}
  15233.  
  15234.         1.e   The rules for evaluating static expressions are designed to
  15235.         maximize portability of static calculations.
  15236. 2   {static (expression)} A static expression is [a scalar or string
  15237. expression that is] one of the following:  {94-4679.a} {94-4684.a}
  15238. {94-4687.a} {94-4738.a} {94-4926.a} {94-4929.a} {94-4950.a}
  15239.  
  15240.     3  a numeric_literal;
  15241.  
  15242.  3.a    Ramification:  A numeric_literal is always a static expression,
  15243.         even if its expected type is not that of a static subtype.
  15244.         However, if its value is explicitly converted to, or qualified
  15245.         by, a nonstatic subtype, the resulting expression is nonstatic.
  15246.  
  15247.     4  a string_literal of a static string subtype;
  15248.  
  15249.  4.a    Ramification:  That is, the constrained subtype defined by the
  15250.         index range of the string is static.  Note that elementary
  15251.         values don't generally have subtypes, while composite values do
  15252.         (since the bounds or discriminants are inherent in the value).
  15253.  
  15254.     5  a name that denotes the declaration of a named number or a static
  15255.        constant;
  15256.  
  15257.  5.a    Ramification:  Note that enumeration literals are covered by the
  15258.         function_call case.
  15259.  
  15260.     6  a function_call whose function_name or function_prefix statically
  15261.        denotes a static function, and whose actual parameters, if any
  15262.        (whether given explicitly or by default), are all static
  15263.        expressions;
  15264.  
  15265.  6.a    Ramification:  This includes uses of operators that are
  15266.         equivalent to function_calls.
  15267.  
  15268.     7  an attribute_reference that denotes a scalar value, and whose
  15269.        prefix denotes a static scalar subtype; {94-4679.c} {94-4684.c}
  15270.  
  15271.  7.a    Ramification:  Note that this does not include the case of an
  15272.         attribute that is a function; a reference to such an attribute
  15273.         is not even an expression.  See above for function calls.
  15274.  
  15275.  7.b    An implementation may define the staticness and other properties
  15276.         of implementation-defined attributes.
  15277.  
  15278.     8  an attribute_reference whose prefix statically denotes a
  15279.        statically constrained array object or array subtype, and whose
  15280.        attribute_designator is First, Last, or Length, with an optional
  15281.        dimension; {94-4968.a}
  15282.  
  15283.     9  a type_conversion whose subtype_mark denotes a static scalar
  15284.        subtype, and whose operand is a static expression;
  15285.  
  15286.    10  a qualified_expression whose subtype_mark denotes a static
  15287.        [(scalar or string)] subtype, and whose operand is a static
  15288.        expression; {94-4667.p}
  15289.  
  15290.  10.a   Ramification:  This rules out the subtype_mark'aggregate case.
  15291.  
  15292.  10.b   Reason:  Adding qualification to an expression shouldn't make it
  15293.         nonstatic, even for strings.
  15294.  
  15295.    11  a membership test whose simple_expression is a static expression,
  15296.        and whose range is a static range or whose subtype_mark denotes a
  15297.        static [(scalar or string)] subtype;
  15298.  
  15299.  11.a   Reason:  Clearly, we should allow membership tests in exactly
  15300.         the same cases where we allow qualified_expressions.
  15301.  
  15302.    12  a short-circuit control form both of whose relations are static
  15303.        expressions;
  15304.  
  15305.    13  a static expression enclosed in parentheses.
  15306.  
  15307.         13.a   Discussion:  {static (value)} Informally, we talk about a
  15308.         static value.  When we do, we mean a value specified by a static
  15309.         expression.
  15310.  
  15311.         13.b   Ramification:  The language requires a static expression in a
  15312.         number_declaration, a numeric type definition, a discrete_choice
  15313.         (sometimes), certain representation items, an attribute_designator,
  15314.         and when specifying the value of a discriminant governing a variant_
  15315.         part in a record_aggregate or extension_aggregate.
  15316.  
  15317. 14   {statically (denote)} A name statically denotes an entity if it denotes
  15318. the entity and:
  15319.  
  15320.    15  It is a direct_name, expanded name, or character_literal, and it
  15321.        denotes a declaration other than a renaming_declaration; or
  15322.  
  15323.    16  It is an attribute_reference whose prefix statically denotes some
  15324.        entity; or
  15325.  
  15326.    17  It denotes a renaming_declaration with a name that statically
  15327.        denotes the renamed entity.
  15328.  
  15329.         17.a   Ramification:  Selected_components that are not expanded names
  15330.         and indexed_components do not statically denote things.
  15331.  
  15332. 18   {static (function)} A static function is one of the following:
  15333.  
  15334.         18.a   Ramification:  These are the functions whose calls can be
  15335.         static expressions.
  15336.  
  15337.    19  a predefined operator whose parameter and result types are all
  15338.        scalar types none of which are descendants of formal scalar
  15339.        types;
  15340.  
  15341.    20  a predefined concatenation operator whose result type is a string
  15342.        type; {94-4679.a} {94-4684.a} {94-4687.a} {94-4738.a}
  15343.  
  15344.    21  an enumeration literal;
  15345.  
  15346.    22  a language-defined attribute that is a function, if the prefix
  15347.        denotes a static scalar subtype, and if the parameter and result
  15348.        types are scalar.
  15349.  
  15350. 23   In any case, a generic formal subprogram is not a static function.
  15351.  
  15352. 24   {static (constant)} A static constant is a constant view declared by a
  15353. full constant declaration or an object_renaming_declaration with a static
  15354. nominal subtype, having a value defined by a static scalar expression or by a
  15355. static string expression whose value has a length not exceeding the maximum
  15356. length of a string_literal in the implementation.
  15357.  
  15358.         24.a   Ramification:  A deferred constant is not static; the view
  15359.         introduced by the corresponding full constant declaration can be
  15360.         static.
  15361.  
  15362.         24.b   Reason:  The reason for restricting the length of static
  15363.         string constants is so that compilers don't have to store giant
  15364.         strings in their symbol tables.  Since most string constants will be
  15365.         initialized from string_literals, the length limit seems pretty
  15366.         natural.  The reason for avoiding nonstring types is also to save
  15367.         symbol table space.  We're trying to keep it cheap and simple (from
  15368.         the implementer's viewpoint), while still allowing, for example, the
  15369.         link name of a pragma Import to contain a concatenation.
  15370.  
  15371.         24.c   The length we're talking about is the maximum number of
  15372.         characters in the value represented by a string_literal, not the
  15373.         number of characters in the source representation; the quotes don't
  15374.         count.  {94-4747.b} {94-4748.b} {94-4754.b}
  15375.  
  15376. 25   {static (range)} A static range is a range whose bounds are static
  15377. expressions, [or a range_attribute_reference that is equivalent to such a
  15378. range.]  {static (discrete_range)} A static discrete_range is one that is a
  15379. static range or is a subtype_indication that defines a static scalar subtype.
  15380. The base range of a scalar type is a static range, unless the type is a
  15381. descendant of a formal scalar type.
  15382.  
  15383. 26   {static (subtype)} A static subtype is either a static scalar subtype or
  15384. a static string subtype.  {static (scalar subtype)} A static scalar subtype
  15385. is an unconstrained scalar subtype whose type is not a descendant of a formal
  15386. scalar type, or a constrained scalar subtype formed by imposing a compatible
  15387. static constraint on a static scalar subtype.  {static (string subtype)} A
  15388. static string subtype is an unconstrained string subtype whose index subtype
  15389. and component subtype are static (and whose type is not a descendant of a
  15390. formal array type), or a constrained string subtype formed by imposing a
  15391. compatible static constraint on a static string subtype.  {94-4539.a} In any
  15392. case, the subtype of a generic formal object of mode in out, and the result
  15393. subtype of a generic formal function, are not static.
  15394.         26.a   Ramification:  String subtypes are the only composite subtypes
  15395.         that can be static.
  15396.  
  15397.         26.b   Reason:  The part about generic formal objects of mode in out
  15398.         is necessary because the subtype of the formal is not required to
  15399.         have anything to do with the subtype of the actual.  For example:
  15400.  
  15401. 26.c        subtype Int10 is Integer range 1..10;
  15402.  
  15403. 26.d        generic
  15404.                 F : in out Int10;
  15405.             procedure G;
  15406.  
  15407. 26.e        procedure G is
  15408.             begin
  15409.                 case F is
  15410.                     when 1..10 => null;
  15411.                     -- Illegal!
  15412.                 end case;
  15413.             end G;
  15414.  
  15415. 26.f        X : Integer range 1..20;
  15416.             procedure I is new G(F => X); -- OK.
  15417.  
  15418.         26.g   The case_statement is illegal, because the subtype of F is not
  15419.         static, so the choices have to cover all values of Integer, not just
  15420.         those in the range 1..10.  A similar issue arises for generic formal
  15421.         functions, now that function calls are object names.
  15422.  
  15423. 27   {static (constraint)} The different kinds of static constraint are
  15424. defined as follows:
  15425.  
  15426.    28  A null constraint is always static;
  15427.  
  15428.    29  {static (range constraint)} {static (digits constraint)} {static
  15429.        (delta constraint)} A scalar constraint is static if it has no
  15430.        range_constraint, or one with a static range;
  15431.  
  15432.    30  {static (index constraint)} An index constraint is static if each
  15433.        discrete_range is static, and each index subtype of the
  15434.        corresponding array type is static;
  15435.  
  15436.    31  {static (discriminant constraint)} A discriminant constraint is
  15437.        static if each expression of the constraint is static, and the
  15438.        subtype of each discriminant is static.
  15439.  
  15440. 32   {statically (constrained)} A subtype is statically constrained if it is
  15441. constrained, and its constraint is static.  An object is statically
  15442. constrained if its nominal subtype is statically constrained, or if it is a
  15443. static string constant.  {94-4776.c}
  15444.  
  15445.  
  15446.                                Legality Rules
  15447.  
  15448. 33   A static expression is evaluated at compile time except when it is part
  15449. of the right operand of a static short-circuit control form whose value is
  15450. determined by its left operand.  This evaluation is performed exactly,
  15451. without performing Overflow_Checks.  For a static expression that is
  15452. evaluated:
  15453.  
  15454.    34  The expression is illegal if its evaluation fails a
  15455.        language-defined check other than Overflow_Check.
  15456.  
  15457.    35  If the expression is not part of a larger static expression, then
  15458.        its value shall be within the base range of its expected type.
  15459.        Otherwise, the value may be arbitrarily large or small.
  15460.  
  15461.    36  If the expression is of type universal_real and its expected type
  15462.        is a decimal fixed point type, then its value shall be a multiple
  15463.        of the small of the decimal type.
  15464.  
  15465.  36.a   Ramification:  This means that a numeric_literal for a decimal
  15466.         type cannot have ``extra'' significant digits.
  15467.  
  15468. 37   The last two restrictions above do not apply if the expected type is a
  15469. descendant of a formal scalar type (or a corresponding actual type in an
  15470. instance).  {94-4926.a} {94-4929.a} {94-4950.a}
  15471.  
  15472.         37.a   Discussion:  Values outside the base range are not permitted
  15473.         when crossing from the ``static'' domain to the ``dynamic'' domain.
  15474.         This rule is designed to enhance portability of programs containing
  15475.         static expressions.  Note that this rule applies to the exact value,
  15476.         not the value after any rounding or truncation.  (See below for the
  15477.         rounding and truncation requirements.)
  15478.  
  15479.         37.b   Short-circuit control forms are a special case:
  15480.  
  15481. 37.c        N: constant := 0.0;
  15482.             X: constant Boolean := (N = 0.0) or else (1.0/N > 0.5); -- Static.
  15483.  
  15484.         37.d   The declaration of X is legal, since the divide-by-zero part
  15485.         of the expression is not evaluated.  X is a static constant equal to
  15486.         True.
  15487.  
  15488.         37.e   Reason:  There is no requirement to recheck these rules in an
  15489.         instance; the base range check will generally be performed at run
  15490.         time anyway.
  15491.  
  15492.  
  15493.                          Implementation Requirements
  15494.  
  15495. 38   For a real static expression that is not part of a larger static
  15496. expression, and whose expected type is not a descendant of a formal scalar
  15497. type, the implementation shall round or truncate the value (according to the
  15498. Machine_Rounds attribute of the expected type) to the nearest machine number
  15499. of the expected type; if the value is exactly half-way between two machine
  15500. numbers, any rounding shall be performed away from zero.  If the expected
  15501. type is a descendant of a formal scalar type, no special rounding or
  15502. truncating is required -- normal accuracy rules apply (see Annex G).
  15503.  
  15504.         38.a   Reason:  Discarding extended precision enhances portability by
  15505.         ensuring that the value of a static constant of a real type is always
  15506.         a machine number of the type.  Deterministic rounding of exact halves
  15507.         also enhances portability.
  15508.  
  15509.         38.b   When the expected type is a descendant of a formal floating
  15510.         point type, extended precision (beyond that of the machine numbers)
  15511.         can be retained when evaluating a static expression, to ease code
  15512.         sharing for generic instantiations.  For similar reasons, normal
  15513.         (nondeterministic) rounding or truncating rules apply for descendants
  15514.         of a formal fixed point type.
  15515.  
  15516.         38.c   Implementation Note:  Note that the implementation of static
  15517.         expressions has to keep track of plus and minus zero for a type whose
  15518.         Signed_Zeros attribute is True.  {94-4539.c}
  15519.  
  15520.         38.d   Note that the only values of a fixed point type are the
  15521.         multiples of the small, so a static conversion to a fixed-point type,
  15522.         or division by an integer, must do truncation to a multiple of small.
  15523.         It is not correct for the implementation to do all static
  15524.         calculations in infinite precision.
  15525.  
  15526.  
  15527.      NOTES
  15528. 39   (28) An expression can be static even if it occurs in a context where
  15529.      staticness is not required.
  15530.  
  15531.    39.a   Ramification:  For example:
  15532.  
  15533. 39.b        X : Float := Float'(1.0E+400) + 1.0 - Float'(1.0E+400);
  15534.  
  15535.    39.c   The expression is static, which means that the value of X must be
  15536.         exactly 1.0, independent of the accuracy or range of the run-time
  15537.         floating point implementation.
  15538.  
  15539.    39.d   The following kinds of expressions are never static:  explicit_
  15540.         dereference, indexed_component, slice, null, aggregate, allocator.
  15541.  
  15542. 40   (29) A static (or run-time) type_conversion from a real type to an
  15543.      integer type performs rounding.  If the operand value is exactly
  15544.      half-way between two integers, the rounding is performed away from zero.
  15545.  
  15546.    40.a   Reason:  We specify this for portability.  The reason for not
  15547.         choosing round-to-nearest-even, for example, is that this method is
  15548.         easier to undo.
  15549.  
  15550.    40.b   Ramification:  The attribute Truncation (see A.5.3) can be used to
  15551.         perform a (static) truncation prior to conversion, to prevent
  15552.         rounding.
  15553.  
  15554.    40.c   Implementation Note:  The value of the literal
  15555.         0E999999999999999999999999999999999999999999999 is zero.  The
  15556.         implementation must take care to evaluate such literals properly.
  15557.         {94-5001.d} {94-5005.c}
  15558.  
  15559.  
  15560.                                   Examples
  15561.  
  15562. 41   Examples of static expressions:
  15563.  
  15564. 42  1 + 1       -- 2
  15565.     abs(-10)*3  -- 30
  15566.  
  15567. 43  Kilo : constant := 1000;
  15568.     Mega : constant := Kilo*Kilo;   -- 1_000_000
  15569.     Long : constant := Float'Digits*2;
  15570.  
  15571. 44  Half_Pi    : constant := Pi/2;           -- see 3.3.2
  15572.     Deg_To_Rad : constant := Half_Pi/90;
  15573.     Rad_To_Deg : constant := 1.0/Deg_To_Rad; -- equivalent to 1.0/((3.14159_265\
  15574. 36/2)/90)
  15575.  
  15576.  
  15577.                             Extensions to Ada 83
  15578.  
  15579.         44.a   {extensions to Ada 83} The rules for static expressions and
  15580.         static subtypes are generalized to allow more kinds of
  15581.         compile-time-known expressions to be used where compile-time-known
  15582.         values are required, as follows:
  15583.  
  15584.          44.b  Membership tests and short-circuit control forms may
  15585.                appear in a static expression.
  15586.  
  15587.          44.c  The bounds and length of statically constrained array
  15588.                objects or subtypes are static.
  15589.  
  15590.          44.d  The Range attribute of a statically constrained array
  15591.                subtype or object gives a static range.
  15592.  
  15593.          44.e  A type_conversion is static if the subtype_mark denotes a
  15594.                static scalar subtype and the operand is a static
  15595.                expression.
  15596.  
  15597.          44.f  All numeric literals are now static, even if the expected
  15598.                type is a formal scalar type.  This is useful in case_
  15599.                statements and variant_parts, which both now allow a
  15600.                value of a formal scalar type to control the selection,
  15601.                to ease conversion of a package into a generic package.
  15602.                Similarly, named array aggregates are also permitted for
  15603.                array types with an index type that is a formal scalar
  15604.                type.
  15605.  
  15606.         44.g   The rules for the evaluation of static expressions are revised
  15607.         to require exact evaluation at compile time, and force a machine
  15608.         number result when crossing from the static realm to the dynamic
  15609.         realm, to enhance portability and predictability.  Exact evaluation
  15610.         is not required for descendants of a formal scalar type, to simplify
  15611.         generic code sharing and to avoid generic contract model problems.
  15612.  
  15613.         44.h   Static expressions are legal even if an intermediate in the
  15614.         expression goes outside the base range of the type.  Therefore, the
  15615.         following will succeed in Ada 9X, whereas it might raise an exception
  15616.         in Ada 83:
  15617.  
  15618. 44.i        type Short_Int is range -32_768 .. 32_767;
  15619.             I : Short_Int := -32_768;
  15620.  
  15621.         44.j   This might raise an exception in Ada 83 because "32_768" is
  15622.         out of range, even though "-32_768" is not.  In Ada 9X, this will
  15623.         always succeed.
  15624.  
  15625.         44.k   Certain expressions involving string operations (in particular
  15626.         concatenation and membership tests) are considered static in Ada 9X.
  15627.  
  15628.         44.l   The reason for this change is to simplify the rule requiring
  15629.         compile-time-known string expressions as the link name in an
  15630.         interfacing pragma, and to simplify the preelaborability rules.
  15631.  
  15632.                         Incompatibilities With Ada 83
  15633.  
  15634.         44.m   {incompatibilities with Ada 83} An Ada 83 program that uses an
  15635.         out-of-range static value is illegal in Ada 9X, unless the expression
  15636.         is part of a larger static expression, or the expression is not
  15637.         evaluated due to being on the right-hand side of a short-circuit
  15638.         control form.
  15639.  
  15640.                          Wording Changes From Ada 83
  15641.  
  15642.         44.n   This clause (and 4.5.5, ``Multiplying Operators'') subsumes
  15643.         the RM83 section on Universal Expressions.
  15644.  
  15645.         44.o   The existence of static string expressions necessitated
  15646.         changing the definition of static subtype to include string subtypes.
  15647.         Most occurrences of "static subtype" have been changed to "static
  15648.         scalar subtype", in order to preserve the effect of the Ada 83 rules.
  15649.         This has the added benefit of clarifying the difference between
  15650.         "static subtype" and "statically constrained subtype", which has been
  15651.         a source of confusion.  In cases where we allow static string
  15652.         subtypes, we explicitly use phrases like "static string subtype" or
  15653.         "static (scalar or string) subtype", in order to clarify the meaning
  15654.         for those who have gotten used to the Ada 83 terminology.
  15655.  
  15656.         44.p   In Ada 83, an expression was considered nonstatic if it raised
  15657.         an exception.  Thus, for example:
  15658.  
  15659. 44.q        Bad: constant := 1/0; -- Illegal!
  15660.  
  15661.         44.r   was illegal because 1/0 was not static.  In Ada 9X, the above
  15662.         example is still illegal, but for a different reason:  1/0 is static,
  15663.         but there's a separate rule forbidding the exception raising.
  15664.  
  15665.  
  15666.  
  15667. 4.9.1 Statically Matching Constraints and Subtypes
  15668.  
  15669.                               Static Semantics
  15670.  
  15671. 1   {statically matching (for constraints)} A constraint statically matches
  15672. another constraint if both are null constraints, both are static and have
  15673. equal corresponding bounds or discriminant values, or both are nonstatic and
  15674. result from the same elaboration of a constraint of a subtype_indication or
  15675. the same evaluation of a range of a discrete_subtype_definition.
  15676.  
  15677. 2   {statically matching (for subtypes)} A subtype statically matches another
  15678. subtype of the same type if they have statically matching constraints.  Two
  15679. anonymous access subtypes statically match if their designated subtypes
  15680. statically match.
  15681.  
  15682.         2.a   Ramification:  Statically matching constraints and subtypes are
  15683.         the basis for subtype conformance of profiles (see 6.3.1).
  15684.  
  15685. 3   {statically matching (for ranges)} Two ranges of the same type statically
  15686. match if both result from the same evaluation of a range, or if both are
  15687. static and have equal corresponding bounds.
  15688.  
  15689.         3.a   Ramification:  The notion of static matching of ranges is used
  15690.         in 12.5.3, ``Formal Array Types''; the index ranges of formal and
  15691.         actual constrained array subtypes have to statically match.
  15692.  
  15693. 4   {statically compatible (for a constraint and a scalar subtype)} A
  15694. constraint is statically compatible with a scalar subtype if it statically
  15695. matches the constraint of the subtype, or if both are static and the
  15696. constraint is compatible with the subtype.  {statically compatible (for a
  15697. constraint and an access or composite subtype)} A constraint is statically
  15698. compatible with an access or composite subtype if it statically matches the
  15699. constraint of the subtype, or if the subtype is unconstrained.  {statically
  15700. compatible (for two subtypes)} One subtype is statically compatible with a
  15701. second subtype if the constraint of the first is statically compatible with
  15702. the second subtype.
  15703.  
  15704.         4.a   Discussion:  Static compatibility is required when constraining
  15705.         a parent subtype with a discriminant from a new discriminant_part.
  15706.         See 3.7.  Static compatibility is also used in matching generic
  15707.         formal derived types.
  15708.  
  15709.         4.b   Note that statically compatible with a subtype does not imply
  15710.         compatible with a type.  It is OK since the terms are used in
  15711.         different contexts.
  15712.  
  15713.  
  15714.                          Wording Changes From Ada 83
  15715.  
  15716.         4.c   This subclause is new to Ada 9X.
  15717.  
  15718.  
  15719.  
  15720.                             Section 5: Statements
  15721.  
  15722.  
  15723. 1   [A statement defines an action to be performed upon its execution.]
  15724.  
  15725. 2   [This section describes the general rules applicable to all statements.
  15726. Some statements are discussed in later sections:  Procedure_call_statements
  15727. and return_statements are described in Section 6, ``Subprograms''.  Entry_
  15728. call_statements, requeue_statements, delay_statements, accept_statements,
  15729. select_statements, and abort_statements are described in Section 9, ``Tasks
  15730. and Synchronization''.  Raise_statements are described in Section 11,
  15731. ``Exceptions'', and code_statements in Section 13.  The remaining forms of
  15732. statements are presented in this section.]
  15733.  
  15734.  
  15735.                          Wording Changes From Ada 83
  15736.  
  15737.         2.a   The description of return_statements has been moved to 6.5,
  15738.         ``Return Statements'', so that it is closer to the description of
  15739.         subprograms.
  15740.  
  15741.  
  15742.  
  15743. 5.1 Simple and Compound Statements - Sequences of Statements
  15744.  
  15745. 1   [A statement is either simple or compound.  A simple_statement encloses
  15746. no other statement.  A compound_statement can enclose simple_statements and
  15747. other compound_statements.]
  15748.  
  15749.  
  15750.                                    Syntax
  15751.  
  15752. 2   sequence_of_statements ::= statement {statement}
  15753.  
  15754. 3   statement ::=
  15755.        {label} simple_statement | {label} compound_statement
  15756.  
  15757. 4   simple_statement ::= null_statement
  15758.        | assignment_statement              | exit_statement
  15759.        | goto_statement                    | procedure_call_statement
  15760.        | return_statement                  | entry_call_statement
  15761.        | requeue_statement                 | delay_statement
  15762.        | abort_statement                   | raise_statement
  15763.        | code_statement
  15764.  
  15765. 5   compound_statement ::=
  15766.          if_statement                      | case_statement
  15767.        | loop_statement                    | block_statement
  15768.        | accept_statement                  | select_statement
  15769.  
  15770. 6   null_statement ::= null;
  15771.  
  15772. 7   label ::= <<label_statement_identifier>>
  15773.  
  15774. 8   statement_identifier ::= direct_name
  15775.  
  15776.     9   The direct_name of a statement_identifier shall be an identifier (not
  15777.     an operator_symbol).
  15778.  
  15779.  
  15780.                             Name Resolution Rules
  15781.  
  15782. 10   The direct_name of a statement_identifier shall resolve to denote its
  15783. corresponding implicit declaration (see below).
  15784.  
  15785.  
  15786.                                Legality Rules
  15787.  
  15788. 11   Distinct identifiers shall be used for all statement_identifiers that
  15789. appear in the same body, including inner block_statements but excluding inner
  15790. program units.
  15791.                               Static Semantics
  15792.  
  15793. 12   For each statement_identifier, there is an implicit declaration (with
  15794. the specified identifier) at the end of the declarative_part of the innermost
  15795. block_statement or body that encloses the statement_identifier.  The implicit
  15796. declarations occur in the same order as the statement_identifiers occur in
  15797. the source text.  If a usage name denotes such an implicit declaration, the
  15798. entity it denotes is the label, loop_statement, or block_statement with the
  15799. given statement_identifier.
  15800.  
  15801.         12.a   Reason:  We talk in terms of individual statement_identifiers
  15802.         here rather than in terms of the corresponding statements, since a
  15803.         given statement may have multiple statement_identifiers.
  15804.  
  15805.         12.b   A block_statement that has no explicit declarative_part has an
  15806.         implicit empty declarative_part, so this rule can safely refer to the
  15807.         declarative_part of a block_statement.
  15808.  
  15809.         12.c   The scope of a declaration starts at the place of the
  15810.         declaration itself (see 8.2).  In the case of a label, loop, or block
  15811.         name, it follows from this rule that the scope of the implicit
  15812.         declaration starts before the first explicit occurrence of the
  15813.         corresponding name, since this occurrence is either in a statement
  15814.         label, a loop_statement, a block_statement, or a goto_statement.  An
  15815.         implicit declaration in a block_statement may hide a declaration
  15816.         given in an outer program unit or block_statement (according to the
  15817.         usual rules of hiding explained in 8.3).
  15818.  
  15819.         12.d   The syntax rule for label uses statement_identifier which is a
  15820.         direct_name (not a defining_identifier), because labels are
  15821.         implicitly declared.  The same applies to loop and block names.  In
  15822.         other words, the label itself is not the defining occurrence; the
  15823.         implicit declaration is.
  15824.  
  15825.         12.e   We cannot consider the label to be a defining occurrence.  An
  15826.         example that can tell the difference is this:
  15827.  
  15828. 12.f        declare
  15829.                 -- Label Foo is implicitly declared here.
  15830.             begin
  15831.                 for Foo in ... loop
  15832.                     ...
  15833.                     <<Foo>> -- Illegal.
  15834.                     ...
  15835.                 end loop;
  15836.             end;
  15837.  
  15838.         12.g   The label in this example is hidden from itself by the loop
  15839.         parameter with the same name; the example is illegal.  We considered
  15840.         creating a new syntactic category name, separate from direct_name and
  15841.         selector_name, for use in the case of statement labels.  However,
  15842.         that would confuse the rules in Section 8, so we didn't do it.
  15843.  
  15844.  
  15845.                               Dynamic Semantics
  15846.  
  15847. 13   {execution [null_statement]} The execution of a null_statement has no
  15848. effect.
  15849.  
  15850. 14   {transfer of control} A transfer of control is the run-time action of an
  15851. exit_statement, return_statement, goto_statement, or requeue_statement,
  15852. selection of a terminate_alternative, raising of an exception, or an abort,
  15853. which causes the next action performed to be one other than what would
  15854. normally be expected from the other rules of the language.  [As explained in
  15855. 7.6.1, a transfer of control can cause the execution of constructs to be
  15856. completed and then left, which may trigger finalization.]
  15857.  
  15858. 15   {execution [sequence_of_statements]} The execution of a sequence_of_
  15859. statements consists of the execution of the individual statements in
  15860. succession until the sequence_ is completed.
  15861.  
  15862.         15.a   Ramification:  It could be completed by reaching the end of
  15863.         it, or by a transfer of control.
  15864.  
  15865.  
  15866.      NOTES
  15867. 16   (1) A statement_identifier that appears immediately within the
  15868.      declarative region of a named loop_statement or an accept_statement is
  15869.      nevertheless implicitly declared immediately within the declarative
  15870.      region of the innermost enclosing body or block_statement; in other
  15871.      words, the expanded name for a named statement is not affected by
  15872.      whether the statement occurs inside or outside a named loop or an
  15873.      accept_statement -- only nesting within block_statements is relevant to
  15874.      the form of its expanded name.
  15875.  
  15876.    16.a   Discussion:  Each comment in the following example gives the
  15877.         expanded name associated with an entity declared in the task body:
  15878.  
  15879. 16.b        task body Compute is
  15880.                Sum : Integer := 0;                       -- Compute.Sum
  15881.             begin
  15882.              Outer:                                      -- Compute.Outer
  15883.                for I in 1..10 loop     -- Compute.Outer.I
  15884.                 Blk:                                     -- Compute.Blk
  15885.                   declare
  15886.                      Sum : Integer := 0;                 -- Compute.Blk.Sum
  15887.                   begin
  15888.                      accept Ent(I : out Integer; J : in Integer) do
  15889.                                                          -- Compute.Ent.I, Comp\
  15890. ute.Ent.J
  15891.                         Compute.Ent.I := Compute.Outer.I;
  15892.                       Inner:                             -- Compute.Blk.Inner
  15893.                         for J in 1..10 loop
  15894.                                                          -- Compute.Blk.Inner.J
  15895.                            Sum := Sum + Compute.Blk.Inner.J * Compute.Ent.J;
  15896.                         end loop Inner;
  15897.                      end Ent;
  15898.                      Compute.Sum := Compute.Sum + Compute.Blk.Sum;
  15899.                   end Blk;
  15900.                end loop Outer;
  15901.                Record_Result(Sum);
  15902.             end Compute;
  15903.  
  15904.  
  15905.                                   Examples
  15906.  
  15907. 17   Examples of labeled statements:
  15908.  
  15909. 18  <<Here>> <<Ici>> <<Aqui>> <<Hier>> null;
  15910.  
  15911. 19  <<After>> X := 1;
  15912.  
  15913.  
  15914.                             Extensions to Ada 83
  15915.  
  15916.         19.a   {extensions to Ada 83} The requeue_statement is new.
  15917.  
  15918.                          Wording Changes From Ada 83
  15919.  
  15920.         19.b   We define the syntactic category statement_identifier to
  15921.         simplify the description.  It is used for labels, loop names, and
  15922.         block names.  We define the entity associated with the implicit
  15923.         declarations of statement names.
  15924.  
  15925.         19.c   Completion includes completion caused by a transfer of
  15926.         control, although RM83-5.1(6) did not take this view.
  15927.  
  15928.  
  15929.  
  15930. 5.2 Assignment Statements
  15931.  
  15932. 1   [An assignment_statement replaces the current value of a variable with
  15933. the result of evaluating an expression.]
  15934.  
  15935.  
  15936.                                    Syntax
  15937.  
  15938. 2   assignment_statement ::=
  15939.        variable_name := expression;
  15940.  
  15941.  
  15942. 3   The execution of an assignment_statement includes the evaluation of the
  15943. expression and the assignment of the value of the expression into the target.
  15944. {assignment operation [distributed]} {assign: see assignment operation} [An
  15945. assignment operation (as opposed to an assignment_statement) is performed in
  15946. other contexts as well, including object initialization and by-copy parameter
  15947. passing.]  {target (of an assignment operation)} {target (of an assignment_
  15948. statement)} The target of an assignment operation is the view of the object
  15949. to which a value is being assigned; the target of an assignment_statement is
  15950. the variable denoted by the variable_name.
  15951.  
  15952.         3.a   Discussion:  Don't confuse this notion of the ``target'' of an
  15953.         assignment with the notion of the ``target object'' of an entry call
  15954.         or requeue.
  15955.  
  15956.         3.b   Don't confuse the term ``assignment operation'' with the
  15957.         assignment_statement.  The assignment operation is just one part of
  15958.         the execution of an assignment_statement.  The assignment operation
  15959.         is also a part of the execution of various other constructs; see
  15960.         7.6.1, ``Completion and Finalization'' for a complete list.  Note
  15961.         that when we say, ``such-and-such is assigned to so-and-so'', we mean
  15962.         that the assignment operation is being applied, and that so-and-so is
  15963.         the target of the assignment operation.
  15964.  
  15965.  
  15966.                             Name Resolution Rules
  15967.  
  15968. 4   {expected type [assignment_statement variable_name]} The variable_name of
  15969. an assignment_statement is expected to be of any nonlimited type.  {expected
  15970. type [assignment_statement expression]} The expected type for the expression
  15971. is the type of the target.
  15972.  
  15973.         4.a   Implementation Note:  An assignment_statement as a whole is a
  15974.         "complete context," so if the variable_name of an assignment_
  15975.         statement is overloaded, the expression can be used to help
  15976.         disambiguate it.  For example:
  15977.  
  15978. 4.b           type P1 is access R1;
  15979.               type P2 is access R2;
  15980.  
  15981. 4.c           function F return P1;
  15982.               function F return P2;
  15983.  
  15984. 4.d           X : R1;
  15985.             begin
  15986.               F.all := X;  -- Right hand side helps resolve left hand side
  15987.  
  15988.  
  15989.                                Legality Rules
  15990. 5   The target [denoted by the variable_name] shall be a variable.
  15991.  
  15992. 6   If the target is of a tagged class-wide type T'Class, then the expression
  15993. shall either be dynamically tagged, or of type T and tag-indeterminate (see
  15994. 3.9.2).
  15995.  
  15996.         6.a   Reason:  This is consistent with the general rule that a single
  15997.         dispatching operation shall not have both dynamically tagged and
  15998.         statically tagged operands.  Note that for an object initialization
  15999.         (as opposed to the assignment_statement), a statically tagged
  16000.         initialization expression is permitted, since there is no chance for
  16001.         confusion (or Tag_Check failure).  Also, in an object initialization,
  16002.         tag-indeterminate expressions of any type covered by T'Class would be
  16003.         allowed, but with an assignment_statement, that might not work if the
  16004.         tag of the target was for a type that didn't have one of the
  16005.         dispatching operations in the tag-indeterminate expression.
  16006.  
  16007.  
  16008.                               Dynamic Semantics
  16009.  
  16010. 7   {execution [assignment_statement]} For the execution of an assignment_
  16011. statement, the variable_name and the expression are first evaluated in an
  16012. arbitrary order.
  16013.  
  16014.         7.a   Ramification:  Other rules of the language may require that the
  16015.         bounds of the variable be determined prior to evaluating the
  16016.         expression, but that does not necessarily require evaluation of the
  16017.         variable_name, as pointed out by the ACID.
  16018.  
  16019. 8   When the type of the target is class-wide:
  16020.  
  16021.     9  {controlling tag value [for the expression in an assignment_
  16022.        statement]} If the expression is tag-indeterminate (see 3.9.2),
  16023.        then the controlling tag value for the expression is the tag of
  16024.        the target;
  16025.  
  16026.  9.a    Ramification:  See 3.9.2, ``Dispatching Operations of Tagged
  16027.         Types''.
  16028.  
  16029.    10  {Tag_Check [partial]} {check, language-defined (Tag_Check)}
  16030.        {Constraint_Error (raised by failure of run-time check)}
  16031.        Otherwise [(the expression is dynamically tagged)], a check is
  16032.        made that the tag of the value of the expression is the same as
  16033.        that of the target; if this check fails, Constraint_Error is
  16034.        raised.
  16035.  
  16036. 11   The value of the expression is converted to the subtype of the target.
  16037. [The conversion might raise an exception (see 4.6).]  {implicit subtype
  16038. conversion [assignment_statement]}
  16039.  
  16040.         11.a   Ramification:  4.6, ``Type Conversions'' defines what actions
  16041.         and checks are associated with subtype conversion.  For non-array
  16042.         subtypes, it is just a constraint check presuming the types match.
  16043.         For array subtypes, it checks the lengths and slides if the target is
  16044.         constrained.  ``Sliding'' means the array doesn't have to have the
  16045.         same bounds, so long as it is the same length.
  16046.  
  16047. 12   In cases involving controlled types, the target is finalized, and an
  16048. anonymous object might be used as an intermediate in the assignment, as
  16049. described in 7.6.1, ``Completion and Finalization''.  {assignment operation}
  16050. {assignment operation (during execution of an assignment_statement)} In any
  16051. case, the converted value of the expression is then assigned to the target,
  16052. which consists of the following two steps:
  16053.  
  16054.         12.a   To be honest:  7.6.1 actually says that finalization happens
  16055.         always, but unless controlled types are involved, this finalization
  16056.         during an assignment_statement does nothing.
  16057.  
  16058.    13  The value of the target becomes the converted value.
  16059.  
  16060.    14  If any part of the target is controlled, its value is adjusted as
  16061.        explained in clause 7.6.  {adjustment [as part of assignment]}
  16062.  
  16063.  14.a   Ramification:  If any parts of the object are controlled, abort
  16064.         is deferred during the assignment operation itself, but not
  16065.         during the rest of the execution of an assignment_statement.
  16066.  
  16067.  
  16068.      NOTES
  16069. 15   (2) The tag of an object never changes; in particular, an assignment_
  16070.      statement does not change the tag of the target.
  16071.  
  16072. 16   (3) The values of the discriminants of an object designated by an access
  16073.      value cannot be changed (not even by assigning a complete value to the
  16074.      object itself) since such objects are always constrained; however,
  16075.      subcomponents of such objects may be unconstrained.
  16076.  
  16077.    16.a   Ramification:  The implicit subtype conversion described above for
  16078.         assignment_statements is performed only for the value of the
  16079.         right-hand side expression as a whole; it is not performed for
  16080.         subcomponents of the value.
  16081.  
  16082.    16.b   The determination of the type of the variable of an assignment_
  16083.         statement may require consideration of the expression if the variable
  16084.         name can be interpreted as the name of a variable designated by the
  16085.         access value returned by a function call, and similarly, as a
  16086.         component or slice of such a variable (see 8.6, ``The Context of
  16087.         Overload Resolution'').
  16088.  
  16089.  
  16090.                                   Examples
  16091.  
  16092. 17   Examples of assignment statements:
  16093.  
  16094. 18  Value := Max_Value - 1;
  16095.     Shade := Blue;
  16096.  
  16097. 19  Next_Frame(F)(M, N) := 2.5;        --  see 4.1.1
  16098.     U := Dot_Product(V, W);            --  see 6.3
  16099.  
  16100. 20  Writer := (Status => Open, Unit => Printer, Line_Count => 60);  -- see 3.8.1
  16101.     Next_Car.all := (72074, null);    --  see 3.10.1
  16102.  
  16103. 21   Examples involving scalar subtype conversions:
  16104.  
  16105. 22  I, J : Integer range 1 .. 10 := 5;
  16106.     K    : Integer range 1 .. 20 := 15;
  16107.      ...
  16108.  
  16109. 23  I := J;  --  identical ranges
  16110.     K := J;  --  compatible ranges
  16111.     J := K;  --  will raise Constraint_Error if K > 10
  16112.  
  16113. 24   Examples involving array subtype conversions:
  16114.  
  16115. 25  A : String(1 .. 31);
  16116.     B : String(3 .. 33);
  16117.      ...
  16118.  
  16119. 26  A := B;  --  same number of components
  16120.  
  16121. 27  A(1 .. 9)  := "tar sauce";
  16122.     A(4 .. 12) := A(1 .. 9);  --  A(1 .. 12) = "tartar sauce"
  16123.  
  16124.  
  16125.      NOTES
  16126. 28   (4) Notes on the examples:  Assignment_statements are allowed even in
  16127.      the case of overlapping slices of the same array, because the
  16128.      variable_name and expression are both evaluated before copying the value
  16129.      into the variable.  In the above example, an implementation yielding A(1
  16130.      .. 12) = "tartartartar" would be incorrect.
  16131.  
  16132.  
  16133.                             Extensions to Ada 83
  16134.  
  16135.         28.a   {extensions to Ada 83} We now allow user-defined finalization
  16136.         and value adjustment actions as part of assignment_statements (see
  16137.         7.6, ``User-Defined Assignment and Finalization'').
  16138.  
  16139.                          Wording Changes From Ada 83
  16140.  
  16141.         28.b   The special case of array assignment is subsumed by the
  16142.         concept of a subtype conversion, which is applied for all kinds of
  16143.         types, not just arrays.  For arrays it provides ``sliding.''  For
  16144.         numeric types it provides conversion of a value of a universal type
  16145.         to the specific type of the target.  For other types, it generally
  16146.         has no run-time effect, other than a constraint check.
  16147.  
  16148.         28.c   We now cover in a general way in 3.7.2 the erroneous execution
  16149.         possible due to changing the value of a discriminant when the
  16150.         variable in an assignment_statement is a subcomponent that depends on
  16151.         discriminants.
  16152.  
  16153.  
  16154.  
  16155. 5.3 If Statements
  16156.  
  16157. 1   [An if_statement selects for execution at most one of the enclosed
  16158. sequences_of_statements, depending on the (truth) value of one or more
  16159. corresponding conditions.]
  16160.  
  16161.  
  16162.                                    Syntax
  16163.  
  16164. 2   if_statement ::=
  16165.         if condition then
  16166.           sequence_of_statements
  16167.        {elsif condition then
  16168.           sequence_of_statements}
  16169.        [else
  16170.           sequence_of_statements]
  16171.         end if;
  16172.  
  16173. 3   condition ::= boolean_expression
  16174.  
  16175.  
  16176.                             Name Resolution Rules
  16177.  
  16178. 4   {expected type [condition]} A condition is expected to be of any boolean
  16179. type.
  16180.  
  16181.  
  16182.                               Dynamic Semantics
  16183.  
  16184. 5   {execution [if_statement]} For the execution of an if_statement, the
  16185. condition specified after if, and any conditions specified after elsif, are
  16186. evaluated in succession (treating a final else as elsif True then), until one
  16187. evaluates to True or all conditions are evaluated and yield False.  If a
  16188. condition evaluates to True, then the corresponding sequence_of_statements is
  16189. executed; otherwise none of them is executed.
  16190.         5.a   Ramification:  The part about all evaluating to False can't
  16191.         happen if there is an else, since that is herein considered
  16192.         equivalent to elsif True then.
  16193.  
  16194.  
  16195.                                   Examples
  16196.  
  16197. 6   Examples of if statements:
  16198.  
  16199. 7   if Month = December and Day = 31 then
  16200.        Month := January;
  16201.        Day   := 1;
  16202.        Year  := Year + 1;
  16203.     end if;
  16204.  
  16205. 8   if Line_Too_Short then
  16206.        raise Layout_Error;
  16207.     elsif Line_Full then
  16208.        New_Line;
  16209.        Put(Item);
  16210.     else
  16211.        Put(Item);
  16212.     end if;
  16213.  
  16214. 9   if My_Car.Owner.Vehicle /= My_Car then            --  see 3.10.1
  16215.        Report ("Incorrect data");
  16216.     end if;
  16217.  
  16218.  
  16219.  
  16220. 5.4 Case Statements
  16221.  
  16222. 1   [A case_statement selects for execution one of a number of alternative
  16223. sequences_of_statements; the chosen alternative is defined by the value of an
  16224. expression.]
  16225.  
  16226.  
  16227.                                    Syntax
  16228.  
  16229. 2   case_statement ::=
  16230.        case expression is
  16231.            case_statement_alternative
  16232.           {case_statement_alternative}
  16233.        end case;
  16234.  
  16235. 3   case_statement_alternative ::=
  16236.        when discrete_choice_list =>
  16237.           sequence_of_statements
  16238.  
  16239.  
  16240.                             Name Resolution Rules
  16241.  
  16242. 4   {expected type [case expression]} The expression is expected to be of any
  16243. discrete type.  {expected type [case_statement_alternative discrete_choice]}
  16244. The expected type for each discrete_choice is the type of the expression.
  16245.  
  16246.  
  16247.                                Legality Rules
  16248.  
  16249. 5   The expressions and discrete_ranges given as discrete_choices of a case_
  16250. statement shall be static.  [A discrete_choice others, if present, shall
  16251. appear alone and in the last discrete_choice_list.]
  16252.  
  16253. 6   The possible values of the expression shall be covered as follows:
  16254.  
  16255.     7  If the expression is a name [(including a type_conversion or a
  16256.        function_call)] having a static and constrained nominal subtype,
  16257.        or is a qualified_expression whose subtype_mark denotes a static
  16258.        and constrained scalar subtype, then each non-others discrete_
  16259.        choice shall cover only values in that subtype, and each value of
  16260.        that subtype shall be covered by some discrete_choice [(either
  16261.        explicitly or by others)].
  16262.  
  16263.  7.a    Ramification:  Although not official names of objects, a value
  16264.         conversion still has a defined nominal subtype, namely its
  16265.         target subtype.  See 4.6.
  16266.  
  16267.     8  If the type of the expression is root_integer, universal_integer,
  16268.        or a descendant of a formal scalar type, then the case_statement
  16269.        shall have an others discrete_choice.
  16270.  
  16271.  8.a    Reason:  This is because the base range is implementation
  16272.         defined for root_integer and universal_integer, and not known
  16273.         statically in the case of a formal scalar type.
  16274.  
  16275.     9  Otherwise, each value of the base range of the type of the
  16276.        expression shall be covered [(either explicitly or by others)].
  16277.  
  16278. 10   Two distinct discrete_choices of a case_statement shall not cover the
  16279. same value.
  16280.  
  16281.         10.a   Ramification:  The goal of these coverage rules is that any
  16282.         possible value of the expression of a case_statement should be
  16283.         covered by exactly one discrete_choice of the case_statement, and
  16284.         that this should be checked at compile time.  The goal is achieved in
  16285.         most cases, but there are two minor loopholes:
  16286.  
  16287.          10.b  If the expression reads an object with an invalid
  16288.                representation (e.g. an uninitialized object), then the
  16289.                value can be outside the covered range.  This can happen
  16290.                for static constrained subtypes, as well as nonstatic or
  16291.                unconstrained subtypes.  It cannot, however, happen if
  16292.                the case_statement has the discrete_choice others,
  16293.                because others covers all values, even those outside the
  16294.                subtype.
  16295.  
  16296.          10.c  If the compiler chooses to represent the value of an
  16297.                expression of an unconstrained subtype in a way that
  16298.                includes values outside the bounds of the subtype, then
  16299.                those values can be outside the covered range.  For
  16300.                example, if X: Integer := Integer'Last;, and the case
  16301.                expression is X+1, then the implementation might choose
  16302.                to produce the correct value, which is outside the bounds
  16303.                of Integer.  (It might raise Constraint_Error instead.)
  16304.                This case can only happen for non-generic subtypes that
  16305.                are either unconstrained or non-static (or both).  It can
  16306.                only happen if there is no others discrete_choice.
  16307.  
  16308.         10.d   In the uninitialized variable case, the value might be
  16309.         anything; hence, any alternative can be chosen, or Constraint_Error
  16310.         can be raised.  (We intend to prevent, however, jumping to random
  16311.         memory locations and the like.)  In the out-of-range case, the
  16312.         behavior is more sensible: if there is an others, then the
  16313.         implementation may choose to raise Constraint_Error on the evaluation
  16314.         of the expression (as usual), or it may choose to correctly evaluate
  16315.         the expression and therefore choose the others alternative.
  16316.         Otherwise (no others), Constraint_Error is raised either way -- on
  16317.         the expression evaluation, or for the case_statement itself.
  16318.  
  16319.         10.e   For an enumeration type with a discontiguous set of internal
  16320.         codes (see 13.4), the only way to get values in between the proper
  16321.         values is via an object with an invalid representation; there is no
  16322.         ``out-of-range'' situation that can produce them.
  16323.  
  16324.  
  16325.                               Dynamic Semantics
  16326.  
  16327. 11   {execution [case_statement]} For the execution of a case_statement the
  16328. expression is first evaluated.
  16329.  
  16330. 12   If the value of the expression is covered by the discrete_choice_list of
  16331. some case_statement_alternative, then the sequence_of_statements of the
  16332. _alternative is executed.
  16333.  
  16334. 13   {Overflow_Check [partial]} {check, language-defined (Overflow_Check)}
  16335. {Constraint_Error (raised by failure of run-time check)} Otherwise (the value
  16336. is not covered by any discrete_choice_list, perhaps due to being outside the
  16337. base range), Constraint_Error is raised.  {94-4768.e}
  16338.  
  16339.         13.a   Ramification:  In this case, the value is outside the base
  16340.         range of its type, or is an invalid representation.
  16341.  
  16342.  
  16343.      NOTES
  16344. 14   (5) The execution of a case_statement chooses one and only one
  16345.      alternative.  Qualification of the expression of a case_statement by a
  16346.      static subtype can often be used to limit the number of choices that
  16347.      need be given explicitly.
  16348.  
  16349.  
  16350.                                   Examples
  16351.  
  16352. 15   Examples of case statements:
  16353.  
  16354. 16  case Sensor is
  16355.        when Elevation  => Record_Elevation(Sensor_Value);
  16356.        when Azimuth    => Record_Azimuth  (Sensor_Value);
  16357.        when Distance   => Record_Distance (Sensor_Value);
  16358.        when others     => null;
  16359.     end case;
  16360.  
  16361. 17
  16362.     case Today is
  16363.        when Mon        => Compute_Initial_Balance;
  16364.        when Fri        => Compute_Closing_Balance;
  16365.        when Tue .. Thu => Generate_Report(Today);
  16366.        when Sat .. Sun => null;
  16367.     end case;
  16368.  
  16369. 18
  16370.     case Bin_Number(Count) is
  16371.        when 1      => Update_Bin(1);
  16372.        when 2      => Update_Bin(2);
  16373.        when 3 | 4  =>
  16374.           Empty_Bin(1);
  16375.           Empty_Bin(2);
  16376.        when others => raise Error;
  16377.     end case;
  16378.  
  16379.  
  16380.                             Extensions to Ada 83
  16381.  
  16382.         18.a   {extensions to Ada 83} In Ada 83, the expression in a case_
  16383.         statement is not allowed to be of a generic formal type.  This
  16384.         restriction is removed in Ada 9X; an others discrete_choice is
  16385.         required instead.
  16386.  
  16387.         18.b   In Ada 9X, a function call is the name of an object; this was
  16388.         not true in Ada 83 (see 4.1, ``Names'').  This change makes the
  16389.         following case_statement legal:
  16390. 18.c        subtype S is Integer range 1..2;
  16391.             function F return S;
  16392.             case F is
  16393.                when 1 => ...;
  16394.                when 2 => ...;
  16395.                -- No others needed.
  16396.             end case;
  16397.  
  16398.         18.d   Note that the result subtype given in a function renaming_
  16399.         declaration is ignored; for a case_statement whose expression calls a
  16400.         such a function, the full coverage rules are checked using the result
  16401.         subtype of the original function.  Note that predefined operators
  16402.         such as "+" have an unconstrained result subtype (see 4.5.1).  Note
  16403.         that generic formal functions do not have static result subtypes.
  16404.         Note that the result subtype of an inherited subprogram need not
  16405.         correspond to any namable subtype; there is still a perfectly good
  16406.         result subtype, though.
  16407.  
  16408.                          Wording Changes From Ada 83
  16409.  
  16410.         18.e   Ada 83 forgot to say what happens for ``legally''
  16411.         out-of-bounds values.
  16412.  
  16413.         18.f   We take advantage of rules and terms (e.g. cover a value)
  16414.         defined for discrete_choices and discrete_choice_lists in 3.8.1,
  16415.         ``Variant Parts and Discrete Choices''.
  16416.  
  16417.         18.g   In the Name Resolution Rule for the case expression, we no
  16418.         longer need RM83-5.4(3)'s ``which must be determinable independently
  16419.         of the context in which the expression occurs, but using the fact
  16420.         that the expression must be of a discrete type,'' because the
  16421.         expression is now a complete context.  See 8.6, ``The Context of
  16422.         Overload Resolution''.
  16423.  
  16424.         18.h   Since type_conversions are now defined as names, their
  16425.         coverage rule is now covered under the general rule for names, rather
  16426.         than being separated out along with qualified_expressions.
  16427.  
  16428.  
  16429.  
  16430. 5.5 Loop Statements
  16431.  
  16432. 1   [A loop_statement includes a sequence_of_statements that is to be
  16433. executed repeatedly, zero or more times.]
  16434.  
  16435.  
  16436.                                    Syntax
  16437.  
  16438. 2   loop_statement ::=
  16439.        [loop_statement_identifier:]
  16440.           [iteration_scheme] loop
  16441.              sequence_of_statements
  16442.            end loop [loop_identifier];
  16443.  
  16444. 3   iteration_scheme ::= while condition
  16445.        | for loop_parameter_specification
  16446.  
  16447. 4   loop_parameter_specification ::=
  16448.        defining_identifier in [reverse] discrete_subtype_definition
  16449.  
  16450.     5   If a loop_statement has a loop_statement_identifier, then the
  16451.     identifier shall be repeated after the end loop; otherwise, there shall
  16452.     not be an identifier after the end loop.
  16453.  
  16454.  
  16455.                               Static Semantics
  16456.  
  16457. 6   {loop parameter} A loop_parameter_specification declares a loop
  16458. parameter, which is an object whose subtype is that defined by the discrete_
  16459. subtype_definition.  {parameter: see also loop parameter}
  16460.  
  16461.  
  16462.                               Dynamic Semantics
  16463.  
  16464. 7   {execution [loop_statement]} For the execution of a loop_statement, the
  16465. sequence_of_statements is executed repeatedly, zero or more times, until the
  16466. loop_statement is complete.  The loop_statement is complete when a transfer
  16467. of control occurs that transfers control out of the loop, or, in the case of
  16468. an iteration_scheme, as specified below.
  16469.  
  16470. 8   {execution [loop_statement with a while iteration_scheme]} For the
  16471. execution of a loop_statement with a while iteration_scheme, the condition is
  16472. evaluated before each execution of the sequence_of_statements; if the value
  16473. of the condition is True, the sequence_of_statements is executed; if False,
  16474. the execution of the loop_statement is complete.
  16475.  
  16476. 9   {execution [loop_statement with a for iteration_scheme]} {elaboration
  16477. [loop_parameter_specification]} For the execution of a loop_statement with a
  16478. for iteration_scheme, the loop_parameter_specification is first elaborated.
  16479. This elaboration creates the loop parameter and elaborates the discrete_
  16480. subtype_definition.  If the discrete_subtype_definition defines a subtype
  16481. with a null range, the execution of the loop_statement is complete.
  16482. Otherwise, the sequence_of_statements is executed once for each value of the
  16483. discrete subtype defined by the discrete_subtype_definition (or until the
  16484. loop is left as a consequence of a transfer of control).  {assignment
  16485. operation (during execution of a for loop)} Prior to each such iteration, the
  16486. corresponding value of the discrete subtype is assigned to the loop
  16487. parameter.  These values are assigned in increasing order unless the reserved
  16488. word reverse is present, in which case the values are assigned in decreasing
  16489. order.
  16490.  
  16491.         9.a   Ramification:  The order of creating the loop parameter and
  16492.         evaluating the discrete_subtype_definition doesn't matter, since the
  16493.         creation of the loop parameter has no side effects (other than
  16494.         possibly raising Storage_Error, but anything can do that).
  16495.  
  16496.  
  16497.      NOTES
  16498. 10   (6) A loop parameter is a constant; it cannot be updated within the
  16499.      sequence_of_statements of the loop (see 3.3).
  16500.  
  16501. 11   (7) An object_declaration should not be given for a loop parameter,
  16502.      since the loop parameter is automatically declared by the loop_
  16503.      parameter_specification.  The scope of a loop parameter extends from the
  16504.      loop_parameter_specification to the end of the loop_statement, and the
  16505.      visibility rules are such that a loop parameter is only visible within
  16506.      the sequence_of_statements of the loop.
  16507.  
  16508.    11.a   Implementation Note:  An implementation could give a warning if a
  16509.         variable is hidden by a loop_parameter_specification.
  16510.  
  16511. 12   (8) The discrete_subtype_definition of a for loop is elaborated just
  16512.      once.  Use of the reserved word reverse does not alter the discrete
  16513.      subtype defined, so that the following iteration_schemes are not
  16514.      equivalent; the first has a null range.
  16515.  
  16516. 13       for J in reverse 1 ..  0
  16517.          for J in 0 .. 1
  16518.  
  16519.    13.a   Ramification:  If a loop_parameter_specification has a static
  16520.         discrete range, the subtype of the loop parameter is static.
  16521.  
  16522.  
  16523.                                   Examples
  16524.  
  16525. 14   Example of a loop statement without an iteration scheme:
  16526.  
  16527. 15  loop
  16528.        Get(Current_Character);
  16529.        exit when Current_Character = '*';
  16530.     end loop;
  16531.  
  16532. 16   Example of a loop statement with a while iteration scheme:
  16533.  
  16534. 17  while Bid(N).Price < Cut_Off.Price loop
  16535.        Record_Bid(Bid(N).Price);
  16536.        N := N + 1;
  16537.     end loop;
  16538.  
  16539. 18   Example of a loop statement with a for iteration scheme:
  16540.  
  16541. 19  for J in Buffer'Range loop     --  works even with a null range
  16542.        if Buffer(J) /= Space then
  16543.           Put(Buffer(J));
  16544.        end if;
  16545.     end loop;
  16546.  
  16547. 20   Example of a loop statement with a name:
  16548.  
  16549. 21  Summation:
  16550.        while Next /= Head loop       -- see 3.10.1
  16551.           Sum  := Sum + Next.Value;
  16552.           Next := Next.Succ;
  16553.        end loop Summation;
  16554.  
  16555.  
  16556.                          Wording Changes From Ada 83
  16557.  
  16558.         21.a   The constant-ness of loop parameters is specified in 3.3,
  16559.         ``Objects and Named Numbers''.
  16560.  
  16561.  
  16562.  
  16563. 5.6 Block Statements
  16564.  
  16565. 1   [A block_statement encloses a handled_sequence_of_statements optionally
  16566. preceded by a declarative_part.]
  16567.  
  16568.  
  16569.                                    Syntax
  16570.  
  16571. 2   block_statement ::=
  16572.        [block_statement_identifier:]
  16573.            [declare
  16574.                 declarative_part]
  16575.             begin
  16576.                 handled_sequence_of_statements
  16577.             end [block_identifier];
  16578.  
  16579.     3   If a block_statement has a block_statement_identifier, then the
  16580.     identifier shall be repeated after the end; otherwise, there shall not be
  16581.     an identifier after the end.
  16582.  
  16583.  
  16584.                               Static Semantics
  16585.  
  16586. 4   A block_statement that has no explicit declarative_part has an implicit
  16587. empty declarative_part.
  16588.         4.a   Ramification:  Thus, other rules can always refer to the
  16589.         declarative_part of a block_statement.
  16590.  
  16591.  
  16592.                               Dynamic Semantics
  16593.  
  16594. 5   {execution [block_statement]} The execution of a block_statement consists
  16595. of the elaboration of its declarative_part followed by the execution of its
  16596. handled_sequence_of_statements.
  16597.  
  16598.  
  16599.                                   Examples
  16600.  
  16601. 6   Example of a block statement with a local variable:
  16602.  
  16603. 7   Swap:
  16604.        declare
  16605.           Temp : Integer;
  16606.        begin
  16607.           Temp := V; V := U; U := Temp;
  16608.        end Swap;
  16609.  
  16610.         7.a   Ramification:  If task objects are declared within a block_
  16611.         statement whose execution is completed, the block_statement is not
  16612.         left until all its dependent tasks are terminated (see 7.6).  This
  16613.         rule applies to completion caused by a transfer of control.
  16614.  
  16615.         7.b   Within a block_statement, the block name can be used in
  16616.         expanded names denoting local entities such as Swap.Temp in the above
  16617.         example (see 4.1.3).
  16618.  
  16619.  
  16620.                          Wording Changes From Ada 83
  16621.  
  16622.         7.c   The syntax rule for block_statement now uses the syntactic
  16623.         category handled_sequence_of_statements.
  16624.  
  16625.  
  16626.  
  16627. 5.7 Exit Statements
  16628.  
  16629. 1   [An exit_statement is used to complete the execution of an enclosing
  16630. loop_statement; the completion is conditional if the exit_statement includes
  16631. a condition.]  {94-4605.a} {94-4560.a}
  16632.  
  16633.  
  16634.                                    Syntax
  16635.  
  16636. 2   exit_statement ::=
  16637.        exit [loop_name] [when condition];
  16638.  
  16639.  
  16640.                             Name Resolution Rules
  16641.  
  16642. 3   The loop_name, if any, in an exit_statement shall resolve to denote a
  16643. loop_statement.
  16644.  
  16645.  
  16646.                                Legality Rules
  16647.  
  16648. 4   {apply (to a loop_statement by an exit_statement)} Each exit_statement
  16649. applies to a loop_statement; this is the loop_statement being exited.  An
  16650. exit_statement with a name is only allowed within the loop_statement denoted
  16651. by the name, and applies to that loop_statement.  An exit_statement without a
  16652. name is only allowed within a loop_statement, and applies to the innermost
  16653. enclosing one.  An exit_statement that applies to a given loop_statement
  16654. shall not appear within a body or accept_statement, if this construct is
  16655. itself enclosed by the given loop_statement.
  16656.  
  16657.  
  16658.                               Dynamic Semantics
  16659.  
  16660. 5   {execution [exit_statement]} For the execution of an exit_statement, the
  16661. condition, if present, is first evaluated.  If the value of the condition is
  16662. True, or if there is no condition, a transfer of control is done to complete
  16663. the loop_statement.  If the value of the condition is False, no transfer of
  16664. control takes place.
  16665.  
  16666.  
  16667.      NOTES
  16668. 6    (9) Several nested loops can be exited by an exit_statement that names
  16669.      the outer loop.
  16670.  
  16671.  
  16672.                                   Examples
  16673.  
  16674. 7   Examples of loops with exit statements:
  16675.  
  16676. 8   for N in 1 .. Max_Num_Items loop
  16677.        Get_New_Item(New_Item);
  16678.        Merge_Item(New_Item, Storage_File);
  16679.        exit when New_Item = Terminal_Item;
  16680.     end loop;
  16681.  
  16682. 9   Main_Cycle:
  16683.        loop
  16684.           --  initial statements
  16685.           exit Main_Cycle when Found;
  16686.           --  final statements
  16687.        end loop Main_Cycle;
  16688.  
  16689.  
  16690.  
  16691. 5.8 Goto Statements
  16692.  
  16693. 1   [A goto_statement specifies an explicit transfer of control from this
  16694. statement to a target statement with a given label.]
  16695.  
  16696.  
  16697.                                    Syntax
  16698.  
  16699. 2   goto_statement ::= goto label_name;
  16700.  
  16701.  
  16702.                             Name Resolution Rules
  16703.  
  16704. 3   {target statement (of a goto_statement)} The label_name shall resolve to
  16705. denote a label; the statement with that label is the target statement.
  16706.  
  16707.  
  16708.                                Legality Rules
  16709.  
  16710. 4   The innermost sequence_of_statements that encloses the target statement
  16711. shall also enclose the goto_statement.
  16712.  
  16713.         4.a   Ramification:  The goto_statement can be a statement of an
  16714.         inner sequence_.
  16715.  
  16716. Furthermore, if a goto_statement is enclosed by an accept_statement or a
  16717. body, then the target statement shall not be outside this enclosing
  16718. construct.
  16719.  
  16720.         4.b   Ramification:  It follows from the previous rule that if the
  16721.         target statement is enclosed by such a construct, then the goto_
  16722.         statement cannot be outside.
  16723.  
  16724.  
  16725.                               Dynamic Semantics
  16726.  
  16727. 5   {execution [goto_statement]} The execution of a goto_statement transfers
  16728. control to the target statement, completing the execution of any compound_
  16729. statement that encloses the goto_statement but does not enclose the target.
  16730.  
  16731.  
  16732.      NOTES
  16733. 6    (10) The above rules allow transfer of control to a statement of an
  16734.      enclosing sequence_of_statements but not the reverse.  Similarly, they
  16735.      prohibit transfers of control such as between alternatives of a case_
  16736.      statement, if_statement, or select_statement; between exception_
  16737.      handlers; or from an exception_handler of a handled_sequence_of_
  16738.      statements back to its sequence_of_statements.
  16739.  
  16740.  
  16741.                                   Examples
  16742.  
  16743. 7   Example of a loop containing a goto statement:
  16744.  
  16745. 8   <<Sort>>
  16746.     for I in 1 .. N-1 loop
  16747.        if A(I) > A(I+1) then
  16748.           Exchange(A(I), A(I+1));
  16749.           goto Sort;
  16750.        end if;
  16751.     end loop;
  16752.  
  16753.  
  16754.  
  16755.                            Section 6: Subprograms
  16756.  
  16757.  
  16758. 1   {subprogram} {procedure} {function} A subprogram is a program unit or
  16759. intrinsic operation whose execution is invoked by a subprogram call.  There
  16760. are two forms of subprogram: procedures and functions.  A procedure call is a
  16761. statement; a function call is an expression and returns a value.  The
  16762. definition of a subprogram can be given in two parts:  a subprogram
  16763. declaration defining its interface, and a subprogram_body defining its
  16764. execution.  [Operators and enumeration literals are functions.]
  16765.  
  16766.         1.a   To be honest:  A function call is an expression, but more
  16767.         specifically it is a name.
  16768.  
  16769. 2   {callable entity} A callable entity is a subprogram or entry (see Section
  16770. 9).  {call} A callable entity is invoked by a call; that is, a subprogram
  16771. call or entry call.  {callable construct} A callable construct is a construct
  16772. that defines the action of a call upon a callable entity:  a subprogram_body,
  16773. entry_body, or accept_statement.
  16774.  
  16775.         2.a   Ramification:  Note that ``callable entity'' includes
  16776.         predefined operators, enumeration literals, and abstract subprograms.
  16777.         ``Call'' includes calls of these things.  They do not have callable
  16778.         constructs, since they don't have completions.
  16779.  
  16780.  
  16781.  
  16782. 6.1 Subprogram Declarations
  16783.  
  16784. 1   [A subprogram_declaration declares a procedure or function.]
  16785.                                    Syntax
  16786.  
  16787. 2   subprogram_declaration ::= subprogram_specification;
  16788.  
  16789. 3   abstract_subprogram_declaration ::= subprogram_specification is abstract;
  16790.  
  16791. 4   subprogram_specification ::=
  16792.          procedure defining_program_unit_name  parameter_profile
  16793.        | function defining_designator  parameter_and_result_profile
  16794.  
  16795. 5   designator ::= [parent_unit_name . ]identifier | operator_symbol
  16796.  
  16797. 6   defining_designator ::= defining_program_unit_name | defining_operator_symb\
  16798. ol
  16799.  
  16800. 7   defining_program_unit_name ::= [parent_unit_name . ]defining_identifier
  16801.  
  16802.     8   [The optional parent_unit_name is only allowed for library units (see
  16803.     10.1.1).]
  16804.  
  16805.  
  16806. 9   operator_symbol ::= string_literal
  16807.  
  16808.     10   The sequence of characters in an operator_symbol shall correspond to
  16809.     an operator belonging to one of the six classes of operators defined in
  16810.     clause 4.5 (spaces are not allowed and the case of letters is not
  16811.     significant).
  16812.  
  16813.  
  16814. 11  defining_operator_symbol ::= operator_symbol
  16815.  
  16816. 12  parameter_profile ::= [formal_part]
  16817.  
  16818. 13  parameter_and_result_profile ::= [formal_part] return subtype_mark
  16819.  
  16820. 14  formal_part ::=
  16821.        (parameter_specification {; parameter_specification})
  16822.  
  16823. 15  parameter_specification ::=
  16824.         defining_identifier_list : mode  subtype_mark [:= default_expression]
  16825.       | defining_identifier_list : access_definition [:= default_expression]
  16826.  
  16827. 16  mode ::= [in] | in out | out
  16828.  
  16829.  
  16830.                             Name Resolution Rules
  16831.  
  16832. 17   {formal parameter (of a subprogram)} A formal parameter is an object
  16833. [directly visible within a subprogram_body] that represents the actual
  16834. parameter passed to the subprogram in a call; it is declared by a parameter_
  16835. specification.  {expected type [parameter default_expression]} For a formal
  16836. parameter, the expected type for its default_expression, if any, is that of
  16837. the formal parameter.  {parameter: see formal parameter}
  16838.  
  16839.  
  16840.                                Legality Rules
  16841.  
  16842. 18   {parameter mode} The parameter mode of a formal parameter conveys the
  16843. direction of information transfer with the actual parameter:  in, in out, or
  16844. out.  Mode in is the default, and is the mode of a parameter defined by an
  16845. access_definition.  The formal parameters of a function, if any, shall have
  16846. the mode in.
  16847.  
  16848.         18.a   Ramification:  Access parameters are permitted.  This
  16849.         restriction to in parameters is primarily a methodological
  16850.         restriction, though it also simplifies implementation for some
  16851.         compiler technologies.
  16852.  
  16853. 19   A default_expression is only allowed in a parameter_specification for a
  16854. formal parameter of mode in.
  16855.  
  16856. 20   {requires a completion [subprogram_declaration]} {requires a completion
  16857. [generic_subprogram_declaration]} A subprogram_declaration or a generic_
  16858. subprogram_declaration requires a completion:  [a body, a renaming_
  16859. declaration (see 8.5), or a pragma Import (see B.1)].  [A completion is not
  16860. allowed for an abstract_subprogram_declaration.]
  16861.  
  16862.         20.a   Ramification:  Abstract subprograms are not declared by
  16863.         subprogram_declarations, and so do not require completion.  Protected
  16864.         subprograms are declared by subprogram_declarations, and so require
  16865.         completion.  Note that an abstract subprogram is a subprogram, and a
  16866.         protected subprogram is a subprogram, but a generic subprogram is not
  16867.         a subprogram.
  16868.  
  16869. 21   A name that denotes a formal parameter is not allowed within the formal_
  16870. part in which it is declared, nor within the formal_part of a corresponding
  16871. body or accept_statement.
  16872.  
  16873.         21.a   Ramification:  By contrast, generic_formal_parameter_declara-
  16874.         tions are visible to subsequent declarations in the same generic_
  16875.         formal_part.
  16876.  
  16877.  
  16878.                               Static Semantics
  16879.  
  16880. 22   {profile} The profile of (a view of) a callable entity is either a
  16881. parameter_profile or parameter_and_result_profile[; it embodies information
  16882. about the interface to that entity -- for example, the profile includes
  16883. information about parameters passed to the callable entity.  All callable
  16884. entities have a profile -- enumeration literals, other subprograms, and
  16885. entries.  An access-to-subprogram type has a designated profile.]  Associated
  16886. with a profile is a calling convention.  A subprogram_declaration declares a
  16887. procedure or a function, as indicated by the initial reserved word, with name
  16888. and profile as given by its specification.
  16889.  
  16890. 23   {nominal subtype [of a formal parameter]} The nominal subtype of a
  16891. formal parameter is the subtype denoted by the subtype_mark, or defined by
  16892. the access_definition, in the parameter_specification.
  16893.  
  16894. 24   {access parameter} An access parameter is a formal in parameter
  16895. specified by an access_definition.  An access parameter is of an anonymous
  16896. general access-to-variable type (see 3.10).  [Access parameters allow
  16897. dispatching calls to be controlled by access values.]
  16898.  
  16899. 25   {subtypes (of a profile)} The subtypes of a profile are:
  16900.  
  16901.    26  For any non-access parameters, the nominal subtype of the
  16902.        parameter.
  16903.  
  16904.    27  For any access parameters, the designated subtype of the
  16905.        parameter type.
  16906.  
  16907.    28  For any result, the result subtype.
  16908.  
  16909. 29   [{types (of a profile)} The types of a profile are the types of those
  16910. subtypes.]
  16911.  
  16912. 30   [A subprogram declared by an abstract_subprogram_declaration is
  16913. abstract; a subprogram declared by a subprogram_declaration is not.  See
  16914. 3.9.3, ``Abstract Types and Subprograms''.]
  16915.  
  16916.  
  16917.                               Dynamic Semantics
  16918.  
  16919. 31   {elaboration [subprogram_declaration]} {elaboration [abstract_
  16920. subprogram_declaration]} The elaboration of a subprogram_declaration or an
  16921. abstract_subprogram_declaration has no effect.
  16922.  
  16923.  
  16924.      NOTES
  16925. 32   (1) A parameter_specification with several identifiers is equivalent to
  16926.      a sequence of single parameter_specifications, as explained in 3.3.
  16927.  
  16928. 33   (2) Abstract subprograms do not have bodies, and cannot be used in a
  16929.      nondispatching call (see 3.9.3, ``Abstract Types and Subprograms'').
  16930.  
  16931. 34   (3) The evaluation of default_expressions is caused by certain calls, as
  16932.      described in 6.4.1.  They are not evaluated during the elaboration of
  16933.      the subprogram declaration.
  16934.  
  16935. 35   (4) Subprograms can be called recursively and can be called concurrently
  16936.      from multiple tasks.
  16937.  
  16938.  
  16939.                                   Examples
  16940.  
  16941. 36   Examples of subprogram declarations:
  16942.  
  16943. 37  procedure Traverse_Tree;
  16944.     procedure Increment(X : in out Integer);
  16945.     procedure Right_Indent(Margin : out Line_Size);          --  see 3.5.4
  16946.     procedure Switch(From, To : in out Link);                --  see 3.10.1
  16947.  
  16948. 38  function Random return Probability;                      --  see 3.5.7
  16949.  
  16950. 39  function Min_Cell(X : Link) return Cell;                 --  see 3.10.1
  16951.     function Next_Frame(K : Positive) return Frame;          --  see 3.10
  16952.     function Dot_Product(Left, Right : Vector) return Real;  --  see 3.6
  16953.  
  16954. 40  function "*"(Left, Right : Matrix) return Matrix;        --  see 3.6
  16955.  
  16956. 41   Examples of in parameters with default expressions:
  16957.  
  16958. 42  procedure Print_Header(Pages  : in Natural;
  16959.                 Header : in Line    :=  (1 .. Line'Last => ' ');  --  see 3.6
  16960.                 Center : in Boolean := True);
  16961.  
  16962.  
  16963.                             Extensions to Ada 83
  16964.  
  16965.         42.a   {extensions to Ada 83} The syntax for abstract_subprogram_
  16966.         declaration is added.  The syntax for parameter_specification is
  16967.         revised to allow for access parameters (see 3.10)
  16968.  
  16969.         42.b   Program units that are library units may have a parent_unit_
  16970.         name to indicate the parent of a child (see Section 10).
  16971.  
  16972.                          Wording Changes From Ada 83
  16973.  
  16974.         42.c   We have incorporated the rules from RM83-6.5, ``Function
  16975.         Subprograms'' here and in 6.3, ``Subprogram Bodies''
  16976.  
  16977.         42.d   We have incorporated the definitions of RM83-6.6, ``Parameter
  16978.         and Result Type Profile - Overloading of Subprograms'' here.
  16979.  
  16980.         42.e   The syntax rule for defining_operator_symbol is new.  It is
  16981.         used for the defining occurrence of an operator_symbol, analogously
  16982.         to defining_identifier.  Usage occurrences use the direct_name or
  16983.         selector_name syntactic categories.  The syntax rules for defining_
  16984.         designator and defining_program_unit_name are new.
  16985. 6.2 Formal Parameter Modes
  16986.  
  16987. 1   [A parameter_specification declares a formal parameter of mode in, in
  16988. out, or out.]
  16989.  
  16990.  
  16991.                               Static Semantics
  16992.  
  16993. 2   {pass by copy} {by copy parameter passing} {copy parameter passing} {pass
  16994. by reference} {by reference parameter passing} {reference parameter passing}
  16995. A parameter is passed either by copy or by reference.  [When a parameter is
  16996. passed by copy, the formal parameter denotes a separate object from the
  16997. actual parameter, and any information transfer between the two occurs only
  16998. before and after executing the subprogram.  When a parameter is passed by
  16999. reference, the formal parameter denotes (a view of) the object denoted by the
  17000. actual parameter; reads and updates of the formal parameter directly
  17001. reference the actual parameter object.]
  17002.  
  17003. 3   {by-copy type} A type is a by-copy type if it is an elementary type, or
  17004. if it is a descendant of a private type whose full type is a by-copy type.  A
  17005. parameter of a by-copy type is passed by copy.
  17006.  
  17007. 4   {by-reference type} A type is a by-reference type if it is a descendant
  17008. of one of the following:
  17009.  
  17010.     5  a tagged type;
  17011.  
  17012.     6  a task or protected type;
  17013.  
  17014.     7  a nonprivate type with the reserved word limited in its
  17015.        declaration;
  17016.  
  17017.  7.a    Ramification:  A limited private type is by-reference only if it
  17018.         falls under one of the other categories.
  17019.  
  17020.     8  a composite type with a subcomponent of a by-reference type;
  17021.  
  17022.     9  a private type whose full type is a by-reference type.
  17023.  
  17024. 10   A parameter of a by-reference type is passed by reference.  {associated
  17025. object (of a value of a by-reference type)} Each value of a by-reference type
  17026. has an associated object.  For a parenthesized expression, qualified_
  17027. expression, or type_conversion, this object is the one associated with the
  17028. operand.  {94-4774.a}
  17029.  
  17030.         10.a   Ramification:  By-reference parameter passing makes sense only
  17031.         if there is an object to reference; hence, we define such an object
  17032.         for each case.
  17033.  
  17034.         10.b   Since tagged types are by-reference types, this implies that
  17035.         every value of a tagged type has an associated object.  This
  17036.         simplifies things, because we can define the tag to be a property of
  17037.         the object, and not of the value of the object, which makes it
  17038.         clearer that object tags never change.
  17039.  
  17040.         10.c   We considered simplifying things even more by making every
  17041.         value (and therefore every expression) have an associated object.
  17042.         After all, there is little semantic difference between a constant
  17043.         object and a value.  However, this would cause problems for untagged
  17044.         types.  In particular, we would have to do a constraint check on
  17045.         every read of a type conversion (or a renaming thereof) in certain
  17046.         cases.
  17047.  
  17048.         10.d   We do not want this definition to depend on the view of the
  17049.         type; privateness is essentially ignored for this definition.
  17050.         Otherwise, things would be confusing (does the rule apply at the call
  17051.         site, at the site of the declaration of the subprogram, at the site
  17052.         of the return_statement?), and requiring different calls to use
  17053.         different mechanisms would be an implementation burden.
  17054.  
  17055.         10.e   C.6, ``Shared Variable Control'' says that a composite type
  17056.         with an atomic or volatile subcomponent is a by-reference type, among
  17057.         other things.
  17058.  
  17059.         10.f   {associated object (of a value of a limited type)} Every value
  17060.         of a limited by-reference type is the value of one and only one
  17061.         limited object.  The associated object of a value of a limited
  17062.         by-reference type is the object whose value it represents.  {same
  17063.         value (for a limited type)} Two values of a limited by-reference type
  17064.         are the same if and only if they represent the value of the same
  17065.         object.
  17066.  
  17067.         10.g   We say ``by-reference'' above because these statements are not
  17068.         always true for limited private types whose underlying type is
  17069.         nonlimited (unfortunately).
  17070.  
  17071. 11   {unspecified [partial]} For parameters of other types, it is unspecified
  17072. whether the parameter is passed by copy or by reference.
  17073.  
  17074.         11.a   Discussion:  There is no need to incorporate the discussion of
  17075.         AI-00178, which requires pass-by-copy for certain kinds of actual
  17076.         parameters, while allowing pass-by-reference for others.  This is
  17077.         because we explicitly indicate that a function creates an anonymous
  17078.         constant object for its result, unless the type is a
  17079.         return-by-reference type (see 6.5).  We also provide a special
  17080.         dispensation for instances of Unchecked_Conversion to return by
  17081.         reference, even if the result type is not a return-by-reference type
  17082.         (see 13.9).
  17083.  
  17084.  
  17085.                           Bounded (Run-Time) Errors
  17086.  
  17087. 12   {bounded error} {distinct access paths} {access paths (distinct)}
  17088. {aliasing: see distinct access paths} If one name denotes a part of a formal
  17089. parameter, and a second name denotes a part of a distinct formal parameter or
  17090. an object that is not part of a formal parameter, then the two names are
  17091. considered distinct access paths.  If an object is of a type for which the
  17092. parameter passing mechanism is not specified, then it is a bounded error to
  17093. assign to the object via one access path, and then read the value of the
  17094. object via a distinct access path, unless the first access path denotes a
  17095. part of a formal parameter that no longer exists at the point of the second
  17096. access [(due to leaving the corresponding callable construct).]  {94-4573.a}
  17097. {94-4572.a} {94-4751.a} {94-4572.b} {94-4751.b} {94-4572.c} {94-4751.c}
  17098. {Program_Error (raised by failure of run-time check)} The possible
  17099. consequences are that Program_Error is raised, or the newly assigned value is
  17100. read, or some old value of the object is read.
  17101.  
  17102.         12.a   Discussion:  For example, if we call ``P(X => Global_Variable,
  17103.         Y => Global_Variable)'', then within P, the names ``X'', ``Y'', and
  17104.         ``Global_Variable'' are all distinct access paths.  If Global_
  17105.         Variable's type is neither pass-by-copy nor pass-by-reference, then
  17106.         it is a bounded error to assign to Global_Variable and then read X or
  17107.         Y, since the language does not specify whether the old or the new
  17108.         value would be read.  On the other hand, if Global_Variable's type is
  17109.         pass-by-copy, then the old value would always be read, and there is
  17110.         no error.  Similarly, if Global_Variable's type is defined by the
  17111.         language to be pass-by-reference, then the new value would always be
  17112.         read, and again there is no error.
  17113.  
  17114.         12.b   Reason:  We are saying assign here, not update, because
  17115.         updating any subcomponent is considered to update the enclosing
  17116.         object.
  17117.  
  17118.         12.c   The ``still exists'' part is so that a read after the
  17119.         subprogram returns is OK.
  17120.  
  17121.         12.d   If the parameter is of a by-copy type, then there is no issue
  17122.         here -- the formal is not a view of the actual.  If the parameter is
  17123.         of a by-reference type, then the programmer may depend on updates
  17124.         through one access path being visible through some other access path,
  17125.         just as if the parameter were of an access type.
  17126.  
  17127.         12.e   Implementation Note:  The implementation can keep a copy in a
  17128.         register of a parameter whose parameter-passing mechanism is not
  17129.         specified.  If a different access path is used to update the object
  17130.         (creating a bounded error situation), then the implementation can
  17131.         still use the value of the register, even though the in-memory
  17132.         version of the object has been changed.  However, to keep the error
  17133.         properly bounded, if the implementation chooses to read the in-memory
  17134.         version, it has to be consistent -- it cannot then assume that
  17135.         something it has proven about the register is true of the memory
  17136.         location.  For example, suppose the formal parameter is L, the value
  17137.         of L(6) is now in a register, and L(6) is used in an indexed_
  17138.         component as in ``A(L(6)) := 99;'', where A has bounds 1..3.  If the
  17139.         implementation can prove that the value for L(6) in the register is
  17140.         in the range 1..3, then it need not perform the constraint check if
  17141.         it uses the register value.  However, if the memory value of L(6) has
  17142.         been changed to 4, and the implementation uses that memory value,
  17143.         then it had better not alter memory outside of A.
  17144.  
  17145.         12.f   Note that the rule allows the implementation to pass a
  17146.         parameter by reference and then keep just part of it in a register,
  17147.         or, equivalently, to pass part of the parameter by reference and
  17148.         another part by copy.
  17149.  
  17150.         12.g   Reason:  We do not want to go so far as to say that the mere
  17151.         presence of aliasing is wrong.  We wish to be able to write the
  17152.         following sorts of things in standard Ada:
  17153.  
  17154. 12.h        procedure Move ( Source  : in  String;
  17155.                              Target  : out String;
  17156.                              Adjust  : in Length_Adjustment :=
  17157.                                          (Drop    => Right;
  17158.                                           Justify => Left;
  17159.                                           Pad     => Representations.Pad ) );
  17160.             -- Copies elements from Source to Target (safely if they overlap)
  17161.  
  17162.         12.i   This is from the standard string handling package.  It would
  17163.         be embarrassing if this couldn't be written in Ada!
  17164.  
  17165.         12.j   The ``then'' before ``read'' in the rule implies that the
  17166.         implementation can move a read to an earlier place in the code, but
  17167.         not to a later place after a potentially aliased assignment.  Thus,
  17168.         if the subprogram reads one of its parameters into a local variable,
  17169.         and then updates another potentially aliased one, the local copy is
  17170.         safe -- it is known to have the old value.  For example, the
  17171.         above-mentioned Move subprogram can be implemented by copying Source
  17172.         into a local variable before assigning into Target.
  17173.  
  17174.         12.k   For an assignment_statement assigning one array parameter to
  17175.         another, the implementation has to check which direction to copy at
  17176.         run time, in general, in case the actual parameters are overlapping
  17177.         slices.  For example:
  17178.  
  17179. 12.l        procedure Copy(X : in out String; Y: String) is
  17180.             begin
  17181.                 X := Y;
  17182.             end Copy;
  17183.  
  17184.         12.m   It would be wrong for the compiler to assume that X and Y do
  17185.         not overlap (unless, of course, it can prove otherwise).
  17186.  
  17187.  
  17188.      NOTES
  17189. 13   (5) A formal parameter of mode in is a constant view (see 3.3); it
  17190.      cannot be updated within the subprogram_body.
  17191.  
  17192.  
  17193.                             Extensions to Ada 83
  17194.  
  17195.         13.a   {extensions to Ada 83} The value of an out parameter may be
  17196.         read.  An out parameter is treated like a declared variable without
  17197.         an explicit initial expression.
  17198.  
  17199.                          Wording Changes From Ada 83
  17200.  
  17201.         13.b   Discussion of copy-in for parts of out parameters is now
  17202.         covered in 6.4.1, ``Parameter Associations''.
  17203.  
  17204.         13.c   The concept of a by-reference type is new to Ada 9X.
  17205.  
  17206.         13.d   We now cover in a general way in 3.7.2 the rule regarding
  17207.         erroneous execution when a discriminant is changed and one of the
  17208.         parameters depends on the discriminant.
  17209.  
  17210.  
  17211.  
  17212. 6.3 Subprogram Bodies
  17213.  
  17214. 1   [A subprogram_body specifies the execution of a subprogram.]
  17215.  
  17216.  
  17217.                                    Syntax
  17218.  
  17219. 2   subprogram_body ::=
  17220.         subprogram_specification is
  17221.            declarative_part
  17222.         begin
  17223.             handled_sequence_of_statements
  17224.         end [designator];
  17225.  
  17226.     3   If a designator appears at the end of a subprogram_body, it shall
  17227.     repeat the defining_designator of the subprogram_specification.
  17228.  
  17229.  
  17230.                                Legality Rules
  17231.  
  17232. 4   [In contrast to other bodies,] a subprogram_body need not be the
  17233. completion of a previous declaration[, in which case the body declares the
  17234. subprogram].  If the body is a completion, it shall be the completion of a
  17235. subprogram_declaration or generic_subprogram_declaration.  The profile of a
  17236. subprogram_body that completes a declaration shall conform fully to that of
  17237. the declaration.  {full conformance (required)}
  17238.  
  17239.  
  17240.                               Static Semantics
  17241.  
  17242. 5   A subprogram_body is considered a declaration.  It can either complete a
  17243. previous declaration, or itself be the initial declaration of the subprogram.
  17244.  
  17245.  
  17246.                               Dynamic Semantics
  17247.  
  17248. 6   {elaboration [non-generic subprogram_body]} The elaboration of a
  17249. non-generic subprogram_body has no other effect than to establish that the
  17250. subprogram can from then on be called without failing the Elaboration_Check.
  17251.  
  17252.         6.a   Ramification:  See 12.2 for elaboration of a generic body.
  17253.         Note that protected subprogram_bodies never get elaborated; the
  17254.         elaboration of the containing protected_body allows them to be called
  17255.         without failing the Elaboration_Check.
  17256.  
  17257. 7   {execution [subprogram_body]} [The execution of a subprogram_body is
  17258. invoked by a subprogram call.]  For this execution the declarative_part is
  17259. elaborated, and the handled_sequence_of_statements is then executed.
  17260.  
  17261.  
  17262.                                   Examples
  17263.  
  17264. 8   Example of procedure body:
  17265.  
  17266. 9   procedure Push(E : in Element_Type; S : in out Stack) is
  17267.     begin
  17268.        if S.Index = S.Size then
  17269.           raise Stack_Overflow;
  17270.        else
  17271.           S.Index := S.Index + 1;
  17272.           S.Space(S.Index) := E;
  17273.        end if;
  17274.     end Push;
  17275.  
  17276. 10   Example of a function body:
  17277.  
  17278. 11  function Dot_Product(Left, Right : Vector) return Real is
  17279.        Sum : Real := 0.0;
  17280.     begin
  17281.        Check(Left'First = Right'First and Left'Last = Right'Last);
  17282.        for J in Left'Range loop
  17283.           Sum := Sum + Left(J)*Right(J);
  17284.        end loop;
  17285.        return Sum;
  17286.     end Dot_Product;
  17287.  
  17288.  
  17289.                             Extensions to Ada 83
  17290.  
  17291.         11.a   {extensions to Ada 83} A renaming_declaration may be used
  17292.         instead of a subprogram_body.
  17293.  
  17294.                          Wording Changes From Ada 83
  17295.  
  17296.         11.b   The syntax rule for subprogram_body now uses the syntactic
  17297.         category handled_sequence_of_statements.
  17298.  
  17299.         11.c   The declarative_part of a subprogram_body is now required;
  17300.         that doesn't make any real difference, because a declarative_part can
  17301.         be empty.
  17302.  
  17303.         11.d   We have incorporated some rules from RM83-6.5 here.
  17304.  
  17305.         11.e   RM83 forgot to restrict the definition of elaboration of a
  17306.         subprogram_body to non-generics.
  17307.  
  17308.  
  17309.  
  17310. 6.3.1 Conformance Rules
  17311.  
  17312. 1   {conformance} [When subprogram profiles are given in more than one place,
  17313. they are required to conform in one of four ways: type conformance, mode
  17314. conformance, subtype conformance, or full conformance.]
  17315.  
  17316.  
  17317.                               Static Semantics
  17318.  
  17319. 2   {convention} {calling convention} [As explained in B.1, ``Interfacing
  17320. Pragmas'', a convention can be specified for an entity.  For a callable
  17321. entity or access-to-subprogram type, the convention is called the calling
  17322. convention.]  The following conventions are defined by the language:
  17323.  
  17324.     3  {Ada calling convention} {calling convention (Ada)} The default
  17325.        calling convention for any subprogram not listed below is Ada.
  17326.        [A pragma Convention, Import, or Export may be used to override
  17327.        the default calling convention (see B.1)].
  17328.  
  17329.  3.a    Ramification:  See also the rule about renamings-as-body in
  17330.         8.5.4.
  17331.  
  17332.     4  {Intrinsic calling convention} {calling convention (Intrinsic)}
  17333.        The Intrinsic calling convention represents subprograms that are
  17334.        ``built in'' to the compiler.  The default calling convention is
  17335.        Intrinsic for the following:
  17336.  
  17337.            5  an enumeration literal;
  17338.  
  17339.            6  a "/=" operator declared implicitly due to the declaration
  17340.               of "=" (see 6.6);
  17341.  
  17342.            7  any other implicitly declared subprogram unless it is a
  17343.               dispatching operation of a tagged type;
  17344.  
  17345.            8  an inherited subprogram of a generic formal tagged type
  17346.               with unknown discriminants; {94-4774.b}
  17347.  
  17348.            9  an attribute that is a subprogram;
  17349.  
  17350.           10  a subprogram declared immediately within a protected_body.
  17351.  
  17352.        11   [The Access attribute is not allowed for Intrinsic
  17353.        subprograms.]  {94-4774.b}
  17354.  
  17355.         11.a   Ramification:  The Intrinsic calling convention really
  17356.         represents any number of calling conventions at the machine code
  17357.         level; the compiler might have a different instruction sequence
  17358.         for each intrinsic.  That's why the Access attribute is
  17359.         disallowed.  We do not wish to require the implementation to
  17360.         generate an out of line body for an intrinsic.
  17361.  
  17362.         11.b   Whenever we wish to disallow the Access attribute in
  17363.         order to ease implementation, we make the subprogram Intrinsic.
  17364.         Several language-defined subprograms have ``pragma
  17365.         Convention(Intrinsic, ...);''.  An implementation might actually
  17366.         implement this as ``pragma Import(Intrinsic, ...);'', if there
  17367.         is really no body, and the implementation of the subprogram is
  17368.         built into the code generator.
  17369.  
  17370.         11.c   Subprograms declared in protected_bodies will generally
  17371.         have a special calling convention so as to pass along the
  17372.         identification of the current instance of the protected type.
  17373.         The convention is not protected since such local subprograms
  17374.         need not contain any ``locking'' logic since they are not
  17375.         callable via ``external'' calls; this rule prevents an access
  17376.         value designating such a subprogram from being passed outside
  17377.         the protected unit.
  17378.  
  17379.         11.d   The ``implicitly declared subprogram'' above refers to
  17380.         predefined operators (other than the "=" of a tagged type) and
  17381.         the inherited subprograms of untagged types.
  17382.  
  17383.    12  {protected calling convention} {calling convention (protected)}
  17384.        The default calling convention is protected for a protected
  17385.        subprogram, and for an access-to-subprogram type with the
  17386.        reserved word protected in its definition.
  17387.  
  17388.    13  {entry calling convention} {calling convention (entry)} The
  17389.        default calling convention is entry for an entry.
  17390.  
  17391. 14   Of these four conventions, only Ada and Intrinsic are allowed as a
  17392. convention_identifier in a pragma Convention, Import, or Export.
  17393.  
  17394.         14.a   Discussion:  The names of the protected and entry calling
  17395.         conventions cannot be used in the interfacing pragmas.  Note that
  17396.         protected and entry are reserved words.
  17397.  
  17398. 15   {type conformance} {profile (type conformant)} Two profiles are type
  17399. conformant if they have the same number of parameters, and both have a result
  17400. if either does, and corresponding parameter and result types are the same,
  17401. or, for access parameters, corresponding designated types are the same.
  17402. {type profile: see profile, type conformant}
  17403.  
  17404.         15.a   Discussion:  For access parameters, the designated types have
  17405.         to be the same for type conformance, not the access types, since in
  17406.         general each access parameter has its own anonymous access type,
  17407.         created when the subprogram is called.  Of course, corresponding
  17408.         parameters have to be either both access parameters or both not
  17409.         access parameters.
  17410.  
  17411. 16   {mode conformance} {profile (mode conformant)} Two profiles are mode
  17412. conformant if they are type-conformant, and corresponding parameters have
  17413. identical modes, and, for access parameters, the designated subtypes
  17414. statically match.  {statically matching [required]}
  17415.  
  17416. 17   {subtype conformance} {profile (subtype conformant)} Two profiles are
  17417. subtype conformant if they are mode-conformant, corresponding subtypes of the
  17418. profile statically match, and the associated calling conventions are the
  17419. same.  {94-4774.b} The profile of a generic formal subprogram is not
  17420. subtype-conformant with any other profile.  {statically matching [required]}
  17421.  
  17422.         17.a   Ramification:  {generic contract issue [partial]}
  17423.  
  17424. 18   {full conformance (for profiles)} {profile (fully conformant)} Two
  17425. profiles are fully conformant if they are subtype-conformant, and
  17426. corresponding parameters have the same names and have default_expressions
  17427. that are fully conformant with one another.
  17428.  
  17429.         18.a   Ramification:  Full conformance requires subtype conformance,
  17430.         which requires the same calling conventions.  However, the calling
  17431.         convention of the declaration and body of a subprogram or entry are
  17432.         always the same by definition.
  17433.  
  17434. 19   {full conformance (for expressions)} Two expressions are fully
  17435. conformant if, [after replacing each use of an operator with the equivalent
  17436. function_call:]
  17437.  
  17438.    20  each constituent construct of one corresponds to an instance of
  17439.        the same syntactic category in the other, except that an expanded
  17440.        name may correspond to a direct_name (or character_literal) or to
  17441.        a different expanded name in the other; and
  17442.  
  17443.    21  each direct_name, character_literal, and selector_name that is
  17444.        not part of the prefix of an expanded name in one denotes the
  17445.        same declaration as the corresponding direct_name, character_
  17446.        literal, or selector_name in the other; and {94-4718.c}
  17447.        {94-4752.a}
  17448.  
  17449.  21.a   Ramification:  Note that it doesn't say ``respectively'' because
  17450.         a direct_name can correspond to a selector_name, and vice-versa,
  17451.         by the previous bullet.  This rule allows the prefix of an
  17452.         expanded name to be removed, or replaced with a different prefix
  17453.         that denotes a renaming of the same entity.  However, it does
  17454.         not allow a direct_name or selector_name to be replaced with one
  17455.         denoting a distinct renaming (except for direct_names and
  17456.         selector_names in prefixes of expanded names).  Note that calls
  17457.         using operator notation are equivalent to calls using prefix
  17458.         notation.
  17459.  
  17460.  21.b   Given the following declarations:
  17461.  
  17462. 21.c        package A is
  17463.                 function F(X : Integer := 1) return Boolean;
  17464.             end A;
  17465.  
  17466. 21.d        with A;
  17467.             package B is
  17468.                 package A_View renames A;
  17469.                 function F_View(X : Integer := 9999) return Boolean renames F;
  17470.             end B;
  17471.  
  17472. 21.e        with A, B; use A, B;
  17473.             procedure Main is ...
  17474.  
  17475.  21.f   Within Main, the expressions ``F'', ``A.F'', ``B.A_View.F'', and
  17476.         ``A_View.F'' are all fully conformant with one another.
  17477.         However, ``F'' and ``F_View'' are not fully conformant.  If they
  17478.         were, it would be bad news, since the two denoted views have
  17479.         different default_expressions.
  17480.  
  17481.    22  each primary that is a literal in one has the same value as the
  17482.        corresponding literal in the other.
  17483.  
  17484.  22.a   Ramification:  The literals may be written differently.
  17485.  
  17486.         22.b   Ramification:  Note that the above definition makes full
  17487.         conformance a transitive relation.
  17488.  
  17489. 23   {full conformance (for known_discriminant_parts)} Two known_
  17490. discriminant_parts are fully conformant if they have the same number of
  17491. discriminants, and discriminants in the same positions have the same names,
  17492. statically matching subtypes, and default_expressions that are fully
  17493. conformant with one another.  {statically matching [required]}
  17494.  
  17495. 24   {full conformance (for discrete_subtype_definitions)} Two discrete_
  17496. subtype_definitions are fully conformant if they are both subtype_indications
  17497. or are both ranges, the subtype_marks (if any) denote the same subtype, and
  17498. the corresponding simple_expressions of the ranges (if any) fully conform.
  17499.  
  17500.         24.a   Ramification:  In the subtype_indication case, any ranges have
  17501.         to be corresponding; that is, two subtype_indications cannot conform
  17502.         unless both or neither has a range.
  17503.  
  17504.         24.b   Discussion:  This definition is used in 9.5.2, ``Entries and
  17505.         Accept Statements'' for the conformance required between the
  17506.         discrete_subtype_definitions of an entry_declaration for a family of
  17507.         entries and the corresponding entry_index_specification of the entry_
  17508.         body.
  17509.  
  17510.  
  17511.                          Implementation Permissions
  17512.  
  17513. 25   An implementation may declare an operator declared in a language-defined
  17514. library unit to be intrinsic.
  17515.  
  17516.  
  17517.                             Extensions to Ada 83
  17518.  
  17519.         25.a   {extensions to Ada 83} The rules for full conformance are
  17520.         relaxed -- they are now based on the structure of constructs, rather
  17521.         than the sequence of lexical elements.  This implies, for example,
  17522.         that "(X, Y: T)" conforms fully with "(X: T; Y: T)", and "(X: T)"
  17523.         conforms fully with "(X: in T)".  {94-4718.c}
  17524.  
  17525.  
  17526.  
  17527. 6.3.2 Inline Expansion of Subprograms
  17528.  
  17529. 1   [Subprograms may be expanded in line at the call site.]
  17530.  
  17531.  
  17532.                                    Syntax
  17533.  
  17534.     2   {program unit pragma [Inline]} {pragma, program unit [Inline]} The
  17535.     form of a pragma Inline, which is a program unit pragma (see 10.1.5), is
  17536.     as follows:
  17537.  
  17538.  
  17539. 3     pragma Inline(name {, name});
  17540.  
  17541.  
  17542.                                Legality Rules
  17543.  
  17544. 4   The pragma shall apply to one or more callable entities or generic
  17545. subprograms.
  17546.  
  17547.  
  17548.                               Static Semantics
  17549.  
  17550. 5   If a pragma Inline applies to a callable entity, this indicates that
  17551. inline expansion is desired for all calls to that entity.  If a pragma Inline
  17552. applies to a generic subprogram, this indicates that inline expansion is
  17553. desired for all calls to all instances of that generic subprogram.
  17554.  
  17555.         5.a   Ramification:  Note that inline expansion is desired no matter
  17556.         what name is used in the call.  This allows one to request inlining
  17557.         for only one of several overloaded subprograms as follows:
  17558.  
  17559. 5.b         package IO is
  17560.                procedure Put(X : in Integer);
  17561.                procedure Put(X : in String);
  17562.                procedure Put(X : in Character);
  17563.             private
  17564.                procedure Character_Put(X : in Character) renames Put;
  17565.                pragma Inline(Character_Put);
  17566.             end IO;
  17567.  
  17568. 5.c         with IO; use IO;
  17569.             procedure Main is
  17570.                I : Integer;
  17571.                C : Character;
  17572.             begin
  17573.                ...
  17574.                Put(C); -- Inline expansion is desired.
  17575.                Put(I); -- Inline expansion is NOT desired.
  17576.             end Main;
  17577.  
  17578.         5.d   Ramification:  The meaning of a subprogram can be changed by a
  17579.         pragma Inline only in the presence of failing checks (see 11.6).
  17580.                          Implementation Permissions
  17581.  
  17582. 6   For each call, an implementation is free to follow or to ignore the
  17583. recommendation expressed by the pragma.
  17584.  
  17585.         6.a   Ramification:  Note, in particular, that the recommendation
  17586.         cannot always be followed for a recursive call, and is often
  17587.         infeasible for entries.  Note also that the implementation can inline
  17588.         calls even when no such desire was expressed by a pragma, so long as
  17589.         the semantics of the program remains unchanged.  {94-4477.a}
  17590.  
  17591.  
  17592.      NOTES
  17593. 7    (6) The name in a pragma Inline can denote more than one entity in the
  17594.      case of overloading.  Such a pragma applies to all of the denoted
  17595.      entities.
  17596.  
  17597.  
  17598.                             Extensions to Ada 83
  17599.  
  17600.         7.a   {extensions to Ada 83} A pragma Inline is allowed inside a
  17601.         subprogram_body if there is no corresponding subprogram_declaration.
  17602.         This is for uniformity with other program unit pragmas.
  17603.  
  17604.  
  17605.  
  17606. 6.4 Subprogram Calls
  17607.  
  17608. 1   {subprogram call} A subprogram call is either a procedure_call_statement
  17609. or a function_call; [it invokes the execution of the subprogram_body.  The
  17610. call specifies the association of the actual parameters, if any, with formal
  17611. parameters of the subprogram.]
  17612.  
  17613.  
  17614.                                    Syntax
  17615.  
  17616. 2   procedure_call_statement ::=
  17617.         procedure_name;
  17618.       | procedure_prefix actual_parameter_part;
  17619.  
  17620. 3   function_call ::=
  17621.         function_name
  17622.       | function_prefix actual_parameter_part
  17623.  
  17624. 4   actual_parameter_part ::=
  17625.         (parameter_association {, parameter_association})
  17626.  
  17627. 5   parameter_association ::=
  17628.        [formal_parameter_selector_name =>] explicit_actual_parameter
  17629.  
  17630. 6   explicit_actual_parameter ::= expression | variable_name
  17631.  
  17632.     7   {named association} {positional association} A parameter_association
  17633.     is named or positional according to whether or not the formal_
  17634.     parameter_selector_name is specified.  Any positional associations shall
  17635.     precede any named associations.  Named associations are not allowed if
  17636.     the prefix in a subprogram call is an attribute_reference.
  17637.  
  17638.         7.a   Ramification:  This means that the formal parameter names used
  17639.         in describing predefined attributes are to aid presentation of their
  17640.         semantics, but are not intended for use in actual calls.
  17641.  
  17642.  
  17643.                             Name Resolution Rules
  17644.  
  17645. 8   The name or prefix given in a procedure_call_statement shall resolve to
  17646. denote a callable entity that is a procedure, or an entry renamed as (viewed
  17647. as) a procedure.  The name or prefix given in a function_call shall resolve
  17648. to denote a callable entity that is a function.  [When there is an actual_
  17649. parameter_part, the prefix can be an implicit_dereference of an
  17650. access-to-subprogram value.]
  17651.  
  17652.         8.a   Ramification:  The function can be an operator, enumeration
  17653.         literal, attribute that is a function, etc.
  17654.  
  17655. 9   A subprogram call shall contain at most one association for each formal
  17656. parameter.  Each formal parameter without an association shall have a
  17657. default_expression (in the profile of the view denoted by the name or
  17658. prefix).  This rule is an overloading rule (see 8.6).
  17659.  
  17660.  
  17661.                               Dynamic Semantics
  17662.  
  17663. 10   {execution [subprogram call]} For the execution of a subprogram call,
  17664. the name or prefix of the call is evaluated, and each parameter_association
  17665. is evaluated (see 6.4.1).  If a default_expression is used, an implicit
  17666. parameter_association is assumed for this rule.  These evaluations are done
  17667. in an arbitrary order.  The subprogram_body is then executed.  Finally, if
  17668. the subprogram completes normally, then after it is left, any necessary
  17669. assigning back of formal to actual parameters occurs (see 6.4.1).
  17670.  
  17671.         10.a   Discussion:  The implicit association for a default is only
  17672.         for this run-time rule.  At compile time, the visibility rules are
  17673.         applied to the default at the place where it occurs, not at the place
  17674.         of a call.
  17675.  
  17676.         10.b   To be honest:  If the subprogram is inherited, see 3.4,
  17677.         ``Derived Types and Classes''.
  17678.  
  17679.         10.c   If the subprogram is protected, see 9.5.1, ``Protected
  17680.         Subprograms and Protected Actions''.
  17681.  
  17682.         10.d   If the subprogram is really a renaming of an entry, see 9.5.3,
  17683.         ``Entry Calls''.
  17684.  
  17685.         10.e   Normally, the subprogram_body that is executed by the above
  17686.         rule is the one for the subprogram being called.  For an enumeration
  17687.         literal, implicitly declared (but noninherited) subprogram, or an
  17688.         attribute that is a subprogram, an implicit body is assumed.  For a
  17689.         dispatching call, 3.9.2, ``Dispatching Operations of Tagged Types''
  17690.         defines which subprogram_body is executed.
  17691.  
  17692. 11   {Program_Error (raised by failure of run-time check)} The exception
  17693. Program_Error is raised at the point of a function_call if the function
  17694. completes normally without executing a return_statement.
  17695.  
  17696.         11.a   Discussion:  We are committing to raising the exception at the
  17697.         point of call, for uniformity -- see AI-00152.  This happens after
  17698.         the function is left, of course.
  17699.  
  17700.         11.b   Note that there is no name for suppressing this check, since
  17701.         the check imposes no time overhead and minimal space overhead (since
  17702.         it can usually be statically eliminated as dead code).
  17703.  
  17704. 12   A function_call denotes a constant, as defined in 6.5; the nominal
  17705. subtype of the constant is given by the result subtype of the function.
  17706. {nominal subtype [of the result of a function_call]} {constant [result of a
  17707. function_call]}
  17708.  
  17709.  
  17710.                                   Examples
  17711.  
  17712. 13   Examples of procedure calls:
  17713.  
  17714. 14  Traverse_Tree;                                               --  see 6.1
  17715.     Print_Header(128, Title, True);                              --  see 6.1
  17716.  
  17717. 15  Switch(From => X, To => Next);                               --  see 6.1
  17718.     Print_Header(128, Header => Title, Center => True);          --  see 6.1
  17719.     Print_Header(Header => Title, Center => True, Pages => 128); --  see 6.1
  17720.  
  17721. 16   Examples of function calls:
  17722.  
  17723. 17  Dot_Product(U, V)   --  see 6.1 and 6.3
  17724.     Clock               --  see 9.6
  17725.     F.all               --  presuming F is of an access-to-subprogram type -- s\
  17726. ee 3.10
  17727.  
  17728. 18   Examples of procedures with default expressions:
  17729.  
  17730. 19  procedure Activate(Process : in Process_Name;
  17731.                        After   : in Process_Name := No_Process;
  17732.                        Wait    : in Duration := 0.0;
  17733.                        Prior   : in Boolean := False);
  17734.  
  17735. 20  procedure Pair(Left, Right : in Person_Name := new Person);   --  see 3.10.1
  17736.  
  17737. 21   Examples of their calls:
  17738.  
  17739. 22  Activate(X);
  17740.     Activate(X, After => Y);
  17741.     Activate(X, Wait => 60.0, Prior => True);
  17742.     Activate(X, Y, 10.0, False);
  17743.  
  17744. 23  Pair;
  17745.     Pair(Left => new Person, Right => new Person);
  17746.  
  17747.  
  17748.      NOTES
  17749. 24   (7) If a default_expression is used for two or more parameters in a
  17750.      multiple parameter_specification, the default_expression is evaluated
  17751.      once for each omitted parameter.  Hence in the above examples, the two
  17752.      calls of Pair are equivalent.
  17753.  
  17754.  
  17755.                                   Examples
  17756.  
  17757. 25   Examples of overloaded subprograms:
  17758.  
  17759. 26  procedure Put(X : in Integer);
  17760.     procedure Put(X : in String);
  17761.  
  17762. 27  procedure Set(Tint   : in Color);
  17763.     procedure Set(Signal : in Light);
  17764.  
  17765. 28   Examples of their calls:
  17766.  
  17767. 29  Put(28);
  17768.     Put("no possible ambiguity here");
  17769.  
  17770. 30  Set(Tint   => Red);
  17771.     Set(Signal => Red);
  17772.     Set(Color'(Red));
  17773.  
  17774. 31  --  Set(Red) would be ambiguous since Red may
  17775.     --  denote a value either of type Color or of type Light
  17776.  
  17777.  
  17778.                          Wording Changes From Ada 83
  17779.         31.a   We have gotten rid of parameters ``of the form of a type
  17780.         conversion'' (see RM83-6.4.1(3)).  The new view semantics of type_
  17781.         conversions allows us to use normal type_conversions instead.
  17782.  
  17783.         31.b   We have moved wording about run-time semantics of parameter
  17784.         associations to 6.4.1.
  17785.  
  17786.         31.c   We have moved wording about raising Program_Error for a
  17787.         function that falls off the end to here from RM83-6.5.
  17788.  
  17789.  
  17790.  
  17791. 6.4.1 Parameter Associations
  17792.  
  17793. 1   [{parameter passing} A parameter association defines the association
  17794. between an actual parameter and a formal parameter.]
  17795.  
  17796.  
  17797.                          Language Design Principles
  17798.  
  17799.         1.a   The parameter passing rules for out parameters are designed to
  17800.         ensure that the parts of a type that have implicit initial values
  17801.         (see 3.3.1) don't become ``de-initialized'' by being passed as an out
  17802.         parameter.
  17803.  
  17804.                             Name Resolution Rules
  17805.  
  17806. 2   The formal_parameter_selector_name of a parameter_association shall
  17807. resolve to denote a parameter_specification of the view being called.
  17808.  
  17809. 3   {actual parameter (for a formal parameter)} The actual parameter is
  17810. either the explicit_actual_parameter given in a parameter_association for a
  17811. given formal parameter, or the corresponding default_expression if no
  17812. parameter_association is given for the formal parameter.  {expected type
  17813. (actual parameter)} The expected type for an actual parameter is the type of
  17814. the corresponding formal parameter.
  17815.  
  17816.         3.a   To be honest:  The corresponding default_expression is the one
  17817.         of the corresponding formal parameter in the profile of the view
  17818.         denoted by the name or prefix of the call.
  17819.  
  17820. 4   If the mode is in, the actual is interpreted as an expression; otherwise,
  17821. the actual is interpreted only as a name, if possible.
  17822.  
  17823.         4.a   Ramification:  This formally resolves the ambiguity present in
  17824.         the syntax rule for explicit_actual_parameter.  Note that we don't
  17825.         actually require that the actual be a name if the mode is not in; we
  17826.         do that below.
  17827.  
  17828.  
  17829.                                Legality Rules
  17830.  
  17831. 5   If the mode is in out or out, the actual shall be a name that denotes a
  17832. variable.
  17833.  
  17834.         5.a   Discussion:  We no longer need ``or a type_conversion whose
  17835.         argument is the name of a variable,'' because a type_conversion is
  17836.         now a name, and a type_conversion of a variable is a variable.
  17837.  
  17838.         5.b   Reason:  The requirement that the actual be a (variable) name
  17839.         is not an overload resolution rule, since we don't want the
  17840.         difference between expression and name to be used to resolve
  17841.         overloading.  For example:
  17842.  
  17843. 5.c         procedure Print(X : in Integer; Y : in Boolean := True);
  17844.             procedure Print(Z : in out Integer);
  17845.             . . .
  17846.             Print(3); -- Ambiguous!
  17847.  
  17848.         5.d   The above call to Print is ambiguous even though the call is
  17849.         not compatible with the second Print which requires an actual that is
  17850.         a (variable) name (``3'' is an expression, not a name).  This
  17851.         requirement is a legality rule, so overload resolution fails before
  17852.         it is considered, meaning that the call is ambiguous.
  17853.  
  17854. 6   The type of the actual parameter associated with an access parameter
  17855. shall be convertible (see 4.6) to its anonymous access type.  {convertible
  17856. [required]}
  17857.  
  17858.  
  17859.                               Dynamic Semantics
  17860.  
  17861. 7   {evaluation [parameter_association]} For the evaluation of a parameter_
  17862. association:
  17863.  
  17864.     8  The actual parameter is first evaluated.
  17865.  
  17866.     9  For an access parameter, the access_definition is elaborated,
  17867.        which creates the anonymous access type.
  17868.  
  17869.    10  For a parameter [(of any mode)] that is passed by reference (see
  17870.        6.2), a view conversion of the actual parameter to the nominal
  17871.        subtype of the formal parameter is evaluated, and the formal
  17872.        parameter denotes that conversion.  {implicit subtype conversion
  17873.        [parameter passing]}
  17874.  
  17875.  10.a   Discussion:  We are always allowing sliding, even for [in] out
  17876.         by-reference parameters.
  17877.  
  17878.    11  {assignment operation (during evaluation of a parameter_
  17879.        association)} For an in or in out parameter that is passed by
  17880.        copy (see 6.2), the formal parameter object is created, and the
  17881.        value of the actual parameter is converted to the nominal subtype
  17882.        of the formal parameter and assigned to the formal.  {implicit
  17883.        subtype conversion [parameter passing]}
  17884.  
  17885.  11.a   Ramification:  The conversion mentioned here is a value
  17886.         conversion.
  17887.  
  17888.    12  For an out parameter that is passed by copy, the formal parameter
  17889.        object is created, and:
  17890.  
  17891.           13  For an access type, the formal parameter is initialized
  17892.               from the value of the actual, without a constraint check;
  17893.  
  17894.  13.a   Reason:  This preserves the Language Design Principle that an
  17895.         object of an access type is always initialized with a
  17896.         ``reasonable'' value.
  17897.  
  17898.           14  For a composite type with discriminants or that has
  17899.               implicit initial values for any subcomponents (see 3.3.1),
  17900.               the behavior is as for an in out parameter passed by copy.
  17901.               {94-4783.a} {94-4785.a}
  17902.  
  17903.  14.a   Reason:  This ensures that no part of an object of such a type
  17904.         can become ``de-initialized'' by being part of an out parameter.
  17905.         {94-4783.b}
  17906.  
  17907.  14.b   Ramification:  This includes an array type whose component type
  17908.         is an access type, and a record type with a component that has a
  17909.         default_expression, among other things.
  17910.  
  17911.           15  For any other type, the formal parameter is uninitialized.
  17912.               If composite, a view conversion of the actual parameter to
  17913.               the nominal subtype of the formal is evaluated [(which
  17914.               might raise Constraint_Error)], and the actual subtype of
  17915.               the formal is that of the view conversion.  If elementary,
  17916.               the actual subtype of the formal is given by its nominal
  17917.               subtype.
  17918.  
  17919.  15.a   Ramification:  This case covers scalar types, and composite
  17920.         types whose subcomponent's subtypes do not have any implicit
  17921.         initial values.  The view conversion for composite types ensures
  17922.         that if the lengths don't match between an actual and a formal
  17923.         array parameter, the Constraint_Error is raised before the call,
  17924.         rather than after.
  17925.  
  17926. 16   {constrained [object]} {unconstrained [object]} A formal parameter of
  17927. mode in out or out with discriminants is constrained if either its nominal
  17928. subtype or the actual parameter is constrained.
  17929.  
  17930. 17   {parameter copy back} {copy back of parameters} {parameter assigning
  17931. back} {assigning back of parameters} {assignment operation (during parameter
  17932. copy back)} After normal completion and leaving of a subprogram, for each in
  17933. out or out parameter that is passed by copy, the value of the formal
  17934. parameter is converted to the subtype of the variable given as the actual
  17935. parameter and assigned to it.  {implicit subtype conversion [parameter
  17936. passing]} These conversions and assignments occur in an arbitrary order.
  17937.  
  17938.         17.a   Ramification:  The conversions mentioned above during
  17939.         parameter passing might raise Constraint_Error -- (see 4.6).
  17940.  
  17941.         17.b   Ramification:  If any conversion or assignment as part of
  17942.         parameter passing propagates an exception, the exception is raised at
  17943.         the place of the subprogram call; that is, it cannot be handled
  17944.         inside the subprogram_body.
  17945.  
  17946.         17.c   Proof:  Since these checks happen before or after executing
  17947.         the subprogram_body, the execution of the subprogram_body does not
  17948.         dynamically enclose them, so it can't handle the exceptions.
  17949.  
  17950.         17.d   Discussion:  The variable we're talking about is the one
  17951.         denoted by the variable_name given as the explicit_actual_parameter.
  17952.         If this variable_name is a type_conversion, then the rules in 4.6 for
  17953.         assigning to a view conversion apply.  That is, if X is of subtype
  17954.         S1, and the actual is S2(X), the above-mentioned conversion will
  17955.         convert to S2, and the one mentioned in 4.6 will convert to S1.
  17956.  
  17957.  
  17958.                             Extensions to Ada 83
  17959.  
  17960.         17.e   {extensions to Ada 83} In Ada 9X, a program can rely on the
  17961.         fact that passing an object as an out parameter does not
  17962.         ``de-initialize'' any parts of the object whose subtypes have
  17963.         implicit initial values.  (This generalizes the RM83 rule that
  17964.         required copy-in for parts that were discriminants or of an access
  17965.         type.)
  17966.  
  17967.                          Wording Changes From Ada 83
  17968.  
  17969.         17.f   We have eliminated the subclause on Default Parameters, as it
  17970.         is subsumed by earlier clauses and subclauses.
  17971.  
  17972.  
  17973.  
  17974. 6.5 Return Statements
  17975.  
  17976. 1   A return_statement is used to complete the execution of the innermost
  17977. enclosing subprogram_body, entry_body, or accept_statement.
  17978.                                    Syntax
  17979.  
  17980. 2   return_statement ::= return [expression];
  17981.  
  17982.  
  17983.                             Name Resolution Rules
  17984.  
  17985. 3   {return expression} The expression, if any, of a return_statement is
  17986. called the return expression.  {result subtype (of a function)} The result
  17987. subtype of a function is the subtype denoted by the subtype_mark after the
  17988. reserved word return in the profile of the function.  {expected type [return
  17989. expression]} The expected type for a return expression is the result type of
  17990. the corresponding function.
  17991.  
  17992.         3.a   To be honest:  The same applies to generic functions.
  17993.  
  17994.  
  17995.                                Legality Rules
  17996.  
  17997. 4   {apply (to a callable construct by a return_statement)} A return_
  17998. statement shall be within a callable construct, and it applies to the
  17999. innermost one.  A return_statement shall not be within a body that is within
  18000. the construct to which the return_statement applies.
  18001.  
  18002. 5   A function body shall contain at least one return_statement that applies
  18003. to the function body, unless the function contains code_statements.  A
  18004. return_statement shall include a return expression if and only if it applies
  18005. to a function body.
  18006.  
  18007.         5.a   Reason:  The requirement that a function body has to have at
  18008.         least one return_statement is a ``helpful'' restriction.  There was
  18009.         been some interest in lifting this restriction, or allowing a raise
  18010.         statement to substitute for the return_statement.  However, there was
  18011.         enough interest in leaving it as is that we decided not to change it.
  18012.  
  18013.  
  18014.                               Dynamic Semantics
  18015.  
  18016. 6   {execution [return_statement]} For the execution of a return_statement,
  18017. the expression (if any) is first evaluated and converted to the result
  18018. subtype.  {implicit subtype conversion [function return]}
  18019.  
  18020.         6.a   Ramification:  The conversion might raise Constraint_Error --
  18021.         (see 4.6).
  18022.  
  18023. 7   If the result type is class-wide, then the tag of the result is the tag
  18024. of the value of the expression.
  18025.  
  18026. 8   If the result type is a specific tagged type:
  18027.  
  18028.     9  {Tag_Check [partial]} {check, language-defined (Tag_Check)} If it
  18029.        is limited, then a check is made that the tag of the value of the
  18030.        return expression identifies the result type.  {Constraint_Error
  18031.        (raised by failure of run-time check)} Constraint_Error is raised
  18032.        if this check fails.
  18033.  
  18034.    10  If it is nonlimited, then the tag of the result is that of the
  18035.        result type.
  18036.  
  18037.  10.a   Ramification:  This is true even if the tag of the return
  18038.         expression is different.
  18039.  
  18040.  10.b   Reason:  These rules ensure that a function whose result type is
  18041.         a specific tagged type always returns an object whose tag is
  18042.         that of the result type.  This is important for dispatching on
  18043.         controlling result, and, if nonlimited, allows the caller to
  18044.         allocate the appropriate amount of space to hold the value being
  18045.         returned (assuming there are no discriminants).
  18046.  
  18047. 11   {return-by-reference type} A type is a return-by-reference type if it is
  18048. a descendant of one of the following:
  18049.  
  18050.    12  a tagged limited type;
  18051.  
  18052.    13  a task or protected type;
  18053.  
  18054.    14  a nonprivate type with the reserved word limited in its
  18055.        declaration;
  18056.  
  18057.    15  a composite type with a subcomponent of a return-by-reference
  18058.        type;
  18059.  
  18060.    16  a private type whose full type is a return-by-reference type.
  18061.  
  18062.         16.a   Ramification:  The above rules are such that there are no "Ada
  18063.         83" types other than those containing tasks that are return-by-
  18064.         reference.  This helps to minimize upward incompatibilities relating
  18065.         to return-by-reference.
  18066.  
  18067. 17   {Accessibility_Check [partial]} {check, language-defined (Accessibility_
  18068. Check)} If the result type is a return-by-reference type, then a check is
  18069. made that the return expression is one of the following:
  18070.  
  18071.    18  a name that denotes an object view whose accessibility level is
  18072.        not deeper than that of the master that elaborated the function
  18073.        body; or
  18074.  
  18075.    19  a parenthesized expression or qualified_expression whose operand
  18076.        is one of these kinds of expressions.  {94-4715.a}
  18077.  
  18078. 20   {Program_Error (raised by failure of run-time check)} The exception
  18079. Program_Error is raised if this check fails.
  18080.  
  18081.         20.a   Discussion:  Compare the definition of return-by-reference
  18082.         with that of by-reference.
  18083.  
  18084.         20.b   The return-by-reference types are all limited types except
  18085.         those that are limited only because of a limited private type with a
  18086.         nonlimited untagged full type.
  18087.  
  18088.         20.c   Reason:  {generic contract issue [partial]}
  18089.  
  18090.         20.d   This check can often be performed at compile time.  It is
  18091.         defined to be a run-time check to avoid generic contract model
  18092.         problems.  In a future version of the standard, we anticipate that
  18093.         function return of a local variable will be illegal for all limited
  18094.         types, eliminating the need for the run-time check except for
  18095.         dereferences of an access parameter.
  18096.  
  18097. 21   For a function with a return-by-reference result type the result is
  18098. returned by reference; that is, the function call denotes a constant view of
  18099. the object associated with the value of the return expression.  {assignment
  18100. operation (during execution of a return_statement)} For any other function,
  18101. the result is returned by copy; that is, the converted value is assigned into
  18102. an anonymous constant created at the point of the return_statement, and the
  18103. function call denotes that object.
  18104.  
  18105.         21.a   Ramification:  The assignment operation does the necessary
  18106.         value adjustment, as described in 7.6, ``User-Defined Assignment and
  18107.         Finalization''.  7.6.1 describes when the anonymous constant is
  18108.         finalized.
  18109.  
  18110. 22   Finally, a transfer of control is performed which completes the
  18111. execution of the callable construct to which the return_statement applies,
  18112. and returns to the caller.
  18113.  
  18114.  
  18115.                                   Examples
  18116.  
  18117. 23   Examples of return statements:
  18118.  
  18119. 24  return;                         -- in a procedure body, entry_body, or acce\
  18120. pt_statement
  18121.     return Key_Value(Last_Index);   -- in a function body
  18122.  
  18123.  
  18124.                         Incompatibilities With Ada 83
  18125.  
  18126.         24.a   {incompatibilities with Ada 83} In Ada 9X, if the result type
  18127.         of a function has a part that is a task, then an attempt to return a
  18128.         local variable will raise Program_Error.  In Ada 83, if a function
  18129.         returns a local variable containing a task, execution is erroneous
  18130.         according to AI-00867.  However, there are other situations where
  18131.         functions that return tasks (or that return a variant record only one
  18132.         of whose variants includes a task) are correct in Ada 83 but will
  18133.         raise Program_Error according to the new rules.
  18134.  
  18135.         24.b   The rule change was made because there will be more types
  18136.         (protected types, limited controlled types) in Ada 9X for which it
  18137.         will be meaningless to return a local variable, and making all of
  18138.         these erroneous is unacceptable.  The current rule was felt to be the
  18139.         simplest that kept upward incompatibilities to situations involving
  18140.         returning tasks, which are quite rare.
  18141.  
  18142.                          Wording Changes From Ada 83
  18143.  
  18144.         24.c   This clause has been moved here from chapter 5, since it has
  18145.         mainly to do with subprograms.
  18146.  
  18147.         24.d   A function now creates an anonymous object.  This is necessary
  18148.         so that controlled types will work.
  18149.  
  18150.         24.e   We have clarified that a return_statement applies to a
  18151.         callable construct, not to a callable entity.
  18152.  
  18153.         24.f   There is no need to mention generics in the rules about where
  18154.         a return_statement can appear and what it applies to; the phrase
  18155.         ``body of a subprogram or generic subprogram'' is syntactic, and
  18156.         refers exactly to ``subprogram_body''.
  18157.  
  18158.  
  18159.  
  18160. 6.6 Overloading of Operators
  18161.  
  18162. 1   {operator} {user-defined operator} {operator (user-defined)} An operator
  18163. is a function whose designator is an operator_symbol.  [Operators, like other
  18164. functions, may be overloaded.]
  18165.  
  18166.  
  18167.                             Name Resolution Rules
  18168.  
  18169. 2   Each use of a unary or binary operator is equivalent to a function_call
  18170. with function_prefix being the corresponding operator_symbol, and with
  18171. (respectively) one or two positional actual parameters being the operand(s)
  18172. of the operator (in order).
  18173.  
  18174.         2.a   To be honest:  We also use the term operator (in Section 4 and
  18175.         in 6.1) to refer to one of the syntactic categories defined in 4.5,
  18176.         ``Operators and Expression Evaluation'' whose names end with
  18177.         ``_operator:''  logical_operator, relational_operator, binary_adding_
  18178.         operator, unary_adding_operator, multiplying_operator, and highest_
  18179.         precedence_operator.
  18180.  
  18181.  
  18182.                                Legality Rules
  18183.  
  18184. 3   The subprogram_specification of a unary or binary operator shall have one
  18185. or two parameters, respectively.  A generic function instantiation whose
  18186. designator is an operator_symbol is only allowed if the specification of the
  18187. generic function has the corresponding number of parameters.
  18188.  
  18189. 4   Default_expressions are not allowed for the parameters of an operator
  18190. (whether the operator is declared with an explicit subprogram_specification
  18191. or by a generic_instantiation).
  18192.  
  18193. 5   An explicit declaration of "/=" shall not have a result type of the
  18194. predefined type Boolean.
  18195.  
  18196.  
  18197.                               Static Semantics
  18198.  
  18199. 6   A declaration of "=" whose result type is Boolean implicitly declares a
  18200. declaration of "/=" that gives the complementary result.  {94-4701.a}
  18201.  
  18202.  
  18203.      NOTES
  18204. 7    (8) The operators "+" and "-" are both unary and binary operators, and
  18205.      hence may be overloaded with both one- and two-parameter functions.
  18206.  
  18207.  
  18208.                                   Examples
  18209.  
  18210. 8   Examples of user-defined operators:
  18211.  
  18212. 9   function "+" (Left, Right : Matrix) return Matrix;
  18213.     function "+" (Left, Right : Vector) return Vector;
  18214.  
  18215.     --  assuming that A, B, and C are of the type Vector
  18216.     --  the following two statements are equivalent:
  18217.  
  18218.     A := B + C;
  18219.     A := "+"(B, C);
  18220.  
  18221.  
  18222.                             Extensions to Ada 83
  18223.  
  18224.         9.a   {extensions to Ada 83} Explicit declarations of "=" are now
  18225.         permitted for any combination of parameter and result types.
  18226.  
  18227.         9.b   Explicit declarations of "/=" are now permitted, so long as the
  18228.         result type is not Boolean.
  18229.  
  18230.  
  18231.  
  18232.                              Section 7: Packages
  18233.  
  18234.  
  18235. 1   [{Package} [glossary entry]Packages are program units that allow the
  18236. specification of groups of logically related entities.  Typically, a package
  18237. contains the declaration of a type (often a private type or private
  18238. extension) along with the declarations of primitive subprograms of the type,
  18239. which can be called from outside the package, while their inner workings
  18240. remain hidden from outside users.{information hiding: see package}
  18241. {encapsulation: see package} {module: see package} {class: see also package}]
  18242.  
  18243.  
  18244.  
  18245. 7.1 Package Specifications and Declarations
  18246.  
  18247. 1   [A package is generally provided in two parts: a package_specification
  18248. and a package_body.  Every package has a package_specification, but not all
  18249. packages have a package_body.]
  18250.  
  18251.  
  18252.                                    Syntax
  18253.  
  18254. 2   package_declaration ::= package_specification;
  18255.  
  18256. 3   package_specification ::=
  18257.         package defining_program_unit_name is
  18258.           {basic_declarative_item}
  18259.        [private
  18260.           {basic_declarative_item}]
  18261.         end [[parent_unit_name.]identifier]
  18262.  
  18263.     4   If an identifier or parent_unit_name.identifier appears at the end of
  18264.     a package_specification, then this sequence of lexical elements shall
  18265.     repeat the defining_program_unit_name.
  18266.  
  18267.  
  18268.                                Legality Rules
  18269.  
  18270. 5   {requires a completion [package_declaration]} {requires a completion
  18271. [generic_package_declaration]} A package_declaration or generic_package_
  18272. declaration requires a completion [(a body)] if it contains any declarative_
  18273. item that requires a completion, but whose completion is not in its package_
  18274. specification.
  18275.  
  18276.         5.a   To be honest:  If an implementation supports it, a pragma
  18277.         Import may substitute for the body of a package or generic package.
  18278.  
  18279.  
  18280.                               Static Semantics
  18281.  
  18282. 6   {visible part [of a package (other than a generic formal package)]} The
  18283. first list of declarative_items of a package_specification of a package other
  18284. than a generic formal package is called the visible part of the package.
  18285. [{private part [of a package]} The optional list of declarative_items after
  18286. the reserved word private (of any package_specification) is called the
  18287. private part of the package.  If the reserved word private does not appear,
  18288. the package has an implicit empty private part.]
  18289.  
  18290.         6.a   Ramification:  This definition of visible part does not apply
  18291.         to generic formal packages -- 12.7 defines the visible part of a
  18292.         generic formal package.
  18293.  
  18294.         6.b   The implicit empty private part is important because certain
  18295.         implicit declarations occur there if the package is a child package,
  18296.         and it defines types in its visible part that are derived from, or
  18297.         contain as components, private types declared within the parent
  18298.         package.  These implicit declarations are visible in children of the
  18299.         child package.  See 10.1.1.
  18300.  
  18301. 7   [An entity declared in the private part of a package is visible only
  18302. within the declarative region of the package itself (including any child
  18303. units -- see 10.1.1).  In contrast, expanded names denoting entities declared
  18304. in the visible part can be used even outside the package; furthermore, direct
  18305. visibility of such entities can be achieved by means of use_clauses (see
  18306. 4.1.3 and 8.4).]
  18307.  
  18308.  
  18309.                               Dynamic Semantics
  18310.  
  18311. 8   {elaboration [package_declaration]} The elaboration of a package_
  18312. declaration consists of the elaboration of its basic_declarative_items in the
  18313. given order.
  18314.  
  18315.  
  18316.      NOTES
  18317. 9    (1) The visible part of a package contains all the information that
  18318.      another program unit is able to know about the package.
  18319.  
  18320. 10   (2) If a declaration occurs immediately within the specification of a
  18321.      package, and the declaration has a corresponding completion that is a
  18322.      body, then that body has to occur immediately within the body of the
  18323.      package.
  18324.  
  18325.    10.a   Proof:  This follows from the fact that the declaration and
  18326.         completion are required to occur immediately within the same
  18327.         declarative region, and the fact that bodies are disallowed (by the
  18328.         Syntax Rules) in package_specifications.  This does not apply to
  18329.         instances of generic units, whose bodies can occur in package_
  18330.         specifications.
  18331.  
  18332.  
  18333.                                   Examples
  18334.  
  18335. 11   Example of a package declaration:
  18336.  
  18337. 12  package Rational_Numbers is
  18338.  
  18339. 13     type Rational is
  18340.           record
  18341.              Numerator   : Integer;
  18342.              Denominator : Positive;
  18343.           end record;
  18344.  
  18345. 14     function "="(X,Y : Rational) return Boolean;
  18346.  
  18347. 15     function "/"  (X,Y : Integer)  return Rational;  --  to construct a rati\
  18348. onal number
  18349.  
  18350. 16     function "+"  (X,Y : Rational) return Rational;
  18351.        function "-"  (X,Y : Rational) return Rational;
  18352.        function "*"  (X,Y : Rational) return Rational;
  18353.        function "/"  (X,Y : Rational) return Rational;
  18354.     end Rational_Numbers;
  18355.  
  18356. 17   There are also many examples of package declarations in the predefined
  18357. language environment (see Annex A).
  18358.  
  18359.  
  18360.                         Incompatibilities With Ada 83
  18361.  
  18362.         17.a   {incompatibilities with Ada 83} In Ada 83, a library package
  18363.         is allowed to have a body even if it doesn't need one.  In Ada 9X, a
  18364.         library package body is either required or forbidden -- never
  18365.         optional.  The workaround is to add pragma Elaborate_Body, or
  18366.         something else requiring a body, to each library package that has a
  18367.         body that isn't otherwise required.
  18368.  
  18369.                          Wording Changes From Ada 83
  18370.  
  18371.         17.b   We have moved the syntax into this clause and the next clause
  18372.         from RM83-7.1, ``Package Structure'', which we have removed.
  18373.  
  18374.         17.c   RM83 was unclear on the rules about when a package requires a
  18375.         body.  For example, RM83-7.1(4) and RM83-7.1(8) clearly forgot about
  18376.         the case of an incomplete type declared in a package_declaration but
  18377.         completed in the body.  In addition, RM83 forgot to make this rule
  18378.         apply to a generic package.  We have corrected these rules.  Finally,
  18379.         since we now allow a pragma Import for any explicit declaration, the
  18380.         completion rules need to take this into account as well.
  18381.  
  18382.  
  18383.  
  18384. 7.2 Package Bodies
  18385.  
  18386. 1   [In contrast to the entities declared in the visible part of a package,
  18387. the entities declared in the package_body are visible only within the
  18388. package_body itself.  As a consequence, a package with a package_body can be
  18389. used for the construction of a group of related subprograms in which the
  18390. logical operations available to clients are clearly isolated from the
  18391. internal entities.]
  18392.  
  18393.  
  18394.                                    Syntax
  18395.  
  18396. 2   package_body ::=
  18397.         package body defining_program_unit_name is
  18398.            declarative_part
  18399.        [begin
  18400.             handled_sequence_of_statements]
  18401.         end [[parent_unit_name.]identifier];
  18402.  
  18403.     3   If an identifier or parent_unit_name.identifier appears at the end of
  18404.     a package_body, then this sequence of lexical elements shall repeat the
  18405.     defining_program_unit_name.
  18406.  
  18407.  
  18408.                                Legality Rules
  18409.  
  18410. 4   A package_body shall be the completion of a previous package_declaration
  18411. or generic_package_declaration.  A library package_declaration or library
  18412. generic_package_declaration shall not have a body unless it requires a body[;
  18413. pragma Elaborate_Body can be used to require a library_unit_declaration to
  18414. have a body (see 10.2.1) if it would not otherwise require one].  {94-4409.a}
  18415.  
  18416.         4.a   Ramification:  The first part of the rule forbids a package_
  18417.         body from standing alone -- it has to belong to some previous
  18418.         package_declaration or generic_package_declaration.
  18419.  
  18420.         4.b   A nonlibrary package_declaration or nonlibrary generic_package_
  18421.         declaration that does not require a completion may have a
  18422.         corresponding body anyway.
  18423.  
  18424.  
  18425.                               Static Semantics
  18426.  
  18427. 5   In any package_body without statements there is an implicit null_
  18428. statement.  For any package_declaration without an explicit completion, there
  18429. is an implicit package_body containing a single null_statement.  For a
  18430. noninstance, nonlibrary package, this body occurs at the end of the
  18431. declarative_part of the innermost enclosing program unit or block_statement;
  18432. if there are several such packages, the order of the implicit package_bodies
  18433. is unspecified.  {unspecified [partial]} [(For an instance, the implicit
  18434. package_body occurs at the place of the instantiation (see 12.3).  For a
  18435. library package, the place is partially determined by the elaboration
  18436. dependences (see Section 10).)]
  18437.  
  18438.         5.a   Discussion:  Thus, for example, we can refer to something
  18439.         happening just after the begin of a package_body, and we can refer to
  18440.         the handled_sequence_of_statements of a package_body, without
  18441.         worrying about all the optional pieces.  The place of the implicit
  18442.         body makes a difference for tasks activated by the package.  See also
  18443.         RM83-9.3(5).
  18444.  
  18445.         5.b   The implicit body would be illegal if explicit in the case of a
  18446.         library package that does not require (and therefore does not allow)
  18447.         a body.  This is a bit strange, but not harmful.
  18448.  
  18449.  
  18450.                               Dynamic Semantics
  18451.  
  18452. 6   {elaboration [nongeneric package_body]} For the elaboration of a
  18453. nongeneric package_body, its declarative_part is first elaborated, and its
  18454. handled_sequence_of_statements is then executed.
  18455.  
  18456.  
  18457.      NOTES
  18458. 7    (3) A variable declared in the body of a package is only visible within
  18459.      this body and, consequently, its value can only be changed within the
  18460.      package_body.  In the absence of local tasks, the value of such a
  18461.      variable remains unchanged between calls issued from outside the package
  18462.      to subprograms declared in the visible part.  The properties of such a
  18463.      variable are similar to those of a ``static'' variable of C.
  18464.  
  18465. 8    (4) The elaboration of the body of a subprogram explicitly declared in
  18466.      the visible part of a package is caused by the elaboration of the body
  18467.      of the package.  Hence a call of such a subprogram by an outside program
  18468.      unit raises the exception Program_Error if the call takes place before
  18469.      the elaboration of the package_body (see 3.11).
  18470.  
  18471.  
  18472.                                   Examples
  18473.  
  18474. 9   Example of a package body (see 7.1):
  18475.  
  18476. 10  package body Rational_Numbers is
  18477.  
  18478. 11     procedure Same_Denominator (X,Y : in out Rational) is
  18479.        begin
  18480.           --  reduces X and Y to the same denominator:
  18481.           ...
  18482.        end Same_Denominator;
  18483.  
  18484. 12     function "="(X,Y : Rational) return Boolean is
  18485.           U : Rational := X;
  18486.           V : Rational := Y;
  18487.        begin
  18488.           Same_Denominator (U,V);
  18489.           return U.Numerator = V.Numerator;
  18490.        end "=";
  18491.  
  18492. 13     function "/" (X,Y : Integer) return Rational is
  18493.        begin
  18494.           if Y > 0 then
  18495.              return (Numerator => X,  Denominator => Y);
  18496.           else
  18497.              return (Numerator => -X, Denominator => -Y);
  18498.           end if;
  18499.        end "/";
  18500.  
  18501. 14     function "+" (X,Y : Rational) return Rational is ...  end "+";
  18502.        function "-" (X,Y : Rational) return Rational is ...  end "-";
  18503.        function "*" (X,Y : Rational) return Rational is ...  end "*";
  18504.        function "/" (X,Y : Rational) return Rational is ...  end "/";
  18505.  
  18506. 15  end Rational_Numbers;
  18507.  
  18508.  
  18509.                          Wording Changes From Ada 83
  18510.  
  18511.         15.a   The syntax rule for package_body now uses the syntactic
  18512.         category handled_sequence_of_statements.
  18513.  
  18514.         15.b   The declarative_part of a package_body is now required; that
  18515.         doesn't make any real difference, since a declarative_part can be
  18516.         empty.
  18517.  
  18518.         15.c   RM83 seems to have forgotten to say that a package_body can't
  18519.         stand alone, without a previous declaration.  We state that rule
  18520.         here.
  18521.  
  18522.         15.d   RM83 forgot to restrict the definition of elaboration of
  18523.         package_bodies to nongeneric ones.  We have corrected that omission.
  18524.  
  18525.         15.e   The rule about implicit bodies (from RM83-9.3(5)) is moved
  18526.         here, since it is more generally applicable.
  18527.  
  18528.  
  18529.  
  18530. 7.3 Private Types and Private Extensions
  18531.  
  18532. 1   [The declaration (in the visible part of a package) of a type as a
  18533. private type or private extension serves to separate the characteristics that
  18534. can be used directly by outside program units (that is, the logical
  18535. properties) from other characteristics whose direct use is confined to the
  18536. package (the details of the definition of the type itself).  See 3.9.1 for an
  18537. overview of type extensions.  {private types and private extensions}
  18538. {information hiding: see private types and private extensions} {opaque type:
  18539. see private types and private extensions} {abstract data type (ADT): see
  18540. private types and private extensions} {ADT (abstract data type): see private
  18541. types and private extensions}]
  18542.  
  18543.  
  18544.                          Language Design Principles
  18545.  
  18546.         1.a   A private (untagged) type can be thought of as a record type
  18547.         with the type of its single (hidden) component being the full view.
  18548.  
  18549.         1.b   A private tagged type can be thought of as a private extension
  18550.         of an anonymous parent with no components.  The only dispatching
  18551.         operation of the parent is equality (although the Size attribute,
  18552.         and, if nonlimited, assignment are allowed, and those will presumably
  18553.         be implemented in terms of dispatching).
  18554.  
  18555.                                    Syntax
  18556.  
  18557. 2   private_type_declaration ::=
  18558.        type defining_identifier [discriminant_part] is [[abstract] tagged] [lim\
  18559. ited] private;
  18560.  
  18561. 3   private_extension_declaration ::=
  18562.        type defining_identifier [discriminant_part] is
  18563.          [abstract] new ancestor_subtype_indication with private;
  18564.  
  18565.  
  18566.                                Legality Rules
  18567.  
  18568. 4   {partial view (of a type)} {requires a completion [declaration of a
  18569. partial view]} A private_type_declaration or private_extension_declaration
  18570. declares a partial view of the type; such a declaration is allowed only as a
  18571. declarative_item of the visible part of a package, and it requires a
  18572. completion, which shall be a full_type_declaration that occurs as a
  18573. declarative_item of the private part of the package.  {full view (of a type)}
  18574. The view of the type declared by the full_type_declaration is called the full
  18575. view.  A generic formal private type or a generic formal private extension is
  18576. also a partial view.
  18577.  
  18578.         4.a   To be honest:  A private type can also be completed by a pragma
  18579.         Import, if supported by an implementation.
  18580.         4.b   Reason:  We originally used the term ``private view,'' but this
  18581.         was easily confused with the view provided from the private part,
  18582.         namely the full view.
  18583.  
  18584. 5   [A type shall be completely defined before it is frozen (see 3.11.1 and
  18585. 13.14).  Thus, neither the declaration of a variable of a partial view of a
  18586. type, nor the creation by an allocator of an object of the partial view are
  18587. allowed before the full declaration of the type.  Similarly, before the full
  18588. declaration, the name of the partial view cannot be used in a generic_
  18589. instantiation or in a representation item.]
  18590.  
  18591.         5.a   Proof:  This rule is stated officially in 3.11.1, ``Completions
  18592.         of Declarations''.
  18593.  
  18594.         5.b   Change:  Rule moved here from 13.14, ``Freezing Rules'', as per
  18595.         WG9 resolution.
  18596.  
  18597. 6   [A private type is limited if its declaration includes the reserved word
  18598. limited; a private extension is limited if its ancestor type is limited.]  If
  18599. the partial view is nonlimited, then the full view shall be nonlimited.  If a
  18600. tagged partial view is limited, then the full view shall be limited.  [On the
  18601. other hand, if an untagged partial view is limited, the full view may be
  18602. limited or nonlimited.]  {94-4662.a} {94-4665.a} {94-4828.b}
  18603.  
  18604. 7   If the partial view is tagged, then the full view shall be tagged.  [On
  18605. the other hand, if the partial view is untagged, then the full view may be
  18606. tagged or untagged.]  In the case where the partial view is untagged and the
  18607. full view is tagged, no derivatives of the partial view are allowed within
  18608. the immediate scope of the partial view; [derivatives of the full view are
  18609. allowed.]
  18610.  
  18611.         7.a   Ramification:  Note that deriving from a partial view within
  18612.         its immediate scope can only occur in a package that is a child of
  18613.         the one where the partial view is declared.  The rule implies that in
  18614.         the visible part of a public child package, it is impossible to
  18615.         derive from an untagged private type declared in the visible part of
  18616.         the parent package in the case where the full view of the parent type
  18617.         turns out to be tagged.  {94-4443.a} We considered a model in which
  18618.         the derived type was implicitly redeclared at the earliest place
  18619.         within its immediate scope where characteristics needed to be added.
  18620.         However, we rejected that model, because (1) it would imply that (for
  18621.         an untagged type) subprograms explicitly declared after the derived
  18622.         type could be inherited, and (2) to make this model work for
  18623.         composite types as well, several implicit redeclarations would be
  18624.         needed, since new characteristics can become visible one by one; that
  18625.         seemed like too much mechanism.
  18626.  
  18627.         7.b   Discussion:  The rule for tagged partial views is redundant for
  18628.         partial views that are private extensions, since all extensions of a
  18629.         given ancestor tagged type are tagged, and limited if the ancestor is
  18630.         limited.  We phrase this rule partially redundantly to keep its
  18631.         structure parallel with the other rules.
  18632.  
  18633.         7.c   To be honest:  This rule is checked in a generic unit, rather
  18634.         than using the ``assume the best'' or ``assume the worst'' method.
  18635.  
  18636.         7.d   Reason:  Tagged limited private types have certain capabilities
  18637.         that are incompatible with having assignment for the full view of the
  18638.         type.  In particular, tagged limited private types can be extended
  18639.         with access discriminants and components of a limited type, which
  18640.         works only because assignment is not allowed.  Consider the following
  18641.         example:
  18642.  
  18643. 7.e         package P1 is
  18644.                 type T1 is tagged limited private;
  18645.                 procedure Foo(X : in T1'Class);
  18646.             private
  18647.                 type T1 is tagged null record; -- Illegal!
  18648.                     -- This should say ``tagged limited null record''.
  18649.             end P1;
  18650.  
  18651. 7.f         package body P1 is
  18652.                 type A is access T1'Class;
  18653.                 Global : A;
  18654.                 procedure Foo(X : in T1'Class) is
  18655.                 begin
  18656.                     Global := new T1'Class'(X);
  18657.                         -- This would be illegal if the full view of
  18658.                         -- T1 were limited, like it's supposed to be.
  18659.                 end A;
  18660.             end P1;
  18661.  
  18662. 7.g         with P1;
  18663.             package P2 is
  18664.                 type T2(D : access Integer) -- Trouble!
  18665.                         is new P1.T1 with
  18666.                     record
  18667.                         My_Task : Some_Task_Type; -- More trouble!
  18668.                     end record;
  18669.             end P2;
  18670.  
  18671. 7.h         with P1;
  18672.             with P2;
  18673.             procedure Main is
  18674.                 Local : aliased Integer;
  18675.                 Y : P2.T2(A => Local'Access);
  18676.             begin
  18677.                 P1.Foo(Y);
  18678.             end Main;
  18679.  
  18680.         7.i   If the above example were legal, we would have succeeded in
  18681.         making an access value that points to Main.Local after Main has been
  18682.         left, and we would also have succeeded in doing an assignment of a
  18683.         task object, both of which are supposed to be no-no's.
  18684.  
  18685.         7.j   This rule is not needed for private extensions, because they
  18686.         inherit their limitedness from their ancestor, and there is a
  18687.         separate rule forbidding limited components of the corresponding
  18688.         record extension if the parent is nonlimited.
  18689.  
  18690.         7.k   Ramification:  A type derived from an untagged private type is
  18691.         untagged, even if the full view of the parent is tagged, and even at
  18692.         places that can see the parent:
  18693.  
  18694. 7.l         package P is
  18695.                 type Parent is private;
  18696.             private
  18697.                 type Parent is tagged
  18698.                     record
  18699.                         X: Integer;
  18700.                     end record;
  18701.             end P;
  18702.  
  18703. 7.m         package Q is
  18704.                 type T is new Parent;
  18705.             end Q;
  18706.  
  18707. 7.n         with Q; use Q;
  18708.             package body P is
  18709.                 ... T'Class ... -- Illegal!
  18710.                 Object: T;
  18711.                 ... Object.X ... -- Illegal!
  18712.                 ... Parent(Object).X ... -- OK.
  18713.             end P;
  18714.  
  18715.         7.o   The declaration of T declares an untagged view.  This view is
  18716.         always untagged, so T'Class is illegal, it would be illegal to extend
  18717.         T, and so forth.  The component name X is never visible for this
  18718.         view, although the component is still there -- one can get one's
  18719.         hands on it via a type_conversion.  {94-4941.a} {94-4946.a}
  18720.         {94-5001.g}
  18721.  
  18722. 8   {ancestor subtype (of a private_extension_declaration)} The ancestor
  18723. subtype of a private_extension_declaration is the subtype defined by the
  18724. ancestor_subtype_indication; the ancestor type shall be a specific tagged
  18725. type.  The full view of a private extension shall be derived (directly or
  18726. indirectly) from the ancestor type.  In addition to the places where Legality
  18727. Rules normally apply (see 12.3), the requirement that the ancestor be
  18728. specific applies also in the private part of an instance of a generic unit.
  18729.  
  18730.         8.a   Reason:  This rule allows the full view to be defined through
  18731.         several intermediate derivations, possibly from a series of types
  18732.         produced by generic_instantiations.
  18733.  
  18734. 9   If the declaration of a partial view includes a known_discriminant_part,
  18735. then the full_type_declaration shall have a fully conforming [(explicit)]
  18736. known_discriminant_part [(see 6.3.1, ``Conformance Rules'')].  {full
  18737. conformance (required)} [The ancestor subtype may be unconstrained; the
  18738. parent subtype of the full view is required to be constrained (see 3.7).]
  18739.  
  18740.         9.a   Discussion:  If the ancestor subtype has discriminants, then it
  18741.         is usually best to make it unconstrained.
  18742.  
  18743.         9.b   Ramification:  If the partial view has a known_discriminant_
  18744.         part, then the full view has to be a composite, non-array type, since
  18745.         only such types may have known discriminants.  {94-4493.c} Also, the
  18746.         full view cannot inherit the discriminants in this case; the known_
  18747.         discriminant_part has to be explicit.
  18748.  
  18749.         9.c   That is, the following is illegal:
  18750.  
  18751. 9.d         package P is
  18752.                 type T(D : Integer) is private;
  18753.             private
  18754.                 type T is new Some_Other_Type; -- Illegal!
  18755.             end P;
  18756.  
  18757.         9.e   even if Some_Other_Type has an integer discriminant called D.
  18758.  
  18759.         9.f   It is a ramification of this and other rules that in order for
  18760.         a tagged type to privately inherit unconstrained discriminants, the
  18761.         private type declaration has to have an unknown_discriminant_part.
  18762.  
  18763. 10   If a private extension inherits known discriminants from the ancestor
  18764. subtype, then the full view shall also inherit its discriminants from the
  18765. ancestor subtype, and the parent subtype of the full view shall be
  18766. constrained if and only if the ancestor subtype is constrained.
  18767.  
  18768.         10.a   Reason:  The first part ensures that the full view has the
  18769.         same discriminants as the partial view.  The second part ensures that
  18770.         if the partial view is unconstrained, then the full view is also
  18771.         unconstrained; otherwise, a client might constrain the partial view
  18772.         in a way that conflicts with the constraint on the full view.
  18773.  
  18774. 11   [If a partial view has unknown discriminants, then the full_type_
  18775. declaration may define a definite or an indefinite subtype, with or without
  18776. discriminants.]  {94-4474.a} {94-4886.a}
  18777.  
  18778. 12   If a partial view has neither known nor unknown discriminants, then the
  18779. full_type_declaration shall define a definite subtype.  {94-4886.a}
  18780. {94-4947.a}
  18781.  
  18782. 13   If the ancestor subtype of a private extension has constrained
  18783. discriminants, then the parent subtype of the full view shall impose a
  18784. statically matching constraint on those discriminants.  {statically matching
  18785. [required]}
  18786.  
  18787.         13.a   Ramification:  If the parent type of the full view is not the
  18788.         ancestor type, but is rather some descendant thereof, the constraint
  18789.         on the discriminants of the parent type might come from the
  18790.         declaration of some intermediate type in the derivation chain between
  18791.         the ancestor type and the parent type.
  18792.  
  18793.         13.b   Reason:  This prevents the following:
  18794.  
  18795. 13.c        package P is
  18796.                 type T2 is new T1(Discrim => 3) with private;
  18797.             private
  18798.                 type T2 is new T1(Discrim => 999) -- Illegal!
  18799.                     with record ...;
  18800.             end P;
  18801.  
  18802.         13.d   The constraints in this example do not statically match.
  18803.  
  18804.         13.e   If the constraint on the parent subtype of the full view
  18805.         depends on discriminants of the full view, then the ancestor subtype
  18806.         has to be unconstrained:
  18807.  
  18808. 13.f        type One_Discrim(A: Integer) is tagged ...;
  18809.             ...
  18810.             package P is
  18811.                 type Two_Discrims(B: Boolean; C: Integer) is new One_Discrim wi\
  18812. th private;
  18813.             private
  18814.                 type Two_Discrims(B: Boolean; C: Integer) is new One_Discrim(A \
  18815. => C) with
  18816.                     record
  18817.                         ...
  18818.                     end record;
  18819.             end P;
  18820.  
  18821.         13.g   The above example would be illegal if the private extension
  18822.         said ``is new One_Discrim(A => C);'', because then the constraints
  18823.         would not statically match.  (Constraints that depend on
  18824.         discriminants are not static.)
  18825.  
  18826.  
  18827.                               Static Semantics
  18828.  
  18829. 14   {private type [partial]} A private_type_declaration declares a private
  18830. type and its first subtype.  {private extension [partial]} Similarly, a
  18831. private_extension_declaration declares a private extension and its first
  18832. subtype.
  18833.  
  18834.         14.a   Discussion:  {package-private type} A package-private type is
  18835.         one declared by a private_type_declaration; that is, a private type
  18836.         other than a generic formal private type.  {package-private
  18837.         extension} Similarly, a package-private extension is one declared by
  18838.         a private_extension_declaration.  These terms are not used in the
  18839.         RM9X version of this document.
  18840.  
  18841. 15   A declaration of a partial view and the corresponding full_type_
  18842. declaration define two views of a single type.  The declaration of a partial
  18843. view together with the visible part define the operations that are available
  18844. to outside program units; the declaration of the full view together with the
  18845. private part define other operations whose direct use is possible only within
  18846. the declarative region of the package itself.  {characteristics} Moreover,
  18847. within the scope of the declaration of the full view, the characteristics of
  18848. the type are determined by the full view; in particular, within its scope,
  18849. the full view determines the classes that include the type, which components,
  18850. entries, and protected subprograms are visible, what attributes and other
  18851. predefined operations are allowed, and whether the first subtype is static.
  18852. See 7.3.1.
  18853.  
  18854. 16   A private extension inherits components (including discriminants unless
  18855. there is a new discriminant_part specified) and user-defined primitive
  18856. subprograms from its ancestor type, in the same way that a record extension
  18857. inherits components and user-defined primitive subprograms from its parent
  18858. type (see 3.4).
  18859.  
  18860.         16.a   To be honest:  If an operation of the parent type is abstract,
  18861.         then the abstractness of the inherited operation is different for
  18862.         nonabstract record extensions than for nonabstract private extensions
  18863.         (see 3.9.3).
  18864.  
  18865.  
  18866.                               Dynamic Semantics
  18867.  
  18868. 17   {elaboration [private_type_declaration]} The elaboration of a private_
  18869. type_declaration creates a partial view of a type.  {elaboration [private_
  18870. extension_declaration]} The elaboration of a private_extension_declaration
  18871. elaborates the ancestor_subtype_indication, and creates a partial view of a
  18872. type.
  18873.  
  18874.  
  18875.      NOTES
  18876. 18   (5) The partial view of a type as declared by a private_type_declaration
  18877.      is defined to be a composite view (in 3.2).  The full view of the type
  18878.      might or might not be composite.  A private extension is also composite,
  18879.      as is its full view.
  18880.  
  18881. 19   (6) Declaring a private type with an unknown_discriminant_part is a way
  18882.      of preventing clients from creating uninitialized objects of the type;
  18883.      they are then forced to initialize each object by calling some operation
  18884.      declared in the visible part of the package.  If such a type is also
  18885.      limited, then no objects of the type can be declared outside the scope
  18886.      of the full_type_declaration, restricting all object creation to the
  18887.      package defining the type.  This allows complete control over all
  18888.      storage allocation for the type.  Objects of such a type can still be
  18889.      passed as parameters, however.
  18890.  
  18891.    19.a   Discussion:  {generic contract/private type contract analogy}
  18892.         Packages with private types are analogous to generic packages with
  18893.         formal private types, as follows:  The declaration of a
  18894.         package-private type is like the declaration of a formal private
  18895.         type.  The visible part of the package is like the generic formal
  18896.         part; these both specify a contract (that is, a set of operations and
  18897.         other things available for the private type).  The private part of
  18898.         the package is like an instantiation of the generic; they both give a
  18899.         full_type_declaration that specifies implementation details of the
  18900.         private type.  The clients of the package are like the body of the
  18901.         generic; usage of the private type in these places is restricted to
  18902.         the operations defined by the contract.
  18903.  
  18904.    19.b   In other words, being inside the package is like being outside the
  18905.         generic, and being outside the package is like being inside the
  18906.         generic; a generic is like an ``inside-out'' package.
  18907.  
  18908.    19.c   This analogy also works for private extensions in the same
  18909.         inside-out way.
  18910.  
  18911.    19.d   Many of the legality rules are defined with this analogy in mind.
  18912.         See, for example, the rules relating to operations of [formal]
  18913.         derived types.
  18914.  
  18915.    19.e   The completion rules for a private type are intentionally quite
  18916.         similar to the matching rules for a generic formal private type.
  18917.  
  18918.    19.f   This analogy breaks down in one respect:  a generic actual subtype
  18919.         is a subtype, whereas the full view for a private type is always a
  18920.         new type.  (We considered allowing the completion of a private_type_
  18921.         declaration to be a subtype_declaration, but the semantics just won't
  18922.         work.)  This difference is behind the fact that a generic actual type
  18923.         can be class-wide, whereas the completion of a private type always
  18924.         declares a specific type.
  18925.  
  18926. 20   (7) The ancestor type specified in a private_extension_declaration and
  18927.      the parent type specified in the corresponding declaration of a record
  18928.      extension given in the private part need not be the same -- the parent
  18929.      type of the full view can be any descendant of the ancestor type.  In
  18930.      this case, for a primitive subprogram that is inherited from the
  18931.      ancestor type and not overridden, the formal parameter names and default
  18932.      expressions (if any) come from the corresponding primitive subprogram of
  18933.      the specified ancestor type, while the body comes from the corresponding
  18934.      primitive subprogram of the parent type of the full view.  See 3.9.2.
  18935.  
  18936.  
  18937.                                   Examples
  18938.  
  18939. 21   Examples of private type declarations:
  18940.  
  18941. 22  type Key is private;
  18942.     type File_Name is limited private;
  18943.  
  18944. 23   Example of a private extension declaration:
  18945.  
  18946. 24  type List is new Ada.Finalization.Controlled with private;
  18947.  
  18948.  
  18949.                             Extensions to Ada 83
  18950.  
  18951.         24.a   {extensions to Ada 83} The syntax for a private_type_
  18952.         declaration is augmented to allow the reserved word tagged.
  18953.  
  18954.         24.b   In Ada 83, a private type without discriminants cannot be
  18955.         completed with a type with discriminants.  Ada 9X allows the full
  18956.         view to have discriminants, so long as they have defaults (that is,
  18957.         so long as the first subtype is definite).  This change is made for
  18958.         uniformity with generics, and because the rule as stated is simpler
  18959.         and easier to remember than the Ada 83 rule.  In the original version
  18960.         of Ada 83, the same restriction applied to generic formal private
  18961.         types.  However, the restriction was removed by the ARG for generics.
  18962.         In order to maintain the ``generic contract/private type contract
  18963.         analogy'' discussed above, we have to apply the same rule to
  18964.         package-private types.  Note that a private untagged type without
  18965.         discriminants can be completed with a tagged type with discriminants
  18966.         only if the full view is constrained, because discriminants of tagged
  18967.         types cannot have defaults.
  18968.  
  18969.                          Wording Changes From Ada 83
  18970.  
  18971.         24.c   RM83-7.4.1(4), ``Within the specification of the package that
  18972.         declares a private type and before the end of the corresponding full
  18973.         type declaration, a restriction applies....'', is subsumed (and
  18974.         corrected) by the rule that a type shall be completely defined before
  18975.         it is frozen, and the rule that the parent type of a derived type
  18976.         declaration shall be completely defined, unless the derived type is a
  18977.         private extension.
  18978. 7.3.1 Private Operations
  18979.  
  18980. 1   [For a type declared in the visible part of a package or generic package,
  18981. certain operations on the type do not become visible until later in the
  18982. package -- either in the private part or the body.  {private operations} Such
  18983. private operations are available only inside the declarative region of the
  18984. package or generic package.]
  18985.  
  18986.  
  18987.                               Static Semantics
  18988.  
  18989. 2   The predefined operators that exist for a given type are determined by
  18990. the classes to which the type belongs.  For example, an integer type has a
  18991. predefined "+" operator.  In most cases, the predefined operators of a type
  18992. are declared immediately after the definition of the type; the exceptions are
  18993. explained below.  Inherited subprograms are also implicitly declared
  18994. immediately after the definition of the type, except as stated below.
  18995.  
  18996. 3   For a composite type, the characteristics (see 7.3) of the type are
  18997. determined in part by the characteristics of its component types.  At the
  18998. place where the composite type is declared, the only characteristics of
  18999. component types used are those characteristics visible at that place.  If
  19000. later within the immediate scope of the composite type additional
  19001. characteristics become visible for a component type, then any corresponding
  19002. characteristics become visible for the composite type.  Any additional
  19003. predefined operators are implicitly declared at that place.
  19004.  
  19005. 4   The corresponding rule applies to a type defined by a derived_type_
  19006. definition, if there is a place within its immediate scope where additional
  19007. characteristics of its parent type become visible.
  19008.  
  19009. 5   {become nonlimited} {nonlimited type (becoming nonlimited)} {limited type
  19010. (becoming nonlimited)} [For example, an array type whose component type is
  19011. limited private becomes nonlimited if the full view of the component type is
  19012. nonlimited and visible at some later place within the immediate scope of the
  19013. array type.  In such a case, the predefined "=" operator is implicitly
  19014. declared at that place, and assignment is allowed after that place.]
  19015.  
  19016. 6   Inherited primitive subprograms follow a different rule.  For a derived_
  19017. type_definition, each inherited primitive subprogram is implicitly declared
  19018. at the earliest place, if any, within the immediate scope of the type_
  19019. declaration, but after the type_declaration, where the corresponding
  19020. declaration from the parent is visible.  If there is no such place, then the
  19021. inherited subprogram is not declared at all.  [An inherited subprogram that
  19022. is not declared at all cannot be named in a call and cannot be overridden,
  19023. but for a tagged type, it is possible to dispatch to it.]  {94-4678.a}
  19024. {94-4683.a}
  19025.  
  19026. 7   For a private_extension_declaration, each inherited subprogram is
  19027. declared immediately after the private_extension_declaration if the
  19028. corresponding declaration from the ancestor is visible at that place.
  19029. Otherwise, the inherited subprogram is not declared for the private
  19030. extension, [though it might be for the full type].
  19031.  
  19032.         7.a   Reason:  There is no need for the ``earliest place within the
  19033.         immediate scope'' business here, because a private_extension_
  19034.         declaration will be completed with a full_type_declaration, so we can
  19035.         hang the necessary private implicit declarations on the full_type_
  19036.         declaration.
  19037.  
  19038.         7.b   Discussion:  The above rules matter only when the component
  19039.         type (or parent type) is declared in the visible part of a package,
  19040.         and the composite type (or derived type) is declared within the
  19041.         declarative region of that package (possibly in a nested package or a
  19042.         child package).
  19043.  
  19044.         7.c   Consider:
  19045.  
  19046. 7.d         package Parent is
  19047.                 type Root is tagged null record;
  19048.                 procedure Op1(X : Root);
  19049.  
  19050. 7.e             type My_Int is range 1..10;
  19051.             private
  19052.                 procedure Op2(X : Root);
  19053.  
  19054. 7.f             type Another_Int is new My_Int;
  19055.                 procedure Int_Op(X : My_Int);
  19056.             end Parent;
  19057.  
  19058. 7.g         with Parent; use Parent;
  19059.             package Unrelated is
  19060.                 type T2 is new Root with null record;
  19061.                 procedure Op2(X : T2);
  19062.             end Unrelated;
  19063.  
  19064. 7.h         package Parent.Child is
  19065.                 type T3 is new Root with null record;
  19066.                 -- Op1(T3) implicitly declared here.
  19067.  
  19068. 7.i             package Nested is
  19069.                     type T4 is new Root with null record;
  19070.                 private
  19071.                     ...
  19072.                 end Nested;
  19073.             private
  19074.                 -- Op2(T3) implicitly declared here.
  19075.                 ...
  19076.             end Parent.Child;
  19077.  
  19078. 7.j         with Unrelated; use Unrelated;
  19079.             package body Parent.Child is
  19080.                 package body Nested is
  19081.                     -- Op2(T4) implicitly declared here.
  19082.                 end Nested;
  19083.  
  19084. 7.k             type T5 is new T2 with null record;
  19085.             end Parent.Child;
  19086.  
  19087.         7.l   Another_Int does not inherit Int_Op, because Int_Op does not
  19088.         ``exist'' at the place where Another_Int is declared.
  19089.  
  19090.         7.m   Type T2 inherits Op1 and Op2 from Root.  However, the inherited
  19091.         Op2 is never declared, because Parent.Op2 is never visible within the
  19092.         immediate scope of T2.  T2 explicitly declares its own Op2, but this
  19093.         is unrelated to the inherited one -- it does not override the
  19094.         inherited one, and occupies a different slot in the type descriptor.
  19095.  
  19096.         7.n   T3 inherits both Op1 and Op2.  Op1 is implicitly declared
  19097.         immediately after the type declaration, whereas Op2 is declared at
  19098.         the beginning of the private part.  Note that if Child were a private
  19099.         child of Parent, then Op1 and Op2 would both be implicitly declared
  19100.         immediately after the type declaration.
  19101.  
  19102.         7.o   T4 is similar to T3, except that the earliest place within T4's
  19103.         immediate scope where Root's Op2 is visible is in the body of Nested.
  19104.  
  19105.         7.p   If T3 or T4 were to declare a type-conformant Op2, this would
  19106.         override the one inherited from Root.  This is different from the
  19107.         situation with T2.
  19108.  
  19109.         7.q   T5 inherits Op1 and two Op2's from T2.  Op1 is implicitly
  19110.         declared immediately after the declaration of T5, as is the Op2 that
  19111.         came from Unrelated.Op2.  However, the Op2 that originally came from
  19112.         Parent.Op2 is never implicitly declared for T5, since T2's version of
  19113.         that Op2 is never visible (anywhere -- it never got declared either).
  19114.         {94-4677.a} {94-4682.a} {94-4439.a}
  19115.  
  19116.         7.r   For all of these rules, implicit private parts and bodies are
  19117.         assumed as needed.
  19118.  
  19119.         7.s   It is possible for characteristics of a type to be revealed in
  19120.         more than one place:
  19121.  
  19122. 7.t         package P is
  19123.                 type Comp1 is private;
  19124.             private
  19125.                 type Comp1 is new Boolean;
  19126.             end P;
  19127.  
  19128. 7.u         package P.Q is
  19129.                 package R is
  19130.                     type Comp2 is limited private;
  19131.                     type A is array(Integer range <>) of Comp2;
  19132.                 private
  19133.                     type Comp2 is new Comp1;
  19134.                     -- A becomes nonlimited here.
  19135.                     -- "="(A, A) return Boolean is implicitly declared here.
  19136.                     ...
  19137.                 end R;
  19138.             private
  19139.                 -- Now we find out what Comp1 really is, which reveals
  19140.                 -- more information about Comp2, but we're not within
  19141.                 -- the immediate scope of Comp2, so we don't do anything
  19142.                 -- about it yet.
  19143.             end P.Q;
  19144.  
  19145. 7.v         package body P.Q is
  19146.                 package body R is
  19147.                     -- Things like "xor"(A,A) return A are implicitly
  19148.                     -- declared here.
  19149.                 end R;
  19150.             end P.Q;
  19151.  
  19152.         {94-4444.a}
  19153.  
  19154. 8   [The Class attribute is defined for tagged subtypes in 3.9.  In
  19155. addition,] for every subtype S of an untagged private type whose full view is
  19156. tagged, the following attribute is defined:
  19157.  
  19158. 9   S'Class
  19159.                 Denotes the class-wide subtype corresponding to the full view
  19160.                 of S. This attribute is allowed only from the beginning of
  19161.                 the private part in which the full view is declared, until
  19162.                 the declaration of the full view.  [After the full view, the
  19163.                 Class attribute of the full view can be used.]
  19164.  
  19165.  
  19166.      NOTES
  19167. 10   (8) Because a partial view and a full view are two different views of
  19168.      one and the same type, outside of the defining package the
  19169.      characteristics of the type are those defined by the visible part.
  19170.      Within these outside program units the type is just a private type or
  19171.      private extension, and any language rule that applies only to another
  19172.      class of types does not apply.  The fact that the full declaration might
  19173.      implement a private type with a type of a particular class (for example,
  19174.      as an array type) is relevant only within the declarative region of the
  19175.      package itself including any child units.
  19176.  
  19177.      11   The consequences of this actual implementation are, however, valid
  19178.      everywhere.  For example: any default initialization of components takes
  19179.      place; the attribute Size provides the size of the full view;
  19180.      finalization is still done for controlled components of the full view;
  19181.      task dependence rules still apply to components that are task objects.
  19182.  
  19183. 12   (9) Partial views provide assignment (unless the view is limited),
  19184.      membership tests, selected components for the selection of discriminants
  19185.      and inherited components, qualification, and explicit conversion.
  19186.  
  19187. 13   (10) For a subtype S of a partial view, S'Size is defined (see 13.3).
  19188.      For an object A of a partial view, the attributes A'Size and A'Address
  19189.      are defined (see 13.3).  The Position, First_Bit, and Last_Bit
  19190.      attributes are also defined for discriminants and inherited components.
  19191.  
  19192.  
  19193.                                   Examples
  19194.  
  19195. 14   Example of a type with private operations:
  19196.  
  19197. 15  package Key_Manager is
  19198.        type Key is private;
  19199.        Null_Key : constant Key; -- a deferred constant declaration (see 7.4)
  19200.        procedure Get_Key(K : out Key);
  19201.        function "<" (X, Y : Key) return Boolean;
  19202.     private
  19203.        type Key is new Natural;
  19204.        Null_Key : constant Key := Key'First;
  19205.     end Key_Manager;
  19206.  
  19207. 16  package body Key_Manager is
  19208.        Last_Key : Key := Null_Key;
  19209.        procedure Get_Key(K : out Key) is
  19210.        begin
  19211.           Last_Key := Last_Key + 1;
  19212.           K := Last_Key;
  19213.        end Get_Key;
  19214.  
  19215. 17     function "<" (X, Y : Key) return Boolean is
  19216.        begin
  19217.           return Natural(X) < Natural(Y);
  19218.        end "<";
  19219.     end Key_Manager;
  19220.  
  19221.  
  19222.      NOTES
  19223. 18   (11) Notes on the example:  Outside of the package Key_Manager, the
  19224.      operations available for objects of type Key include assignment, the
  19225.      comparison for equality or inequality, the procedure Get_Key and the
  19226.      operator "<"; they do not include other relational operators such as
  19227.      ">=", or arithmetic operators.
  19228.  
  19229.      19   The explicitly declared operator "<" hides the predefined operator
  19230.      "<" implicitly declared by the full_type_declaration.  Within the body
  19231.      of the function, an explicit conversion of X and Y to the subtype
  19232.      Natural is necessary to invoke the "<" operator of the parent type.
  19233.      Alternatively, the result of the function could be written as not (X >=
  19234.      Y), since the operator ">=" is not redefined.
  19235.  
  19236.      20   The value of the variable Last_Key, declared in the package body,
  19237.      remains unchanged between calls of the procedure Get_Key.  (See also the
  19238.      NOTES of 7.2.)
  19239.  
  19240.  
  19241.                          Wording Changes From Ada 83
  19242.  
  19243.         20.a   The phrase in RM83-7.4.2(7), ``...after the full type
  19244.         declaration'', doesn't work in the presence of child units, so we
  19245.         define that rule in terms of visibility.
  19246.  
  19247.         20.b   The definition of the Constrained attribute for private types
  19248.         has been moved to ``Obsolescent Features.''  (The Constrained
  19249.         attribute of an object has not been moved there.)
  19250.  
  19251.  
  19252.  
  19253. 7.4 Deferred Constants
  19254.  
  19255. 1   [Deferred constant declarations may be used to declare constants in the
  19256. visible part of a package, but with the value of the constant given in the
  19257. private part.  They may also be used to declare constants imported from other
  19258. languages (see Annex B).]
  19259.  
  19260.  
  19261.                                Legality Rules
  19262.  
  19263. 2   [{deferred constant declaration} A deferred constant declaration is an
  19264. object_declaration with the reserved word constant but no initialization
  19265. expression.]
  19266.  
  19267.         2.a   Proof:  This is stated officially in Section 3.
  19268.  
  19269. {deferred constant} The constant declared by a deferred constant declaration
  19270. is called a deferred constant.  {requires a completion [deferred constant
  19271. declaration]} A deferred constant declaration requires a completion, which
  19272. shall be a full constant declaration (called the full declaration of the
  19273. deferred constant), or a pragma Import (see Annex B).  {full declaration}
  19274.  
  19275. 3   A deferred constant declaration that is completed by a full constant
  19276. declaration shall occur immediately within the visible part of a package_
  19277. specification.  For this case, the following additional rules apply to the
  19278. corresponding full declaration:
  19279.  
  19280.     4  The full declaration shall occur immediately within the private
  19281.        part of the same package;
  19282.  
  19283.     5  The deferred and full constants shall have the same type;
  19284.  
  19285.  5.a    Ramification:  This implies that both the deferred declaration
  19286.         and the full declaration have to have a subtype_indication
  19287.         rather than an array_type_definition, because each array_type_
  19288.         definition would define a new type.
  19289.  
  19290.     6  If the subtype defined by the subtype_indication in the deferred
  19291.        declaration is constrained, then the subtype defined by the
  19292.        subtype_indication in the full declaration shall match it
  19293.        statically.  [On the other hand, if the subtype of the deferred
  19294.        constant is unconstrained, then the full declaration is still
  19295.        allowed to impose a constraint.  The constant itself will be
  19296.        constrained, like all constants;]
  19297.  
  19298.     7  If the deferred constant declaration includes the reserved word
  19299.        aliased, then the full declaration shall also.
  19300.  
  19301.  7.a    Ramification:  On the other hand, the full constant can be
  19302.         aliased even if the deferred constant is not.
  19303.  
  19304. 8   [A deferred constant declaration that is completed by a pragma Import
  19305. need not appear in the visible part of a package_specification, and has no
  19306. full constant declaration.]
  19307.  
  19308. 9   The completion of a deferred constant declaration shall occur before the
  19309. constant is frozen (see 7.4).
  19310.  
  19311.         9.a   Change:  Rule moved here from 13.14, ``Freezing Rules'', as per
  19312.         WG9 resolution.
  19313.  
  19314.  
  19315.                               Dynamic Semantics
  19316.  
  19317. 10   {elaboration [deferred constant declaration]} The elaboration of a
  19318. deferred constant declaration elaborates the subtype_indication or (only
  19319. allowed in the case of an imported constant) the array_type_definition.
  19320.  
  19321.  
  19322.      NOTES
  19323. 11   (12) The full constant declaration for a deferred constant that is of a
  19324.      given private type or private extension is not allowed before the
  19325.      corresponding full_type_declaration.  This is a consequence of the
  19326.      freezing rules for types (see 13.14).
  19327.  
  19328.    11.a   Ramification:  Multiple or single declarations are allowed for the
  19329.         deferred and the full declarations, provided that the equivalent
  19330.         single declarations would be allowed.
  19331.  
  19332.    11.b   Deferred constant declarations are useful for declaring constants
  19333.         of private views, and types with components of private views.  They
  19334.         are also useful for declaring access-to-constant objects that
  19335.         designate variables declared in the private part of a package.
  19336.  
  19337.  
  19338.                                   Examples
  19339.  
  19340. 12   Examples of deferred constant declarations:
  19341.  
  19342. 13  Null_Key : constant Key;      -- see 7.3.1
  19343.  
  19344. 14  CPU_Identifier : constant String(1..8);
  19345.     pragma Import(Assembler, CPU_Identifier, Link_Name => "CPU_ID");
  19346.                                   -- see B.1
  19347.  
  19348.  
  19349.                             Extensions to Ada 83
  19350.  
  19351.         14.a   {extensions to Ada 83} In Ada 83, a deferred constant is
  19352.         required to be of a private type declared in the same visible part.
  19353.         This restriction is removed for Ada 9X; deferred constants can be of
  19354.         any type.
  19355.  
  19356.         14.b   In Ada 83, a deferred constant declaration was not permitted
  19357.         to include a constraint, nor the reserved word aliased.
  19358.  
  19359.         14.c   In Ada 83, the rules required conformance of type marks; here
  19360.         we require static matching of subtypes if the deferred constant is
  19361.         constrained.
  19362.  
  19363.         14.d   A deferred constant declaration can be completed with a pragma
  19364.         Import.  Such a deferred constant declaration need not be within a
  19365.         package_specification.
  19366.  
  19367.         14.e   The rules for too-early uses of deferred constants are
  19368.         modified in Ada 9X to allow more cases, and catch all errors at
  19369.         compile time.  This change is necessary in order to allow deferred
  19370.         constants of a tagged type without violating the principle that for a
  19371.         dispatching call, there is always an implementation to dispatch to.
  19372.         It has the beneficial side-effect of catching some Ada-83-erroneous
  19373.         programs at compile time.  The new rule fits in well with the new
  19374.         freezing-point rules.  Furthermore, we are trying to convert
  19375.         undefined-value problems into bounded errors, and we were having
  19376.         trouble for the case of deferred constants.  Furthermore,
  19377.         uninitialized deferred constants cause trouble for the shared
  19378.         variable / tasking rules, since they are really variable, even though
  19379.         they purport to be constant.  In Ada 9X, they cannot be touched until
  19380.         they become constant.
  19381.  
  19382.         14.f   Note that we do not consider this change to be an upward
  19383.         incompatibility, because it merely changes an erroneous execution in
  19384.         Ada 83 into a compile-time error.
  19385.  
  19386.         14.g   The Ada 83 semantics are unclear in the case where the full
  19387.         view turns out to be an access type.  It is a goal of the language
  19388.         design to prevent uninitialized access objects.  One wonders if the
  19389.         implementation is required to initialize the deferred constant to
  19390.         null, and then initialize it (again!) to its real value.  In Ada 9X,
  19391.         the problem goes away.
  19392.  
  19393.                          Wording Changes From Ada 83
  19394.  
  19395.         14.h   Since deferred constants can now be of a nonprivate type, we
  19396.         have made this a stand-alone clause, rather than a subclause of 7.3,
  19397.         ``Private Types and Private Extensions''.
  19398.  
  19399.         14.i   Deferred constant declarations used to have their own syntax,
  19400.         but now they are simply a special case of object_declarations.
  19401.  
  19402.  
  19403.  
  19404. 7.5 Limited Types
  19405.  
  19406. 1   [{Limited type} [glossary entry]A limited type is (a view of) a type for
  19407. which the assignment operation is not allowed.  A nonlimited type is a (view
  19408. of a) type for which the assignment operation is allowed.]
  19409.  
  19410.         1.a   Discussion:  The concept of the value of a limited type is
  19411.         difficult to define, since the abstract value of a limited type often
  19412.         extends beyond its physical representation.  In some sense, values of
  19413.         a limited type cannot be divorced from their object.  The value is
  19414.         the object.
  19415.  
  19416.         1.b   In Ada 83, in the two places where limited types were defined
  19417.         by the language, namely tasks and files, an implicit level of
  19418.         indirection was implied by the semantics to avoid the separation of
  19419.         the value from an associated object.  In Ada 9X, most limited types
  19420.         are passed by reference, and even return-ed by reference.
  19421.  
  19422.         1.c   To be honest:  For a limited partial view whose full view is
  19423.         nonlimited, assignment is possible on parameter passing and function
  19424.         return.  To prevent any copying whatsoever, one should make both the
  19425.         partial and full views limited.
  19426.  
  19427.  
  19428.                                Legality Rules
  19429.  
  19430. 2   If a tagged record type has any limited components, then the reserved
  19431. word limited shall appear in its record_type_definition.
  19432.  
  19433.         2.a   Reason:  This prevents tagged limited types from becoming
  19434.         nonlimited.  Otherwise, the following could happen:
  19435.  
  19436. 2.b         package P is
  19437.                 type T is limited private;
  19438.                 type R is tagged
  19439.                     record -- Illegal!
  19440.                            -- This should say ``limited record''.
  19441.                         X : T;
  19442.                     end record;
  19443.             private
  19444.                 type T is new Integer; -- R becomes nonlimited here.
  19445.             end P;
  19446.  
  19447. 2.c         package Q is
  19448.                 type R2(Access_Discrim : access ...) is new R with
  19449.                     record
  19450.                         Y : Some_Task_Type;
  19451.                     end record;
  19452.             end Q;
  19453.  
  19454.         2.d   If the above were legal, then assignment would be defined for
  19455.         R'Class in the body of P, which is bad news, given the access
  19456.         discriminant and the task.
  19457.  
  19458.  
  19459.                               Static Semantics
  19460.  
  19461. 3   {limited type} A type is limited if it is a descendant of one of the
  19462. following:
  19463.  
  19464.     4  a type with the reserved word limited in its definition;
  19465.  
  19466.  4.a    Ramification:  Note that there is always a ``definition,''
  19467.         conceptually, even if there is no syntactic category called
  19468.         ``..._definition''.
  19469.  
  19470.     5  a task or protected type;
  19471.  
  19472.     6  a composite type with a limited component.
  19473.  
  19474. 7   {nonlimited type} Otherwise, the type is nonlimited.
  19475.  
  19476. 8   [There are no predefined equality operators for a limited type.]
  19477.  
  19478.  
  19479.      NOTES
  19480. 9    (13) The following are consequences of the rules for limited types:
  19481.  
  19482.         10  An initialization expression is not allowed in an object_
  19483.             declaration if the type of the object is limited.
  19484.  
  19485.         11  A default expression is not allowed in a component_
  19486.             declaration if the type of the record component is limited.
  19487.  
  19488.         12  An initialized allocator is not allowed if the designated
  19489.             type is limited.
  19490.  
  19491.         13  A generic formal parameter of mode in must not be of a
  19492.             limited type.
  19493.  
  19494. 14   (14) Aggregates are not available for a limited composite type.
  19495.      Concatenation is not available for a limited array type.
  19496.  
  19497. 15   (15) The rules do not exclude a default_expression for a formal
  19498.      parameter of a limited type; they do not exclude a deferred constant of
  19499.      a limited type if the full declaration of the constant is of a
  19500.      nonlimited type.
  19501.  
  19502. 16   (16) {become nonlimited} {nonlimited type (becoming nonlimited)}
  19503.      {limited type (becoming nonlimited)} As illustrated in 7.3.1, an
  19504.      untagged limited type can become nonlimited under certain circumstances.
  19505.  
  19506.    16.a   Ramification:  Limited private types do not become nonlimited;
  19507.         instead, their full view can be nonlimited, which has a similar
  19508.         effect.
  19509.  
  19510.    16.b   It is important to remember that a single nonprivate type can be
  19511.         both limited and nonlimited in different parts of its scope.  In
  19512.         other words, ``limited'' is a property that depends on where you are
  19513.         in the scope of the type.  We don't call this a ``view property''
  19514.         because there is no particular declaration to declare the nonlimited
  19515.         view.
  19516.  
  19517.    16.c   Tagged types never become nonlimited.
  19518.  
  19519.  
  19520.                                   Examples
  19521.  
  19522. 17   Example of a package with a limited type:
  19523.  
  19524. 18  package IO_Package is
  19525.        type File_Name is limited private;
  19526.  
  19527. 19     procedure Open (F : in out File_Name);
  19528.        procedure Close(F : in out File_Name);
  19529.        procedure Read (F : in File_Name; Item : out Integer);
  19530.        procedure Write(F : in File_Name; Item : in  Integer);
  19531.     private
  19532.        type File_Name is
  19533.           limited record
  19534.              Internal_Name : Integer := 0;
  19535.           end record;
  19536.     end IO_Package;
  19537.  
  19538. 20  package body IO_Package is
  19539.        Limit : constant := 200;
  19540.        type File_Descriptor is record  ...  end record;
  19541.        Directory : array (1 .. Limit) of File_Descriptor;
  19542.        ...
  19543.        procedure Open (F : in out File_Name) is  ...  end;
  19544.        procedure Close(F : in out File_Name) is  ...  end;
  19545.        procedure Read (F : in File_Name; Item : out Integer) is ... end;
  19546.        procedure Write(F : in File_Name; Item : in  Integer) is ... end;
  19547.     begin
  19548.        ...
  19549.     end IO_Package;
  19550.  
  19551.  
  19552.      NOTES
  19553. 21   (17) Notes on the example:  In the example above, an outside subprogram
  19554.      making use of IO_Package may obtain a file name by calling Open and
  19555.      later use it in calls to Read and Write.  Thus, outside the package, a
  19556.      file name obtained from Open acts as a kind of password; its internal
  19557.      properties (such as containing a numeric value) are not known and no
  19558.      other operations (such as addition or comparison of internal names) can
  19559.      be performed on a file name.  Most importantly, clients of the package
  19560.      cannot make copies of objects of type File_Name.
  19561.  
  19562.      22   This example is characteristic of any case where complete control
  19563.      over the operations of a type is desired.  Such packages serve a dual
  19564.      purpose.  They prevent a user from making use of the internal structure
  19565.      of the type.  They also implement the notion of an encapsulated data
  19566.      type where the only operations on the type are those given in the
  19567.      package specification.
  19568.  
  19569.      23   The fact that the full view of File_Name is explicitly declared
  19570.      limited means that parameter passing and function return will always be
  19571.      by reference (see 6.2 and 6.5).
  19572.                             Extensions to Ada 83
  19573.  
  19574.         23.a   {extensions to Ada 83} The restrictions in RM83-7.4.4(4),
  19575.         which disallowed out parameters of limited types in certain cases,
  19576.         are removed.
  19577.  
  19578.                          Wording Changes From Ada 83
  19579.  
  19580.         23.b   Since limitedness and privateness are orthogonal in Ada 9X
  19581.         (and to some extent in Ada 83), this is now its own clause rather
  19582.         than being a subclause of 7.3, ``Private Types and Private
  19583.         Extensions''.
  19584.  
  19585.  
  19586.  
  19587. 7.6 User-Defined Assignment and Finalization
  19588.  
  19589. 1   [{user-defined assignment} {assignment (user-defined)} Three kinds of
  19590. actions are fundamental to the manipulation of objects:  initialization,
  19591. finalization, and assignment.  Every object is initialized, either explicitly
  19592. or by default, after being created (for example, by an object_declaration or
  19593. allocator).  Every object is finalized before being destroyed (for example,
  19594. by leaving a subprogram_body containing an object_declaration, or by a call
  19595. to an instance of Unchecked_Deallocation).  An assignment operation is used
  19596. as part of assignment_statements, explicit initialization, parameter passing,
  19597. and other operations.  {constructor: see initialization} {constructor: see
  19598. Initialize} {destructor: see finalization}
  19599.  
  19600. 2   Default definitions for these three fundamental operations are provided
  19601. by the language, but {controlled type} a controlled type gives the user
  19602. additional control over parts of these operations.
  19603.  
  19604.         2.a   Glossary entry:  {Controlled type} A controlled type supports
  19605.         user-defined assignment and finalization.  Objects are always
  19606.         finalized before being destroyed.
  19607.  
  19608. {Initialize} {Finalize} {Adjust} In particular, the user can define, for a
  19609. controlled type, an Initialize procedure which is invoked immediately after
  19610. the normal default initialization of a controlled object, a Finalize
  19611. procedure which is invoked immediately before finalization of any of the
  19612. components of a controlled object, and an Adjust procedure which is invoked
  19613. as the last step of an assignment to a (nonlimited) controlled object.]
  19614.  
  19615.         2.b   Ramification:  Here's the basic idea of initialization, value
  19616.         adjustment, and finalization, whether or not user defined:  When an
  19617.         object is created, if it is explicitly assigned an initial value, the
  19618.         assignment copies and adjusts the initial value.  Otherwise,
  19619.         Initialize is applied to it (except in the case of an aggregate as a
  19620.         whole).  An assignment_statement finalizes the target before copying
  19621.         in and adjusting the new value.  Whenever an object goes away, it is
  19622.         finalized.  Calls on Initialize and Adjust happen bottom-up; that is,
  19623.         components first, followed by the containing object.  Calls on
  19624.         Finalize happens top-down; that is, first the containing object, and
  19625.         then its components.  These ordering rules ensure that any components
  19626.         will be in a well-defined state when Initialize, Adjust, or Finalize
  19627.         is applied to the containing object.
  19628.  
  19629.  
  19630.                               Static Semantics
  19631.  
  19632. 3   The following language-defined library package exists:
  19633.  
  19634. 4
  19635.     package Ada.Finalization is
  19636.         pragma Preelaborate(Finalization);{94-4528.a}
  19637.  
  19638. 5       type Controlled is abstract tagged private;
  19639.  
  19640. 6       procedure Initialize(Object : in out Controlled);
  19641.         procedure Adjust                 (Object : in out Controlled);
  19642.         procedure Finalize               (Object : in out Controlled);
  19643.  
  19644. 7       type Limited_Controlled is abstract tagged limited private;
  19645.  
  19646. 8
  19647.         procedure Initialize(Object : in out Limited_Controlled);
  19648.         procedure Finalize  (Object : in out Limited_Controlled);
  19649.     private
  19650.         ... -- not specified by the language
  19651.     end Ada.Finalization;
  19652.  
  19653. 9   {controlled type} A controlled type is a descendant of Controlled or
  19654. Limited_Controlled.
  19655.  
  19656.         9.a   Discussion:  We say ``nonlimited controlled types'' when we
  19657.         want to talk about descendants of Controlled only.
  19658.  
  19659. The (default) implementations of Initialize, Adjust, and Finalize have no
  19660. effect.  The predefined "=" operator of type Controlled always returns True,
  19661. [since this operator is incorporated into the implementation of the
  19662. predefined equality operator of types derived from Controlled, as explained
  19663. in 4.5.2.]  {94-4619.a} {94-4843.a} The type Limited_Controlled is like
  19664. Controlled, except that it is limited and it lacks the primitive subprogram
  19665. Adjust.
  19666.  
  19667.         9.b   Reason:  We considered making Adjust and Finalize abstract.
  19668.         However, a reasonable coding convention is e.g. for Finalize to
  19669.         always call the parent's Finalize after doing whatever work is needed
  19670.         for the extension part.  (Unlike CLOS, we have no way to do that
  19671.         automatically in Ada 9X.)  For this to work, Finalize cannot be
  19672.         abstract.  In a generic unit, for a generic formal abstract derived
  19673.         type whose ancestor is Controlled or Limited_Controlled, calling the
  19674.         ancestor's Finalize would be illegal if it were abstract, even though
  19675.         the actual type might have a concrete version.
  19676.  
  19677.         9.c   Types Controlled and Limited_Controlled are abstract, even
  19678.         though they have no abstract primitive subprograms.  It is not clear
  19679.         that they need to be abstract, but there seems to be no harm in it,
  19680.         and it might make an implementation's life easier to know that there
  19681.         are no objects of these types -- in case the implementation wishes to
  19682.         make them ``magic'' in some way.
  19683.  
  19684.  
  19685.                               Dynamic Semantics
  19686.  
  19687. 10   {elaboration [object_declaration]} During the elaboration of an object_
  19688. declaration, for every controlled subcomponent of the object that is not
  19689. assigned an initial value (as defined in 3.3.1), Initialize is called on that
  19690. subcomponent.  Similarly, if the object as a whole is controlled and is not
  19691. assigned an initial value, Initialize is called on the object.  The same
  19692. applies to the evaluation of an allocator, as explained in 4.8.
  19693.  
  19694. 11   For an extension_aggregate whose ancestor_part is a subtype_mark,
  19695. Initialize is called on all controlled subcomponents of the ancestor part; if
  19696. the type of the ancestor part is itself controlled, the Initialize procedure
  19697. of the ancestor type is called, unless that Initialize procedure is abstract.
  19698.  
  19699.         11.a   Discussion:  Example:
  19700.  
  19701. 11.b        type T1 is new Controlled with
  19702.                 record
  19703.                     ... -- some components might have defaults
  19704.                 end record;
  19705.  
  19706. 11.c        type T2 is new Controlled with
  19707.                 record
  19708.                     X : T1; -- no default
  19709.                     Y : T1 := ...; -- default
  19710.                 end record;
  19711.  
  19712. 11.d        A : T2;
  19713.             B : T2 := ...;
  19714.  
  19715.         11.e   As part of the elaboration of A's declaration, A.Y is assigned
  19716.         a value; therefore Initialize is not applied to A.Y.  Instead, Adjust
  19717.         is applied to A.Y as part of the assignment operation.  Initialize is
  19718.         applied to A.X and to A, since those objects are not assigned an
  19719.         initial value.  The assignment to A.Y is not considered an assignment
  19720.         to A.
  19721.  
  19722.         11.f   For the elaboration of B's declaration, Initialize is not
  19723.         called at all.  Instead the assignment adjusts B's value; that is, it
  19724.         applies Adjust to B.X, B.Y, and B.
  19725.  
  19726. 12   Initialize and other initialization operations are done in an arbitrary
  19727. order, except as follows.  Initialize is applied to an object after
  19728. initialization of its subcomponents, if any [(including both implicit
  19729. initialization and Initialize calls)].  If an object has a component with an
  19730. access discriminant constrained by a per-object expression, Initialize is
  19731. applied to this component after any components that do not have such
  19732. discriminants.  For an object with several components with such a
  19733. discriminant, Initialize is applied to them in order of their component_
  19734. declarations.  For an allocator, any task activations follow all calls on
  19735. Initialize.
  19736.  
  19737.         12.a   Reason:  The fact that Initialize is done for subcomponents
  19738.         first allows Initialize for a composite object to refer to its
  19739.         subcomponents knowing they have been properly initialized.
  19740.  
  19741.         12.b   The fact that Initialize is done for components with access
  19742.         discriminants after other components allows the Initialize operation
  19743.         for a component with a self-referential access discriminant to assume
  19744.         that other components of the enclosing object have already been
  19745.         properly initialized.  For multiple such components, it allows some
  19746.         predictability.
  19747.  
  19748. 13   {assignment operation} When a target object with any controlled parts is
  19749. assigned a value, [either when created or in a subsequent assignment_
  19750. statement,] the assignment operation proceeds as follows:
  19751.  
  19752.    14  The value of the target becomes the assigned value.
  19753.  
  19754.    15  {adjusting the value of an object} {adjustment} The value of the
  19755.        target is adjusted.
  19756.  
  19757.         15.a   Ramification:  If any parts of the object are controlled,
  19758.         abort is deferred during the assignment operation.
  19759.  
  19760. 16   {adjusting the value of an object} {adjustment} To adjust the value of a
  19761. [(nonlimited)] composite object, the values of the components of the object
  19762. are first adjusted in an arbitrary order, and then, if the object is
  19763. controlled, Adjust is called.  Adjusting the value of an elementary object
  19764. has no effect[, nor does adjusting the value of a composite object with no
  19765. controlled parts.]
  19766.  
  19767.         16.a   Ramification:  Adjustment is never performed for values of a
  19768.         by-reference limited type, since these types do not support copying.
  19769.  
  19770.         16.b   Reason:  The verbiage in the Initialize rule about access
  19771.         discriminants constrained by per-object expressions is not necessary
  19772.         here, since such types are limited, and therefore are never adjusted.
  19773.  
  19774. 17   {execution [assignment_statement]} For an assignment_statement, [ after
  19775. the name and expression have been evaluated, and any conversion (including
  19776. constraint checking) has been done,] an anonymous object is created, and the
  19777. value is assigned into it; [that is, the assignment operation is applied].
  19778. [(Assignment includes value adjustment.)]  The target of the assignment_
  19779. statement is then finalized.  The value of the anonymous object is then
  19780. assigned into the target of the assignment_statement.  Finally, the anonymous
  19781. object is finalized.  [As explained below, the implementation may eliminate
  19782. the intermediate anonymous object, so this description subsumes the one given
  19783. in 5.2, ``Assignment Statements''.]
  19784.  
  19785.         17.a   Reason:  An alternative design for user-defined assignment
  19786.         might involve an Assign operation instead of Adjust:
  19787.  
  19788. 17.b        procedure Assign(Target : in out Controlled; Source : in out Contro\
  19789. lled);
  19790.  
  19791.         17.c   Or perhaps even a syntax like this:
  19792.  
  19793. 17.d        procedure ":="(Target : in out Controlled; Source : in out Controll\
  19794. ed);
  19795.  
  19796.         17.e   Assign (or ":=") would have the responsibility of doing the
  19797.         copy, as well as whatever else is necessary.  This would have the
  19798.         advantage that the Assign operation knows about both the target and
  19799.         the source at the same time -- it would be possible to do things like
  19800.         reuse storage belonging to the target, for example, which Adjust
  19801.         cannot do.  However, this sort of design would not work in the case
  19802.         of unconstrained discriminated variables, because there is no way to
  19803.         change the discriminants individually.  For example:
  19804.  
  19805. 17.f        type Mutable(D : Integer := 0) is
  19806.                 record
  19807.                     X : Array_Of_Controlled_Things(1..D);
  19808.                     case D is
  19809.                         when 17 => Y : Controlled_Thing;
  19810.                         when others => null;
  19811.                     end D;
  19812.                 end record;
  19813.  
  19814.         17.g   An assignment to an unconstrained variable of type Mutable can
  19815.         cause some of the components of X, and the component Y, to appear
  19816.         and/or disappear.  There is no way to write the Assign operation to
  19817.         handle this sort of case.
  19818.  
  19819.         17.h   Forbidding such cases is not an option -- it would cause
  19820.         generic contract model violations.
  19821.  
  19822.  
  19823.                          Implementation Permissions
  19824.  
  19825. 18   An implementation is allowed to relax the above rules [(for nonlimited
  19826. controlled types)] in the following ways:
  19827.  
  19828.         18.a   Proof:  The phrase ``for nonlimited controlled types'' follows
  19829.         from the fact that all of the following permissions apply to cases
  19830.         involving assignment.  It is important because the programmer can
  19831.         count on a stricter semantics for limited controlled types.
  19832.  
  19833.    19  For an assignment_statement that assigns to an object the value
  19834.        of that same object, the implementation need not do anything.
  19835.        {94-4495.a}
  19836.  
  19837.  19.a   Ramification:  In other words, even if an object is controlled
  19838.         and a combination of Finalize and Adjust on the object might
  19839.         have a net side effect, they need not be performed.
  19840.  
  19841.    20  For an assignment_statement for a noncontrolled type, the
  19842.        implementation may finalize and assign each component of the
  19843.        variable separately (rather than finalizing the entire variable
  19844.        and assigning the entire new value) unless a discriminant of the
  19845.        variable is changed by the assignment.
  19846.  
  19847.  20.a   Reason:  For example, in a slice assignment, an anonymous object
  19848.         is not necessary if the slice is copied component-by-component
  19849.         in the right direction, since array types are not controlled
  19850.         (although their components may be).  Note that the direction,
  19851.         and even the fact that it's a slice assignment, can in general
  19852.         be determined only at run time.
  19853.  
  19854.    21  For an aggregate or function call whose value is assigned into a
  19855.        target object, the implementation need not create a separate
  19856.        anonymous object if it can safely create the value of the
  19857.        aggregate or function call directly in the target object.
  19858.        Similarly, for an assignment_statement, the implementation need
  19859.        not create an anonymous object if the value being assigned is the
  19860.        result of evaluating a name denoting an object (the source
  19861.        object) whose storage cannot overlap with the target.  If the
  19862.        source object might overlap with the target object, then the
  19863.        implementation can avoid the need for an intermediary anonymous
  19864.        object by exercising one of the above permissions and perform the
  19865.        assignment one component at a time (for an overlapping array
  19866.        assignment), or not at all (for an assignment where the target
  19867.        and the source of the assignment are the same object).  Even if
  19868.        an anonymous object is created, the implementation may move its
  19869.        value to the target object as part of the assignment without
  19870.        re-adjusting so long as the anonymous object has no aliased
  19871.        subcomponents.
  19872.  
  19873.  21.a   Ramification:  In the aggregate case, only one value adjustment
  19874.         is necessary, and there is no anonymous object to be finalized.
  19875.  
  19876.  21.b   In the assignment_statement case as well, no finalization of the
  19877.         anonymous object is needed.  On the other hand, if the target
  19878.         has aliased subcomponents, then an adjustment takes place
  19879.         directly on the target object as the last step of the
  19880.         assignment, since some of the subcomponents may be
  19881.         self-referential or otherwise position-dependent.
  19882.  
  19883.  
  19884.                             Extensions to Ada 83
  19885.  
  19886.         21.c   {extensions to Ada 83} Controlled types and user-defined
  19887.         finalization are new to Ada 9X.  (Ada 83 had finalization semantics
  19888.         only for masters of tasks.)
  19889.  
  19890.  
  19891.  
  19892. 7.6.1 Completion and Finalization
  19893.  
  19894. 1   [This subclause defines completion and leaving of the execution of
  19895. constructs and entities.  A master is the execution of a construct that
  19896. includes finalization of local objects after it is complete (and after
  19897. waiting for any local tasks -- see 9.3), but before leaving.  {94-4715.a}
  19898. Other constructs and entities are left immediately upon completion.
  19899. {cleanup: see finalization} {destructor: see finalization}]
  19900.  
  19901.  
  19902.                               Dynamic Semantics
  19903.  
  19904. 2   {completion and leaving (completed and left)} {completion (run-time
  19905. concept)} The execution of a construct or entity is complete when the end of
  19906. that execution has been reached, or when a transfer of control (see 5.1)
  19907. causes it to be abandoned.  {normal completion} {completion (normal)}
  19908. {abnormal completion} {completion (abnormal)} Completion due to reaching the
  19909. end of execution, or due to the transfer of control of an exit_, return_,
  19910. goto_, or requeue_statement or of the selection of a terminate_alternative is
  19911. normal completion.  Completion is abnormal otherwise [-- when control is
  19912. transferred out of a construct due to abort or the raising of an exception].
  19913.  
  19914.         2.a   Discussion:  Don't confuse the run-time concept of completion
  19915.         with the compile-time concept of completion defined in 3.11.1.
  19916.  
  19917. 3   {leaving} {left} After execution of a construct or entity is complete, it
  19918. is left, meaning that execution continues with the next action, as defined
  19919. for the execution that is taking place.  {master} Leaving an execution
  19920. happens immediately after its completion, except in the case of a master:
  19921. the execution of a task_body, a block_statement, a subprogram_body, an entry_
  19922. body, or an accept_statement.  A master is finalized after it is complete,
  19923. and before it is left.  {94-4715.a}
  19924.  
  19925.         3.a   Reason:  Note that although an accept_statement has no
  19926.         declarative_part, it can call functions and evaluate aggregates,
  19927.         possibly causing anonymous controlled objects to be created, and we
  19928.         don't want those objects to escape outside the rendezvous.
  19929.  
  19930. 4   {finalization (of a master)} For the finalization of a master, dependent
  19931. tasks are first awaited, as explained in 9.3.  Then each object whose
  19932. accessibility level is the same as that of the master is finalized if the
  19933. object was successfully initialized and still exists.  {94-4715.a} [These
  19934. actions are performed whether the master is left by reaching the last
  19935. statement or via a transfer of control.]
  19936.  
  19937.         4.a   Ramification:  As explained in 3.10.2, the set of objects with
  19938.         the same accessibility level as that of the master includes objects
  19939.         declared immediately within the master, objects declared in nested
  19940.         packages, objects created by allocators (if the ultimate ancestor
  19941.         access type is declared in one of those places) and subcomponents of
  19942.         all of these things.  If an object was already finalized by
  19943.         Unchecked_Deallocation, then it is not finalized again when the
  19944.         master is left.
  19945.  
  19946.         4.b   Note that any object whose accessibility level is deeper than
  19947.         that of the master would no longer exist; those objects would have
  19948.         been finalized by some inner master.  Thus, after leaving a master,
  19949.         the only objects yet to be finalized are those whose accessibility
  19950.         level is less deep than that of the master.  {94-4715.a}
  19951.  
  19952.         4.c   To be honest:  Subcomponents of objects due to be finalized are
  19953.         not finalized by the finalization of the master; they are finalized
  19954.         by the finalization of the containing object.
  19955.  
  19956.         4.d   Reason:  We need to finalize subcomponents of objects even if
  19957.         the containing object is not going to get finalized because it was
  19958.         not fully initialized.  But if the containing object is finalized, we
  19959.         don't want to require repeated finalization of the subcomponents, as
  19960.         might normally be implied by the recursion in finalization of a
  19961.         master and the recursion in finalization of an object.
  19962.  
  19963. When a transfer of control causes completion of an execution, each included
  19964. master is finalized in order, from innermost outward.
  19965.  
  19966.         4.e   To be honest:  Formally, completion and leaving refer to
  19967.         executions of constructs or entities.  However, the standard
  19968.         sometimes (informally) refers to the constructs or entities whose
  19969.         executions are being completed.  Thus, for example, ``the subprogram_
  19970.         call or task is complete'' really means ``the execution of the
  19971.         subprogram_call or task is complete.''
  19972.  
  19973. 5   {finalization (of an object) [distributed]} For the finalization of an
  19974. object:
  19975.  
  19976.     6  If the object is of an elementary type, finalization has no
  19977.        effect;
  19978.  
  19979.     7  If the object is of a controlled type, the Finalize procedure is
  19980.        called;
  19981.  
  19982.     8  If the object is of a protected type, the actions defined in 9.4
  19983.        are performed;
  19984.  
  19985.     9  If the object is of a composite type, then after performing the
  19986.        above actions, if any, every component of the object is finalized
  19987.        in an arbitrary order, except as follows:  if the object has a
  19988.        component with an access discriminant constrained by a per-object
  19989.        expression, this component is finalized before any components
  19990.        that do not have such discriminants; for an object with several
  19991.        components with such a discriminant, they are finalized in the
  19992.        reverse of the order of their component_declarations.
  19993.  
  19994.  9.a    Reason:  This allows the finalization of a component with an
  19995.         access discriminant to refer to other components of the
  19996.         enclosing object prior to their being finalized.
  19997.  
  19998. 10   {execution [instance of Unchecked_Deallocation]} Immediately before an
  19999. instance of Unchecked_Deallocation reclaims the storage of an object, the
  20000. object is finalized.  [If an instance of Unchecked_Deallocation is never
  20001. applied to an object created by an allocator, the object will still exist
  20002. when the corresponding master completes, and it will be finalized then.]
  20003.  
  20004. 11   The order in which the finalization of a master performs finalization of
  20005. objects is as follows:  Objects created by declarations in the master are
  20006. finalized in the reverse order of their creation.  For objects that were
  20007. created by allocators for an access type whose ultimate ancestor is declared
  20008. in the master, this rule is applied as though each such object that still
  20009. exists had been created in an arbitrary order at the first freezing point
  20010. (see 13.14) of the ultimate ancestor type.
  20011.  
  20012.         11.a   Reason:  Note that we talk about the type of the allocator
  20013.         here.  There may be access values of a (general) access type pointing
  20014.         at objects created by allocators for some other type; these are not
  20015.         finalized at this point.
  20016.  
  20017.         11.b   The freezing point of the ultimate ancestor access type is
  20018.         chosen because before that point, pool elements cannot be created,
  20019.         and after that point, access values designating (parts of) the pool
  20020.         elements can be created.  This is also the point after which the pool
  20021.         object cannot have been declared.  We don't want to finalize the pool
  20022.         elements until after anything finalizing objects that contain access
  20023.         values designating them.  Nor do we want to finalize pool elements
  20024.         after finalizing the pool object itself.
  20025.  
  20026.         11.c   Ramification:  Finalization of allocated objects is done
  20027.         according to the (ultimate ancestor) allocator type, not according to
  20028.         the storage pool in which they are allocated.  Pool finalization
  20029.         might reclaim storage (see 13.11, ``Storage Management''), but has
  20030.         nothing (directly) to do with finalization of the pool elements.
  20031.  
  20032.         11.d   Note that finalization is done only for objects that still
  20033.         exist; if an instance of Unchecked_Deallocation has already gotten
  20034.         rid of a given pool element, that pool element will not be finalized
  20035.         when the master is left.
  20036.  
  20037.         11.e   Note that a deferred constant declaration does not create the
  20038.         constant; the full constant declaration creates it.  Therefore, the
  20039.         order of finalization depends on where the full constant declaration
  20040.         occurs, not the deferred constant declaration.
  20041.  
  20042.         11.f   An imported object is not created by its declaration.  It is
  20043.         neither initialized nor finalized.
  20044.  
  20045.         11.g   Implementation Note:  An implementation has to ensure that the
  20046.         storage for an object is not reclaimed when references to the object
  20047.         are still possible (unless, of course, the user explicitly requests
  20048.         reclamation via an instance of Unchecked_Deallocation).  This
  20049.         implies, in general, that objects cannot be deallocated one by one as
  20050.         they are finalized; a subsequent finalization might reference an
  20051.         object that has been finalized, and that object had better be in its
  20052.         (well-defined) finalized state.
  20053.  
  20054. 12   {execution [assignment_statement]} The target of an assignment statement
  20055. is finalized before copying in the new value, as explained in 7.6.
  20056.  
  20057. 13   The anonymous objects created by function calls and by aggregates are
  20058. finalized no later than the end of the innermost enclosing declarative_item
  20059. or statement; if that is a compound_statement, they are finalized before
  20060. starting the execution of any statement within the compound_statement.
  20061.  
  20062.         13.a   To be honest:  This is not to be construed as permission to
  20063.         call Finalize asynchronously with respect to normal user code.  For
  20064.         example,
  20065.  
  20066. 13.b        declare
  20067.                 X : Some_Controlled_Type := F(G(...));
  20068.                 -- The anonymous objects created for F and G are finalized
  20069.                 -- no later than this point.
  20070.                 Y : ...
  20071.             begin
  20072.                 ...
  20073.             end;
  20074.  
  20075.         13.c   The anonymous object for G should not be finalized at some
  20076.         random point in the middle of the body of F, because F might
  20077.         manipulate the same data structures as the Finalize operation,
  20078.         resulting in erroneous access to shared variables.
  20079.  
  20080.         13.d   Reason:  It might be quite inconvenient for the implementation
  20081.         to defer finalization of the anonymous object for G until after
  20082.         copying the value of F into X, especially if the size of the result
  20083.         is not known at the call site.
  20084.  
  20085.  
  20086.                           Bounded (Run-Time) Errors
  20087.  
  20088. 14   {bounded error} It is a bounded error for a call on Finalize or Adjust
  20089. to propagate an exception.  The possible consequences depend on what action
  20090. invoked the Finalize or Adjust operation:
  20091.  
  20092.         14.a   Ramification:  It is not a bounded error for Initialize to
  20093.         propagate an exception.  If Initialize propagates an exception, then
  20094.         no further calls on Initialize are performed, and those components
  20095.         that have already been initialized (either explicitly or by default)
  20096.         are finalized in the usual way.
  20097.  
  20098.    15  {Program_Error (raised by failure of run-time check)} For a
  20099.        Finalize invoked as part of an assignment_statement, Program_
  20100.        Error is raised at that point.
  20101.  
  20102.    16  {Program_Error (raised by failure of run-time check)} For an
  20103.        Adjust invoked as part of an assignment operation, any other
  20104.        adjustments due to be performed are performed, and then Program_
  20105.        Error is raised.
  20106.  
  20107.    17  {Program_Error (raised by failure of run-time check)} For a
  20108.        Finalize invoked as part of a call on an instance of Unchecked_
  20109.        Deallocation, any other finalizations due to be performed are
  20110.        performed, and then Program_Error is raised.
  20111.  
  20112.    18  {Program_Error (raised by failure of run-time check)} For a
  20113.        Finalize invoked by the transfer of control of an exit_, return_,
  20114.        goto_, or requeue_statement, Program_Error is raised no earlier
  20115.        than after the finalization of the master being finalized when
  20116.        the exception occurred, and no later than the point where normal
  20117.        execution would have continued.  Any other finalizations due to
  20118.        be performed up to that point are performed before raising
  20119.        Program_Error.
  20120.  
  20121.  18.a   Ramification:  For example, upon leaving a block_statement due
  20122.         to a goto_statement, the Program_Error would be raised at the
  20123.         point of the target statement denoted by the label, or else in
  20124.         some more dynamically nested place, but not so nested as to
  20125.         allow an exception_handler that has visibility upon the
  20126.         finalized object to handle it.  For example,
  20127.  
  20128. 18.b        procedure Main is
  20129.             begin
  20130.                 <<The_Label>>
  20131.                 Outer_Block_Statement : declare
  20132.                     X : Some_Controlled_Type;
  20133.                 begin
  20134.                     Inner_Block_Statement : declare
  20135.                         Y : Some_Controlled_Type;
  20136.                         Z : Some_Controlled_Type;
  20137.                     begin
  20138.                         goto The_Label;
  20139.                     exception
  20140.                         when Program_Error => ... -- Handler number 1.
  20141.                     end;
  20142.                 exception
  20143.                     when Program_Error => ... -- Handler number 2.
  20144.                 end;
  20145.             exception
  20146.                 when Program_Error => ... -- Handler number 3.
  20147.             end Main;
  20148.  
  20149.  18.c   The goto_statement will first cause Finalize(Y) to be called.
  20150.         Suppose that Finalize(Y) propagates an exception.  Program_Error
  20151.         will be raised after leaving Inner_Block_Statement, but before
  20152.         leaving Main.  Thus, handler number 1 cannot handle this
  20153.         Program_Error; it will be handled either by handler number 2 or
  20154.         handler number 3.  If it is handled by handler number 2, then
  20155.         Finalize(Z) will be done before executing the handler.  If it is
  20156.         handled by handler number 3, then Finalize(Z) and Finalize(X)
  20157.         will both be done before executing the handler.
  20158.  
  20159.    19  For a Finalize invoked by a transfer of control that is due to
  20160.        raising an exception, any other finalizations due to be performed
  20161.        for the same master are performed; Program_Error is raised
  20162.        immediately after leaving the master.
  20163.  
  20164.  19.a   Ramification:  If, in the above example, the goto_statement were
  20165.         replaced by a raise_statement, then the Program_Error would be
  20166.         handled by handler number 2, and Finalize(Z) would be done
  20167.         before executing the handler.
  20168.  
  20169.  19.b   Reason:  We considered treating this case in the same way as the
  20170.         others, but that would render certain exception_handlers
  20171.         useless.  For example, suppose the only exception_handler is one
  20172.         for others in the main subprogram.  If some deeply nested call
  20173.         raises an exception, causing some Finalize operation to be
  20174.         called, which then raises an exception, then normal execution
  20175.         ``would have continued'' at the beginning of the exception_
  20176.         handler.  Raising Program_Error at that point would cause that
  20177.         handler's code to be skipped.  One would need two nested
  20178.         exception_handlers to be sure of catching such cases!
  20179.  
  20180.  19.c   On the other hand, the exception_handler for a given master
  20181.         should not be allowed to handle exceptions raised during
  20182.         finalization of that master.
  20183.  
  20184.    20  For a Finalize invoked by a transfer of control due to an abort
  20185.        or selection of a terminate alternative, the exception is
  20186.        ignored; any other finalizations due to be performed are
  20187.        performed.
  20188.  
  20189.  20.a   Ramification:  This case includes an asynchronous transfer of
  20190.         control.
  20191.  
  20192.  20.b   To be honest:  {Program_Error (raised by failure of run-time
  20193.         check)} This violates the general principle that it is always
  20194.         possible for a bounded error to raise Program_Error (see 1.1.5,
  20195.         ``Classification of Errors'').
  20196.  
  20197.  
  20198.      NOTES
  20199. 21   (18) The rules of Section 10 imply that immediately prior to partition
  20200.      termination, Finalize operations are applied to library-level controlled
  20201.      objects (including those created by allocators of library-level access
  20202.      types, except those already finalized).  This occurs after waiting for
  20203.      library-level tasks to terminate.
  20204.  
  20205.    21.a   Discussion:  We considered defining a pragma that would apply to a
  20206.         controlled type that would suppress Finalize operations for
  20207.         library-level objects of the type upon partition termination.  This
  20208.         would be useful for types whose finalization actions consist of
  20209.         simply reclaiming global heap storage, when this is already provided
  20210.         automatically by the environment upon program termination.
  20211.  
  20212. 22   (19) A constant is only constant between its initialization and
  20213.      finalization.  Both initialization and finalization are allowed to
  20214.      change the value of a constant.
  20215.  
  20216. 23   (20) Abort is deferred during certain operations related to controlled
  20217.      types, as explained in 9.8.  Those rules prevent an abort from causing a
  20218.      controlled object to be left in an ill-defined state.
  20219.  
  20220. 24   (21) The Finalize procedure is called upon finalization of a controlled
  20221.      object, even if Finalize was called earlier, either explicitly or as
  20222.      part of an assignment; hence, if a controlled type is visibly controlled
  20223.      (implying that its Finalize primitive is directly callable), or is
  20224.      nonlimited (implying that assignment is allowed), its Finalize procedure
  20225.      should be designed to have no ill effect if it is applied a second time
  20226.      to the same object.
  20227.  
  20228.    24.a   Discussion:  Or equivalently, a Finalize procedure should be
  20229.         ``idempotent''; applying it twice to the same object should be
  20230.         equivalent to applying it once.
  20231.  
  20232.    24.b   Reason:  A user-written Finalize procedure should be idempotent
  20233.         since it can be called explicitly by a client (at least if the type
  20234.         is "visibly" controlled).  Also, Finalize is used implicitly as part
  20235.         of the assignment_statement if the type is nonlimited, and an abort
  20236.         is permitted to disrupt an assignment_statement between finalizing
  20237.         the left-hand side and assigning the new value to it (an abort is not
  20238.         permitted to disrupt an assignment operation between copying in the
  20239.         new value and adjusting it).
  20240.  
  20241.    24.c   Discussion:  Either Initialize or Adjust, but not both, is applied
  20242.         to (almost) every controlled object when it is created:  Initialize
  20243.         is done when no initial value is assigned to the object, whereas
  20244.         Adjust is done as part of assigning the initial value.  The one
  20245.         exception is the anonymous object created by an aggregate; Initialize
  20246.         is not applied to the aggregate as a whole, nor is the value of the
  20247.         aggregate adjusted.
  20248.  
  20249.    24.d   {assignment operation (list of uses)} All of the following use the
  20250.         assignment operation, and thus perform value adjustment:
  20251.  
  20252.          24.e  the assignment_statement (see 5.2);
  20253.  
  20254.          24.f  explicit initialization of a stand-alone object (see
  20255.                3.3.1) or of a pool element (see 4.8);
  20256.  
  20257.          24.g  default initialization of a component of a stand-alone
  20258.                object or pool element (in this case, the value of each
  20259.                component is assigned, and therefore adjusted, but the
  20260.                value of the object as a whole is not adjusted);
  20261.  
  20262.          24.h  function return, when the result type is not a
  20263.                return-by-reference type (see 6.5); (adjustment of the
  20264.                result happens before finalization of the function;
  20265.                values of return-by-reference types are not adjusted);
  20266.  
  20267.          24.i  predefined operators (although the only one that matters
  20268.                is concatenation; see 4.5.3);
  20269.  
  20270.          24.j  generic formal objects of mode in (see 12.4); these are
  20271.                defined in terms of constant_declarations; and
  20272.  
  20273.          24.k  aggregates (see 4.3) (in this case, the value of each
  20274.                component, and the parent part, for an extension_
  20275.                aggregate, is assigned, and therefore adjusted, but the
  20276.                value of the aggregate as a whole is not adjusted;
  20277.                neither is Initialize called);
  20278.  
  20279.    24.l   The following also use the assignment operation, but adjustment
  20280.         never does anything interesting in these cases:
  20281.  
  20282.          24.m  By-copy parameter passing uses the assignment operation
  20283.                (see 6.4.1), but controlled objects are always passed by
  20284.                reference, so the assignment operation never does
  20285.                anything interesting in this case.  If we were to allow
  20286.                by-copy parameter passing for controlled objects, we
  20287.                would need to make sure that the actual is finalized
  20288.                before doing the copy back for [in] out parameters.  The
  20289.                finalization of the parameter itself needs to happen
  20290.                after the copy back (if any), similar to the finalization
  20291.                of an anonymous function return object or aggregate
  20292.                object.
  20293.  
  20294.          24.n  For loops use the assignment operation (see 5.5), but
  20295.                since the type of the loop parameter is never controlled,
  20296.                nothing interesting happens there, either.
  20297.  
  20298.    24.o   Because Controlled and Limited_Controlled are library-level tagged
  20299.         types, all controlled types will be library-level types, because of
  20300.         the accessibility rules (see 3.10.2 and 3.9.1).  This ensures that
  20301.         the Finalize operations may be applied without providing any
  20302.         ``display'' or ``static-link.''  This simplifies finalization as a
  20303.         result of garbage collection, abort, and asynchronous transfer of
  20304.         control.
  20305.  
  20306.    24.p   Finalization of the parts of a protected object are not done as
  20307.         protected actions.  It is possible (in pathological cases) to create
  20308.         tasks during finalization that access these parts in parallel with
  20309.         the finalization itself.  This is an erroneous use of shared
  20310.         variables.
  20311.  
  20312.    24.q   Implementation Note:  One implementation technique for finalization
  20313.         is to chain the controlled objects together on a per-task list.  When
  20314.         leaving a master, the list can be walked up to a marked place.  The
  20315.         links needed to implement the list can be declared (privately) in
  20316.         types Controlled and Limited_Controlled, so they will be inherited by
  20317.         all controlled types.
  20318.  
  20319.    24.r   Another implementation technique, which we refer to as the
  20320.         ``PC-map'' approach essentially implies inserting exception handlers
  20321.         at various places, and finalizing objects based on where the
  20322.         exception was raised.
  20323.  
  20324.    24.s   {PC-map approach to finalization} {program-counter-map approach to
  20325.         finalization} The PC-map approach is for the compiler/linker to
  20326.         create a map of code addresses; when an exception is raised, or abort
  20327.         occurs, the map can be consulted to see where the task was executing,
  20328.         and what finalization needs to be performed.  This approach was given
  20329.         in the Ada 83 Rationale as a possible implementation strategy for
  20330.         exception handling -- the map is consulted to determine which
  20331.         exception handler applies.
  20332.  
  20333.    24.t   If the PC-map approach is used, the implementation must take care
  20334.         in the case of arrays.  The generated code will generally contain a
  20335.         loop to initialize an array.  If an exception is raised part way
  20336.         through the array, the components that have been initialized must be
  20337.         finalized, and the others must not be finalized.
  20338.  
  20339.    24.u   It is our intention that both of these implementation methods
  20340.         should be possible.
  20341.  
  20342.  
  20343.                          Wording Changes From Ada 83
  20344.  
  20345.         24.v   Finalization depends on the concepts of completion and
  20346.         leaving, and on the concept of a master.  Therefore, we have moved
  20347.         the definitions of these concepts here, from where they used to be in
  20348.         Section 9.  These concepts also needed to be generalized somewhat.
  20349.         Task waiting is closely related to user-defined finalization; the
  20350.         rules here refer to the task-waiting rules of Section 9.
  20351.  
  20352.  
  20353.  
  20354.                          Section 8: Visibility Rules
  20355.  
  20356.  
  20357. 1   [The rules defining the scope of declarations and the rules defining
  20358. which identifiers, character_literals, and operator_symbols are visible at
  20359. (or from) various places in the text of the program are described in this
  20360. section.  The formulation of these rules uses the notion of a declarative
  20361. region.
  20362.  
  20363. 2   As explained in Section 3, a declaration declares a view of an entity and
  20364. associates a defining name with that view.  The view comprises an
  20365. identification of the viewed entity, and possibly additional properties.  A
  20366. usage name denotes a declaration.  It also denotes the view declared by that
  20367. declaration, and denotes the entity of that view.  Thus, two different usage
  20368. names might denote two different views of the same entity; in this case they
  20369. denote the same entity.]
  20370.         2.a   To be honest:  In some cases, a usage name that denotes a
  20371.         declaration does not denote the view declared by that declaration,
  20372.         nor the entity of that view, but instead denotes a view of the
  20373.         current instance of the entity, and denotes the current instance of
  20374.         the entity.  This sometimes happens when the usage name occurs inside
  20375.         the declarative region of the declaration.
  20376.  
  20377.  
  20378.                          Wording Changes From Ada 83
  20379.  
  20380.         2.b   We no longer define the term ``basic operation;'' thus we no
  20381.         longer have to worry about the visibility of them.  Since they were
  20382.         essentially always visible in Ada 83, this change has no effect.  The
  20383.         reason for this change is that the definition in Ada 83 was
  20384.         confusing, and not quite correct, and we found it difficult to fix.
  20385.         For example, one wonders why an if_statement was not a basic
  20386.         operation of type Boolean.  For another example, one wonders what it
  20387.         meant for a basic operation to be ``inherent in'' something.
  20388.         Finally, this fixes the problem addressed by AI-00027/07.
  20389.  
  20390.  
  20391.  
  20392. 8.1 Declarative Region
  20393.  
  20394.                               Static Semantics
  20395.  
  20396. 1   {declarative region (of a construct)} For each of the following
  20397. constructs, there is a portion of the program text called its declarative
  20398. region, [within which nested declarations can occur]:
  20399.  
  20400.     2  any declaration, other than that of an enumeration type, that is
  20401.        not a completion [of a previous declaration];
  20402.  
  20403.     3  a block_statement;
  20404.  
  20405.     4  a loop_statement;
  20406.  
  20407.     5  an accept_statement;
  20408.  
  20409.     6  an exception_handler.
  20410.  
  20411. 7   The declarative region includes the text of the construct together with
  20412. additional text determined [(recursively)], as follows:
  20413.  
  20414.     8  If a declaration is included, so is its completion, if any.
  20415.  
  20416.     9  If the declaration of a library unit [(including Standard -- see
  20417.        10.1.1)] is included, so are the declarations of any child units
  20418.        [(and their completions, by the previous rule)].  The child
  20419.        declarations occur after the declaration.
  20420.  
  20421.    10  If a body_stub is included, so is the corresponding subunit.
  20422.  
  20423.    11  If a type_declaration is included, then so is a corresponding
  20424.        record_representation_clause, if any.
  20425.  
  20426.  11.a   Reason:  This is so that the component_declarations can be
  20427.         directly visible in the record_representation_clause.
  20428.  
  20429. 12   The declarative region of a declaration is also called the declarative
  20430. region of any view or entity declared by the declaration.
  20431.  
  20432.         12.a   Reason:  The constructs that have declarative regions are the
  20433.         constructs that can have declarations nested inside them.  Nested
  20434.         declarations are declared in that declarative region.  The one
  20435.         exception is for enumeration literals; although they are nested
  20436.         inside an enumeration type declaration, they behave as if they were
  20437.         declared at the same level as the type.
  20438.  
  20439.         12.b   To be honest:  A declarative region does not include parent_
  20440.         unit_names.
  20441.  
  20442.         12.c   Ramification:  A declarative region does not include context_
  20443.         clauses.
  20444.  
  20445. 13   {occur immediately within} {immediately within} {within (immediately)}
  20446. {immediately enclosing} {enclosing (immediately)} A declaration occurs
  20447. immediately within a declarative region if this region is the innermost
  20448. declarative region that encloses the declaration (the immediately enclosing
  20449. declarative region), not counting the declarative region (if any) associated
  20450. with the declaration itself.
  20451.  
  20452.         13.a   Discussion:  Don't confuse the declarative region of a
  20453.         declaration with the declarative region in which it immediately
  20454.         occurs.
  20455.  
  20456. 14   [{local to} A declaration is local to a declarative region if the
  20457. declaration occurs immediately within the declarative region.]
  20458.  
  20459.         14.a   Ramification:  That is, "occurs immediately within" and "local
  20460.         to" are synonyms (when referring to declarations).
  20461.  
  20462. [An entity is local to a declarative region if the entity is declared by a
  20463. declaration that is local to the declarative region.]
  20464.  
  20465.         14.b   Ramification:  Thus, ``local to'' applies to both declarations
  20466.         and entities, whereas ``occurs immediately within'' only applies to
  20467.         declarations.  We use this term only informally; for cases where
  20468.         precision is required, we use the term "occurs immediately within",
  20469.         since it is less likely to cause confusion.
  20470.  
  20471. 15   {global to} A declaration is global to a declarative region if the
  20472. declaration occurs immediately within another declarative region that
  20473. encloses the declarative region.  An entity is global to a declarative region
  20474. if the entity is declared by a declaration that is global to the declarative
  20475. region.
  20476.  
  20477.  
  20478.      NOTES
  20479. 16   (1) The children of a parent library unit are inside the parent's
  20480.      declarative region, even though they do not occur inside the parent's
  20481.      declaration or body.  This implies that one can use (for example) "P.Q"
  20482.      to refer to a child of P whose defining name is Q, and that after "use
  20483.      P;" Q can refer (directly) to that child.
  20484.  
  20485. 17   (2) As explained above and in 10.1.1, ``Compilation Units - Library
  20486.      Units'', all library units are descendants of Standard, and so are
  20487.      contained in the declarative region of Standard.  They are not inside
  20488.      the declaration or body of Standard, but they are inside its declarative
  20489.      region.
  20490.  
  20491. 18   (3) For a declarative region that comes in multiple parts, the text of
  20492.      the declarative region does not contain any text that might appear
  20493.      between the parts.  Thus, when a portion of a declarative region is said
  20494.      to extend from one place to another in the declarative region, the
  20495.      portion does not contain any text that might appear between the parts of
  20496.      the declarative region.
  20497.  
  20498.    18.a   Discussion:  It is necessary for the things that have a declarative
  20499.         region to include anything that contains declarations (except for
  20500.         enumeration type declarations).  This includes any declaration that
  20501.         has a profile (that is, subprogram_declaration, subprogram_body,
  20502.         entry_declaration, subprogram_renaming_declaration, formal_
  20503.         subprogram_declaration, access-to-subprogram type_declaration), any-
  20504.         thing that has a discriminant_part (that is, various kinds of type_
  20505.         declaration), anything that has a component_list (that is, record
  20506.         type_declaration and record extension type_declaration), and finally
  20507.         the declarations of task and protected units and packages.
  20508.  
  20509.  
  20510.                          Wording Changes From Ada 83
  20511.  
  20512.         18.b   It was necessary to extend Ada 83's definition of declarative
  20513.         region to take the following Ada 9X features into account:
  20514.  
  20515.          18.c  Child library units.
  20516.  
  20517.          18.d  Derived types/type extensions -- we need a declarative
  20518.                region for inherited components and also for new
  20519.                components.
  20520.  
  20521.          18.e  All the kinds of types that allow discriminants.
  20522.  
  20523.          18.f  Protected units.
  20524.  
  20525.          18.g  Entries that have bodies instead of accept statements.
  20526.  
  20527.          18.h  The choice_parameter_specification of an exception_
  20528.                handler.
  20529.  
  20530.          18.i  The formal parameters of access-to-subprogram types.
  20531.  
  20532.          18.j  Renamings-as-body.
  20533.  
  20534.         18.k   Discriminated and access-to-subprogram type declarations need
  20535.         a declarative region.  Enumeration type declarations cannot have one,
  20536.         because you don't have to say "Color.Red" to refer to the literal Red
  20537.         of Color.  For other type declarations, it doesn't really matter
  20538.         whether or not there is an associated declarative region, so for
  20539.         simplicity, we give one to all types except enumeration types.
  20540.  
  20541.         18.l   We now say that an accept_statement has its own declarative
  20542.         region, rather than being part of the declarative region of the
  20543.         entry_declaration, so that declarative regions are properly nested
  20544.         regions of text, so that it makes sense to talk about "inner
  20545.         declarative regions," and "...extends to the end of a declarative
  20546.         region."  Inside an accept_statement, the name of one of the
  20547.         parameters denotes the parameter_specification of the accept_
  20548.         statement, not that of the entry_declaration.  If the accept_
  20549.         statement is nested within a block_statement, these parameter_
  20550.         specifications can hide declarations of the block_statement.  The
  20551.         semantics of such cases was unclear in RM83.
  20552.  
  20553.         18.m   To be honest:  Unfortunately, we have the same problem for the
  20554.         entry name itself -- it should denote the accept_statement, but
  20555.         accept_statements are not declarations.  They should be, and they
  20556.         should hide the entry from all visibility within themselves.
  20557.  
  20558.         18.n   Note that we can't generalize this to entry_bodies, or other
  20559.         bodies, because the declarative_part of a body is not supposed to
  20560.         contain (explicit) homographs of things in the declaration.  It works
  20561.         for accept_statements only because an accept_statement does not have
  20562.         a declarative_part.
  20563.  
  20564.         18.o   To avoid confusion, we use the term ``local to'' only
  20565.         informally in Ada 9X.  Even RM83 used the term incorrectly (see, for
  20566.         example, RM83-12.3(13)).
  20567.  
  20568.         18.p   In Ada 83, (root) library units were inside Standard; it was
  20569.         not clear whether the declaration or body of Standard was meant.  In
  20570.         Ada 9X, they are children of Standard, and so occur immediately
  20571.         within Standard's declarative region, but not within either the
  20572.         declaration or the body.  (See RM83-8.6(2) and RM83-10.1.1(5).)
  20573.  
  20574.  
  20575.  
  20576. 8.2 Scope of Declarations
  20577.  
  20578. 1   [For each declaration, the language rules define a certain portion of the
  20579. program text called the scope of the declaration.  The scope of a declaration
  20580. is also called the scope of any view or entity declared by the declaration.
  20581. Within the scope of an entity, and only there, there are places where it is
  20582. legal to refer to the declared entity.  These places are defined by the rules
  20583. of visibility and overloading.]
  20584.  
  20585.  
  20586.                               Static Semantics
  20587.  
  20588. 2   {immediate scope (of a declaration)} The immediate scope of a declaration
  20589. is a portion of the declarative region immediately enclosing the declaration.
  20590. The immediate scope starts at the beginning of the declaration, except in the
  20591. case of an overloadable declaration, in which case the immediate scope starts
  20592. just after the place where the profile of the callable entity is determined
  20593. (which is at the end of the _specification for the callable entity, or at the
  20594. end of the generic_instantiation if an instance).
  20595.  
  20596.         2.a   Reason:  The reason for making overloadable declarations with
  20597.         profiles special is to simplify compilation:  until the compiler has
  20598.         determined the profile, it doesn't know which other declarations are
  20599.         homographs of this one, so it doesn't know which ones this one should
  20600.         hide.  Without this rule, two passes over the _specification or
  20601.         generic_instantiation would be required to resolve names that denote
  20602.         things with the same name as this one.
  20603.  
  20604. The immediate scope extends to the end of the declarative region, with the
  20605. following exceptions:
  20606.  
  20607.     3  The immediate scope of a library_item includes only its semantic
  20608.        dependents.
  20609.  
  20610.  3.a    Reason:  Section 10 defines only a partial ordering of library_
  20611.         items.  Therefore, it is a good idea to restrict the immediate
  20612.         scope (and the scope, defined below) to semantic dependents.
  20613.  
  20614.  3.b    Consider also examples like this:
  20615.  
  20616. 3.c         package P is end P;
  20617.  
  20618. 3.d         package P.Q is
  20619.                 I : Integer := 0;
  20620.             end P.Q;
  20621.  
  20622. 3.e         with P;
  20623.             package R is
  20624.                 package X renames P;
  20625.                 X.Q.I := 17; -- Illegal!
  20626.             end R;
  20627.  
  20628.  3.f    The scope of P.Q does not contain R. Hence, neither P.Q nor X.Q
  20629.         are visible within R. However, the name R.X.Q would be visible
  20630.         in some other library unit where both R and P.Q are visible
  20631.         (assuming R were made legal by removing the offending
  20632.         declaration).
  20633.  
  20634.     4  The immediate scope of a declaration in the private part of a
  20635.        library unit does not include the visible part of any public
  20636.        descendant of that library unit.  {descendant [relationship with
  20637.        scope]}
  20638.  
  20639.  4.a    Ramification:  In other words, a declaration in the private part
  20640.         can be visible within the visible part, private part and body of
  20641.         a private child unit.  On the other hand, such a declaration can
  20642.         be visible within only the private part and body of a public
  20643.         child unit.
  20644.  
  20645.  4.b    Reason:  The purpose of this rule is to prevent children from
  20646.         giving private information to clients.
  20647.  
  20648.  4.c    Ramification:  For a public child subprogram, this means that
  20649.         the parent's private part is not visible in the formal_parts of
  20650.         the declaration and of the body.  This is true even for
  20651.         subprogram_bodies that are not completions.  For a public child
  20652.         generic unit, it means that the parent's private part is not
  20653.         visible in the generic_formal_part, as well as in the first list
  20654.         of basic_declarative_items (for a generic package), or the
  20655.         formal_part(s) (for a generic subprogram).
  20656.  
  20657. 5   {visible part} [The visible part of (a view of) an entity is a portion of
  20658. the text of its declaration containing declarations that are visible from
  20659. outside.]  {private part [distributed]} The private part of (a view of) an
  20660. entity that has a visible part contains all declarations within the
  20661. declaration of (the view of) the entity, except those in the visible part;
  20662. [these are not visible from outside.  Visible and private parts are defined
  20663. only for these kinds of entities: callable entities, other program units, and
  20664. composite types.]
  20665.  
  20666.     6  {visible part [of a view of a callable entity]} The visible part
  20667.        of a view of a callable entity is its profile.
  20668.  
  20669.     7  {visible part [of a view of a composite type]} The visible part
  20670.        of a composite type other than a task or protected type consists
  20671.        of the declarations of all components declared [(explicitly or
  20672.        implicitly)] within the type_declaration.
  20673.  
  20674.     8  {visible part [of a generic unit]} The visible part of a generic
  20675.        unit includes the generic_formal_part.  For a generic package, it
  20676.        also includes the first list of basic_declarative_items of the
  20677.        package_specification.  For a generic subprogram, it also
  20678.        includes the profile.
  20679.  
  20680.  8.a    Reason:  Although there is no way to reference anything but the
  20681.         formals from outside a generic unit, they are still in the
  20682.         visible part in the sense that the corresponding declarations in
  20683.         an instance can be referenced (at least in some cases).  In
  20684.         other words, these declarations have an effect on the outside
  20685.         world.  The visible part of a generic unit needs to be defined
  20686.         this way in order to properly support the rule that makes a
  20687.         parent's private part invisible within a public child's visible
  20688.         part.
  20689.  
  20690.  8.b    Ramification:  The visible part of an instance of a generic unit
  20691.         is as defined for packages and subprograms; it is not defined in
  20692.         terms of the visible part of a generic unit.
  20693.  
  20694.     9  [The visible part of a package, task unit, or protected unit
  20695.        consists of declarations in the program unit's declaration other
  20696.        than those following the reserved word private, if any; see 7.1
  20697.        and 12.7 for packages, 9.1 for task units, and 9.4 for protected
  20698.        units.]
  20699.  
  20700. 10   {scope (of a declaration)} The scope of a declaration always contains
  20701. the immediate scope of the declaration.  In addition, for a given declaration
  20702. that occurs immediately within the visible part of an outer declaration, or
  20703. is a public child of an outer declaration, the scope of the given declaration
  20704. extends to the end of the scope of the outer declaration, except that the
  20705. scope of a library_item includes only its semantic dependents.
  20706.  
  20707.         10.a   Ramification:  Note the recursion.  If a declaration appears
  20708.         in the visible part of a library unit, its scope extends to the end
  20709.         of the scope of the library unit, but since that only includes
  20710.         dependents of the declaration of the library unit, the scope of the
  20711.         inner declaration also only includes those dependents.  If X renames
  20712.         library package P, which has a child Q, a with_clause mentioning P.Q
  20713.         is necessary to be able to refer to X.Q, even if P.Q is visible at
  20714.         the place where X is declared.
  20715.  
  20716. 11   {immediate scope (of (a view of) an entity)} The immediate scope of a
  20717. declaration is also the immediate scope of the entity or view declared by the
  20718. declaration.  {scope (of (a view of) an entity)} Similarly, the scope of a
  20719. declaration is also the scope of the entity or view declared by the
  20720. declaration.
  20721.  
  20722.         11.a   Ramification:  The rule for immediate scope implies the
  20723.         following:
  20724.  
  20725.          11.b  If the declaration is that of a library unit, then the
  20726.                immediate scope includes the declarative region of the
  20727.                declaration itself, but not other places, unless they are
  20728.                within the scope of a with_clause that mentions the
  20729.                library unit.
  20730.  
  20731.                11.c   It is necessary to attach the semantics of with_
  20732.                clauses to [immediate] scopes (as opposed to visibility),
  20733.                in order for various rules to work properly.  A library
  20734.                unit should hide a homographic implicit declaration that
  20735.                appears in its parent, but only within the scope of a
  20736.                with_clause that mentions the library unit.  Otherwise,
  20737.                we would violate the "legality determinable via semantic
  20738.                dependences" rule of Section 10, ``Program Structure and
  20739.                Compilation Issues''.  The declaration of a library unit
  20740.                should be allowed to be a homograph of an explicit
  20741.                declaration in its parent's body, so long as that body
  20742.                does not mention the library unit in a with_clause.
  20743.  
  20744.                11.d   This means that one cannot denote the declaration
  20745.                of the library unit, but one might still be able to
  20746.                denote the library unit via another view.
  20747.  
  20748.                11.e   A with_clause does not make the declaration of a
  20749.                library unit visible; the lack of a with_clause prevents
  20750.                it from being visible.  Even if a library unit is
  20751.                mentioned in a with_clause, its declaration can still be
  20752.                hidden.
  20753.  
  20754.          11.f  The completion of the declaration of a library unit
  20755.                (assuming that's also a declaration) is not visible,
  20756.                neither directly nor by selection, outside that
  20757.                completion.
  20758.  
  20759.          11.g  The immediate scope of a declaration immediately within
  20760.                the body of a library unit does not include any child of
  20761.                that library unit.
  20762.  
  20763.                11.h   This is needed to prevent children from looking
  20764.                inside their parent's body.  The children are in the
  20765.                declarative region of the parent, and they might be after
  20766.                the parent's body.  Therefore, the scope of a declaration
  20767.                that occurs immediately within the body might include
  20768.                some children.
  20769.      NOTES
  20770. 12   (4) There are notations for denoting visible declarations that are not
  20771.      directly visible.  For example, parameter_specifications are in the
  20772.      visible part of a subprogram_declaration so that they can be used in
  20773.      named-notation calls appearing outside the called subprogram.  For
  20774.      another example, declarations of the visible part of a package can be
  20775.      denoted by expanded names appearing outside the package, and can be made
  20776.      directly visible by a use_clause.
  20777.  
  20778.    12.a   Ramification:  There are some obscure involving generics cases in
  20779.         which there is no such notation.  See Section 12.
  20780.  
  20781.  
  20782.                             Extensions to Ada 83
  20783.  
  20784.         12.b   {extensions to Ada 83} The fact that the immediate scope of an
  20785.         overloadable declaration does not include its profile is new to Ada
  20786.         9X.  It replaces RM83-8.3(16), which said that within a subprogram
  20787.         specification and within the formal part of an entry declaration or
  20788.         accept statement, all declarations with the same designator as the
  20789.         subprogram or entry were hidden from all visibility.  The
  20790.         RM83-8.3(16) rule seemed to be overkill, and created both
  20791.         implementation difficulties and unnecessary semantic complexity.
  20792.  
  20793.                          Wording Changes From Ada 83
  20794.  
  20795.         12.c   We no longer need to talk about the scope of notations,
  20796.         identifiers, character_literals, and operator_symbols.
  20797.  
  20798.         12.d   The notion of "visible part" has been extended in Ada 9X.  The
  20799.         syntax of task and protected units now allows private parts, thus
  20800.         requiring us to be able to talk about the visible part as well.  It
  20801.         was necessary to extend the concept to subprograms and to generic
  20802.         units, in order for the visibility rules related to child library
  20803.         units to work properly.  It was necessary to define the concept
  20804.         separately for generic formal packages, since their visible part is
  20805.         slightly different from that of a normal package.  Extending the
  20806.         concept to composite types made the definition of scope slightly
  20807.         simpler.  We define visible part for some things elsewhere, since it
  20808.         makes a big difference to the user for those things.  For composite
  20809.         types and subprograms, however, the concept is used only in arcane
  20810.         visibility rules, so we localize it to this clause.
  20811.  
  20812.         12.e   In Ada 83, the semantics of with_clauses was described in
  20813.         terms of visibility.  It is now described in terms of [immediate]
  20814.         scope.
  20815.  
  20816.         12.f   We have clarified that the following is illegal (where Q and R
  20817.         are library units):
  20818.  
  20819. 12.g        package Q is
  20820.                 I : Integer := 0;
  20821.             end Q;
  20822.  
  20823. 12.h        package R is
  20824.                 package X renames Standard;
  20825.                 X.Q.I := 17; -- Illegal!
  20826.             end R;
  20827.  
  20828.         12.i   even though Q is declared in the declarative region of
  20829.         Standard, because R does not mention Q in a with_clause.
  20830.  
  20831.  
  20832.  
  20833. 8.3 Visibility
  20834.  
  20835. 1   [{visibility rules} The visibility rules, given below, determine which
  20836. declarations are visible and directly visible at each place within a program.
  20837. The visibility rules apply to both explicit and implicit declarations.]
  20838.  
  20839.  
  20840.                               Static Semantics
  20841.  
  20842. 2   {visibility (direct)} {directly visible} {directly visible} A declaration
  20843. is defined to be directly visible at places where a name consisting of only
  20844. an identifier or operator_symbol is sufficient to denote the declaration;
  20845. that is, no selected_component notation or special context (such as preceding
  20846. => in a named association) is necessary to denote the declaration.  {visible}
  20847. A declaration is defined to be visible wherever it is directly visible, as
  20848. well as at other places where some name (such as a selected_component) can
  20849. denote the declaration.
  20850.  
  20851. 3   The syntactic category direct_name is used to indicate contexts where
  20852. direct visibility is required.  The syntactic category selector_name is used
  20853. to indicate contexts where visibility, but not direct visibility, is
  20854. required.
  20855.  
  20856. 4   {visibility (immediate)} {visibility (use clause)} There are two kinds of
  20857. direct visibility:  immediate visibility and use-visibility.  {immediately
  20858. visible} A declaration is immediately visible at a place if it is directly
  20859. visible because the place is within its immediate scope.  {use-visible} A
  20860. declaration is use-visible if it is directly visible because of a use_clause
  20861. (see 8.4).  Both conditions can apply.
  20862.  
  20863. 5   {hiding} A declaration can be hidden, either from direct visibility, or
  20864. from all visibility, within certain parts of its scope.  {hidden from all
  20865. visibility} Where hidden from all visibility, it is not visible at all
  20866. (neither using a direct_name nor a selector_name).  {hidden from direct
  20867. visibility} Where hidden from direct visibility, only direct visibility is
  20868. lost; visibility using a selector_name is still possible.
  20869.  
  20870. 6   [{overloaded} Two or more declarations are overloaded if they all have
  20871. the same defining name and there is a place where they are all directly
  20872. visible.]
  20873.  
  20874.         6.a   Ramification:  Note that a name can have more than one possible
  20875.         interpretation even if it denotes a non-overloadable entity.  For
  20876.         example, if there are two functions F that return records, both
  20877.         containing a component called C, then the name F.C has two possible
  20878.         interpretations, even though component declarations are not
  20879.         overloadable.
  20880.  
  20881. 7   {overloadable} The declarations of callable entities [(including
  20882. enumeration literals)] are overloadable[, meaning that overloading is allowed
  20883. for them].
  20884.  
  20885.         7.a   Ramification:  A generic_declaration is not overloadable within
  20886.         its own generic_formal_part.  This follows from the rules about when
  20887.         a name denotes a current instance.  See AI-00286.  This implies that
  20888.         within a generic_formal_part, outer declarations with the same
  20889.         defining name are hidden from direct visibility.  It also implies
  20890.         that if a generic formal parameter has the same defining name as the
  20891.         generic itself, the formal parameter hides the generic from direct
  20892.         visibility.
  20893.  
  20894. 8   {homograph} Two declarations are homographs if they have the same
  20895. defining name, and, if both are overloadable, their profiles are type
  20896. conformant.  {type conformance [partial]}[An inner declaration hides any
  20897. outer homograph from direct visibility.]
  20898.  
  20899. 9   [Two homographs are not generally allowed immediately within the same
  20900. declarative region unless one overrides the other (see Legality Rules
  20901. below).]  {override} A declaration overrides another homograph that occurs
  20902. immediately within the same declarative region in the following cases:
  20903.  
  20904.    10  An explicit declaration overrides an implicit declaration of a
  20905.        primitive subprogram, [regardless of which declaration occurs
  20906.        first];
  20907.  
  20908.  10.a   Ramification:  And regardless of whether the explicit
  20909.         declaration is overloadable or not.
  20910.  
  20911.  10.b   The ``regardless of which declaration occurs first'' is there
  20912.         because the explicit declaration could be a primitive subprogram
  20913.         of a partial view, and then the full view might inherit a
  20914.         homograph.  We are saying that the explicit one wins (within its
  20915.         scope), even though the implicit one comes later.
  20916.  
  20917.  10.c   If the overriding declaration is also a subprogram, then it is a
  20918.         primitive subprogram.
  20919.  
  20920.  10.d   As explained in 7.3.1, ``Private Operations'', some inherited
  20921.         primitive subprograms are never declared.  Such subprograms
  20922.         cannot be overridden, although they can be reached by
  20923.         dispatching calls in the case of a tagged type.
  20924.  
  20925.    11  The implicit declaration of an inherited operator overrides that
  20926.        of a predefined operator;
  20927.  
  20928.  11.a   Ramification:  In a previous version of Ada 9X, we tried to
  20929.         avoid the notion of predefined operators, and say that they were
  20930.         inherited from some magical root type.  However, this seemed
  20931.         like too much mechanism.  Therefore, a type can have a
  20932.         predefined "+" as well as an inherited "+".  The above rule says
  20933.         the inherited one wins.
  20934.  
  20935.  11.b   The ``regardless of which declaration occurs first'' applies
  20936.         here as well, in the case where derived_type_declaration in the
  20937.         visible part of a public library unit derives from a private
  20938.         type declared in the parent unit, and the full view of the
  20939.         parent type has additional predefined operators, as explained in
  20940.         7.3.1, ``Private Operations''.  Those predefined operators can
  20941.         be overridden by inherited subprograms implicitly declared
  20942.         earlier.
  20943.  
  20944.    12  An implicit declaration of an inherited subprogram overrides a
  20945.        previous implicit declaration of an inherited subprogram.
  20946.  
  20947.    13  [For an implicit declaration of a primitive subprogram in a
  20948.        generic unit, there is a copy of this declaration in an
  20949.        instance.]  However, a whole new set of primitive subprograms is
  20950.        implicitly declared for each type declared within the visible
  20951.        part of the instance.  These new declarations occur immediately
  20952.        after the type declaration, and override the copied ones.  [The
  20953.        copied ones can be called only from within the instance; the new
  20954.        ones can be called only from outside the instance, although for
  20955.        tagged types, the body of a new one can be executed by a call to
  20956.        an old one.]
  20957.  
  20958.  13.a   Discussion:  In addition, this is also stated redundantly
  20959.         (again), and is repeated, in 12.3, ``Generic Instantiation''.
  20960.         The rationale for the rule is explained there.
  20961.  
  20962. 14   {visible} {hidden from all visibility [distributed]} A declaration is
  20963. visible within its scope, except where hidden from all visibility, as
  20964. follows:
  20965.  
  20966.    15  {hidden from all visibility [for overridden declaration]} An
  20967.        overridden declaration is hidden from all visibility within the
  20968.        scope of the overriding declaration.
  20969.  15.a   Ramification:  We have to talk about the scope of the overriding
  20970.         declaration, not its visibility, because it hides even when it
  20971.         is itself hidden.
  20972.  
  20973.  15.b   Note that the scope of an explicit subprogram_declaration does
  20974.         not start until after its profile.
  20975.  
  20976.    16  {hidden from all visibility [within the declaration itself]} A
  20977.        declaration is hidden from all visibility until the end of the
  20978.        declaration, except:
  20979.  
  20980.           17  For a record type or record extension, the declaration is
  20981.               hidden from all visibility only until the reserved word
  20982.               record;
  20983.  
  20984.           18  For a package_declaration, task declaration, protected
  20985.               declaration, generic_package_declaration, or subprogram_
  20986.               body, the declaration is hidden from all visibility only
  20987.               until the reserved word is of the declaration.
  20988.               {94-4942.a}
  20989.  
  20990.  18.a   Ramification:  We're talking about the is of the construct
  20991.         itself, here, not some random is that might appear in a generic_
  20992.         formal_part.
  20993.  
  20994.    19  {hidden from all visibility [for a declaration completed by a
  20995.        subsequent declaration]} If the completion of a declaration is a
  20996.        declaration, then within the scope of the completion, the first
  20997.        declaration is hidden from all visibility.  Similarly, a
  20998.        discriminant_specification or parameter_specification is hidden
  20999.        within the scope of a corresponding discriminant_specification or
  21000.        parameter_specification of a corresponding completion, or of a
  21001.        corresponding accept_statement.
  21002.  
  21003.  19.a   Ramification:  This rule means, for example, that within the
  21004.         scope of a full_type_declaration that completes a private_type_
  21005.         declaration, the name of the type will denote the full_type_
  21006.         declaration, and therefore the full view of the type.  On the
  21007.         other hand, if the completion is not a declaration, then it
  21008.         doesn't hide anything, and you can't denote it.
  21009.  
  21010.    20  {hidden from all visibility [by lack of a with_clause]} The
  21011.        declaration of a library unit (including a library_unit_renaming_
  21012.        declaration) is hidden from all visibility except at places that
  21013.        are within its declarative region or within the scope of a with_
  21014.        clause that mentions it.  [For each declaration or renaming of a
  21015.        generic unit as a child of some parent generic package, there is
  21016.        a corresponding declaration nested immediately within each
  21017.        instance of the parent.]  Such a nested declaration is hidden
  21018.        from all visibility except at places that are within the scope of
  21019.        a with_clause that mentions the child.  {94-4933.a}
  21020.  
  21021.  20.a   Discussion:  This is the rule that prevents with_clauses from
  21022.         being transitive; the [immediate] scope includes indirect
  21023.         semantic dependents.
  21024.  
  21025. 21   {directly visible} {immediately visible} {visibility (direct)}
  21026. {visibility (immediate)} A declaration with a defining_identifier or
  21027. defining_operator_symbol is immediately visible [(and hence directly
  21028. visible)] within its immediate scope {hidden from direct visibility
  21029. [distributed]} except where hidden from direct visibility, as follows:
  21030.  
  21031.    22  {hidden from direct visibility [by an inner homograph]} A
  21032.        declaration is hidden from direct visibility within the immediate
  21033.        scope of a homograph of the declaration, if the homograph occurs
  21034.        within an inner declarative region;
  21035.  
  21036.    23  {hidden from direct visibility [where hidden from all
  21037.        visibility]} A declaration is also hidden from direct visibility
  21038.        where hidden from all visibility.
  21039.  
  21040.  
  21041.                             Name Resolution Rules
  21042.  
  21043. 24   {possible interpretation [for direct_names]} A direct_name shall resolve
  21044. to denote a directly visible declaration whose defining name is the same as
  21045. the direct_name.  {possible interpretation [for selector_names]} A selector_
  21046. name shall resolve to denote a visible declaration whose defining name is the
  21047. same as the selector_name.
  21048.  
  21049.         24.a   Discussion:  "The same as" has the obvious meaning here, so
  21050.         for +, the possible interpretations are declarations whose defining
  21051.         name is "+" (an operator_symbol).
  21052.  
  21053. 25   These rules on visibility and direct visibility do not apply in a
  21054. context_clause, a parent_unit_name, or a pragma that appears at the place of
  21055. a compilation_unit.  For those contexts, see the rules in 10.1.6,
  21056. ``Environment-Level Visibility Rules''.
  21057.  
  21058.         25.a   Ramification:  Direct visibility is irrelevant for character_
  21059.         literals.  In terms of overload resolution character_literals are
  21060.         similar to other literals, like null -- see 4.2.  For character_
  21061.         literals, there is no need to worry about hiding, since there is no
  21062.         way to declare homographs.
  21063.  
  21064.  
  21065.                                Legality Rules
  21066.  
  21067. 26   An explicit declaration is illegal if there is a homograph occurring
  21068. immediately within the same declarative region that is visible at the place
  21069. of the declaration, and is not hidden from all visibility by the explicit
  21070. declaration.  Similarly, the context_clause for a subunit is illegal if it
  21071. mentions (in a with_clause) some library unit, and there is a homograph of
  21072. the library unit that is visible at the place of the corresponding stub, and
  21073. the homograph and the mentioned library unit are both declared immediately
  21074. within the same declarative region.  {generic contract issue [partial]} These
  21075. rules also apply to dispatching operations declared in the visible part of an
  21076. instance of a generic unit.  However, they do not apply to other overloadable
  21077. declarations in an instance[; such declarations may have type conformant
  21078. profiles in the instance, so long as the corresponding declarations in the
  21079. generic were not type conformant].  {type conformance [partial]}
  21080.  
  21081.         26.a   Discussion:  Normally, these rules just mean you can't
  21082.         explicitly declare two homographs immediately within the same
  21083.         declarative region.  The wording is designed to handle the following
  21084.         special cases:
  21085.  
  21086.          26.b  If the second declaration completes the first one, the
  21087.                second declaration is legal.
  21088.  
  21089.          26.c  If the body of a library unit contains an explicit
  21090.                homograph of a child of that same library unit, this is
  21091.                illegal only if the body mentions the child in its
  21092.                context_clause, or if some subunit mentions the child.
  21093.                Here's an example:
  21094.  
  21095. 26.d               package P is
  21096.                    end P;
  21097.  
  21098. 26.e               package P.Q is
  21099.                    end P.Q;
  21100.  
  21101. 26.f               package body P is
  21102.                        Q : Integer; -- OK; we cannot see package P.Q here.
  21103.                        procedure Sub is separate;
  21104.                    end P;
  21105.  
  21106. 26.g               with P.Q;
  21107.                    separate(P)
  21108.                    procedure Sub is -- Illegal.
  21109.                    begin
  21110.                        null;
  21111.                    end Sub;
  21112.  
  21113.                26.h   If package body P said "with P.Q;", then it would
  21114.                be illegal to declare the homograph Q: Integer.  But it
  21115.                does not, so the body of P is OK.  However, the subunit
  21116.                would be able to see both P.Q's, and is therefore
  21117.                illegal.
  21118.  
  21119.                26.i   A previous version of Ada 9X allowed the subunit,
  21120.                and said that references to P.Q would tend to be
  21121.                ambiguous.  However, that was a bad idea, because it
  21122.                requires overload resolution to resolve references to
  21123.                directly visible non-overloadable homographs, which is
  21124.                something compilers have never before been required to
  21125.                do.
  21126.  
  21127.         26.j   Note that we need to be careful which things we make "hidden
  21128.         from all visibility" versus which things we make simply illegal for
  21129.         names to denote.  The distinction is subtle.  The rules that disallow
  21130.         names denoting components within a type declaration (see 3.7) do not
  21131.         make the components invisible at those places, so that the above rule
  21132.         makes components with the same name illegal.  The same is true for
  21133.         the rule that disallows names denoting formal parameters within a
  21134.         formal_part (see 6.1).
  21135.  
  21136.         26.k   Discussion:  The part about instances is from AI-00012.  The
  21137.         reason it says ``overloadable declarations'' is because we don't want
  21138.         it to apply to type extensions that appear in an instance; components
  21139.         are not overloadable.
  21140.  
  21141.  
  21142.      NOTES
  21143. 27   (5) Visibility for compilation units follows from the definition of the
  21144.      environment in 10.1.4, except that it is necessary to apply a with_
  21145.      clause to obtain visibility to a library_unit_declaration or library_
  21146.      unit_renaming_declaration.
  21147.  
  21148. 28   (6) In addition to the visibility rules given above, the meaning of the
  21149.      occurrence of a direct_name or selector_name at a given place in the
  21150.      text can depend on the overloading rules (see 8.6).  {94-4666.a}
  21151.  
  21152. 29   (7) Not all contexts where an identifier, character_literal, or
  21153.      operator_symbol are allowed require visibility of a corresponding
  21154.      declaration.  Contexts where visibility is not required are identified
  21155.      by using one of these three syntactic categories directly in a syntax
  21156.      rule, rather than using direct_name or selector_name.
  21157.  
  21158.    29.a   Ramification:  An identifier, character_literal or operator_symbol
  21159.         that occurs in one of the following contexts is not required to
  21160.         denote a visible or directly visible declaration:
  21161.  
  21162.          29.b  A defining name.
  21163.  
  21164.          29.c  The identifiers or operator_symbol that appear after the
  21165.                reserved word end in a proper_body.  Similarly for ``end
  21166.                loop'', etc.
  21167.  
  21168.          29.d  An attribute_designator.
  21169.  
  21170.          29.e  A pragma identifier.
  21171.  
  21172.          29.f  A pragma_argument_identifier.
  21173.  
  21174.          29.g  An identifier specific to a pragma used in a pragma
  21175.                argument.
  21176.  
  21177.    29.h   The visibility rules have nothing to do with the above cases; the
  21178.         meanings of such things are defined elsewhere.  Reserved words are
  21179.         not identifiers; the visibility rules don't apply to them either.
  21180.  
  21181.    29.i   Because of the way we have defined "declaration", it is possible
  21182.         for a usage name to denote a subprogram_body, either within that
  21183.         body, or (for a non-library unit) after it (since the body hides the
  21184.         corresponding declaration, if any).  Other bodies do not work that
  21185.         way.  Completions of type_ and deferred_constant_declarations do work
  21186.         that way.  Accept_statements are never denoted, although the
  21187.         parameter_specifications in their profiles can be.
  21188.  
  21189.    29.j   The scope of a subprogram does not start until after its profile.
  21190.         Thus, the following is legal:
  21191.  
  21192. 29.k        X : constant Integer := 17;
  21193.             ...
  21194.             package P is
  21195.                 procedure X(Y : in Integer := X);
  21196.             end P;
  21197.  
  21198.    29.l   The body of the subprogram will probably be illegal, however, since
  21199.         the constant X will be hidden by then.
  21200.  
  21201.    29.m   The rule is different for generic subprograms, since they are not
  21202.         overloadable; the following is illegal:
  21203.  
  21204. 29.n        X : constant Integer := 17;
  21205.             package P is
  21206.                 generic
  21207.                   Z : Integer := X; -- Illegal!
  21208.                 procedure X(Y : in Integer := X); -- Illegal!
  21209.             end P;
  21210.  
  21211.         {94-4942.a}
  21212.  
  21213.    29.o   The constant X is hidden from direct visibility by the generic
  21214.         declaration.
  21215.  
  21216.  
  21217.                             Extensions to Ada 83
  21218.  
  21219.         29.p   {extensions to Ada 83} Declarations with the same defining
  21220.         name as that of a subprogram or entry being defined are nevertheless
  21221.         visible within the subprogram specification or entry declaration.
  21222.  
  21223.                          Wording Changes From Ada 83
  21224.  
  21225.         29.q   The term ``visible by selection'' is no longer defined.  We
  21226.         use the terms ``directly visible'' and ``visible'' (among other
  21227.         things).  There are only two regions of text that are of interest,
  21228.         here: the region in which a declaration is visible, and the region in
  21229.         which it is directly visible.
  21230.  
  21231.         29.r   Visibility is defined only for declarations.
  21232.  
  21233.  
  21234.  
  21235. 8.4 Use Clauses
  21236.  
  21237. 1   [A use_package_clause achieves direct visibility of declarations that
  21238. appear in the visible part of a package; a use_type_clause achieves direct
  21239. visibility of the primitive operators of a type.]
  21240.  
  21241.  
  21242.                          Language Design Principles
  21243.  
  21244.         1.a   {equivalence of use_clauses and selected_components} If and
  21245.         only if the visibility rules allow P.A, "use P;" should make A
  21246.         directly visible (barring name conflicts).  This means, for example,
  21247.         that child library units, and generic formals of a formal package
  21248.         whose formal_package_actual_part is (<>), should be made visible by a
  21249.         use_clause for the appropriate package.
  21250.  
  21251.         1.b   {Beaujolais effect} The rules for use_clauses were carefully
  21252.         constructed to avoid so-called Beaujolais effects, where the addition
  21253.         or removal of a single use_clause, or a single declaration in a
  21254.         "use"d package, would change the meaning of a program from one legal
  21255.         interpretation to another.
  21256.  
  21257.                                    Syntax
  21258.  
  21259. 2   use_clause ::= use_package_clause | use_type_clause
  21260.  
  21261. 3   use_package_clause ::= use package_name {, package_name};
  21262.  
  21263. 4   use_type_clause ::= use type subtype_mark {, subtype_mark};
  21264.  
  21265.  
  21266.                                Legality Rules
  21267.  
  21268. 5   A package_name of a use_package_clause shall denote a package.
  21269.  
  21270.         5.a   Ramification:  This includes formal packages.
  21271.  
  21272.  
  21273.                               Static Semantics
  21274.  
  21275. 6   {scope (of a use_clause)} For each use_clause, there is a certain region
  21276. of text called the scope of the use_clause.  For a use_clause within a
  21277. context_clause of a library_unit_declaration or library_unit_renaming_
  21278. declaration, the scope is the entire declarative region of the declaration.
  21279. For a use_clause within a context_clause of a body, the scope is the entire
  21280. body [and any subunits (including multiply nested subunits).  The scope does
  21281. not include context_clauses themselves.]
  21282.  
  21283. 7   For a use_clause immediately within a declarative region, the scope is
  21284. the portion of the declarative region starting just after the use_clause and
  21285. extending to the end of the declarative region.  However, the scope of a use_
  21286. clause in the private part of a library unit does not include the visible
  21287. part of any public descendant of that library unit.
  21288.  
  21289.         7.a   Reason:  The exception echoes the similar exception for
  21290.         ``immediate scope (of a declaration)'' (see 8.2).  It makes use_
  21291.         clauses work like this:
  21292.  
  21293. 7.b         package P is
  21294.                 type T is range 1..10;
  21295.             end P;
  21296.  
  21297. 7.c         with P;
  21298.             package Parent is
  21299.             private
  21300.                 use P;
  21301.                 X : T;
  21302.             end Parent;
  21303.  
  21304. 7.d         package Parent.Child is
  21305.                 Y : T; -- Illegal!
  21306.                 Z : P.T;
  21307.             private
  21308.                 W : T;
  21309.             end Parent.Child;
  21310.  
  21311.         7.e   The declaration of Y is illegal because the scope of the ``use
  21312.         P'' does not include that place, so T is not directly visible there.
  21313.         The declarations of X, Z, and W are legal.
  21314.  
  21315. 8   {potentially use-visible} For each package denoted by a package_name of a
  21316. use_package_clause whose scope encloses a place, each declaration that occurs
  21317. immediately within the declarative region of the package is potentially
  21318. use-visible at this place if the declaration is visible at this place.
  21319. {94-4666.b} For each type T or T'Class determined by a subtype_mark of a use_
  21320. type_clause whose scope encloses a place, the declaration of each primitive
  21321. operator of type T is potentially use-visible at this place if its
  21322. declaration is visible at this place.
  21323.  
  21324.         8.a   Ramification:  Primitive subprograms whose defining name is an
  21325.         identifier are not made potentially visible by a use_type_clause.  A
  21326.         use_type_clause is only for operators.
  21327.  
  21328.         8.b   The semantics described here should be similar to the semantics
  21329.         for expanded names given in 4.1.3, ``Selected Components'' so as to
  21330.         achieve the effect requested by the ``principle of equivalence of
  21331.         use_clauses and selected_components.''  Thus, child library units and
  21332.         generic formal parameters of a formal package are potentially
  21333.         use-visible when their enclosing package is use'd.
  21334.  
  21335.         8.c   The "visible at that place" part implies that applying a use_
  21336.         clause to a parent unit does not make all of its children use-visible
  21337.         -- only those that have been made visible by a with_clause.  It also
  21338.         implies that we don't have to worry about hiding in the definition of
  21339.         "directly visible" -- a declaration cannot be use-visible unless it
  21340.         is visible.
  21341.  
  21342.         8.d   Note that "use type T'Class;" is equivalent to "use type T;",
  21343.         which helps avoid breaking the generic contract model.
  21344.  
  21345. 9   {use-visible} {visibility (use clause)} A declaration is use-visible if
  21346. it is potentially use-visible, except in these naming-conflict cases:
  21347.  
  21348.    10  A potentially use-visible declaration is not use-visible if the
  21349.        place considered is within the immediate scope of a homograph of
  21350.        the declaration.
  21351.  
  21352.    11  Potentially use-visible declarations that have the same
  21353.        identifier are not use-visible unless each of them is an
  21354.        overloadable declaration.
  21355.  
  21356.  11.a   Ramification:  Overloadable declarations don't cancel each other
  21357.         out, even if they are homographs, though if they are not
  21358.         distinguishable by formal parameter names or the presence or
  21359.         absence of default_expressions, any use will be ambiguous.  We
  21360.         only mention identifiers here, because declarations named by
  21361.         operator_symbols are always overloadable, and hence never cancel
  21362.         each other.  Direct visibility is irrelevant for character_
  21363.         literals.
  21364.                               Dynamic Semantics
  21365.  
  21366. 12   {elaboration [use_clause]} The elaboration of a use_clause has no
  21367. effect.
  21368.  
  21369.  
  21370.                                   Examples
  21371.  
  21372. 13   Example of a use clause in a context clause:
  21373.  
  21374. 14  with Ada.Calendar; use Ada;
  21375.  
  21376. 15   Example of a use type clause:
  21377.  
  21378. 16  use type Rational_Numbers.Rational; -- see 7.1
  21379.     Two_Thirds: Rational_Numbers.Rational := 2/3;
  21380.  
  21381. {94-4774.c}
  21382.  
  21383.         16.a   Ramification:  In ``use X, Y;'', Y cannot refer to something
  21384.         made visible by the ``use'' of X. Thus, it's not (quite) equivalent
  21385.         to ``use X; use Y;''.
  21386.  
  21387.         16.b   If a given declaration is already immediately visible, then a
  21388.         use_clause that makes it potentially use-visible has no effect.
  21389.         Therefore, a use_type_clause for a type whose declaration appears in
  21390.         a place other than the visible part of a package has no effect; it
  21391.         cannot make a declaration use-visible unless that declaration is
  21392.         already immediately visible.
  21393.  
  21394.         16.c   "Use type S1;" and "use type S2;" are equivalent if S1 and S2
  21395.         are both subtypes of the same type.  In particular, "use type S;" and
  21396.         "use type S'Base;" are equivalent.
  21397.  
  21398.         16.d   Reason:  We considered adding a rule that prevented several
  21399.         declarations of views of the same entity that all have the same
  21400.         semantics from cancelling each other out.  For example, if a
  21401.         (possibly implicit) subprogram_declaration for "+" is potentially
  21402.         use-visible, and a fully conformant renaming of it is also
  21403.         potentially use-visible, then they (annoyingly) cancel each other
  21404.         out; neither one is use-visible.  The considered rule would have made
  21405.         just one of them use-visible.  We gave up on this idea due to the
  21406.         complexity of the rule.  It would have had to account for both
  21407.         overloadable and non-overloadable renaming_declarations, the case
  21408.         where the rule should apply only to some subset of the declarations
  21409.         with the same defining name, and the case of subtype_declarations
  21410.         (since they are claimed to be sufficient for renaming of subtypes).
  21411.  
  21412.  
  21413.                             Extensions to Ada 83
  21414.  
  21415.         16.e   {extensions to Ada 83} The use_type_clause is new to Ada 9X.
  21416.  
  21417.                          Wording Changes From Ada 83
  21418.  
  21419.         16.f   The phrase ``omitting from this set any packages that enclose
  21420.         this place'' is no longer necessary to avoid making something visible
  21421.         outside its scope, because we explicitly state that the declaration
  21422.         has to be visible in order to be potentially use-visible.
  21423.  
  21424.  
  21425.  
  21426. 8.5 Renaming Declarations
  21427.  
  21428. 1   [A renaming_declaration declares another name for an entity, such as an
  21429. object, exception, package, subprogram, entry, or generic unit.
  21430. Alternatively, a subprogram_renaming_declaration can be the completion of a
  21431. previous subprogram_declaration.]
  21432.  
  21433.  
  21434.                                    Syntax
  21435.  
  21436. 2   renaming_declaration ::=
  21437.           object_renaming_declaration
  21438.         | exception_renaming_declaration
  21439.         | package_renaming_declaration
  21440.         | subprogram_renaming_declaration
  21441.         | generic_renaming_declaration
  21442.  
  21443.  
  21444.                               Dynamic Semantics
  21445.  
  21446. 3   {elaboration [renaming_declaration]} The elaboration of a renaming_
  21447. declaration evaluates the name that follows the reserved word renames and
  21448. thereby determines the view and entity denoted by this name {renamed view}
  21449. {renamed entity} (the renamed view and renamed entity).  [A name that denotes
  21450. the renaming_declaration denotes (a new view of) the renamed entity.]
  21451.  
  21452.  
  21453.      NOTES
  21454. 4    (8) Renaming may be used to resolve name conflicts and to act as a
  21455.      shorthand.  Renaming with a different identifier or operator_symbol does
  21456.      not hide the old name; the new name and the old name need not be visible
  21457.      at the same places.
  21458.  
  21459. 5    (9) A task or protected object that is declared by an explicit object_
  21460.      declaration can be renamed as an object.  However, a single task or
  21461.      protected object cannot be renamed since the corresponding type is
  21462.      anonymous (meaning it has no nameable subtypes).  For similar reasons,
  21463.      an object of an anonymous array or access type cannot be renamed.
  21464.  
  21465. 6    (10) A subtype defined without any additional constraint can be used to
  21466.      achieve the effect of renaming another subtype (including a task or
  21467.      protected subtype) as in
  21468.  
  21469. 7        subtype Mode is Ada.Text_IO.File_Mode;
  21470.  
  21471.  
  21472.                          Wording Changes From Ada 83
  21473.  
  21474.         7.a   The second sentence of RM83-8.5(3), ``At any point where a
  21475.         renaming declaration is visible, the identifier, or operator symbol
  21476.         of this declaration denotes the renamed entity.''  is incorrect.  It
  21477.         doesn't say directly visible.  Also, such an identifier might resolve
  21478.         to something else.
  21479.  
  21480.         7.b   The verbiage about renamings being legal ``only if exactly
  21481.         one...'', which appears in RM83-8.5(4) (for objects) and RM83-8.5(7)
  21482.         (for subprograms) is removed, because it follows from the normal
  21483.         rules about overload resolution.  For language lawyers, these facts
  21484.         are obvious; for programmers, they are irrelevant, since failing
  21485.         these tests is highly unlikely.
  21486.  
  21487.  
  21488.  
  21489. 8.5.1 Object Renaming Declarations
  21490.  
  21491. 1   [An object_renaming_declaration is used to rename an object.]
  21492.  
  21493.  
  21494.                                    Syntax
  21495.  
  21496. 2   object_renaming_declaration ::= defining_identifier : subtype_mark renames \
  21497. object_name;
  21498.  
  21499.  
  21500.                             Name Resolution Rules
  21501.  
  21502. 3   The type of the object_name shall resolve to the type determined by the
  21503. subtype_mark.  {94-4500.a} {94-4505.a} {94-4506.a} {94-4507.a} {94-4509.a}
  21504. {94-4532.a}
  21505.  
  21506.         3.a   Reason:  A previous version of Ada 9X used the usual ``expected
  21507.         type'' wording:  ``The expected type for the object_name is that
  21508.         determined by the subtype_mark.''  We changed it so that this would
  21509.         be illegal:
  21510.  
  21511. 3.b         X: T;
  21512.             Y: T'Class renames X; -- Illegal!
  21513.  
  21514.         3.c   When the above was legal, it was unclear whether Y was of type
  21515.         T or T'Class.  Note that we still allow this:
  21516.  
  21517. 3.d         Z: T'Class := ...;
  21518.             W: T renames F(Z);
  21519.  
  21520.         3.e   where F is a function with a controlling parameter and result.
  21521.         This is admittedly a bit odd.
  21522.  
  21523.         3.f   Note that the matching rule for generic formal parameters of
  21524.         mode in out was changed to keep it consistent with the rule for
  21525.         renaming.  That makes the rule different for in vs. in out.
  21526.  
  21527. {94-5001.h}
  21528.  
  21529.  
  21530.                                Legality Rules
  21531.  
  21532. 4   The renamed entity shall be an object.
  21533.  
  21534. 5   The renamed entity shall not be a subcomponent that depends on
  21535. discriminants of a variable whose nominal subtype is unconstrained, unless
  21536. this subtype is indefinite, or the variable is aliased.  A slice of an array
  21537. shall not be renamed if this restriction disallows renaming of the array.
  21538.  
  21539.         5.a   Reason:  This prevents renaming of subcomponents that might
  21540.         disappear, which might leave dangling references.  Similar
  21541.         restrictions exist for the Access attribute.
  21542.  
  21543.         5.b   Implementation Note:  Note that if an implementation chooses to
  21544.         deallocate-then-reallocate on assignment_statements assigning to
  21545.         unconstrained definite objects, then it cannot represent renamings
  21546.         and access values as simple addresses, because the above rule does
  21547.         not apply to all components of such an object.
  21548.  
  21549.         5.c   Ramification:  If it is a generic formal object, then the
  21550.         assume-the-best or assume-the-worst rules are applied as appropriate.
  21551.  
  21552.  
  21553.                               Static Semantics
  21554.  
  21555. 6   An object_renaming_declaration declares a new view [of the renamed
  21556. object] whose properties are identical to those of the renamed view.  [Thus,
  21557. the properties of the renamed object are not affected by the renaming_
  21558. declaration.  In particular, its value and whether or not it is a constant
  21559. are unaffected; similarly, the constraints that apply to an object are not
  21560. affected by renaming (any constraint implied by the subtype_mark of the
  21561. object_renaming_declaration is ignored).]
  21562.  
  21563.         6.a   Discussion:  Because the constraints are ignored, it is a good
  21564.         idea to use the nominal subtype of the renamed object when writing an
  21565.         object_renaming_declaration.
  21566.  
  21567.  
  21568.                                   Examples
  21569.  
  21570. 7   Example of renaming an object:
  21571.  
  21572. 8   declare
  21573.        L : Person renames Leftmost_Person; -- see 3.10.1
  21574.     begin
  21575.        L.Age := L.Age + 1;
  21576.     end;
  21577.  
  21578.  
  21579.                          Wording Changes From Ada 83
  21580.  
  21581.         8.a   The phrase ``subtype ... as defined in a corresponding object
  21582.         declaration, component declaration, or component subtype indica-
  21583.         tion,'' from RM83-8.5(5), is incorrect in Ada 9X; therefore we
  21584.         removed it.  It is incorrect in the case of an object with an
  21585.         indefinite unconstrained nominal subtype.
  21586.  
  21587.  
  21588.  
  21589. 8.5.2 Exception Renaming Declarations
  21590.  
  21591. 1   [An exception_renaming_declaration is used to rename an exception.]
  21592.  
  21593.  
  21594.                                    Syntax
  21595.  
  21596. 2   exception_renaming_declaration ::= defining_identifier : exception renames \
  21597. exception_name;
  21598.  
  21599.  
  21600.                                Legality Rules
  21601.  
  21602. 3   The renamed entity shall be an exception.
  21603.  
  21604.  
  21605.                               Static Semantics
  21606.  
  21607. 4   An exception_renaming_declaration declares a new view [of the renamed
  21608. exception].
  21609.  
  21610.  
  21611.                                   Examples
  21612.  
  21613. 5   Example of renaming an exception:
  21614.  
  21615. 6   EOF : exception renames Ada.IO_Exceptions.End_Error;-- see A.13
  21616.  
  21617.  
  21618.  
  21619. 8.5.3 Package Renaming Declarations
  21620.  
  21621. 1   [A package_renaming_declaration is used to rename a package.]
  21622.  
  21623.  
  21624.                                    Syntax
  21625.  
  21626. 2   package_renaming_declaration ::= package defining_program_unit_name renames\
  21627.  package_name;
  21628.  
  21629.  
  21630.                                Legality Rules
  21631.  
  21632. 3   The renamed entity shall be a package.
  21633.  
  21634.  
  21635.                               Static Semantics
  21636.  
  21637. 4   A package_renaming_declaration declares a new view [of the renamed
  21638. package].
  21639.  
  21640.  
  21641.                                   Examples
  21642.  
  21643. 5   Example of renaming a package:
  21644.  
  21645. 6   package TM renames Table_Manager;
  21646.  
  21647.  
  21648.  
  21649. 8.5.4 Subprogram Renaming Declarations
  21650.  
  21651. 1   A subprogram_renaming_declaration can serve as the completion of a
  21652. subprogram_declaration; {renaming-as-body} such a renaming_declaration is
  21653. called a renaming-as-body.  {renaming-as-declaration} A subprogram_renaming_
  21654. declaration that is not a completion is called a renaming-as-declaration[,
  21655. and is used to rename a subprogram (possibly an enumeration literal) or an
  21656. entry].
  21657.  
  21658.         1.a   Ramification:  A renaming-as-body is a declaration, as defined
  21659.         in Section 3.
  21660.  
  21661.  
  21662.                                    Syntax
  21663.  
  21664. 2   subprogram_renaming_declaration ::= subprogram_specification renames callab\
  21665. le_entity_name;
  21666.  
  21667.  
  21668.                             Name Resolution Rules
  21669.  
  21670. 3   {expected profile [subprogram_renaming_declaration]} The expected profile
  21671. for the callable_entity_name is the profile given in the subprogram_
  21672. specification.
  21673.  
  21674.  
  21675.                                Legality Rules
  21676.  
  21677. 4   The profile of a renaming-as-declaration shall be mode-conformant with
  21678. that of the renamed callable entity.  {mode conformance (required)}
  21679.  
  21680. 5   The profile of a renaming-as-body shall be subtype-conformant with that
  21681. of the renamed callable entity, and shall conform fully to that of the
  21682. declaration it completes.  {subtype conformance (required)} {full conformance
  21683. (required)} If the renaming-as-body completes that declaration before the
  21684. subprogram it declares is frozen, the subprogram it declares takes its
  21685. convention from the renamed subprogram; otherwise the convention of the
  21686. renamed subprogram shall not be Intrinsic.  {94-4774.b}
  21687.  
  21688.         5.a   Reason:  The first part of the first sentence is to allow an
  21689.         implementation of a renaming-as-body as a single jump instruction to
  21690.         the target subprogram.  Among other things, this prevents a
  21691.         subprogram from being completed with a renaming of an entry.  (In
  21692.         most cases, the target of the jump can be filled in at link time.  In
  21693.         some cases, such as a renaming of a name like "A(I).all", an indirect
  21694.         jump is needed.  Note that the name is evaluated at renaming time,
  21695.         not at call time.)
  21696.  
  21697.         5.b   The second part of the first sentence is the normal rule for
  21698.         completions of subprogram_declarations.
  21699.  
  21700.         5.c   Ramification:  An entry_declaration, unlike a subprogram_
  21701.         declaration, cannot be completed with a renaming_declaration.  Nor
  21702.         can a generic_subprogram_declaration.
  21703.  
  21704.         5.d   The syntax rules prevent a protected subprogram declaration
  21705.         from being completed by a renaming.  This is fortunate, because it
  21706.         allows us to avoid worrying about whether the implicit protected
  21707.         object parameter of a protected operation is involved in the
  21708.         conformance rules.
  21709.  
  21710. 6   A name that denotes a formal parameter of the subprogram_specification is
  21711. not allowed within the callable_entity_name.
  21712.  
  21713.         6.a   Reason:  This is to prevent things like this:
  21714.  
  21715. 6.b         function F(X : Integer) return Integer renames Table(X).all;
  21716.  
  21717.         6.c   A similar rule in 6.1 forbids things like this:
  21718.  
  21719. 6.d         function F(X : Integer; Y : Integer := X) return Integer;
  21720.  
  21721.  
  21722.                               Static Semantics
  21723.  
  21724. 7   A renaming-as-declaration declares a new view of the renamed entity.  The
  21725. profile of this new view takes its subtypes, parameter modes, and calling
  21726. convention from the original profile of the callable entity, while taking the
  21727. formal parameter names and default_expressions from the profile given in the
  21728. subprogram_renaming_declaration.  The new view is a function or procedure,
  21729. never an entry.
  21730.  
  21731.         7.a   To be honest:  When renaming an entry as a procedure, the
  21732.         compile-time rules apply as if the new view is a procedure, but the
  21733.         run-time semantics of a call are that of an entry call.
  21734.  
  21735.         7.b   Ramification:  For example, it is illegal for the entry_call_
  21736.         statement of a timed_entry_call to call the new view.  But what looks
  21737.         like a procedure call will do things like barrier waiting.
  21738.  
  21739.  
  21740.                               Dynamic Semantics
  21741.  
  21742. 8   For a call on a renaming of a dispatching subprogram that is overridden,
  21743. if the overriding occurred before the renaming, then the body executed is
  21744. that of the overriding declaration, even if the overriding declaration is not
  21745. visible at the place of the renaming; otherwise, the inherited or predefined
  21746. subprogram is called.
  21747.  
  21748.         8.a   Discussion:  Note that whether or not the renaming is itself
  21749.         primitive has nothing to do with the renamed subprogram.
  21750.  
  21751.         8.b   Note that the above rule is only for tagged types.
  21752.  
  21753.         8.c   Consider the following example:
  21754.  
  21755. 8.d         package P is
  21756.                 type T is tagged null record;
  21757.                 function Predefined_Equal(X, Y : T) return Boolean renames "=";
  21758.             private
  21759.                 function "="(X, Y : T) return Boolean; -- Override predefined "\
  21760. =".
  21761.             end P;
  21762.  
  21763. 8.e         with P; use P;
  21764.             package Q is
  21765.                 function User_Defined_Equal(X, Y : T) return Boolean renames P.\
  21766. "=";
  21767.             end Q;
  21768.  
  21769.         8.f   A call on Predefined_Equal will execute the predefined equality
  21770.         operator of T, whereas a call on User_Defined_Equal will execute the
  21771.         body of the overriding declaration in the private part of P.
  21772.  
  21773.         8.g   Thus a renaming allows one to squirrel away a copy of an
  21774.         inherited or predefined subprogram before later overriding it.
  21775.         {squirrel away (included in fairness to alligators)}
  21776.  
  21777.  
  21778.      NOTES
  21779. 9    (11) A procedure can only be renamed as a procedure.  A function whose
  21780.      defining_designator is either an identifier or an operator_symbol can be
  21781.      renamed with either an identifier or an operator_symbol; for renaming as
  21782.      an operator, the subprogram specification given in the renaming_
  21783.      declaration is subject to the rules given in 6.6 for operator
  21784.      declarations.  Enumeration literals can be renamed as functions;
  21785.      similarly, attribute_references that denote functions (such as
  21786.      references to Succ and Pred) can be renamed as functions.  An entry can
  21787.      only be renamed as a procedure; the new name is only allowed to appear
  21788.      in contexts that allow a procedure name.  An entry of a family can be
  21789.      renamed, but an entry family cannot be renamed as a whole.
  21790.  
  21791. 10   (12) The operators of the root numeric types cannot be renamed because
  21792.      the types in the profile are anonymous, so the corresponding
  21793.      specifications cannot be written; the same holds for certain attributes,
  21794.      such as Pos.  {94-4666.c}
  21795.  
  21796. 11   (13) Calls with the new name of a renamed entry are procedure_call_
  21797.      statements and are not allowed at places where the syntax requires an
  21798.      entry_call_statement in conditional_ and timed_entry_calls, nor in an
  21799.      asynchronous_select; similarly, the Count attribute is not available for
  21800.      the new name.
  21801.  
  21802. 12   (14) The primitiveness of a renaming-as-declaration is determined by its
  21803.      profile, and by where it occurs, as for any declaration of (a view of) a
  21804.      subprogram; primitiveness is not determined by the renamed view.  In
  21805.      order to perform a dispatching call, the subprogram name has to denote a
  21806.      primitive subprogram, not a non-primitive renaming of a primitive
  21807.      subprogram.
  21808.  
  21809.    12.a   Reason:  A subprogram_renaming_declaration could more properly be
  21810.         called renaming_as_subprogram_declaration, since you're renaming
  21811.         something as a subprogram, but you're not necessarily renaming a
  21812.         subprogram.  But that's too much of a mouthful.  Or, alternatively,
  21813.         we could call it a callable_entity_renaming_declaration, but that's
  21814.         even worse.  Not only is it a mouthful, it emphasizes the entity
  21815.         being renamed, rather than the new view, which we think is a bad
  21816.         idea.  We'll live with the oddity.
  21817.  
  21818.  
  21819.                                   Examples
  21820.  
  21821. 13   Examples of subprogram renaming declarations:
  21822.  
  21823. 14  procedure My_Write(C : in Character) renames Pool(K).Write; --  see 4.1.3
  21824.  
  21825. 15  function Real_Plus(Left, Right : Real   ) return Real    renames "+";
  21826.     function Int_Plus (Left, Right : Integer) return Integer renames "+";
  21827.  
  21828. 16  function Rouge return Color renames Red;  --  see 3.5.1
  21829.     function Rot   return Color renames Red;
  21830.     function Rosso return Color renames Rouge;
  21831.  
  21832. 17  function Next(X : Color) return Color renames Color'Succ; -- see 3.5.1
  21833.  
  21834. 18   Example of a subprogram renaming declaration with new parameter names:
  21835.  
  21836. 19  function "*" (X,Y : Vector) return Real renames Dot_Product; -- see 6.1
  21837.  
  21838. 20   Example of a subprogram renaming declaration with a new default
  21839. expression:
  21840.  
  21841. 21  function Minimum(L : Link := Head) return Cell renames Min_Cell; -- see 6.1
  21842.  
  21843.  
  21844.  
  21845. 8.5.5 Generic Renaming Declarations
  21846.  
  21847. 1   [A generic_renaming_declaration is used to rename a generic unit.]
  21848.  
  21849.  
  21850.                                    Syntax
  21851.  
  21852. 2   generic_renaming_declaration ::=
  21853.         generic package       defining_program_unit_name renames generic_packag\
  21854. e_name;
  21855.       | generic procedure     defining_program_unit_name renames generic_proced\
  21856. ure_name;
  21857.       | generic function      defining_program_unit_name renames generic_functi\
  21858. on_name;
  21859.  
  21860.  
  21861.                                Legality Rules
  21862.  
  21863. 3   The renamed entity shall be a generic unit of the corresponding kind.
  21864.  
  21865.  
  21866.                               Static Semantics
  21867.  
  21868. 4   A generic_renaming_declaration declares a new view [of the renamed
  21869. generic unit].
  21870.  
  21871.  
  21872.      NOTES
  21873. 5    (15) Although the properties of the new view are the same as those of
  21874.      the renamed view, the place where the generic_renaming_declaration
  21875.      occurs may affect the legality of subsequent renamings and
  21876.      instantiations that denote the generic_renaming_declaration, in
  21877.      particular if the renamed generic unit is a library unit (see 10.1.1).
  21878.  
  21879.  
  21880.                                   Examples
  21881.  
  21882. 6   Example of renaming a generic unit:
  21883.  
  21884. 7   generic package Enum_IO renames Ada.Text_IO.Enumeration_IO;  -- see A.10.10
  21885.  
  21886.  
  21887.                             Extensions to Ada 83
  21888.  
  21889.         7.a   {extensions to Ada 83} Renaming of generic units is new to Ada
  21890.         9X.  It is particularly important for renaming child library units
  21891.         that are generic units.  For example, it might be used to rename
  21892.         Numerics.Generic_Elementary_Functions as simply Generic_Elementary_
  21893.         Functions, to match the name for the corresponding Ada-83-based
  21894.         package.
  21895.  
  21896.                          Wording Changes From Ada 83
  21897.  
  21898.         7.b   The information in RM83-8.6, ``The Package Standard,'' has been
  21899.         updated for the child unit feature, and moved to Annex A, except for
  21900.         the definition of ``predefined type,'' which has been moved to 3.2.1.
  21901.  
  21902.  
  21903.  
  21904. 8.6 The Context of Overload Resolution
  21905.  
  21906. 1   [{overload resolution} Because declarations can be overloaded, it is
  21907. possible for an occurrence of a usage name to have more than one possible
  21908. interpretation; in most cases, ambiguity is disallowed.  This clause
  21909. describes how the possible interpretations resolve to the actual
  21910. interpretation.
  21911.  
  21912. 2   {overloading rules} Certain rules of the language (the Name Resolution
  21913. Rules) are considered ``overloading rules''.  If a possible interpretation
  21914. violates an overloading rule, it is assumed not to be the intended
  21915. interpretation; some other possible interpretation is assumed to be the
  21916. actual interpretation.  On the other hand, violations of non-overloading
  21917. rules do not affect which interpretation is chosen; instead, they cause the
  21918. construct to be illegal.  To be legal, there usually has to be exactly one
  21919. acceptable interpretation of a construct that is a ``complete context'', not
  21920. counting any nested complete contexts.
  21921.  
  21922. 3   {grammar (resolution of ambiguity)} The syntax rules of the language and
  21923. the visibility rules given in 8.3 determine the possible interpretations.
  21924. Most type checking rules (rules that require a particular type, or a
  21925. particular class of types, for example) are overloading rules.  Various rules
  21926. for the matching of formal and actual parameters are overloading rules.]
  21927.  
  21928.  
  21929.                          Language Design Principles
  21930.  
  21931.         3.a   The type resolution rules are intended to minimize the need for
  21932.         implicit declarations and preference rules associated with implicit
  21933.         conversion and dispatching operations.
  21934.  
  21935.                             Name Resolution Rules
  21936.  
  21937. 4   {complete context} [Overload resolution is applied separately to each
  21938. complete context, not counting inner complete contexts.]  Each of the
  21939. following constructs is a complete context:
  21940.  
  21941.     5  A context_item.
  21942.  
  21943.     6  A declarative_item or declaration.
  21944.  
  21945.  6.a    Ramification:  A loop_parameter_specification is a declaration,
  21946.         and hence a complete context.
  21947.  
  21948.     7  A statement.
  21949.  
  21950.     8  A pragma_argument_association.
  21951.  
  21952.  8.a    Reason:  We would make it the whole pragma, except that certain
  21953.         pragma arguments are allowed to be ambiguous, and ambiguity
  21954.         applies to a complete context.
  21955.  
  21956.     9  The expression of a case_statement.
  21957.  
  21958.  9.a    Ramification:  This means that the expression is resolved
  21959.         without looking at the choices.
  21960.  
  21961. 10   {interpretation (of a complete context)} {overall interpretation (of a
  21962. complete context)} An (overall) interpretation of a complete context embodies
  21963. its meaning, and includes the following information about the constituents of
  21964. the complete context, not including constituents of inner complete contexts:
  21965.  
  21966.    11  for each constituent of the complete context, to which syntactic
  21967.        categories it belongs, and by which syntax rules; and
  21968.  
  21969.  11.a   Ramification:  Syntactic categories is plural here, because
  21970.         there are lots of trivial productions -- an expression might
  21971.         also be all of the following, in this order: identifier, name,
  21972.         primary, factor, term, simple_expression, and relation.
  21973.         Basically, we're trying to capture all the information in the
  21974.         parse tree here, without using compiler-writer's jargon like
  21975.         ``parse tree''.
  21976.  
  21977.    12  for each usage name, which declaration it denotes (and,
  21978.        therefore, which view and which entity it denotes); and
  21979.  
  21980.  12.a   Ramification:  In most cases, a usage name denotes the view
  21981.         declared by the denoted declaration.  However, in certain cases,
  21982.         a usage name that denotes a declaration and appears inside the
  21983.         declarative region of that same declaration, denotes the current
  21984.         instance of the declaration.  For example, within a task_body, a
  21985.         usage name that denotes the task_type_declaration denotes the
  21986.         object containing the currently executing task, and not the task
  21987.         type declared by the declaration.
  21988.  
  21989.    13  for a complete context that is a declarative_item, whether or not
  21990.        it is a completion of a declaration, and (if so) which
  21991.        declaration it completes.
  21992.  
  21993.         13.a   Ramification:  Unfortunately, we are not confident that the
  21994.         above list is complete.  We'll have to live with that.
  21995.  
  21996.         13.b   To be honest:  For ``possible'' interpretations, the above
  21997.         information is tentative.
  21998.  
  21999.         13.c   Discussion:  A possible interpretation (an input to overload
  22000.         resolution) contains information about what a usage name might
  22001.         denote, but what it actually does denote requires overload resolution
  22002.         to determine.  Hence the term ``tentative'' is needed for possible
  22003.         interpretations; otherwise, the definition would be circular.
  22004.  
  22005. 14   {possible interpretation} A possible interpretation is one that obeys
  22006. the syntax rules and the visibility rules.  {acceptable interpretation}
  22007. {resolve (overload resolution)} {interpretation (overload resolution)} An
  22008. acceptable interpretation is a possible interpretation that obeys the
  22009. overloading rules[, that is, those rules that specify an expected type or
  22010. expected profile, or specify how a construct shall resolve or be
  22011. interpreted.]
  22012.  
  22013.         14.a   To be honest:  One rule that falls into this category, but
  22014.         does not use the above-mentioned magic words, is the rule about
  22015.         numbers of parameter associations in a call (see 6.4).
  22016.  
  22017.         14.b   Ramification:  The Name Resolution Rules are the ones that
  22018.         appear under the Name Resolution Rules heading.  Some Syntax Rules
  22019.         are written in English, instead of BNF.  No rule is a Syntax Rule or
  22020.         Name Resolution Rule unless it appears under the appropriate heading.
  22021.  
  22022. 15   {interpretation (of a constituent of a complete context)} The
  22023. interpretation of a constituent of a complete context is determined from the
  22024. overall interpretation of the complete context as a whole.  [Thus, for
  22025. example, ``interpreted as a function_call,'' means that the construct's
  22026. interpretation says that it belongs to the syntactic category function_call.]
  22027.  
  22028. 16   {denote} [Each occurrence of] a usage name denotes the declaration
  22029. determined by its interpretation.  It also denotes the view declared by its
  22030. denoted declaration, except in the following cases:
  22031.  
  22032.         16.a   Ramification:  As explained below, a pragma argument is
  22033.         allowed to be ambiguous, so it can denote several declarations, and
  22034.         all of the views declared by those declarations.
  22035.  
  22036.    17  {current instance (of a type)} If a usage name appears within the
  22037.        declarative region of a type_declaration and denotes that same
  22038.        type_declaration, then it denotes the current instance of the
  22039.        type (rather than the type itself).  The current instance of a
  22040.        type is the object or value of the type that is associated with
  22041.        the execution that evaluates the usage name.
  22042.  
  22043.  17.a   Reason:  This is needed, for example, for references to the
  22044.         Access attribute from within the type_declaration.  Also, within
  22045.         a task_body or protected_body, we need to be able to denote the
  22046.         current task or protected object.  (For a single_task_
  22047.         declaration or single_protected_declaration, the rule about
  22048.         current instances is not needed.)
  22049.  
  22050.    18  {current instance (of a generic unit)} If a usage name appears
  22051.        within the declarative region of a generic_declaration (but not
  22052.        within its generic_formal_part) and it denotes that same generic_
  22053.        declaration, then it denotes the current instance of the generic
  22054.        unit (rather than the generic unit itself).  See also 12.3.
  22055.  
  22056.  18.a   To be honest:  The current instance of a generic unit is the
  22057.         instance created by whichever generic_instantiation is of
  22058.         interest at any given time.
  22059.  
  22060.  18.b   Ramification:  Within a generic_formal_part, a name that denotes
  22061.         the generic_declaration denotes the generic unit, which implies
  22062.         that it is not overloadable.
  22063.  
  22064. 19   A usage name that denotes a view also denotes the entity of that view.
  22065.  
  22066.         19.a   Ramification:  Usually, a usage name denotes only one
  22067.         declaration, and therefore one view and one entity.
  22068.  
  22069. 20   {expected type [distributed]} The expected type for a given expression,
  22070. name, or other construct determines, according to the type resolution rules
  22071. given below, the types considered for the construct during overload
  22072. resolution.  {type resolution rules} [The type resolution rules provide
  22073. support for class-wide programming, universal numeric literals, dispatching
  22074. operations, and anonymous access types:]
  22075.  
  22076.         20.a   Ramification:  Expected types are defined throughout the RM9X.
  22077.         The most important definition is that, for a subprogram, the expected
  22078.         type for the actual parameter is the type of the formal parameter.
  22079.  
  22080.         20.b   The type resolution rules are trivial unless either the actual
  22081.         or expected type is universal, class-wide, or of an anonymous access
  22082.         type.
  22083.  
  22084.    21  {type resolution rules [if any type in a specified class of types
  22085.        is expected]} {type resolution rules [if expected type is
  22086.        universal or class-wide]} If a construct is expected to be of any
  22087.        type in a class of types, or of the universal or class-wide type
  22088.        for a class, then the type of the construct shall resolve to a
  22089.        type in that class or to a universal type that covers the class.
  22090.  
  22091.  21.a   Ramification:  This matching rule handles (among other things)
  22092.         cases like the Val attribute, which denotes a function that
  22093.         takes a parameter of type universal_integer.
  22094.  
  22095.  21.b   The last part of the rule, ``or to a universal type that
  22096.         includes the class'' implies that if the expected type for an
  22097.         expression is universal_fixed, then an expression whose type is
  22098.         universal_real (such as a real literal) is OK.
  22099.  
  22100.    22  {type resolution rules [if expected type is specific]} If the
  22101.        expected type for a construct is a specific type T, then the type
  22102.        of the construct shall resolve either to T, or:
  22103.  
  22104.  22.a   Ramification:  {Beaujolais effect [partial]} This rule is not
  22105.         intended to create a preference for the specific type -- such a
  22106.         preference would cause Beaujolais effects.
  22107.  
  22108.           23  to T'Class; or
  22109.  
  22110.  23.a   Ramification:  This will only be legal as part of a call on a
  22111.         dispatching operation; see 3.9.2, ``Dispatching Operations of
  22112.         Tagged Types''.  Note that that rule is not a Name Resolution
  22113.         Rule.
  22114.  
  22115.           24  to a universal type that covers T; or
  22116.  
  22117.           25  when T is an anonymous access type (see 3.10) with
  22118.               designated type D, to an access-to-variable type whose
  22119.               designated type is D'Class or is covered by D.
  22120.  
  22121.  25.a   Ramification:  Because it says ``access-to-variable'' instead of
  22122.         ``access-to-object,'' two subprograms that differ only in that
  22123.         one has a parameter of an access-to-constant type, and the other
  22124.         has an access parameter, are distinguishable during overload
  22125.         resolution.
  22126.  
  22127.  25.b   The case where the actual is access-to-D'Class will only be
  22128.         legal as part of a call on a dispatching operation; see 3.9.2,
  22129.         ``Dispatching Operations of Tagged Types''.  Note that that rule
  22130.         is not a Name Resolution Rule.
  22131.  
  22132. 26   {expected profile [distributed]} In certain contexts, [such as in a
  22133. subprogram_renaming_declaration,] the Name Resolution Rules define an
  22134. expected profile for a given name; {profile resolution rule (name with a
  22135. given expected profile)} in such cases, the name shall resolve to the name of
  22136. a callable entity whose profile is type conformant with the expected profile.
  22137. {type conformance (required)}
  22138.  
  22139.         26.a   Ramification:  The parameter and result subtypes are not used
  22140.         in overload resolution.  Only type conformance of profiles is
  22141.         considered during overload resolution.  Legality rules generally
  22142.         require at least mode-conformance in addition, but those rules are
  22143.         not used in overload resolution.
  22144.  
  22145.  
  22146.                                Legality Rules
  22147.  
  22148. 27   {single (class expected type)} When the expected type for a construct is
  22149. required to be a single type in a given class, the type expected for the
  22150. construct shall be determinable solely from the context in which the
  22151. construct appears, excluding the construct itself, but using the requirement
  22152. that it be in the given class; the type of the construct is then this single
  22153. expected type.  Furthermore, the context shall not be one that expects any
  22154. type in some class that contains types of the given class; in particular, the
  22155. construct shall not be the operand of a type_conversion.
  22156.  
  22157.         27.a   Ramification:  For example, the expected type for the literal
  22158.         null is required to be a single access type.  But the expected type
  22159.         for the operand of a type_conversion is any type.  Therefore, the
  22160.         literal null is not allowed as the operand of a type_conversion.
  22161.         This is true even if there is only one access type in scope.  The
  22162.         reason for these rules is so that the compiler will not have to
  22163.         search ``everywhere'' to see if there is exactly one type in a class
  22164.         in scope.
  22165.  
  22166. 28   A complete context shall have at least one acceptable interpretation; if
  22167. there is exactly one, then that one is chosen.
  22168.  
  22169.         28.a   Ramification:  This, and the rule below about ambiguity, are
  22170.         the ones that suck in all the Syntax Rules and Name Resolution Rules
  22171.         as compile-time rules.  Note that this and the ambiguity rule have to
  22172.         be Legality Rules.
  22173.  
  22174. 29   {preference (for root numeric operators and ranges)} There is a
  22175. preference for the primitive operators (and ranges) of the root numeric types
  22176. root_integer and root_real.  In particular, if two acceptable interpretations
  22177. of a constituent of a complete context differ only in that one is for a
  22178. primitive operator (or range) of the type root_integer or root_real, and the
  22179. other is not, the interpretation using the primitive operator (or range) of
  22180. the root numeric type is preferred.
  22181.  
  22182.         29.a   Reason:  The reason for this preference is so that