Debian Codegraph @

source_2012/03a.mss

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