Debian Codegraph @

source_2005/03a.mss

raw
1 @Part(03, Root="ada.mss")
2
3 @Comment{$Date: 2006/10/17 05:29:41 $}
4 @LabeledSection{Declarations and Types}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/03a.mss,v $}
7 @Comment{$Revision: 1.83 $}
8
9 @begin{Intro}
10 This section describes the types in the language and the rules
11 for declaring constants, variables, and named numbers.
12 @end{Intro}
13
14 @LabeledClause{Declarations}
15
16 @begin{Intro}
17 @PDefn{entity}
18 The language defines
19 several kinds of named @i(entities) that are declared
20 by declarations.
21 @PDefn{name}
22 The entity's @i(name)
23 is defined by the declaration, usually by a
24 @nt<defining_@!identifier>,
25 but sometimes by a @nt{defining_@!character_@!literal}
26 or @nt{defining_@!operator_@!symbol}.
27
28 There are several forms of declaration. A @nt<basic_declaration>
29 is a form of declaration defined as follows.
30 @end{Intro}
31
32 @begin{Syntax}
33 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]}
34 @Syn{tabs=[P27], lhs=<basic_declaration>,rhs="
35 @Syn2{type_declaration}@\| @Syn2{subtype_declaration}
36 | @Syn2{object_declaration}@\| @Syn2{number_declaration}
37 | @Syn2{subprogram_declaration}@\| @Syn2{abstract_subprogram_declaration}
38 | @Chg{Version=[2],New=[@Syn2{null_procedure_declaration}@\| ],Old=[]}@Syn2{package_declaration}@Chg{Version=[2],New=[
39 |],Old=[@\|]} @Syn2{renaming_declaration}@Chg{Version=[2],New=[@\|],Old=[
40 |]} @Syn2{exception_declaration}@Chg{Version=[2],New=[
41 |],Old=[@\|]} @Syn2{generic_declaration}@Chg{Version=[2],New=[@\|],Old=[
42 |]} @Syn2{generic_instantiation}"}
43
44
45 @Syn{lhs=<defining_identifier>,rhs="@Syn2{identifier}"}
46 @end{Syntax}
47
48 @begin{StaticSem}
49 @ToGlossaryAlso{Term=<Declaration>,
50 Text=<A @i(declaration) is a language construct that associates a name
51 with (a view of) an entity.
52 @Defn(explicit declaration)
53 @Defn(implicit declaration)
54 A declaration may appear explicitly in the program
55 text (an @i(explicit) declaration), or may be supposed to
56 occur at a given place in the text as a
57 consequence of the semantics of another construct (an @i(implicit)
58 declaration).>}
59 @begin{Discussion}
60 An implicit declaration generally declares
61 a predefined or inherited operation associated with the definition
62 of a type. This term is
63 used primarily when allowing explicit declarations to override
64 implicit declarations, as part of a type declaration.
65 @end{Discussion}
66
67 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
68 @Defn{declaration}
69 Each of the following is defined to be a declaration:
70 any @nt{basic_@!declaration};
71 an @nt{enumeration_@!literal_@!specification};
72 a @nt{discriminant_@!specification};
73 a @nt{component_@!declaration};
74 a @nt{loop_@!parameter_@!specification};
75 a @nt{parameter_@!specification};
76 a @nt{subprogram_@!body};
77 an @nt{entry_@!declaration};
78 an @nt{entry_@!index_@!specification};
79 a @nt{choice_@!parameter_@!specification};
80 a @nt{generic_@!formal_@!parameter_@!declaration}.@Chg{Version=[2],New=[
81 In addition, an @nt{extended_return_statement} is a declaration of its
82 @nt{defining_identifier}.],Old=[]}
83 @begin(Discussion)
84 This list (when @nt<basic_declaration> is expanded out)
85 contains all syntactic categories that end in "_declaration"
86 or "_specification", except for program unit _specifications.
87 Moreover, it contains @nt{subprogram_body}.
88 A @nt{subprogram_body} is a declaration,
89 whether or not it completes a previous declaration.
90 This is a bit strange, @nt{subprogram_body} is not part of the syntax
91 of @nt{basic_declaration} or @nt{library_unit_declaration}.
92 A renaming-as-body is considered a declaration.
93 An @nt{accept_statement} is not considered a declaration.
94 Completions are sometimes declarations, and sometimes not.
95 @end(Discussion)
96
97 @Defn(view)@Defn(definition)
98 All declarations contain a @i(definition) for a @i(view) of an entity.
99 A view consists of an identification of the entity
100 (the entity @i(of) the view),
101 plus view-specific characteristics that affect the use
102 of the entity through that view (such as mode of access to an object,
103 formal parameter names and defaults for a subprogram, or visibility to
104 components of a type).
105 In most cases, a declaration also contains the definition for the
106 entity itself (a @nt(renaming_declaration) is an example of a declaration
107 that does not define a new entity,
108 but instead defines a view of an existing entity
109 (see @RefSecNum(Renaming Declarations))).
110
111 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<View>,
112 Text=<@Chg{Version=[2],New=[A view of an entity reveals some or all of the
113 properties of the entity. A single entity may have multiple views.],
114 Old=[(See @b[Definition].)]}>}
115 @begin{Discussion}
116 Most declarations define a view (of some entity) whose
117 view-specific characteristics are unchanging for the
118 life of the view. However, subtypes are somewhat unusual
119 in that they inherit characteristics from whatever view
120 of their type is currently visible. Hence, a subtype is not a
121 @i(view) of a type; it is more of an indirect reference.
122 By contrast, a private type provides a single, unchanging (partial)
123 view of its full type.
124 @end{Discussion}
125
126 @ChgToGlossary{Version=[2],Kind=[Deleted],Term=<Definition>,
127 Text=<@ChgDeleted{Version=[2],Text=[@Defn(view)
128 All declarations contain a @i(definition) for a @i(view) of an entity.
129 A view consists of an identification of the entity
130 (the entity @i(of) the view),
131 plus view-specific characteristics that affect the use
132 of the entity through that view (such as mode of access to an object,
133 formal parameter names and defaults for a subprogram, or visibility to
134 components of a type).
135 In most cases, a declaration also contains the definition for the
136 entity itself (a @nt(renaming_declaration) is an example of a declaration
137 that does not define a new entity,
138 but instead defines a view of an existing entity
139 (see @RefSecNum(Renaming Declarations))).]}>}
140
141 @PDefn2{Term=[scope], Sec=(informal definition)}
142 For each declaration, the language rules define a certain
143 region of text called the @i(scope) of the declaration
144 (see @RefSecNum(Scope of Declarations)). Most declarations
145 associate an @nt<identifier>
146 with a declared entity. Within its scope,
147 and only there, there are places where it is possible to use the
148 @nt<identifier> to refer to the declaration, the view it defines,
149 and the associated entity; these places are defined by
150 the visibility rules (see @RefSecNum(Visibility)).
151 @Defn2{Term=[name], Sec={of (a view of) an entity}}
152 At such places
153 the @nt<identifier> is said to be a @i(name) of the entity (the
154 @nt<direct_name> or @nt<selector_name>);
155 @PDefn2{Term=[denote], Sec={informal definition}}
156 the name is said to @i(denote) the declaration,
157 the view, and the associated entity
158 (see @RefSecNum{The Context of Overload Resolution}).
159 @Defn{declare}
160 The declaration is said
161 to @i(declare) the name, the view, and in most cases, the
162 entity itself.
163
164 As an alternative to an @nt<identifier>,
165 an enumeration literal can be declared with a @nt<character_literal>
166 as its name (see @RefSecNum(Enumeration Types)),
167 and a function can be declared with an @nt<operator_symbol>
168 as its name (see @RefSecNum(Subprogram Declarations)).
169
170 @Defn{defining name}
171 The syntax rules use the terms @nt<defining_identifier>,
172 @nt<defining_@!character_@!literal>, and @nt<defining_@!operator_@!symbol>
173 for the defining occurrence of a name; these are collectively
174 called @i(defining names).
175 @Defn{usage name}
176 The terms @nt<direct_name> and
177 @nt<selector_name> are used for usage occurrences of @nt<identifier>s,
178 @nt<character_literal>s, and @nt<operator_symbol>s. These
179 are collectively called @i(usage names).
180 @begin(Honest)
181 The terms @nt<identifier>,
182 @nt<character_literal>, and @nt<operator_symbol> are used directly
183 in contexts where the normal visibility rules do not
184 apply (such as the @nt<identifier> that appears after the @key(end) of
185 a @nt<task_body>). Analogous conventions apply to the use of @nt<designator>,
186 which is the collective term for @nt<identifier> and @nt<operator_symbol>.
187 @end(Honest)
188
189 @end{StaticSem}
190
191 @begin{RunTime}
192 @RootDefn{execution}
193 The process by which a construct achieves its run-time effect is
194 called @i(execution).
195 @RootDefn{elaboration}
196 @RootDefn{evaluation}
197 This process is also called @i(elaboration) for declarations
198 and @i(evaluation) for expressions.
199 One of the terms execution, elaboration, or evaluation is defined
200 by this International Standard for each construct that has a run-time effect.
201 @ToGlossary{Term=<Execution>,
202 Text=<The process by which a construct achieves its run-time effect is
203 called @i(execution).
204 @Defn(elaboration)
205 @Defn(evaluation)
206 Execution of a declaration is also called @i(elaboration).
207 Execution of an expression is also called @i(evaluation).>}
208 @begin{Honest}
209 The term elaboration is also used for the execution of certain
210 constructs that are not declarations,
211 and the term evaluation is used for the execution of certain
212 constructs that are not expressions.
213 For example, @nt{subtype_indication}s are elaborated,
214 and @nt{range}s are evaluated.
215
216 For bodies, execution and elaboration are both explicitly defined.
217 When we refer specifically to the execution of a body,
218 we mean the explicit definition of execution for that kind of body,
219 not its elaboration.
220 @end{Honest}
221 @begin(Discussion)
222 Technically, "the execution of a declaration" and "the
223 elaboration of a declaration" are synonymous.
224 We use the term "elaboration" of a construct when we know the
225 construct is elaborable.
226 When we are talking about more arbitrary constructs,
227 we use the term "execution".
228 For example, we use the term "erroneous execution",
229 to refer to any erroneous execution, including
230 erroneous elaboration or evaluation.
231
232 When we explicitly define evaluation or elaboration for a construct,
233 we are implicitly defining execution of that construct.
234
235 We also use the term "execution" for things like @nt{statement}s,
236 which are executable, but neither elaborable nor evaluable.
237 We considered using the term "execution" only for non-elaborable,
238 non-evaluable constructs, and defining the term "action" to mean what
239 we have defined "execution" to mean.
240 We rejected this idea because we thought three terms that mean the
241 same thing was enough @em four would be overkill.
242 Thus, the term "action" is used only informally in the standard
243 (except where it is defined as part of a larger term,
244 such as "protected action").
245 @end(Discussion)
246 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Elaboration>,
247 Text=<@ChgAdded{Version=[2],Text=[The process by which a declaration achieves
248 its run-time effect is called elaboration. Elaboration is one of the forms of
249 execution.]}>}
250 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Evaluation>,
251 Text=<@ChgAdded{Version=[2],Text=[The process by which an expression achieves
252 its run-time effect is called evaluation. Evaluation is one of the forms of
253 execution.]}>}
254 @begin{Honest}
255 @Defn{elaborable}
256 A construct is @i(elaborable) if elaboration is defined for it.
257 @Defn{evaluable}
258 A construct is @i(evaluable) if evaluation is defined for it.
259 @Defn{executable}
260 A construct is @i(executable) if execution is defined for it.
261 @end{Honest}
262 @begin(Discussion)
263 Don't confuse @lquotes@;elaborable@rquotes@; with @lquotes@;preelaborable@rquotes@; (defined
264 in @RefSecNum(Elaboration Control)).
265
266 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
267 Evaluation of an evaluable construct produces a result that is
268 either a value, a denotation, or a range.
269 The following are evaluable:
270 expression; @nt{name}
271 @nt{prefix}; @nt{range};
272 @Chg{Version=[2],New=[@nt{entry_index_specification}],Old=[@ntf{entry_list_iterator}]};
273 and possibly @nt{discrete_range}.
274 The last one is curious @em RM83 uses the term @lquotes@;evaluation of a
275 @nt{discrete_range},@rquotes@; but never defines it.
276 One might presume that the evaluation of a @nt{discrete_range}
277 consists of the evaluation of the @nt{range} or the
278 @nt{subtype_indication}, depending on what it is.
279 But @nt{subtype_indication}s are not evaluated; they are elaborated.
280
281 Intuitively, an @i(executable) construct is one that has
282 a defined run-time effect (which may be null). Since execution
283 includes elaboration and evaluation as special cases, all
284 elaborable and all evaluable constructs
285 are also executable. Hence, most constructs in Ada are executable.
286 An important exception is that the constructs inside a generic unit are
287 not executable directly, but rather are used as a template for
288 (generally) executable constructs in instances of the generic.
289 @end(Discussion)
290 @end{RunTime}
291
292 @begin{Notes}
293 @Defn{declare}
294 At compile time, the declaration of an entity @i(declares) the entity.
295 @Defn{create}
296 At run time, the elaboration of the declaration @i(creates) the entity.
297 @begin{Ramification}
298 Syntactic categories for declarations are named either
299 @i(entity_)@ntf<declaration> (if they include a trailing semicolon)
300 or @i(entity_)@ntf<specification> (if not).
301
302 @Defn{entity}
303 The various kinds of named entities that can be declared are as
304 follows: an object (including components and parameters), a named number,
305 a type (the name always refers to its first subtype), a subtype,
306 a subprogram (including enumeration literals and operators), a single entry,
307 an entry family, a package, a protected or task unit (which corresponds
308 to either a type or a single object), an exception,
309 a generic unit, a label,
310 and the name of a statement.
311
312 Identifiers are also associated with names of pragmas, arguments to
313 pragmas, and with attributes, but these are not user-definable.
314 @end{Ramification}
315 @end{Notes}
316
317 @begin{DiffWord83}
318 The syntax rule for @nt{defining_identifier} is new.
319 It is used for the defining occurrence of an @nt{identifier}.
320 Usage occurrences use the @nt{direct_name} or @nt{selector_name}
321 syntactic categories.
322 @Leading@;Each occurrence of an @nt{identifier} (or @ntf{simple_name}), @nt{character_literal}, or
323 @nt{operator_symbol} in the Ada 83 syntax rules is handled as follows in Ada
324 95:
325 @begin{itemize}
326 It becomes a @nt{defining_identifier}, @nt{defining_character_literal}, or
327 @nt{defining_operator_symbol} (or some syntactic category composed of these),
328 to indicate a defining occurrence;
329
330 It becomes a @nt{direct_name}, in usage occurrences where
331 the usage is required (in Section 8) to be directly visible;
332
333 It becomes a @nt{selector_name}, in usage occurrences
334 where the usage is required (in
335 Section 8) to be visible but not
336 necessarily directly visible;
337
338 It remains an @nt{identifier}, @nt{character_literal}, or @nt{operator_symbol},
339 in cases where the visibility rules do not apply
340 (such as the @nt{designator} that appears after the
341 @key{end} of a @nt{subprogram_body}).
342 @end{itemize}
343
344 For declarations that come in @lquotes@;two parts@rquotes@;
345 (program unit declaration plus body, private or
346 incomplete type plus full type, deferred constant plus full constant),
347 we consider both to be defining occurrences.
348 Thus, for example, the syntax for @nt{package_body} uses
349 @nt{defining_identifier} after the reserved word @key{body},
350 as opposed to @nt{direct_name}.
351
352 The defining occurrence of a statement name is in
353 its implicit declaration, not where it appears in the program text.
354 Considering the statement name itself to be the defining occurrence would
355 complicate the visibility rules.
356
357 The phrase @lquotes@;visible by selection@rquotes@;
358 is not used in Ada 95. It is subsumed by simply @lquotes@;visible@rquotes@; and
359 the Name Resolution Rules for @nt<selector_name>s.
360
361 (Note that in Ada 95, a declaration is visible at all
362 places where one could have used a @nt{selector_name},
363 not just at places where a @nt{selector_name} was actually used.
364 Thus, the places where a declaration is directly visible are a
365 subset of the places where it is visible.
366 See Section 8 for details.)
367
368 We use the term @lquotes@;declaration@rquotes@; to cover @ntf<_specification>s that declare
369 (views of) objects, such as @nt<parameter_specification>s. In Ada 83,
370 these are referred to as a @lquotes@;form of declaration,@rquotes@; but it is not
371 entirely clear that they are considered simply @lquotes@;declarations.@rquotes@;
372
373 RM83 contains an incomplete definition of "elaborated" in this clause:
374 it defines "elaborated" for declarations,
375 @nt{declarative_part}s, @nt{declarative_item}s
376 and @nt{compilation_unit}s,
377 but "elaboration" is defined elsewhere for various other constructs.
378 To make matters worse, Ada 95 has a different set of elaborable
379 constructs.
380 Instead of correcting the list, it is more maintainable to
381 refer to the term "elaborable," which is defined in a distributed
382 manner.
383
384 RM83 uses the term @lquotes@;has no other effect@rquotes@; to describe an elaboration that
385 doesn't do anything except change the state from not-yet-elaborated to
386 elaborated. This was a confusing wording, because the answer to @lquotes@;other than
387 what?@rquotes@; was to be found many pages away.
388 In Ada 95, we change this wording to @lquotes@;has no effect@rquotes@; (for things that truly
389 do nothing at run time), and @lquotes@;has no effect other than to establish that
390 so-and-so can happen without failing the
391 Elaboration_Check@rquotes@; (for things where it matters).
392
393 We make it clearer that the term "execution" covers elaboration and
394 evaluation as special cases.
395 This was implied in RM83.
396 For example, "erroneous execution" can include any execution,
397 and RM83-9.4(3) has,
398 "The task designated by any other task object depends on the master
399 whose execution creates the task object;"
400 the elaboration of the master's @nt{declarative_part} is doing
401 the task creation.
402 @end{DiffWord83}
403
404 @begin{DiffWord95}
405 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
406 @ChgAdded{Version=[2],Text=[Added @nt{extended_return_statement} to
407 the list of declarations.]}
408
409 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]}
410 @ChgAdded{Version=[2],Text=[Added null procedures
411 (see @RefSecNum{Null Procedures}) to the syntax.]}
412 @end{DiffWord95}
413
414
415 @LabeledClause{Types and Subtypes}
416
417 @begin{StaticSem}
418 @Defn{type}
419 @PDefn{primitive operation}
420 A @i(type) is characterized by a set of values,
421 and a set of @i(primitive operations)
422 which implement the fundamental aspects of its semantics.
423 @PDefn{object}
424 An @i(object) of a given type is a run-time entity that contains (has)
425 a value of the type.
426 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Type>,
427 Text=<Each object has a type.
428 A @i(type) has an associated set of values, and a set of @i(primitive
429 operations) which implement the fundamental aspects of its semantics.
430 Types are grouped into @Chg{Version=[2],New=[@i(categories)],
431 Old=[@i(classes)]}.
432 @Chg{Version=[2],New=[Most language-defined
433 categories of types are also @i<classes> of types],Old=[The types of a
434 given class share a set of primitive operations.
435 @Defn(closed under derivation) Classes are closed under derivation;
436 that is, if a type is in a class, then all of its derivatives
437 are in that class]}.>}
438 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Subtype>,
439 Text=<A subtype is a type together with a constraint@Chg{Version=[2],
440 New=[ or null exclusion],Old=[]},
441 which constrains the values of the subtype to satisfy a certain
442 condition.
443 The values of a subtype are a subset of the values of its type.>}
444
445 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
446 @Chg{Version=[2],New=[@Defn2{Term=[category], Sec=(of types)}],
447 Old=[]}@Defn2{Term=[class], Sec=(of types)}
448 Types are grouped into @Chg{Version=[2],New=[@i(categories)],
449 Old=[@i(classes)]} of types@Chg{Version=[2],New=[],Old=[, reflecting the
450 similarity of their values and primitive operations]}.
451 @Defn2{Term=[language-defined class], Sec=(of types)}
452 There exist several @i(language-defined @Chg{Version=[2],New=[categories],
453 Old=[classes]}) of types (see NOTES below)@Chg{Version=[2],New=[, reflecting
454 the similarity of their values and primitive operations],Old=[]}.@Chg{Version=[2],
455 New=[@Defn2{Term=[language-defined category], Sec=(of types)} @Redundant[Most
456 categories of types form @i(classes) of types.]],Old=[]}
457 @Defn{elementary type}
458 @i(Elementary) types are those whose values are logically indivisible;
459 @Defn{composite type}
460 @Defn{component}
461 @i(composite) types are those whose values are composed
462 of @i(component) values.
463 @IndexSeeAlso{Term={aggregate},See=(composite type)}
464 @begin{TheProof}
465 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
466 @ChgAdded{Version=[2],Text=[The formal definition of @i<category> and
467 @i<class> is found in @RefSecNum{Derived Types and Classes}.]}
468 @end{TheProof}
469 @ChgNote<The following ought to have the Term be:
470 Class@Chg{Version=[2],New=[ (of types)],Old=[]}
471 but that doesn't index properly and it is too much work to fix. See if
472 anyone complains.>
473 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Class (of types)>,
474 Text=<@Defn(closed under derivation)
475 A class is a set of types that is
476 closed under derivation,
477 which means that if a given type is in the class,
478 then all types derived from that type are also in the class.
479 The set of types of a class share common properties,
480 such as their primitive operations.>}
481 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Category (of types)>,
482 Text=<@ChgAdded{Version=[2],Text=[A category of types is a set of types with
483 one or more common properties, such as primitive operations. A
484 category of types that is closed under derivation is also known as
485 a @i<class>.]}>}
486 @ToGlossary{Term=<Elementary type>,
487 Text=<An elementary type does not have components.>}
488 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Composite type>,
489 Text=<A composite type @Chg{Version=[2],New=[may have],Old=[has]} components.>}
490 @ToGlossary{Term=<Scalar type>,
491 Text=<A scalar type is either a discrete type or a real type.>}
492 @ToGlossary{Term=<Access type>,
493 Text=<An access type has values that designate aliased
494 objects.
495 Access types correspond to @lquotes@;pointer types@rquotes@;
496 or @lquotes@;reference types@rquotes@; in some other languages.>}
497 @ToGlossary{Term=<Discrete type>,
498 Text=<A discrete type is either an integer type or an enumeration
499 type.
500 Discrete types may be used, for example, in @nt(case_statement)s
501 and as array indices.>}
502 @ToGlossary{Term=<Real type>,
503 Text=<A real type has values that are approximations
504 of the real numbers.
505 Floating point and fixed point types are real types.>}
506 @ToGlossary{Term=<Integer type>,
507 Text=<Integer types comprise the signed integer types
508 and the modular types.
509 A signed integer type has a base range that includes both
510 positive and negative numbers,
511 and has operations that may raise an exception when the result
512 is outside the base range.
513 A modular type has a base range whose lower bound is zero,
514 and has operations with @lquotes@;wraparound@rquotes@; semantics.
515 Modular types subsume what are called @lquotes@;unsigned types@rquotes@;
516 in some other languages.>}
517 @ToGlossary{Term=<Enumeration type>,
518 Text=<An enumeration type is defined by an enumeration of its values,
519 which may be named by identifiers or character
520 literals.>}
521 @ToGlossary{Term=<Character type>,
522 Text=<A character type is an enumeration type whose values
523 include characters.>}
524 @ToGlossary{Term=<Record type>,
525 Text=<A record type is a composite type consisting of zero or more
526 named components, possibly of different types.>}
527 @ToGlossary{Term=<Record extension>,
528 Text=<A record extension is a type that extends another type by adding
529 additional components.>}
530 @ToGlossary{Term=<Array type>,
531 Text=<An array type is a composite type whose components are all of
532 the same type. Components are selected by indexing.>}
533 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Task type>,
534 Text=<A task type is a composite type @Chg{Version=[2],New=[used to
535 represent], Old=[whose values are tasks, which are]} active entities
536 @Chg{Version=[2],New=[which],Old=[that may]} execute concurrently
537 @Chg{Version=[2],New=[and which can communicate via queued task entries],
538 Old=[with other tasks]}.
539 The top-level task of a partition is called the environment task.>}
540 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Protected type>,
541 Text=<A protected type is a composite type whose components are
542 @Chg{Version=[2],New=[accessible only
543 through one of its protected operations which synchronize],
544 Old=[protected from]} concurrent access by multiple tasks.>}
545 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Private type>,
546 Text=<A private type @Chg{Version=[2],New=[gives a],Old=[is a partial]} view
547 of a type @Chg{Version=[2],New=[that reveals only some of its properties.
548 The remaining properties are provided by the],Old=[whose]} full view
549 @Chg{Version=[2],New=[given elsewhere. Private types can be used for
550 defining abstractions that hide unnecessary details],Old=[is hidden]} from
551 @Chg{Version=[2],New=[their],Old=[its]} clients.>}@ChgNote{This was changed
552 to parallel "incomplete type"}
553 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Private extension>,
554 Text=<A private extension is @Chg{Version=[2],New=[a type that extends
555 another type, with the additional properties],Old=[like a record extension,
556 except that the components of the extension part
557 are]} hidden from its clients.>}
558
559 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Incomplete type>,
560 Text=<@ChgAdded{Version=[2],Text=[An incomplete type gives a view of a type
561 that reveals only some of its properties. The remaining properties are
562 provided by the full view given elsewhere. Incomplete types can be used
563 for defining recursive data structures.]}>}
564
565 @Defn{scalar type}
566 The elementary types are the @i(scalar) types (@i(discrete) and @i(real))
567 and the @i(access) types (whose values provide access to objects or
568 subprograms).
569 @Defn{discrete type}
570 @Defn{enumeration type}
571 Discrete types are either @i(integer) types or are defined by enumeration
572 of their values (@i(enumeration) types).
573 @Defn{real type}
574 Real types are either @i(floating point) types
575 or @i(fixed point) types.
576
577 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00326-01]}
578 The composite types are the @i(record) types, @i(record extensions),
579 @i(array) types, @Chg{Version=[2],New=[@i(interface) types, ],Old=[]}@i(task)
580 types, and @i(protected) types.@Chg{Version=[2], New=[],
581 Old=[@Defn{private type}
582 @Defn{private extension}
583 A @i(private) type or @i(private extension) represents a partial view
584 (see @RefSecNum{Private Types and Private Extensions})
585 of a type, providing support for data abstraction.
586 A partial view is a composite type.]}
587 @begin{Honest}
588 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00442-01]}
589 @ChgDeleted{Version=[2],Text=[The set of all record types do not form a
590 class (because tagged record types can have private extensions), though
591 the set of untagged record types do.
592 In any case, what record types had in common in Ada 83 (component selection)
593 is now a property of the composite class, since all composite types
594 (other than array types) can have discriminants.
595 Similarly, the set of all private types do not form a class (because
596 tagged private types can have record extensions), though
597 the set of untagged private types do.
598 Nevertheless, the set of untagged private types is not particularly
599 @lquotes@;interesting@rquotes@; @em more interesting is the set of
600 all nonlimited
601 types, since that is what a generic formal (nonlimited) private
602 type matches.]}
603 @end{Honest}
604
605 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00326-01]}
606 @ChgAdded{Version=[2],Text=[@Defn{incomplete type}
607 @Defn{private type}
608 @Defn{private extension}
609 There can be multiple views of a type with varying
610 sets of operations. @Redundant[An @i(incomplete) type represents an incomplete
611 view (see @RefSecNum{Incomplete Type Declarations}) of a type with a
612 very restricted usage, providing support for recursive data structures. A
613 @i(private) type or @i(private extension) represents a partial view
614 (see @RefSecNum{Private Types and Private Extensions}) of a
615 type, providing support for data abstraction. The full view
616 (see @RefSecNum{Type Declarations}) of a
617 type represents its complete definition.] An incomplete or partial view is
618 considered a composite type@Redundant[, even if the full view is not].]}
619 @begin{TheProof}
620 @ChgRef{Version=[2],Kind=[AddedNormal]}
621 @ChgAdded{Version=[2],Text=[The real definitions of the views are in the
622 referenced clauses.]}
623 @end{TheProof}
624
625 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00326-01]}
626 @Defn{discriminant}
627 Certain composite types (and@Chg{Version=[2],New=[],Old=[ partial]} views
628 thereof) have special
629 components called @i(discriminants) whose values affect the
630 presence, constraints, or initialization of other components.
631 Discriminants can be thought of as parameters of the type.
632
633 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00366-01]}
634 @Defn{subcomponent}
635 The term @i(subcomponent) is used
636 in this International Standard in place of the term component
637 to indicate either a component, or a component of another
638 subcomponent. Where other subcomponents
639 are excluded, the term component is used instead.
640 @Defn2{Term=[part], Sec=(of an object or value)}
641 Similarly, a @i(part) of an object or value is used to mean
642 the whole object or value, or any set of its subcomponents.@Chg{Version=[2],
643 New=[ The terms component, subcomponent, and part are also applied to a type
644 meaning the component, subcomponent, or part of objects and values of the type.],Old=[]}
645 @begin{Discussion}
646 The definition of @lquotes@;part@rquotes@; here is designed to simplify rules
647 elsewhere. By design, the intuitive meaning of
648 @lquotes@;part@rquotes@; will convey the correct result to the casual reader,
649 while this formalistic definition will answer the concern of
650 the compiler-writer.
651
652 We use the term @lquotes@;part@rquotes@; when talking about the parent part,
653 ancestor part, or extension part of a type extension.
654 In contexts such as these, the part might represent an empty
655 set of subcomponents (e.g. in a null record extension, or a
656 nonnull extension of a null record).
657 We also use @lquotes@;part@rquotes@; when specifying rules such as
658 those that apply to an object
659 with a @lquotes@;controlled part@rquotes@; meaning that it applies if the
660 object as a whole is controlled, or any subcomponent is.
661 @end{Discussion}
662
663 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
664 @PDefn{constraint}
665 The set of possible values for an object of a given type can be
666 subjected to a condition that is called a @i(constraint)
667 @Defn{null constraint}
668 (the case
669 of a @i(null constraint) that specifies no restriction is also
670 included)@Redundant[;
671 the rules for which values satisfy a given kind of constraint
672 are given in @RefSecNum(Scalar Types) for @nt<range_constraint>s,
673 @RefSecNum(Index Constraints and Discrete Ranges)
674 for @nt<index_constraint>s, and
675 @RefSecNum(Discriminant Constraints) for
676 @nt<discriminant_constraint>s].@Chg{Version=[2],New=[ The set of possible values
677 for an object of an access type can also be subjected to a condition that
678 excludes the null value (see @RefSecNum{Access Types}).],Old=[]}
679
680 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00415-01]}
681 @Defn{subtype}
682 A @i(subtype) of a given type is a combination of the type,
683 a constraint on values of the type, and certain
684 attributes specific to the subtype.
685 The given type is called the @Chg{Version=[2],New=[@i(type of the subtype)],
686 Old=[type @i(of) the subtype]}.@Chg{Version=[2],New=[@Defn2{Term=[type], Sec=(of a subtype)}
687 @Defn2{Term=[subtype], Sec=(type of)}],Old=[]}
688 Similarly, the associated constraint is
689 called the @Chg{Version=[2],New=[@i(constraint of the subtype)],
690 Old=[constraint @i(of) the subtype]}.@Chg{Version=[2],New=[@Defn2{Term=[constraint], Sec=(of a subtype)}
691 @Defn2{Term=[subtype], Sec=(constraint of)}],Old=[]} The set of
692 values of a subtype consists of the values of its type
693 that satisfy its constraint@Chg{Version=[2],New=[ and any exclusion of the
694 null value],
695 Old=[]}.
696 @Defn2{Term=[belong], Sec=(to a subtype)}
697 Such values @i(belong) to the subtype.@Chg{Version=[2],New=[@Defn2{Term=[values], Sec=(belonging to a subtype)}
698 @Defn2{Term=[subtype], Sec=(values belonging to)}],Old=[]}
699 @begin{Discussion}
700 We make a strong distinction between a type and its
701 subtypes.
702 In particular, a type is @i(not) a subtype of itself.
703 There is no constraint associated with a type (not even a null one),
704 and type-related attributes are distinct from subtype-specific attributes.
705 @end{Discussion}
706 @begin{Discussion}
707 We no longer use the term "base type."
708 All types were "base types" anyway in Ada 83, so the term was redundant,
709 and occasionally confusing. In the RM95 we
710 say simply "the type @i(of) the subtype" instead of "the base type
711 of the subtype."
712 @end{Discussion}
713 @begin{Ramification}
714 The value subset for a subtype might be empty, and need
715 not be a proper subset.
716 @end{Ramification}
717 @begin{Honest}
718 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
719 Any name of a @Chg{Version=[2],New=[category],Old=[class]} of types (such as
720 @lquotes@;discrete@rquotes@;@Chg{Version=[2],New=[, ],Old=[ or]}
721 @lquotes@;real@rquotes@;@Chg{Version=[2],New=[, or],Old=[), or other category of
722 types (such as]} @lquotes@;limited@rquotes@;@Chg{Version=[2],New=[],
723 Old=[ or @lquotes@;incomplete@rquotes@;]})
724 is also used to qualify its subtypes, as well as its objects, values,
725 declarations, and definitions, such as an @lquotes@;integer type
726 declaration@rquotes@; or an @lquotes@;integer value.@rquotes@; In addition, if
727 a term such as @lquotes@;parent subtype@rquotes@; or @lquotes@;index
728 subtype@rquotes@; is defined, then the corresponding term for the type of the
729 subtype is @lquotes@;parent type@rquotes@; or @lquotes@;index type.@rquotes@;
730 @end{Honest}
731 @begin{Discussion}
732 We use these corresponding terms without explicitly defining them,
733 when the meaning is obvious.
734 @end{Discussion}
735
736 @Defn{constrained}
737 @Defn{unconstrained}
738 @Defn2{Term=[constrained], Sec=(subtype)}
739 @Defn2{Term=[unconstrained], Sec=(subtype)}
740 A subtype is called an @i(unconstrained) subtype if its
741 type has unknown discriminants,
742 or if its type allows range, index, or discriminant constraints,
743 but the subtype does not impose such a constraint;
744 otherwise, the subtype is called a @i(constrained) subtype
745 (since it has no unconstrained characteristics).
746 @begin{Discussion}
747 In an earlier version of Ada 9X,
748 "constrained" meant "has a non-null
749 constraint." However, we changed to this definition
750 since we kept having to special
751 case composite non-array/non-discriminated types. It also corresponds
752 better to the (now obsolescent) attribute 'Constrained.
753
754 For scalar types, @lquotes@;constrained@rquotes@; means @lquotes@;has a non-null
755 constraint@rquotes@;.
756 For composite types, in implementation terms, @lquotes@;constrained@rquotes@; means
757 that the size of all objects of the subtype is the same, assuming a
758 typical implementation model.
759
760 Class-wide subtypes are always unconstrained.
761 @end{Discussion}
762 @end{StaticSem}
763
764 @begin{Notes}
765 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
766 @Chg{Version=[2],New=[Any set of types can be called a
767 @lquotes@;category@rquotes@; of types, and any],Old=[Any]}
768 set of types that is closed under derivation
769 (see @RefSecNum(Derived Types and Classes)) can be called
770 a @lquotes@;class@rquotes@; of types. However, only certain
771 @Chg{Version=[2],New=[categories and ],Old=[]}classes are used in the
772 description of the rules of the language @em generally those
773 that have their own particular set of primitive operations
774 (see @RefSecNum(Classification of Operations)), or that
775 correspond to a set of types that are matched by a given
776 kind of generic formal type (see @RefSecNum(Formal Types)).
777 @PDefn{language-defined class}
778 The following are examples of @lquotes@;interesting@rquotes@; @i(language-defined classes):
779 elementary, scalar, discrete, enumeration, character, boolean,
780 integer, signed integer, modular, real, floating point,
781 fixed point, ordinary fixed point, decimal fixed point,
782 numeric, access, access-to-object, access-to-subprogram,
783 composite, array, string, (untagged) record, tagged, task, protected,
784 nonlimited. Special syntax is provided to define types in
785 each of these classes.@Chg{Version=[2],New=[ In addition to these
786 classes, the following are examples of @lquotes@;interesting@rquotes@;
787 @i(language-defined categories): @PDefn{language-defined categories}
788 abstract, incomplete, interface, limited, private, record.],Old=[]}
789 @begin{Discussion}
790 @Defn{value}
791 A @i(value) is a run-time entity with a given type which can be
792 assigned to an object of an appropriate subtype of the type.
793 @Defn{operation}
794 An @i(operation) is a program entity that operates on zero or more
795 operands to produce an effect, or yield a result, or both.
796 @end{Discussion}
797 @begin{Ramification}
798 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
799 Note that a type's @Chg{Version=[2],New=[category (and ],Old=[]}class@Chg{Version=[2],New=[)],Old=[]}
800 depends on the place of the reference @em a
801 private type is composite outside and possibly elementary inside.
802 It's really the @i{view} that is elementary or composite.
803 Note that although private types are composite,
804 there are some properties that
805 depend on the corresponding full view @em for example,
806 parameter passing modes, and
807 the constraint checks that apply in various places.
808
809 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
810 @Chg{Version=[2],New=[Every property of types forms a category, but not],
811 Old=[Not]} every property of types represents a class.
812 For example, the set of all abstract types does not form a class,
813 because this set is not closed under derivation.@Chg{Version=[2],New=[
814 Similarly, the set of all interface types does not form a class.],Old=[]}
815
816 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
817 The set of limited types @Chg{Version=[2],New=[does not form a class
818 (since nonlimited types can inherit from limited interfaces), but the
819 set of nonlimited types does. The set of tagged record types and the set
820 of tagged private types do not form a class (because each of them can
821 be extended to create a type of the other category); that implies that
822 the set of record types and the set of private types also do not form a
823 class (even though untagged record types and untagged private types do
824 form a class). In all of these cases, we can talk about the category
825 of the type; for instance, we can talk about the @lquotes@;category
826 of limited types@rquotes.],
827 Old=[forms a class in the sense that it is closed
828 under derivation, but the more interesting
829 class, from the point of generic formal type matching, is the
830 set of all types, limited and nonlimited, since that is what
831 matches a generic formal @lquotes@;limited@rquotes@; private type.
832 Note also that a limited type can @lquotes@;become nonlimited@rquotes@; under
833 certain circumstances, which
834 makes @lquotes@;limited@rquotes@; somewhat problematic as a class of types]}.
835
836 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
837 @ChgAdded{Version=[2],Text=[Normatively, the @i<language-defined classes>
838 are those that are defined to be inherited on derivation by
839 @RefSecNum{Derived Types and Classes}; other properties either aren't
840 interesting or form categories, not classes.]}
841 @end{Ramification}
842
843 @noprefix@;@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00442-01]}
844 These language-defined @Chg{Version=[2],New=[categories],Old=[classes]} are
845 organized like this:
846 @begin{Display}
847 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
848 @TabClear{}
849 @TabSet{3, 6, 9, 12, 15, 18, 21}
850 all types
851 @\elementary
852 @\@\scalar
853 @\@\@\discrete
854 @\@\@\@\enumeration
855 @\@\@\@\@\character
856 @\@\@\@\@\boolean
857 @\@\@\@\@\other enumeration
858 @\@\@\@\integer
859 @\@\@\@\@\signed integer
860 @\@\@\@\@\modular integer
861 @\@\@\real
862 @\@\@\@\floating point
863 @\@\@\@\fixed point
864 @\@\@\@\@\ordinary fixed point
865 @\@\@\@\@\decimal fixed point
866 @\@\access
867 @\@\@\access-to-object
868 @\@\@\access-to-subprogram
869 @\composite@Chg{Version=[2],New=[
870 @\@\untagged],Old=[]}
871 @Chg{Version=[2],New=[@\],Old=[]}@\@\array
872 @Chg{Version=[2],New=[@\],Old=[]}@\@\@\string
873 @Chg{Version=[2],New=[@\],Old=[]}@\@\@\other array
874 @\@\@Chg{Version=[2],New=[@\],Old=[untagged ]}record@Chg{Version=[2],New=[],Old=[
875 @\@\tagged]}
876 @Chg{Version=[2],New=[@\],Old=[]}@\@\task
877 @Chg{Version=[2],New=[@\],Old=[]}@\@\protected@Chg{Version=[2],New=[
878 @\@\tagged (including interfaces)
879 @\@\@\nonlimited tagged record
880 @\@\@\limited tagged
881 @\@\@\@\limited tagged record
882 @\@\@\@\synchronized tagged
883 @\@\@\@\@\tagged task
884 @\@\@\@\@\tagged protected],Old=[]}
885 @end{Display}
886
887 @noprefix@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
888 @Chg{Version=[2],New=[There are other categories, such as],Old=[The classes]}
889 @lquotes@;numeric@rquotes@; and
890 @lquotes@;@Chg{Version=[2],New=[discriminated],Old=[nonlimited]}@rquotes@;@Chg{Version=[2],
891 New=[, which],Old=[]}
892 represent other @Chg{Version=[2],New=[categorization],Old=[classification]}
893 dimensions@Chg{Version=[2],New=[, but],
894 Old=[ and]} do not fit into the above strictly hierarchical picture.
895 @begin{Discussion}
896 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00442-01]}
897 @ChgAdded{Version=[2],Text=[Note that this is also true for some categories
898 mentioned in the chart. The category @lquotes@;task@rquotes@; includes both
899 untagged tasks and tagged tasks. Similarly for @lquotes@;protected@rquotes@;,
900 @lquotes@;limited@rquotes@;, and @lquotes@;nonlimited@rquotes@; (note that
901 limited and nonlimited are not shown for untagged composite types).]}
902 @end{Discussion}
903 @end{Notes}
904
905 @begin{DiffWord83}
906 This clause and its subclauses now precede the clause and
907 subclauses on objects and named numbers, to cut down on the number of
908 forward references.
909
910 We have dropped the term "base type" in favor of simply "type" (all
911 types in Ada 83 were "base types" so it wasn't clear when it was
912 appropriate/necessary to say "base type"). Given a subtype S of
913 a type T, we call T the "type of the subtype S."
914 @end{DiffWord83}
915
916 @begin{DiffWord95}
917 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
918 @ChgAdded{Version=[2],Text=[Added a mention of null exclusions when we're
919 talking about constraints (these are not constraints, but they are similar).]}
920
921 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
922 @ChgAdded{Version=[2],Text=[Defined an interface type to be a composite
923 type.]}
924
925 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
926 @ChgAdded{Version=[2],Text=[Revised the wording so that it is clear
927 that an incomplete view is similar to a partial view in terms of the
928 language.]}
929
930 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00366-01]}
931 @ChgAdded{Version=[2],Text=[Added a definition of component of a type,
932 subcomponent of a type, and part of a type. These are commonly used in
933 the standard, but they were not previously defined.]}
934
935 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
936 @ChgAdded{Version=[2],Text=[Reworded most of this clause to use
937 category rather than class, since so many interesting properties are
938 not, strictly speaking, classes. Moreover, there was no normative
939 description of exactly which properties formed classes, and which did
940 not. The real definition of class, along with a list of properties, is now
941 in @RefSecNum{Derived Types and Classes}.]}
942 @end{DiffWord95}
943
944
945 @LabeledSubClause{Type Declarations}
946
947 @begin{Intro}
948 A @nt<type_declaration> declares a type and its first subtype.
949 @end{Intro}
950
951 @begin{Syntax}
952 @Syn{lhs=<type_declaration>,rhs=" @Syn2{full_type_declaration}
953 | @Syn2{incomplete_type_declaration}
954 | @Syn2{private_type_declaration}
955 | @Syn2{private_extension_declaration}"}
956
957
958 @Syn{lhs=<full_type_declaration>,rhs="
959 @key{type} @Syn2{defining_identifier} [@Syn2{known_discriminant_part}] @key{is} @Syn2{type_definition};
960 | @Syn2{task_type_declaration}
961 | @Syn2{protected_type_declaration}"}
962
963 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
964 @Syn{tabs=[P29], lhs=<type_definition>,rhs="
965 @Syn2{enumeration_type_definition}@\| @Syn2{integer_type_definition}
966 | @Syn2{real_type_definition}@\| @Syn2{array_type_definition}
967 | @Syn2{record_type_definition}@\| @Syn2{access_type_definition}
968 | @Syn2{derived_type_definition}@Chg{Version=[2],New=[@\| @Syn2{interface_type_definition}],Old=[]}"}
969 @end{Syntax}
970
971 @begin{Legality}
972 A given type shall not have a subcomponent whose type is the given
973 type itself.
974 @end{Legality}
975
976 @begin{StaticSem}
977 @Defn{first subtype}
978 The @nt{defining_@!identifier} of a @nt{type_@!declaration} denotes
979 the @i(first subtype) of the type.
980 The @nt<known_@!discriminant_@!part>, if any,
981 defines the discriminants of the type (see @RefSec(Discriminants)).
982 The remainder of the @nt<type_@!declaration> defines the
983 remaining characteristics of (the view of) the type.
984
985 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
986 @Defn{named type}
987 A type defined by a @nt<type_@!declaration> is a @i(named) type;
988 such a type has one or more nameable subtypes.
989 @Defn{anonymous type}
990 Certain other forms of declaration also include type
991 definitions as part of the declaration for an object@Chg{Version=[2],New=[],
992 Old=[ (including a parameter or a discriminant)]}. The type defined by such
993 a declaration is @i(anonymous) @em it has no nameable subtypes.
994 @Defn2{Term=[italics],Sec=(pseudo-names of anonymous types)}
995 For explanatory purposes, this International Standard sometimes refers to
996 an anonymous type by a pseudo-name, written in italics, and
997 uses such pseudo-names at places where the syntax normally requires
998 an @nt<identifier>. For a named type whose first subtype is T,
999 this International Standard sometimes refers to the type of T
1000 as simply @lquotes@;the type T@rquotes@;.
1001 @begin{Ramification}
1002 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
1003 The only user-defined types
1004 that can be anonymous in the above sense are array,
1005 access, task, and protected types.
1006 An anonymous array, task, or protected type
1007 can be defined as part of an @nt{object_declaration}.
1008 An anonymous access type can be defined as part of
1009 @Chg{Version=[2],New=[numerous other constructs],Old=[a parameter or
1010 discriminant specification]}.
1011 @end{Ramification}
1012
1013 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00326-01]}
1014 @Defn{full type}
1015 A named type that is declared by a @nt<full_type_@!declaration>,
1016 or an anonymous type that is defined @Chg{Version=[2],New=[by an
1017 @nt{access_definition} or ],Old=[]}as part of declaring an object of the type,
1018 is called a
1019 @i(full type).@Defn{full type definition} @Chg{Version=[2],New=[The
1020 declaration of a full type also declares the @i<full view> of the
1021 type.@Defn2{Term=[full view],Sec=(of a type)} ],Old=[]}The
1022 @nt<type_@!definition>, @nt<task_@!definition>, @nt<protected_@!definition>,
1023 or @nt<access_@!definition> that defines a full type is called
1024 a @i(full type definition).
1025 @redundant[Types declared by other forms of @nt<type_@!declaration> are
1026 not separate types; they are partial or incomplete views
1027 of some full type.]
1028 @begin{Honest}
1029 Class-wide, universal, and root numeric types are full types.
1030 @end{Honest}
1031 @begin{Reason}
1032 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1033 @ChgAdded{Version=[2],Text=[We need to mention @nt{access_definition}
1034 separately, as it may occur in renames, which do not declare objects.]}
1035 @end{Reason}
1036
1037 @PDefn{predefined operator}
1038 The definition of a type implicitly declares
1039 certain @i(predefined operators) that operate on the type,
1040 according to what classes the type belongs,
1041 as specified in @RefSec(Operators and Expression Evaluation).
1042 @begin{Discussion}
1043 We no longer talk about the implicit declaration of basic operations.
1044 These are treated like an @nt{if_statement} @em they don't need
1045 to be declared, but are still applicable to only certain classes of types.
1046
1047 @end{Discussion}
1048
1049 @Defn{predefined type}
1050 The @i{predefined types}
1051 @Redundant[(for example the types
1052 Boolean, Wide_Character, Integer,
1053 @i{root_integer}, and @i{universal_integer})]
1054 are the types that are defined in
1055 @Redundant[a predefined library package called] Standard@Redundant[;
1056 this package also includes the @Redundant{(implicit)}
1057 declarations of their predefined operators].
1058 @Redundant[The package Standard is described in
1059 @RefSecNum{The Package Standard}.]
1060 @begin{Ramification}
1061 We use the term @lquotes@;predefined@rquotes@; to refer to entities declared in the
1062 visible part of Standard,
1063 to implicitly declared operators of a type whose semantics are defined
1064 by the language, to Standard itself,
1065 and to the @lquotes@;predefined environment@rquotes@;.
1066 We do not use this term to refer to library packages other than Standard.
1067 For example Text_IO is a language-defined package,
1068 not a predefined package,
1069 and Text_IO.Put_Line is not a predefined operation.
1070 @end{Ramification}
1071 @end{StaticSem}
1072
1073 @begin{RunTime}
1074 @PDefn2{Term=[elaboration], Sec=(full_type_declaration)}
1075 The elaboration of a @nt{full_type_declaration} consists of the
1076 elaboration of the full type definition.
1077 @PDefn2{Term=[elaboration], Sec=(full type definition)}
1078 Each elaboration of a full type definition
1079 creates a distinct type and its first subtype.
1080 @begin{Reason}
1081 The creation is associated with the type @i(definition), rather than
1082 the type @i(declaration), because there are types
1083 that are created by full type definitions that are
1084 not immediately contained within a type declaration (e.g.
1085 an array object declaration, a singleton task declaration, etc.).
1086 @end{Reason}
1087 @begin{Ramification}
1088 Any implicit declarations that occur immediately following the full
1089 type definition are elaborated where they (implicitly) occur.
1090 @end{Ramification}
1091 @end{RunTime}
1092
1093 @begin{Examples}
1094 @Leading@keepnext@i(Examples of type definitions:)
1095 @begin(Example)
1096 (White, Red, Yellow, Green, Blue, Brown, Black)
1097 @key(range) 1 .. 72
1098 @key(array)(1 .. 10) @key(of) Integer
1099 @end(Example)
1100
1101 @begin{Wide}
1102 @leading@keepnext@i(Examples of type declarations:)
1103 @end{Wide}
1104 @begin(Example)
1105 @key(type) Color @key(is) (White, Red, Yellow, Green, Blue, Brown, Black);
1106 @key(type) Column @key(is) @key(range) 1 .. 72;
1107 @key(type) Table @key(is) @key(array)(1 .. 10) @key(of) Integer;
1108 @end(Example)
1109 @end{Examples}
1110
1111 @begin{Notes}
1112 Each of the above examples declares a named type. The identifier
1113 given denotes the first subtype of the type. Other named subtypes of the
1114 type can be declared with @nt<subtype_declaration>s
1115 (see @RefSecNum{Subtype Declarations}). Although names do not directly
1116 denote types, a phrase like @lquotes@;the type Column@rquotes@; is sometimes used
1117 in this International Standard to refer to the type of Column, where Column denotes
1118 the first subtype of the type. For an example of the definition
1119 of an anonymous type, see the declaration
1120 of the array Color_Table in @RefSecNum{Object Declarations}; its type
1121 is anonymous @em it has no nameable subtypes.
1122 @end{Notes}
1123
1124 @begin{DiffWord83}
1125 The syntactic category @nt{full_type_declaration} now includes task and
1126 protected type declarations.
1127
1128 We have generalized the concept of first-named subtype (now
1129 called simply @lquotes@;first subtype@rquotes@;) to cover all kinds of types, for uniformity
1130 of description elsewhere.
1131 RM83 defined first-named subtype in Section 13.
1132 We define first subtype here, because it is now a more fundamental concept.
1133 We renamed the term, because in Ada 95 some first subtypes have no
1134 name.
1135
1136 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1137 We no longer elaborate @nt{discriminant_part}s, because
1138 there is nothing to do, and it was complex to say that you only wanted
1139 to elaborate it once for a private or incomplete type. This is also
1140 consistent with the fact that subprogram specifications are not
1141 elaborated (neither in Ada 83 nor in Ada 95). Note, however, that an
1142 @nt<access_definition> appearing in a @nt<discriminant_part> is
1143 elaborated@Chg{Version=[2],New=[ at the @nt{full_type_declaration} (for
1144 a nonlimited type) or],Old=[]} when an object with such a discriminant is
1145 created@Chg{Version=[2],New=[ (for a limited type)],Old=[]}.
1146 @end{DiffWord83}
1147
1148 @begin{DiffWord95}
1149 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
1150 @ChgAdded{Version=[2],Text=[Added wording so that anonymous access types
1151 are always full types, even if they appear in renames.]}
1152
1153 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1154 @ChgAdded{Version=[2],Text=[Added interface types
1155 (see @RefSecNum{Interface Types}) to the syntax.]}
1156
1157 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00326-01]}
1158 @ChgAdded{Version=[2],Text=[Added a definition of full view, so that
1159 all types have a well-defined full view.]}
1160 @end{DiffWord95}
1161
1162
1163 @LabeledSubClause{Subtype Declarations}
1164
1165 @begin{Intro}
1166 A @nt<subtype_declaration> declares a subtype of some previously
1167 declared type, as defined by a @nt<subtype_indication>.
1168 @end{Intro}
1169
1170 @begin{Syntax}
1171 @Syn{lhs=<subtype_declaration>,rhs="
1172 @key{subtype} @Syn2{defining_identifier} @key{is} @Syn2{subtype_indication};"}
1173
1174
1175 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
1176 @Syn{lhs=<subtype_indication>,rhs=" @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{subtype_mark} [@Syn2{constraint}]"}
1177
1178 @Syn{lhs=<subtype_mark>,rhs="@SynI{subtype_}@Syn2{name}"}
1179 @begin{Ramification}
1180 Note that @nt{name} includes @nt{attribute_reference};
1181 thus, S'Base can be used as a @nt{subtype_mark}.
1182 @end{Ramification}
1183 @begin{Reason}
1184 We considered changing @nt{subtype_mark} to @ntf{subtype_name}.
1185 However, existing users are used to the word "mark,"
1186 so we're keeping it.
1187 @end{Reason}
1188
1189 @Syn{lhs=<constraint>,rhs="@Syn2<scalar_constraint> | @Syn2<composite_constraint>"}
1190
1191 @Syn{lhs=<scalar_constraint>,rhs="
1192 @Syn2{range_constraint} | @Syn2{digits_constraint} | @Syn2{delta_constraint}"}
1193 @Syn{lhs=<composite_constraint>,rhs="
1194 @Syn2{index_constraint} | @Syn2{discriminant_constraint}"}
1195 @end{Syntax}
1196
1197 @begin{Resolution}
1198 A @nt{subtype_mark} shall resolve to denote a subtype.
1199 @Defn2{Term=[determines], Sec=(a type by a @nt{subtype_mark})}
1200 The type @i(determined by) a @nt<subtype_mark> is the
1201 type of the subtype denoted by the @nt{subtype_mark}.
1202 @begin{Ramification}
1203 Types are never directly named; all @nt{subtype_mark}s denote
1204 subtypes @em possibly an unconstrained (base) subtype,
1205 but never the type.
1206 When we use the term @i(anonymous type) we really
1207 mean a type with no namable subtypes.
1208 @end{Ramification}
1209 @end{Resolution}
1210
1211 @begin{RunTime}
1212 @Leading@PDefn2{Term=[elaboration], Sec=(subtype_declaration)}
1213 The elaboration of a @nt{subtype_declaration} consists of the elaboration
1214 of the @nt{subtype_indication}.
1215 @PDefn2{Term=[elaboration], Sec=(subtype_indication)}
1216 The elaboration of a @nt{subtype_indication} creates a new subtype.
1217 If the @nt{subtype_indication} does not include a
1218 @nt<constraint>, the new subtype has the same (possibly null)
1219 constraint as that denoted by the @nt{subtype_mark}.
1220 The elaboration of a @nt{subtype_indication} that includes a
1221 @nt<constraint> proceeds as follows:
1222 @begin{itemize}
1223 The @nt<constraint> is first elaborated.
1224
1225 @IndexCheck{Range_Check}
1226 A check is then made that
1227 the @nt<constraint> is @i(compatible) with the
1228 subtype denoted by the @nt{subtype_mark}.
1229 @begin{Ramification}
1230 The checks associated with
1231 constraint compatibility are all Range_Checks.
1232 Discriminant_Checks and Index_Checks are associated only with
1233 checks that a value satisfies a constraint.
1234 @end{Ramification}
1235 @end{itemize}
1236
1237 The condition imposed by a @nt<constraint> is the condition obtained
1238 after elaboration of the @nt<constraint>.
1239 @RootDefn2{Term=[compatibility], Sec=(constraint with a subtype)}
1240 The rules defining compatibility are given for each form of @nt<constraint>
1241 in the appropriate subclause. These rules are such that if a
1242 @nt<constraint> is @i(compatible) with a subtype,
1243 then the condition imposed by the @nt<constraint> cannot
1244 contradict any condition already imposed by the subtype on its values.
1245 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
1246 The exception Constraint_Error is raised if any check of
1247 compatibility fails.
1248 @begin{Honest}
1249 The condition imposed by a @nt<constraint> is named after it @em
1250 a @nt<range_constraint> imposes a range constraint, etc.
1251 @end{Honest}
1252 @begin{Ramification}
1253 A @nt<range_constraint> causes freezing of its type.
1254 Other @nt<constraint>s do not.
1255 @end{Ramification}
1256 @end{RunTime}
1257
1258 @begin{Notes}
1259 A @nt<scalar_constraint> may be applied to a subtype of an appropriate
1260 scalar type (see @RefSecNum{Scalar Types}, @RefSecNum{Fixed Point Types},
1261 and @RefSecNum{Reduced Accuracy Subtypes}), even if the subtype
1262 is already constrained. On the other hand, a @nt<composite_constraint>
1263 may be applied to a composite subtype (or an access-to-composite subtype)
1264 only if the composite subtype is unconstrained
1265 (see @RefSecNum{Index Constraints and Discrete Ranges} and
1266 @RefSecNum{Discriminant Constraints}).
1267 @end{Notes}
1268
1269 @begin{Examples}
1270 @Leading@keepnext@i(Examples of subtype declarations:)
1271 @begin(Example)
1272 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
1273 @key(subtype) Rainbow @key(is) Color @key(range) Red .. Blue; --@RI[ see @RefSecNum(Type Declarations)]
1274 @key(subtype) Red_Blue @key(is) Rainbow;
1275 @key(subtype) Int @key(is) Integer;
1276 @key(subtype) Small_Int @key(is) Integer @key(range) -10 .. 10;
1277 @key(subtype) Up_To_K @key(is) Column @key(range) 1 .. K; --@RI[ see @RefSecNum(Type Declarations)]
1278 @key(subtype) Square @key(is) Matrix(1 .. 10, 1 .. 10); --@RI[ see @RefSecNum(Array Types)]
1279 @key(subtype) Male @key(is) Person(Sex => M); --@RI[ see @RefSecNum(Incomplete Type Declarations)]@Chg{Version=[2],New=[
1280 @key(subtype) Binop_Ref @key(is not null) Binop_Ptr; --@RI[ see @RefSecNum(Access Types)]],Old=[]}
1281 @end(Example)
1282
1283 @end{Examples}
1284
1285 @begin{Incompatible83}
1286 @Defn{incompatibilities with Ada 83}
1287 In Ada 95, all @nt<range_constraint>s cause freezing of their type.
1288 Hence, a type-related representation item for a scalar type has to
1289 precede any @nt<range_constraint>s whose type is the scalar type.
1290 @end{Incompatible83}
1291
1292 @begin{DiffWord83}
1293 @nt{Subtype_mark}s allow only subtype names now, since
1294 types are never directly named.
1295 There is no need for RM83-3.3.2(3), which says a
1296 @nt{subtype_mark} can denote both the type and the subtype;
1297 in Ada 95, you denote an unconstrained (base) subtype if you want,
1298 but never the type.
1299
1300 The syntactic category @ntf{type_mark} is now called @nt{subtype_mark},
1301 since it always denotes a subtype.
1302 @end{DiffWord83}
1303
1304 @begin{Extend95}
1305 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
1306 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1307 An optional @nt{null_exclusion} can be used in a @nt{subtype_indication}.
1308 This is described in @RefSecNum{Access Types}]}
1309 @end{Extend95}
1310
1311
1312 @LabeledSubClause{Classification of Operations}
1313
1314 @begin{StaticSem}
1315 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1316 @Defn{operates on a type}
1317 An operation @i(operates
1318 on a type) @i(T) if it yields a value of type @i(T), if it has an operand
1319 whose expected type
1320 (see @RefSecNum{The Context of Overload Resolution})
1321 is @i(T), or if it has an access parameter@Chg{Version=[2],New=[ or access result type],Old=[]}
1322 (see @RefSecNum(Subprogram Declarations))
1323 designating @i(T).
1324 @Defn2{Term=[predefined operation], Sec=(of a type)}
1325 A predefined operator, or
1326 other language-defined operation
1327 such as assignment or a membership test, that operates
1328 on a type, is called
1329 a @i(predefined operation) of the type.
1330 @Defn2{Term=[primitive operations], Sec=(of a type)}
1331 The @i(primitive operations) of a type are
1332 the predefined operations of the type, plus any user-defined
1333 primitive subprograms.
1334 @ToGlossary{Term=<Primitive operations>,
1335 Text=<The primitive operations of a type are the operations
1336 (such as subprograms) declared together with
1337 the type declaration.
1338 They are inherited by other types in the same class of types.
1339 For a tagged type,
1340 the primitive subprograms are dispatching subprograms,
1341 providing run-time polymorphism.
1342 A dispatching subprogram may be called with statically
1343 tagged operands, in which case the subprogram body invoked
1344 is determined at compile time.
1345 Alternatively, a dispatching subprogram may be called
1346 using a dispatching call,
1347 in which case the subprogram body invoked is determined
1348 at run time.>}
1349 @begin{Honest}
1350 Protected subprograms are not considered to be
1351 @lquotes@;primitive subprograms,@rquotes@; even though they are
1352 subprograms, and they are inherited by derived types.
1353 @end{Honest}
1354 @begin{Discussion}
1355 We use the term
1356 @lquotes@;primitive subprogram@rquotes@; in most of the rest of the manual.
1357 The term @lquotes@;primitive operation@rquotes@; is used mostly in conceptual
1358 discussions.
1359 @end{Discussion}
1360
1361 @Leading@Defn2{Term=[primitive subprograms], Sec=(of a type)}
1362 The @i(primitive subprograms) of a
1363 specific type are defined as follows:
1364 @begin{Itemize}
1365 The predefined operators of the
1366 type (see @RefSecNum{Operators and Expression Evaluation});
1367
1368 For a derived type, the inherited (see @RefSecNum{Derived Types and Classes})
1369 user-defined subprograms;
1370
1371 For an enumeration type, the enumeration literals (which are
1372 considered parameterless
1373 functions @em see @RefSecNum{Enumeration Types});
1374
1375 For a specific type declared immediately within
1376 a @nt<package_specification>,
1377 any subprograms (in addition to the enumeration literals)
1378 that are
1379 explicitly declared immediately within the same
1380 @nt<package_specification> and that operate on the type;
1381
1382 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00200-01]}
1383 @Defn2{Term=[override], Sec=(a primitive subprogram)}
1384 @Chg{Version=[2],New=[For a nonformal type, any],Old=[Any]}
1385 subprograms not covered above
1386 @Redundant[that are explicitly declared immediately within the same
1387 declarative region as the type] and that override (see @RefSecNum{Visibility})
1388 other implicitly declared primitive subprograms of the type.
1389 @end{Itemize}
1390 @begin{Discussion}
1391 In Ada 83, only subprograms
1392 declared in the visible part were @lquotes@;primitive@rquotes@; (i.e.
1393 derivable). In Ada 95, mostly because of child library units,
1394 we include all operations declared in the private part as well,
1395 and all operations that override implicit declarations.
1396 @end{Discussion}
1397 @begin{Ramification}
1398 It is possible for a subprogram
1399 to be primitive for more than one type, though it is illegal
1400 for a subprogram to be primitive for more than one tagged type.
1401 See @RefSecNum(Tagged Types and Type Extensions).
1402 @end{Ramification}
1403 @begin(Discussion)
1404 The order of the implicit declarations when there are both
1405 predefined operators and inherited subprograms is described in
1406 @RefSec(Derived Types and Classes).
1407 @end(Discussion)
1408 @begin{Ramification}
1409 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00200-01]}
1410 @ChgAdded{Version=[2],Text=[Subprograms declared in a generic package
1411 specification are never primitive for a formal type, even if they happen
1412 to override an operation of the formal type. This includes formal
1413 subprograms, which are never primitive operations (that's true even
1414 for an abstract formal subprogram).]}
1415 @end{Ramification}
1416
1417 @Defn2{Term=[primitive operator], Sec=(of a type)}
1418 A primitive subprogram whose designator is an @nt<operator_symbol>
1419 is called a @i(primitive operator).
1420
1421 @end{StaticSem}
1422
1423 @begin{Incompatible83}
1424 @Defn{incompatibilities with Ada 83}
1425 The attribute S'Base is no longer defined for
1426 non-scalar subtypes. Since this was only permitted
1427 as the prefix of another attribute, and there are no
1428 interesting non-scalar attributes defined for an unconstrained
1429 composite or access subtype, this should not affect any
1430 existing programs.
1431 @end{Incompatible83}
1432
1433 @begin{Extend83}
1434 @Defn{extensions to Ada 83}
1435 The primitive subprograms (derivable subprograms) include
1436 subprograms declared in the private part of a package
1437 specification as well, and those that override implicitly declared
1438 subprograms, even if declared in a body.
1439 @end{Extend83}
1440
1441 @begin{DiffWord83}
1442 We have dropped the confusing
1443 term @i<operation of a type> in favor of the more useful
1444 @i<primitive operation of a type> and the phrase
1445 @i<operates on a type>.
1446
1447 The description of S'Base has been moved to
1448 @RefSec{Scalar Types} because it is now defined only for scalar types.
1449 @end{DiffWord83}
1450
1451 @begin{DiffWord95}
1452 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00200-01]}
1453 @ChgAdded{Version=[2],Text=[Clarified that a formal subprogram that happens
1454 to override a primitive operation of a formal type is not a primitive
1455 operation (and thus not a dispatching operation) of the formal type.]}
1456
1457 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1458 @ChgAdded{Version=[2],Text=[Added wording to include access result types
1459 in the kinds of operations that operate on a type T.]}
1460 @end{DiffWord95}
1461
1462
1463 @LabeledClause{Objects and Named Numbers}
1464
1465 @begin{Intro}
1466 @redundant[Objects are created at run time
1467 and contain a value of a given type.
1468 @Defn2{Term=[creation], Sec=(of an object)}
1469 An object can be created and
1470 initialized as part of elaborating a
1471 declaration, evaluating an @nt<allocator>, @nt<aggregate>,
1472 or @nt<function_call>, or passing a parameter by copy.
1473 Prior to reclaiming the storage for an object, it is finalized if
1474 necessary (see @RefSecNum(Completion and Finalization)).]
1475 @end{Intro}
1476
1477 @begin{StaticSem}
1478
1479 @Leading@keepnext@Defn{object}
1480 All of the following are objects:
1481 @ToGlossary{Term=<Object>,
1482 Text=<An object is either a constant or a variable.
1483 An object contains a value.
1484 An object is created by an @nt(object_declaration)
1485 or by an @nt(allocator).
1486 A formal parameter is (a view of) an object.
1487 A subcomponent of an object is an object.>}
1488 @begin(itemize)
1489 the entity declared by
1490 an @nt<object_declaration>;
1491
1492 a formal parameter of a subprogram, entry, or generic subprogram;
1493
1494 a generic formal object;
1495
1496 a loop parameter;
1497
1498 a choice parameter of an @nt<exception_handler>;
1499
1500 an entry index of an @nt<entry_body>;
1501
1502 the result of dereferencing an
1503 access-to-object value (see @RefSecNum{Names});
1504
1505 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00416-01]}
1506 the @Chg{Version=[2],New=[return object created as the ],Old=[]}result
1507 of evaluating a @nt<function_call> (or the equivalent
1508 operator invocation @em see @RefSecNum{Overloading of Operators});
1509
1510 the result of evaluating an @nt<aggregate>;
1511
1512 a component, slice, or view conversion of another object.
1513 @end(itemize)
1514
1515 @Defn{constant}
1516 @Defn{variable}
1517 @Defn{constant object}
1518 @Defn{variable object}
1519 @Defn{constant view}
1520 @Defn{variable view}
1521 An object is either a @i(constant) object or a @i(variable) object.
1522 The value of a constant object cannot be changed
1523 between its initialization
1524 and its finalization, whereas the value of a variable object can be
1525 changed.
1526 Similarly, a view of an object is either a @i(constant) or
1527 a @i(variable). All views of a constant object are constant.
1528 A constant view of a variable object cannot be used to modify
1529 the value of the variable. The terms constant and variable by themselves
1530 refer to constant and variable views of objects.
1531
1532 @Defn2{Term=[read], Sec=(the value of an object)}
1533 The value of an object
1534 is @i(read) when the value of any part of the object is evaluated,
1535 or when the value of an enclosing object is evaluated.
1536 @Defn2{Term=[update], Sec=(the value of an object)}
1537 The value of a variable
1538 is @i(updated) when an assignment is performed to any part of the
1539 variable, or when an assignment is performed to an enclosing object.
1540 @begin{Ramification}
1541 Reading and updating are intended to include read/write references of
1542 any kind, even if they are not associated with the evaluation of a
1543 particular construct. Consider, for example, the expression
1544 @lquotes@;X.@key[all](F)@rquotes@;,
1545 where X is an access-to-array object, and F is a function.
1546 The implementation is allowed to first evaluate @lquotes@;X.@key[all]@rquotes@;
1547 and then F.
1548 Finally, a read is performed to get the value of the F'th component of
1549 the array.
1550 Note that the array is not necessarily read as part of the evaluation of
1551 @lquotes@;X.@key[all]@rquotes@;.
1552 This is important, because if F were to free X using
1553 Unchecked_Deallocation, we want the execution of the final read to be
1554 erroneous.
1555 @end{Ramification}
1556
1557 @Leading@;Whether a view of an object is constant or variable is determined
1558 by the definition of the view.
1559 The following (and no others) represent constants:
1560 @begin(itemize)
1561 an object declared by an @nt<object_declaration> with the
1562 reserved word @key(constant);
1563
1564 @begin{Honest}
1565 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00385-01]}
1566 @ChgAdded{Version=[2],Type=[Leading],Text=[We mean the word @key{constant}
1567 as defined by the grammar for @nt{object_declaration}, not some random word
1568 @key{constant}. Thus,]}
1569 @begin{Example}
1570 @ChgRef{Version=[2],Kind=[AddedNormal]}
1571 @ChgAdded{Version=[2],Text=[X : @key{access constant} T;]}
1572 @end{Example}
1573 @ChgRef{Version=[2],Kind=[AddedNormal]}
1574 @ChgAdded{Version=[2],Text=[is not a constant.]}
1575 @end{Honest}
1576
1577 a formal parameter or generic formal object of mode @key(in);
1578
1579 a discriminant;
1580
1581 a loop parameter, choice parameter, or entry index;
1582
1583 the dereference of an access-to-constant value;
1584
1585 the result of evaluating a @nt<function_call> or an @nt<aggregate>;
1586
1587 a @nt<selected_component>, @nt<indexed_component>,
1588 @nt<slice>, or view conversion of a constant.
1589 @begin{Honest}
1590 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00114-01]}
1591 @ChgNote{This is just wrong, even for Ada 95.}
1592 @ChgDeleted{Version=[2],Text=[A noninvertible view conversion to a
1593 general access type
1594 is also defined to be a constant @em see @RefSecNum(Type Conversions).]}
1595 @end{Honest}
1596
1597 @end(itemize)
1598
1599 @Defn{nominal subtype}
1600 At the place where a view of an
1601 object is defined, a @i(nominal subtype) is associated
1602 with the view.
1603 @Defn{actual subtype}
1604 @IndexSee{Term=[subtype (of an object)],See=(actual subtype of an object)}
1605 The object's @i(actual subtype) (that is, its
1606 subtype) can be more restrictive than
1607 the nominal subtype of the view; it always is if the nominal subtype
1608 is an @i(indefinite subtype).
1609 @Defn{indefinite subtype}
1610 @Defn{definite subtype}
1611 A subtype is an indefinite subtype if it is an unconstrained array
1612 subtype, or if it has unknown discriminants or unconstrained
1613 discriminants without defaults (see @RefSecNum(Discriminants));
1614 otherwise the subtype is a @i{definite} subtype @Redundant[(all
1615 elementary subtypes are definite subtypes)].
1616 @redundant[A class-wide subtype is defined to have unknown discriminants,
1617 and is therefore an indefinite subtype.
1618 An indefinite subtype does not by itself
1619 provide enough information to create an object;
1620 an additional @nt<constraint> or
1621 explicit initialization @nt<expression>
1622 is necessary (see @RefSecNum(Object Declarations)).
1623 A component cannot have an indefinite nominal subtype.]
1624
1625 @Defn{named number}
1626 A @i(named number) provides a name for a numeric value known
1627 at compile time. It is declared by a @nt<number_declaration>.
1628 @end{StaticSem}
1629
1630 @begin{Notes}
1631 A constant cannot be the target of an assignment operation, nor be
1632 passed as an @key(in) @key(out) or @key(out)
1633 parameter, between its initialization and finalization, if any.
1634
1635 The nominal and actual subtypes of an elementary object are
1636 always the same. For a discriminated or array object,
1637 if the nominal subtype is constrained then so is the actual
1638 subtype.
1639 @end{Notes}
1640
1641 @begin{Extend83}
1642 @Defn{extensions to Ada 83}
1643 There are additional kinds of objects (choice parameters and
1644 entry indices of entry bodies).
1645
1646 The result of a function and of evaluating an aggregate
1647 are considered (constant) objects. This is necessary to explain
1648 the action of finalization on such things.
1649 Because a @nt<function_call> is also syntactically a @nt<name>
1650 (see @RefSecNum(Names)), the result of a @nt{function_call} can be renamed,
1651 thereby allowing repeated use of the result without calling
1652 the function again.
1653 @end{Extend83}
1654
1655 @begin{DiffWord83}
1656 This clause and its subclauses now follow the clause and
1657 subclauses on types and subtypes, to cut down on the number of
1658 forward references.
1659
1660 The term nominal subtype is new. It is used to distinguish
1661 what is known at compile time about an object's constraint, versus what
1662 its "true" run-time constraint is.
1663
1664 The terms definite and indefinite (which apply to
1665 subtypes) are new.
1666 They are used to aid in the description of generic formal
1667 type matching,
1668 and to specify when an explicit initial value is required
1669 in an @nt<object_declaration>.
1670
1671 We have moved the syntax for @nt<object_declaration> and
1672 @nt<number_declaration> down into their respective subclauses, to
1673 keep the syntax close to the description of the associated semantics.
1674
1675 We talk about variables and constants here, since the discussion is
1676 not specific to @nt<object_declaration>s, and it seems
1677 better to have the list of the kinds of constants juxtaposed
1678 with the kinds of objects.
1679
1680 We no longer talk about indirect updating due to parameter passing.
1681 Parameter passing is handled in 6.2 and 6.4.1 in a way that there
1682 is no need to mention it here in the definition of read and update.
1683 Reading and updating now includes the case of evaluating or
1684 assigning to an enclosing object.
1685 @end{DiffWord83}
1686
1687 @begin{DiffWord95}
1688 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]}
1689 @ChgAdded{Version=[2],Text=[Clarified that the return object is the object
1690 created by a function call.]}
1691 @end{DiffWord95}
1692
1693 @LabeledSubClause{Object Declarations}
1694
1695 @begin{Intro}
1696 @RootDefn{stand-alone object}
1697 @Defn{explicit initial value}
1698 @Defn{initialization expression}
1699 An @nt<object_declaration> declares a @i(stand-alone) object with a given
1700 nominal subtype and, optionally, an explicit initial
1701 value given by an initialization expression.
1702 @Defn{anonymous array type}
1703 @Defn{anonymous task type}
1704 @Defn{anonymous protected type}
1705 For an array, task, or protected object,
1706 the @nt<object_declaration> may include the definition
1707 of the (anonymous) type of the object.
1708 @end{Intro}
1709
1710 @begin{Syntax}
1711 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01],ARef=[AI95-00406-01]}
1712 @Syn{lhs=<object_declaration>,rhs="
1713 @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{subtype_indication} [:= @Syn2{expression}];@Chg{Version=[2],New=<
1714 | @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{access_definition} [:= @Syn2{expression}];>,Old=<>}
1715 | @Syn2{defining_identifier_list} : [@key{aliased}] [@key{constant}] @Syn2{array_type_definition} [:= @Syn2{expression}];
1716 | @Syn2{single_task_declaration}
1717 | @Syn2{single_protected_declaration}"}
1718
1719 @Syn{lhs=<defining_identifier_list>,rhs="
1720 @Syn2{defining_identifier} {, @Syn2{defining_identifier}}"}
1721 @end{Syntax}
1722
1723 @begin{Resolution}
1724 @PDefn2{Term=[expected type],
1725 Sec=(object_declaration initialization expression)}
1726 For an @nt<object_declaration> with an @nt<expression> following
1727 the compound delimiter :=,
1728 the type expected for
1729 the @nt<expression> is that of the object.
1730 @Defn{initialization expression}
1731 This @nt<expression> is called the @i(initialization expression).
1732 @IndexSee{Term=[constructor],See=[initialization expression]}
1733 @end{Resolution}
1734
1735 @begin{Legality}
1736 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00287-01]}
1737 An @nt<object_declaration> without the reserved word @key(constant)
1738 declares a variable object. If it has a @nt<subtype_indication> or
1739 an @nt<array_type_definition> that defines an indefinite subtype,
1740 then there shall be an initialization expression.@Chg{Version=[2],New=[],Old=[
1741 An initialization expression shall not be given if the object is
1742 of a limited type.]}
1743 @end{Legality}
1744
1745 @begin{StaticSem}
1746 An @nt<object_declaration> with the reserved word @key(constant)
1747 declares a constant object.
1748 @Defn{full constant declaration}
1749 If it has an initialization expression,
1750 then it is called a @i(full constant declaration).
1751 @Defn{deferred constant declaration}
1752 Otherwise it is called a @i(deferred constant declaration).
1753 The rules for deferred constant declarations are given in clause
1754 @RefSecNum(Deferred Constants). The rules for full constant declarations
1755 are given in this subclause.
1756
1757 Any declaration that includes a @nt{defining_identifier_list}
1758 with more than one @nt{defining_identifier}
1759 is equivalent to a series of declarations each containing one
1760 @nt{defining_identifier} from the list,
1761 with the rest of the text of the declaration copied for each
1762 declaration in the series, in the same order as the list.
1763 The remainder of this International Standard relies
1764 on this equivalence;
1765 explanations are given for
1766 declarations with a single @nt<defining_identifier>.
1767
1768 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
1769 @Defn{nominal subtype}
1770 The @nt<subtype_indication>@Chg{Version=[2],New=[, @nt{access_definition},],Old=[]}
1771 or full type definition of an
1772 @nt<object_declaration> defines the nominal subtype of the object.
1773 The @nt<object_declaration> declares an object of the type
1774 of the nominal subtype.
1775 @begin{Discussion}
1776 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
1777 The phrase @lquotes@;full type definition@rquotes@; here includes the
1778 case of an anonymous array, @Chg{Version=[2],New=[access, ],Old=[]}task, or
1779 protected type.
1780 @end{Discussion}
1781
1782 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
1783 @ChgAdded{Version=[2],Text=[@Defn{requires late initialization}
1784 A component of an object is said to
1785 @i{require late initialization} if it has an access discriminant value
1786 constrained by a per-object expression, or if it has an initialization
1787 expression that includes a name denoting the current instance of the type
1788 or denoting an access discriminant.]}
1789 @begin{Reason}
1790 @ChgRef{Version=[2],Kind=[AddedNormal]}
1791 @ChgAdded{Version=[2],Text=[Such components can depend on the values of
1792 other components of the object. We want to initialize them as late and as
1793 reproducibly as possible.]}
1794 @end{Reason}
1795 @end{StaticSem}
1796
1797 @begin{RunTime}
1798 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
1799 @Defn2{Term=[constraint], Sec=(of an object)}
1800 If a composite object declared by an
1801 @nt{object_declaration} has an unconstrained nominal subtype,
1802 then if this subtype is indefinite
1803 or the object is constant @Chg{Version=[2],New=[],
1804 Old=[or aliased (see @RefSecNum(Access Types)) ]}the
1805 actual subtype of this object is constrained.
1806 The constraint is determined
1807 by the bounds or discriminants (if any) of its initial value;
1808 @Defn{constrained by its initial value}
1809 the object is said to be @i(constrained by its initial value).
1810 @Defn2{Term=[actual subtype], Sec=(of an object)}
1811 @IndexSee{Term=[subtype (of an object)],See=(actual subtype of an object)}
1812 @Chg{Version=[2],New=[],
1813 Old=[@Redundant[In the case of an aliased object,
1814 this initial value may be either explicit or implicit;
1815 in the other cases, an explicit initial value is required.] ]}When
1816 not constrained by its initial value, the actual and nominal
1817 subtypes of the object are the same.
1818 @Defn2{Term=[constrained], Sec=(object)}
1819 @Defn2{Term=[unconstrained], Sec=(object)}
1820 If its actual subtype is constrained, the object
1821 is called a @i(constrained object).
1822
1823 @Leading@Defn2{Term=[implicit initial values], Sec=(for a subtype)}
1824 For an @nt<object_declaration> without an initialization expression,
1825 any initial values for the object or its subcomponents
1826 are determined by the @i(implicit initial values) defined for
1827 its nominal subtype, as follows:
1828 @begin(itemize)
1829 The implicit initial value for an access subtype is the
1830 null value of the access type.
1831
1832 The implicit initial (and only) value for each discriminant
1833 of a constrained discriminated subtype is defined by the subtype.
1834
1835 For a (definite) composite subtype,
1836 the implicit initial value of each component
1837 with a @nt<default_expression> is obtained by
1838 evaluation of this expression and conversion to the
1839 component's nominal subtype (which might raise
1840 Constraint_Error @em see @RefSec{Type Conversions}),
1841 unless the component is a
1842 discriminant of a constrained subtype (the previous case),
1843 or is in an excluded @nt<variant>
1844 (see @RefSecNum(Variant Parts and Discrete Choices)).
1845 @PDefn2{Term=[implicit subtype conversion],Sec=(component defaults)}
1846 For each component that does not have a @nt<default_expression>, any implicit
1847 initial values are those determined by the component's nominal subtype.
1848
1849 For a protected or task subtype, there is an implicit component
1850 (an entry queue) corresponding to each entry, with its implicit
1851 initial value being an empty queue.
1852 @begin(ImplNote)
1853 The implementation may add implicit components for its own use,
1854 which might have implicit initial values.
1855 For a task subtype, such components might represent the state
1856 of the associated thread of control. For a type with dynamic-sized
1857 components, such implicit components might be used to hold the offset to
1858 some explicit component.
1859 @end(ImplNote)
1860 @end(itemize)
1861
1862 @Leading@PDefn2{Term=[elaboration], Sec=(object_declaration)}
1863 The elaboration of an @nt{object_declaration} proceeds in the following
1864 sequence of steps:
1865 @begin(enumerate)
1866 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00385-01]}
1867 The @nt{subtype_@!indication},@Chg{Version=[2],New=[ @nt{access_@!definition},],Old=[]}
1868 @nt<array_@!type_@!definition>, @nt{single_@!task_@!declaration},
1869 or @nt{single_@!protected_@!declaration} is first elaborated.
1870 This creates the nominal subtype (and the anonymous type in the
1871 @Chg{Version=[2],New=[last four],Old=[latter three]} cases).
1872
1873 If the @nt<object_declaration> includes an initialization expression,
1874 the (explicit) initial value is obtained by evaluating the
1875 expression and converting it to the nominal subtype (which might
1876 raise Constraint_Error @em see @RefSecNum(Type Conversions)).
1877 @PDefn2{Term=[implicit subtype conversion],Sec=(initialization expression)}
1878
1879 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0002],ARef=[AI95-00171-01]}
1880 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
1881 The object is created, and, if there is not an initialization expression,
1882 @Chg{Version=[2],New=[the object is @i{initialized by default}.
1883 @Defn{initialized by default}When an object is initialized by
1884 default, ],Old=[]}any per-object @Chg{New=[constraints],Old=[expressions]}
1885 (see @RefSecNum(Record Types)) are
1886 @Chg{New=[elaborated], Old=[evaluated]} and any implicit initial values for
1887 the object or for its subcomponents are obtained as determined by
1888 the nominal subtype.@Chg{Version=[2],New=[
1889 @Defn2{Term=[initialization], Sec=(of an object)}
1890 @Defn2{Term=[assignment operation], Sec=(during elaboration of an @nt{object_declaration})}
1891 Any initial values (whether explicit or implicit) are assigned
1892 to the object or to the corresponding subcomponents.
1893 As described in @RefSecNum{Assignment Statements}
1894 and @RefSecNum{User-Defined Assignment and Finalization},
1895 Initialize and Adjust procedures can be called.
1896 @IndexSee{Term=[constructor],See=[initialization]}],Old=[]}
1897 @begin(Discussion)
1898 For a per-object constraint that contains some per-object
1899 expressions and some non-per-object expressions,
1900 the values used for the constraint consist of the values
1901 of the non-per-object expressions evaluated at the point
1902 of the @nt{type_declaration}, and the values of the per-object
1903 expressions evaluated at the point of the creation of the
1904 object.
1905
1906 The elaboration of per-object constraints was presumably performed
1907 as part of the dependent compatibility check in Ada 83.
1908 If the object is of a limited type
1909 with an access discriminant, the @nt<access_definition> is elaborated
1910 at this time (see @RefSecNum(Discriminants)).
1911 @end(Discussion)
1912 @begin{Reason}
1913 The reason we say that evaluating an explicit initialization
1914 expression happens before creating the object is that in some cases
1915 it is impossible to know the size of the object being created until
1916 its initial value is known, as in
1917 @lquotes@;X: String := Func_Call(...);@rquotes@;.
1918 The implementation can create the object early in the
1919 common case where the size can be known early,
1920 since this optimization is semantically neutral.
1921 @end{Reason}
1922
1923 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00373-01]}
1924 @ChgDeleted{Version=[2],Text=[@Defn2{Term=[initialization], Sec=(of an object)}
1925 @Defn2{Term=[assignment operation], Sec=(during elaboration of an @nt{object_declaration})}
1926 Any initial values (whether explicit or implicit) are assigned
1927 to the object or to the corresponding subcomponents.
1928 As described in @RefSecNum{Assignment Statements}
1929 and @RefSecNum{User-Defined Assignment and Finalization},
1930 Initialize and Adjust procedures can be called.
1931 @IndexSee{Term=[constructor],See=[initialization]}]}
1932 @begin(Ramification)
1933 Since the initial values have already been converted to the appropriate
1934 nominal subtype, the only Constraint_Errors that might
1935 occur as part of these assignments are for values outside their
1936 base range that are used to initialize unconstrained numeric
1937 subcomponents. See @RefSecNum{Scalar Types}.
1938 @end(Ramification)
1939 @end(enumerate)
1940
1941 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00373-01]}
1942 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Just to get conditional Leading here.}
1943 For the third step above, @Chg{Version=[2],New=[],Old=[the object creation and
1944 any elaborations and ]}evaluations @Chg{Version=[2],New=[and assignments ],Old=[]}are
1945 performed in an arbitrary
1946 order@Chg{Version=[2],New=[ subject to the following restrictions:],Old=[,
1947 except that if the @nt<default_expression> for a discriminant is
1948 evaluated to obtain its initial value, then this evaluation
1949 is performed before that of
1950 the @nt<default_expression> for any component that depends on the
1951 discriminant,
1952 and also before that of any @nt<default_expression> that
1953 includes the name of the discriminant.
1954 The evaluations of the third step and the assignments of the fourth step
1955 are performed in an arbitrary order,
1956 except that each evaluation is performed before the resulting value is
1957 assigned.]}
1958 @begin(Itemize)
1959
1960 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
1961 @ChgAdded{Version=[2],Text=[Assignment to any part of the object
1962 is preceded by the evaluation of the value that is to be assigned.]}
1963 @begin{Reason}
1964 @ChgRef{Version=[2],Kind=[Added]}
1965 @ChgAdded{Version=[2],Text=[Duh. But we ought to say it. Note that, like
1966 any rule in the International Standard, it doesn't prevent
1967 an @lquotes@;as-if@rquotes optimization; as long as the semantics as observed
1968 from the program are correct, the compiler can generate any code it wants.]}
1969 @end{Reason}
1970 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
1971 @ChgAdded{Version=[2],Text=[The evaluation of a @nt{default_expression} that
1972 includes the name of a discriminant is preceded by the assignment to that
1973 discriminant.]}
1974 @begin{Reason}
1975 @ChgRef{Version=[2],Kind=[Added]}
1976 @ChgAdded{Version=[2],Text=[Duh again. But we have to say this, too. It's
1977 odd that Ada 95 only required the default expressions to be evaluated before
1978 the discriminant is used; it says nothing about discriminant values that
1979 come from @nt{subtype_indication}s.]}
1980 @end{Reason}
1981 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
1982 @ChgAdded{Version=[2],Text=[The evaluation of the @nt{default_expression}
1983 for any component that depends on a discriminant is preceded by the assignment
1984 to that discriminant.]}
1985 @begin{Reason}
1986 @Leading@keepnext@;For example:
1987 @begin{Example}
1988 @key[type] R(D : Integer := F) @key[is]
1989 @key[record]
1990 S : String(1..D) := (@key[others] => G);
1991 @key[end] @key[record];
1992
1993 X : R;
1994 @end{Example}
1995
1996 For the elaboration of the declaration of X,
1997 it is important that F be evaluated before the aggregate.
1998 @end{Reason}
1999
2000 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00373-01]}
2001 @ChgAdded{Version=[2],Text=[The assignments to any components, including
2002 implicit components, not requiring late initialization must precede the
2003 initial value evaluations for any components requiring late initialization;
2004 if two components both require late initialization, then assignments to parts
2005 of the component occurring earlier in the order of the component declarations
2006 must precede the initial value evaluations of the component occurring later.]}
2007 @begin{Reason}
2008 @ChgRef{Version=[2],Kind=[AddedNormal]}
2009 @ChgAdded{Version=[2],Type=[Leading],Text=[Components that require late
2010 initialization can refer to the entire object during their initialization.
2011 We want them to be initialized as late as possible to reduce the chance
2012 that their initialization depends on uninitialized components. For instance:]}
2013 @begin{Example}
2014 @ChgRef{Version=[2],Kind=[AddedNormal]}
2015 @ChgAdded{Version=[2],Text=[@key{type} T (D : Natural) @key{is}
2016 @key{limited record}
2017 C1 : T1 (T'Access);
2018 C2 : Natural := F (D);
2019 C3 : String (1 .. D) := (others => ' ');
2020 @key{end record};]}
2021 @end{Example}
2022 @ChgRef{Version=[2],Kind=[AddedNormal]}
2023 @ChgAdded{Version=[2],Text=[Component C1 requires late initialization. The
2024 initialization could depend on the values of any component of T, including D,
2025 C2, or C3. Therefore, we want to it to be initialized last. Note that C2 and
2026 C3 do not require late initialization; they only have to be initialized after
2027 D.]}
2028
2029 @ChgRef{Version=[2],Kind=[AddedNormal]}
2030 @ChgAdded{Version=[2],Text=[It is possible for there to be more than one
2031 component that requires late initialization. In this case, the language can't
2032 prevent problems, because all of the components can't be the last one
2033 initialized. In this case, we specify the order of initialization for
2034 components requiring late initialization; by doing so, programmers can
2035 arrange their code to avoid accessing uninitialized components, and such
2036 arrangements are portable. Note that if the program accesses an uninitialized
2037 component, @RefSecNum{Data Validity} defines the execution to be erroneous.]}
2038 @end{Reason}
2039 @end{Itemize}
2040
2041 @Redundant[There is no implicit initial
2042 value defined for a scalar subtype.]
2043 @PDefn{uninitialized variables}
2044 In the absence of an explicit initialization, a newly created
2045 scalar object might have a value that does not belong to its subtype
2046 (see @RefSecNum{Data Validity} and @RefSecNum{Pragma Normalize_Scalars}).
2047 @begin{Honest}
2048 It could even be represented by a bit pattern that doesn't
2049 actually represent any value of the type at all,
2050 such as an invalid internal code for an enumeration type,
2051 or a NaN for a floating point type.
2052 It is a generally a bounded error to reference scalar objects with
2053 such @lquotes@;invalid representations@rquotes@;, as explained in
2054 @RefSec{Data Validity}.
2055 @end{Honest}
2056 @begin{Ramification}
2057 There is no requirement that two objects of the same scalar subtype have
2058 the same implicit initial @lquotes@;value@rquotes@; (or representation).
2059 It might even be the case that two elaborations of the same
2060 @nt{object_declaration} produce two different initial values.
2061 However, any particular uninitialized object is default-initialized to a
2062 single value (or invalid representation).
2063 Thus, multiple reads of such an uninitialized object will produce the
2064 same value each time
2065 (if the implementation chooses not to detect the error).
2066 @end{Ramification}
2067 @end{RunTime}
2068
2069 @begin{Notes}
2070 Implicit initial values are not defined
2071 for an indefinite subtype,
2072 because if an object's nominal subtype is indefinite,
2073 an explicit initial value is required.
2074
2075 @Defn{stand-alone constant}
2076 @Defn{stand-alone variable}
2077 As indicated above,
2078 a stand-alone object is an object declared by an @nt<object_declaration>.
2079 Similar definitions apply to
2080 @lquotes@;stand-alone constant@rquotes@; and @lquotes@;stand-alone variable.@rquotes@;
2081 A subcomponent of an object is not a stand-alone object,
2082 nor is an object that is created by an @nt<allocator>.
2083 An object declared by a
2084 @nt<loop_parameter_specification>, @nt<parameter_specification>,
2085 @nt<entry_index_specification>, @nt<choice_parameter_specification>,
2086 or a @nt<formal_object_declaration> is not called a
2087 stand-alone object.
2088
2089 The type of a stand-alone object cannot
2090 be abstract (see @RefSecNum{Abstract Types and Subprograms}).
2091 @end{Notes}
2092
2093 @begin{Examples}
2094 @Leading@keepnext@i(Example of a multiple object declaration:)
2095 @begin(Example)
2096 --@RI[ the multiple object declaration ]
2097
2098 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
2099 John, Paul : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M); --@RI[ see @RefSecNum(Incomplete Type Declarations)]
2100
2101 --@RI[ is equivalent to the two single object declarations in the order given]
2102
2103 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
2104 John : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M);
2105 Paul : @Chg{Version=[2],New=[@key{not null} ],Old=[]}Person_Name := @key(new) Person(Sex => M);
2106 @end(Example)
2107
2108 @begin{Wide}
2109 @leading@keepnext@i(Examples of variable declarations:)
2110 @end{Wide}
2111 @begin(Example)
2112 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
2113 Count, Sum : Integer;
2114 Size : Integer @key(range) 0 .. 10_000 := 0;
2115 Sorted : Boolean := False;
2116 Color_Table : @key(array)(1 .. Max) @key(of) Color;
2117 Option : Bit_Vector(1 .. 10) := (@key(others) => True);
2118 Hello : @Chg{Version=[2],New=[@key(aliased)],Old=[@key(constant)]} String := "Hi, world.";@Chg{Version=[2],New=[
2119 @unicode(952), @unicode(966) : Float @b<range> -@pi .. +@pi;],Old=[]}
2120 @end(Example)
2121
2122 @begin{Wide}
2123 @leading@keepnext@i(Examples of constant declarations:)
2124 @end{Wide}
2125 @begin(Example)
2126 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
2127 Limit : @key(constant) Integer := 10_000;
2128 Low_Limit : @key(constant) Integer := Limit/10;
2129 Tolerance : @key(constant) Real := Dispersion(1.15);@Chg{Version=[2],New=[
2130 Hello_Msg : @key(constant access) String := Hello'Access; --@RI[ see @RefSecNum{Operations of Access Types}]],Old=[]}
2131 @end(Example)
2132 @end{Examples}
2133
2134 @begin{Extend83}
2135 @Defn{extensions to Ada 83}
2136 The syntax rule for @nt{object_declaration} is modified to allow the
2137 @key{aliased} reserved word.
2138
2139 A variable declared by an @nt<object_declaration> can be constrained
2140 by its initial value; that is, a variable of a nominally unconstrained
2141 array subtype, or discriminated type without defaults, can
2142 be declared so long as it has an explicit initial value.
2143 In Ada 83, this was permitted for constants, and for variables
2144 created by allocators, but not for variables declared by
2145 @nt<object_declaration>s. This is particularly important
2146 for tagged class-wide types, since there is no way to constrain
2147 them explicitly, and so an initial value is the only way
2148 to provide a constraint. It is also important for generic formal
2149 private types with unknown discriminants.
2150
2151 We now allow an @nt{unconstrained_array_definition}
2152 in an @nt{object_declaration}.
2153 This allows an object of an anonymous array type to have its
2154 bounds determined by its initial value.
2155 This is for uniformity: If one can write @lquotes@;X: @key[constant]
2156 @key[array](Integer @key[range] 1..10) @key[of] Integer := ...;@rquotes@; then
2157 it makes sense to also allow
2158 @lquotes@;X: @key[constant] @key[array](Integer @key[range] <>) @key[of] Integer := ...;@rquotes@;.
2159 (Note that if anonymous array types are
2160 ever sensible, a common situation is for a table implemented as an array.
2161 Tables are often constant, and for constants, there's usually no point in
2162 forcing the user to count the number of elements in the value.)
2163 @end{Extend83}
2164
2165 @begin{DiffWord83}
2166 We have moved the syntax for @nt{object_declaration}s into this subclause.
2167
2168 Deferred constants no longer have a separate syntax rule, but rather
2169 are incorporated in @nt<object_declaration> as constants declared
2170 without an initialization expression.
2171 @end{DiffWord83}
2172
2173 @begin{Inconsistent95}
2174 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
2175 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
2176 Unconstrained aliased objects of types
2177 with discriminants with defaults are no longer
2178 constrained by their initial values. This means that a program that
2179 raised Constraint_Error from an attempt to change the discriminants
2180 will no longer do so. The change only affects programs that depended
2181 on the raising of Constraint_Error in this case, so the inconsistency
2182 is unlikely to occur outside of the ACATS. This change may however cause
2183 compilers to implement these objects differently, possibly taking additional
2184 memory or time. This is unlikely to be worse than the differences caused by
2185 any major compiler upgrade.]}
2186 @end{Inconsistent95}
2187
2188 @begin{Extend95}
2189 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00287-01]}
2190 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2191 A constant may have a limited type; the initialization @nt{expression}
2192 has to be built-in-place (see @RefSecNum{Limited Types}).]}
2193
2194 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00385-01],ARef=[AI95-00406-01]}
2195 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2196 A stand-alone object may have an anonymous access type.]}
2197 @end{Extend95}
2198
2199 @begin{DiffWord95}
2200 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0002],ARef=[AI95-00171-01]}
2201 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected wording to say that
2202 per-object constraints are elaborated (not evaluated).]}
2203
2204 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00373-01]}
2205 @ChgAdded{Version=[2],Text=[The rules for evaluating default initialization
2206 have been tightened. In particular, components whose default initialization
2207 can refer to the rest of the object are required to be initialized last.]}
2208
2209 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
2210 @ChgAdded{Version=[2],Text=[Added examples of various new constructs.]}
2211 @end{DiffWord95}
2212
2213
2214 @LabeledSubClause{Number Declarations}
2215
2216 @begin{Intro}
2217 A @nt<number_declaration> declares a named number.
2218 @begin{Discussion}
2219 @Defn{static}
2220 If a value or other property of a construct is required to be
2221 @i(static) that means it is required to be determined prior
2222 to execution. A @i(static) expression is an expression
2223 whose value is computed
2224 at compile time and is usable in contexts where the actual value
2225 might affect the legality of the construct.
2226 This is fully defined in clause
2227 @RefSecNum(Static Expressions and Static Subtypes).
2228 @end{Discussion}
2229 @end{Intro}
2230
2231 @begin{Syntax}
2232 @Syn{lhs=<number_declaration>,rhs="
2233 @Syn2{defining_identifier_list} : @key{constant} := @SynI{static_}@Syn2{expression};"}
2234 @end{Syntax}
2235
2236 @begin{Resolution}
2237 @PDefn2{Term=[expected type],
2238 Sec=(number_declaration expression)}
2239 The @SynI(static_)@nt{expression} given for
2240 a @nt{number_declaration} is expected to be of any numeric type.
2241 @end{Resolution}
2242
2243 @begin{Legality}
2244 The @i(static_)@nt{expression} given for a number declaration
2245 shall be a static expression, as defined by clause
2246 @RefSecNum(Static Expressions and Static Subtypes).
2247 @end{Legality}
2248
2249 @begin{StaticSem}
2250 The named number denotes a value of type @i(universal_integer) if
2251 the type of the @i(static_)@!@nt{expression} is an integer type.
2252 The named number denotes a value of type @i(universal_real) if
2253 the type of the @i(static_)@!@nt{expression} is a real type.
2254
2255 The value denoted by the named number is the value of the
2256 @i(static_)@nt{expression}, converted to the corresponding
2257 universal type.
2258 @PDefn2{Term=[implicit subtype conversion],Sec=(named number value)}
2259 @end{StaticSem}
2260
2261 @begin{RunTime}
2262 @PDefn2{Term=[elaboration], Sec=(number_declaration)}
2263 The elaboration of a @nt<number_declaration> has no effect.
2264 @begin(TheProof)
2265 Since the @i(static_)@nt<expression> was evaluated at compile time.
2266 @end(TheProof)
2267 @end{RunTime}
2268
2269 @begin{Examples}
2270 @Leading@keepnext@i(Examples of number declarations:)
2271 @begin(Example)
2272 Two_Pi : @key(constant) := 2.0*Ada.Numerics.Pi; --@RI[ a real number (see @RefSecNum{The Numerics Packages})]
2273
2274 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
2275 Max : @key(constant) := 500; --@RI[ an integer number]
2276 Max_Line_Size : @key(constant) := Max/6@Chg{Version=[2],New=[;],Old=[ ]} --@RI[ the integer 83]
2277 Power_16 : @key(constant) := 2**16; --@RI[ the integer 65_536]
2278 One, Un, Eins : @key(constant) := 1; --@RI[ three different names for 1]
2279 @end(Example)
2280 @end{Examples}
2281
2282 @begin{Extend83}
2283 @Defn{extensions to Ada 83}
2284 We now allow a static expression of any numeric type
2285 to initialize a named
2286 number. For integer types, it was possible in Ada 83
2287 to use 'Pos to define a named number, but there was
2288 no way to use a static expression of some non-universal
2289 real type to define a named number. This change is
2290 upward compatible because of the preference rule for
2291 the operators of the root numeric types.
2292 @end{Extend83}
2293
2294 @begin{DiffWord83}
2295 We have moved the syntax rule into this subclause.
2296
2297 AI83-00263 describes the elaboration of a number declaration
2298 in words similar to that of an @nt{object_declaration}. However, since
2299 there is no expression to be evaluated and no object to be created,
2300 it seems simpler to say that the elaboration has no effect.
2301 @end{DiffWord83}
2302
2303
2304 @LabeledClause{Derived Types and Classes}
2305
2306 @begin{Intro}
2307 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01],ARef=[AI95-00419-01]}
2308 @Defn{derived type}
2309 A @nt<derived_type_definition> defines a @Chg{Version=[2],
2310 New=[@i{derived type}],Old=[new type]} (and its first subtype)
2311 whose characteristics are @i(derived) from those of a
2312 @Chg{Version=[2],New=[parent type, and possibly from progenitor types],
2313 Old=[@i(parent type)]}.
2314 @IndexSee{Term=[inheritance],See=[derived types and classes]}
2315 @ChgToGlossary{Version=[2],Kind=[Revised],Term=<Derived type>,
2316 Text=<A derived type is a type defined in terms of @Chg{Version=[2],
2317 New=[one or more other types given in a derived type definition. The
2318 first of those types],Old=[another type, which]}
2319 is the parent type of the derived type@Chg{Version=[2],New=[ and
2320 any others are progenitor types],Old=[]}.
2321 Each class containing the parent type @Chg{Version=[2],New=[or a progenitor
2322 type ],Old=[]}also contains the derived type.
2323 The derived type inherits properties such as components and
2324 primitive operations from the parent@Chg{Version=[2],New=[ and progenitors],Old=[]}.
2325 A type together with the types derived from it
2326 (directly or indirectly) form a derivation class.>}
2327
2328 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00442-01]}
2329 @ChgAdded{Version=[2],Text=[@Defn2{Term=[class],Sec=[of types]}
2330 @Defn2{Term=[category],Sec=[of types]}
2331 A @i<class of types> is a set of types that is closed under
2332 derivation; that is, if the parent or a progenitor type of a
2333 derived type belongs to a class, then so does the derived type.
2334 By saying that a particular group of types forms a class,
2335 we are saying that all derivatives of a type in the set inherit
2336 the characteristics that define that set. The
2337 more general term @i<category of types> is used for a set of types
2338 whose defining characteristics are not necessarily inherited by
2339 derivatives; for example, limited, abstract, and interface are all
2340 categories of types, but not classes of types.]}
2341
2342 @begin{Ramification}
2343 @ChgRef{Version=[2],Kind=[AddedNormal]}
2344 @ChgAdded{Version=[2],Text=[A class of types is also a category of types.]}
2345 @end{Ramification}
2346
2347 @end{Intro}
2348
2349 @begin{Syntax}
2350 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00419-01]}
2351 @Syn{lhs=<derived_type_definition>,rhs="@Chg{Version=[2],New=<
2352 >,Old=<>}[@key{abstract}] @Chg{Version=[2],New=<[@key{limited}] >,Old=<>}@key{new} @SynI{parent_}@Syn2{subtype_indication} [@Chg{Version=[2],New=<[@key{and} @Syn2{interface_list}] >,Old=<>}@Syn2{record_extension_part}]"}
2353 @end{Syntax}
2354
2355 @begin{Legality}
2356 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01],ARef=[AI95-00419-01]}
2357 @Defn{parent subtype}
2358 @Defn{parent type}
2359 The @Syni(parent_)@nt<subtype_indication> defines the @i(parent subtype);
2360 its type is the @Chg{Version=[2],New=[@i(parent type)],Old=[parent type]}.
2361 @Chg{Version=[2],New=[The @nt{interface_list} defines the progenitor types
2362 (see @RefSecNum{Interface Types}). A derived type
2363 has one parent type and zero or more progenitor types.],Old=[]}
2364
2365 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Parent>,
2366 Text=<@ChgAdded{Version=[2],Text=[The parent of a derived type is the
2367 first type given in the definition of the derived type. The parent
2368 can be almost any kind of type, including an interface type.]}>}
2369
2370
2371 A type shall be completely defined
2372 (see @RefSecNum(Completions of Declarations))
2373 prior to being specified as the parent type
2374 in a @nt<derived_type_definition> @em @Redundant[the
2375 @nt<full_type_declaration>s for the parent
2376 type and any of its subcomponents have to
2377 precede the @nt<derived_type_definition>.]
2378 @begin{Discussion}
2379 This restriction does not apply to the ancestor type of a private
2380 extension @em see @RefSecNum(Private Types and Private Extensions);
2381 such a type need not be completely defined prior to the
2382 @nt<private_extension_declaration>. However, the restriction
2383 does apply to record extensions, so the ancestor type will
2384 have to be completely defined prior to the @nt<full_type_declaration>
2385 corresponding to the @nt<private_extension_declaration>.
2386 @end{Discussion}
2387 @begin{Reason}
2388 We originally hoped we could relax this restriction.
2389 However, we found it too complex to specify the rules for
2390 a type derived from an incompletely defined limited type that
2391 subsequently became nonlimited.
2392 @end{Reason}
2393
2394 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2395 @Defn{record extension}
2396 If there is a @nt<record_extension_part>, the derived type is
2397 called a @i(record extension) of the parent type.
2398 A @nt<record_extension_part> shall be provided if and only if
2399 the parent type is a tagged type.@Chg{Version=[2],New=[ @Redundant[An
2400 @nt{interface_list} shall be provided only if
2401 the parent type is a tagged type.]],Old=[]}
2402 @begin(TheProof)
2403 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00401-01]}
2404 @ChgAdded{Version=[2],Text=[The syntax only allows an @nt{interface_list}
2405 to appear with a @nt{record_extension_part}, and a @nt{record_extension_part}
2406 can only be provided if the parent type is a tagged type. We give the last
2407 sentence anyway for completeness.]}
2408 @end(TheProof)
2409 @begin(ImplNote)
2410 We allow a record extension to inherit discriminants;
2411 an early version of Ada 9X did not.
2412 If the parent subtype is unconstrained, it can be implemented
2413 as though its discriminants were repeated in a new
2414 @nt{known_discriminant_part} and then used to constrain the old ones
2415 one-for-one.
2416 However, in an extension aggregate, the discriminants in this case
2417 do not appear in the component association list.
2418 @end(ImplNote)
2419 @begin{Ramification}
2420 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
2421 @ChgAdded{Version=[2],Type=[Leading],Text=[]}@Comment{Conditional leading}
2422 This rule needs to be rechecked in the visible
2423 part of an instance of a generic unit@Chg{Version=[2],New=[ because of the
2424 @lquotes@;only if@rquotes@; part of the rule. For example:],Old=[]}
2425 @begin{Example}
2426 @ChgRef{Version=[2],Kind=[AddedNormal]}
2427 @ChgAdded{Version=[2],Text=[@key{generic}
2428 @key{type} T @key{is private};
2429 @key{package} P @key{is}
2430 @key{type} Der @key{is new} T;
2431 @key{end} P;]}
2432
2433 @ChgRef{Version=[2],Kind=[AddedNormal]}
2434 @ChgAdded{Version=[2],Text=[@key{package} I @key{is new} P (Some_Tagged_Type); -- @RI[illegal]]}
2435 @end{Example}
2436 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00114-01]}
2437 @ChgAdded{Version=[2],Text=[The instantiation is illegal because a tagged
2438 type is being extended in the visible part without a
2439 @nt{record_extension_part}. Note that this is legal in the private part or
2440 body of an instance, both to avoid a contract model violation, and because
2441 no code that can see that the type is actually tagged can also see the
2442 derived type declaration.]}
2443
2444 @ChgRef{Version=[2],Kind=[AddedNormal]}
2445 @ChgAdded{Version=[2],Text=[No recheck is needed for derived types with
2446 a @nt{record_extension_part}, as that has to be derived from something that
2447 is known to be tagged (otherwise the template is illegal).]}
2448 @end{Ramification}
2449
2450 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00419-01]}
2451 @ChgAdded{Version=[2],Text=[If the reserved word @key{limited} appears in a
2452 @nt{derived_type_definition}, the parent type shall be a limited type.]}
2453 @begin{Reason}
2454 @ChgRef{Version=[2],Kind=[AddedNormal]}
2455 @ChgAdded{Version=[2],Text=[We allow @key{limited} because we don't inherit
2456 limitedness from interfaces, so we must have a way to derive a limited type
2457 from interfaces. The word @key{limited} has to be legal when the parent
2458 @i{could be} an interface, and that includes generic formal abstract types.
2459 Since we have to allow it in this case, we might as well allow it everywhere
2460 as documentation, to make it explicit that the type is limited.]}
2461
2462 @ChgRef{Version=[2],Kind=[AddedNormal]}
2463 @ChgAdded{Version=[2],Text=[However, we do not want to allow @key{limited}
2464 when the parent is nonlimited: limitedness cannot change in a derivation
2465 tree.]}
2466 @end{Reason}
2467 @end{Legality}
2468
2469 @begin{StaticSem}
2470 @Defn2{Term=[constrained], Sec=(subtype)}
2471 @Defn2{Term=[unconstrained], Sec=(subtype)}
2472 The first subtype of the derived type is
2473 unconstrained if a @nt{known_discriminant_part}
2474 is provided in the declaration of the derived type, or if the
2475 parent subtype is unconstrained.
2476 @Defn{corresponding constraint}
2477 Otherwise, the constraint
2478 of the first subtype @i(corresponds) to that of the parent subtype
2479 in the following sense: it is the same as that of the parent subtype
2480 except that for a range constraint (implicit or explicit), the value of
2481 each bound of its range is replaced by the corresponding value
2482 of the derived type.
2483 @begin(Discussion)
2484 A @nt<digits_constraint> in a @nt<subtype_indication> for
2485 a decimal fixed point subtype always imposes a range constraint,
2486 implicitly if there is no explicit one given.
2487 See @RefSec(Fixed Point Types).
2488 @end(Discussion)
2489
2490 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01]}
2491 @ChgAdded{Version=[2],Text=[The first subtype of the derived type excludes null
2492 (see @RefSecNum{Access Types}) if and only if the parent subtype excludes null.]}
2493
2494 @Leading@keepnext@;The characteristics of the derived type are defined as follows:
2495 @begin(itemize)
2496 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01],ARef=[AI95-00442-01]}
2497 @Chg{Version=[2],New=[@Redundant[If the parent type or a progenitor type
2498 belongs to a class of types, then the derived type also belongs to that class.]
2499 The following sets of types, as well as any higher-level sets composed from
2500 them, are classes in this sense@Redundant[, and hence the characteristics
2501 defining these classes are inherited by derived types from their parent or
2502 progenitor types]: signed integer, modular integer, ordinary fixed, decimal
2503 fixed, floating point, enumeration, boolean, character, access-to-constant,
2504 general access-to-variable, pool-specific access-to-variable,
2505 access-to-subprogram, array, string, non-array composite, nonlimited, untagged
2506 record, tagged, task, protected, and synchronized tagged],
2507 Old=[Each class of types that includes the parent type also includes
2508 the derived type]}.
2509 @begin{Discussion}
2510 This is inherent in our notion
2511 of a @lquotes@;class@rquotes@; of types. It is not mentioned in the
2512 initial definition of @lquotes@;class@rquotes@; since at that point
2513 type derivation has not been defined. In any case, this rule
2514 ensures that every class of types is closed under
2515 derivation.
2516 @end{Discussion}
2517
2518 If the parent type is an elementary type or an array type, then the
2519 set of possible values of the derived type
2520 is a copy of the set of possible values of the parent type.
2521 For a scalar type, the base range of the derived type is the same
2522 as that of the parent type.
2523 @begin{Discussion}
2524 The base range of a type defined by an @nt<integer_type_definition>
2525 or a @nt<real_type_definition> is determined by the @ntf<_definition>,
2526 and is not necessarily the same as that of the corresponding
2527 root numeric type from which the newly defined type is implicitly
2528 derived. Treating numerics types as implicitly derived from one of
2529 the two root numeric types is simply to link them into a type hierarchy;
2530 such an implicit derivation does not follow all the rules given here
2531 for an explicit @nt<derived_type_definition>.
2532 @end{Discussion}
2533
2534 If the parent type is a composite type other than an array type,
2535 then the components,
2536 protected subprograms, and entries
2537 that are declared for the derived type are as follows:
2538 @begin(inneritemize)
2539 The discriminants specified by a new @nt{known_discriminant_part},
2540 if there is one;
2541 otherwise, each discriminant of the parent type
2542 (implicitly declared in the same order with the same specifications) @em
2543 @Defn{inherited discriminant}
2544 @Defn{inherited component}
2545 in the latter case, the discriminants are said to be @i(inherited),
2546 or if unknown in the parent, are also unknown in the derived type;
2547
2548 Each nondiscriminant component, entry, and protected subprogram
2549 of the parent type, implicitly declared in the same order
2550 with the same declarations;
2551 @Defn{inherited component}
2552 @Defn{inherited protected subprogram}
2553 @Defn{inherited entry}
2554 these components, entries, and protected subprograms are said to be @i(inherited);
2555 @begin{Ramification}
2556
2557 The profiles of entries and protected subprograms do
2558 not change upon type derivation, although the type of the
2559 @lquotes@;implicit@rquotes@; parameter identified by the @nt<prefix> of
2560 the @nt<name> in a call does.@end{ramification}
2561 @begin{Honest}
2562
2563 Any name in the parent @nt{type_declaration} that denotes the
2564 current instance of the type is replaced with a name denoting the
2565 current instance of the derived type, converted to the parent type.
2566
2567 @end{Honest}
2568
2569 Each component declared in a
2570 @nt<record_extension_part>, if any.
2571 @end(inneritemize)
2572
2573 @noprefix@;Declarations of components, protected subprograms,
2574 and entries, whether implicit or explicit,
2575 occur immediately within the declarative region of
2576 the type, in the order indicated above,
2577 following the parent @nt<subtype_indication>.
2578 @begin(Discussion)
2579 The order of declarations within the region matters
2580 for @nt{record_aggregate}s and @nt<extension_aggregate>s.
2581 @end(Discussion)
2582 @begin{Ramification}
2583 In most cases, these things are implicitly declared
2584 @i{immediately} following the parent @nt<subtype_indication>.
2585 However, @RefSec{Private Operations} defines some cases in which
2586 they are implicitly declared later, and some cases in which
2587 the are not declared at all.
2588 @end{Ramification}
2589 @begin{Discussion}
2590 The place of the implicit declarations of inherited components matters
2591 for visibility @em they are not visible in the
2592 @nt<known_discriminant_part> nor in the parent @nt<subtype_indication>,
2593 but are usually visible within the
2594 @nt<record_extension_part>, if any
2595 (although there are restrictions on their use).
2596 Note that a discriminant specified in a new
2597 @nt<known_discriminant_part> is
2598 not considered @lquotes@;inherited@rquotes@; even if it has the same name
2599 and subtype as a discriminant of the parent type.
2600 @end{Discussion}
2601
2602 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00419-01]}
2603 @ChgDeleted{Version=[2],Text=[The derived type is limited if and
2604 only if the parent type is limited.]}
2605 @ChgNote{This rule is normatively in 7.5, and we don't want it scattered
2606 everywhere.}
2607 @begin{Honest}
2608 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00419-01]}
2609 @ChgDeleted{Version=[2],Text=[The derived type can become nonlimited if
2610 the derivation takes place in the visible part of a child package,
2611 and the parent type is nonlimited as viewed from the
2612 private part of the child package @em see @RefSecNum(Limited Types).]}
2613 @end{Honest}
2614
2615 @Redundant[For each predefined operator of the parent type,
2616 there is a corresponding predefined operator of the derived type.]
2617 @begin(TheProof)
2618 This is a ramification of the fact that each class that includes
2619 the parent type also includes the derived type,
2620 and the fact that the set of predefined operators that is defined for
2621 a type, as described in
2622 @RefSecNum(Operators and Expression Evaluation), is determined by
2623 the classes to which it belongs.
2624 @end(TheProof)
2625 @begin(Reason)
2626 Predefined operators are handled separately because
2627 they follow a slightly different rule
2628 than user-defined primitive subprograms. In particular
2629 the systematic replacement described below does not apply fully to the
2630 relational operators for Boolean and the exponentiation
2631 operator for Integer. The relational operators for a type
2632 derived from Boolean still return Standard.Boolean. The
2633 exponentiation operator for a type derived from Integer
2634 still expects Standard.Integer for the right operand.
2635 In addition, predefined operators "reemerge" when a type
2636 is the actual type corresponding to a generic formal type,
2637 so they need to be well defined even if hidden by user-defined
2638 primitive subprograms.
2639 @end(Reason)
2640
2641 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2642 @Defn{inherited subprogram}
2643 For each user-defined primitive subprogram (other than a user-defined
2644 equality operator @em see below) of the parent type@Chg{Version=[2],New=[ or of a
2645 progenitor type],Old=[]} that already exists at the place of the
2646 @nt{derived_type_definition}, there exists a corresponding @i(inherited)
2647 primitive subprogram of the derived type
2648 with the same defining name.
2649 @Defn2{Term=[equality operator],Sec=(special inheritance rule for tagged types)}
2650 Primitive user-defined equality operators of the parent
2651 type@Chg{Version=[2],New=[ and any progenitor types],Old=[]} are also
2652 inherited by the derived type, except when
2653 the derived type is a nonlimited record extension, and
2654 the inherited operator would have a profile that is type
2655 conformant with the profile of the corresponding
2656 predefined equality operator; in this case, the user-defined
2657 equality operator is not inherited, but is rather incorporated into
2658 the implementation of the predefined equality operator of the record extension
2659 (see @RefSecNum(Relational Operators and Membership Tests)).
2660 @PDefn{type conformance}
2661 @begin{Ramification}
2662 We say @lquotes@;...already exists...@rquotes@; rather than @lquotes@;is visible@rquotes@; or @lquotes@;has
2663 been declared@rquotes@; because there are certain operations that are declared
2664 later, but still exist at the place of the
2665 @nt{derived_type_definition},
2666 and there are operations that are never declared, but still exist.
2667 These cases are explained in @RefSecNum{Private Operations}.
2668
2669 Note that nonprivate extensions can appear only after the last
2670 primitive subprogram of the parent @em the freezing rules ensure this.
2671 @end{Ramification}
2672 @begin{Reason}
2673 A special case is made for the equality operators on nonlimited
2674 record extensions
2675 because their predefined equality operators are already defined in terms
2676 of the primitive equality operator of their parent type (and of the
2677 tagged components of the extension part). Inheriting the parent's
2678 equality operator as is would be undesirable, because it would ignore
2679 any components of the extension part.
2680 On the other hand, if the parent type is limited, then any user-defined
2681 equality operator is inherited as is, since there is no predefined
2682 equality operator to take its place.
2683 @end{Reason}
2684 @begin{Ramification}
2685 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
2686 Because user-defined equality operators are not inherited
2687 by @Chg{Version=[2],New=[nonlimited ],Old=[]}record extensions, the
2688 formal parameter names of = and /=
2689 revert to Left and Right, even if different formal parameter names
2690 were used in the user-defined equality operators of the parent type.
2691 @end{Ramification}
2692 @begin{Discussion}
2693 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00401-01]}
2694 @ChgAdded{Version=[2],Text=[This rule only describes what operations
2695 are inherited; the rules that describe what happens when there are
2696 conflicting inherited subprograms are found in @RefSecNum{Visibility}.]}
2697 @end{Discussion}
2698
2699 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2700 @noprefix@;The profile of an inherited subprogram
2701 (including an inherited enumeration literal) is obtained
2702 from the profile of the corresponding
2703 (user-defined) primitive subprogram of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]}
2704 type, after systematic replacement of each
2705 subtype of its profile (see @RefSecNum{Subprogram Declarations})
2706 that is of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]} type
2707 with a @i(corresponding subtype) of the derived type.
2708 @Defn{corresponding subtype}
2709 For a given subtype of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]} type,
2710 the corresponding subtype of the derived type is defined as follows:
2711 @begin(inneritemize)
2712 If the declaration of the derived type has neither a
2713 @nt<known_discriminant_part> nor a @nt<record_extension_part>,
2714 then the corresponding subtype
2715 has a constraint that corresponds (as defined above for the first
2716 subtype of the derived type) to that of the given subtype.
2717
2718 If the derived type is a record extension, then the
2719 corresponding subtype is the first subtype of the derived type.
2720
2721 If the derived type has a new @nt<known_discriminant_part>
2722 but is not a record extension,
2723 then the corresponding subtype is constrained
2724 to those values that when converted to the parent type belong to
2725 the given subtype (see @RefSecNum(Type Conversions)).
2726 @PDefn2{Term=[implicit subtype conversion],Sec=(derived type discriminants)}
2727 @begin{Reason}
2728 An inherited subprogram of an untagged type has an Intrinsic
2729 calling convention, which precludes the use of the Access
2730 attribute.
2731 We preclude 'Access because correctly performing
2732 all required constraint checks on an indirect call to such
2733 an inherited subprogram was felt to impose an undesirable
2734 implementation burden.
2735 @end{Reason}
2736 @end(inneritemize)
2737
2738 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2739 @noprefix@;The same formal parameters have @nt<default_expression>s in
2740 the profile of the inherited subprogram. @Redundant[Any type mismatch due
2741 to the systematic replacement of the parent@Chg{Version=[2],New=[ or progenitor],Old=[]}
2742 type by the derived type is handled as part of the normal
2743 type conversion associated with parameter
2744 passing @em see @RefSecNum(Parameter Associations).]
2745 @begin(Reason)
2746 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2747 We don't introduce the type conversion explicitly here
2748 since conversions to record extensions or on access parameters
2749 are not generally legal. Furthermore, any type conversion would
2750 just be "undone" since the @Chg{Version=[2],New=[],Old=[parent's ]}subprogram
2751 @Chg{Version=[2],New=[of the parent or progenitor ],Old=[]}is ultimately being
2752 called anyway.@Chg{Version=[2],New=[ (Null procedures can be inherited from
2753 a progenitor without being overridden, so it is possible to call subprograms
2754 of an interface.)],Old=[]}
2755 @end(Reason)
2756
2757 @end(itemize) @Comment{end of characteristics of derived type}
2758
2759 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00401-01]}
2760 If a primitive subprogram of the parent@Chg{Version=[2],New=[ or progenitor],
2761 Old=[]} type is visible at the
2762 place of the @nt{derived_type_definition},
2763 then the corresponding inherited subprogram is implicitly declared
2764 immediately after the @nt{derived_type_definition}.
2765 Otherwise, the inherited subprogram is implicitly declared later
2766 or not at all,
2767 as explained in @RefSecNum{Private Operations}.
2768
2769 @PDefn{derived type}
2770 A derived type can also be defined by a @nt<private_@!extension_@!declaration>
2771 (see @RefSecNum(Private Types and Private Extensions))
2772 or a @nt<formal_@!derived_@!type_@!definition>
2773 (see @RefSecNum(Formal Private and Derived Types)).
2774 Such a derived type is a partial
2775 view of the corresponding full or actual type.
2776
2777 All numeric types are derived types, in that
2778 they are implicitly derived from a corresponding
2779 root numeric type (see @RefSecNum(Integer Types) and @RefSecNum(Real Types)).
2780
2781 @end{StaticSem}
2782
2783 @begin{RunTime}
2784 @PDefn2{Term=[elaboration], Sec=(derived_type_definition)}
2785 The elaboration of a @nt<derived_type_definition>
2786 creates the derived type and its first subtype,
2787 and consists of the elaboration of the @nt<subtype_@!indication>
2788 and the @nt<record_@!extension_@!part>, if any.
2789 If the @nt{subtype_@!indication} depends on a discriminant,
2790 then only those expressions that do not depend on a discriminant
2791 are evaluated.
2792 @begin{Discussion}
2793 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
2794 @ChgAdded{Version=[2],Text=[We don't mention the @nt{interface_list}, because
2795 it does not need elaboration (see @RefSecNum{Interface Types}. This is
2796 consistent with the handling of @nt{discriminant_part}s, which aren't
2797 elaborated either.]}
2798 @end{Discussion}
2799 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01],ARef=[AI95-00401-01]}
2800 @PDefn2{Term=[execution], Sec=(call on an inherited subprogram)}
2801 For the execution of a call on an inherited subprogram,
2802 a call on the corresponding primitive subprogram of the
2803 parent@Chg{Version=[2],New=[ or progenitor],Old=[]} type is
2804 performed; the normal conversion of each actual parameter
2805 to the subtype of the corresponding formal parameter
2806 (see @RefSecNum(Parameter Associations))
2807 performs any necessary type conversion as well.
2808 If the result type of the inherited subprogram
2809 is the derived type, the result of calling the
2810 @Chg{Version=[2],New=[],Old=[parent's ]}subprogram@Chg{Version=[2],
2811 New=[ of the parent or progenitor],Old=[]} is converted to the
2812 derived type@Chg{Version=[2],New=[, or in the case of a
2813 null extension, extended to the derived type using the equivalent of an
2814 @nt{extension_aggregate} with the original result as the @nt{ancestor_part}
2815 and @key{null record} as the @nt{record_component_association_list}],Old=[]}.
2816 @PDefn2{Term=[implicit subtype conversion],Sec=(result of inherited function)}
2817 @begin(Discussion)
2818 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00391-01]}
2819 If an inherited function returns the derived type, and the type
2820 is a @Chg{Version=[2],New=[non-null ],Old=[]}record extension, then the
2821 inherited function @Chg{Version=[2],New=[shall be overridden, unless
2822 the type is abstract (in which case the function ],Old=[]}is abstract,
2823 and (unless overridden) cannot be called except via
2824 a dispatching call@Chg{Version=[2],New=[)],Old=[]}.
2825 See @RefSecNum(Abstract Types and Subprograms).
2826 @end(Discussion)
2827 @end{RunTime}
2828
2829 @begin{Notes}
2830 @Defn{closed under derivation}
2831 Classes are closed under derivation @em
2832 any class that contains a type also contains its derivatives.
2833 Operations available for a given class of types
2834 are available for the derived types in that class.
2835
2836 Evaluating an inherited enumeration literal
2837 is equivalent to evaluating the corresponding enumeration literal
2838 of the parent type, and then converting the result to
2839 the derived type. This follows from their equivalence to
2840 parameterless functions.
2841 @PDefn2{Term=[implicit subtype conversion],Sec=(inherited enumeration literal)}
2842
2843 A generic subprogram is not a subprogram,
2844 and hence cannot be a primitive subprogram and
2845 cannot be inherited by a derived type. On the other hand,
2846 an instance of a generic subprogram can be a primitive subprogram,
2847 and hence can be inherited.
2848
2849 If the parent type is an access type, then the parent
2850 and the derived type share the same storage pool;
2851 there is a @key{null} access value for the derived type
2852 and it is the implicit initial value for the type.
2853 See @RefSecNum(Access Types).
2854
2855 If the parent type is a boolean type, the predefined relational operators
2856 of the derived type deliver a result of the predefined type Boolean
2857 (see @RefSecNum(Relational Operators and Membership Tests)).
2858 If the parent type is an integer type, the right operand of the
2859 predefined exponentiation operator is of the predefined type Integer
2860 (see @RefSecNum(Highest Precedence Operators)).
2861
2862 Any discriminants of the parent type are either all inherited, or
2863 completely replaced with a new set of discriminants.
2864
2865 For an inherited subprogram, the subtype of a formal parameter
2866 of the derived type need not have any value in common with the first
2867 subtype of the derived type.
2868 @begin(TheProof)
2869 @Leading@;This happens when the parent subtype is constrained to a range
2870 that does not overlap with the range of a subtype of the parent
2871 type that appears in the profile of
2872 some primitive subprogram of the parent type.
2873 For example:
2874 @begin(example)
2875 @key(type) T1 @key(is range) 1..100;
2876 @key(subtype) S1 @key(is) T1 @key(range) 1..10;
2877 @key(procedure) P(X : @key[in] S1); @RI{-- P is a primitive subprogram}
2878 @key(type) T2 @key(is new) T1 @key(range) 11..20;
2879 @RI(-- implicitly declared:)
2880 @RI{-- @key(procedure) P(X : @key[in] T2'Base @key(range) 1..10);}
2881 @RI{-- X cannot be in T2'First .. T2'Last}
2882 @end(example)
2883 @end(TheProof)
2884
2885 If the reserved word @key{abstract} is given in the declaration of a
2886 type, the type is abstract (see @RefSecNum{Abstract Types and Subprograms}).
2887
2888 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
2889 @ChgAdded{Version=[2],Text=[An interface type that has a progenitor type
2890 @lquotes@;is derived from@rquotes@; that type.
2891 A @nt{derived_type_definition}, however, never defines an interface type.]}
2892
2893 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
2894 @ChgAdded{Version=[2],Text=[It is illegal for the parent type of a
2895 @nt{derived_type_definition} to be a synchronized tagged type.]}
2896 @begin{TheProof}
2897 @ChgRef{Version=[2],Kind=[AddedNormal]}
2898 @ChgAdded{Version=[2],Text=[@RefSecNum{Type extensions} prohibits record
2899 extensions whose parent type is a synchronized tagged type, and this clause
2900 requires tagged types to have a record extension. Thus there are no legal
2901 derivations. Note that a synchronized interface can be used as a progenitor
2902 in an @nt{interface_type_definition} as well as in task and protected types,
2903 but we do not allow concrete extensions of any synchronized tagged type.]}
2904 @end{TheProof}
2905
2906 @end{Notes}
2907
2908 @begin{Examples}
2909 @Leading@keepnext@i(Examples of derived type declarations:)
2910 @begin(Example)
2911 @key(type) Local_Coordinate @key(is) @key(new) Coordinate; --@RI[ two different types]
2912 @key(type) Midweek @key(is) @key(new) Day @key(range) Tue .. Thu; --@RI[ see @RefSecNum(Enumeration Types)]
2913 @key(type) Counter @key(is) @key(new) Positive; --@RI[ same range as Positive ]
2914
2915 @key(type) Special_Key @key(is) @key(new) Key_Manager.Key; --@RI[ see @RefSecNum(Private Operations)]
2916 --@RI[ the inherited subprograms have the following specifications: ]
2917 --@RI[ procedure Get_Key(K : out Special_Key);]
2918 --@RI[ function "<"(X,Y : Special_Key) return Boolean;]
2919 @end(Example)
2920 @end{Examples}
2921
2922 @begin{Inconsistent83}
2923 @Defn{inconsistencies with Ada 83}
2924 When deriving from a (nonprivate, nonderived) type in the same
2925 visible part in which it is defined, if a predefined
2926 operator had been overridden prior to the derivation,
2927 the derived type will inherit the user-defined operator rather
2928 than the predefined operator. The work-around (if the new behavior
2929 is not the desired behavior) is to move the definition of the
2930 derived type prior to the overriding of any predefined operators.
2931
2932 @end{Inconsistent83}
2933
2934 @begin{Incompatible83}
2935 @Defn{incompatibilities with Ada 83}
2936 @Leading@;When deriving from a (nonprivate, nonderived) type in the same
2937 visible part in which it is defined, a primitive subprogram of the
2938 parent type declared before the derived type will be inherited by the
2939 derived type. This can cause upward incompatibilities in cases like
2940 this:
2941 @begin{Example}
2942 @key[package] P @key[is]
2943 @key[type] T @key[is] (A, B, C, D);
2944 @key[function] F( X : T := A ) @key[return] Integer;
2945 @key[type] NT @key[is] @key[new] T;
2946 --@RI{ inherits F as}
2947 --@RI{ function F( X : NT := A ) return Integer;}
2948 --@RI{ in Ada 95 only}
2949 ...
2950 @key[end] P;
2951 ...
2952 @key[use] P; --@RI{ Only one declaration of F from P is use-visible in}
2953 --@RI{ Ada 83; two declarations of F are use-visible in}
2954 --@RI{ Ada 95.}
2955 @key[begin]
2956 ...
2957 @key[if] F > 1 @key[then] ... --@RI{ legal in Ada 83, ambiguous in Ada 95}
2958 @end{Example}
2959 @end{Incompatible83}
2960
2961 @begin{Extend83}
2962 @Defn{extensions to Ada 83}
2963 The syntax for a @nt{derived_type_definition} is amended to
2964 include an optional @nt{record_extension_part}
2965 (see @RefSecNum(Type Extensions)).
2966
2967 A derived type may override the discriminants of the parent by giving a
2968 new @nt{discriminant_part}.
2969
2970 The parent type in a @nt<derived_type_definition>
2971 may be a derived type defined
2972 in the same visible part.
2973
2974 When deriving from a type in the same visible part in which it is defined,
2975 the primitive subprograms declared prior to the derivation
2976 are inherited as primitive subprograms of the derived type.
2977 See @RefSecNum(Classification of Operations).
2978 @end{Extend83}
2979
2980 @begin{DiffWord83}
2981 We now talk about the classes to which a type belongs, rather than
2982 a single class.
2983
2984 As explained in Section 13, the concept of "storage pool"
2985 replaces the Ada 83 concept of "collection."
2986 These concepts are similar, but not the same.
2987 @end{DiffWord83}
2988
2989 @begin{Extend95}
2990 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
2991 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2992 A derived type may inherit from multiple (interface) progenitors,
2993 as well as the parent type @em see @RefSec{Interface Types}.]}
2994
2995 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00419-01]}
2996 @ChgAdded{Version=[2],Text=[A derived type may specify that it is a limited
2997 type. This is required for interface ancestors (from which limitedness is
2998 not inherited), but it is generally useful as documentation of limitedness.]}
2999 @end{Extend95}
3000
3001 @begin{DiffWord95}
3002 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00391-01]}
3003 @ChgAdded{Version=[2],Text=[Defined the result of functions for
3004 null extensions (which we no longer require to be overridden - see
3005 @RefSecNum{Abstract Types and Subprograms}).]}
3006
3007 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00442-01]}
3008 @ChgAdded{Version=[2],Text=[Defined the term @lquotes@;category of
3009 types@rquotes and used it in wording elsewhere; also specified the
3010 language-defined categories that form classes of types (this was never
3011 normatively specified in Ada 95.]}
3012 @end{DiffWord95}
3013
3014
3015 @LabeledSubClause{Derivation Classes}
3016
3017 @begin{Intro}
3018 In addition to the various language-defined classes of types,
3019 types can be grouped into @i(derivation classes).
3020 @end{Intro}
3021
3022 @begin{StaticSem}
3023 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
3024 @Defn2{Term=[derived from], Sec=(directly or indirectly)}
3025 A derived type is @i(derived from) its parent type @i(directly);
3026 it is derived
3027 @i(indirectly) from any type from which its parent type is derived.@Chg{Version=[2],
3028 New=[ A derived type, interface type, type extension, task type, protected type,
3029 or formal derived type is also derived from every ancestor of each of its
3030 progenitor types, if any.],Old=[]}
3031 @Defn2{Term=[derivation class], Sec=(for a type)}
3032 @Defn2{Term=[root type], Sec=(of a class)}
3033 @Defn{rooted at a type}
3034 The derivation class of types for a type @i(T) (also called
3035 the class @i(rooted) at @i(T)) is
3036 the set consisting of @i(T) (the @i(root type) of the class)
3037 and all types derived from @i(T) (directly or indirectly) plus
3038 any associated universal or class-wide types (defined below).
3039 @begin{Discussion}
3040 Note that the definition of @lquotes@;derived from@rquotes@; is a recursive
3041 definition.
3042 We don't define a root type for all interesting
3043 language-defined classes, though presumably we could.
3044 @end{Discussion}
3045 @begin{Honest}
3046 By the class-wide type @lquotes@;associated@rquotes@; with a type @i(T),
3047 we mean the type @i(T)'Class.
3048 Similarly, the universal type associated with
3049 @i{root_integer}, @i{root_real}, and @i{root_fixed} are
3050 @i{universal_integer}, @i{universal_real}, and @i{universal_fixed},
3051 respectively.
3052 @end{Honest}
3053
3054 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
3055 Every type is either a @i(specific) type, a @i(class-wide) type,
3056 or a @i(universal) type.
3057 @Defn{specific type}
3058 A specific type is
3059 one defined by a @nt<type_declaration>,
3060 a @nt<formal_type_declaration>, or a full type definition
3061 embedded in @Chg{Version=[2],New=[another construct],Old=[a declaration
3062 for an object]}.
3063 Class-wide and universal types are implicitly defined, to act
3064 as representatives for an entire class of types, as follows:
3065 @begin(Honest)
3066 The root types @i(root_integer), @i(root_real), and
3067 @i(root_fixed) are also specific
3068 types. They are declared in the specification of package Standard.
3069 @end(Honest)
3070 @begin(Description)
3071 @Defn{class-wide type}Class-wide types
3072 @\Class-wide types are defined for @Redundant[(and belong to)]
3073 each derivation class rooted
3074 at a tagged type (see @RefSecNum(Tagged Types and Type Extensions)).
3075 Given a subtype S of a tagged type @i(T),
3076 S'Class is the @nt<subtype_mark> for a corresponding
3077 subtype of the tagged class-wide
3078 type @i(T)'Class. Such types are called
3079 @lquotes@;class-wide@rquotes@; because when a formal parameter is defined
3080 to be of a class-wide type @i(T)'Class, an actual parameter
3081 of any type in the derivation class rooted at @i(T) is acceptable
3082 (see @RefSecNum(The Context of Overload Resolution)).
3083
3084 @NoPrefix@Defn{first subtype}
3085 The set of values for a class-wide type @i(T)'Class is the discriminated
3086 union of the set of values of each specific type in the
3087 derivation class rooted at @i(T) (the tag acts as the implicit discriminant
3088 @em see @RefSecNum(Tagged Types and Type Extensions)).
3089 Class-wide types have no primitive subprograms of their own.
3090 However, as explained in @RefSecNum(Dispatching Operations of Tagged Types),
3091 operands of a class-wide type @i(T)'Class can be used as part
3092 of a dispatching call on a primitive subprogram of the type @i(T).
3093 The only components @Redundant[(including discriminants)] of
3094 @i(T)'Class that are visible are those of @i(T).
3095 If S is a first subtype,
3096 then S'Class is a first subtype.
3097 @begin{Reason}
3098 We want S'Class to be a first subtype when S is,
3099 so that an @nt{attribute_@!definition_@!clause} like
3100 @lquotes@key[for] S'Class'Output @key[use] ...;@rquotes@;
3101 will be legal.
3102 @end{Reason}
3103
3104 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
3105 @Defn{universal type}Universal types
3106 @\Universal types
3107 are defined for @Redundant[(and belong to)] the integer,
3108 real, @Chg{Version=[2],New=[],Old=[and ]}fixed point@Chg{Version=[2],
3109 New=[, and access],Old=[]} classes,
3110 and are referred to in this standard as respectively,
3111 @i(universal_integer), @i(universal_real), @Chg{Version=[2],New=[],
3112 Old=[and ]}@i(universal_fixed)@Chg{Version=[2],
3113 New=[, and @i(universal_access)],Old=[]}.
3114 These are analogous to class-wide types for these language-defined
3115 @Chg{Version=[2],New=[elementary],Old=[numeric]} classes.
3116 As with class-wide types, if a formal parameter is of a universal type,
3117 then an actual parameter of any type in the corresponding class
3118 is acceptable. In addition, a value of a universal type
3119 (including an integer or real @nt<numeric_literal>@Chg{Version=[2],New=[, or
3120 the literal @key{null}],Old=[]}) is @lquotes@;universal@rquotes@;
3121 in that it is acceptable where some particular type in the
3122 class is expected
3123 (see @RefSecNum(The Context of Overload Resolution)).
3124
3125 @NoPrefix@;The set of values of a universal type is the undiscriminated union
3126 of the set of values possible for any definable type in the associated class.
3127 Like class-wide types, universal types have no
3128 primitive subprograms of their own. However, their @lquotes@;universality@rquotes@; allows
3129 them to be used as operands with the primitive subprograms of any
3130 type in the corresponding class.
3131 @begin(Discussion)
3132 A class-wide type is only class-wide in one direction,
3133 from specific to class-wide, whereas
3134 a universal type is class-wide (universal) in both directions,
3135 from specific to universal and back.
3136
3137 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}
3138 We considered defining class-wide or perhaps universal types for
3139 all derivation classes, not just tagged classes and these @Chg{Version=[2],
3140 New=[four elementary],Old=[three numeric]} classes. However, this was felt
3141 to overly weaken the strong-typing model in some situations. Tagged types
3142 preserve strong type distinctions thanks to the run-time tag. Class-wide
3143 or universal types for untagged types would weaken the compile-time
3144 type distinctions without providing a compensating run-time-checkable
3145 distinction.
3146
3147 We considered defining standard names for the universal
3148 numeric types so they could be used in formal parameter specifications.
3149 However, this was felt to impose an undue implementation burden for
3150 some implementations.
3151 @end(Discussion)
3152 @begin(Honest)
3153 Formally, the set of values of a universal type is actually a @i(copy) of
3154 the undiscriminated union of the values of the types in its
3155 class. This is because we
3156 want each value to have exactly one type, with explicit or implicit
3157 conversion needed to go between types. An alternative,
3158 consistent model would be to associate a class, rather than
3159 a particular type, with a value,
3160 even though any given expression would have a particular type.
3161 In that case, implicit type conversions would not generally need to
3162 change the value, although an associated subtype conversion might
3163 need to.
3164 @end(Honest)
3165 @end(Description)
3166
3167 @PDefn{root_integer}
3168 @PDefn{root_real}
3169 The integer and real numeric classes each have a specific root type in
3170 addition to their universal type, named respectively @i(root_integer)
3171 and @i(root_real).
3172
3173 @Defn2{Term=[cover], Sec=(a type)}
3174 A class-wide or universal type is said to @i(cover) all of the types
3175 in its class. A specific type covers only itself.
3176
3177 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00251-01]}
3178 @Defn2{Term=[descendant], Sec=(of a type)}
3179 A specific type @i(T2) is defined to be a @i(descendant) of a
3180 type @i(T1) if @i(T2) is the same as @i(T1), or if @i(T2) is derived
3181 (directly or indirectly) from @i(T1). A class-wide type @i(T2)'Class is
3182 defined to be a descendant of type @i(T1) if @i(T2) is a descendant of @i(T1).
3183 Similarly, the @Chg{Version=[2],New=[numeric ],Old=[]}universal types are
3184 defined to be descendants of the root types of their classes.
3185 @Defn2{Term=[ancestor], Sec=(of a type)}
3186 If a type @i(T2) is a descendant of a type @i(T1),
3187 then @i(T1) is called an @i(ancestor) of @i(T2).
3188 @Defn2{Term=[ultimate ancestor], Sec=(of a type)}
3189 @Defn2{Term=[ancestor], Sec=(ultimate)}
3190 @Chg{Version=[2],New=[An],Old=[The]} @i(ultimate ancestor) of a type
3191 is @Chg{Version=[2],New=[an],Old=[the]} ancestor of
3192 @Chg{Version=[2],New=[that],Old=[the]} type that is not
3193 @Chg{Version=[2],New=[itself ],Old=[]}a descendant of any other
3194 type.@Chg{Version=[2],New=[ Every untagged type
3195 has a unique ultimate ancestor.],Old=[]}
3196 @begin{Ramification}
3197 A specific type is a descendant of itself.
3198 Class-wide types are considered descendants of the corresponding
3199 specific type, and do not have any descendants of their own.
3200
3201 A specific type is an ancestor of itself.
3202 The root of a derivation class is an ancestor of all types in the
3203 class, including any class-wide types in the class.
3204 @end{Ramification}
3205 @begin(Discussion)
3206 @Leading@keepnext@;The terms root, parent, ancestor, and ultimate ancestor
3207 are all related. For example:
3208 @begin(Itemize)
3209 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00251-01]}
3210 Each type has at most one parent, and one
3211 or more ancestor types; each @Chg{Version=[2],New=[untagged ],Old=[]}type
3212 has exactly one ultimate ancestor.
3213 In Ada 83, the term @lquotes@;parent type@rquotes@; was sometimes used
3214 more generally to include any ancestor type
3215 (e.g. RM83-9.4(14)). In Ada 95, we restrict
3216 parent to mean the immediate ancestor.
3217
3218 A class of types has at most one root type; a derivation class
3219 has exactly one root type.
3220
3221 The root of a class is an ancestor of all of the types in the class
3222 (including itself).
3223
3224 The type @i(root_integer) is the root of the integer class,
3225 and is the ultimate ancestor of all integer types.
3226 A similar statement applies to @i(root_real).
3227 @end(Itemize)
3228 @end(Discussion)
3229
3230 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Ancestor>,
3231 Text=<@ChgAdded{Version=[2],Text=[An ancestor of a type is the type itself
3232 or, in the case of a type derived from other types, its parent type or one
3233 of its progenitor types or one of their ancestors. Note that ancestor and
3234 descendant are inverse relationships.]}>}
3235
3236 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Descendant>,
3237 Text=<@ChgAdded{Version=[2],Text=[A type is a descendant of itself, its
3238 parent and progenitor types, and their ancestors. Note that descendant and
3239 ancestor are inverse relationships.]}>}
3240
3241 @Defn2{Term=[inherited], Sec=(from an ancestor type)}
3242 An inherited component @Redundant[(including an inherited discriminant)] of a
3243 derived type is inherited @i(from) a given
3244 ancestor of the type
3245 if the corresponding component was inherited by each derived type in the
3246 chain of derivations going back to the given ancestor.
3247
3248 @end{StaticSem}
3249
3250 @begin{Notes}
3251 Because operands of a universal type are acceptable to the
3252 predefined operators of any type in their class, ambiguity can
3253 result. For @i(universal_integer) and @i(universal_real), this
3254 potential ambiguity is resolved by giving a preference
3255 (see @RefSecNum{The Context of Overload Resolution})
3256 to the predefined operators
3257 of the corresponding root types (@i(root_integer)
3258 and @i(root_real), respectively).
3259 Hence, in an apparently ambiguous expression like
3260 @begin(Display)
3261 1 + 4 < 7
3262 @end(Display)
3263
3264 @NoPrefix@;where each of the literals is of type @i(universal_integer),
3265 the predefined operators of @i(root_integer) will be preferred over those
3266 of other specific integer types, thereby resolving the ambiguity.
3267 @begin(Ramification)
3268 Except for this preference, a root numeric type
3269 is essentially like any other specific type in the
3270 associated numeric class. In particular, the result of a
3271 predefined operator of a root numeric type is not @lquotes@;universal@rquotes@;
3272 (implicitly convertible) even if both operands were.
3273 @end(Ramification)
3274 @end{Notes}
3275
3276 @begin{DiffWord95}
3277 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01]}
3278 @ChgAdded{Version=[2],Text=[Updated the wording to define the
3279 @i{universal_access} type. This was defined to make @key{null} for
3280 anonymous access types sensible.]}
3281
3282 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01],ARef=[AI95-00401-01]}
3283 @ChgAdded{Version=[2],Text=[The definitions of ancestors and descendants
3284 were updated to allow multiple ancestors (necessary to support interfaces).]}
3285 @end{DiffWord95}
3286
3287
3288 @LabeledClause{Scalar Types}
3289
3290 @begin{Intro}
3291 @Defn{scalar type}
3292 @i(Scalar) types comprise enumeration types, integer types, and real types.
3293 @Defn{discrete type}
3294 Enumeration types and integer types are called @i(discrete) types;
3295 @Defn{position number}
3296 each value of a discrete type has a @i(position number) which is an integer
3297 value.
3298 @Defn{numeric type}
3299 Integer types and real types are called @i(numeric) types.
3300 @Redundant[All scalar types are ordered, that is, all
3301 relational operators are predefined for their values.]
3302
3303 @end{Intro}
3304
3305 @begin{Syntax}
3306 @Syn{lhs=<range_constraint>,rhs=" @key{range} @Syn2{range}"}
3307
3308
3309 @Syn{lhs=<range>,rhs=" @Syn2{range_attribute_reference}
3310 | @Syn2{simple_expression} .. @Syn2{simple_expression}"}
3311 @end{Syntax}
3312 @begin(Discussion)
3313 These need to be @nt<simple_expression>s rather than
3314 more general @nt<expression>s because ranges appear in
3315 membership tests and other contexts where
3316 @nt<expression> .. @nt<expression> would
3317 be ambiguous.
3318 @end(Discussion)
3319
3320 @begin{Intro}
3321 @Defn{range}
3322 @Defn2{Term=[lower bound], Sec=(of a range)}
3323 @Defn2{Term=[upper bound], Sec=(of a range)}
3324 @Defn{type of a range}
3325 A @i(range) has a @i(lower bound) and an @i(upper bound) and
3326 specifies a subset of the values of some scalar type
3327 (the @i(type of the range)).
3328 A range with lower bound L and upper bound R is described by @lquotes@;L .. R@rquotes@;.
3329 @Defn{null range}
3330 If R is less than L, then
3331 the range is a @i(null range), and specifies an
3332 empty set of values.
3333 Otherwise, the range specifies the values of the type from
3334 the lower bound to the upper bound, inclusive.
3335 @Defn2{Term=[belong], Sec=(to a range)}
3336 A value @i(belongs) to a range if it is of the type of the
3337 range, and is in the subset of values specified by the range.
3338 @PDefn2{Term=[satisfies], Sec=(a range constraint)}
3339 A value @i(satisfies) a range constraint if it belongs to
3340 the associated range.
3341 @Defn2{Term=[included], Sec=(one range in another)}
3342 One range is @i(included) in another if all values that
3343 belong to the first range also belong to the second.
3344 @end{Intro}
3345
3346 @begin{Resolution}
3347 @PDefn2{Term=[expected type], Sec=(range_constraint range)}
3348 For a @nt<subtype_indication> containing a @nt<range_constraint>, either
3349 directly or as part of some other @nt<scalar_constraint>,
3350 the type of the @nt<range> shall resolve to that of the type determined by
3351 the @nt<subtype_mark> of the @nt<subtype_indication>.
3352 @PDefn2{Term=[expected type], Sec=(range simple_expressions)}
3353 For a @nt<range> of a given type,
3354 the @nt<simple_expression>s of the @nt<range> (likewise, the
3355 @nt<simple_expression>s of the equivalent @nt<range> for a
3356 @nt<range_attribute_reference>)
3357 are expected to be of the type of the @nt<range>.
3358 @begin(Discussion)
3359 In Ada 95, @nt<constraint>s
3360 only appear within @nt<subtype_indication>s; things that look
3361 like constraints that appear in type declarations are called
3362 something else like @nt<real_range_specification>s.
3363
3364 We say "the expected type is ..." or "the type is expected to be ..."
3365 depending on which reads better. They are fundamentally equivalent,
3366 and both feed into the type resolution rules of clause
3367 @RefSecNum(The Context of Overload Resolution).
3368
3369 In some cases, it doesn't work to use expected types.
3370 For example, in the above rule, we say that
3371 the @lquotes@;type of the @nt<range> shall resolve to ...@rquotes@;
3372 rather than @lquotes@;the expected type for the @nt<range> is ...@rquotes@;.
3373 We then use @lquotes@;expected type@rquotes@; for the bounds.
3374 If we used @lquotes@;expected@rquotes@; at both points, there
3375 would be an ambiguity, since one could apply the rules of
3376 @RefSecNum{The Context of Overload Resolution}
3377 either on determining the type of the range, or on determining the
3378 types of the individual bounds. It is clearly important
3379 to allow one bound to be of a universal type, and the other of
3380 a specific type, so we need to use @lquotes@;expected type@rquotes@; for the bounds.
3381 Hence, we used @lquotes@;shall resolve to@rquotes@; for the type of the range as a
3382 whole.
3383 There are other situations where @lquotes@;expected type@rquotes@; is not quite
3384 right, and we use @lquotes@;shall resolve to@rquotes@; instead.
3385 @end(Discussion)
3386 @end{Resolution}
3387
3388 @begin{StaticSem}
3389 @RootDefn2{Term=[base range], Sec=(of a scalar type)}
3390 The @i(base range) of a scalar type is the range of
3391 finite values of the type that can be represented
3392 in every unconstrained object of the type;
3393 it is also the range supported at a minimum for
3394 intermediate values during the evaluation of expressions involving
3395 predefined operators of the type.
3396 @begin{ImplNote}
3397 Note that in some machine architectures intermediates
3398 in an expression (particularly if static),
3399 and register-resident variables might accommodate
3400 a wider range. The base range does not include the values
3401 of this wider range that are not assignable without overflow to
3402 memory-resident objects.@end{implnote}
3403 @begin(Ramification)
3404 @PDefn2{Term=[base range], Sec=(of an enumeration type)}
3405 The base range of an enumeration type is the range of values
3406 of the enumeration type.
3407 @end(Ramification)
3408 @begin{Reason}
3409
3410 If the representation supports infinities,
3411 the base range is nevertheless restricted
3412 to include only the representable finite values,
3413 so that 'Base'First and 'Base'Last are always guaranteed to be finite.@end{reason}
3414 @begin(Honest)
3415 By a "value that can be assigned without overflow" we don't mean
3416 to restrict ourselves to values that can be represented exactly.
3417 Values between machine representable values can be assigned,
3418 but on subsequent reading, a slightly different value might
3419 be retrieved, as (partially) determined by the number of digits of
3420 precision of the type.
3421 @end(Honest)
3422
3423 @Defn2{Term=[constrained], Sec=(subtype)}
3424 @Defn2{Term=[unconstrained], Sec=(subtype)}
3425 @Redundant[A constrained scalar subtype is one to which a range constraint
3426 applies.]
3427 @Defn2{Term=[range], Sec=(of a scalar subtype)}
3428 The @i(range) of a constrained scalar subtype
3429 is the range associated with the range constraint of the subtype.
3430 The @i(range) of an unconstrained scalar subtype is the base range of
3431 its type.
3432 @end{StaticSem}
3433
3434 @begin{RunTime}
3435 @PDefn2{Term=[compatibility], Sec=(range with a scalar subtype)}
3436 A range is @i(compatible) with a scalar subtype if and only
3437 if it is either a null range
3438 or each bound of the range belongs to the range of the subtype.
3439 @PDefn2{Term=[compatibility], Sec=(range_constraint with a scalar subtype)}
3440 A @nt<range_constraint> is @i(compatible) with a scalar subtype if and only if
3441 its range is compatible with the subtype.
3442 @begin(Ramification)
3443 Only @nt<range_constraint>s (explicit or implicit) impose conditions
3444 on the values of a scalar subtype. The other @nt<scalar_constraint>s,
3445 @nt<digits_constraint>s and @nt<delta_constraint>s impose conditions
3446 on the subtype denoted by the @nt<subtype_mark> in a @nt<subtype_indication>,
3447 but don't impose a condition on the values of the subtype being
3448 defined. Therefore, a scalar subtype is not called @i(constrained)
3449 if all that applies to it is a @nt<digits_constraint>.
3450 Decimal subtypes are subtle, because a @nt<digits_constraint> without
3451 a @nt<range_constraint> nevertheless includes an implicit
3452 @nt<range_constraint>.
3453 @end(Ramification)
3454
3455 @PDefn2{Term=[elaboration], Sec=(range_constraint)}
3456 The elaboration of a @nt{range_constraint} consists of the
3457 evaluation of the @nt{range}.
3458 @PDefn2{Term=[evaluation], Sec=(range)}
3459 The evaluation of a @nt{range} determines a lower bound and an upper bound.
3460 If @nt<simple_expression>s are given to specify bounds, the evaluation of
3461 the @nt<range> evaluates these @nt<simple_expression>s in an arbitrary order,
3462 and converts them to the type of the @nt<range>.
3463 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a range)}
3464 If a @nt<range_attribute_reference> is given, the evaluation
3465 of the @nt<range>
3466 consists of the evaluation of the @nt<range_attribute_reference>.
3467
3468 @keepnext@i(Attributes)
3469
3470 @Leading@keepnext@;For @PrefixType{every scalar subtype S},
3471 the following attributes are defined:
3472 @begin(description)
3473 @Attribute{Prefix=<S>, AttrName=<First>,
3474 Text=[S'First denotes the lower bound of
3475 the range of S. The value of this attribute is of the type
3476 of S.]}
3477 @begin{Ramification}
3478 Evaluating S'First never raises Constraint_Error.@end{ramification}
3479
3480 @Attribute{Prefix=<S>, AttrName=<Last>,
3481 Text=[S'Last denotes the upper bound of
3482 the range of S. The value of this attribute is of the type
3483 of S.]}
3484 @begin{Ramification}
3485 Evaluating S'Last never raises Constraint_Error.@end{ramification}
3486
3487 @Attribute{Prefix=<S>, AttrName=<Range>,
3488 Text=[S'Range is equivalent to the @nt<range> S'First .. S'Last.]}
3489
3490 @Attribute{Prefix=<S>, AttrName=<Base>,
3491 Text=[S'Base denotes an
3492 unconstrained subtype of the type of S.
3493 This unconstrained subtype is called the @i(base subtype) of the type.
3494 ]}@Defn2{Term=(base subtype), Sec=(of a type)}
3495
3496 @AttributeLeading{Prefix=<S>, AttrName=<Min>,
3497 Text=[S'Min denotes a function with the following specification:
3498 @begin(Descexample)
3499 @b(function) S'Min(@RI(Left), @RI(Right) : S'Base)
3500 @b(return) S'Base
3501 @end(Descexample)
3502
3503 @NoPrefix@;The function returns the lesser of the values
3504 of the two parameters.]}
3505 @begin{Discussion}
3506 @Defn2{Term=[italics],Sec=(formal parameters of attribute functions)}
3507 The formal parameter names are italicized because they cannot be
3508 used in calls @em
3509 see @RefSecNum{Subprogram Calls}.
3510 Such a specification
3511 cannot be written by the user because an @nt<attribute_reference>
3512 is not permitted as the designator of a user-defined function, nor
3513 can its formal parameters be anonymous.
3514 @end{Discussion}
3515
3516 @AttributeLeading{Prefix=<S>, AttrName=<Max>,
3517 Text=[S'Max denotes a function with the following specification:
3518 @begin(Descexample)
3519 @b(function) S'Max(@RI(Left), @RI(Right) : S'Base)
3520 @b(return) S'Base
3521 @end(Descexample)
3522
3523 @NoPrefix@;The function returns the greater of the values of the two parameters.]}
3524
3525 @AttributeLeading{Prefix=<S>, AttrName=<Succ>,
3526 Text=[S'Succ denotes a function with the following specification:
3527 @begin(Descexample)
3528 @b(function) S'Succ(@RI(Arg) : S'Base)
3529 @b(return) S'Base
3530 @end(Descexample)
3531
3532 @NoPrefix@Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
3533 For an enumeration type, the function returns the value
3534 whose position number is one more than that of the value of @i(Arg);
3535 @IndexCheck{Range_Check}
3536 Constraint_Error is raised if there is no such value of the type.
3537 For an integer type, the function returns the result of
3538 adding one to the value of @i(Arg).
3539 For a fixed point type, the function returns the result of
3540 adding @i(small) to the value of @i(Arg).
3541 For a floating point type, the
3542 function returns the machine number (as defined
3543 in @RefSecNum(Floating Point Types))
3544 immediately above the value of @i(Arg);
3545 @IndexCheck{Range_Check}
3546 Constraint_Error is raised if there is no such machine number.]}
3547 @begin{Ramification}
3548 S'Succ for a modular integer subtype wraps around
3549 if the value of @i(Arg) is S'Base'Last. S'Succ for a signed integer
3550 subtype might raise Constraint_Error if the value of @i(Arg) is
3551 S'Base'Last, or it might return the out-of-base-range value
3552 S'Base'Last+1, as is permitted for all predefined numeric operations.@end{ramification}
3553
3554 @AttributeLeading{Prefix=<S>, AttrName=<Pred>,
3555 Text=[S'Pred denotes a function with
3556 the following specification:
3557 @begin(Descexample)
3558 @b(function) S'Pred(@RI(Arg) : S'Base)
3559 @b(return) S'Base
3560 @end(Descexample)
3561
3562 @NoPrefix@Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
3563 For an enumeration type, the function returns the value
3564 whose position number is one less than that of the value of @i(Arg);
3565 @IndexCheck{Range_Check}
3566 Constraint_Error is raised if there is no such value of the type.
3567 For an integer type, the function returns the result of
3568 subtracting one from the value of @i(Arg).
3569 For a fixed point type, the function returns the result of
3570 subtracting @i(small) from the value of @i(Arg).
3571 For a floating point type, the
3572 function returns the machine number (as defined
3573 in @RefSecNum(Floating Point Types))
3574 immediately below the value of @i(Arg);
3575 @IndexCheck{Range_Check}
3576 Constraint_Error is raised if there is no such machine number.]}
3577 @begin{Ramification}
3578 S'Pred for a modular integer subtype wraps around
3579 if the value of @i(Arg) is S'Base'First. S'Pred for a signed integer
3580 subtype might raise Constraint_Error if the value of @i(Arg) is
3581 S'Base'First, or it might return the out-of-base-range value
3582 S'Base'First@en@;1, as is permitted for all predefined numeric operations.@end{ramification}
3583
3584 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
3585 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Image>, ARef=[AI95-00285-01],
3586 Text=[@Chg{Version=[2],New=[S'Wide_Wide_Image denotes a function
3587 with the following specification:],Old=[]}
3588 @begin(Descexample)
3589 @ChgRef{Version=[2],Kind=[Added]}
3590 @ChgAdded{Version=[2],Text=[@b(function) S'Wide_Wide_Image(@RI(Arg) : S'Base)
3591 @b(return) Wide_Wide_String]}
3592 @end(Descexample)
3593
3594 @ChgRef{Version=[2],Kind=[Added]}
3595 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=[image], Sec=(of a value)}
3596 The function returns an @i(image) of the value of @i(Arg),
3597 that is, a sequence of characters representing the value in display
3598 form.]}]}@Comment{End of Annex text here.}
3599 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The lower bound of the result is one.]}
3600
3601 @ChgRef{Version=[2],Kind=[Added]}
3602 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The image of an integer value is
3603 the corresponding decimal literal,
3604 without underlines, leading zeros, exponent, or trailing spaces, but
3605 with a single leading character that is either a minus sign or
3606 a space.]}
3607 @begin{ImplNote}
3608 @ChgRef{Version=[2],Kind=[AddedNormal]}
3609 @ChgAdded{Version=[2],Text=[
3610 If the machine supports negative zeros for signed integer types,
3611 it is not specified whether "@ 0" or "@en@;0" should be returned
3612 for negative zero. We don't have enough experience with
3613 such machines to know what is appropriate, and what other
3614 languages do. In any case, the implementation should be
3615 consistent.]}
3616 @end{implnote}
3617
3618 @ChgRef{Version=[2],Kind=[Added]}
3619 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn{nongraphic character}
3620 The image of an enumeration value is either the corresponding
3621 identifier in upper case or the corresponding character literal
3622 (including the two apostrophes); neither leading nor trailing
3623 spaces are included.
3624 For a @i(nongraphic character) (a value of
3625 a character type that has no
3626 enumeration literal associated with it), the
3627 result is a corresponding language-defined
3628 name in upper case (for example, the image
3629 of the nongraphic character identified as @i(nul) is @lquotes@;NUL@rquotes@; @em the
3630 quotes are not part of the image).]}
3631 @begin{ImplNote}
3632 @ChgRef{Version=[2],Kind=[AddedNormal]}
3633 @ChgAdded{Version=[2],Text=[
3634 For an enumeration type T that has @lquotes@;holes@rquotes@;
3635 (caused by an @nt{enumeration_@!representation_@!clause}),
3636 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
3637 T'Wide_Image should raise Program_Error if the value
3638 is one of the holes (which is a bounded error anyway,
3639 since holes can be generated only via uninitialized variables and
3640 similar things.]}
3641 @end{ImplNote}
3642
3643 @ChgRef{Version=[2],Kind=[Added]}
3644 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The image of a
3645 floating point value is a decimal real literal
3646 best approximating the value (rounded away from zero if halfway between)
3647 with a single leading character that is either a minus sign
3648 or a space, a single digit (that is nonzero unless the value is zero),
3649 a decimal point, S'Digits@en@;1
3650 (see @RefSecNum(Operations of Floating Point Types)) digits
3651 after the decimal point (but one if S'Digits is one),
3652 an upper case E, the sign of the
3653 exponent (either + or @en), and two or more digits
3654 (with leading zeros if necessary)
3655 representing the exponent.
3656 If S'Signed_Zeros is True, then the leading character is a minus
3657 sign for a negatively signed zero.]}
3658 @begin{Honest}
3659 @ChgRef{Version=[2],Kind=[AddedNormal]}
3660 @ChgAdded{Version=[2],Text=[
3661 Leading zeros are present in the exponent only if necessary to make
3662 the exponent at least two digits.]}
3663 @end{Honest}
3664 @begin{Reason}
3665 @ChgRef{Version=[2],Kind=[AddedNormal]}
3666 @ChgAdded{Version=[2],Text=[
3667 This image is intended to conform to that produced by
3668 Text_IO.Float_IO.Put in its default format.]}
3669 @end{reason}
3670 @begin{ImplNote}
3671 @ChgRef{Version=[2],Kind=[AddedNormal]}
3672 @ChgAdded{Version=[2],Text=[The rounding direction is specified here
3673 to ensure portability of output results.]}
3674 @end{implnote}
3675
3676 @ChgRef{Version=[2],Kind=[Added]}
3677 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The image of a fixed point value
3678 is a decimal real literal
3679 best approximating the value (rounded away from zero if halfway between)
3680 with a single leading character that is either a minus sign
3681 or a space, one or more digits before the decimal point
3682 (with no redundant leading zeros),
3683 a decimal point, and S'Aft (see @RefSecNum(Operations of Fixed Point Types))
3684 digits after the decimal point.]}
3685 @begin{Reason}
3686 @ChgRef{Version=[2],Kind=[AddedNormal]}
3687 @ChgAdded{Version=[2],Text=[This image is intended to conform to
3688 that produced by Text_IO.Fixed_IO.Put.]}
3689 @end{reason}
3690 @begin{ImplNote}
3691 @ChgRef{Version=[2],Kind=[AddedNormal]}
3692 @ChgAdded{Version=[2],Text=[The rounding direction is specified here
3693 to ensure portability of output results.]}
3694 @end{implnote}
3695 @begin{ImplNote}
3696 @ChgRef{Version=[2],Kind=[AddedNormal]}
3697 @ChgAdded{Version=[2],Text=[For a machine that supports negative zeros,
3698 it is not specified whether "@ 0.000" or "@en@;0.000" is returned.
3699 See corresponding comment above about integer types with
3700 signed zeros.]}
3701 @end{implnote}
3702
3703 @AttributeLeading{Prefix=<S>, AttrName=<Wide_Image>,
3704 Text=[S'Wide_Image denotes a function
3705 with the following specification:
3706 @begin(Descexample)
3707 @b(function) S'Wide_Image(@RI(Arg) : S'Base)
3708 @b(return) Wide_String
3709 @end(Descexample)
3710
3711 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
3712 @NoPrefix@Defn2{Term=[image], Sec=(of a value)}
3713 The function returns an @Chg{Version=[2],New=[image],Old=[@i(image)]} of
3714 the value of @i(Arg)@Chg{Version=[2],New=[ as a Wide_String],Old=[,
3715 that is, a sequence of characters representing the value in display
3716 form]}.]}
3717 The lower bound of the result is one.@Chg{Version=[2],
3718 New=[ The image has the same sequence of character as
3719 defined for S'Wide_Wide_Image if all the graphic characters are defined in
3720 Wide_Character; otherwise the sequence of characters is
3721 implementation defined (but no shorter than that of S'Wide_Wide_Image for
3722 the same value of Arg).],Old=[]}
3723 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@ChgAdded{Version=[2],
3724 Text=[The sequence of characters of the value returned by
3725 S'Wide_Image when some of the graphic characters of S'Wide_Wide_Image
3726 are not defined in Wide_Character.]}]}
3727
3728 @begin{NotIso}
3729 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 31
3730 through 34 were moved to Wide_Wide_Image.>}]}@Comment{This message should be
3731 deleted if the paragraphs are ever renumbered.}
3732 @end{NotIso}
3733
3734 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
3735 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of an integer value is
3736 the corresponding decimal literal,
3737 without underlines, leading zeros, exponent, or trailing spaces, but
3738 with a single leading character that is either a minus sign or
3739 a space.]}
3740 @begin{ImplNote}
3741 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3742 @ChgDeleted{Version=[2],Text=[
3743 If the machine supports negative zeros for signed integer types,
3744 it is not specified whether "@en@;0" or " 0" should be returned
3745 for negative zero. We don't have enough experience with
3746 such machines to know what is appropriate, and what other
3747 languages do. In any case, the implementation should be
3748 consistent.]}
3749 @end{implnote}
3750
3751 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
3752 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn{nongraphic character}
3753 The image of an enumeration value is either the corresponding
3754 identifier in upper case or the corresponding character literal
3755 (including the two apostrophes); neither leading nor trailing
3756 spaces are included.
3757 For a @i(nongraphic character) (a value of
3758 a character type that has no
3759 enumeration literal associated with it), the
3760 result is a corresponding language-defined or implementation-defined
3761 name in upper case (for example, the image
3762 of the nongraphic character identified as @i(nul) is @lquotes@;NUL@rquotes@; @em the
3763 quotes are not part of the image).]}
3764 @begin{ImplNote}
3765 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3766 @ChgDeleted{Version=[2],Text=[For an enumeration type T
3767 that has @lquotes@;holes@rquotes@;
3768 (caused by an @nt{enumeration_representation_clause}),
3769 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
3770 T'Wide_Image should raise Program_Error if the value
3771 is one of the holes (which is a bounded error anyway,
3772 since holes can be generated only via uninitialized variables and
3773 similar things.]}
3774 @end{ImplNote}
3775
3776 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
3777 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of a
3778 floating point value is a decimal real literal
3779 best approximating the value (rounded away from zero if halfway
3780 between)
3781 with a single leading character that is either a minus sign
3782 or a space, a single digit (that is nonzero unless the value is zero),
3783 a decimal point, S'Digits@en@;1
3784 (see @RefSecNum(Operations of Floating Point Types)) digits
3785 after the decimal point (but one if S'Digits is one),
3786 an upper case E, the sign of the
3787 exponent (either + or @en), and two or more digits
3788 (with leading zeros if necessary)
3789 representing the exponent.
3790 If S'Signed_Zeros is True, then the leading character is a minus
3791 sign for a negatively signed zero.]}
3792 @begin{Honest}
3793 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3794 @ChgDeleted{Version=[2],Text=[Leading zeros are present in the
3795 exponent only if necessary to make the exponent at least two digits.]}
3796 @end{Honest}
3797 @begin{Reason}
3798 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3799 @ChgDeleted{Version=[2],Text=[This image is intended to conform to
3800 that produced by
3801 Text_IO.Float_IO.Put in its default format.]}
3802 @end{reason}
3803 @begin{ImplNote}
3804 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3805 @ChgDeleted{Version=[2],Text=[The rounding direction is specified here
3806 to ensure portability of output results.]}
3807 @end{implnote}
3808
3809 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
3810 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[The image of a
3811 fixed point value is a decimal real literal
3812 best approximating the value (rounded away from zero if halfway between)
3813 with a single leading character that is either a minus sign
3814 or a space, one or more digits before the decimal point
3815 (with no redundant leading zeros),
3816 a decimal point, and S'Aft (see @RefSecNum(Operations of Fixed Point Types))
3817 digits after the decimal point.]}
3818 @begin{Reason}
3819 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3820 @ChgDeleted{Version=[2],Text=[This image is intended to conform to
3821 that produced by Text_IO.Fixed_IO.Put.]}
3822 @end{reason}
3823 @begin{ImplNote}
3824 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3825 @ChgDeleted{Version=[2],Text=[The rounding direction is specified here
3826 to ensure portability of output results.]}
3827 @end{implnote}
3828 @begin{ImplNote}
3829 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
3830 @ChgDeleted{Version=[2],Text=[For a machine that supports negative zeros,
3831 it is not specified whether "@en@;0.000" or " 0.000" is returned.
3832 See corresponding comment above about integer types with
3833 signed zeros.]}
3834 @end{implnote}
3835
3836 @AttributeLeading{Prefix=<S>, AttrName=<Image>,
3837 Text=[S'Image denotes a function with
3838 the following specification:
3839 @begin(Descexample)
3840 @b(function) S'Image(@RI(Arg) : S'Base)
3841 @b(return) String
3842 @end(Descexample)
3843
3844 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
3845 @NoPrefix@;The function returns an image of the value of @i(Arg)
3846 as a String.]}
3847 The lower bound of the result is one. The image has the
3848 same sequence of graphic characters as that defined
3849 for S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]} if all
3850 the graphic characters are defined in Character;
3851 otherwise the sequence of characters is implementation defined (but
3852 no shorter than that of S'@Chg{Version=[2],New=[Wide_Wide_Image],
3853 Old=[Wide_Image]} for the same value of @i(Arg)).
3854 @ChgImplDef{Version=[2],Kind=[Revised],Text=[The
3855 sequence of characters of the value returned by
3856 S'Image when some of the graphic characters of
3857 S'@Chg{Version=[2],New=[Wide_Wide_Image],Old=[Wide_Image]} are not
3858 defined in Character.]}
3859
3860 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
3861 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Width>, ARef=[AI95-00285-01],
3862 Text=[@Chg{Version=[2],New=[S'Wide_Wide_Width denotes the
3863 maximum length of a Wide_Wide_String
3864 returned by S'Wide_Wide_Image over all values of the
3865 subtype S. It denotes zero for a subtype that has
3866 a null range. Its type is @i(universal_integer).],Old=[]}]}
3867
3868 @Attribute{Prefix=<S>, AttrName=<Wide_Width>,
3869 Text=[S'Wide_Width denotes the maximum length of a Wide_String
3870 returned by S'Wide_Image over all values of the
3871 subtype S. It denotes zero for a subtype that has
3872 a null range. Its type is @i(universal_integer).]}
3873
3874 @Attribute{Prefix=<S>, AttrName=<Width>,
3875 Text=[S'Width denotes the maximum length of a String
3876 returned by S'Image over all values of the
3877 subtype S. It denotes zero for a subtype that has
3878 a null range. Its type is @i(universal_integer).]}
3879
3880 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
3881 Leading=<T>, Prefix=<S>, AttrName=<Wide_Wide_Value>, ARef=[AI95-00285-01],
3882 Text=[@Chg{Version=[2],New=[S'Wide_Wide_Value denotes a function
3883 with the following specification:],Old=[]}
3884 @begin(Descexample)
3885 @ChgRef{Version=[2],Kind=[Added]}
3886 @ChgAdded{Version=[2],Text=[@b(function) S'Wide_Wide_Value(@RI(Arg) : Wide_Wide_String)
3887 @b(return) S'Base]}
3888 @end(Descexample)
3889 @ChgRef{Version=[2],Kind=[Added]}
3890 @ChgAdded{Version=[2],NoPrefix=[T],Text=[This function returns
3891 a value given an image of the value
3892 as a Wide_Wide_String, ignoring any leading or trailing spaces.]}]}
3893
3894 @ChgRef{Version=[2],Kind=[Added]}
3895 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@PDefn2{Term=[evaluation], Sec=(Wide_Wide_Value)}
3896 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
3897 For the evaluation of a call on S'Wide_Wide_Value
3898 for an enumeration subtype S,
3899 if the sequence of characters of the parameter (ignoring
3900 leading and trailing spaces) has the syntax
3901 of an enumeration literal and if it corresponds to a literal of the
3902 type of S (or corresponds to the result of S'Wide_Wide_Image
3903 for a nongraphic character of the type),
3904 the result is the corresponding enumeration value;
3905 @IndexCheck{Range_Check}
3906 otherwise Constraint_Error is raised.]}
3907 @begin{Discussion}
3908 @ChgRef{Version=[2],Kind=[Added]}
3909 @ChgAdded{Version=[2],Text=[It's not crystal clear that Range_Check
3910 is appropriate here,
3911 but it doesn't seem worthwhile to invent a whole new check name
3912 just for this weird case, so we decided to lump it in with
3913 Range_Check.]}
3914 @end{discussion}
3915 @begin{Honest}
3916 @ChgRef{Version=[2],Kind=[Added],Ref=[8652/0096],ARef=[AI95-00053-01]}
3917 @ChgAdded{Version=[2],Text=[A sequence of
3918 characters corresponds to the result of
3919 S'Wide_Wide_Image if it is the same ignoring case. Thus, the case of an
3920 image of a nongraphic character does not matter. For example,
3921 Character'Wide_Wide_Value("nul") does not raise Constraint_Error, even though
3922 Character'Wide_Wide_Image returns "NUL" for the nul character.]}
3923 @end{Honest}
3924
3925 @ChgRef{Version=[2],Kind=[Added]}
3926 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
3927 Sec=(raised by failure of run-time check)}
3928 For the evaluation of a call on S'Wide_Wide_Value for an integer
3929 subtype S, if the sequence of characters of the
3930 parameter (ignoring leading and trailing spaces)
3931 has the syntax of an integer literal,
3932 with an optional leading sign character
3933 (plus or minus for a signed type;
3934 only plus for a modular type), and the
3935 corresponding numeric value belongs to the base range of the
3936 type of S, then that value is the result;
3937 @IndexCheck{Range_Check}
3938 otherwise Constraint_Error is raised.]}
3939
3940 @begin(Discussion)
3941 @ChgRef{Version=[2],Kind=[Added]}
3942 @ChgAdded{Version=[2],Text=[We considered allowing 'Value
3943 to return a representable but out-of-range
3944 value without a Constraint_Error. However, we currently require
3945 (see @RefSecNum(Static Expressions and Static Subtypes))
3946 in an @nt{assignment_statement} like "X := <numeric_literal>;" that
3947 the value of the
3948 numeric-literal be in X's base range (at compile time), so it seems
3949 unfriendly and confusing to have a different range allowed for 'Value.
3950 Furthermore, for modular types, without the requirement for being
3951 in the base range, 'Value would have to handle arbitrarily long
3952 literals (since overflow never occurs for modular types).]}
3953 @end(Discussion)
3954
3955 @ChgRef{Version=[2],Kind=[Added]}
3956 @ChgAdded{Version=[2],NoPrefix=[T],Type=[Leading],Text=[For the
3957 evaluation of a call on S'Wide_Wide_Value for a
3958 real subtype S, if the sequence of characters of the
3959 parameter (ignoring leading and trailing spaces)
3960 has the syntax of one of the following:]}
3961 @begin[itemize]
3962 @ChgRef{Version=[2],Kind=[Added]}
3963 @ChgAdded{Version=[2],Text=[@nt[numeric_literal]]}
3964
3965 @ChgRef{Version=[2],Kind=[Added]}
3966 @ChgAdded{Version=[2],Text=<@nt[numeral].[@nt[exponent]]>}
3967
3968 @ChgRef{Version=[2],Kind=[Added]}
3969 @ChgAdded{Version=[2],Text=<.@nt[numeral][@nt[exponent]]>}
3970
3971 @ChgRef{Version=[2],Kind=[Added]}
3972 @ChgAdded{Version=[2],Text=<@nt[base]#@nt[based_numeral].#[@nt[exponent]]>}
3973
3974 @ChgRef{Version=[2],Kind=[Added]}
3975 @ChgAdded{Version=[2],Text=<@nt[base]#.@nt[based_numeral]#[@nt[exponent]]>}
3976 @end{Itemize}
3977
3978 @ChgRef{Version=[2],Kind=[Added]}
3979 @ChgAdded{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
3980 Sec=(raised by failure of run-time check)}
3981 with an optional leading sign character (plus or minus), and if the
3982 corresponding numeric value belongs to the base range of the
3983 type of S, then that value is the result;
3984 @IndexCheck{Range_Check}
3985 otherwise Constraint_Error is raised.
3986 The sign of a zero value is preserved
3987 (positive if none has been specified)
3988 if S'Signed_Zeros is True.]}
3989
3990
3991 @AttributeLeading{Prefix=<S>, AttrName=<Wide_Value>,
3992 Text=[S'Wide_Value denotes a function with
3993 the following specification:
3994 @begin(Descexample)
3995 @b(function) S'Wide_Value(@RI(Arg) : Wide_String)
3996 @b(return) S'Base
3997 @end(Descexample)
3998
3999 @NoPrefix@;This function returns a value given an image of the value
4000 as a Wide_String, ignoring any leading or trailing
4001 spaces.]}@Comment{This marks the end of the Annex text.}
4002
4003 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4004 @NoPrefix@PDefn2{Term=[evaluation], Sec=(Wide_Value)}
4005 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
4006 For the evaluation of a call on S'Wide_Value
4007 for an enumeration subtype S,
4008 if the sequence of characters of the parameter (ignoring
4009 leading and trailing spaces) has the syntax
4010 of an enumeration literal and if it corresponds to a literal of the
4011 type of S (or corresponds to the result of S'Wide_Image
4012 for a @Chg{Version=[2],New=[value],Old=[nongraphic character]} of the type),
4013 the result is the corresponding enumeration value;
4014 @IndexCheck{Range_Check}
4015 otherwise Constraint_Error is raised.
4016 @Chg{Version=[2],New=[For a numeric subtype S,
4017 the evaluation of a call on S'Wide_Value with @i(Arg) of type Wide_String
4018 is equivalent to a call on S'Wide_Wide_Value for a corresponding
4019 @i(Arg) of type Wide_Wide_String.],Old=[]}
4020 @begin{Discussion}
4021 @ChgRef{Version=[2],Kind=[Deleted]}
4022 @ChgDeleted{Version=[2],Text=[It's not crystal clear that Range_Check
4023 is appropriate here,
4024 but it doesn't seem worthwhile to invent a whole new check name
4025 just for this weird case, so we decided to lump it in with
4026 Range_Check.]}
4027 @end{discussion}
4028 @begin{Honest}
4029 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0096],ARef=[AI95-00053-01]}
4030 @ChgRef{Version=[2],Kind=[DeletedAdded]}
4031 @ChgDeleted{Version=[2],Text=[
4032 @Chg{Version=[1],New=[A sequence of characters corresponds to the result of
4033 S'Wide_Image if it is the same ignoring case. Thus, the case of an
4034 image of a nongraphic character does not matter. For example,
4035 Character'Wide_Value("nul") does not raise Constraint_Error, even though
4036 Character'Wide_Image returns "NUL" for the nul character.],Old=[]}]}
4037 @end{Honest}
4038 @begin(Reason)
4039 @ChgRef{Version=[2],Kind=[AddedNormal]}
4040 @ChgAdded{Version=[2],Text=[S'Wide_Value is subtly different from
4041 S'Wide_Wide_Value for enumeration
4042 subtypes since S'Wide_Image might produce a different sequence of
4043 characters than S'Wide_Wide_Image if the enumeration literal
4044 uses characters outside of the predefined type Wide_Character.
4045 That is why we don't just define S'Wide_Value in terms of
4046 S'Wide_Wide_Value for enumeration subtypes.
4047 S'Wide_Value and S'Wide_Wide_Value for numeric subtypes yield
4048 the same result given the same sequence of characters.]}
4049 @end(Reason)
4050
4051 @begin{NotIso}
4052 @ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 44
4053 through 51 were moved to Wide_Wide_Value.>}]}@Comment{This message should be deleted if the
4054 paragraphs are ever renumbered.}
4055 @end{NotIso}
4056
4057 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4058 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
4059 Sec=(raised by failure of run-time check)}
4060 For the evaluation of a call on S'Wide_Value (or S'Value) for an integer
4061 subtype S, if the sequence of characters of the
4062 parameter (ignoring leading and trailing spaces)
4063 has the syntax of an integer literal,
4064 with an optional leading sign character
4065 (plus or minus for a signed type;
4066 only plus for a modular type), and the
4067 corresponding numeric value belongs to the base range of the
4068 type of S, then that value is the result;
4069 @IndexCheck{Range_Check}
4070 otherwise Constraint_Error is raised.]}
4071
4072 @begin(Discussion)
4073 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4074 @ChgDeleted{Version=[2],Text=[We considered allowing 'Value
4075 to return a representable but out-of-range
4076 value without a Constraint_Error. However, we currently require
4077 (see @RefSecNum(Static Expressions and Static Subtypes))
4078 in an @nt{assignment_statement} like "X := <numeric_literal>;" that
4079 the value of the
4080 numeric-literal be in X's base range (at compile time), so it seems
4081 unfriendly and confusing to have a different range allowed for 'Value.
4082 Furthermore, for modular types, without the requirement for being
4083 in the base range, 'Value would have to handle arbitrarily long
4084 literals (since overflow never occurs for modular types).]}
4085 @end(Discussion)
4086
4087 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4088 @ChgDeleted{Version=[2],NoPrefix=[T],Type=[Leading],Text=[For the
4089 evaluation of a call on S'Wide_Value (or S'Value) for a
4090 real subtype S, if the sequence of characters of the
4091 parameter (ignoring leading and trailing spaces)
4092 has the syntax of one of the following:]}
4093 @begin[itemize]
4094 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4095 @ChgDeleted{Version=[2],Text=<@nt[numeric_literal]>}
4096
4097 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4098 @ChgDeleted{Version=[2],Text=<@nt[numeral].[@nt[exponent]]>}
4099
4100 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4101 @ChgDeleted{Version=[2],Text=<.@nt[numeral][@nt[exponent]]>}
4102
4103 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4104 @ChgDeleted{Version=[2],Text=<@nt[base]#@nt[based_numeral].#[@nt[exponent]]>}
4105
4106 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4107 @ChgDeleted{Version=[2],Text=[@nt[base]#.@nt[based_numeral]#[@nt[exponent]]]}
4108 @end{Itemize}
4109
4110 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg]}
4111 @ChgDeleted{Version=[2],NoPrefix=[T],Text=[@Defn2{Term=(Constraint_Error),
4112 Sec=(raised by failure of run-time check)}
4113 with an optional leading sign character (plus or minus), and if the
4114 corresponding numeric value belongs to the base range of the
4115 type of S, then that value is the result;
4116 @IndexCheck{Range_Check}
4117 otherwise Constraint_Error is raised.
4118 The sign of a zero value is preserved
4119 (positive if none has been specified)
4120 if S'Signed_Zeros is True.]}
4121
4122 @AttributeLeading{Prefix=<S>, AttrName=<Value>,
4123 Text=[S'Value denotes a function with
4124 the following specification:
4125 @begin(Descexample)
4126 @b(function) S'Value(@RI(Arg) : String)
4127 @b(return) S'Base
4128 @end(Descexample)
4129
4130 @NoPrefix@;This function returns a value given an image of the value
4131 as a String, ignoring any leading or trailing spaces.]}
4132
4133 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4134 @NoPrefix@PDefn2{Term=[evaluation], Sec=(Value)}
4135 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
4136 For the evaluation of a call on S'Value
4137 for an enumeration subtype S,
4138 if the sequence of characters of the parameter (ignoring
4139 leading and trailing spaces) has the syntax
4140 of an enumeration literal and if it corresponds to a literal of the
4141 type of S (or corresponds to the result of S'Image
4142 for a value of the type),
4143 the result is the corresponding enumeration value;
4144 @IndexCheck{Range_Check}
4145 otherwise Constraint_Error is raised.
4146 For a numeric subtype S,
4147 the evaluation of a call on S'Value with @i(Arg) of type String
4148 is equivalent to a call on S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} for a corresponding
4149 @i(Arg) of type @Chg{Version=[2],New=[Wide_Wide_String],Old=[Wide_String]}.
4150 @begin(Reason)
4151 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4152 S'Value is subtly different from S'@Chg{Version=[2],New=[Wide_Wide_Value],Old=[Wide_Value]} for enumeration
4153 subtypes@Chg{Version=[2],New=[; see the discussion under S'Wide_Value],
4154 Old=[since S'Image might produce a different sequence of
4155 characters than S'Wide_Image if the enumeration literal
4156 uses characters outside of the predefined type Character.
4157 That is why we don't just define S'Value in terms of S'Wide_Value
4158 for enumeration subtypes.
4159 S'Value and S'Wide_Value for numeric subtypes yield
4160 the same result given the same sequence of characters]}.
4161 @end(Reason)
4162
4163 @end(description)
4164 @EndPrefixType{}
4165 @end{RunTime}
4166
4167 @begin{ImplPerm}
4168
4169 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4170 An implementation may extend the @Chg{Version=[2],New=[Wide_Wide_Value, ],
4171 Old=[Wide_Value, ]}
4172 @Redundant[@Chg{Version=[2],New=[Wide_Value, ],Old=[]}Value,
4173 @Chg{Version=[2],New=[Wide_Wide_Image, ],
4174 Old=[]}Wide_Image, and Image] attributes
4175 of a floating point type
4176 to support special values such as infinities and NaNs.
4177
4178 @begin{TheProof}
4179 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4180 The permission is really only necessary for @Chg{Version=[2],New=[Wide_Wide_Value],
4181 Old=[Wide_Value]},
4182 because Value @Chg{Version=[2],New=[and Wide_Value are],Old=[is]} defined in
4183 terms of @Chg{Version=[2],New=[Wide_Wide_Value],
4184 Old=[Wide_Value]},
4185 and because the behavior of @Chg{Version=[2],New=[Wide_Wide_Image, ],
4186 Old=[]}Wide_Image@Chg{Version=[2],New=[,],Old=[]} and Image is already
4187 unspecified for things like infinities and NaNs.
4188 @end{TheProof}
4189 @begin{Reason}
4190 This is to allow implementations to define full support for IEEE
4191 arithmetic.
4192 See also the similar permission for Get in
4193 @RefSecNum{Input-Output for Real Types}.
4194 @end{Reason}
4195 @end{ImplPerm}
4196
4197 @begin{Notes}
4198 The evaluation of S'First or S'Last never raises an exception.
4199 If a scalar subtype S has a nonnull range, S'First and S'Last
4200 belong to this range. These values can, for example, always be
4201 assigned to a variable of subtype S.
4202 @begin(Discussion)
4203 This paragraph addresses an issue that came up with Ada 83,
4204 where for fixed point types, the end points of the range
4205 specified in the type definition were not necessarily within
4206 the base range of the type. However, it was later clarified (and
4207 we reconfirm it in @RefSec(Fixed Point Types)) that the First and
4208 Last attributes reflect the true bounds chosen for the type, not the
4209 bounds specified in the type definition (which might be outside
4210 the ultimately chosen base range).
4211 @end(Discussion)
4212
4213 For a subtype of a scalar type, the result delivered by the attributes
4214 Succ, Pred, and Value might not belong to the subtype; similarly,
4215 the actual parameters
4216 of the attributes Succ, Pred, and Image need not belong to the subtype.
4217
4218 For any value V (including any nongraphic character) of an
4219 enumeration subtype S, S'Value(S'Image(V)) equals V,
4220 as @Chg{Version=[2],New=[do],Old=[does]} S'Wide_Value(S'Wide_Image(V))@Chg{Version=[2],
4221 New=[ and S'Wide_Wide_Value(S'Wide_Wide_Image(V))],Old=[]}.
4222 @Chg{Version=[2],New=[None of these
4223 expressions],Old=[Neither expression]} ever @Chg{Version=[2],New=[raise],Old=[raises]}
4224 Constraint_Error.
4225 @end{Notes}
4226
4227 @begin{Examples}
4228 @Leading@keepnext@i(Examples of ranges:)
4229 @begin{Example}
4230 -10 .. 10
4231 X .. X + 1
4232 0.0 .. 2.0*Pi
4233 Red .. Green --@RI[ see @RefSecNum{Enumeration Types}]
4234 1 .. 0 --@RI[ a null range]
4235 Table'Range --@RI[ a range attribute reference (see @RefSecNum{Array Types})]
4236
4237 @end{Example}
4238 @Leading@keepnext@i(Examples of range constraints:)
4239 @begin{Example}
4240 @key(range) -999.0 .. +999.0
4241 @key(range) S'First+1 .. S'Last-1
4242 @end{Example}
4243 @end{Examples}
4244
4245 @begin{Incompatible83}
4246 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
4247 @Defn{incompatibilities with Ada 83}
4248 S'Base is no longer defined for nonscalar types.
4249 One conceivable existing use of S'Base for nonscalar types is
4250 S'Base'Size where S is a generic formal private type.
4251 However, that is not generally useful because the actual
4252 subtype corresponding to S might be a constrained array
4253 or discriminated type, which would mean that S'Base'Size might
4254 very well overflow (for example, S'Base'Size where S is
4255 a constrained subtype of String will generally be 8 * (Integer'Last + 1)).
4256 For derived discriminated types that are packed, S'Base'Size might not even
4257 be well defined if the first subtype is constrained, thereby allowing
4258 some amount of normally required @lquotes@;dope@rquotes@; to have been squeezed out
4259 in the packing. Hence our conclusion is that S'Base'Size is
4260 not generally useful in a generic, and does not justify keeping
4261 the attribute Base for nonscalar types just so it can be used
4262 as a @Chg{New=[@nt{prefix}],Old=[prefix]}.
4263
4264 @end{Incompatible83}
4265
4266 @begin{Extend83}
4267 @Defn{extensions to Ada 83}
4268 The attribute S'Base for a scalar subtype is now permitted
4269 anywhere a @nt{subtype_mark} is permitted.
4270 S'Base'First .. S'Base'Last
4271 is the base range of the type.
4272 Using an @nt{attribute_@!definition_@!clause},
4273 one cannot specify any subtype-specific attributes
4274 for the subtype denoted by S'Base
4275 (the base subtype).
4276
4277 The attribute S'Range is now allowed for scalar subtypes.
4278
4279 The attributes S'Min and S'Max are now defined, and made available for all
4280 scalar types.
4281
4282 The attributes S'Succ, S'Pred, S'Image, S'Value, and S'Width are
4283 now defined for real types as well as discrete types.
4284
4285 Wide_String versions of S'Image and S'Value are defined.
4286 These are called S'Wide_Image and S'Wide_Value to avoid
4287 introducing ambiguities involving uses of these attributes
4288 with string literals.
4289 @end{Extend83}
4290
4291 @begin{DiffWord83}
4292 We now use the syntactic category @nt<range_attribute_reference> since
4293 it is now syntactically distinguished from other attribute references.
4294
4295 The definition of S'Base has been moved here from
4296 3.3.3 since it now applies only to scalar types.
4297
4298 More explicit rules are provided for nongraphic characters.
4299 @end{DiffWord83}
4300
4301 @begin{Extend95}
4302 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4303 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4304 The attributes Wide_Wide_Image, Wide_Wide_Value, and Wide_Wide_Width are new.
4305 Note that Wide_Image and Wide_Value are now defined in terms of
4306 Wide_Wide_Image and Wide_Wide_Value, but the image of types other than
4307 characters have not changed.]}
4308 @end{Extend95}
4309
4310 @begin{DiffWord95}
4311 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4312 @ChgAdded{Version=[2],Text=[
4313 The Wide_Image and Wide_Value attributes are now defined in terms of
4314 Wide_Wide_Image and Wide_Wide_Value, but the images of numeric types
4315 have not changed.]}
4316 @end{DiffWord95}
4317
4318
4319 @LabeledSubClause{Enumeration Types}
4320
4321 @begin{Intro}
4322 @Redundant[@Defn{enumeration type}
4323 An @nt<enumeration_type_definition> defines an enumeration type.]
4324 @end{Intro}
4325
4326 @begin{Syntax}
4327 @Syn{lhs=<enumeration_type_definition>,rhs="
4328 (@Syn2{enumeration_literal_specification} {, @Syn2{enumeration_literal_specification}})"}
4329
4330
4331 @Syn{lhs=<enumeration_literal_specification>,
4332 rhs=" @Syn2{defining_identifier} | @Syn2{defining_character_literal}"}
4333
4334 @Syn{lhs=<defining_character_literal>,rhs="@Syn2{character_literal}"}
4335 @end{Syntax}
4336
4337 @begin{Legality}
4338 @Redundant[The @nt<defining_identifier>s and
4339 @nt<defining_character_literal>s listed in an
4340 @nt<enumeration_type_definition> shall be distinct.]
4341 @begin{TheProof}
4342 This is a ramification of the normal disallowance
4343 of homographs explicitly declared immediately in the same
4344 declarative region.@end{theproof}
4345 @end{Legality}
4346
4347 @begin{StaticSem}
4348 @Defn{enumeration literal}
4349 Each @nt<enumeration_literal_specification> is the explicit declaration
4350 of the corresponding @i(enumeration literal): it declares
4351 a parameterless function,
4352 whose defining name is the @nt<defining_@!identifier>
4353 or @nt<defining_@!character_@!literal>, and whose result type
4354 is the enumeration type.
4355 @begin{Reason}
4356 This rule defines the profile of the enumeration literal,
4357 which is used in the various types of conformance.
4358 @end{Reason}
4359 @begin{Ramification}
4360 The parameterless function associated with an enumeration literal
4361 is fully defined by the @nt<enumeration_type_definition>;
4362 a body is not permitted for it,
4363 and it never fails the Elaboration_Check when called.
4364 @end{Ramification}
4365
4366 Each enumeration literal corresponds to a distinct value
4367 of the enumeration type, and to a distinct position number.
4368 @PDefn2{Term=[position number], Sec=(of an enumeration value)}
4369 The position number of the value of
4370 the first listed enumeration literal
4371 is zero; the position number of the value of each
4372 subsequent enumeration literal
4373 is one more than that of its predecessor in the list.
4374
4375 @redundant[The predefined order relations between values of
4376 the enumeration type follow the
4377 order of corresponding position numbers.]
4378
4379 @redundant[@PDefn2{Term=[overloaded], Sec=(enumeration literal)}
4380 If the same @nt<defining_identifier> or
4381 @nt<defining_character_literal> is specified in more than one
4382 @nt<enumeration_@!type_@!definition>, the corresponding enumeration literals
4383 are said to be @i(overloaded). At any place where an overloaded
4384 enumeration literal occurs in the text of a program, the type
4385 of the enumeration literal has to be determinable from the context
4386 (see @RefSecNum(The Context of Overload Resolution)).]
4387 @end{StaticSem}
4388
4389 @begin{RunTime}
4390 @PDefn2{Term=[elaboration], Sec=(enumeration_type_definition)}
4391 @Defn2{Term=[constrained], Sec=(subtype)}
4392 @Defn2{Term=[unconstrained], Sec=(subtype)}
4393 The elaboration of an @nt<enumeration_type_definition> creates
4394 the enumeration type and its first subtype,
4395 which is constrained to the base range of the type.
4396 @begin{Ramification}
4397 The first subtype of a discrete type is always constrained,
4398 except in the case of a derived type whose parent subtype
4399 is Whatever'Base.
4400 @end{Ramification}
4401
4402 When called, the parameterless function associated with an enumeration literal
4403 returns the corresponding value of the enumeration type.
4404 @end{RunTime}
4405
4406 @begin{Notes}
4407 If an enumeration literal occurs in a context that does not
4408 otherwise suffice to determine the type of the literal, then qualification
4409 by the name of the enumeration type is one way to resolve
4410 the ambiguity (see @RefSecNum(Qualified Expressions)).
4411 @end{Notes}
4412
4413 @begin{Examples}
4414 @Leading@keepnext@i(Examples of enumeration types and subtypes: )
4415 @begin(Example)
4416 @key(type) Day @key(is) (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
4417 @key(type) Suit @key(is) (Clubs, Diamonds, Hearts, Spades);
4418 @key(type) Gender @key(is) (M, F);
4419 @key(type) Level @key(is) (Low, Medium, Urgent);
4420 @key(type) Color @key(is) (White, Red, Yellow, Green, Blue, Brown, Black);
4421 @key(type) Light @key(is) (Red, Amber, Green); --@RI[ Red and Green are overloaded]
4422
4423 @key(type) Hexa @key(is) ('A', 'B', 'C', 'D', 'E', 'F');
4424 @key(type) Mixed @key(is) ('A', 'B', '*', B, None, '?', '%');
4425
4426 @key(subtype) Weekday @key(is) Day @key(range) Mon .. Fri;
4427 @key(subtype) Major @key(is) Suit @key(range) Hearts .. Spades;
4428 @key(subtype) Rainbow @key(is) Color @key(range) Red .. Blue; --@RI[ the Color Red, not the Light]
4429 @end(Example)
4430 @end{Examples}
4431
4432 @begin{DiffWord83}
4433 The syntax rule for @nt{defining_character_literal} is new.
4434 It is used for the defining occurrence of a @nt{character_literal},
4435 analogously to @nt{defining_identifier}.
4436 Usage occurrences use the @nt{name} or @nt{selector_name}
4437 syntactic categories.
4438
4439 We emphasize the fact that an enumeration literal denotes
4440 a function, which is called to produce a value.
4441 @end{DiffWord83}
4442
4443
4444 @LabeledSubClause{Character Types}
4445
4446 @begin{StaticSem}
4447 @Defn{character type}
4448 An enumeration type is said to be a @i(character type) if at least
4449 one of its enumeration literals is a @nt<character_literal>.
4450
4451 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4452 @Defn{Latin-1}
4453 @Defn{BMP}
4454 @Chg{Version=[2],New=[@Defn{ISO/IEC 10646:2003}],Old=[@Defn{ISO 10646}]}
4455 @Defn{Character}
4456 The predefined type Character is a character type whose values
4457 correspond to the 256 code positions of Row 00 (also
4458 known as Latin-1) of the @Chg{Version=[2],New=[ISO/IEC 10646:2003],
4459 Old=[ISO 10646]}
4460 Basic Multilingual Plane (BMP).
4461 Each of the graphic characters of Row 00 of the BMP has
4462 a corresponding @nt<character_literal> in Character.
4463 Each of the nongraphic positions of Row 00 (0000-001F and 007F-009F)
4464 has a corresponding language-defined name, which is not usable as an
4465 enumeration literal,
4466 but which is usable with the attributes @Chg{Version=[2],New=[Image,
4467 Wide_Image, Wide_Wide_Image, Value, Wide_Value, and Wide_Wide_Value],
4468 Old=[(Wide_)Image and (Wide_)Value]};
4469 these names are given in the definition of type Character
4470 in @RefSec{The Package Standard}, but are set in @i{italics}.
4471 @Defn2{Term=[italics],Sec=(nongraphic characters)}
4472
4473 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4474 @Defn{Wide_Character}
4475 @Defn{BMP}
4476 @Chg{Version=[2],New=[@Defn{ISO/IEC 10646:2003}],Old=[@Defn{ISO 10646}]}
4477 The predefined type Wide_Character is a character type whose
4478 values correspond to the 65536 code positions of the @Chg{Version=[2],
4479 New=[ISO/IEC 10646:2003],Old=[ISO 10646]}
4480 Basic Multilingual Plane (BMP).
4481 Each of the graphic characters of the BMP has
4482 a corresponding @nt<character_literal> in Wide_Character.
4483 The first 256 values of Wide_Character
4484 have the same @nt<character_literal> or language-defined
4485 name as defined for Character. @Chg{Version=[2],New=[Each of the
4486 @ntf{graphic_character}s has],Old=[The last 2 values
4487 of Wide_Character correspond to the nongraphic
4488 positions FFFE and FFFF of the BMP,
4489 and are assigned
4490 the language-defined names @i(FFFE) and @i(FFFF). As with the other
4491 language-defined names for nongraphic characters,
4492 the names @i(FFFE) and @i(FFFF) are usable only with the attributes
4493 (Wide_)Image and (Wide_)Value; they are not usable as enumeration
4494 literals.
4495 All other values of Wide_Character are considered graphic characters,
4496 and have]} a corresponding @nt<character_literal>.
4497
4498 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00285-01]}
4499 @ChgAdded{Version=[2],Text=[@Defn{Wide_Wide_Character}
4500 @Defn{BMP}
4501 @Chg{Version=[2],New=[@Defn{ISO/IEC 10646:2003}],Old=[@Defn{ISO 10646}]}
4502 The predefined type Wide_Wide_Character is a character type whose values
4503 correspond to the 2147483648 code positions of the ISO/IEC 10646:2003 character
4504 set. Each of the @ntf{graphic_character}s has a corresponding
4505 @nt{character_literal} in
4506 Wide_Wide_Character. The first 65536 values of Wide_Wide_Character have the
4507 same @nt{character_literal} or language-defined name as defined for
4508 Wide_Character.]}
4509
4510 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00285-01]}
4511 @ChgAdded{Version=[2],Text=[The characters whose code position is larger
4512 than 16#FF# and which are not @ntf{graphic_character}s have language-defined
4513 names which are formed by appending to the string "Hex_" the
4514 representation of their code position in hexadecimal as eight extended digits.
4515 As with other language-defined names, these names are usable only with the
4516 attributes (Wide_)Wide_Image and (Wide_)Wide_Value; they are not usable as
4517 enumeration literals.]}
4518
4519 @begin{Reason}
4520 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00285-01]}
4521 The language-defined names are not usable as
4522 enumeration literals to avoid "polluting" the name space. Since
4523 Wide_Character @Chg{Version=[2],New=[and Wide_Wide_Character ],Old=[]}are
4524 defined in Standard, if the @Chg{Version=[2],New=[language-defined ],
4525 Old=[]}names @Chg{Version=[2],New=[],Old=[FFFE and FFFF ]}were usable
4526 as enumeration literals, they would hide other nonoverloadable declarations
4527 with the same names in @key[use]-d packages.]}
4528
4529 @ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00285-01]}
4530 @ChgDeleted{Version=[2],Text=[ISO 10646 has not defined the meaning of
4531 all of the code positions
4532 from 0100 through FFFD, but they are all considered graphic characters by
4533 Ada to simplify the implementation, and to allow for revisions to ISO 10646.
4534 In ISO 10646, FFFE and FFFF are special, and will never be associated
4535 with graphic characters in any revision.]}
4536 @end{Reason}
4537 @end{StaticSem}
4538
4539 @begin{ImplPerm}
4540 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00285-01]}
4541 @ChgDeleted{Version=[2],Text=[@Defn{localization}
4542 In a nonstandard mode, an implementation may provide
4543 other interpretations for the predefined types Character and
4544 Wide_Character@Redundant[, to conform to local conventions].]}
4545 @end{ImplPerm}
4546
4547 @begin{ImplAdvice}
4548 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00285-01]}
4549 @ChgDeleted{Version=[2],Text=[@Defn{localization}
4550 If an implementation supports a mode with alternative interpretations
4551 for Character and Wide_Character, the set of graphic characters
4552 of Character should nevertheless remain
4553 a proper subset of the set of graphic characters of Wide_Character.
4554 Any character set @lquotes@;localizations@rquotes@; should be reflected in the results of
4555 the subprograms defined in the language-defined package Characters.Handling
4556 (see @RefSecNum{Character Handling}) available in such a mode.
4557 In a mode with an alternative interpretation of Character, the
4558 implementation should also support a corresponding change in what is
4559 a legal @ntf<identifier_letter>.]}
4560 @ChgNote{We won't add an ChgImplAdvice here, because we would need to add
4561 and remove it in the same command.}
4562 @end{ImplAdvice}
4563
4564 @begin{Notes}
4565 The language-defined library package Characters.Latin_1
4566 (see @RefSecNum(The Package Characters.Latin_1))
4567 includes the declaration of constants
4568 denoting control characters, lower case characters, and special characters
4569 of the predefined type Character.
4570 @begin{Honest}
4571 The package ASCII does the same, but only for the first
4572 128 characters of Character. Hence, it is an obsolescent
4573 package, and we no longer mention it here.
4574 @end{Honest}
4575
4576 A conventional character set such as @i(EBCDIC) can be declared as
4577 a character type; the internal codes of the characters can be specified
4578 by an @nt<enumeration_representation_clause> as explained in
4579 clause @RefSecNum(Enumeration Representation Clauses).
4580 @end{Notes}
4581
4582 @begin{Examples}
4583 @Leading@keepnext@i(Example of a character type: )
4584 @begin(Example)
4585 @key(type) Roman_Digit @key(is) ('I', 'V', 'X', 'L', 'C', 'D', 'M');
4586 @end(Example)
4587 @end{Examples}
4588
4589 @begin{Inconsistent83}
4590 @Defn{inconsistencies with Ada 83}
4591 The declaration of Wide_Character in package Standard hides
4592 use-visible declarations with the same defining identifier.
4593 In the unlikely event that an Ada 83 program had depended on
4594 such a use-visible declaration, and the program remains
4595 legal after the substitution of Standard.Wide_Character,
4596 the meaning of the program will be different.
4597 @end{Inconsistent83}
4598
4599 @begin{Incompatible83}
4600 @Defn{incompatibilities with Ada 83}
4601 The presence of Wide_Character in package Standard means that
4602 an expression such as
4603 @begin(Example)
4604 'a' = 'b'
4605 @end(Example)
4606
4607 is ambiguous in Ada 95, whereas in Ada 83 both
4608 literals could be resolved to be of type Character.
4609
4610 The change in visibility rules (see @RefSecNum(Literals))
4611 for character literals means
4612 that additional qualification might be necessary to resolve
4613 expressions involving overloaded subprograms and
4614 character literals.
4615 @end{Incompatible83}
4616
4617 @begin{Extend83}
4618 @Defn{extensions to Ada 83}
4619 The type Character has been extended to have 256 positions,
4620 and the type Wide_Character has been added.
4621 Note that this change was already approved by the ARG
4622 for Ada 83 conforming compilers.
4623
4624 The rules for referencing character literals are changed
4625 (see @RefSecNum(Literals)),
4626 so that the declaration of the character type need
4627 not be directly visible to use its literals,
4628 similar to @b(null) and string literals.
4629 Context is used to resolve their type.
4630 @end{Extend83}
4631
4632 @begin{Inconsistent95}
4633 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4634 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
4635 Ada 95 defined most characters in Wide_Character to be graphic characters,
4636 while Ada 2005 uses the categorizations from ISO-10646:2003. It also
4637 provides language-defined names for all non-graphic characters. That
4638 means that in Ada 2005, Wide_Character'Wide_Value will raise Constraint_Error
4639 for a string representing a @nt{character_literal} of a non-graphic character,
4640 while Ada 95 would have accepted it. Similarly, the result of
4641 Wide_Character'Wide_Image will change for such non-graphic characters.]}
4642
4643 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]}
4644 @ChgAdded{Version=[2],Text=[The language-defined names FFFE and FFFF were
4645 replaced by a consistent set of language-defined names for all non-graphic
4646 characters with positions greater than 16#FF#. That means that
4647 in Ada 2005, Wide_Character'Wide_Value("FFFE") will raise Constraint_Error
4648 while Ada 95 would have accepted it. Similarly, the result of
4649 Wide_Character'Wide_Image will change for the position numbers 16#FFFE#
4650 and 16#FFFF#. It is very unlikely that this will matter in practice,
4651 as these names do not represent useable characters.]}
4652
4653 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01],ARef=[AI95-00395-01]}
4654 @ChgAdded{Version=[2],Text=[Because of the previously mentioned changes to
4655 the Wide_Character'Wide_Image of various character values, the value of
4656 attribute Wide_Width will change for some subtypes of Wide_Character.
4657 However, the new language-defined names were chosen so that the value of
4658 Wide_Character'Wide_Width itself does not change.]}
4659
4660 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4661 @ChgAdded{Version=[2],Text=[The declaration of Wide_Wide_Character in
4662 package Standard hides use-visible declarations with the same defining
4663 identifier. In the (very) unlikely event that an Ada 95 program had
4664 depended on such a use-visible declaration, and the program remains
4665 legal after the substitution of Standard.Wide_Wide_Character,
4666 the meaning of the program will be different.]}
4667 @end{Inconsistent95}
4668
4669 @begin{Extend95}
4670 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4671 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
4672 The type Wide_Wide_Character is new.]}
4673 @end{Extend95}
4674
4675 @begin{DiffWord95}
4676 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4677 @ChgAdded{Version=[2],Text=[Characters are now defined in terms of
4678 the entire ISO/IEC 10646:2003 character set.]}
4679
4680 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00285-01]}
4681 @ChgAdded{Version=[2],Text=[We dropped the @ImplAdviceTitle for
4682 non-standard interpretation of character sets; an implementation can
4683 do what it wants in a non-standard mode, so there isn't much point to
4684 any advice.]}
4685 @end{DiffWord95}
4686
4687
4688 @LabeledSubClause{Boolean Types}
4689
4690 @begin{StaticSem}
4691 @Defn{Boolean}
4692 There is a predefined enumeration type named Boolean,
4693 @Redundant[declared in the visible part of package Standard].
4694 @Defn{False}
4695 @Defn{True}
4696 It has the two enumeration literals False and True ordered
4697 with the relation False < True.
4698 @Defn{boolean type}
4699 Any descendant of the predefined type Boolean is called
4700 a @i(boolean) type.
4701 @begin{ImplNote}
4702 An implementation is not required to support
4703 enumeration representation clauses on boolean types that
4704 impose an unacceptable implementation burden.
4705 See @RefSec(Enumeration Representation Clauses).
4706 However, it is generally straightforward to support representations
4707 where False is zero and True is 2**n @en@; 1 for some n.
4708 @end{ImplNote}
4709 @end{StaticSem}
4710
4711 @LabeledSubClause{Integer Types}
4712
4713 @begin{Intro}
4714 @Defn{integer type}
4715 @Defn{signed integer type}
4716 @Defn{modular type}
4717 An @nt<integer_type_definition> defines an integer type;
4718 it defines either a @i(signed)
4719 integer type, or a @i(modular) integer type.
4720 The base range
4721 of a signed integer type includes at
4722 least the values of the specified
4723 range.
4724 A modular type is an integer type with all arithmetic modulo
4725 a specified positive @i(modulus);
4726 such a type corresponds to an unsigned
4727 type with wrap-around semantics.
4728 @IndexSee{Term=[unsigned type],See=(modular type)}
4729 @end{Intro}
4730
4731 @begin{Syntax}
4732 @Syn{lhs=<integer_type_definition>,
4733 rhs="@Syn2{signed_integer_type_definition} | @Syn2{modular_type_definition}"}
4734
4735 @Syn{lhs=<signed_integer_type_definition>,
4736 rhs="@key(range) @SynI{static_}@Syn2{simple_expression} .. @SynI{static_}@Syn2{simple_expression}"}
4737 @begin{Discussion}
4738 We don't call this a @nt<range_constraint>,
4739 because it is rather different @em not only is
4740 it required to be static, but the associated overload resolution rules are
4741 different than for normal range constraints. A similar comment applies to
4742 @nt{real_range_specification}.
4743 This used to be @ntf<integer_range_specification> but when we
4744 added support for modular types, it seemed overkill to have three levels
4745 of syntax rules, and just calling these
4746 @ntf<signed_integer_range_specification>
4747 and @ntf<modular_range_specification> loses the fact that they
4748 are defining different classes of types, which is important for
4749 the generic type matching rules.
4750 @end{Discussion}
4751
4752 @Syn{lhs=<modular_type_definition>,
4753 rhs="@key(mod) @SynI{static_}@Syn2{expression}"}
4754 @end{Syntax}
4755
4756 @begin{Resolution}
4757 @PDefn2{Term=[expected type],
4758 Sec=(signed_integer_type_definition simple_expression)}
4759 Each @nt<simple_expression> in a
4760 @nt<signed_integer_type_definition> is expected to be of any integer type;
4761 they need not be of the same type.
4762 @PDefn2{Term=[expected type],
4763 Sec=(modular_type_definition expression)}
4764 The @nt<expression> in a
4765 @nt<modular_type_definition> is likewise expected to be of any integer type.
4766 @end{Resolution}
4767
4768 @begin{Legality}
4769 The @nt<simple_expression>s of a
4770 @nt<signed_integer_type_definition>
4771 shall be static, and their values shall be in the
4772 range System.Min_Int .. System.Max_Int.
4773
4774 @Defn2{Term=[modulus], Sec=(of a modular type)}
4775 @Defn{Max_Binary_Modulus}
4776 @Defn{Max_Nonbinary_Modulus}
4777 The @nt<expression> of a @nt<modular_type_definition> shall be static,
4778 and its value (the @i(modulus)) shall be positive,
4779 and shall be no greater than System.Max_Binary_Modulus if a power of 2,
4780 or no greater than System.Max_Nonbinary_Modulus if not.
4781 @begin(Reason)
4782 For a 2's-complement machine, supporting nonbinary moduli greater
4783 than System.Max_Int can be quite difficult, whereas essentially any
4784 binary moduli are straightforward to support, up to 2*System.Max_Int+2,
4785 so this justifies having two separate limits.
4786 @end(Reason)
4787 @end{Legality}
4788
4789 @begin{StaticSem}
4790 The set of values for a signed integer type is the (infinite)
4791 set of mathematical
4792 integers@Redundant[, though only values of the base range of the type
4793 are fully supported for run-time operations].
4794 The set of values for a modular integer type are the values from
4795 0 to one less than the modulus,
4796 inclusive.
4797
4798 @PDefn2{Term=[base range], Sec=(of a signed integer type)}
4799 A @nt<signed_integer_type_definition> defines an integer type whose
4800 base range
4801 includes at least the values of the @nt<simple_expression>s and
4802 is symmetric about zero, excepting possibly an extra negative value.
4803 @Defn2{Term=[constrained], Sec=(subtype)}
4804 @Defn2{Term=[unconstrained], Sec=(subtype)}
4805 A @nt<signed_integer_type_definition> also defines a constrained first
4806 subtype of the type, with a range whose bounds are given by
4807 the values of the @nt<simple_expression>s, converted to the type being defined.
4808 @begin{ImplNote}
4809 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
4810 The base range of a signed integer type might be much larger than is
4811 necessary to satisfy the @Chg{Version=[2],New=[above],Old=[aboved]}
4812 requirements.
4813 @end{ImplNote}
4814 @begin{Honest}
4815 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
4816 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not
4817 an @i{implicit subtype conversion} (which is something that happens at
4818 overload resolution, see
4819 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
4820 the freezing rules are not invoked on the type (which is important so that
4821 representation items can be given for the type).
4822 @PDefn2{Term=[subtype conversion],Sec=(bounds of signed integer type)}]}
4823 @end{Honest}
4824
4825 @PDefn2{Term=[base range], Sec=(of a modular type)}
4826 A @nt<modular_type_definition> defines a modular type whose base range
4827 is from zero to one less than the given modulus.
4828 @Defn2{Term=[constrained], Sec=(subtype)}
4829 @Defn2{Term=[unconstrained], Sec=(subtype)}
4830 A @nt<modular_type_definition> also defines a constrained first
4831 subtype of the type with a range that is the same as the base range of
4832 the type.
4833
4834 @Defn{Integer}
4835 There is a predefined signed integer subtype named
4836 Integer@Redundant[,
4837 declared in the visible part of
4838 package Standard].
4839 It is constrained to the base range of its type.
4840 @begin{Reason}
4841 Integer is a constrained subtype, rather than an unconstrained
4842 subtype. This means that on assignment to an object of subtype Integer,
4843 a range check is required. On the other hand, an object of subtype
4844 Integer'Base is unconstrained, and no range check (only overflow check)
4845 is required on assignment. For example, if the object is held in an
4846 extended-length register, its value might be outside of
4847 Integer'First .. Integer'Last. All parameter and result subtypes
4848 of the predefined integer operators are of such unconstrained subtypes,
4849 allowing extended-length registers to be used as operands or
4850 for the result.
4851 In an earlier version of Ada 95, Integer was unconstrained. However,
4852 the fact that certain Constraint_Errors might be omitted or appear
4853 elsewhere was felt to be an undesirable upward inconsistency in this case.
4854 Note that for Float, the opposite conclusion was reached, partly because
4855 of the high cost of performing range checks when not actually necessary.
4856 Objects of subtype Float are unconstrained, and no range checks, only
4857 overflow checks, are performed for them.
4858 @end{Reason}
4859
4860 @Leading@Defn{Natural}
4861 @Defn{Positive}
4862 Integer has two predefined subtypes,
4863 @Redundant[declared in the visible part of package Standard:]
4864 @begin{Example}
4865 @key[subtype] Natural @key[is] Integer @key[range] 0 .. Integer'Last;
4866 @key[subtype] Positive @key[is] Integer @key[range] 1 .. Integer'Last;
4867 @end{Example}
4868
4869 @Defn{root_integer}
4870 @Defn{Min_Int}
4871 @Defn{Max_Int}
4872 A type defined by an @nt<integer_type_definition> is implicitly
4873 derived from @i(root_integer), an anonymous
4874 predefined (specific) integer type, whose base
4875 range is System.Min_Int .. System.Max_Int.
4876 However, the base range of the new type is not inherited from
4877 @i{root_integer}, but is instead determined by the range or modulus
4878 specified by the @nt{integer_type_definition}.
4879 @PDefn{universal_integer}
4880 @Defn{integer literals}
4881 @Redundant[Integer literals are all of the type @i(universal_integer),
4882 the universal type (see @RefSecNum(Derivation Classes)) for the
4883 class rooted at @i(root_integer), allowing their use with
4884 the operations of any integer type.]
4885 @begin{Discussion}
4886 This implicit derivation is not considered exactly equivalent to
4887 explicit derivation via a @nt<derived_type_definition>. In particular,
4888 integer types defined via a @nt<derived_type_definition> inherit their
4889 base range from their parent type. A type defined by
4890 an @nt<integer_type_definition> does not necessarily inherit
4891 its base range from @i(root_integer).
4892 It is not specified whether the implicit derivation from
4893 @i(root_integer) is direct or indirect, not that it really matters.
4894 All we want is for all integer types to be descendants of @i(root_integer).
4895
4896 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0099],ARef=[AI95-00152-01]}
4897 @Chg{New=[Note that this derivation does not imply any inheritance of
4898 subprograms. Subprograms are inherited only for types derived by a
4899 @nt{derived_@!type_@!definition} (see @RefSecNum{Derived Types and Classes}),
4900 or a @nt{private_@!extension_@!declaration} (see
4901 @RefSecNum{Private Types and Private Extensions}, @RefSecNum{Private Operations},
4902 and @RefSecNum{Formal Private and Derived Types}).],Old=[]}
4903 @end{Discussion}
4904 @begin{ImplNote}
4905 It is the intent that even nonstandard integer
4906 types (see below) will be descendants of @i(root_integer), even though they
4907 might have a base range that exceeds that of @i(root_integer).
4908 This causes no problem for static calculations, which
4909 are performed without range restrictions
4910 (see @RefSecNum(Static Expressions and Static Subtypes)). However
4911 for run-time calculations, it is possible that Constraint_Error
4912 might be raised when using an operator of @i(root_integer)
4913 on the result of 'Val applied to a value of a nonstandard integer type.
4914 @end{ImplNote}
4915
4916 @PDefn2{Term=[position number], Sec=(of an integer value)}
4917 The @i(position number) of an integer value is equal to the value.
4918
4919 @begin{Wide}
4920 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00340-01]}
4921 @Leading@keepnext@;For @PrefixType{every modular subtype S},
4922 the following @Chg{Version=[2],New=[attributes are],Old=[attribute is]} defined:
4923 @end{Wide}
4924 @begin(description)
4925 @ChgAttribute{Version=[2],Kind=[Added],ChginAnnex=[T],
4926 Leading=<T>, Prefix=<S>, AttrName=<Mod>, ARef=[AI95-00340-01],
4927 Text=[@Chg{Version=[2],New=[S'Mod denotes a function with the following specification:],Old=[]}
4928
4929 @begin(Descexample)
4930 @ChgRef{Version=[2],Kind=[Added]}
4931 @ChgAdded{Version=[2],Text=[@key{function} S'Mod (@RI{Arg} : @RI{universal_integer})
4932 @key{return} S'Base]}
4933 @end(Descexample)
4934
4935 @ChgRef{Version=[2],Kind=[Added]}
4936 @ChgAdded{Version=[2],NoPrefix=[T],Text=[This function returns @i{Arg}
4937 @key{mod} S'Modulus, as a value of the type of S.]}]}@Comment{end attribute Mod}
4938
4939 @Attribute{Prefix=<S>, AttrName=<Modulus>,
4940 Text=[S'Modulus yields the modulus of the type of S, as a value of the
4941 type @i(universal_integer).]}
4942 @end(description)
4943
4944 @end{StaticSem}
4945
4946 @begin{RunTime}
4947 @PDefn2{Term=[elaboration], Sec=(integer_type_definition)}
4948 The elaboration of an @nt<integer_type_definition> creates the
4949 integer type and its first subtype.
4950
4951 For a modular type, if the result of the execution of a
4952 predefined operator (see @RefSecNum(Operators and Expression Evaluation))
4953 is outside the base range of the type, the result is reduced
4954 modulo the modulus of the type to a value that is within the
4955 base range of the type.
4956
4957 @IndexCheck{Overflow_Check}
4958 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
4959 For a signed integer type,
4960 the exception Constraint_Error is raised by the execution of
4961 an operation that cannot deliver the correct result because
4962 it is outside the base range of the type.
4963 @redundant[@IndexCheck{Division_Check}
4964 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
4965 For any integer type, Constraint_Error is raised by the operators
4966 "/", "@key(rem)", and "@key(mod)" if the right operand is zero.]
4967
4968 @end{RunTime}
4969
4970 @begin{ImplReq}
4971 @Defn{Integer}
4972 In an implementation, the range of Integer shall include the range
4973 @en@;2**15+1 .. +2**15@en@;1.
4974
4975 @Defn{Long_Integer}
4976 If Long_Integer is predefined for an implementation, then its
4977 range shall include the range @en@;2**31+1 .. +2**31@en@;1.
4978
4979 System.Max_Binary_Modulus shall be at least 2**16.
4980 @end{ImplReq}
4981
4982 @begin{ImplPerm}
4983 For the execution of a predefined operation of a signed integer type,
4984 the implementation need not raise Constraint_Error if the result is
4985 outside the base range of the type, so long as the correct result
4986 is produced.
4987 @begin{Discussion}
4988 Constraint_Error is never raised for operations on modular types,
4989 except for divide-by-zero (and @key[rem]/@key[mod]-by-zero).
4990 @end{Discussion}
4991
4992 @Defn{Long_Integer}
4993 @Defn{Short_Integer}
4994 An implementation may provide additional predefined signed integer
4995 types@Redundant[, declared in the visible part of Standard], whose first
4996 subtypes have names of the form Short_Integer,
4997 Long_Integer, Short_Short_Integer, Long_Long_Integer, etc.
4998 Different predefined integer types are allowed to have the same base range.
4999 However, the range of Integer should be no wider than that of Long_Integer.
5000 Similarly, the range of Short_Integer (if provided) should be no wider
5001 than Integer.
5002 Corresponding recommendations apply to any other predefined integer types.
5003 There need not be a named integer type corresponding to each
5004 distinct base range supported by an implementation.
5005 The range of each first subtype should be the base range of its type.
5006 @ImplDef{The predefined integer types declared in Standard.}
5007
5008 @Defn{nonstandard integer type}
5009 An implementation may provide @i(nonstandard integer types),
5010 descendants of @i(root_integer) that are
5011 declared outside of the specification of package Standard,
5012 which need not have all the standard characteristics
5013 of a type defined by an @nt<integer_type_definition>.
5014 For example, a nonstandard integer type
5015 might have an asymmetric base range
5016 or it might not be allowed as
5017 an array or loop index (a very long integer).
5018 Any type descended from a nonstandard integer type is also nonstandard.
5019 An implementation may place arbitrary restrictions on the use of such types;
5020 it is implementation defined whether operators that are predefined
5021 for @lquotes@;any integer type@rquotes@; are defined for a particular
5022 nonstandard integer type.
5023 @Redundant[In any case, such types are not permitted as
5024 @nt{explicit_generic_actual_parameter}s for formal scalar types @em
5025 see @RefSecNum(Formal Scalar Types).]
5026 @ImplDef{Any nonstandard integer types and the operators defined for them.}
5027
5028 @PDefn2{Term=[one's complement], Sec=(modular types)}
5029 For a one's complement machine, the high bound of the base range
5030 of a modular type whose modulus is one less than a power of 2
5031 may be equal to the modulus, rather than one less than the modulus.
5032 It is implementation defined for which powers of 2, if any, this
5033 permission is exercised.
5034
5035 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0003],ARef=[AI95-00095-01]}
5036 @Chg{New=[For a one's complement machine, implementations may support non-binary
5037 modulus values greater than System.Max_Nonbinary_Modulus. It is implementation
5038 defined which specific values greater than System.Max_Nonbinary_Modulus, if
5039 any, are supported.],Old=[]}
5040 @begin{Reason}
5041 @ChgRef{Version=[1],Kind=[Added]}
5042 @ChgAdded{Version=[1],Text=[On a one's complement machine, the natural full word
5043 type would have
5044 a modulus of 2**Word_Size@en@;1. However, we would want to allow the all-ones
5045 bit pattern (which represents negative zero as a number) in logical operations.
5046 These permissions are intended to allow that and the natural modulus value
5047 without burdening implementations with supporting expensive modulus values.]}
5048 @end{Reason}
5049 @end{ImplPerm}
5050
5051 @begin{ImplAdvice}
5052 @Defn{Long_Integer}
5053 An implementation should support Long_Integer in addition to
5054 Integer if the target machine supports 32-bit (or longer) arithmetic.
5055 No other named integer subtypes are recommended for package Standard.
5056 Instead, appropriate named integer subtypes should be provided in
5057 the library package Interfaces
5058 (see @RefSecNum{The Package Interfaces}).
5059 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
5060 Text=[Long_Integer should be declared in Standard if the target supports
5061 32-bit arithmetic. No other named integer subtypes should be declared in
5062 Standard.]}]}
5063 @begin{ImplNote}
5064 To promote portability, implementations should explicitly declare the integer
5065 (sub)types Integer and Long_Integer in Standard, and leave other
5066 predefined integer types anonymous.
5067 For implementations
5068 that already support Byte_Integer, etc., upward compatibility
5069 argues for keeping such declarations in Standard during the
5070 transition period, but perhaps generating a warning on use.
5071 A separate package Interfaces in the predefined environment
5072 is available for pre-declaring types such as Integer_8, Integer_16, etc.
5073 See @RefSecNum(The Package Interfaces).
5074 In any case, if the user declares a subtype (first or not)
5075 whose range fits in, for example, a byte, the implementation can
5076 store variables of the subtype in a single byte, even if the
5077 base range of the type is wider.
5078 @end{ImplNote}
5079
5080 @PDefn2{Term=[two's complement],Sec=(modular types)}
5081 An implementation for a two's complement machine should support
5082 modular types with a binary modulus
5083 up to System.Max_Int*2+2.
5084 An implementation should support a nonbinary modulus up to Integer'Last.
5085 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
5086 Text=[For a two's complement target, modular types with a binary modulus
5087 up to System.Max_Int*2+2 should be supported. A nonbinary modulus up
5088 to Integer'Last should be supported.]}]}
5089 @begin{Reason}
5090 Modular types provide bit-wise "@key{and}", "@key{or}", "@key{xor}",
5091 and "@key{not}" operations.
5092 It is important for systems programming that these be available for all
5093 integer types of the target hardware.
5094 @end{Reason}
5095 @begin{Ramification}
5096 Note that on a one's complement machine,
5097 the largest supported modular type would normally have a nonbinary
5098 modulus. On a two's complement machine, the largest supported
5099 modular type would normally have a binary modulus.
5100 @end{Ramification}
5101 @begin{ImplNote}
5102 Supporting a nonbinary modulus greater than Integer'Last can
5103 impose an undesirable implementation burden on some machines.
5104 @end{ImplNote}
5105 @end{ImplAdvice}
5106
5107 @begin{Notes}
5108 @Defn{universal_integer}
5109 @Defn{integer literals}
5110 Integer literals are of the anonymous predefined
5111 integer type @i(universal_integer). Other integer types
5112 have no literals. However, the overload resolution rules
5113 (see @RefSec(The Context of Overload Resolution))
5114 allow expressions of the type @i(universal_integer)
5115 whenever an integer type is expected.
5116
5117 The same arithmetic operators are predefined for all signed integer types
5118 defined by a @nt<signed_integer_type_definition>
5119 (see @RefSec(Operators and Expression Evaluation)).
5120 For modular types, these same operators are predefined, plus
5121 bit-wise logical operators (@key(and), @key(or), @key(xor), and @key(not)).
5122 In addition, for the unsigned types declared in the language-defined
5123 package Interfaces (see @RefSecNum(The Package Interfaces)),
5124 functions are defined that provide
5125 bit-wise shifting and rotating.
5126
5127 Modular types match a @nt{generic_formal_parameter_declaration} of the
5128 form "@key(type) T @key(is mod) <>;";
5129 signed integer types match "@key(type) T @key(is range) <>;"
5130 (see @RefSecNum{Formal Scalar Types}).
5131 @end{Notes}
5132
5133 @begin{Examples}
5134 @Leading@keepnext@i(Examples of integer types and subtypes: )
5135 @begin(Example)
5136 @key(type) Page_Num @key(is) @key(range) 1 .. 2_000;
5137 @key(type) Line_Size @key(is) @key(range) 1 .. Max_Line_Size;
5138
5139 @key(subtype) Small_Int @key(is) Integer @key(range) -10 .. 10;
5140 @key(subtype) Column_Ptr @key(is) Line_Size @key(range) 1 .. 10;
5141 @key(subtype) Buffer_Size @key(is) Integer @key(range) 0 .. Max;
5142
5143 @key(type) Byte @key(is) @key(mod) 256; --@RI[ an unsigned byte]
5144 @key(type) Hash_Index @key(is) @key(mod) 97; --@RI[ modulus is prime]
5145 @end(Example)
5146 @end{Examples}
5147
5148 @begin{Extend83}
5149 @Defn{extensions to Ada 83}
5150 An implementation is allowed to support any number of distinct
5151 base ranges for integer types, even if fewer
5152 integer types are explicitly declared in Standard.
5153
5154 Modular (unsigned, wrap-around) types are new.
5155 @end{Extend83}
5156
5157 @begin{DiffWord83}
5158 Ada 83's integer types are now called "signed" integer types,
5159 to contrast them with "modular" integer types.
5160
5161 Standard.Integer, Standard.Long_Integer, etc., denote
5162 constrained subtypes of predefined integer types, consistent
5163 with the Ada 95 model that only subtypes have names.
5164
5165 We now impose minimum requirements on the base range of
5166 Integer and Long_Integer.
5167
5168 We no longer explain integer type definition in terms
5169 of an equivalence to a normal type derivation, except to say that all
5170 integer types are by definition implicitly derived from @i(root_integer).
5171 This is for various reasons.
5172
5173 First of all, the equivalence with a type derivation and a subtype
5174 declaration was not perfect, and was the source of various AIs (for example,
5175 is the conversion of the bounds static? Is a numeric type a derived
5176 type with respect to other rules of the language?)
5177
5178 Secondly, we don't want to require that every integer size supported
5179 shall have a corresponding named type in Standard. Adding named
5180 types to Standard creates nonportabilities.
5181
5182 Thirdly, we don't want the set of types that match
5183 a formal derived type "type T is new Integer;" to
5184 depend on the particular underlying integer representation chosen
5185 to implement a given user-defined integer type. Hence, we
5186 would have needed anonymous integer types as parent types for
5187 the implicit derivation anyway. We have simply chosen to identify
5188 only one anonymous integer type @em @i(root_integer), and stated
5189 that every integer type is derived from it.
5190
5191 Finally, the @lquotes@;fiction@rquotes@; that there were distinct
5192 preexisting predefined types
5193 for every supported representation breaks down for fixed point
5194 with arbitrary smalls, and was never exploited for enumeration
5195 types, array types, etc. Hence, there seems little benefit
5196 to pushing an explicit equivalence between integer type
5197 definition and normal type derivation.
5198 @end{DiffWord83}
5199
5200 @begin{Extend95}
5201 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00340-01]}
5202 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
5203 The Mod attribute is new. It eases mixing of signed and unsigned values in
5204 an expression, which can be difficult as there may be no type which
5205 can contain all of the values of both of the types involved.]}
5206 @end{Extend95}
5207
5208 @begin{DiffWord95}
5209 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0003],ARef=[AI95-00095-01]}
5210 @Chg{Version=[2],New=[@b<Corrigendum:> Added additional permissions for
5211 modular types on one's complement machines.],Old=[]}
5212 @end{DiffWord95}
5213
5214
5215 @LabeledSubClause{Operations of Discrete Types}
5216
5217 @begin{StaticSem}
5218 @Leading@;For @PrefixType{every discrete subtype S},
5219 the following attributes are defined:
5220 @begin(description)
5221 @AttributeLeading{Prefix=<S>, AttrName=<Pos>,
5222 Text=[S'Pos denotes a function with the following specification:
5223 @begin(Descexample)
5224 @b(function) S'Pos(@RI(Arg) : S'Base)
5225 @b(return) @RI(universal_integer)
5226 @end(Descexample)
5227
5228 @NoPrefix@;This function returns the position number of the value
5229 of @i(Arg), as a value of type @i(universal_integer).]}
5230
5231 @AttributeLeading{Prefix=<S>, AttrName=<Val>,
5232 Text=[S'Val denotes a function with the following specification:
5233 @begin(Descexample)
5234 @b(function) S'Val(@RI(Arg) : @RI(universal_integer))
5235 @b(return) S'Base
5236 @end(Descexample)
5237
5238 @NoPrefix@PDefn2{Term=(evaluation), Sec=(Val)}
5239 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
5240 This function returns a value of the type of S
5241 whose position number equals the value of @i(Arg).]}
5242 @IndexCheck{Range_Check}
5243 For the evaluation of a call on S'Val, if there
5244 is no value in the base range of its type with the given
5245 position number, Constraint_Error is raised.
5246 @begin{Ramification}
5247
5248 By the overload resolution rules, a formal parameter of type
5249 @i(universal_integer) allows an actual parameter of any
5250 integer type.@end{ramification}
5251 @begin{Reason}
5252 We considered allowing
5253 S'Val for a signed integer subtype S to return an out-of-range value,
5254 but since checks were required for enumeration and modular types
5255 anyway, the allowance didn't seem worth the complexity of the rule.@end{reason}
5256 @end(description)
5257 @EndPrefixType{}
5258 @end{StaticSem}
5259
5260 @begin{ImplAdvice}
5261 For the evaluation of a call on S'Pos for an enumeration
5262 subtype, if the value of the operand does not correspond
5263 to the internal code for any enumeration literal of its
5264 type
5265 @Redundant[(perhaps due to an uninitialized variable)],
5266 then the implementation should raise Program_Error.
5267 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
5268 This is particularly important for enumeration types with
5269 noncontiguous internal codes specified by an
5270 @nt<enumeration_@!representation_@!clause>.
5271 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
5272 Text=[Program_Error should be raised for the evaluation of S'Pos for an
5273 enumeration type, if the value of the operand does not correspond
5274 to the internal code for any enumeration literal of the type.]}]}
5275 @begin{Reason}
5276 We say Program_Error here, rather than Constraint_Error,
5277 because the main reason for such values is uninitialized variables,
5278 and the normal way to indicate such a use (if detected) is to raise
5279 Program_Error.
5280 (Other reasons would involve the misuse of low-level features such as
5281 Unchecked_Conversion.)
5282 @end{Reason}
5283 @end{ImplAdvice}
5284
5285 @begin{Notes}
5286 Indexing and loop iteration use values of discrete types.
5287
5288 @PDefn2{Term=[predefined operations],Sec=(of a discrete type)}
5289 The predefined operations of a discrete type include the assignment
5290 operation, qualification, the membership tests, and the
5291 relational operators; for a boolean type
5292 they include the short-circuit control forms and the
5293 logical operators; for an integer
5294 type they include type conversion to and from other numeric types,
5295 as well as the binary and unary adding operators @en@; and +, the multiplying
5296 operators, the unary operator @key(abs),
5297 and the exponentiation operator.
5298 The assignment operation is described in @RefSecNum(Assignment Statements).
5299 The other predefined operations are described in Section 4.
5300
5301 As for all types, objects of a discrete type
5302 have Size and Address attributes (see @RefSecNum(Operational and Representation Attributes)).
5303
5304 @Leading@;For a subtype of a discrete type, the result delivered by the
5305 attribute Val might not belong to the subtype; similarly, the actual parameter
5306 of the attribute Pos need not belong to the subtype. The following relations
5307 are satisfied (in the absence of an exception) by these attributes:
5308 @begin(Example)
5309 S'Val(S'Pos(X)) = X
5310 S'Pos(S'Val(N)) = N
5311 @end(Example)
5312 @end{Notes}
5313
5314 @begin{Examples}
5315 @Leading@keepnext@i(Examples of attributes of discrete subtypes: )
5316 @begin(Example)
5317 --@RI[ For the types and subtypes declared in subclause @RefSecNum(Enumeration Types) the following hold: ]
5318
5319 -- Color'First = White, Color'Last = Black
5320 -- Rainbow'First = Red, Rainbow'Last = Blue
5321
5322 -- Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown
5323 -- Color'Pos(Blue) = Rainbow'Pos(Blue) = 4
5324 -- Color'Val(0) = Rainbow'Val(0) = White
5325 @end(Example)
5326 @end{Examples}
5327
5328 @begin{Extend83}
5329 @Defn{extensions to Ada 83}
5330 The attributes S'Succ, S'Pred, S'Width, S'Image, and S'Value have
5331 been generalized to apply to real types as well
5332 (see @RefSec{Scalar Types}).
5333 @end{Extend83}
5334
5335 @LabeledSubClause{Real Types}
5336
5337 @begin{Intro}
5338 @Defn{real type}
5339 Real types provide approximations to the real numbers, with relative bounds
5340 on errors for floating point types, and with absolute bounds for fixed
5341 point types.
5342 @end{Intro}
5343
5344 @begin{Syntax}
5345 @Syn{lhs=<real_type_definition>,rhs="
5346 @Syn2{floating_point_definition} | @Syn2{fixed_point_definition}"}
5347 @end{Syntax}
5348
5349 @begin{StaticSem}
5350 @Defn{root_real}
5351 A type defined by a @nt<real_type_definition> is implicitly
5352 derived from @i(root_real), an anonymous
5353 predefined (specific) real type.
5354 @Redundant[Hence, all real types, whether floating point or fixed point,
5355 are in the derivation class rooted at @i(root_real).]
5356 @begin{Ramification}
5357 It is not specified whether the derivation from @i(root_real) is
5358 direct or indirect, not that it really matters.
5359 All we want is for all real types to be descendants of @i(root_real).
5360
5361 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0099],ARef=[AI95-00152-01]}
5362 @Chg{New=[Note that this derivation does not imply any inheritance of
5363 subprograms. Subprograms are inherited only for types derived by a
5364 @nt{derived_@!type_@!definition} (see @RefSecNum{Derived Types and Classes}),
5365 or a @nt{private_@!extension_@!declaration} (see
5366 @RefSecNum{Private Types and Private Extensions}, @RefSecNum{Private Operations},
5367 and @RefSecNum{Formal Private and Derived Types}).],Old=[]}
5368
5369 @end{Ramification}
5370
5371 @redundant[@PDefn{universal_real}
5372 @Defn{real literals}
5373 Real literals are all of the type @i(universal_real),
5374 the universal type (see @RefSecNum(Derivation Classes)) for the
5375 class rooted at @i(root_real), allowing their use with
5376 the operations of any real type.
5377 @PDefn{universal_fixed}
5378 Certain multiplying operators have a result type of @i(universal_fixed)
5379 (see @RefSecNum{Multiplying Operators}),
5380 the universal type for the class of fixed point types, allowing
5381 the result of the multiplication or division to be used where any
5382 specific fixed point type is expected.]
5383 @end{StaticSem}
5384
5385 @begin{RunTime}
5386 @PDefn2{Term=[elaboration], Sec=(real_type_definition)}
5387 The elaboration of a @nt<real_type_definition> consists of the
5388 elaboration of the @nt<floating_point_definition> or the
5389 @nt<fixed_point_definition>.
5390 @end{RunTime}
5391
5392 @begin{ImplReq}
5393 An implementation shall perform the run-time evaluation
5394 of a use of a predefined operator of @i(root_real)
5395 with an accuracy at least as great as that of any floating point
5396 type definable by a @nt<floating_point_definition>.
5397 @begin{Ramification}
5398 Static calculations using the operators of @i(root_real) are
5399 exact, as for all static calculations.
5400 See @RefSecNum(Static Expressions and Static Subtypes).
5401 @end{Ramification}
5402 @begin(ImplNote)
5403 The Digits attribute of the type used to represent @i(root_real)
5404 at run time is at least as great as that of any other floating
5405 point type defined by a @nt<floating_point_definition>,
5406 and its safe range includes that of any such floating point type
5407 with the same Digits attribute.
5408 On some machines, there might be real types with less accuracy but
5409 a wider range, and hence run-time calculations with @i(root_real)
5410 might not be able to accommodate all values that can be represented
5411 at run time in such floating point or fixed point types.
5412 @end(ImplNote)
5413 @end{ImplReq}
5414
5415 @begin{ImplPerm}
5416 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
5417 @Redundant[For the execution of a predefined operation of a real type,
5418 the implementation need not raise Constraint_Error if the result is
5419 outside the base range of the type, so long as the correct result
5420 is produced, or the Machine_Overflows attribute of the type is @Chg{Version=[2],
5421 New=[False],Old=[false]}
5422 (see @RefSecNum{Numeric Performance Requirements}).]
5423
5424 @Defn{nonstandard real type}
5425 An implementation may provide @i(nonstandard real types),
5426 descendants of @i(root_real) that are
5427 declared outside of the specification of package Standard,
5428 which need not have all the standard characteristics
5429 of a type defined by a @nt<real_type_definition>. For
5430 example, a nonstandard real type
5431 might have an asymmetric or unsigned base range,
5432 or its predefined operations might wrap around or @lquotes@;saturate@rquotes@; rather
5433 than overflow (modular or saturating arithmetic), or it might not
5434 conform to the accuracy
5435 model (see @RefSecNum{Numeric Performance Requirements}).
5436 Any type descended from a nonstandard real type is also nonstandard.
5437 An implementation may place arbitrary restrictions on the use of such types;
5438 it is implementation defined whether operators that are predefined
5439 for @lquotes@;any real type@rquotes@; are defined for a particular nonstandard real type.
5440 @Redundant[In any case, such types are not permitted as @nt{explicit_generic_actual_parameter}s for formal scalar types @em see @RefSecNum(Formal Scalar Types).]
5441 @ImplDef{Any nonstandard real types and the operators defined for them.}
5442 @end{ImplPerm}
5443
5444 @begin{Notes}
5445 As stated, real literals are of the anonymous predefined
5446 real type @i(universal_real). Other real types
5447 have no literals. However, the overload resolution rules
5448 (see @RefSecNum(The Context of Overload Resolution))
5449 allow expressions of the type @i(universal_real)
5450 whenever a real type is expected.
5451
5452 @end{Notes}
5453
5454 @begin{DiffWord83}
5455 The syntax rule for @nt{real_type_definition} is modified to use
5456 the new syntactic categories
5457 @nt{floating_point_definition} and @nt{fixed_point_definition},
5458 instead of @ntf{floating_point_constraint} and
5459 @ntf{fixed_point_constraint}, because the semantics of a type
5460 definition are significantly different than the semantics of a
5461 constraint.
5462
5463 All discussion of model numbers, safe ranges, and machine numbers
5464 is moved to @RefSecNum{Floating Point Types},
5465 @RefSecNum{Operations of Floating Point Types}, and
5466 @RefSecNum{Numeric Performance Requirements}.
5467 Values of a fixed point type are now described as being multiples of
5468 the @i(small) of the fixed point type, and we have no need for model
5469 numbers, safe ranges, etc. for fixed point types.
5470
5471 @end{DiffWord83}
5472
5473 @LabeledSubClause{Floating Point Types}
5474
5475 @begin{Intro}
5476 @Defn{floating point type}
5477 For floating point types, the error bound is specified as a relative
5478 precision by giving the required minimum number of significant decimal
5479 digits.
5480 @end{Intro}
5481
5482 @begin{Syntax}
5483 @Syn{lhs=<floating_point_definition>,rhs="
5484 @key{digits} @SynI{static_}@Syn2{expression} [@Syn2{real_range_specification}]"}
5485
5486 @Syn{lhs=<real_range_specification>,rhs="
5487 @key{range} @SynI{static_}@Syn2{simple_expression} .. @SynI{static_}@Syn2{simple_expression}"}
5488 @end{Syntax}
5489
5490 @begin{Resolution}
5491 @Defn2{Term=[requested decimal precision], Sec=(of a floating point type)}
5492 The @i(requested decimal precision), which is the minimum
5493 number of significant decimal digits required for the floating point type,
5494 is specified by the
5495 value of the @nt<expression> given after
5496 the reserved word @key(digits).
5497 @PDefn2{Term=[expected type], Sec=(requested decimal precision)}
5498 This @nt<expression>
5499 is expected to be of any integer type.
5500
5501 @PDefn2{Term=[expected type], Sec=(real_range_specification bounds)}
5502 Each @nt<simple_expression> of a
5503 @nt<real_range_specification> is expected to be of any real
5504 type@Redundant[; the types need not be the same].
5505 @end{Resolution}
5506
5507 @begin{Legality}
5508 @Defn{Max_Base_Digits}
5509 The requested decimal precision shall be specified by a static @nt<expression>
5510 whose value is positive and no greater than
5511 System.Max_Base_Digits.
5512 Each @nt<simple_expression> of a @nt<real_range_specification>
5513 shall also be static.
5514 @Defn{Max_Digits}
5515 If the @nt<real_range_specification> is omitted,
5516 the requested decimal precision shall be no greater than System.Max_Digits.
5517 @begin(Reason)
5518 We have added Max_Base_Digits to package System. It corresponds
5519 to the requested decimal precision of
5520 @i(root_real). System.Max_Digits
5521 corresponds to the maximum value for Digits that may be specified
5522 in the absence of a @nt<real_range_specification>, for upward
5523 compatibility. These might not be the same if @i<root_real>
5524 has a base range that does not include @PorM 10.0**(4*Max_Base_Digits).
5525 @end(Reason)
5526
5527 A @nt<floating_point_definition> is illegal if the
5528 implementation does not support a floating point type that
5529 satisfies the requested decimal precision and range.
5530 @ImplDef{What combinations of requested decimal precision and range
5531 are supported for floating point types.}
5532 @end{Legality}
5533
5534 @begin{StaticSem}
5535 The set of values for a floating point type is the (infinite) set of rational
5536 numbers.
5537 @Defn2{Term=[machine numbers], Sec=(of a floating point type)}
5538 The @i(machine numbers) of a floating point type are the values
5539 of the type that can be represented exactly in every
5540 unconstrained variable of the type.
5541 @PDefn2{Term=[base range], Sec=(of a floating point type)}
5542 The base range (see @RefSecNum{Scalar Types})
5543 of a floating point type is symmetric around zero,
5544 except that it can include some extra negative values
5545 in some implementations.@begin{ImplNote}
5546 For example, if a 2's complement
5547 representation is used for the mantissa rather than a sign-mantissa or
5548 1's complement representation, then there is usually one extra
5549 negative machine number.@end{implnote}
5550 @begin{Honest}
5551
5552 If the Signed_Zeros attribute is True,
5553 then minus zero could in a sense be considered a value of the type.
5554 However, for most purposes, minus zero behaves the same as plus zero.
5555
5556 @end{Honest}
5557
5558 @Defn2{Term=[base decimal precision], Sec=(of a floating point type)}
5559 The @i(base decimal precision) of a floating point type is the number
5560 of decimal digits of precision representable in objects
5561 of the type.
5562 @Defn2{Term=[safe range], Sec=(of a floating point type)}
5563 The @i(safe range) of a floating point type is that part of its
5564 base range for which the accuracy corresponding to the base decimal precision
5565 is preserved by all predefined operations.
5566 @begin{ImplNote}
5567 In most cases,
5568 the safe range and base range are the same.
5569 However, for some hardware, values near the boundaries of
5570 the base range might result in excessive
5571 inaccuracies or spurious overflows when used with
5572 certain predefined operations. For such hardware, the safe
5573 range would omit such values.@end{implnote}
5574
5575 @PDefn2{Term=[base decimal precision], Sec=(of a floating point type)}
5576 A @nt<floating_point_definition> defines a floating point type
5577 whose base decimal precision is no less than the requested
5578 decimal precision.
5579 @PDefn2{Term=[safe range], Sec=(of a floating point type)}
5580 @PDefn2{Term=[base range], Sec=(of a floating point type)}
5581 If a @nt<real_range_specification> is given,
5582 the safe range of the floating point type (and hence, also its base range)
5583 includes at least the
5584 values of the simple expressions
5585 given in the @nt<real_range_specification>.
5586 If a @nt<real_range_specification> is not given,
5587 the safe (and base) range of the type includes at least the values of the range
5588 @en@;10.0**(4*D) .. +10.0**(4*D) where D is the requested decimal precision.
5589 @Redundant[The safe range might include
5590 other values as well. The attributes Safe_First and Safe_Last
5591 give the actual bounds of the safe range.]
5592
5593 A @nt<floating_point_definition> also defines a first
5594 subtype of the type.
5595 @Defn2{Term=[constrained], Sec=(subtype)}
5596 @Defn2{Term=[unconstrained], Sec=(subtype)}
5597 If a @nt<real_range_specification> is given, then
5598 the subtype is constrained to a range whose bounds are
5599 given by a conversion of the values of the @nt<simple_expression>s
5600 of the @nt<real_range_specification> to the type being defined.
5601 Otherwise, the subtype is unconstrained.
5602
5603 @begin{Honest}
5604 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
5605 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
5606 conversion} (which is something that happens at overload resolution, see
5607 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
5608 the freezing rules are not invoked on the type (which is important so that
5609 representation items can be given for the type).
5610 @PDefn2{Term=[subtype conversion],Sec=(bounds of a floating point type)}]}
5611 @end{Honest}
5612
5613 @Defn{Float}
5614 There is a predefined, unconstrained, floating point subtype
5615 named Float@Redundant[, declared in the visible part of
5616 package Standard].
5617 @end{StaticSem}
5618
5619 @begin{RunTime}
5620 @PDefn2{Term=[elaboration], Sec=(floating_point_definition)}
5621 @Redundant[The elaboration of a @nt<floating_point_definition> creates
5622 the floating point type and its first subtype.]
5623 @end{RunTime}
5624
5625 @begin{ImplReq}
5626 @Defn{Float}
5627 In an implementation that supports floating point types with
5628 6 or more digits of precision, the requested
5629 decimal precision for Float shall be at least 6.
5630
5631 @Defn{Long_Float}
5632 If Long_Float is predefined for an implementation, then its
5633 requested decimal precision shall be at least 11.
5634 @end{ImplReq}
5635
5636 @begin{ImplPerm}
5637 @Defn{Short_Float}
5638 @Defn{Long_Float}
5639 An implementation is
5640 allowed to provide additional predefined floating point
5641 types@Redundant[, declared in the visible part of Standard], whose
5642 (unconstrained) first subtypes have names of the form Short_Float,
5643 Long_Float, Short_Short_Float, Long_Long_Float, etc.
5644 Different predefined floating point types are allowed to
5645 have the same base decimal precision.
5646 However, the precision of Float should be no greater than that of Long_Float.
5647 Similarly, the precision of Short_Float (if provided) should be no greater
5648 than Float.
5649 Corresponding recommendations apply to any other predefined floating point
5650 types.
5651 There need not be a named floating point type corresponding to each
5652 distinct base decimal precision supported by an implementation.
5653 @ImplDef{The predefined floating point types declared in Standard.}
5654 @end{ImplPerm}
5655
5656 @begin{ImplAdvice}
5657 @Defn{Long_Float}
5658 An implementation should support Long_Float in addition to
5659 Float if the target machine supports 11 or more digits of precision.
5660 No other named floating point subtypes are recommended for package Standard.
5661 Instead, appropriate named floating point subtypes should be provided in
5662 the library package Interfaces
5663 (see @RefSecNum(The Package Interfaces)).
5664 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
5665 Text=[Long_Float should be declared in Standard if the target supports
5666 11 or more digits of precision. No other named float subtypes should be
5667 declared in Standard.]}]}
5668 @begin{ImplNote}
5669 To promote portability, implementations should explicitly declare the floating
5670 point (sub)types Float and Long_Float in Standard, and leave other
5671 predefined float types anonymous.
5672 For implementations
5673 that already support Short_Float, etc., upward compatibility
5674 argues for keeping such declarations in Standard during the
5675 transition period, but perhaps generating a warning on use.
5676 A separate package Interfaces in the predefined environment
5677 is available for pre-declaring types such as Float_32, IEEE_Float_64, etc.
5678 See @RefSecNum(The Package Interfaces).
5679 @end{ImplNote}
5680 @end{ImplAdvice}
5681
5682 @begin{Notes}
5683 If a floating point subtype is unconstrained,
5684 then assignments to variables of the subtype involve only
5685 Overflow_Checks, never Range_Checks.
5686 @end{Notes}
5687
5688 @begin{Examples}
5689 @Leading@keepnext@i(Examples of floating point types and subtypes:)
5690 @begin(Example)
5691 @key(type) Coefficient @key(is) @key(digits) 10 @key(range) -1.0 .. 1.0;
5692
5693 @key(type) Real @key(is) @key(digits) 8;
5694 @key(type) Mass @key(is) @key(digits) 7 @key(range) 0.0 .. 1.0E35;
5695
5696 @key(subtype) Probability @key(is) Real @key(range) 0.0 .. 1.0; --@RI[ a subtype with a smaller range]
5697 @end(Example)
5698 @end{Examples}
5699
5700 @begin{Inconsistent83}
5701 @Defn{inconsistencies with Ada 83}
5702 No Range_Checks, only Overflow_Checks, are performed on
5703 variables (or parameters) of an
5704 unconstrained floating point subtype. This is upward
5705 compatible for programs that do not raise Constraint_Error.
5706 For those that do raise Constraint_Error, it is possible
5707 that the exception will be raised at a later point, or
5708 not at all, if extended range floating point registers are used to hold
5709 the value of the variable (or parameter).
5710 @begin(Reason)
5711 This change was felt to be justified by the possibility
5712 of improved performance on machines with extended-range
5713 floating point registers. An implementation need not
5714 take advantage of this relaxation in the range checking; it
5715 can hide completely the use of extended range registers if desired,
5716 presumably at some run-time expense.
5717 @end(Reason)
5718 @end{Inconsistent83}
5719
5720 @begin{DiffWord83}
5721 The syntax rules for @ntf{floating_point_constraint} and
5722 @ntf{floating_accuracy_definition} are removed. The syntax rules for
5723 @nt{floating_point_definition} and
5724 @nt{real_range_specification} are new.
5725
5726 A syntax rule for @nt<digits_constraint> is given in
5727 @RefSec{Fixed Point Types}. In @RefSecNum{Reduced Accuracy Subtypes}
5728 we indicate that a @nt<digits_constraint>
5729 may be applied to a floating point @nt<subtype_mark> as well
5730 (to be compatible with Ada 83's @ntf<floating_point_constraint>).
5731
5732 Discussion of model numbers is postponed to
5733 @RefSecNum{Operations of Floating Point Types} and
5734 @RefSecNum{Numeric Performance Requirements}.
5735 The concept of safe numbers has been replaced by the concept
5736 of the safe range of values. The bounds of the safe range are
5737 given by T'Safe_First .. T'Safe_Last, rather than -T'Safe_Large ..
5738 T'Safe_Large, since on some machines the safe range is not
5739 perfectly symmetric.
5740 The concept of machine numbers is new, and is relevant to
5741 the definition of Succ and Pred for floating point numbers.
5742 @end{DiffWord83}
5743
5744
5745 @LabeledSubClause{Operations of Floating Point Types}
5746
5747 @begin{StaticSem}
5748 @Leading@;The following attribute is defined for
5749 @PrefixType{every floating point subtype S}:
5750
5751 @begin(description)
5752 @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
5753 Prefix=<S>, AttrName=<Digits>, Ref=[8652/0004], ARef=[AI95-00203-01],
5754 Text=[S'Digits denotes the requested decimal precision
5755 for the subtype S. The value of this attribute
5756 is of the type @i(universal_integer).]}
5757 The requested decimal precision of the base subtype of a floating
5758 point type @i{T} is defined to be the largest value of @i{d} for which
5759 @chg{New=[@*],Old=[]}
5760 ceiling(@i{d} * log(10) / log(T'Machine_Radix)) + @Chg{New=[@i{g}],Old=[1]}
5761 <= T'Model_Mantissa@Chg{New=[@*
5762 where g is 0 if Machine_Radix is a positive power of 10 and 1 otherwise],Old=[]}.
5763 @end(description)
5764 @EndPrefixType{}
5765 @end{StaticSem}
5766
5767 @begin{Notes}
5768 @PDefn2{Term=[predefined operations],Sec=(of a floating point type)}
5769 The predefined operations of a floating point type include the assignment
5770 operation, qualification, the membership tests, and
5771 explicit conversion to and from other numeric types. They also
5772 include the relational operators and the following predefined
5773 arithmetic operators:
5774 the binary and unary adding operators @en@; and +,
5775 certain multiplying
5776 operators, the unary operator @key(abs),
5777 and the exponentiation operator.
5778
5779 As for all types, objects of a floating point type
5780 have Size and Address attributes
5781 (see @RefSecNum(Operational and Representation Attributes)).
5782 Other attributes of floating point types are defined in
5783 @RefSecNum{Attributes of Floating Point Types}.
5784 @end{Notes}
5785
5786 @begin{DiffWord95}
5787 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0004],ARef=[AI95-00203-01]}
5788 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Corrected the formula for Digits when
5789 the Machine_Radix is 10.]}
5790 @end{DiffWord95}
5791
5792
5793 @LabeledSubClause{Fixed Point Types}
5794
5795 @begin{Intro}
5796 @Defn{fixed point type}
5797 @Defn{ordinary fixed point type}
5798 @Defn{decimal fixed point type}
5799 A fixed point type is either an ordinary fixed point type,
5800 or a decimal fixed point type.
5801 @Defn2{Term=[delta], Sec=(of a fixed point type)}
5802 The error bound of a fixed point type is specified as an
5803 absolute value, called the @i(delta) of the fixed point type.
5804 @end{Intro}
5805
5806 @begin{Syntax}
5807 @Syn{lhs=<fixed_point_definition>,rhs="@Syn2{ordinary_fixed_point_definition} | @Syn2{decimal_fixed_point_definition}"}
5808
5809
5810 @Syn{lhs=<ordinary_fixed_point_definition>,rhs="
5811 @key{delta} @SynI{static_}@Syn2{expression} @Syn2{real_range_specification}"}
5812
5813 @Syn{lhs=<decimal_fixed_point_definition>,rhs="
5814 @key{delta} @SynI{static_}@Syn2{expression} @key{digits} @SynI{static_}@Syn2{expression} [@Syn2{real_range_specification}]"}
5815
5816 @Syn{lhs=<digits_constraint>,rhs="
5817 @key{digits} @SynI{static_}@Syn2{expression} [@Syn2{range_constraint}]"}
5818 @end{Syntax}
5819
5820 @begin{Resolution}
5821 @PDefn2{Term=[expected type], Sec=(fixed point type delta)}
5822 For a type defined by a @nt<fixed_point_definition>,
5823 the @i(delta) of the type is specified by the value of
5824 the @nt<expression> given after the
5825 reserved word @key(delta); this @nt<expression> is expected
5826 to be of any real type.
5827 @PDefn2{Term=[expected type], Sec=(decimal fixed point type digits)}
5828 @Defn2{Term=[digits], Sec=(of a decimal fixed point subtype)}
5829 @Defn{decimal fixed point type}
5830 For a type defined by a @nt<decimal_fixed_point_definition>
5831 (a @i(decimal) fixed point type),
5832 the number of significant decimal digits
5833 for its first subtype (the @i(digits) of the first subtype)
5834 is specified by the @nt<expression> given
5835 after the reserved word @key(digits); this @nt<expression>
5836 is expected to be of any integer type.
5837 @end{Resolution}
5838
5839 @begin{Legality}
5840 In a @nt<fixed_point_definition> or @nt<digits_constraint>,
5841 the @nt<expression>s given after the
5842 reserved words @key(delta) and @key(digits) shall be static; their
5843 values shall be positive.
5844
5845 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00100-01]}
5846 @Defn2{Term=[small], Sec=(of a fixed point type)}
5847 The set of values of a fixed point type comprise the integral multiples
5848 of a number called the @i(small) of the
5849 type.@Chg{Version=[2],New=[@PDefn2{Term=[machine numbers],Sec=[of a fixed point type]}
5850 The @i{machine numbers} of a fixed point type are the values of the type that
5851 can be represented exactly in every unconstrained variable of the type.],Old=[]}
5852 @Defn{ordinary fixed point type}
5853 For a type defined by an @nt<ordinary_fixed_point_definition>
5854 (an @i(ordinary) fixed point type), the @i(small) may be specified
5855 by an @nt<attribute_@!definition_@!clause>
5856 (see @RefSecNum{Operational and Representation Attributes});
5857 if so specified, it shall be no greater than the @i(delta) of the type.
5858 If not specified, the @i(small) of an ordinary fixed
5859 point type is an implementation-defined
5860 power of two less than or equal to the @i(delta).
5861 @ImplDef{The @i(small) of an ordinary fixed point type.}
5862
5863 For a decimal fixed point type,
5864 the @i(small) equals the @i(delta);
5865 the @i(delta)
5866 shall be a power of 10.
5867 If a @nt<real_range_specification> is given,
5868 both bounds of the range shall be in
5869 the range @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
5870
5871 A @nt<fixed_point_definition> is illegal if the implementation
5872 does not support a fixed point type with the given @i(small) and
5873 specified range or @i(digits).
5874 @ImplDef{What combinations of @i(small), range, and @i(digits)
5875 are supported for fixed point types.}
5876
5877 For a @nt<subtype_indication> with a @nt<digits_constraint>, the
5878 @nt<subtype_mark> shall denote a decimal fixed point subtype.
5879 @begin(Honest)
5880 Or, as an obsolescent feature, a floating point subtype is permitted
5881 @em see @RefSecNum(Reduced Accuracy Subtypes).
5882 @end(Honest)
5883 @end{Legality}
5884
5885 @begin{StaticSem}
5886 @PDefn2{Term=[base range], Sec=(of a fixed point type)}
5887 The base range (see @RefSecNum{Scalar Types}) of a fixed point type
5888 is symmetric around zero, except possibly for an extra negative
5889 value in some implementations.
5890
5891 @Leading@PDefn2{Term=[base range], Sec=(of an ordinary fixed point type)}
5892 An @nt<ordinary_fixed_point_definition> defines an
5893 ordinary fixed point type whose base range
5894 includes at least all multiples of @i(small) that are between the
5895 bounds specified
5896 in the @nt<real_range_specification>. The base range of the
5897 type does not necessarily include the specified bounds themselves.
5898 @Defn2{Term=[constrained], Sec=(subtype)}
5899 @Defn2{Term=[unconstrained], Sec=(subtype)}
5900 An @nt<ordinary_@!fixed_@!point_@!definition> also defines a constrained first
5901 subtype of the type, with each bound of its range
5902 given by the closer to zero of:
5903 @begin(itemize)
5904 the value of the conversion to the fixed point type
5905 of the corresponding @nt<expression> of the
5906 @nt<real_range_specification>;
5907 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a fixed point type)}
5908
5909 @begin{Honest}
5910 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
5911 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
5912 conversion} (which is something that happens at overload resolution, see
5913 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
5914 the freezing rules are not invoked on the type (which is important so that
5915 representation items can be given for the type).
5916 @PDefn2{Term=[subtype conversion],Sec=(bounds of a fixed point type)}]}
5917 @end{Honest}
5918
5919 the corresponding bound of the base range.
5920 @end(itemize)
5921
5922 @PDefn2{Term=[base range], Sec=(of a decimal fixed point type)}
5923 A @nt<decimal_fixed_point_definition> defines a decimal fixed point
5924 type whose base range includes at least
5925 the range @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
5926 @Defn2{Term=[constrained], Sec=(subtype)}
5927 @Defn2{Term=[unconstrained], Sec=(subtype)}
5928 A @nt<decimal_fixed_point_definition> also defines a constrained first
5929 subtype of the type. If a @nt<real_range_specification> is given,
5930 the bounds of the first subtype are given by a conversion
5931 of the values of the @nt<expression>s of the
5932 @nt<real_range_specification>.
5933 @PDefn2{Term=[implicit subtype conversion],Sec=(bounds of a decimal fixed point type)}
5934 Otherwise, the range of the first subtype is
5935 @en@;(10**@i(digits)@en@;1)*@i(delta) .. +(10**@i(digits)@en@;1)*@i(delta).
5936
5937 @begin{Honest}
5938 @ChgRef{Version=[1],Kind=[Added]}@ChgNote{This is discussed in AC-00002, which we can't reference here}
5939 @ChgAdded{Version=[1],Text=[The conversion mentioned above is not an @i{implicit subtype
5940 conversion} (which is something that happens at overload resolution, see
5941 @RefSecNum{Type Conversions}), although it happens implicitly. Therefore,
5942 the freezing rules are not invoked on the type (which is important so that
5943 representation items can be given for the type).
5944 @PDefn2{Term=[subtype conversion],Sec=(bounds of a decimal fixed point type)}]}
5945 @end{Honest}
5946
5947 @end{StaticSem}
5948
5949 @begin{RunTime}
5950 @PDefn2{Term=[elaboration], Sec=(fixed_point_definition)}
5951 The elaboration of a @nt<fixed_point_definition>
5952 creates the fixed point type and its first subtype.
5953
5954 For a @nt<digits_constraint> on a decimal fixed point subtype with
5955 a given @i(delta), if it does not have a @nt<range_constraint>,
5956 then it specifies an implicit range
5957 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta),
5958 where @i(D) is the value of the @nt<expression>.
5959 @Defn2{Term=[compatibility],
5960 Sec=(digits_constraint with a decimal fixed point subtype)}
5961 A @nt<digits_constraint> is @i(compatible) with a decimal
5962 fixed point subtype if the value of the @nt<expression>
5963 is no greater than the @i(digits) of the subtype,
5964 and if it specifies (explicitly
5965 or implicitly) a range that is compatible with the subtype.
5966 @begin(Discussion)
5967 Except for the requirement that the @i(digits) specified be
5968 no greater than the @i(digits) of the subtype being
5969 constrained, a @nt<digits_constraint> is essentially
5970 equivalent to a @nt<range_constraint>.
5971
5972 @Leading@keepnext@;Consider the following example:
5973 @begin{Example}
5974 @key[type] D @key[is] @key[delta] 0.01 @key[digits] 7 @key[range] -0.00 .. 9999.99;
5975 @end{Example}
5976
5977 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00008}
5978 The compatibility rule implies that the @nt{digits_constraint}
5979 "@key[digits] 6" specifies an implicit range of
5980 "@en@;@Chg{New=[9999.99],Old=[99.9999]} .. @Chg{New=[9999.99],Old=[99.9999]}".
5981 Thus, "@key[digits] 6" is not compatible with the constraint of D, but
5982 "@key[digits] 6 range 0.00 .. 9999.99" is compatible.
5983
5984 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
5985 A value of a scalar type
5986 belongs to a constrained subtype of the type if it belongs to the
5987 range of the subtype. Attributes like Digits and Delta have no
5988 @Chg{Version=[2],New=[effect],Old=[affect]} on this fundamental rule.
5989 So the obsolescent forms of
5990 @nt<digits_constraint>s and @nt<delta_constraint>s that are
5991 called @lquotes@;accuracy constraints@rquotes@; in RM83 don't really
5992 represent constraints on the values of the subtype, but rather primarily
5993 affect compatibility of the @lquotes@;constraint@rquotes@; with the subtype
5994 being @lquotes@;constrained.@rquotes@; In this sense, they might better
5995 be called @lquotes@;subtype assertions@rquotes@; rather than @lquotes@;constraints.@rquotes@;
5996
5997 Note that the @nt<digits_constraint> on a decimal fixed point subtype
5998 is a combination of an assertion about the @i(digits) of the
5999 subtype being further constrained, and a constraint on the range of
6000 the subtype being defined, either explicit or implicit.
6001 @end(Discussion)
6002
6003 @PDefn2{Term=[elaboration], Sec=(digits_constraint)}
6004 The elaboration of a @nt<digits_constraint> consists of the
6005 elaboration of the @nt<range_constraint>, if any.
6006 @IndexCheck{Range_Check}
6007 If a @nt<range_constraint> is given, a check is made that
6008 the bounds of the range are both in the range
6009 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta),
6010 where @i(D) is the value of the (static) @nt<expression>
6011 given after the reserved word @key(digits).
6012 @Defn2{Term=(Constraint_Error),Sec=(raised by failure of run-time check)}
6013 If this check fails, Constraint_Error is raised.
6014 @end{RunTime}
6015
6016 @begin{ImplReq}
6017 The implementation shall support at least 24 bits of precision
6018 (including the sign bit) for fixed point types.
6019 @begin{Reason}
6020 This is sufficient to represent Standard.Duration with a @i(small)
6021 no more than 50 milliseconds.
6022 @end{Reason}
6023 @end{ImplReq}
6024
6025 @begin{ImplPerm}
6026 Implementations are permitted to support only
6027 @i(small)s that are a power of two. In particular,
6028 all decimal fixed point type declarations can be disallowed.
6029 Note however that conformance with the Information Systems Annex
6030 requires support for decimal @i(small)s, and decimal fixed point
6031 type declarations with @i(digits) up to at least 18.
6032 @begin{ImplNote}
6033 The accuracy requirements for multiplication, division, and conversion
6034 (see @RefSec{Model of Floating Point Arithmetic})
6035 are such that
6036 support for arbitrary @i(small)s should be practical without undue
6037 implementation effort. Therefore, implementations should support fixed point
6038 types with arbitrary values for @i(small) (within reason).
6039 One reasonable limitation would be to limit support to fixed point types
6040 that can be converted to the most precise floating point type
6041 without loss of precision (so that Fixed_IO is implementable in terms
6042 of Float_IO).
6043 @end{ImplNote}
6044 @end{ImplPerm}
6045
6046 @begin{Notes}
6047 @Leading@;The base range of
6048 an ordinary fixed point type need not include the specified bounds
6049 themselves
6050 so that the range specification can be given in a natural way, such as:
6051 @begin(example)
6052 @b(type) Fraction @b(is delta) 2.0**(-15) @b(range) -1.0 .. 1.0;
6053 @end(example)
6054
6055 @NoPrefix@;With 2's complement hardware, such a type could have a
6056 signed 16-bit representation, using 1 bit for the sign
6057 and 15 bits for fraction, resulting in a base range of
6058 @en@;1.0 .. 1.0@en@;2.0**(@en@;15).
6059 @end{Notes}
6060
6061 @begin{Examples}
6062 @Leading@keepnext@i(Examples of fixed point types and subtypes:)
6063 @begin(Example)
6064 @key(type) Volt @key(is) @key(delta) 0.125 @key(range) 0.0 .. 255.0;
6065
6066 -- @RI[A pure fraction which requires all the available]
6067 -- @RI[space in a word can be declared as the type Fraction:]
6068 @key(type) Fraction @key(is) @key(delta) System.Fine_Delta @key(range) -1.0 .. 1.0;
6069 -- @RI[Fraction'Last = 1.0 @en System.Fine_Delta]
6070
6071 @key(type) Money @key(is) @key(delta) 0.01 @key(digits) 15; -- @RI[decimal fixed point]
6072 @key(subtype) Salary @key(is) Money @key(digits) 10;
6073 -- @RI[Money'Last = 10.0**13 @en 0.01, Salary'Last = 10.0**8 @en 0.01]
6074 @end(Example)
6075 @end{Examples}
6076
6077 @begin{Inconsistent83}
6078 @Defn{inconsistencies with Ada 83}
6079 In Ada 95, S'Small always equals S'Base'Small,
6080 so if an implementation chooses a @i(small) for a fixed point type smaller
6081 than required by the @i(delta), the value of S'Small in Ada 95 might not be
6082 the same as it was in Ada 83.
6083 @end{Inconsistent83}
6084
6085 @begin{Extend83}
6086 @Defn{extensions to Ada 83}
6087 Decimal fixed point types are new, though their
6088 capabilities are essentially similar to that available
6089 in Ada 83 with a fixed point type whose @i(small) equals its @i(delta) equals
6090 a power of 10. However, in the Information Systems Annex, additional
6091 requirements are placed on the support of decimal fixed point types
6092 (e.g. a minimum of 18 digits of precision).
6093 @end{Extend83}
6094
6095 @begin{DiffWord83}
6096 The syntax rules for @ntf{fixed_point_constraint} and
6097 @ntf{fixed_accuracy_definition} are removed. The syntax rule for
6098 @nt{fixed_point_definition} is new.
6099 A syntax rule for @nt<delta_constraint> is included in the
6100 Obsolescent features (to be compatible with Ada 83's
6101 @ntf<fixed_point_constraint>).
6102 @end{DiffWord83}
6103
6104 @begin{DiffWord95}
6105 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00100-01]}
6106 @ChgAdded{Version=[2],Text=[Added wording to define the
6107 machine numbers of fixed point types; this is needed by the static
6108 evaluation rules.]}
6109 @end{DiffWord95}
6110
6111
6112 @LabeledSubClause{Operations of Fixed Point Types}
6113
6114 @begin{StaticSem}
6115 @Leading@;The following attributes are defined for
6116 @PrefixType{every fixed point subtype S}:
6117 @begin(description)
6118 @ChgAttribute{Version=[1], Kind=[Revised], ChginAnnex=[F], Leading=[F],
6119 Prefix=<S>, AttrName=<Small>, Ref=[8652/0005], ARef=[AI95-00054-01],
6120 Text=[S'Small
6121 denotes the @i(small) of the type of S.
6122 The value of this attribute is of the type @i(universal_real).]}
6123 @PDefn2{Term=[specifiable], Sec=(of Small for fixed point types)}
6124 @Defn{Small clause}
6125 Small may be specified
6126 for nonderived@Chg{New=[ ordinary],Old=[]} fixed point types
6127 via an @nt{attribute_@!definition_@!clause}
6128 (see @RefSecNum{Operational and Representation Attributes});
6129 the expression of such a clause shall be static.
6130
6131 @Attribute{Prefix=<S>, AttrName=<Delta>,
6132 Text=[S'Delta
6133 denotes the @i(delta) of the fixed point subtype S.
6134 The value of this attribute is of the type @i(universal_real).]}
6135 @begin{Reason}
6136
6137 The @i(delta) is associated with the @i(sub)type as opposed
6138 to the type,
6139 because of the possibility of an (obsolescent) @nt<delta_constraint>.@end{reason}
6140
6141 @Attribute{Prefix=<S>, AttrName=<Fore>,
6142 Text=[S'Fore yields the minimum number of characters needed
6143 before the decimal point
6144 for the decimal representation of any value of the subtype S, assuming
6145 that the representation does not include an exponent, but includes
6146 a one-character prefix that is either a minus sign or a space.
6147 (This minimum number does not include superfluous zeros or
6148 underlines, and is at least 2.) The value of this attribute
6149 is of the type @i(universal_integer).]}
6150
6151 @Attribute{Prefix=<S>, AttrName=<Aft>,
6152 Text=<S'Aft yields the number of decimal digits needed after
6153 the decimal point to accommodate the @i(delta) of the subtype
6154 S, unless the @i(delta) of the subtype S is greater than 0.1,
6155 in which case the attribute yields the value one. @Redundant[(S'Aft
6156 is the smallest positive integer N for which (10**N)*S'Delta is
6157 greater than or equal to one.)] The value of this attribute is of
6158 the type @i(universal_integer).>}
6159 @end(description)
6160 @EndPrefixType{}
6161
6162 @begin{Wide}
6163 @Leading@;The following additional attributes are defined for
6164 @PrefixType{every decimal fixed point subtype S}:
6165 @end{Wide}
6166 @begin(description)
6167 @Attribute{Prefix=<S>, AttrName=<Digits>,
6168 Text=[S'Digits denotes the @i(digits) of the decimal
6169 fixed point subtype S, which corresponds to the number
6170 of decimal digits that are representable in objects of the
6171 subtype.
6172 The value of this attribute is of the type @i(universal_integer).]}
6173 Its value is determined as follows:
6174 @Defn2{Term=[digits], Sec=(of a decimal fixed point subtype)}
6175 @begin(itemize)
6176 For a first subtype or a subtype
6177 defined by a @nt<subtype_indication> with
6178 a @nt<digits_constraint>, the digits is the value
6179 of the expression given after the reserved word @key(digits);
6180
6181 For a subtype defined by a @nt<subtype_indication> without
6182 a @nt<digits_constraint>, the digits of the subtype
6183 is the same as that of the subtype denoted
6184 by the @nt<subtype_mark> in the @nt<subtype_indication>.
6185 @begin(ImplNote)
6186 Although a decimal subtype can be both range-constrained
6187 and digits-constrained, the digits constraint is intended
6188 to control the Size attribute of the subtype. For decimal
6189 types, Size can be important because input/output of decimal types
6190 is so common.
6191 @end(ImplNote)
6192
6193 The digits of a base subtype is the largest integer
6194 @i(D) such that the range
6195 @en@;(10**@i(D)@en@;1)*@i(delta) .. +(10**@i(D)@en@;1)*@i(delta)
6196 is included in the base range of the type.
6197
6198 @end(itemize)
6199
6200 @Attribute{Prefix=<S>, AttrName=<Scale>,
6201 Text=[S'Scale denotes the @i(scale) of the subtype S,
6202 defined as the value N such that S'Delta = 10.0**(@en@;N).
6203 @Defn2{Term=[scale], Sec=(of a decimal fixed point subtype)}
6204 @Redundant{The scale indicates the position of the point relative
6205 to the rightmost significant digits of values of subtype S.}
6206 The value of this attribute is of the type @i{universal_integer}.]}
6207 @begin{Ramification}
6208 S'Scale is negative if S'Delta is greater than one.
6209 By contrast, S'Aft is always positive.
6210 @end{Ramification}
6211
6212 @AttributeLeading{Prefix=<S>, AttrName=<Round>,
6213 Text=[S'Round denotes a function with
6214 the following specification:
6215 @begin(Descexample)
6216 @b(function) S'Round(@RI(X) : @RI(universal_real))
6217 @b(return) S'Base
6218 @end(Descexample)
6219
6220 @NoPrefix@;The function returns the value obtained by rounding X (away
6221 from 0, if X is midway between two values of the type of S).]}
6222 @end(description)
6223 @EndPrefixType{}
6224 @end{StaticSem}
6225
6226 @begin{Notes}
6227 All subtypes of a fixed point type will have the same value
6228 for the Delta attribute, in the absence of @nt<delta_constraint>s
6229 (see @RefSecNum(Reduced Accuracy Subtypes)).
6230
6231 S'Scale is not always the same as S'Aft for a decimal subtype;
6232 for example, if S'Delta = 1.0 then
6233 S'Aft is 1 while S'Scale is 0.
6234
6235 @PDefn2{Term=[predefined operations],Sec=(of a fixed point type)}
6236 The predefined operations of a fixed point type include the assignment
6237 operation, qualification, the membership tests, and
6238 explicit conversion to and from other numeric types. They also
6239 include the relational operators and the following predefined
6240 arithmetic operators:
6241 the binary and unary adding operators @en@; and +, multiplying
6242 operators, and the unary operator @key(abs).
6243
6244 As for all types, objects of a fixed point type
6245 have Size and Address attributes
6246 (see @RefSecNum(Operational and Representation Attributes)).
6247 Other attributes of fixed point types are defined in
6248 @RefSecNum{Attributes of Fixed Point Types}.
6249 @end{Notes}
6250
6251 @begin{DiffWord95}
6252 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0005],ARef=[AI95-00054-01]}
6253 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that @i<small> may be
6254 specified only for ordinary fixed point types.]}
6255 @end{DiffWord95}