Debian Codegraph @

source_2005/08.mss

raw
1 @Part(08, Root="ada.mss")
2
3 @Comment{$Date: 2006/10/19 06:40:28 $}
4 @LabeledSection{Visibility Rules}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/08.mss,v $}
7 @Comment{$Revision: 1.73 $}
8
9 @begin{Intro}
10 @redundant[The rules defining the scope of declarations and the rules defining
11 which @nt{identifier}s, @nt{character_literal}s, and
12 @nt{operator_symbol}s are visible at (or from) various places in the text of
13 the program are described in this section. The formulation of these
14 rules uses the notion of a declarative region.
15
16 As explained in Section 3,
17 a declaration declares a view of an entity
18 and associates a defining name with that view.
19 The view comprises an identification of the viewed entity,
20 and possibly additional properties.
21 A usage name denotes a declaration.
22 It also denotes the view declared by that declaration,
23 and denotes the entity of that view.
24 Thus, two different usage names might denote two different views of
25 the same entity; in this case they denote the same entity.]
26 @begin{Honest}
27 In some cases, a usage name that denotes a declaration
28 does not denote the view declared by that declaration,
29 nor the entity of that view,
30 but instead denotes a view of the current instance of the entity,
31 and denotes the current instance of the entity.
32 This sometimes happens when the usage name occurs inside
33 the declarative region of the declaration.
34 @end{Honest}
35 @end{Intro}
36
37 @begin{DiffWord83}
38 We no longer define the term @lquotes@;basic operation;@rquotes@;
39 thus we no longer have to worry about the visibility of them.
40 Since they were essentially always visible in Ada 83, this change has
41 no effect. The reason for this change is that the definition in Ada
42 83 was confusing, and not quite correct,
43 and we found it difficult to fix. For example, one
44 wonders why an @nt{if_statement} was not a basic operation of type
45 Boolean. For another example, one wonders what it meant for a basic
46 operation to be @lquotes@;inherent in@rquotes@; something.
47 Finally, this fixes the problem addressed by AI83-00027/07.
48 @end{DiffWord83}
49
50 @LabeledClause{Declarative Region}
51
52 @begin{StaticSem}
53 @leading@Defn2{Term=[declarative region], Sec=(of a construct)}
54 For each of the following constructs,
55 there is a portion of the program text
56 called its @i{declarative region},
57 @Redundant[within which nested declarations can occur]:
58 @begin(itemize)
59 any declaration, other than that of an enumeration type,
60 that is not a completion @Redundant[of a previous declaration];
61
62 a @nt{block_statement};
63
64 a @nt{loop_statement};
65
66 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]}
67 @ChgAdded{Version=[2],Text=[an @nt{extended_return_statement};]}
68
69 an @nt{accept_statement};
70
71 an @nt{exception_handler}.
72 @end(itemize)
73
74 @begin{Wide}
75 @leading@;The declarative region includes the text of the construct
76 together with additional text determined @Redundant[(recursively)],
77 as follows:
78 @end{Wide}
79 @begin{Itemize}
80 If a declaration is included, so is its completion, if any.
81
82 If the declaration of a library unit
83 @Redundant[(including Standard @em
84 see @RefSecNum{Compilation Units - Library Units})] is included,
85 so are the declarations of any child units
86 @Redundant[(and their completions, by the previous rule)].
87 The child declarations occur after the declaration.
88
89 If a @nt{body_stub} is included,
90 so is the corresponding @nt{subunit}.
91
92 If a @nt{type_declaration} is included,
93 then so is a corresponding @nt{record_representation_clause},
94 if any.
95 @begin{Reason}
96 This is so that the @nt{component_declaration}s can be directly
97 visible in the @nt{record_representation_clause}.
98 @end{Reason}
99 @end{Itemize}
100
101 The declarative region of a declaration is also called the
102 @i{declarative region} of any view or entity declared by the
103 declaration.
104 @begin{Reason}
105 The constructs that have declarative regions
106 are the constructs that can have declarations nested inside them.
107 Nested declarations are declared in that declarative region.
108 The one exception is for enumeration literals;
109 although they are nested inside an enumeration type declaration,
110 they behave as if they were declared at the same level as the type.
111 @end{Reason}
112 @begin{Honest}
113 A declarative region does not include @nt{parent_unit_name}s.
114 @end{Honest}
115 @begin{Ramification}
116 A declarative region does not include @nt{context_clause}s.
117 @end{Ramification}
118
119 @Defn{occur immediately within}
120 @Defn{immediately within}
121 @Defn2{Term=[within],Sec=(immediately)}
122 @Defn{immediately enclosing}
123 @Defn2{Term=[enclosing],Sec=(immediately)}
124 A declaration occurs @i{immediately within} a declarative region if this
125 region is the innermost declarative region that
126 encloses the declaration
127 (the @i{immediately enclosing} declarative region),
128 not counting the declarative region (if any)
129 associated with the declaration itself.
130 @begin{Discussion}
131 Don't confuse the declarative region of a declaration
132 with the declarative region in which it immediately occurs.
133 @end{Discussion}
134
135 @redundant[@Defn{local to}
136 A declaration is @i{local} to a declarative region if
137 the declaration occurs immediately within the declarative region.]
138 @redundant[An entity is @i{local} to a declarative region if the entity is
139 declared by a declaration that is local to the declarative region.]
140 @begin{Ramification}
141 "Occurs immediately within" and "local to" are synonyms
142 (when referring to declarations).
143
144 Thus, @lquotes@;local to@rquotes@; applies to both declarations and entities,
145 whereas @lquotes@;occurs immediately within@rquotes@; only applies to declarations.
146 We use this term only informally; for cases where precision is required,
147 we use the term "occurs immediately within", since it is less likely to
148 cause confusion.
149 @end{Ramification}
150
151 @Defn{global to}
152 A declaration is @i{global} to a declarative region
153 if the declaration occurs immediately within
154 another declarative region that encloses the
155 declarative region.
156 An entity is @i{global} to a declarative region if the entity is
157 declared by a declaration that is global to the declarative region.
158 @end{StaticSem}
159
160 @begin{Notes}
161 The children of a parent library unit are inside the parent's
162 declarative region, even though they do not occur inside the
163 parent's declaration or body.
164 This implies that one can use (for example) "P.Q" to refer to
165 a child of P whose defining name is Q,
166 and that after "@key[use] P;" Q can refer (directly) to that child.
167
168 As explained above
169 and in @RefSec{Compilation Units - Library Units},
170 all library units are descendants of Standard,
171 and so are contained in the declarative region of Standard.
172 They are @i{not} inside the
173 declaration or body of Standard,
174 but they @i{are} inside its declarative region.
175
176 For a declarative region that comes in multiple parts,
177 the text of the declarative region does not contain any text that might appear
178 between the parts.
179 Thus, when a portion of a declarative region is said to extend from one
180 place to another in the declarative region,
181 the portion does not contain any text that
182 might appear between the parts of the declarative region.
183 @begin{Discussion}
184 It is necessary for the things that have a declarative region to
185 include
186 anything that contains declarations (except for enumeration type
187 declarations).
188 This includes any declaration that has a profile
189 (that is, @nt{subprogram_declaration},
190 @nt{subprogram_body},
191 @nt{entry_declaration},
192 @nt{subprogram_renaming_declaration},
193 @nt{formal_subprogram_declaration},
194 access-to-subprogram @nt{type_declaration}),
195 anything that has a @nt{discriminant_part}
196 (that is, various kinds of @nt{type_declaration}),
197 anything that has a @nt{component_list}
198 (that is, record @nt{type_declaration} and
199 record extension @nt{type_declaration}),
200 and finally the declarations of task and protected units and packages.
201 @end{Discussion}
202 @end{Notes}
203
204 @begin{DiffWord83}
205 @leading@;It was necessary to extend Ada 83's definition of declarative region
206 to take the following Ada 95 features into account:
207 @begin{Itemize}
208 Child library units.
209
210 Derived types/type extensions @em we need a declarative region for
211 inherited components and also for new components.
212
213 All the kinds of types that allow discriminants.
214
215 Protected units.
216
217 Entries that have bodies instead of accept statements.
218
219 The @nt{choice_parameter_specification} of an @nt{exception_handler}.
220
221 The formal parameters of access-to-subprogram types.
222
223 Renamings-as-body.
224 @end{Itemize}
225
226 Discriminated and access-to-subprogram type declarations
227 need a declarative region.
228 Enumeration type declarations cannot have one,
229 because you don't have to say "Color.Red" to refer to the literal Red
230 of Color.
231 For other type declarations,
232 it doesn't really matter whether or not there is an
233 associated declarative region,
234 so for simplicity, we give one to all types except enumeration types.
235
236 We now say that an @nt{accept_statement} has its own declarative
237 region, rather than being part of the declarative region of the
238 @nt{entry_declaration},
239 so that declarative regions are properly nested regions of text,
240 so that it makes sense to talk about "inner declarative regions,"
241 and "...extends to the end of a declarative region."
242 Inside an @nt{accept_statement}, the @nt{name} of one of the parameters
243 denotes the @nt{parameter_specification} of the @nt{accept_statement},
244 not that of the @nt{entry_declaration}. If the @nt{accept_statement} is
245 nested within a @nt{block_statement}, these
246 @nt{parameter_specification}s can hide declarations of the
247 @nt{block_statement}.
248 The semantics of such cases was unclear in RM83.
249 @begin{Honest}
250 Unfortunately, we have the same problem for the entry name
251 itself @em it should denote the @nt{accept_statement},
252 but @nt{accept_statement}s are not declarations.
253 They should be, and they should hide the entry from all visibility
254 within themselves.
255 @end{Honest}
256
257 Note that we can't generalize this to @ntf{entry_bodies},
258 or other bodies, because the @nt{declarative_part} of a
259 body is not supposed to contain (explicit) homographs of
260 things in the declaration.
261 It works for @nt{accept_statement}s only because an
262 @nt{accept_statement} does not have a @nt{declarative_part}.
263
264 To avoid confusion,
265 we use the term @lquotes@;local to@rquotes@; only informally in Ada 95.
266 Even RM83 used the term incorrectly (see, for example, RM83-12.3(13)).
267
268 In Ada 83, (root) library units were inside Standard;
269 it was not clear whether the declaration or body of Standard
270 was meant.
271 In Ada 95, they are children of Standard,
272 and so occur immediately within Standard's declarative
273 region, but not within either the declaration or the body.
274 (See RM83-8.6(2) and RM83-10.1.1(5).)
275 @end{DiffWord83}
276
277 @begin{DiffWord95}
278 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]}
279 @ChgAdded{Version=[2],Text=[@nt{Extended_return_statement}
280 (see @RefSecNum{Return Statements}) is added to the list
281 of constructs that have a declarative region.]}
282 @end{DiffWord95}
283
284
285 @LabeledClause{Scope of Declarations}
286
287 @begin{Intro}
288 @redundant[For each declaration, the language rules define a certain
289 portion of the program text called the @i{scope} of the declaration.
290 The scope of a declaration is also called the scope of any view
291 or entity declared by the declaration.
292 Within the scope of an entity, and only there,
293 there are places where it is legal to refer
294 to the declared entity.
295 These places are defined by the rules of visibility and overloading.]
296 @end{Intro}
297
298 @begin{StaticSem}
299 @Leading@Defn2{Term=[immediate scope], Sec=(of a declaration)}
300 The @i{immediate scope} of a declaration
301 is a portion of the declarative region immediately enclosing
302 the declaration.
303 The immediate scope starts at the beginning of the declaration,
304 except in the case of an overloadable declaration,
305 in which case the immediate scope starts just after the place
306 where the profile of the callable entity is determined
307 (which is at the end of the @ntf<_specification> for the callable entity,
308 or at the end of the @nt<generic_instantiation> if an instance).
309 The immediate scope extends to the end of the declarative region,
310 with the following exceptions:
311 @begin{Reason}
312 The reason for making overloadable declarations with profiles
313 special is to simplify compilation:
314 until the compiler has determined the profile,
315 it doesn't know which other declarations are homographs of this one,
316 so it doesn't know which ones this one should hide.
317 Without this rule, two passes over the @ntf<_specification> or
318 @nt<generic_instantiation> would be required to
319 resolve names that denote things with the same name as this one.
320 @end{Reason}
321 @begin{Itemize}
322 The immediate scope of a @nt{library_item} includes only its semantic
323 dependents.
324 @begin{Reason}
325 Section 10 defines only a partial ordering of @nt{library_item}s.
326 Therefore, it is a good idea to restrict the immediate scope
327 (and the scope, defined below)
328 to semantic dependents.
329
330 @leading@;Consider also examples like this:
331 @begin{Example}
332 @key[package] P @key[is] @key[end] P;
333
334 @key[package] P.Q @key[is]
335 I : Integer := 0;
336 @key[end] P.Q;
337
338 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00080 - syntax error}
339 @key[with] P;
340 @key[package] R @key[is]
341 @key[package] X @key[renames] P;
342 @Chg{New=[J : Integer := ],Old=[]}X.Q.I@Chg{New=[],Old=[ := 17]}; --@RI{ Illegal!}
343 @key[end] R;
344 @end{Example}
345
346 The scope of P.Q does not contain R.
347 Hence, neither P.Q nor X.Q are visible within R.
348 However, the name R.X.Q would be visible in some other
349 library unit where both R and P.Q are visible
350 (assuming R were made legal by removing the offending declaration).
351 @end{Reason}
352 @begin{Ramification}
353 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
354 @ChgAdded{Version=[2],Text=[This rule applies to limited views as well as
355 @lquotes@;normal@rquotes library items. In that case, the semantic dependents
356 are the units that have a @nt{limited_with_clause} for the limited view.]}
357 @end{Ramification}
358 The immediate scope of
359 a declaration in the private part of a library unit does
360 not include the visible part of any
361 public descendant of that library unit.
362 @Pdefn2{Term=[descendant],Sec=(relationship with scope)}
363 @begin{Ramification}
364 In other words, a declaration in the private part can be
365 visible within the visible part, private part and body of a private
366 child unit.
367 On the other hand, such a declaration
368 can be visible within only the private part and body of a public
369 child unit.
370 @end{Ramification}
371 @begin{Reason}
372 The purpose of this rule is to prevent children from giving
373 private information to clients.
374 @end{Reason}
375 @begin{Ramification}
376 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]}
377 For a public child subprogram,
378 this means that the parent's private part is not visible in the
379 @Chg{Version=[2],New=[profile],Old=[@nt{formal_part}s]} of the declaration
380 and of the body.
381 This is true even for @ntf{subprogram_bodies} that are not
382 completions.
383 For a public child generic unit,
384 it means that the parent's private part is not visible in the
385 @nt{generic_formal_part}, as well as in
386 the first list of @nt{basic_declarative_item}s (for a generic package),
387 or the @Chg{Version=[2],New=[(syntactic) profile],Old=[@nt{formal_part}(s)]}
388 (for a generic subprogram).
389 @end{Ramification}
390 @end{Itemize}
391
392 @Defn{visible part}
393 @Redundant[The @i(visible part) of (a view of) an entity
394 is a portion of the text of its declaration
395 containing declarations that are visible from outside.]
396 @RootDefn{private part}
397 The @i{private part} of (a view of) an entity that has a visible part
398 contains all declarations within the declaration of
399 (the view of) the entity,
400 except those in the visible part;
401 @Redundant[these are not visible from outside.
402 Visible and private parts are defined only for these kinds of
403 entities: callable entities, other program units,
404 and composite types.]
405 @begin{Itemize}
406 @PDefn2{Term=[visible part], Sec=(of a view of a callable entity)}
407 The visible part of a view of a callable entity is its profile.
408
409 @PDefn2{Term=[visible part], Sec=(of a view of a composite type)}
410 The visible part of a composite type other than a task or protected type
411 consists of the declarations of
412 all components declared @Redundant[(explicitly or implicitly)]
413 within the @nt{type_declaration}.
414
415 @PDefn2{Term=[visible part], Sec=(of a generic unit)}
416 The visible part of a generic unit
417 includes the @nt{generic_formal_part}.
418 For a generic package, it also includes
419 the first list of @nt{basic_declarative_item}s of the
420 @nt{package_specification}.
421 For a generic subprogram, it also includes
422 the profile.
423 @begin{Reason}
424 Although there is no way to reference anything but the formals from
425 outside a generic unit, they are still in the visible part in the sense that
426 the corresponding declarations in an instance can be referenced
427 (at least in some cases).
428 In other words, these declarations have an effect on the outside world.
429 The visible part of a generic unit needs to be defined
430 this way in order to properly support
431 the rule that makes a parent's private part invisible within a
432 public child's visible part.
433 @end{Reason}
434 @begin{Ramification}
435 The visible part of an instance of a generic unit is as defined
436 for packages and subprograms;
437 it is not defined in terms of the visible part of a generic unit.
438 @end{Ramification}
439
440 @Redundant[The visible part of a package, task unit, or protected
441 unit consists of declarations in the program unit's declaration
442 other than those following the reserved word @key{private}, if any;
443 see @RefSecNum{Package Specifications and Declarations}
444 and @RefSecNum{Formal Packages} for packages,
445 @RefSecNum{Task Units and Task Objects} for task units,
446 and @RefSecNum{Protected Units and Protected Objects}
447 for protected units.]
448 @end{Itemize}
449
450 @Defn2{Term=[scope], Sec=(of a declaration)}
451 The scope of a declaration always
452 contains the immediate scope of the declaration.
453 In addition, for a given declaration that occurs immediately within
454 the visible part of an outer declaration,
455 or is a public child of an outer declaration,
456 the scope of the given declaration
457 extends to the end of the scope of the outer declaration,
458 except that the scope of a @nt{library_item} includes only its
459 semantic dependents.
460 @begin{Ramification}
461 Note the recursion.
462 If a declaration appears in the visible part of a library unit,
463 its scope extends to the end of the scope of the library unit,
464 but since that only includes dependents of the declaration of the library unit,
465 the scope of the inner declaration also only includes those dependents.
466 If X renames library package P,
467 which has a child Q, a @nt{with_clause} mentioning P.Q is necessary to
468 be able to refer to X.Q,
469 even if P.Q is visible at the place where X is declared.
470 @end{Ramification}
471
472 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00408-01]}
473 @ChgAdded{Version=[2],Text=[@Defn2{Term=[scope], Sec=(of an attribute_@!definition_@!clause)}
474 The scope of an @nt{attribute_definition_clause} is identical to the scope of a
475 declaration that would occur at the point of the
476 @nt{attribute_definition_clause}.]}
477
478 @Defn2{Term=[immediate scope], Sec=[of (a view of) an entity]}
479 The immediate scope of a declaration is also the immediate scope
480 of the entity or view declared by the declaration.
481 @Defn2{Term=[scope], Sec=[of (a view of) an entity]}
482 Similarly,
483 the scope of a declaration is also the scope
484 of the entity or view declared by the declaration.
485 @begin{Ramification}
486 @leading@;The rule for immediate scope implies the following:
487 @begin{Itemize}
488 If the declaration is that of a library unit,
489 then the immediate scope includes the declarative region of the
490 declaration itself, but not other places,
491 unless they are within the scope of a @nt{with_clause} that mentions the
492 library unit.
493
494 @NoPrefix@;It is necessary to attach the semantics of @nt{with_clause}s to
495 [immediate] scopes (as opposed to visibility),
496 in order for various rules to work properly.
497 A library unit should hide a homographic implicit declaration that
498 appears in its parent, but only within the scope of a @nt{with_clause}
499 that mentions the library unit.
500 Otherwise, we would violate the "legality determinable via semantic
501 dependences" rule of @RefSec{Program Structure and Compilation Issues}.
502 The declaration of a library unit should be allowed to be a homograph of
503 an explicit declaration in its parent's body,
504 so long as that body does not mention the library unit in a
505 @nt{with_clause}.
506
507 @NoPrefix@;This means that one cannot denote the declaration of the library unit,
508 but one might still be able to denote the library unit via another
509 view.
510
511 @NoPrefix@;A @nt{with_clause} does not make the declaration of a library unit
512 visible; the lack of a @nt{with_clause} prevents it from being visible.
513 Even if a library unit is mentioned in a @nt{with_clause},
514 its declaration can still be hidden.
515
516 The completion of the declaration of a library unit
517 (assuming that's also a declaration)
518 is not visible, neither directly nor by selection,
519 outside that completion.
520
521 The immediate scope of
522 a declaration immediately within the body of a library unit
523 does not include any child of that library unit.
524
525 @NoPrefix@;This is needed to prevent children from looking inside their
526 parent's body. The children are in the declarative region of the
527 parent, and they might be after the parent's body.
528 Therefore, the scope of a declaration that occurs immediately within
529 the body might include some children.
530 @end{Itemize}
531 @end{Ramification}
532 @end{StaticSem}
533
534 @begin{Notes}
535 There are notations for denoting visible declarations
536 that are not directly visible.
537 For example, @nt{parameter_@!specification}s are in the visible part of a
538 @nt{subprogram_@!declaration} so that they can be used in
539 named-notation calls appearing outside the called subprogram.
540 For another example,
541 declarations of the visible part of a package can be denoted by expanded names
542 appearing outside the package,
543 and can be made directly visible by a @nt{use_clause}.
544 @begin{Ramification}
545 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
546 There are some obscure @Chg{Version=[2],New=[cases ],Old=[]}involving
547 generics @Chg{Version=[2],New=[],Old=[cases ]}in which there is
548 no such notation.
549 See Section 12.
550 @end{Ramification}
551 @end{Notes}
552
553 @begin{Extend83}
554 @Defn{extensions to Ada 83}
555 The fact that the immediate scope of an overloadable declaration does
556 not include its profile is new to Ada 95. It replaces
557 RM83-8.3(16), which said that within
558 a subprogram specification and within the formal part of an
559 entry declaration or accept statement, all declarations with
560 the same designator as the subprogram or entry were hidden from all
561 visibility.
562 The RM83-8.3(16) rule seemed to be overkill, and created both
563 implementation difficulties and unnecessary semantic complexity.
564 @end{Extend83}
565
566 @begin{DiffWord83}
567 We no longer need to talk about the scope of notations,
568 @nt{identifier}s, @nt{character_literal}s, and @nt{operator_symbol}s.
569
570 The notion of "visible part" has been extended in Ada 95.
571 The syntax of
572 task and protected units now allows private parts,
573 thus requiring us to be able to talk about the visible part as well.
574 It was necessary to extend the concept to subprograms
575 and to generic units, in order for the visibility rules
576 related to child library units to work properly.
577 It was necessary to define the concept separately for
578 generic formal packages, since their visible part is
579 slightly different from that of a normal package.
580 Extending the concept to composite types made the
581 definition of scope slightly simpler.
582 We define visible part for some things elsewhere,
583 since it makes a big difference to the user for those things.
584 For composite types and subprograms, however,
585 the concept is used only in arcane visibility rules,
586 so we localize it to this clause.
587
588 In Ada 83, the semantics of @nt{with_clause}s was described
589 in terms of visibility.
590 It is now described in terms of [immediate] scope.
591
592 @leading@;We have clarified that the following is illegal
593 (where Q and R are library units):
594 @begin{Example}
595 @key[package] Q @key[is]
596 I : Integer := 0;
597 @key[end] Q;
598
599 @key[package] R @key[is]
600 @key[package] X @key[renames] Standard;
601 X.Q.I := 17; --@RI{ Illegal!}
602 @key[end] R;
603 @end{Example}
604
605 even though Q is declared in the declarative region of Standard,
606 because R does not mention Q in a @nt{with_clause}.
607 @end{DiffWord83}
608
609 @begin{DiffWord95}
610 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00408-01]}
611 @ChgAdded{Version=[2],Text=[The scope of an @nt{attribute_definition_clause}
612 is defined so that it can be used to define the visibility of such a clause,
613 so @i<that> can be used by the stream attribute availability rules
614 (see @RefSecNum{Stream-Oriented Attributes}).]}
615 @end{DiffWord95}
616
617 @LabeledClause{Visibility}
618
619 @begin{Intro}
620 @redundant[@Defn{visibility rules}
621 The @i{visibility rules},
622 given below, determine which declarations are
623 visible and directly visible at each place within a program.
624 The visibility rules apply to both explicit and implicit declarations.]
625 @end{Intro}
626
627 @begin{StaticSem}
628 @Defn2{Term=[visibility], Sec=(direct)}
629 @Defn{directly visible}
630 @Defn{directly visible}
631 A declaration is defined to be @i{directly visible} at places
632 where a @nt<name> consisting of only an @nt{identifier} or
633 @nt{operator_symbol} is sufficient to denote the declaration;
634 that is, no @nt<selected_component> notation or special context
635 (such as preceding => in a named association) is necessary
636 to denote the declaration.
637 @Defn{visible}
638 A declaration is defined to be @i{visible} wherever it is
639 directly visible, as well as at other places where
640 some @nt<name> (such as a @nt<selected_component>) can denote
641 the declaration.
642
643 The syntactic category @nt<direct_name> is used to indicate
644 contexts where direct visibility is required.
645 The syntactic category @nt<selector_name> is used to indicate
646 contexts where visibility, but not direct visibility,
647 is required.
648
649 @Defn2{Term=[visibility], Sec=(immediate)}
650 @Defn2{Term=[visibility], Sec=(use clause)}
651 There are two kinds of direct visibility:
652 @i{immediate visibility} and @i{use-visibility}.
653 @Defn{immediately visible}
654 A declaration is immediately visible at a place if it is directly
655 visible because the place is within its immediate scope.
656 @Defn{use-visible}
657 A declaration is use-visible if it is directly visible
658 because of a @nt{use_clause} (see @RefSecNum{Use Clauses}).
659 Both conditions can apply.
660
661 @Defn{hiding}
662 A declaration can be @i{hidden}, either from direct visibility,
663 or from all visibility,
664 within certain parts of its scope.
665 @Defn{hidden from all visibility}
666 Where @i{hidden from all visibility},
667 it is not visible at all (neither using a @nt<direct_name>
668 nor a @nt<selector_name>).
669 @Defn{hidden from direct visibility}
670 Where @i{hidden from direct visibility}, only direct visibility is lost;
671 visibility using a @nt<selector_name> is still possible.
672
673 @redundant[@Defn{overloaded}
674 Two or more declarations are @i{overloaded} if
675 they all have the same defining name
676 and there is a place where they are all directly visible.]
677 @begin{Ramification}
678 Note that a @nt{name} can have more than one possible interpretation
679 even if it denotes a non-overloadable entity.
680 For example, if there are two functions F that return records,
681 both containing a component called C, then
682 the name F.C has two possible interpretations,
683 even though component declarations are not overloadable.
684 @end{Ramification}
685
686 @Defn{overloadable}
687 The declarations of callable entities
688 @Redundant[(including enumeration literals)]
689 are @i{overloadable}@Redundant[,
690 meaning that overloading is allowed for them].
691 @begin{Ramification}
692 A @nt{generic_declaration} is not overloadable within its own
693 @nt{generic_formal_part}.
694 This follows from the rules about when a @nt{name} denotes a current
695 instance.
696 See AI83-00286. This implies that within a
697 @nt{generic_formal_part}, outer declarations with the same defining name
698 are hidden from direct visibility. It also implies that if a generic
699 formal parameter has the same defining name as the generic itself,
700 the formal parameter hides the generic from direct visibility.
701 @end{Ramification}
702
703 @Defn{homograph}
704 Two declarations are @i{homographs}
705 if they have the same defining name,
706 and, if both are overloadable,
707 their profiles are type conformant.
708 @PDefn{type conformance}
709 @redundant[An inner declaration hides any outer homograph from direct visibility.]
710
711
712 @ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Overriding operation>,
713 Text=[@ChgAdded{Version=[2],Text=[An overriding operation
714 is one that replaces an inherited primitive operation. Operations may be marked
715 explicitly as overriding or not overriding.]}]}
716
717 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
718 @leading@Redundant[Two homographs are not generally allowed
719 immediately within the same declarative region unless one
720 @i{overrides} the other (see Legality Rules below).]
721 @Defn{override}
722 @Chg{New=[The only declarations that are @Defn{overridable}@i{overridable} are
723 the implicit declarations for predefined operators and inherited primitive
724 subprograms.],Old=[]}
725 A declaration overrides another homograph that occurs
726 immediately within the same declarative region in the
727 following cases:
728 @begin{Itemize}
729 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
730 @Chg{New=[A declaration that is not overridable overrides one that is overridable],
731 Old=[An explicit declaration overrides an implicit declaration of a primitive
732 subprogram]}, @Redundant[regardless of which declaration occurs first];
733 @begin{Ramification}
734 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],ARef=[AI95-00044-01]}
735 And regardless of whether the @Chg{New=[non-overridable],Old=[explicit]}
736 declaration is overloadable or not.
737 @Chg{New=[For example, @nt{statement_identifier}s are covered by this rule.],Old=[]}
738
739 The @lquotes@;regardless of which declaration occurs first@rquotes@;
740 is there because the explicit declaration could be a primitive subprogram
741 of a partial view, and then the full view might inherit a homograph.
742 We are saying that the explicit one wins
743 (within its scope), even though the implicit one comes later.
744
745 If the overriding declaration is also a subprogram,
746 then it is a primitive subprogram.
747
748 As explained in @RefSec{Private Operations},
749 some inherited primitive subprograms are never declared.
750 Such subprograms cannot be overridden,
751 although they can be reached by dispatching calls
752 in the case of a tagged type.
753 @end{Ramification}
754
755 The implicit declaration of an inherited operator overrides
756 that of a predefined operator;
757 @begin{Ramification}
758 In a previous version of Ada 9X, we tried to avoid the notion of
759 predefined operators, and say that they were inherited from some
760 magical root type.
761 However, this seemed like too much mechanism.
762 Therefore, a type can have a predefined "+" as well as an inherited "+".
763 The above rule says the inherited one wins.
764
765 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
766 The @lquotes@;regardless of which declaration occurs first@rquotes@; applies here
767 as well, in the case where @Chg{Version=[2],New=[@nt{derived_type_definition}],
768 Old=[@ntf{derived_type_declaration}]} in the visible
769 part of a public library unit derives from a private type declared in
770 the parent unit, and the full view of the parent type has additional
771 predefined operators, as explained in @RefSec{Private Operations}.
772 Those predefined operators can be overridden by inherited subprograms
773 implicitly declared earlier.
774 @end{Ramification}
775
776 An implicit declaration of an inherited subprogram
777 overrides a previous implicit declaration of an inherited
778 subprogram.
779
780 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
781 @ChgAdded{Version=[2],Type=[Leading],Text=[If two or more homographs are
782 implicitly declared at the same place:]}
783
784 @begin{InnerItemize}
785 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
786 @ChgAdded{Version=[2],Text=[If at least one is a subprogram that is neither a
787 null procedure nor an abstract subprogram, and does not require overriding (see
788 @RefSecNum{Abstract Types and Subprograms}), then they override those that are
789 null procedures, abstract subprograms, or require overriding. If more than one
790 such homograph remains that is not thus overridden, then they are all hidden
791 from all visibility.]}
792
793 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00251-01]}
794 @ChgAdded{Version=[2],Text=[Otherwise (all are null procedures, abstract
795 subprograms, or require overriding), then any null procedure overrides all
796 abstract subprograms and all subprograms that require overriding; if more than
797 one such homograph remains that is not thus overridden, then if they are all
798 fully conformant with one another, one is chosen arbitrarily; if not, they are
799 all hidden from all visibility.
800 @Defn2{Term=[full conformance],Sec=(required)}]}
801
802 @begin{Discussion}
803 @ChgRef{Version=[2],Kind=[AddedNormal]}
804 @ChgAdded{Version=[2],Type=[Leading],Text=[In the case where the
805 implementation arbitrarily chooses one overrider from among a group
806 of inherited subprograms, users should not be able to determine which
807 member was chosen, as the set of inherited subprograms which are chosen
808 from must be fully conformant. This rule is needed in order to
809 allow]}
810
811 @begin{Example}
812 @ChgRef{Version=[2],Kind=[AddedNormal]}
813 @Chg{Version=[2],New=[@Key{package} Outer @Key{is}
814 @Key{package} P1 @Key{is}
815 @Key{type} Ifc1 @Key{is interface};
816 @Key{procedure} Null_Procedure (X : Ifc1) @Key{is null};
817 @Key{procedure} Abstract_Subp (X : Ifc1) @Key{is abstract};
818 @Key{end} P1;],Old=[]}
819
820 @ChgRef{Version=[2],Kind=[AddedNormal]}
821 @Chg{Version=[2],New=[ @Key{package} P2 @Key{is}
822 @Key{type} Ifc2 @Key{is interface};
823 @Key{procedure} Null_Procedure (X : Ifc2) @Key{is null};
824 @Key{procedure} Abstract_Subp (X : Ifc2) @Key{is abstract};
825 @Key{end} P2;],Old=[]}
826
827 @ChgRef{Version=[2],Kind=[AddedNormal]}
828 @Chg{Version=[2],New=[ @Key{type} T @Key{is abstract new} P1.Ifc1 @Key{and} P2.Ifc2 @Key{with null record};
829 @Key{end} Outer;],Old=[]}
830 @end{Example}
831
832 @ChgRef{Version=[2],Kind=[AddedNormal]}
833 @ChgAdded{Version=[2],Text=[without requiring that T explicitly override
834 any of its inherited operations.]}
835
836 @ChgRef{Version=[2],Kind=[AddedNormal]}
837 @ChgAdded{Version=[2],Text=[Full conformance is required here,
838 as we cannot allow the parameter names to differ. If they did differ, the
839 routine which was selected for overriding could be determined by using
840 named parameter notation in a call.]}
841
842 @ChgRef{Version=[2],Kind=[AddedNormal]}
843 @ChgAdded{Version=[2],Text=[When the subprograms do not conform,
844 we chose not to adopt the @lquotes@;use clause@rquotes rule which would make
845 them all visible resulting in likely ambiguity. If we had used such a rule,
846 any successful calls would be confusing; and the fact that there are no
847 Beaujolais-like effect to worry about means we can consider other rules.
848 The hidden-from-all-visibility homographs are still inherited
849 by further derivations, which avoids order-of-declaration dependencies
850 and other anomalies.]}
851
852 @ChgRef{Version=[2],Kind=[AddedNormal]}
853 @ChgAdded{Version=[2],Text=[We have to be careful to not include arbitrary
854 selection if the routines have real bodies. (This can happen in generics, see
855 the example in the incompatibilities section below.) We don't want the
856 ability to successfully call routines where the body executed depends on the
857 compiler or a phase of the moon.]}
858
859 @ChgRef{Version=[2],Kind=[AddedNormal]}
860 @ChgAdded{Version=[2],Text=[Note that if the type is concrete, abstract
861 subprograms are inherited as subprograms that require overriding. We include
862 functions that require overriding as well; these don't have real bodies, so
863 they can use the more liberal rules.]}
864 @end{Discussion}
865
866 @end{InnerItemize}
867
868 @Redundant[For an implicit declaration of a primitive subprogram in a
869 generic unit, there is a copy of this declaration in an instance.]
870 However, a whole new set of primitive subprograms is implicitly
871 declared for each type declared within the visible part of the instance.
872 These new declarations occur immediately after the type
873 declaration, and override the copied ones.
874 @Redundant[The copied ones can be called only from within the instance;
875 the new ones can be called only from outside the instance,
876 although for tagged types, the body of a new one can be executed
877 by a call to an old one.]
878 @begin{Discussion}
879 In addition, this is also stated redundantly (again),
880 and is repeated, in @RefSec{Generic Instantiation}.
881 The rationale for the rule is explained there.
882 @end{Discussion}
883 @end{Itemize}
884
885 @leading@Defn{visible}
886 @RootDefn{hidden from all visibility}
887 A declaration is visible within its scope,
888 except where hidden from all visibility,
889 as follows:
890 @begin{Itemize}
891 @PDefn2{Term=[hidden from all visibility], Sec=(for overridden declaration)}
892 An overridden declaration is hidden from all visibility within the
893 scope of the overriding declaration.
894 @begin{Ramification}
895 We have to talk about the scope of the overriding declaration,
896 not its visibility, because it hides
897 even when it is itself hidden.
898
899 Note that the scope of an explicit @nt{subprogram_declaration}
900 does not start until after its profile.
901 @end{Ramification}
902
903 @leading@PDefn2{Term=[hidden from all visibility], Sec=(within the declaration itself)}
904 A declaration is hidden from all visibility until the end of the
905 declaration, except:
906 @begin(InnerItemize)
907 For a record type or record extension,
908 the declaration is hidden from all visibility only
909 until the reserved word @b(record);
910
911 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]}
912 For a @nt{package_declaration}, @Chg{Version=[2],New=[],Old=[task declaration,
913 protected declaration, ]}@nt{generic_@!package_@!declaration},
914 or @nt{subprogram_@!body}, the declaration is
915 hidden from all visibility only until the reserved word @key(is)
916 of the declaration@Chg{Version=[2],New=[;],Old=[.]}
917 @begin{Ramification}
918 We're talking about the @key{is} of the construct itself, here,
919 not some random @key{is} that might appear in a
920 @nt{generic_formal_part}.
921 @end{Ramification}
922
923 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]}
924 @ChgAdded{Version=[2],Text=[For a task declaration or protected declaration,
925 the declaration is hidden from all visibility only
926 until the reserved word @key(with) of the declaration if there is one, or the
927 reserved word @key(is) of the declaration if there is no @key(with).]}
928
929 @begin{Honest}
930 @ChgRef{Version=[2],Kind=[AddedNormal]}
931 @ChgAdded{Version=[2],Text=[If there is neither a @key(with) nor @key(is),
932 then the exception does not apply and the name is hidden from all
933 visibility until the end of the declaration. This oddity was inherited
934 from Ada 95.]}
935 @end{Honest}
936 @begin{Reason}
937 @ChgRef{Version=[2],Kind=[AddedNormal]}
938 @ChgAdded{Version=[2],Text=[We need the @lquotes@key(with) or @key(is)@rquotes
939 rule so that the visibility within an @nt{interface_list} does not
940 vary by construct. That would make it harder to complete private extensions
941 and would complicate implementations.]}
942 @end{Reason}
943
944 @end(InnerItemize)
945
946 @PDefn2{Term=[hidden from all visibility], Sec=(for a declaration completed
947 by a subsequent declaration)}
948 If the completion of a declaration is a declaration,
949 then within the scope of the completion,
950 the first declaration is hidden from all visibility.
951 Similarly, a @nt{discriminant_@!specification} or
952 @nt{parameter_@!specification} is hidden within the scope of a
953 corresponding @nt{discriminant_@!specification} or
954 @nt{parameter_@!specification} of a corresponding completion,
955 or of a corresponding @nt{accept_@!statement}.
956 @begin{Ramification}
957 This rule means, for example, that within the scope of a
958 @nt{full_type_declaration} that completes a
959 @nt{private_type_declaration},
960 the name of the type will denote the @nt{full_type_declaration},
961 and therefore the full view of the type.
962 On the other hand, if the completion is not a declaration,
963 then it doesn't hide anything,
964 and you can't denote it.
965 @end{Ramification}
966
967 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
968 @PDefn2{Term=[hidden from all visibility], Sec=(by lack of a
969 @nt{with_clause})}
970 The declaration of a library unit
971 (including a @nt{library_unit_renaming_declaration})
972 is hidden from all visibility @Chg{Version=[2],New=[],Old=[except ]}at
973 places @Chg{Version=[2],New=[outside],Old=[that are within]} its declarative
974 region @Chg{Version=[2],New=[that are not],Old=[or]} within the scope
975 of a @Chg{Version=[2],New=[@nt{nonlimited_with_clause}],Old=[@nt{with_clause}]} that
976 mentions it.@Chg{Version=[2],New=[ The limited view of a library package
977 is hidden from all visibility at places that are not within the scope
978 of a @nt{limited_with_clause} that mentions it; in addition, the limited view
979 is hidden from all visibility within the declarative region of the package, as
980 well as within the scope of any @nt{nonlimited_with_clause} that
981 mentions the package. Where the declaration of the limited view of a
982 package is visible, any name that denotes the package denotes the
983 limited view, including those provided by a package renaming.],Old=[@Redundant[For
984 each declaration or renaming of a generic unit as a child of
985 some parent generic package, there is a corresponding declaration nested
986 immediately within each instance of the parent.]
987 Such a nested declaration is hidden from all visibility
988 except at places that are
989 within the scope of a @nt{with_clause} that mentions the child.]}
990
991 @begin{Discussion}
992 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
993 This is the rule that prevents @nt{with_clause}s from being
994 transitive; the [immediate] scope includes indirect semantic dependents.
995 @Chg{Version=[2],New=[This rule also prevents the limited view of a package
996 from being visible in the same place as the full view of the package, which
997 prevents various ripple effects.],Old=[]}
998 @end{Discussion}
999
1000 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}@ChgNote{Just moved from above}
1001 @ChgAdded{Version=[2],Text=[@Redundant[For each
1002 declaration or renaming of a generic unit as a child of
1003 some parent generic package, there is a corresponding declaration nested
1004 immediately within each instance of the parent.]
1005 Such a nested declaration is hidden from all visibility
1006 except at places that are
1007 within the scope of a @nt{with_clause} that mentions the child.]}
1008
1009 @end{Itemize}
1010
1011 @leading@Defn{directly visible}
1012 @Defn{immediately visible}
1013 @Defn2{Term=[visibility], Sec=(direct)}
1014 @Defn2{Term=[visibility], Sec=(immediate)}
1015 A declaration with a @nt{defining_identifier} or
1016 @nt{defining_operator_symbol} is immediately visible
1017 @Redundant[(and hence
1018 directly visible)] within its immediate scope
1019 @RootDefn{hidden from direct visibility} except where hidden
1020 from direct visibility, as follows:
1021 @begin{Itemize}
1022 @PDefn2{Term=[hidden from direct visibility], Sec=(by an inner homograph)}
1023 A declaration is hidden from direct visibility
1024 within the immediate scope of a homograph of the
1025 declaration, if the homograph occurs within an inner declarative
1026 region;
1027
1028 @PDefn2{Term=[hidden from direct visibility],
1029 Sec=(where hidden from all visibility)}
1030 A declaration is also hidden from direct visibility
1031 where hidden from all visibility.
1032 @end{Itemize}
1033
1034 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00195-01],ARef=[AI95-00408-01]}
1035 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[visible], Sec=(attribute_@!definition_@!clause)}
1036 An @nt{attribute_definition_clause} is @i{visible}
1037 everywhere within its scope.]}
1038
1039 @end{StaticSem}
1040
1041 @begin{Resolution}
1042 @PDefn2{Term=[possible interpretation], Sec=(for @nt{direct_name}s)}
1043 A @nt{direct_name} shall resolve to denote a directly visible
1044 declaration whose defining name is the same as the @nt{direct_name}.
1045 @PDefn2{Term=[possible interpretation], Sec=(for @nt{selector_name}s)}
1046 A @nt{selector_name} shall resolve to denote
1047 a visible declaration whose defining name is the same as the
1048 @nt{selector_name}.
1049 @begin{Discussion}
1050 "The same as" has the obvious meaning here,
1051 so for +,
1052 the possible interpretations are declarations whose defining name is "+"
1053 (an @nt{operator_symbol}).
1054 @end{Discussion}
1055
1056 These rules on visibility and direct visibility do not apply
1057 in a @nt{context_clause}, a @nt{parent_unit_name},
1058 or a @nt{pragma} that appears at the place of a
1059 @nt{compilation_unit}.
1060 For those contexts, see the rules
1061 in @RefSec{Environment-Level Visibility Rules}.
1062 @begin{Ramification}
1063 Direct visibility is irrelevant for @nt{character_literal}s.
1064 In terms of overload resolution
1065 @nt{character_literal}s are similar to other literals,
1066 like @key{null} @em see @RefSecNum{Literals}.
1067 For @nt{character_literal}s, there is no need to worry about
1068 hiding, since there is no way to declare homographs.
1069 @end{Ramification}
1070 @end{Resolution}
1071
1072 @begin{Legality}
1073 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0025],Ref=[8652/0026],ARef=[AI95-00044-01],ARef=[AI95-00150-01]}
1074 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00377-01]}
1075 @Chg{New=[A non-overridable],Old=[An explicit]} declaration is illegal if there is a
1076 homograph occurring immediately within the same
1077 declarative region that is visible at the place of the
1078 declaration, and is not hidden from all visibility by the
1079 @Chg{New=[non-overridable],Old=[explicit]} declaration.
1080 @Chg{New=[In addition, a type extension is illegal if somewhere within its
1081 immediate scope it has two visible components with the same name.],Old=[]}
1082 Similarly, the @nt<context_clause> for a @Chg{Version=[2],
1083 New=[compilation unit],Old=[@nt<subunit>]} is illegal if it mentions (in a
1084 @nt<with_clause>) some library unit, and there is a homograph
1085 of the library unit that is visible at the place of the @Chg{Version=[2],
1086 New=[compilation unit],Old=[corresponding stub]}, and the
1087 homograph and the mentioned library unit are both
1088 declared immediately within the same declarative region.@PDefn{generic contract issue}
1089 These rules also apply to dispatching operations declared
1090 in the visible part of an instance of a generic unit.
1091 However, they do not apply to other overloadable declarations in
1092 an instance@Redundant[; such declarations may have type conformant profiles
1093 in the instance, so long as the corresponding declarations in the generic
1094 were not type conformant].
1095 @PDefn{type conformance}
1096
1097 @begin{Discussion}
1098 @leading@;Normally, these rules just mean you can't explicitly
1099 declare two homographs
1100 immediately within the same declarative region.
1101 The wording is designed to handle the
1102 following special cases:
1103 @begin{Itemize}
1104 If the second declaration completes the first one,
1105 the second declaration is legal.
1106
1107 @leading@;If the body of a library unit contains an explicit homograph of
1108 a child of that same library unit, this is illegal only if the body
1109 mentions the child in its @nt<context_clause>, or if
1110 some subunit mentions the child.
1111 Here's an example:
1112 @begin{Example}
1113 @key[package] P @key[is]
1114 @key[end] P;
1115
1116 @key[package] P.Q @key[is]
1117 @key[end] P.Q;
1118
1119 @key[package] @key[body] P @key[is]
1120 Q : Integer; --@RI{ OK; we cannot see package P.Q here.}
1121 @key[procedure] Sub @key[is] @key[separate];
1122 @key[end] P;
1123
1124 @key[with] P.Q;
1125 @key[separate](P)
1126 @key[procedure] Sub @key[is] --@RI{ Illegal.}
1127 @key[begin]
1128 @key[null];
1129 @key[end] Sub;
1130 @end{Example}
1131
1132 @NoPrefix@;If package body P said "@key[with] P.Q;", then it would be illegal
1133 to declare the homograph Q: Integer. But it does not, so the
1134 body of P is OK.
1135 However, the subunit would be able to see both P.Q's,
1136 and is therefore illegal.
1137
1138 @NoPrefix@;A previous version of Ada 9X allowed the subunit,
1139 and said that references to P.Q would tend to be ambiguous.
1140 However, that was a bad idea, because it requires overload resolution
1141 to resolve references to directly visible non-overloadable
1142 homographs, which is something compilers have never before been
1143 required to do.
1144
1145 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0026],Ref=[8652/0102],ARef=[AI95-00150-01],ARef=[AI95-00157-01]}
1146 @ChgAdded{Version=[1],Type=[Leading],Text=[If a type extension contains a
1147 component with
1148 the same name as a component in an ancestor type, there must be no place
1149 where both components are visible. For instance:]}
1150 @begin{Example}@ChgRef{Version=[1],Kind=[Added]}
1151 @Chg{New=[@key[package] A @key[is]
1152 @key[type] T @key[is tagged private];
1153 @key[package] B @key[is]
1154 @key[type] NT @key[is new] T @key[with record]
1155 I: Integer; -- @RI{Illegal because T.I is visible in the body.}
1156 @key[end record]; -- @RI{T.I is not visible here.}
1157 @key[end] B;
1158 @key[private]
1159 @key[type] T @key[is tagged record]
1160 I: Integer; -- @RI{Illegal because T.I is visible in the body.}
1161 @key[end record];
1162 @key[end] A;],Old=[]}
1163
1164 @ChgRef{Version=[1],Kind=[Added]}
1165 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00114-01]}
1166 @Chg{New=[@Chg{Version=[2],New=[],Old=[@key[package] A @key[is]
1167 ]}@key[package] @key[body] A @key[is]
1168 @key[package] @key[body] B @key[is]
1169 -- @RI{T.I becomes visible here.}
1170 @key[end] B;
1171 @key[end] A;],Old=[]}
1172
1173 @ChgRef{Version=[1],Kind=[Added]}
1174 @Chg{New=[@key[package] A.C @key[is]
1175 @key[type] NT2 @key[is new] A.T @key[with record]
1176 I: Integer; -- @RI{Illegal because T.I is visible in the private part.}
1177 @key[end record]; -- @RI{T.I is not visible here.}
1178 @key[private]
1179 -- @RI{T.I is visible here.}
1180 @key[end] A.C;],Old=[]}
1181
1182 @ChgRef{Version=[1],Kind=[Added]}
1183 @Chg{New=[@key[with] A;
1184 @key[package] D @key[is]
1185 @key[type] NT3 @key[is new] A.T @key[with record]
1186 I: Integer; -- @RI{Legal because T.I is never visible in this package.}
1187 @key[end record];
1188 @key[end] D;],Old=[]}
1189
1190 @ChgRef{Version=[1],Kind=[Added]}
1191 @Chg{New=[@key[with] D;
1192 @key[package] A.E @key[is]
1193 @key[type] NT4 @key[is new] D.NT3 @key[with null record];
1194 X : NT4;
1195 I1 : Integer := X.I; -- @RI{D.NT3.I}
1196 I2 : Integer := D.NT3(X).I; -- @RI{D.NT3.I}
1197 I3 : Integer := A.T(X).I; -- @RI{A.T.I}
1198 @key[end] A.E;],Old=[]}
1199 @end{Example}
1200 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0102],ARef=[AI95-00157-01]}
1201 @ChgAdded{Version=[1],NoPrefix=[T],Text=[D.NT3 can have a component I because
1202 the component I of the parent type is never visible. The parent component
1203 exists, of course, but is never declared for the type D.NT3. In the child
1204 package A.E, the component I of A.T is visible, but that does not change the
1205 fact that the A.T.I component was never declared for type D.NT3. Thus, A.E.NT4
1206 does not (visibly) inherit the component I from A.T, while it does inherit the
1207 component I from D.NT3. Of course, both components exist, and can be accessed
1208 by a type conversion as shown above. This behavior stems from the fact that
1209 every characteristic of a type (including components) must be declared
1210 somewhere in the innermost declarative region containing the type @em if the
1211 characteristic is never visible in that declarative region, it is never
1212 declared. Therefore, such characteristics do not suddenly become available even
1213 if they are in fact visible in some other scope.
1214 See @RefSecNum{Private Operations} for more on the rules.]}
1215
1216 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00377-01]}
1217 @ChgAdded{Version=[2],Text=[It is illegal to mention both an explicit child of
1218 an instance, and a child of the generic from which the instance was
1219 instantiated. This is easier to understand with an example:]}
1220 @begin{Example}
1221 @ChgRef{Version=[2],Kind=[Added]}
1222 @Chg{Version=[2],New=[@key{generic}
1223 @key{package} G1 @key{is}
1224 @key{end} G1;],Old=[]}
1225
1226 @ChgRef{Version=[2],Kind=[Added]}
1227 @Chg{Version=[2],New=[@key{generic}
1228 @key{package} G1.G2 @key{is}
1229 @key{end} G1.G2;],Old=[]}
1230
1231 @ChgRef{Version=[2],Kind=[Added]}
1232 @Chg{Version=[2],New=[@key{with} G1;
1233 @key{package} I1 @key{is new} G1;],Old=[]}
1234
1235 @ChgRef{Version=[2],Kind=[Added]}
1236 @ChgAdded{Version=[2],Text=[@key{package} I1.G2 @key{renames} ...]}
1237
1238 @ChgRef{Version=[2],Kind=[Added]}
1239 @Chg{Version=[2],New=[@key{with} G1.G2;
1240 @key{with} I1.G2; -- @RI{Illegal}
1241 @key{package} Bad @key{is} ...],Old=[]}
1242 @end{Example}
1243
1244 @ChgRef{Version=[2],Kind=[Added]}
1245 @ChgAdded{Version=[2],NoPrefix=[T],Text=[The context clause for Bad is illegal
1246 as I1 has an implicit declaration of I1.G2 based on the generic child G1.G2,
1247 as well as the mention of the explicit child I1.G2. As in the previous cases,
1248 this is illegal only if the context clause makes both children visible; the
1249 explicit child can be mentioned as long as the generic child is not (and
1250 vice-versa).]}
1251 @end{Itemize}
1252
1253 Note that we need to be careful which things we make "hidden from all
1254 visibility" versus which things we make simply illegal for names to
1255 denote. The distinction is subtle.
1256 The rules that disallow names denoting components within a type
1257 declaration (see @RefSecNum{Discriminants}) do not make the components
1258 invisible at those places, so that the above rule makes components with
1259 the same name illegal.
1260 The same is true for the rule that disallows names denoting formal
1261 parameters within a @nt{formal_part} (see @RefSecNum{Subprogram Declarations}).
1262 @end{Discussion}
1263 @begin{Discussion}
1264 The part about instances is from AI83-00012.
1265 The reason it says @lquotes@;overloadable declarations@rquotes@; is because
1266 we don't want it to apply to type extensions that appear in an instance;
1267 components are not overloadable.
1268 @end{Discussion}
1269 @end{Legality}
1270
1271 @begin{Notes}
1272 Visibility for compilation units
1273 follows from the definition of the environment
1274 in @RefSecNum{The Compilation Process},
1275 except that it is necessary to apply a @nt{with_clause} to obtain
1276 visibility to a @nt{library_unit_declaration}
1277 or @nt{library_unit_renaming_declaration}.
1278
1279 In addition to the visibility rules given above,
1280 the meaning of the occurrence of a @nt{direct_name} or
1281 @nt{selector_name} at a given place in the text can depend on
1282 the overloading rules
1283 (see @RefSecNum{The Context of Overload Resolution}).
1284
1285 Not all contexts where an @nt<identifier>, @nt<character_literal>,
1286 or @nt<operator_symbol> are allowed require visibility of a corresponding
1287 declaration.
1288 Contexts where visibility is not required
1289 are identified by using one of these three syntactic categories
1290 directly in a syntax rule, rather than using @nt<direct_name> or
1291 @nt<selector_name>.
1292 @begin{Ramification}
1293 @leading@;An @nt{identifier}, @nt{character_literal} or @nt{operator_symbol}
1294 that occurs in one of the following contexts is not
1295 required to denote a visible or directly
1296 visible declaration:
1297 @begin{enumerate}
1298 A defining name.
1299
1300 The @nt{identifier}s or @nt{operator_symbol} that appear after the
1301 reserved word @key{end} in a @nt{proper_body}.
1302 Similarly for @lquotes@;@key{end loop}@rquotes@;, etc.
1303
1304 An @nt{attribute_designator}.
1305
1306 A @nt{pragma} @nt{identifier}.
1307
1308 A @SynI{pragma_argument_}@nt{identifier}.
1309
1310 An @nt{identifier} specific to a
1311 pragma used in a pragma argument.
1312 @end{enumerate}
1313
1314 The visibility rules have nothing to do with the above cases;
1315 the meanings of such things are defined elsewhere.
1316 Reserved words are not @nt{identifier}s;
1317 the visibility rules don't apply to them either.
1318
1319 Because of the way we have defined "declaration",
1320 it is possible for a usage name to denote a @nt{subprogram_body}, either
1321 within that body, or (for a non-library unit) after it
1322 (since the body hides the corresponding declaration, if any).
1323 Other bodies do not work that way.
1324 Completions of @nt{type_declaration}s and
1325 deferred constant declarations do work that way.
1326 @nt{Accept_statement}s are never denoted, although the
1327 @nt{parameter_specification}s in their profiles can be.
1328
1329 @leading@;The scope of a subprogram does not start until after its profile.
1330 Thus, the following is legal:
1331 @begin{Example}
1332 X : @key[constant] Integer := 17;
1333 ...
1334 @key[package] P @key[is]
1335 @key[procedure] X(Y : @key[in] Integer := X);
1336 @key[end] P;
1337 @end{Example}
1338
1339 The body of the subprogram will probably be illegal,
1340 however, since the constant X will be hidden by then.
1341
1342 @leading@;The rule is different for generic subprograms,
1343 since they are not overloadable;
1344 the following is illegal:
1345 @begin{Example}
1346 X : @key[constant] Integer := 17;
1347 @key[package] P @key[is]
1348 @key[generic]
1349 Z : Integer := X; --@RI{ Illegal!}
1350 @key[procedure] X(Y : @key[in] Integer := X); --@RI{ Illegal!}
1351 @key[end] P;
1352 @end{Example}
1353
1354 The constant X is hidden from direct visibility by the generic
1355 declaration.
1356 @end{Ramification}
1357 @end{Notes}
1358
1359 @begin{Extend83}
1360 @Defn{extensions to Ada 83}
1361 Declarations with the same defining
1362 name as that of a subprogram or entry being defined
1363 are nevertheless visible within
1364 the subprogram specification or entry declaration.
1365 @end{Extend83}
1366
1367 @begin{DiffWord83}
1368 The term @lquotes@;visible by selection@rquotes@; is no longer defined.
1369 We use the terms @lquotes@;directly visible@rquotes@; and @lquotes@;visible@rquotes@; (among other things).
1370 There are only two regions of text that are of interest, here: the
1371 region in which a declaration is visible,
1372 and the region in which it is directly visible.
1373
1374 Visibility is defined only for declarations.
1375 @end{DiffWord83}
1376
1377
1378 @begin{Incompatible95}
1379 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00251-01]}
1380 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
1381 Added rules to handle the inheritance and overriding of
1382 multiple homographs for a single type declaration, in order to support
1383 multiple inheritance from interfaces. The new rules are intended to be
1384 compatible with the existing rules so that programs that do not use
1385 interfaces do not change their legality. However, there is a very rare
1386 case where this is not true:]}
1387 @begin{Example}
1388 @ChgRef{Version=[2],Kind=[AddedNormal]}
1389 @ChgAdded{Version=[2],Text=[@key{generic}
1390 @key{type} T1 @key{is private};
1391 @key{type} T2 @key{is private};
1392 @key{package} G @key{is}
1393 @key{type} T @key{is null record};
1394 @key{procedure} P (X : T; Y : T1);
1395 @key{procedure} P (X : T; Z : T2);
1396 @key{end} G;]]}
1397
1398 @ChgRef{Version=[2],Kind=[AddedNormal]}
1399 @ChgAdded{Version=[2],Text=[@key{package} I @key{is new} G (Integer, Integer); -- @RI[Exports homographs of P.]]}
1400
1401 @ChgRef{Version=[2],Kind=[AddedNormal]}
1402 @ChgAdded{Version=[2],Text=[@key{type} D @key{is new} I.T; -- @RI[Both Ps are inherited.]]}
1403
1404 @ChgRef{Version=[2],Kind=[AddedNormal]}
1405 @ChgAdded{Version=[2],Text=[Obj : D;]}
1406
1407 @ChgRef{Version=[2],Kind=[AddedNormal]}
1408 @ChgAdded{Version=[2],Text=[P (Obj, Z => 10); -- @RI[Legal in Ada 95, illegal in Ada 2005.]]}
1409 @end{Example}
1410 @ChgRef{Version=[2],Kind=[AddedNormal]}
1411 @ChgAdded{Version=[2],Text=[The call to P would resolve in Ada 95 by using the
1412 parameter name, while the procedures P would be hidden from all visibility
1413 in Ada 2005 and thus would not resolve.
1414 This case doesn't seem worth making the rules any more
1415 complex than they already are.]}
1416
1417 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00377-01]}
1418 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] A @nt{with_clause} is
1419 illegal if it would create a homograph of an implicitly declared generic
1420 child (see @RefSecNum{Compilation Units - Library Units}). An Ada 95 compiler
1421 could have allowed this, but which unit of the two units involved would be
1422 denoted wasn't specified, so any successful use isn't portable. Removing one
1423 of the two @nt{with_clause}s involved will fix the problem.]}
1424 @end{Incompatible95}
1425
1426 @begin{DiffWord95}
1427 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0025],ARef=[AI95-00044-01]}
1428 @Chg{Version=[2],New=[@b<Corrigendum:> Clarified the overriding rules so that
1429 "/=" and @nt{statement_identifier}s are covered.],Old=[]}
1430
1431 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0026],ARef=[AI95-00150-01]}
1432 @Chg{Version=[2],New=[@b<Corrigendum:> Clarified that is it never possible
1433 for two components with the same name to be visible; any such program is
1434 illegal.],Old=[]}
1435
1436 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00195-01],ARef=[AI95-00408-01]}
1437 @ChgAdded{Version=[2],Text=[The visibility of an @nt{attribute_definition_clause} is
1438 defined so that it can be used by the stream attribute availability rules
1439 (see @RefSecNum{Stream-Oriented Attributes}).]}
1440
1441 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1442 @Chg{Version=[2],New=[The visibility of a limited view of a library package
1443 is defined (see @RefSecNum{Compilation Units - Library Units}).],Old=[]}
1444 @end{DiffWord95}
1445
1446
1447 @RMNewPage@Comment{For printed Ada 2005 only}
1448 @LabeledAddedSubClause{Version=[2],Name=[Overriding Indicators]}
1449
1450 @begin{Intro}
1451 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1452 @ChgAdded{Version=[2],Text=[An @nt{overriding_indicator} is used to declare
1453 that an operation is intended to override (or not override) an inherited
1454 operation.]}
1455 @end{Intro}
1456
1457 @begin{Syntax}
1458 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1459 @AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<overriding_indicator>,Old=<>}>,
1460 rhs="@Chg{Version=[2],New=<[@key{not}] @key{overriding}>,Old=<>}"}
1461 @end{Syntax}
1462
1463 @begin{Legality}
1464 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03],ARef=[AI95-00348-01],ARef=[AI95-00397-01]}
1465 @ChgAdded{Version=[2],Type=[Leading],Text=[If an
1466 @nt{abstract_@!subprogram_@!declaration}, @nt{null_@!procedure_@!declaration},
1467 @nt{subprogram_body}, @nt{subprogram_@!body_stub},
1468 @nt{subprogram_@!renaming_@!declaration}, @nt{generic_@!instantiation} of a
1469 subprogram, or @nt{subprogram_@!declaration}
1470 other than a protected subprogram has an @nt{overriding_@!indicator}, then:]}
1471
1472 @begin{Itemize}
1473 @ChgRef{Version=[2],Kind=[AddedNormal]}
1474 @ChgAdded{Version=[2],Text=[the operation shall be a primitive operation for some
1475 type;]}
1476
1477 @ChgRef{Version=[2],Kind=[AddedNormal]}
1478 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1479 @key{overriding}, then the operation shall override a homograph at the place of
1480 the declaration or body;]}
1481
1482 @ChgRef{Version=[2],Kind=[AddedNormal]}
1483 @ChgAdded{Version=[2],Text=[if the @nt{overriding_indicator} is
1484 @key{not overriding}, then the operation shall not override any homograph
1485 (at any place).]}
1486 @end{Itemize}
1487
1488 @ChgRef{Version=[2],Kind=[AddedNormal]}
1489 @ChgAdded{Version=[2],Text=[@PDefn{generic contract issue}In addition to the
1490 places where @LegalityTitle normally
1491 apply, these rules also apply in the private part of an instance of a generic
1492 unit.]}
1493
1494 @begin{Discussion}
1495 @ChgRef{Version=[2],Kind=[AddedNormal]}
1496 @ChgAdded{Version=[2],Text=[The @Key{overriding} and @Key{not overriding} rules
1497 differ slightly. For @Key{overriding}, we want the indicator to reflect the
1498 overriding state at the place of the declaration; otherwise the indicator would
1499 be @LQuotes@;lying@RQuotes@;. Whether a homograph is implicitly declared after
1500 the declaration (see 7.3.1 to see how this can happen)
1501 has no impact on this check. However, @Key{not overriding} is different;
1502 @LQuotes@;lying@RQuotes@; would happen if a homograph declared later actually
1503 is overriding. So, we require this check to take into account later overridings.
1504 That can be implemented either by looking ahead, or by rechecking when
1505 additional operations are declared.]}
1506
1507 @ChgRef{Version=[2],Kind=[AddedNormal]}
1508 @ChgAdded{Version=[2],Text=[The @LQuotes@;no lying@RQuotes@; rules are
1509 needed to prevent a @nt{subprogram_declaration} and @nt{subprogram_body}
1510 from having contradictory @nt{overriding_indicator}s.]}
1511 @end{Discussion}
1512 @end{Legality}
1513
1514 @begin{Notes}
1515 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00397-01]}
1516 @ChgAdded{Version=[2],Text=[Rules for @nt{overriding_indicator}s of task and
1517 protected entries and of protected subprograms are found in
1518 @RefSecNum{Entries and Accept Statements}
1519 and @RefSecNum{Protected Units and Protected Objects}, respectively.]}
1520 @end{Notes}
1521
1522 @begin{Examples}
1523 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]}
1524 @ChgAdded{Version=[2],Type=[Leading],Text=[The use of
1525 @nt{overriding_indicator}s allows the detection of errors at compile-time that
1526 otherwise might not be detected at all. For instance, we might declare a
1527 security queue derived from the Queue interface of 3.9.4 as:]}
1528
1529 @begin{Example}
1530 @ChgRef{Version=[2],Kind=[AddedNormal]}
1531 @ChgAdded{Version=[2],Text=[@key{type} Security_Queue @key{is new} Queue @key{with record} ...;]}
1532
1533 @ChgRef{Version=[2],Kind=[AddedNormal]}
1534 @ChgAdded{Version=[2],Text=[@key{overriding}
1535 @key{procedure} Append(Q : @key{in out} Security_Queue; Person : @key{in} Person_Name);]}
1536
1537 @ChgRef{Version=[2],Kind=[AddedNormal]}
1538 @ChgAdded{Version=[2],Text=[@key{overriding}
1539 @key{procedure} Remove_First(Q : @key{in out} Security_Queue; Person : @key{in} Person_Name);]}
1540
1541 @ChgRef{Version=[2],Kind=[AddedNormal]}
1542 @ChgAdded{Version=[2],Text=[@key{overriding}
1543 @key{function} Cur_Count(Q : @key{in} Security_Queue) @key{return} Natural;]}
1544
1545 @ChgRef{Version=[2],Kind=[AddedNormal]}
1546 @ChgAdded{Version=[2],Text=[@key{overriding}
1547 @key{function} Max_Count(Q : @key{in} Security_Queue) @key{return} Natural;]}
1548
1549 @ChgRef{Version=[2],Kind=[AddedNormal]}
1550 @ChgAdded{Version=[2],Text=[@key{not overriding}
1551 @key{procedure} Arrest(Q : @key{in out} Security_Queue; Person : @key{in} Person_Name);]}
1552 @end{Example}
1553
1554 @ChgRef{Version=[2],Kind=[AddedNormal]}
1555 @ChgAdded{Version=[2],Text=[The first four subprogram declarations guarantee
1556 that these subprograms will override the four subprograms inherited from the
1557 Queue interface. A misspelling in one of these subprograms will be detected
1558 by the implementation. Conversely, the declaration of Arrest guarantees that
1559 this is a new operation.]}
1560
1561 @begin{Discussion}
1562 @ChgRef{Version=[2],Kind=[AddedNormal]}
1563 @ChgAdded{Version=[2],Text=[In this case, the subprograms are abstract, so
1564 misspellings will get detected anyway. But for other subprograms
1565 (especially when deriving from concrete types), the error might never be
1566 detected, and a body other than the one the programmer intended might be
1567 executed without warning. Thus our new motto: @lquotes@;Overriding
1568 indicators @em don't derive a type without them!@rquotes]}
1569 @end{Discussion}
1570 @end{Examples}
1571
1572 @begin{Extend95}
1573 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
1574 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1575 @nt{Overriding_indicator}s are new. These let the
1576 programmer state her overriding intentions to the compiler; if the compiler
1577 disagrees, an error will be produced rather than a hard to find bug.]}
1578 @end{Extend95}
1579
1580
1581 @RMNewPage@Comment{For printed RM Ada 2005}
1582 @LabeledClause{Use Clauses}
1583
1584 @begin{Intro}
1585 @redundant[A @nt{use_package_clause} achieves direct visibility of declarations that
1586 appear in the visible part of a package;
1587 a @nt{use_type_clause} achieves direct visibility of the primitive
1588 operators of a type.]
1589 @end{Intro}
1590
1591 @begin{MetaRules}
1592 @Defn{equivalence of @nt{use_clause}s and @nt{selected_component}s}
1593 If and only if the visibility rules allow P.A,
1594 "@key[use] P;" should make A directly visible
1595 (barring name conflicts).
1596 This means, for example, that child library units, and
1597 generic formals of a formal package whose
1598 @nt{formal_package_actual_part} is (<>),
1599 should be made visible by
1600 a @nt{use_clause} for the appropriate package.
1601
1602 @Defn{Beaujolais effect}
1603 The rules for @nt{use_clause}s were carefully constructed to avoid
1604 so-called @i(Beaujolais) effects, where the addition or removal
1605 of a single @nt{use_clause}, or a single declaration in a "use"d
1606 package, would
1607 change the meaning of a program from one legal interpretation to another.
1608 @end{MetaRules}
1609
1610 @begin{Syntax}
1611 @Syn{lhs=<use_clause>,rhs="@Syn2{use_package_clause} | @Syn2{use_type_clause}"}
1612
1613
1614 @Syn{lhs=<use_package_clause>,rhs="@key{use} @SynI{package_}@Syn2{name} {, @SynI{package_}@Syn2{name}};"}
1615
1616 @Syn{lhs=<use_type_clause>,rhs="@key{use type} @Syn2{subtype_mark} {, @Syn2{subtype_mark}};"}
1617 @end{Syntax}
1618
1619 @begin{Legality}
1620 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1621 A @SynI{package_}@nt{name} of a @nt{use_package_clause}
1622 shall denote @Chg{Version=[2],New=[a nonlimited view of ],Old=[]}a package.
1623 @begin{Ramification}
1624 This includes formal packages.
1625 @end{Ramification}
1626 @end{Legality}
1627
1628 @begin{StaticSem}
1629 @Defn2{Term=[scope], Sec=(of a @nt{use_clause})}
1630 For each @nt{use_clause},
1631 there is a certain region of text called the @i{scope} of the @nt{use_clause}.
1632 For a @nt{use_clause} within a @nt{context_clause} of a
1633 @nt{library_unit_declaration}
1634 or @nt{library_unit_renaming_declaration},
1635 the scope is the entire declarative region of the declaration.
1636 For a @nt{use_clause} within a @nt{context_clause} of a
1637 body, the scope is the entire body @Redundant[and any
1638 subunits (including multiply
1639 nested subunits).
1640 The scope does not include @nt<context_clause>s themselves.]
1641
1642 For a @nt{use_clause} immediately within a declarative region,
1643 the scope is the portion of the declarative region
1644 starting just after the @nt{use_clause}
1645 and extending to the end of the declarative region.
1646 However, the scope of a @nt{use_clause} in the private part of a library
1647 unit does not include the visible part of
1648 any public descendant of that library unit.
1649 @begin{Reason}
1650 @leading@;The exception echoes the similar exception for
1651 @lquotes@;immediate scope (of a declaration)@rquotes@;
1652 (see @RefSecNum{Scope of Declarations}).
1653 It makes @nt{use_clause}s work like this:
1654 @begin{Example}
1655 @key[package] P @key[is]
1656 @key[type] T @key[is] @key[range] 1..10;
1657 @key[end] P;
1658
1659 @key[with] P;
1660 @key[package] Parent @key[is]
1661 @key[private]
1662 @key[use] P;
1663 X : T;
1664 @key[end] Parent;
1665
1666 @key[package] Parent.Child @key[is]
1667 Y : T; --@RI{ Illegal!}
1668 Z : P.T;
1669 @key[private]
1670 W : T;
1671 @key[end] Parent.Child;
1672 @end{Example}
1673
1674 The declaration of Y is illegal because the scope of the @lquotes@;@key[use] P@rquotes@;
1675 does not include that place, so T is not directly visible there.
1676 The declarations of X, Z, and W are legal.
1677 @end{Reason}
1678
1679 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06]}
1680 @Chg{Version=[2],New=[A package is @i{named} in a @nt{use_package_clause} if
1681 it is denoted by a @SynI{package_}@nt{name} of that clause. A type is @i{named}
1682 in a @nt{use_type_clause} if it is determined by a @nt{subtype_mark} of that
1683 clause.@Defn2{Term=[named],Sec=[in a use clause]}],Old=[]}
1684
1685 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00217-06]}
1686 @Defn{potentially use-visible}
1687 For each package @Chg{Version=[2],New=[named in ],Old=[denoted by
1688 a @SynI{package_}@nt{name} of ]}a @nt{use_package_clause} whose scope
1689 encloses a place, each declaration that occurs immediately within
1690 the declarative region of the package is
1691 @i(potentially use-visible) at this place
1692 if the declaration is visible at this place.
1693 For each type @i(T) or @i(T)'Class @Chg{Version=[2],New=[named in ],Old=[
1694 determined by a @nt<subtype_mark> of ]}a @nt{use_type_clause} whose scope
1695 encloses a place, the declaration of each primitive operator of type @i(T)
1696 is potentially use-visible at this place
1697 if its declaration is visible at this place.
1698 @begin{Ramification}
1699 Primitive subprograms whose defining name is an @nt{identifier} are
1700 @i{not} made potentially visible by a @nt{use_type_clause}.
1701 A @nt{use_type_clause} is only for operators.
1702
1703 The semantics described here should be similar
1704 to the semantics for expanded names given
1705 in @RefSec{Selected Components}
1706 so as to achieve the effect requested by
1707 the @lquotes@;principle of equivalence of @nt{use_clause}s and
1708 @nt{selected_component}s.@rquotes@;
1709 Thus, child library units and generic formal parameters of a formal
1710 package are
1711 potentially use-visible when their enclosing package is use'd.
1712
1713 The "visible at that place" part implies that
1714 applying a @nt{use_clause} to a parent unit does not make all of its
1715 children use-visible @em only those that have been made
1716 visible by a @nt{with_clause}.
1717 It also implies that we don't have to worry about hiding in the
1718 definition of "directly visible" @em a declaration cannot be use-visible
1719 unless it is visible.
1720
1721 Note that
1722 "@key[use type] T'Class;" is equivalent to "@key[use type] T;",
1723 which helps avoid breaking the generic contract model.
1724 @end{Ramification}
1725
1726 @leading@Defn{use-visible}
1727 @Defn2{Term=[visibility],Sec=(use clause)}
1728 A declaration is @i{use-visible} if it is potentially use-visible,
1729 except in these naming-conflict cases:
1730 @begin{itemize}
1731 A potentially use-visible declaration is not use-visible if the place
1732 considered is within the immediate scope of a homograph of the
1733 declaration.
1734
1735 Potentially use-visible declarations that have the same @nt{identifier}
1736 are not use-visible unless each of them is an overloadable
1737 declaration.
1738 @begin{Ramification}
1739 Overloadable declarations don't cancel each other out,
1740 even if they are homographs,
1741 though if they are not distinguishable
1742 by formal parameter names or the presence or absence of
1743 @nt{default_expression}s, any use will be ambiguous.
1744 We only mention @nt{identifier}s here, because
1745 declarations named by @nt<operator_symbol>s are
1746 always overloadable, and hence never cancel each other.
1747 Direct visibility is irrelevant for @nt{character_literal}s.
1748 @end{Ramification}
1749 @end{itemize}
1750 @end{StaticSem}
1751
1752 @begin{RunTime}
1753 @PDefn2{Term=[elaboration], Sec=(use_clause)}
1754 The elaboration of a @nt{use_clause} has no effect.
1755 @end{RunTime}
1756
1757 @begin{Examples}
1758
1759 @leading@keepnext@i{Example of a use clause in a context clause:}
1760 @begin{Example}
1761 @key[with] Ada.Calendar; @key[use] Ada;
1762 @end{Example}
1763
1764 @begin{Wide}
1765 @leading@keepnext@i{Example of a use type clause:}
1766 @end{Wide}
1767 @begin{Example}
1768 @key[use type] Rational_Numbers.Rational; --@RI{ see @RefSecNum{Package Specifications and Declarations}}
1769 Two_Thirds: Rational_Numbers.Rational := 2/3;
1770 @end{Example}
1771
1772 @begin{Ramification}
1773 In @lquotes@;@key[use] X, Y;@rquotes@;, Y cannot refer to something made visible by the
1774 @lquotes@;@key[use]@rquotes@; of X.
1775 Thus, it's not (quite) equivalent to @lquotes@;@key[use] X; @key[use] Y;@rquotes@;.
1776
1777 If a given declaration is already immediately visible,
1778 then a @nt{use_clause} that makes it potentially use-visible
1779 has no effect.
1780 Therefore,
1781 a @nt{use_type_clause} for a type whose declaration appears
1782 in a place other than the visible part
1783 of a package has no effect;
1784 it cannot make a declaration use-visible
1785 unless that declaration is already immediately visible.
1786
1787 "@key[Use] @key[type] S1;" and "@key[use] @key[type] S2;"
1788 are equivalent if S1 and S2 are both subtypes of the same type.
1789 In particular,
1790 "@key[use] @key[type] S;" and "@key[use] @key[type] S'Base;"
1791 are equivalent.
1792 @end{Ramification}
1793 @begin{Reason}
1794 We considered adding a rule that prevented several declarations of
1795 views of the same entity that all have the same semantics from
1796 cancelling each other out.
1797 For example, if a (possibly implicit)
1798 @nt{subprogram_declaration} for "+" is potentially use-visible,
1799 and a fully conformant renaming of it is also potentially
1800 use-visible, then they (annoyingly) cancel each other out;
1801 neither one is use-visible.
1802 The considered rule would have made just one of them use-visible.
1803 We gave up on this idea due to the complexity of the rule.
1804 It would have had to account for both overloadable and
1805 non-overloadable @nt{renaming_declaration}s,
1806 the case where the rule should apply only to some subset of the
1807 declarations with the same defining name,
1808 and the case of @nt{subtype_declaration}s
1809 (since they are claimed to be sufficient for renaming of subtypes).
1810 @end{Reason}
1811 @end{Examples}
1812
1813 @begin{Extend83}
1814 @Defn{extensions to Ada 83}
1815 The @nt{use_type_clause} is new to Ada 95.
1816 @end{Extend83}
1817
1818 @begin{DiffWord83}
1819 The phrase @lquotes@;omitting from this set any packages that
1820 enclose this place@rquotes@; is no longer necessary to avoid making something
1821 visible outside its scope, because we explicitly state that the
1822 declaration has to be visible in order to be
1823 potentially use-visible.
1824 @end{DiffWord83}
1825
1826
1827 @begin{DiffWord95}
1828 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06]}
1829 @Chg{Version=[2],New=[Limited views of packages are not allowed in use clauses.
1830 Defined @i<named in a use clause> for use in other limited view rules (see
1831 @RefSecNum{Context Clauses - With Clauses}).],Old=[]}
1832 @end{DiffWord95}
1833
1834
1835 @LabeledClause{Renaming Declarations}
1836
1837 @begin{Intro}
1838 @redundant[A @nt{renaming_declaration} declares another name for an entity,
1839 such as an object, exception, package, subprogram, entry,
1840 or generic unit.
1841 Alternatively, a @nt{subprogram_renaming_declaration} can be the
1842 completion of a previous @nt{subprogram_declaration}.]
1843
1844 @ChgToGlossary{Version=[2],Kind=[Added],Term=<Renaming>,
1845 Text=<@ChgAdded{Version=[2],Text=[A @nt{renaming_declaration} is a declaration
1846 that does not define a new entity, but instead defines a view of an existing
1847 entity.]}>}
1848
1849 @end{Intro}
1850
1851 @begin{Syntax}
1852 @Syn{lhs=<renaming_declaration>,rhs="
1853 @Syn2{object_renaming_declaration}
1854 | @Syn2{exception_renaming_declaration}
1855 | @Syn2{package_renaming_declaration}
1856 | @Syn2{subprogram_renaming_declaration}
1857 | @Syn2{generic_renaming_declaration}"}
1858 @end{Syntax}
1859
1860 @begin{RunTime}
1861 @PDefn2{Term=[elaboration], Sec=(renaming_declaration)}
1862 The elaboration of a @nt{renaming_declaration} evaluates the @nt{name} that
1863 follows the reserved word @key{renames} and thereby determines the
1864 view and entity denoted by this name
1865 @Defn{renamed view}
1866 @Defn{renamed entity}
1867 (the @i{renamed view} and @i{renamed entity}).
1868 @Redundant[A @nt{name} that denotes the @nt{renaming_declaration}
1869 denotes (a new view of) the renamed entity.]
1870 @end{RunTime}
1871
1872 @begin{Notes}
1873 Renaming may be used to resolve name conflicts and to act as a
1874 shorthand. Renaming with a different @nt{identifier} or
1875 @nt{operator_symbol} does not hide the old @nt{name}; the new
1876 @nt{name} and the old @nt{name} need not be visible at the same
1877 places.
1878
1879 A task or protected object that is declared by an explicit
1880 @nt{object_declaration} can be renamed as an object. However, a
1881 single task or protected object cannot be renamed since the
1882 corresponding type is anonymous (meaning it has no nameable subtypes).
1883 For similar reasons, an object of an anonymous array or access type
1884 cannot be renamed.
1885
1886 @leading@keepnext@;A subtype defined without any additional constraint
1887 can be used to achieve the effect of renaming another subtype
1888 (including a task or protected subtype) as in
1889 @begin{Example}
1890 @key[subtype] Mode @key[is] Ada.Text_IO.File_Mode;
1891 @end{Example}
1892 @end{Notes}
1893
1894 @begin{DiffWord83}
1895 The second sentence of RM83-8.5(3),
1896 @lquotes@;At any point where a renaming declaration is visible,
1897 the identifier, or operator symbol of this declaration denotes the
1898 renamed entity.@rquotes@; is incorrect. It doesn't say directly visible.
1899 Also, such an @nt{identifier} might resolve to something else.
1900
1901 The verbiage about renamings being legal @lquotes@;only if exactly one...@rquotes@;,
1902 which appears in RM83-8.5(4) (for objects) and RM83-8.5(7) (for subprograms) is
1903 removed, because it follows from the normal rules about overload resolution.
1904 For language lawyers, these facts are obvious; for programmers, they are
1905 irrelevant, since failing these tests is highly unlikely.
1906 @end{DiffWord83}
1907
1908
1909 @LabeledSubClause{Object Renaming Declarations}
1910
1911 @begin{Intro}
1912 @redundant[An @nt{object_renaming_declaration} is used to rename an object.]
1913 @end{Intro}
1914
1915 @begin{Syntax}
1916 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00423-01]}
1917 @Syn{lhs=<object_renaming_declaration>,rhs="@Chg{Version=[2],New=[
1918 ],Old=[]}@Syn2{defining_identifier} : @Chg{Version=[2],New=<[@Syn2{null_exclusion}] >,Old=<>}@Syn2{subtype_mark} @key{renames} @SynI{object_}@Syn2{name};@Chg{Version=[2],New=[
1919 | @Syn2{defining_identifier} : @Syn2{access_definition} @key{renames} @SynI{object_}@Syn2{name};],Old=[]}"}
1920 @end{Syntax}
1921
1922 @begin{Resolution}
1923
1924 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
1925 The type of the @SynI{object_}@nt{name} shall resolve to
1926 the type determined by the @nt{subtype_mark}@Chg{Version=[2],New=[,
1927 or in the case where the type is defined by an @nt{access_definition}, to an
1928 anonymous access type. If the anonymous access type is an access-to-object type,
1929 the type of the @SynI{object_}@nt{name}
1930 shall have the same designated type as that of the @nt{access_definition}.
1931 If the anonymous access type is an access-to-subprogram type,
1932 the type of the @SynI{object_}@nt{name} shall have a designated profile
1933 that is type conformant with that of the @nt{access_definition}],Old=[]}.
1934
1935 @begin{Reason}
1936 @leading@;A previous version of Ada 9X used the usual
1937 @lquotes@;expected type@rquotes@; wording:@*
1938 @lquotes@;The expected type for the @SynI{object_}@nt{name} is
1939 that determined by the @nt{subtype_mark}.@rquotes@;@*
1940 We changed it so that this would be illegal:
1941 @begin{Example}
1942 X: T;
1943 Y: T'Class @key[renames] X; --@RI{ Illegal!}
1944 @end{Example}
1945
1946 @leading@;When the above was legal, it was unclear whether Y
1947 was of type T or T'Class.
1948 Note that we still allow this:
1949 @begin{Example}
1950 Z: T'Class := ...;
1951 W: T @key[renames] F(Z);
1952 @end{Example}
1953
1954 where F is a function with a controlling parameter and result.
1955 This is admittedly a bit odd.
1956
1957 Note that the matching rule for generic formal parameters of mode
1958 @key[in out] was changed to keep it consistent with the rule
1959 for renaming.
1960 That makes the rule different for @key[in] vs. @key[in out].
1961
1962 @end{Reason}
1963 @end{Resolution}
1964
1965 @begin{Legality}
1966 The renamed entity shall be an object.
1967
1968 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01],ARef=[AI95-00409-01]}
1969 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[In the case
1970 where the type is defined by an @nt{access_definition},
1971 the type of the renamed object and the type defined by the
1972 @nt{access_definition}:]}
1973 @begin{Itemize}
1974 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00231-01],ARef=[AI95-00409-01]}
1975 @ChgAdded{Version=[2],Text=[shall both be access-to-object types with
1976 statically matching designated subtypes and with both or neither being
1977 access-to-constant types; or
1978 @PDefn2{Term=[statically matching],Sec=(required)}]}
1979
1980 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00409-01]}
1981 @ChgAdded{Version=[2],Text=[shall both be access-to-subprogram types with
1982 subtype conformant designated profiles.
1983 @Defn2{Term=[subtype conformance],Sec=(required)}]}
1984 @end{Itemize}
1985
1986 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00423-01]}
1987 @ChgAdded{Version=[2],Type=[Leading],Text=[For an
1988 @nt{object_renaming_declaration} with a @nt{null_exclusion} or an
1989 @nt{access_definition} that has a @nt{null_exclusion}:]}
1990
1991 @begin{Itemize}
1992 @ChgRef{Version=[2],Kind=[Added]}
1993 @ChgAdded{Version=[2],Text=[if the @Syni{object_}@nt{name} denotes a
1994 generic formal object of a generic unit @i{G}, and the
1995 @nt{object_renaming_declaration} occurs within the body of @i{G} or within
1996 the body of a generic unit declared within the declarative region of @i{G},
1997 then the declaration of the formal object of @i{G} shall have a
1998 @nt{null_exclusion};]}
1999
2000 @ChgRef{Version=[2],Kind=[Added]}
2001 @ChgAdded{Version=[2],Text=[otherwise, the subtype of the
2002 @Syni{object_}@nt{name} shall exclude null.
2003 @PDefn{generic contract issue}
2004 In addition to the places where @LegalityTitle normally apply
2005 (see @RefSecNum{Generic Instantiation}),
2006 this rule applies also in the private part of an
2007 instance of a generic unit.]}
2008
2009 @begin{Reason}
2010 @ChgRef{Version=[2],Kind=[AddedNormal]}
2011 @ChgAdded{Version=[2],Type=[Leading],Text=[This rule prevents
2012 @lquotes@;lying@rquotes.
2013 @b<Null> must never be the value of an object with an explicit
2014 @nt{null_exclusion}. The first bullet is an assume-the-worst rule
2015 which prevents trouble in one obscure case:]}
2016 @begin{Example}
2017 @ChgRef{Version=[2],Kind=[AddedNormal]}
2018 @ChgAdded{Version=[2],Text=[@key{type} Acc_I @key{is access} Integer;
2019 @key{subtype} Acc_NN_I @key{is not null} Acc_I;
2020 Obj : Acc_I := @key{null};]}
2021
2022 @ChgRef{Version=[2],Kind=[AddedNormal]}
2023 @ChgAdded{Version=[2],Text=[@key{generic}
2024 B : @key{in out} Acc_NN_I;
2025 @key{package} Gen @key{is}
2026 ...
2027 @key{end} Gen;]}
2028
2029 @ChgRef{Version=[2],Kind=[AddedNormal]}
2030 @ChgAdded{Version=[2],Text=[@key{package body} Gen @key{is}
2031 D : @key{not null} Acc_I @key{renames} B;
2032 @key{end} Gen;]}
2033
2034 @ChgRef{Version=[2],Kind=[AddedNormal]}
2035 @ChgAdded{Version=[2],Text=[@key{package} Inst @key{is new} Gen (B => Obj);]}
2036 @end{Example}
2037 @ChgRef{Version=[2],Kind=[AddedNormal]}
2038 @ChgAdded{Version=[2],Text=[Without the first bullet rule, D would
2039 be legal, and contain the value @key{null}, because the rule about lying
2040 is satisfied for generic matching (Obj matches B; B does not explicitly
2041 state @key{not null}),
2042 @LegalityTitle are not rechecked in the body of any instance, and the
2043 template passes the lying rule as well. The rule is so complex because it
2044 has to apply to formals used in bodies of child generics as well as in
2045 the bodies of generics.]}
2046 @end{Reason}
2047 @end{Itemize}
2048
2049 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0017],ARef=[AI95-00184-01]}
2050 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00363-01]}
2051 The renamed entity shall not be a subcomponent that depends on
2052 discriminants of a variable whose nominal subtype is unconstrained,
2053 unless this subtype is indefinite, or the variable is @Chg{Version=[2],
2054 New=[constrained by its initial value],Old=[aliased]}.
2055 A @nt{slice} of an array shall not be renamed if
2056 this restriction disallows renaming of the array.
2057 @Chg{New=[In addition to the places where Legality Rules normally apply, these
2058 rules apply also in the private part of an instance of a generic unit. These
2059 rules also apply for a renaming that appears in the body of a generic unit,
2060 with the additional requirement that even if the nominal subtype of the
2061 variable is indefinite, its type shall not be a descendant of an untagged
2062 generic formal derived type.],Old=[]}
2063 @begin{Reason}
2064 This prevents renaming of subcomponents that might
2065 disappear, which might leave dangling references.
2066 Similar restrictions exist for the Access attribute.
2067
2068 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0017],ARef=[AI95-00184-01]}
2069 @ChgAdded{Version=[1],Type=[Leading],Text=[The @lquotes@;recheck on
2070 instantiation@rquotes@; and @lquotes@;assume-the-worst in the body@rquotes@;
2071 restrictions on generics are necessary to avoid renaming of components which
2072 could disappear even when the nominal subtype would prevent the problem:]}
2073
2074 @begin{Example}
2075 @ChgRef{Version=[1],Kind=[Added]}
2076 @Chg{New=[@key{type} T1 (D1 : Boolean) @key{is}
2077 @key{record}
2078 @key{case} D1 @key{is}
2079 @key{when} False =>
2080 C1 : Integer;
2081 @key{when} True =>
2082 @key{null};
2083 @key{end} @key{case};
2084 @key{end} @key{record};],Old=[]}
2085
2086 @ChgRef{Version=[1],Kind=[Added]}
2087 @Chg{New=[@key{generic}
2088 @key{type} F @key{is} @key{new} T1;
2089 X : @key{in out} F;
2090 @key{package} G @key{is}
2091 C1_Ren : Integer @key{renames} X.C1;
2092 @key{end} G;],Old=[]}
2093
2094 @ChgRef{Version=[1],Kind=[Added]}
2095 @Chg{New=[@key{type} T2 (D2 : Boolean := False) @key{is} @key{new} T1 (D1 => D2);
2096 @Comment{Blank line}
2097 Y : T2;
2098 @Comment{Blank line}
2099 @key{package} I @key{is new} G (T2, Y);
2100 @Comment{Blank line}
2101 Y := (D1 => True); -- @RI[Oops! What happened to I.C1_Ren?]],Old=[]}
2102 @end{Example}
2103
2104
2105 @end{Reason}
2106 @begin{ImplNote}
2107 Note that if an implementation chooses to deallocate-then-reallocate
2108 on @nt{assignment_@!statement}s assigning to unconstrained definite objects,
2109 then it cannot represent renamings and access values as simple
2110 addresses, because the above rule does not apply to all components of
2111 such an object.
2112 @end{ImplNote}
2113 @begin{Ramification}
2114 If it is a generic formal object,
2115 then the assume-the-best or assume-the-worst rules are applied as
2116 appropriate.
2117 @end{Ramification}
2118 @begin{Honest}
2119 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
2120 @ChgAdded{Version=[2],Text=[If renamed entity is a subcomponent that
2121 depends on discriminants, and the subcomponent is a dereference of a
2122 general access type whose designated type is unconstrained and whose
2123 discriminants have defaults, the renaming is illegal. Such a
2124 general access type can designate an unconstrained (stack) object.
2125 Since such a type might not designate an object
2126 constrained by its initial value, the renaming is illegal @em the rule
2127 says @lquotes@;is@rquotes constrained by its initial value, not
2128 @lquotes@;might be@rquotes constrained by its initial value.
2129 No other interpretation makes sense, as we can't have legality depending
2130 on something (which object is designated) that is not known at
2131 compile-time, and we surely can't allow this for unconstrained objects.
2132 The wording of the rule
2133 should be much clearer on this point, but this was discovered after the
2134 completion of Amendment 1 when it was too late to fix it.]}
2135 @end{Honest}
2136 @end{Legality}
2137
2138 @begin{StaticSem}
2139 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00409-01]}
2140 An @nt{object_renaming_declaration} declares a new view
2141 @Redundant{of the renamed object} whose
2142 properties are identical to those of the renamed view.
2143 @Redundant[Thus, the properties of the renamed object are not affected by the
2144 @nt{renaming_declaration}.
2145 In particular, its value and whether or not it is a constant
2146 are unaffected; similarly, the@Chg{Version=[2],New=[ null exclusion or],Old=[]}
2147 constraints that apply to an object are
2148 not affected by renaming (any constraint implied by the
2149 @nt{subtype_mark} @Chg{Version=[2],New=[or @nt{access_definition} ],Old=[]}of
2150 the @nt{object_renaming_declaration} is ignored).]
2151 @begin{Discussion}
2152 Because the constraints are ignored,
2153 it is a good idea
2154 to use the nominal subtype of the renamed object
2155 when writing an @nt{object_renaming_declaration}.
2156
2157 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]}
2158 @ChgAdded{Version=[2],Text=[If no @nt{null_exclusion} is given in the
2159 renaming, the
2160 object may or may not exclude null. This is similar to the way that
2161 constraints need not match, and @key{constant} is not specified. The
2162 renaming defines a view of the
2163 renamed entity, inheriting the original properties.]}
2164 @end{Discussion}
2165 @end{StaticSem}
2166
2167 @begin{Examples}
2168 @leading@keepnext@i{Example of renaming an object:}
2169 @begin{Example}
2170 @key[declare]
2171 L : Person @key[renames] Leftmost_Person; --@RI{ see @RefSecNum{Incomplete Type Declarations}}
2172 @key[begin]
2173 L.Age := L.Age + 1;
2174 @key[end];
2175 @end{Example}
2176 @end{Examples}
2177
2178 @begin{DiffWord83}
2179 The phrase @lquotes@;subtype ... as defined in a corresponding
2180 object declaration, component declaration, or component subtype
2181 indication,@rquotes@; from RM83-8.5(5), is incorrect in Ada 95;
2182 therefore we removed it.
2183 It is incorrect in the case of an object with an indefinite
2184 unconstrained nominal subtype.
2185 @end{DiffWord83}
2186
2187 @begin{Incompatible95}
2188 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00363-01]}
2189 @ChgAdded{Version=[2],Type=[Leading],Text=[@Leading@;@Defn{incompatibilities with Ada 95}
2190 Aliased variables are not necessarily constrained in Ada
2191 2005 (see @RefSecNum{Array Types}). Therefore, a subcomponent of an aliased
2192 variable may disappear or change shape, and renaming such a subcomponent thus
2193 is illegal, while the same operation would have been legal in Ada 95. Note that
2194 most allocated objects are still constrained by their initial value (see
2195 @RefSecNum{Allocators}), and thus have no change in the
2196 legality of renaming for them. For example,
2197 using the type T2 of the previous example:]}
2198 @begin{Example}
2199 @ChgRef{Version=[2],Kind=[AddedNormal]}
2200 @ChgAdded{Version=[2],Text=[ AT2 : @key{aliased} T2;
2201 C1_Ren : Integer @key{renames} AT2.C1; -- @RI[Illegal in Ada 2005, legal in Ada 95]
2202 AT2 := (D1 => True); -- @RI[Raised Constraint_Error in Ada 95,]
2203 -- @RI[but does not in Ada 2005, so C1_Ren becomes]
2204 -- @RI[invalid when this is assigned.]]}
2205 @end{Example}
2206 @end{Incompatible95}
2207
2208 @begin{Extend95}
2209 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
2210 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2211 A renaming can have an anonymous access type. In that case, the accessibility
2212 of the renaming is that of the original object (accessibility is not
2213 lost as it is for a component or stand-alone object).]}
2214
2215 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01],ARef=[AI95-00423-01]}
2216 @ChgAdded{Version=[2],Text=[A renaming can have a @nt{null_exclusion}; if so,
2217 the renamed object must also exclude null, so that the @nt{null_exclusion}
2218 does not lie. On the other hand, if the renaming does not have a
2219 @nt{null_exclusion}. it excludes null of the renamed object does.]}
2220 @end{Extend95}
2221
2222 @begin{DiffWord95}
2223 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0017],ARef=[AI95-00184-01]}
2224 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Fixed to forbid renamings of
2225 depends-on-discriminant components if the type @i{might} be definite.]}
2226 @end{DiffWord95}
2227
2228
2229 @LabeledSubClause{Exception Renaming Declarations}
2230
2231 @begin{Intro}
2232 @redundant[An @nt{exception_renaming_declaration} is used to rename an exception.]
2233 @end{Intro}
2234
2235 @begin{Syntax}
2236 @Syn{lhs=<exception_renaming_declaration>,rhs="@Syn2{defining_identifier} : @key{exception} @key{renames} @SynI{exception_}@Syn2{name};"}
2237 @end{Syntax}
2238
2239 @begin{Legality}
2240 The renamed entity shall be an exception.
2241 @end{Legality}
2242
2243 @begin{StaticSem}
2244 An @nt{exception_renaming_declaration} declares a new view
2245 @Redundant{of the renamed exception}.
2246 @end{StaticSem}
2247
2248 @begin{Examples}
2249 @leading@keepnext@i{Example of renaming an exception:}
2250 @begin{Example}
2251 EOF : @key[exception] @key[renames] Ada.IO_Exceptions.End_Error; @RI{-- see @RefSecNum{Exceptions in Input-Output}}
2252 @end{Example}
2253 @end{Examples}
2254
2255
2256 @LabeledSubClause{Package Renaming Declarations}
2257
2258 @begin{Intro}
2259 @redundant[A @nt{package_renaming_declaration} is used to rename a package.]
2260 @end{Intro}
2261
2262 @begin{Syntax}
2263 @Syn{lhs=<package_renaming_declaration>,rhs="@key{package} @Syn2{defining_program_unit_name} @key{renames} @SynI{package_}@Syn2{name};"}
2264 @end{Syntax}
2265
2266 @begin{Legality}
2267 The renamed entity shall be a package.
2268
2269 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
2270 @ChgAdded{Version=[2],Text=[If the @SynI{package_}@nt{name} of a
2271 @nt{package_renaming_declaration} denotes a limited view of a package @i{P},
2272 then a name that denotes the @nt{package_renaming_declaration} shall occur
2273 only within the immediate scope of the renaming or the scope of a
2274 @nt{with_clause} that mentions the package @i{P} or, if @i{P} is a nested
2275 package, the innermost library package enclosing @i{P}.]}
2276 @begin{Discussion}
2277 @ChgRef{Version=[2],Kind=[Added]}
2278 @ChgAdded{Version=[2],Text=[The use of a renaming that designates a limited
2279 view is restricted to locations where we know whether the view is limited
2280 or nonlimited (based on a @nt{with_clause}). We don't want to make an
2281 implicit limited view, as those are not transitive like a regular view.
2282 Implementations should be able to see all limited views needed based on the
2283 @nt{context_clause}.]}
2284 @end{Discussion}
2285 @end{Legality}
2286
2287 @begin{StaticSem}
2288 A @nt{package_renaming_declaration} declares a new view
2289 @Redundant{of the renamed package}.
2290
2291 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00412-01]}
2292 @ChgAdded{Version=[2],Text=[@Redundant[At places where the declaration of the
2293 limited view of the renamed package is visible, a @nt{name} that denotes the
2294 @nt{package_renaming_declaration} denotes a limited view of the package (see
2295 @RefSecNum{Compilation Units - Library Units}).]]}
2296 @begin{TheProof}
2297 @ChgRef{Version=[2],Kind=[Added]}
2298 @ChgAdded{Version=[2],Text=[This rule is found in @RefSec{Visibility}.]}
2299 @end{TheProof}
2300 @end{StaticSem}
2301
2302 @begin{Examples}
2303 @leading@keepnext@i{Example of renaming a package:}
2304 @begin{Example}
2305 @key[package] TM @key[renames] Table_Manager;
2306 @end{Example}
2307 @end{Examples}
2308
2309 @begin{DiffWord95}
2310 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00217-06],ARef=[AI95-00412-01]}
2311 @ChgAdded{Version=[2],Text=[Uses of renamed limited views of packages can
2312 only be used within the scope of a with_clause for the renamed package.]}
2313 @end{DiffWord95}
2314
2315
2316 @LabeledSubClause{Subprogram Renaming Declarations}
2317
2318 @begin{Intro}
2319 A @nt{subprogram_renaming_declaration} can serve as the completion of
2320 a @nt{subprogram_declaration};
2321 @Defn{renaming-as-body}
2322 such a @nt{renaming_declaration} is called a @i{renaming-as-body}.
2323 @Defn{renaming-as-declaration}
2324 A @nt{subprogram_renaming_declaration} that is not a completion is
2325 called a @i{renaming-as-declaration}@Redundant[,
2326 and is used to rename a subprogram
2327 (possibly an enumeration literal) or an entry].
2328 @begin{Ramification}
2329 A renaming-as-body is a declaration,
2330 as defined in Section 3.
2331 @end{Ramification}
2332 @end{Intro}
2333
2334 @begin{Syntax}
2335 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]}
2336 @Syn{lhs=<subprogram_renaming_declaration>,rhs="@Chg{Version=[2],New=<
2337 [@Syn2{overriding_indicator}]
2338 >,Old=<>}@Syn2{subprogram_specification} @key{renames} @SynI{callable_entity_}@Syn2{name};"}
2339 @end{Syntax}
2340
2341 @begin{Resolution}
2342 @PDefn2{Term=[expected profile],
2343 Sec=(subprogram_renaming_declaration)}
2344 The expected profile for the @i(callable_entity_)@nt<name>
2345 is the profile given in the @nt<subprogram_specification>.
2346 @end{Resolution}
2347
2348 @begin{Legality}
2349 The profile of a renaming-as-declaration
2350 shall be mode-conformant with that of the renamed callable entity.
2351 @Defn2{Term=[mode conformance],Sec=(required)}
2352
2353 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00423-01]}
2354 @ChgAdded{Version=[2],Type=[Leading],Text=[For a parameter or result subtype of
2355 the @nt{subprogram_specification} that has an explicit @nt{null_exclusion}:]}
2356
2357 @begin{Itemize}
2358 @ChgRef{Version=[2],Kind=[Added]}
2359 @ChgAdded{Version=[2],Text=[if the @Syni{callable_entity_}@nt{name}
2360 denotes a generic formal subprogram of
2361 a generic unit @i{G}, and the @nt{subprogram_renaming_declaration} occurs
2362 within the body of a generic unit @i{G} or within the body of a generic unit
2363 declared within the declarative region of the generic unit @i{G}, then the
2364 corresponding parameter or result subtype of the formal subprogram of @i{G}
2365 shall have a @nt{null_exclusion};]}
2366
2367 @ChgRef{Version=[2],Kind=[Added]}
2368 @ChgAdded{Version=[2],Text=[otherwise, the subtype of the corresponding
2369 parameter or result type of the renamed callable entity shall exclude null.
2370 @PDefn{generic contract issue}
2371 In addition to the places where @LegalityTitle normally apply
2372 (see @RefSecNum{Generic Instantiation}),
2373 this rule applies also in the private part of an
2374 instance of a generic unit.]}
2375 @end{Itemize}
2376
2377 @begin{Reason}
2378 @ChgRef{Version=[2],Kind=[AddedNormal]}
2379 @ChgAdded{Version=[2],Type=[Leading],Text=[This rule prevents
2380 @lquotes@;lying@rquotes.
2381 @b<Null> must never be the value of a parameter or result with an explicit
2382 @nt{null_exclusion}. The first bullet is an assume-the-worst rule
2383 which prevents trouble in generic bodies (including bodies of child
2384 units) when the formal subtype excludes null implicitly.]}
2385 @end{Reason}
2386
2387 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0027],Ref=[8652/0028],ARef=[AI95-00135-01],ARef=[AI95-00145-01]}
2388 The profile of a renaming-as-body
2389 @Chg{New=[],Old=[shall be subtype-conformant with that of the renamed
2390 callable entity, and ]}shall conform fully to that of the declaration it
2391 completes.
2392 @Defn2{Term=[full conformance],Sec=(required)}
2393 If the renaming-as-body completes that declaration
2394 before the subprogram it declares is frozen,
2395 @Chg{New=[the profile shall be mode-conformant
2396 @Defn2{Term=[mode conformance],Sec=(required)}with that of the renamed
2397 callable entity and ],Old=[]}the subprogram it declares
2398 takes its convention from the renamed subprogram;
2399 otherwise@Chg{New=[, the profile shall be subtype-conformant with that of the
2400 renamed callable entity and],Old=[]} the convention of the renamed subprogram
2401 shall not be Intrinsic.
2402 @Defn2{Term=[subtype conformance],Sec=(required)}
2403 @Chg{New=[A renaming-as-body is illegal if the declaration occurs before the
2404 subprogram whose declaration it completes is frozen, and the renaming renames
2405 the subprogram itself, through one or more subprogram renaming declarations,
2406 none of whose subprograms has been frozen.],Old=[]}
2407 @begin{Reason}
2408 @ChgRef{Version=[1],Kind=[Revised]}
2409 The @Chg{New=[otherwise part of the second sentence],Old=[first part of the first sentence]}
2410 is to allow an implementation of a renaming-as-body
2411 as a single jump instruction to the target subprogram.
2412 Among other things, this prevents a subprogram from being completed with
2413 a renaming of an entry.
2414 (In most cases, the target of the jump can be filled in at link time.
2415 In some cases, such as a renaming of a name like "A(I).@key[all]", an indirect
2416 jump is needed. Note that the name is evaluated at renaming time, not at
2417 call time.)
2418
2419 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0028],ARef=[AI95-00145-01]}
2420 @Chg{New=[The first part of the second sentence is intended to allow
2421 renaming-as-body of predefined operators before the @nt{subprogram_declaration}
2422 is frozen. For some types (such as integer types), the parameter type for
2423 operators is the base type, and it would be very strange for@*
2424 @f{@ @ @ @key{function} Equal (A, B : @key{in} T) @key{return} Boolean;}@*
2425 @f{@ @ @ @key{function} Equal (A, B : @key{in} T) @key{return} Boolean @key{renames} "=";}@*
2426 to be illegal. (Note that predefined operators cannot be renamed this way
2427 after the @nt{subprogram_declaration} is frozen, as they have convention
2428 Intrinsic.)],Old=[]}
2429
2430 @ChgRef{Version=[1],Kind=[Revised]}
2431 The @Chg{New=[],Old=[second part of the ]}first sentence is
2432 the normal rule for completions of @nt{subprogram_declaration}s.
2433 @end{Reason}
2434 @begin{Ramification}
2435 An @nt{entry_declaration}, unlike a @nt{subprogram_declaration},
2436 cannot be completed with a @nt{renaming_@!declaration}.
2437 Nor can a @nt{generic_@!subprogram_@!declaration}.
2438
2439 The syntax rules prevent a protected subprogram declaration from being
2440 completed by a renaming.
2441 This is fortunate, because it allows us to avoid worrying about whether
2442 the implicit protected object parameter of a protected operation is
2443 involved in the conformance rules.
2444 @end{Ramification}
2445 @begin{Reason}
2446 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2447 @ChgAdded{Version=[1],Text=[Circular renames before freezing is illegal, as the compiler
2448 would not be able to determine the convention of the subprogram. Other
2449 circular renames are handled below; see @BoundedTitle.]}
2450 @end{Reason}
2451
2452 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2453 @ChgAdded{Version=[2],Text=[The @Syni{callable_entity_}@nt{name} of a renaming
2454 shall not denote a subprogram that requires overriding
2455 (see @RefSecNum{Abstract Types and Subprograms}).]}
2456 @begin{Reason}
2457 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2458 @ChgAdded{Version=[2],Text=[Such a rename cannot be of the inherited subprogram
2459 (which requires overriding because it cannot be called),
2460 and thus cannot squirrel away a subprogram (see below). That would be
2461 confusing, so we make it illegal. The renaming is allowed after the
2462 overriding, as then the @nt{name} will denote the overriding subprogram,
2463 not the inherited one.]}
2464 @end{Reason}
2465
2466 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2467 @ChgAdded{Version=[2],Text=[The @Syni{callable_entity_}@nt{name} of a
2468 renaming-as-body shall not denote an abstract subprogram.]}
2469 @begin{Reason}
2470 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00228-01]}
2471 @ChgAdded{Version=[2],Text=[Such a subprogram has no body, so it hardly
2472 can replace one in the program.]}
2473 @end{Reason}
2474
2475 A @nt{name} that denotes a formal parameter
2476 of the @nt{subprogram_specification}
2477 is not allowed within the @Syni{callable_entity_}@nt{name}.
2478 @begin{Reason}
2479 @leading@keepnext@;This is to prevent things like this:
2480 @begin{Example}
2481 @key[function] F(X : Integer) @key[return] Integer @key[renames] Table(X).@key[all];
2482 @end{Example}
2483
2484 @begin{Wide}
2485 @leading@;A similar rule in @RefSecNum{Subprogram Declarations}
2486 forbids things like this:
2487 @end{Wide}
2488 @begin{Example}
2489 @key[function] F(X : Integer; Y : Integer := X) @key[return] Integer;
2490 @end{Example}
2491 @end{Reason}
2492 @end{Legality}
2493
2494 @begin{StaticSem}
2495 A renaming-as-declaration
2496 declares a new view of the renamed entity.
2497 The profile of this new view takes its subtypes, parameter modes,
2498 and calling convention from the original profile of the
2499 callable entity, while taking the formal parameter
2500 @nt{name}s and @nt{default_expression}s from the profile given in the
2501 @nt{subprogram_renaming_declaration}.
2502 The new view is a function or procedure, never an entry.
2503 @begin{Honest}
2504 When renaming an entry as a procedure,
2505 the compile-time rules apply as if the new view is a procedure,
2506 but the run-time semantics of a call are that of an entry call.
2507 @end{Honest}
2508 @begin{Ramification}
2509 For example, it is illegal for the @nt{entry_call_statement} of a
2510 @nt{timed_entry_call} to call the new view.
2511 But what looks like a procedure call will do things like barrier
2512 waiting.
2513
2514 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0105],ARef=[AI95-00211-01]}
2515 @ChgRef{Version=[2],Kind=[RevisedAdded],ARef=[AI95-00228-01]}
2516 @Chg{New=[All properties of the renamed entity are inherited by the new view
2517 unless otherwise stated by this International Standard. In particular, if the
2518 renamed entity is abstract@Chg{Version=[2],New=[],Old=[ or requires
2519 overriding (see @RefSecNum{Abstract Types and Subprograms})]}, the new view
2520 also is abstract@Chg{Version=[2],New=[.],Old=[ or requires overriding. (The
2521 renaming will often be illegal in these cases,
2522 as a renaming cannot be overridden.)]}],Old=[]}
2523 @end{Ramification}
2524 @end{StaticSem}
2525
2526 @begin{RunTime}
2527 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0014],ARef=[AI95-00064-01]}
2528 @Chg{New=[For a call to a subprogram whose body is given as a renaming-as-body,
2529 the execution of the renaming-as-body is equivalent to the execution of a
2530 @nt{subprogram_body} that simply calls the renamed subprogram with its formal
2531 parameters as the actual parameters and, if it is a function, returns the
2532 value of the call.],Old=[]}
2533 @begin{Ramification}
2534 @ChgRef{Version=[1],Kind=[Added]}
2535 @ChgAdded{Version=[1],Text=[This implies that the subprogram completed by the
2536 renaming-as-body has its own elaboration check.]}
2537 @end{Ramification}
2538
2539 For a call on a renaming of a dispatching subprogram that is overridden,
2540 if the overriding occurred before the renaming, then the body executed
2541 is that of the overriding declaration,
2542 even if the overriding declaration is not visible at the place of the renaming;
2543 otherwise, the inherited or predefined subprogram is called.
2544 @begin{Discussion}
2545 Note that whether or not the renaming is itself primitive has
2546 nothing to do with the renamed subprogram.
2547
2548 Note that the above rule is only for tagged types.
2549
2550 @leading@keepnext@;Consider the following example:
2551 @begin{Example}
2552 @key[package] P @key[is]
2553 @key[type] T @key[is] @key[tagged] @key[null] @key[record];
2554 @key[function] Predefined_Equal(X, Y : T) @key[return] Boolean @key[renames] "=";
2555 @key[private]
2556 @key[function] "="(X, Y : T) @key[return] Boolean; --@RI{ Override predefined "=".}
2557 @key[end] P;
2558
2559 @key[with] P; @key[use] P;
2560 @key[package] Q @key[is]
2561 @key[function] User_Defined_Equal(X, Y : T) @key[return] Boolean @key[renames] P."=";
2562 @key[end] Q;
2563 @end{Example}
2564
2565 A call on Predefined_Equal will execute the predefined equality operator
2566 of T, whereas a call on User_Defined_Equal will execute the body of the
2567 overriding declaration in the private part of P.
2568
2569 Thus a renaming allows one to squirrel away a copy of an inherited or
2570 predefined subprogram before later overriding it.@Defn{squirrel away}
2571 @end{Discussion}
2572 @end{RunTime}
2573
2574 @begin{Bounded}
2575 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2576 @ChgAdded{Version=[1],Text=[@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
2577 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
2578 If a subprogram directly or indirectly renames itself, then it is a bounded
2579 error to call that subprogram. Possible consequences are that Program_Error or
2580 Storage_Error is raised, or that the call results in infinite recursion.]}
2581 @begin{Reason}
2582 @ChgRef{Version=[1],Kind=[Added],Ref=[8652/0027],ARef=[AI95-00135-01]}
2583 @ChgAdded{Version=[1],Text=[This has to be a bounded error, as it is possible
2584 for a renaming-as-body appearing in a package body to cause this problem.
2585 Thus it is not possible in general to detect this problem at compile time.]}
2586 @end{Reason}
2587 @end{Bounded}
2588
2589 @begin{Notes}
2590 A procedure can only be renamed as a procedure.
2591 A function whose @nt{defining_designator} is either an
2592 @nt{identifier} or an @nt{operator_symbol}
2593 can be renamed with either an
2594 @nt{identifier} or an @nt{operator_symbol};
2595 for renaming as an operator, the subprogram specification given in
2596 the @nt{renaming_declaration} is subject to the rules given in
2597 @RefSecNum{Overloading of Operators}
2598 for operator declarations. Enumeration literals can be
2599 renamed as functions; similarly, @nt{attribute_reference}s that
2600 denote functions (such as references to Succ and Pred) can be renamed
2601 as functions. An entry can only be renamed as a procedure; the new
2602 @nt{name} is only allowed to appear in contexts that allow a
2603 procedure @nt{name}. An entry of a family can be renamed, but an
2604 entry family cannot be renamed as a whole.
2605
2606
2607 The operators of the root numeric types cannot be renamed because the
2608 types in the profile are anonymous, so the corresponding specifications
2609 cannot be written; the same holds for certain attributes, such as Pos.
2610
2611
2612 Calls with the new @nt{name} of a renamed entry are
2613 @nt{procedure_call_statement}s and are not allowed at places
2614 where the syntax requires an @nt{entry_call_statement} in
2615 @ntf{conditional_} and @nt{timed_entry_call}s,
2616 nor in an @nt{asynchronous_select}; similarly, the Count
2617 attribute is not available for the new @nt{name}.
2618
2619 The primitiveness of a renaming-as-declaration is determined by its
2620 profile, and by where it occurs, as for any declaration of
2621 (a view of) a subprogram;
2622 primitiveness is not determined by the renamed view.
2623 In order to perform a dispatching call,
2624 the subprogram name has to denote a primitive subprogram,
2625 not a non-primitive renaming of a primitive subprogram.
2626 @begin{Reason}
2627 A @nt{subprogram_renaming_declaration} could more properly be called
2628 @ntf{renaming_@!as_@!subprogram_@!declaration}, since you're renaming something
2629 as a subprogram, but you're not necessarily renaming a subprogram.
2630 But that's too much of a mouthful. Or, alternatively, we could call it a
2631 @ntf{callable_@!entity_@!renaming_@!declaration}, but that's even worse.
2632 Not only is it a mouthful, it emphasizes the entity being renamed,
2633 rather than the new view, which we think is a bad idea.
2634 We'll live with the oddity.
2635 @end{Reason}
2636 @end{Notes}
2637
2638 @begin{Examples}
2639 @leading@keepnext@i{Examples of subprogram renaming declarations:}
2640 @begin{Example}
2641 @key[procedure] My_Write(C : @key[in] Character) @key[renames] Pool(K).Write; --@RI{ see @RefSecNum{Selected Components}}
2642
2643 @key[function] Real_Plus(Left, Right : Real ) @key[return] Real @key[renames] "+";
2644 @key[function] Int_Plus (Left, Right : Integer) @key[return] Integer @key[renames] "+";
2645
2646 @key[function] Rouge @key[return] Color @key[renames] Red; --@RI{ see @RefSecNum{Enumeration Types}}
2647 @key[function] Rot @key[return] Color @key[renames] Red;
2648 @key[function] Rosso @key[return] Color @key[renames] Rouge;
2649
2650 @key[function] Next(X : Color) @key[return] Color @key[renames] Color'Succ; --@RI{ see @RefSecNum{Enumeration Types}}
2651 @end{Example}
2652
2653 @begin{Wide}
2654 @leading@keepnext@i{Example of a subprogram renaming declaration with new parameter names:}
2655 @end{Wide}
2656 @begin{Example}
2657 @key[function] "*" (X,Y : Vector) @key[return] Real @key[renames] Dot_Product; --@RI{ see @RefSecNum{Subprogram Declarations}}
2658 @end{Example}
2659
2660 @begin{Wide}
2661 @leading@keepnext@i{Example of a subprogram renaming declaration with a new default expression:}
2662 @end{Wide}
2663 @begin{Example}
2664 @key[function] Minimum(L : Link := Head) @key[return] Cell @key[renames] Min_Cell; --@RI{ see @RefSecNum{Subprogram Declarations}}
2665 @end{Example}
2666 @end{Examples}
2667
2668 @begin{Extend95}
2669 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0028],ARef=[AI95-00145-01]}
2670 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
2671 @b<Corrigendum:> Allowed a renaming-as-body to be just
2672 mode conformant with the specification if the subprogram is not yet frozen.]}
2673
2674 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]}
2675 @ChgAdded{Version=[2],Text=[@nt{Overriding_indicator} (see
2676 @RefSecNum{Overriding Indicators}) is
2677 optionally added to subprogram renamings.]}
2678 @end{Extend95}
2679
2680 @begin{DiffWord95}
2681 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0014],ARef=[AI95-00064-01]}
2682 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Described the semantics of
2683 renaming-as-body, so that the location of elaboration checks is clear.]}
2684
2685 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0027],ARef=[AI95-00135-01]}
2686 @ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that circular
2687 renaming-as-body is illegal (if it can be detected in time) or a
2688 bounded error.]}
2689
2690 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00228-01]}
2691 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:] Clarified that
2692 renaming a shall-be-overridden
2693 subprogram is illegal, as well as renaming-as-body an abstract subprogram.]}
2694
2695 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00423-01]}
2696 @ChgAdded{Version=[2],Text=[Added matching rules for @nt{null_exclusion}s.]}
2697 @end{DiffWord95}
2698
2699
2700 @LabeledSubClause{Generic Renaming Declarations}
2701
2702 @begin{Intro}
2703 @redundant[A @nt{generic_renaming_declaration} is used to rename a generic unit.]
2704 @end{Intro}
2705
2706 @begin{Syntax}
2707 @Syn{tabs=[P22], lhs=<generic_renaming_declaration>,rhs="
2708 @key{generic package}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_package_}@Syn2{name};
2709 | @key{generic procedure}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_procedure_}@Syn2{name};
2710 | @key{generic function}@\@Syn2{defining_program_unit_name} @key{renames} @SynI{generic_function_}@Syn2{name};"}
2711 @end{Syntax}
2712
2713 @begin{Legality}
2714 The renamed entity shall be a generic unit of the corresponding kind.
2715 @end{Legality}
2716
2717 @begin{StaticSem}
2718 A @nt{generic_renaming_declaration} declares a new view
2719 @Redundant{of the renamed generic unit}.
2720 @end{StaticSem}
2721
2722 @begin{Notes}
2723 Although the properties of the new view are the same as those of the
2724 renamed view, the place where the @nt<generic_renaming_declaration> occurs
2725 may affect the legality of subsequent renamings and instantiations
2726 that denote the @nt<generic_renaming_declaration>,
2727 in particular if the renamed generic unit is a library unit
2728 (see @RefSecNum{Compilation Units - Library Units}).
2729 @end{Notes}
2730
2731 @begin{Examples}
2732 @leading@keepnext@i{Example of renaming a generic unit:}
2733 @begin{Example}
2734 @key[generic package] Enum_IO @key[renames] Ada.Text_IO.Enumeration_IO; @RI{-- see @RefSecNum{Input-Output for Enumeration Types}}
2735 @end{Example}
2736 @end{Examples}
2737
2738 @begin{Extend83}
2739 @Defn{extensions to Ada 83}
2740 Renaming of generic units is new to Ada 95.
2741 It is particularly important for renaming child library
2742 units that are generic units. For example, it might
2743 be used to rename Numerics.Generic_Elementary_Functions as simply
2744 Generic_Elementary_Functions, to match the name for
2745 the corresponding Ada-83-based package.
2746 @end{Extend83}
2747
2748 @begin{DiffWord83}
2749 The information in RM83-8.6, @lquotes@;The Package Standard,@rquotes@;
2750 has been updated for the child unit feature,
2751 and moved to @RefSecNum{Predefined Language Environment},
2752 except for the definition of @lquotes@;predefined type,@rquotes@;
2753 which has been moved to @RefSecNum{Type Declarations}.
2754 @end{DiffWord83}
2755
2756 @LabeledClause{The Context of Overload Resolution}
2757
2758 @begin{Intro}
2759 @redundant[@Defn{overload resolution}
2760 Because declarations can be overloaded,
2761 it is possible for an occurrence of a usage name
2762 to have more than one possible interpretation;
2763 in most cases, ambiguity is disallowed.
2764 This clause describes how the possible interpretations resolve
2765 to the actual interpretation.
2766
2767 @Defn{overloading rules}
2768 Certain rules of the language (the @ResolutionTitle)
2769 are considered @lquotes@;overloading rules@rquotes@;.
2770 If a possible interpretation violates an overloading rule,
2771 it is assumed not to be the intended interpretation;
2772 some other possible interpretation
2773 is assumed to be the actual interpretation.
2774 On the other hand,
2775 violations of non-overloading rules do not affect which
2776 interpretation is chosen; instead,
2777 they cause the construct to be illegal.
2778 To be legal, there usually has to be exactly one acceptable
2779 interpretation of a construct that is a @lquotes@;complete context@rquotes@;,
2780 not counting any nested complete contexts.
2781
2782 @Defn2{Term=[grammar],Sec=(resolution of ambiguity)}
2783 The syntax rules of the language and the visibility rules
2784 given in @RefSecNum{Visibility}
2785 determine the possible interpretations.
2786 Most type checking rules
2787 (rules that require a particular type,
2788 or a particular class of types,
2789 for example)
2790 are overloading rules.
2791 Various rules for the matching of formal and actual parameters are
2792 overloading rules.]
2793 @end{Intro}
2794
2795 @begin{MetaRules}
2796 The type resolution rules are
2797 intended to minimize the need for implicit declarations
2798 and preference rules associated with implicit conversion and dispatching
2799 operations.
2800 @end{MetaRules}
2801
2802 @begin{Resolution}
2803 @leading@Defn{complete context}
2804 @Redundant{Overload resolution is applied separately to each
2805 @i{complete context},
2806 not counting inner complete contexts.}
2807 Each of the following constructs is a @i{complete context}:
2808 @begin{itemize}
2809 A @nt{context_item}.
2810
2811 A @nt{declarative_item} or declaration.
2812 @begin{Ramification}
2813 A @nt{loop_parameter_specification} is a declaration,
2814 and hence a complete context.
2815 @end{Ramification}
2816
2817 A @nt{statement}.
2818
2819 A @nt{pragma_argument_association}.
2820 @begin{Reason}
2821 We would make it the whole @nt{pragma},
2822 except that certain pragma arguments are allowed to be ambiguous,
2823 and ambiguity applies to a complete context.
2824 @end{Reason}
2825
2826 The @nt{expression} of a @nt{case_statement}.
2827 @begin{Ramification}
2828 This means that the @nt{expression} is resolved without looking
2829 at the choices.
2830 @end{Ramification}
2831 @end{itemize}
2832
2833 @leading@Defn2{Term=[interpretation], Sec=(of a complete context)}
2834 @Defn2{Term=[overall interpretation], Sec=(of a complete context)}
2835 An (overall) @i{interpretation} of a complete context
2836 embodies its meaning, and includes
2837 the following information about the constituents of the complete
2838 context,
2839 not including constituents of inner complete contexts:
2840 @begin{Itemize}
2841 for each constituent of the complete context,
2842 to which syntactic categories it belongs,
2843 and by which syntax rules; and
2844 @begin{Ramification}
2845 Syntactic categor@i{ies} is plural here,
2846 because there are lots of trivial productions @em
2847 an @nt{expression} might also be all of the following,
2848 in this order: @nt{identifier},
2849 @nt{name},
2850 @nt{primary},
2851 @nt{factor},
2852 @nt{term},
2853 @nt{simple_expression}, and
2854 @nt{relation}.
2855 Basically, we're trying to capture all the information in the parse tree
2856 here, without using compiler-writer's jargon like @lquotes@;parse tree@rquotes@;.
2857 @end{Ramification}
2858
2859 for each usage name, which declaration it denotes
2860 (and, therefore, which view and which entity it denotes); and
2861 @begin{Ramification}
2862 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
2863 In most cases, a usage name denotes the view declared by the denoted
2864 declaration.
2865 However, in certain cases, a usage name that denotes a declaration and
2866 appears inside the declarative region of that same declaration, denotes
2867 the current instance of the declaration.
2868 For example, within a @nt{task_body}@Chg{Version=[2],New=[ other than in
2869 an @nt{access_definition}],Old=[]}, a usage name that denotes the
2870 @nt{task_type_declaration} denotes the object containing the
2871 currently executing task,
2872 and not the task type declared by the declaration.
2873 @end{Ramification}
2874
2875 for a complete context that is a @nt{declarative_item},
2876 whether or not it is a completion of a declaration,
2877 and (if so) which declaration it completes.
2878 @end{Itemize}
2879 @begin{Ramification}
2880 Unfortunately, we are not confident that the above list is complete.
2881 We'll have to live with that.
2882 @end{Ramification}
2883 @begin{Honest}
2884 For @lquotes@;possible@rquotes@; interpretations, the above information is tentative.
2885 @end{Honest}
2886 @begin{Discussion}
2887 A possible interpretation (an @i{input} to overload
2888 resolution) contains information about what a
2889 usage name @i{might} denote, but what it actually @i{does} denote
2890 requires overload resolution to determine.
2891 Hence the term @lquotes@;tentative@rquotes@; is needed for possible interpretations;
2892 otherwise, the definition would be circular.
2893 @end{Discussion}
2894
2895 @Defn{possible interpretation}
2896 A @i{possible interpretation} is one
2897 that obeys the syntax rules and the visibility rules.
2898 @Defn{acceptable interpretation}
2899 @Defn2{Term=[resolve],Sec=(overload resolution)}
2900 @Defn2{Term=[interpretation],Sec=(overload resolution)}
2901 An @i{acceptable interpretation} is a possible interpretation that
2902 obeys the @i{overloading rules}@Redundant{,
2903 that is, those rules that specify an expected type or
2904 expected profile, or specify how a construct shall @i(resolve)
2905 or be @i(interpreted).}
2906 @begin{Honest}
2907 One rule that falls into this category,
2908 but does not use the above-mentioned magic words,
2909 is the rule about numbers of parameter associations in a call
2910 (see @RefSecNum{Subprogram Calls}).
2911 @end{Honest}
2912 @begin{Ramification}
2913 The @ResolutionName@;s are the ones that appear under the
2914 @ResolutionTitle heading.
2915 Some @SyntaxName@;s are written in English, instead of BNF.
2916 No rule is a @SyntaxName or @ResolutionName unless it appears under the
2917 appropriate heading.
2918 @end{Ramification}
2919
2920 @Defn2{Term=[interpretation], Sec=(of a constituent of a complete context)}
2921 The @i{interpretation} of a constituent of a complete context is
2922 determined from the overall interpretation of the complete context as a
2923 whole.
2924 @Redundant{Thus,
2925 for example, @lquotes@;interpreted as a @nt{function_call},@rquotes@;
2926 means that the construct's interpretation says that it belongs
2927 to the syntactic category @nt{function_call}.}
2928
2929 @leading@Defn{denote}
2930 @Redundant[Each occurrence of]
2931 a usage name @i{denotes} the declaration determined by its
2932 interpretation.
2933 It also denotes the view declared by its denoted
2934 declaration, except in the following cases:
2935 @begin{Ramification}
2936 As explained below, a pragma argument is allowed to be ambiguous,
2937 so it can denote several declarations,
2938 and all of the views declared by those declarations.
2939 @end{Ramification}
2940 @begin(itemize)
2941 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
2942 @Defn2{Term=[current instance], Sec=(of a type)}
2943 If a usage name appears within the declarative region of a
2944 @nt{type_declaration} and denotes that same @nt{type_declaration},
2945 then it denotes the @i{current instance} of the type (rather than
2946 the type itself)@Chg{Version=[2],New=[; the],Old=[. The]} current
2947 instance of a type is the object or value
2948 of the type that is associated with the execution that
2949 evaluates the usage name.@Chg{Version=[2],New=[ This rule does not apply
2950 if the usage name appears within the @nt{subtype_mark} of an
2951 @nt{access_definition} for an access-to-object type, or within the subtype
2952 of a parameter or result of an access-to-subprogram type.],Old=[]}
2953 @begin{Reason}
2954 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00382-01]}
2955 This is needed, for example, for references to the Access attribute
2956 from within the @nt{type_declaration}.
2957 Also, within a @nt{task_body} or @nt{protected_body},
2958 we need to be able to denote the current task or protected object.
2959 (For a @nt{single_task_declaration} or
2960 @nt{single_protected_declaration}, the rule about current instances
2961 is not needed.)@Chg{Version=[2],New=[ We exclude anonymous access types
2962 so that they can be used to create self-referencing types in the natural
2963 manner (otherwise such types would be illegal).],Old=[]}
2964 @end{Reason}
2965 @begin{Discussion}
2966 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
2967 @ChgAdded{Version=[2],Text=[The phrase @lquotes@;within the @nt{subtype_mark}@rquotes@;
2968 in the @lquotes@;this rule does not apply@rquotes@; part is intended to cover
2969 a case like @key{access} T'Class appearing within the declarative region of
2970 T: here T denotes the type, not the current instance.]}
2971 @end{Discussion}
2972
2973 @Defn2{Term=[current instance], Sec=(of a generic unit)}
2974 If a usage name appears within the declarative region of a
2975 @nt{generic_declaration} (but not within its @nt{generic_formal_part})
2976 and it denotes that same @nt{generic_declaration}, then it
2977 denotes the @i{current instance} of the generic unit (rather than
2978 the generic unit itself).
2979 See also @RefSecNum{Generic Instantiation}.
2980 @begin{Honest}
2981 The current instance of a generic unit is the instance created
2982 by whichever @nt{generic_instantiation} is of interest at any
2983 given time.
2984 @end{Honest}
2985 @begin{Ramification}
2986 Within a @nt{generic_formal_part}, a @nt{name} that denotes the
2987 @nt{generic_declaration} denotes the generic unit,
2988 which implies that it is not overloadable.
2989 @end{Ramification}
2990 @end(itemize)
2991
2992 A usage name that denotes a view also denotes the entity of that view.
2993 @begin{Ramification}
2994 Usually, a usage name denotes only one declaration,
2995 and therefore one view and one entity.
2996 @end{Ramification}
2997
2998 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
2999 @leading@RootDefn[expected type]
3000 The @i(expected type) for a given @nt<expression>, @nt<name>,
3001 or other construct determines, according to the @i{type resolution
3002 rules} given below, the types considered for the construct during
3003 overload resolution.
3004 @Defn{type resolution rules}
3005 @Redundant[
3006 The type resolution rules provide support for class-wide programming,
3007 universal @Chg{Version=[2],New=[],Old=[numeric ]}literals, dispatching
3008 operations, and anonymous access types:]
3009 @begin{Ramification}
3010 Expected types are defined throughout the RM95.
3011 The most important definition is that, for a
3012 subprogram, the expected type for the
3013 actual parameter is the type of the formal parameter.
3014
3015 The type resolution rules are trivial unless either the
3016 actual or expected type is universal, class-wide, or of
3017 an anonymous access type.
3018 @end{Ramification}
3019 @begin{Itemize}
3020 @PDefn2{Term=[type resolution rules],
3021 Sec=(if any type in a specified class of types is expected)}
3022 @PDefn2{Term=[type resolution rules],
3023 Sec=(if expected type is universal or class-wide)}
3024 If a construct is expected to be of any type in a class of types,
3025 or of the universal or class-wide type for a class,
3026 then the type of the construct shall resolve to a type in that class
3027 or to a universal type that covers the class.
3028 @begin{Ramification}
3029 This matching rule handles (among other things) cases like the
3030 Val attribute, which denotes a function that takes a parameter of type
3031 @i(universal_integer).
3032
3033 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00021 - Quoted text doesn't match}
3034 The last part of the rule,
3035 @lquotes@;or to a universal type that @Chg{New=[covers],Old=[includes]} the
3036 class@rquotes implies that if the expected type for an expression is
3037 @i{universal_fixed}, then an expression whose type is @i{universal_real}
3038 (such as a real literal) is OK.
3039 @end{Ramification}
3040
3041 @leading@PDefn2{Term=[type resolution rules],
3042 Sec=(if expected type is specific)}
3043 If the expected type for a construct is a specific type @i(T), then the type
3044 of the construct shall resolve either to @i(T), or:
3045 @begin{Ramification}
3046 @PDefn{Beaujolais effect}
3047 This rule is @i{not} intended to create a preference for the specific
3048 type @em such a preference would cause Beaujolais effects.
3049 @end{Ramification}
3050 @begin(Inneritemize)
3051 to @i(T)'Class; or
3052 @begin{Ramification}
3053 This will only be legal as part of a call on a dispatching operation;
3054 see @RefSec(Dispatching Operations of Tagged Types).
3055 Note that that rule is not a @ResolutionName.
3056 @end{Ramification}
3057
3058 to a universal type that covers @i(T); or
3059
3060 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
3061 when @i(T) is @Chg{Version=[2],New=[a specific],Old=[an]} anonymous
3062 access@Chg{Version=[2],New=[-to-object],Old=[]} type
3063 (see @RefSecNum{Access Types}) with designated type @i(D),
3064 to an access-to-@Chg{Version=[2],New=[object],Old=[variable]} type
3065 whose designated type is @i(D)'Class or is covered by
3066 @i(D)@Chg{Version=[2],New=[; or],Old=[.]}
3067
3068 @begin{Ramification}
3069 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00409-01]}
3070 @ChgNote{We use Chg here, rather than ChgDeleted so that the prefix is
3071 left behind.}@Chg{Version=[2],New=[],Old=[Because it says @lquotes@;access-to-variable@rquotes@;
3072 instead of @lquotes@;access-to-object,@rquotes@;
3073 two subprograms that differ only in that one has a parameter
3074 of an access-to-constant type,
3075 and the other has an
3076 access parameter,
3077 are distinguishable during overload resolution.]}
3078
3079 The case where the actual is access-to-@i(D)'Class will only
3080 be legal as part of a call on a dispatching operation;
3081 see @RefSec(Dispatching Operations of Tagged Types).
3082 Note that that rule is not a @ResolutionName.
3083 @end{Ramification}
3084
3085 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01],ARef=[AI95-00409-01]}
3086 @ChgAdded{Version=[2],Text=[when @i(T) is an anonymous access-to-subprogram
3087 type (see @RefSecNum{Access Types}), to an access-to-subprogram type
3088 whose designated profile is type-conformant with that of @i{T}.]}
3089
3090 @end(Inneritemize)
3091 @end{Itemize}
3092
3093
3094 @RootDefn[expected profile]
3095 In certain contexts,
3096 @Redundant[such as in a @nt{subprogram_renaming_declaration},]
3097 the @ResolutionTitle define an @i(expected profile) for a given
3098 @nt<name>;
3099 @Defn2{Term=[profile resolution rule],
3100 Sec=(@nt<name> with a given expected profile)}
3101 in such cases, the @nt{name}
3102 shall resolve to the name of a callable entity whose profile is type
3103 conformant with the expected profile.
3104 @Defn2{Term=[type conformance],Sec=(required)}
3105 @begin{Ramification}
3106 The parameter and result @i{sub}types are not used in overload
3107 resolution.
3108 Only type conformance of profiles
3109 is considered during overload resolution.
3110 Legality rules generally require at least mode-conformance
3111 in addition, but those rules are not used in overload resolution.
3112 @end{Ramification}
3113 @end{Resolution}
3114
3115 @begin{Legality}
3116 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00332-01]}
3117 @Defn2{Term=[single], Sec=[class expected type]}
3118 When @Chg{Version=[2],New=[],Old=[the expected type for ]}a construct is
3119 @Chg{Version=[2],New=[one that requires that its expected type],
3120 Old=[required to]}
3121 be a @i<single> type in a given class, the type
3122 @Chg{Version=[2],New=[of],Old=[expected for]}
3123 the construct shall be determinable solely
3124 from the context in which the construct appears,
3125 excluding the construct itself,
3126 but using the requirement that it be in the given class@Chg{Version=[2],
3127 New=[],Old=[; the type of the construct is then this single expected type]}.
3128 Furthermore, the context shall not be one that expects any type in
3129 some class that contains types of the given class;
3130 in particular, the construct shall not be the operand of a
3131 @nt{type_conversion}.
3132
3133 @begin{Ramification}
3134 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00230-01]}@ChgNote{Null no longer requires a single type}
3135 For example, the expected type for @Chg{Version=[2],New=[a string literal],
3136 Old=[the literal @key{null}]} is required to be a
3137 single @Chg{Version=[2],New=[string],Old=[access]} type.
3138 But the expected type for the operand of a @nt{type_conversion} is
3139 any type.
3140 Therefore, @Chg{Version=[2],New=[a string literal],
3141 Old=[the literal @key{null}]} is not allowed as the operand of a
3142 @nt{type_conversion}.
3143 This is true even if there is only one @Chg{Version=[2],New=[string],
3144 Old=[access]} type in scope@Chg{Version=[2],New=[ (which is never the
3145 case)],Old=[]}.
3146 The reason for these rules is so that the compiler will not have to
3147 search @lquotes@;everywhere@rquotes@; to see if there is exactly one type
3148 in a class in scope.
3149 @end{Ramification}
3150 @begin{Discussion}
3151 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00332-01]}
3152 @ChgAdded{Version=[2],Text=[The first sentence is carefully worded so that it
3153 only mentions @lquotes@;expected type@rquotes as part of identifying the
3154 interesting case, but doesn't require that the context actually provide such
3155 an expected type. This allows such constructs to be used inside of constructs
3156 that don't provide an expected type (like qualified expressions and renames).
3157 Otherwise, such constructs wouldn't allow @nt{aggregate}s, 'Access, and so
3158 on.]}
3159 @end{Discussion}
3160
3161 A complete context shall have at least one acceptable interpretation;
3162 if there is exactly one, then that one is chosen.
3163 @begin{Ramification}
3164 This, and the rule below
3165 about ambiguity, are the ones that suck in all the @SyntaxName@;s and
3166 @ResolutionName@;s as compile-time rules.
3167 Note that this and the ambiguity rule have to be @LegalityName@;s.
3168 @end{Ramification}
3169
3170 @Defn2{Term=[preference], Sec=(for root numeric operators and @nt<range>s)}
3171 There is a @i{preference} for the primitive operators (and @nt<range>s)
3172 of the root numeric
3173 types @i{root_integer} and @i{root_real}.
3174 In particular,
3175 if two acceptable interpretations of a constituent of a complete
3176 context differ only in that one is for a primitive operator (or
3177 @nt<range>) of the
3178 type @i{root_integer} or @i{root_real}, and the other is not,
3179 the interpretation using the primitive operator (or @nt<range>)
3180 of the root numeric type is @i{preferred}.
3181 @begin{Reason}
3182 @leading@;The reason for this preference is so that expressions involving
3183 literals and named numbers can be unambiguous.
3184 For example, without the preference rule, the following would be ambiguous:
3185 @begin{Example}
3186 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00022}
3187 N : @key[constant] := 123;
3188 @key[if] N > 100 @key[then] --@RI{ Preference for root_integer "@Chg{New=[>],Old=[<]}" operator.}
3189 ...
3190 @key[end] @key[if];
3191 @end{Example}
3192 @end{Reason}
3193
3194 For a complete context, if there is exactly one
3195 overall acceptable interpretation where each constituent's interpretation
3196 is the same as or preferred (in the
3197 above sense) over those in all other overall acceptable interpretations, then
3198 that one overall acceptable interpretation is chosen.
3199 @Defn{ambiguous}
3200 Otherwise, the complete context is @i{ambiguous}.
3201
3202 A complete context other than a @nt{pragma_argument_association}
3203 shall not be ambiguous.
3204
3205 A complete context that is a @nt{pragma_argument_association}
3206 is allowed to be ambiguous (unless otherwise specified
3207 for the particular pragma),
3208 but only
3209 if every acceptable interpretation of the pragma argument is as a
3210 @nt{name} that statically denotes a callable entity.
3211 @PDefn2{Term=[denote],Sec=(name used as a pragma argument)}
3212 Such a @nt{name} denotes
3213 all of the declarations determined by its interpretations,
3214 and all of the views declared by these declarations.
3215 @begin{Ramification}
3216 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}@ChgNote{Pragma is obsolete}
3217 This applies to Inline, Suppress,
3218 Import, Export, and Convention @nt{pragma}s.
3219 For example, it is OK to say @lquotes@;@key[pragma] @Chg{Version=[2],
3220 New=[Export(C, Entity_Name],Old=[Suppress(Elaboration_Check, On]}
3221 => P.Q);@rquotes@;, even if there are two directly visible P's, and
3222 there are two Q's declared in the visible part of each P.
3223 In this case, P.Q denotes four different declarations.
3224 This rule also applies to certain pragmas defined in the
3225 Specialized Needs Annexes.
3226 It almost applies to Pure, Elaborate_Body, and Elaborate_All @nt{pragma}s,
3227 but those can't have overloading for other reasons.
3228
3229 Note that if a pragma argument denotes a @i{call} to a callable
3230 entity, rather than the entity itself,
3231 this exception does not apply, and ambiguity is disallowed.
3232
3233 Note that we need to carefully define which pragma-related rules are
3234 @ResolutionName@;s,
3235 so that, for example, a @nt{pragma} Inline does not pick up
3236 subprograms declared in enclosing declarative regions,
3237 and therefore make itself illegal.
3238
3239 We say @lquotes@;statically denotes@rquotes@; in the above rule in order to avoid
3240 having to worry about how many times the @nt{name} is evaluated,
3241 in case it denotes more than one callable entity.
3242 @end{Ramification}
3243 @end{Legality}
3244
3245 @begin{Notes}
3246 If a usage name has only one acceptable interpretation,
3247 then it denotes the corresponding entity.
3248 However, this does not mean that the usage name is necessarily legal
3249 since other requirements exist which are not considered for overload
3250 resolution; for example, the fact that an expression is static, whether
3251 an object is constant, mode and subtype conformance rules, freezing
3252 rules, order of elaboration, and so on.
3253
3254 @NoPrefix@;Similarly, subtypes are not considered for overload resolution (the
3255 violation of a constraint does not make a program illegal but raises an
3256 exception during program execution).
3257 @end{Notes}
3258
3259 @begin{Incompatible83}
3260 @Defn{incompatibilities with Ada 83}
3261 @PDefn{Beaujolais effect}
3262 The new preference rule for operators of root numeric types
3263 is upward incompatible,
3264 but only in cases that involved @i(Beaujolais) effects in Ada 83.
3265 Such cases are ambiguous in Ada 95.
3266 @end{Incompatible83}
3267
3268 @begin{Extend83}
3269 @Defn{extensions to Ada 83}
3270 The rule that allows an expected type to match an actual expression of a
3271 universal type,
3272 in combination with the new preference rule for operators of root numeric
3273 types, subsumes the Ada 83 "implicit conversion" rules
3274 for universal types.
3275 @end{Extend83}
3276
3277 @begin{DiffWord83}
3278 In Ada 83, it is not clear what the @lquotes@;syntax rules@rquotes@; are.
3279 AI83-00157 states that a certain textual rule is a syntax rule,
3280 but it's still not clear how one tells in general which textual rules are
3281 syntax rules.
3282 We have solved the problem by stating exactly which
3283 rules are syntax rules @em the ones that appear under the @lquotes@;@SyntaxTitle@rquotes@;
3284 heading.
3285
3286 RM83 has a long list of the @lquotes@;forms@rquotes@; of rules that are to be
3287 used in overload resolution (in addition to the syntax rules).
3288 It is not clear exactly which rules fall under each form.
3289 We have solved the problem by explicitly
3290 marking all rules that are used in overload resolution.
3291 Thus, the list of kinds of rules is unnecessary.
3292 It is replaced with some introductory
3293 (intentionally vague)
3294 text explaining the basic idea
3295 of what sorts of rules are overloading rules.
3296
3297 It is not clear from RM83 what information is embodied in a @lquotes@;meaning@rquotes@;
3298 or an @lquotes@;interpretation.@rquotes@;
3299 @lquotes@;Meaning@rquotes@; and @lquotes@;interpretation@rquotes@; were intended to be synonymous;
3300 we now use the latter only in defining the rules about overload
3301 resolution.
3302 @lquotes@;Meaning@rquotes@; is used only informally.
3303 This clause attempts to clarify what is meant by @lquotes@;interpretation.@rquotes@;
3304
3305 @NoPrefix@;For example,
3306 RM83 does not make it clear that overload resolution is required in
3307 order to match @ntf{subprogram_bodies} with their corresponding
3308 declarations (and even to tell whether a given @nt{subprogram_body}
3309 is the completion of a previous declaration).
3310 Clearly, the information needed to do this is part of the
3311 @lquotes@;interpretation@rquotes@; of a @nt{subprogram_body}.
3312 The resolution of such things is defined in terms of
3313 the @lquotes@;expected profile@rquotes@; concept.
3314 Ada 95 has some new cases where expected profiles
3315 are needed @em the resolution of P'Access,
3316 where P might denote a subprogram,
3317 is an example.
3318
3319 @Leading@NoPrefix@;RM83-8.7(2) might seem to imply that an interpretation
3320 embodies information about what is denoted by each usage name,
3321 but not information about which syntactic category each construct belongs to.
3322 However, it seems necessary to include such information,
3323 since the Ada grammar is highly ambiguous.
3324 For example, X(Y) might be a @nt{function_call} or an
3325 @nt{indexed_component}, and no context-free/syntactic information can
3326 tell the difference.
3327 It seems like we should view X(Y) as being, for example, @lquotes@;interpreted as a
3328 @nt{function_call}@rquotes@; (if that's what overload resolution decides it is).
3329 Note that there are examples where the denotation of each usage name
3330 does not imply the syntactic category.
3331 However, even if that were not true, it seems that intuitively,
3332 the interpretation includes that information.
3333 Here's an example:
3334 @begin{Example}
3335 @key[type] T;
3336 @key[type] A @key[is] @key[access] T;
3337 @key[type] T @key[is] @key[array](Integer @key[range] 1..10) @key[of] A;
3338 I : Integer := 3;
3339 @key[function] F(X : Integer := 7) @key[return] A;
3340 Y : A := F(I); --@RI{ Ambiguous? (We hope so.)}
3341 @end{Example}
3342
3343 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
3344 @NoPrefix@;Consider the declaration of Y (a complete context).
3345 In the above example, overload resolution can easily determine the
3346 declaration, and therefore the entity,
3347 denoted by Y, A, F, and I.
3348 However, given all of that information,
3349 we still don't know whether F(I) is a @nt{function_call}
3350 or an @nt{indexed_component} whose @Chg{New=[@nt{prefix}],Old=[prefix]} is
3351 a @nt{function_call}.
3352 (In the latter case, it is equivalent to F(7).@key[all](I).)
3353
3354 @NoPrefix@;It seems clear that the declaration of Y ought to be considered
3355 ambiguous.
3356 We describe that by saying that there are two interpretations,
3357 one as a @nt{function_call}, and one as an @nt{indexed_component}.
3358 These interpretations are both acceptable to the overloading
3359 rules.
3360 Therefore, the complete context is ambiguous, and therefore illegal.
3361
3362 @PDefn{Beaujolais effect}
3363 It is the intent that the Ada 95 preference rule for root numeric
3364 operators is more locally enforceable than that of RM83-4.6(15).
3365 It should also eliminate interpretation shifts due to the
3366 addition or removal of a @nt{use_clause}
3367 (the so called @i{Beaujolais} effect).
3368
3369 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
3370 RM83-8.7 seems to be missing some complete contexts,
3371 such as @nt{pragma_argument_association}s,
3372 @nt{declarative_item}s that are not
3373 declarations or @Chg{Version=[2],New=[@nt{aspect_clause}s],
3374 Old=[@nt{representation_clause}s]},
3375 and @nt{context_item}s.
3376 We have added these, and also replaced the @lquotes@;must be determinable@rquotes@;
3377 wording of RM83-5.4(3) with the notion that the expression of a
3378 @nt{case_statement} is a complete context.
3379
3380 Cases like the Val attribute are now handled using the normal type
3381 resolution rules, instead of having special cases that explicitly allow
3382 things like @lquotes@;any integer type.@rquotes@;
3383 @end{DiffWord83}
3384
3385 @begin{Incompatible95}
3386 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]}
3387 @ChgAdded{Version=[2],Type=[Leading],Text=[@Defn{incompatibilities with Ada 95}
3388 Ada 95 allowed name resolution to distinguish between anonymous
3389 access-to-variable and access-to-constant types. This is similar to
3390 distinguishing between subprograms with @key{in} and @key{in out} parameters,
3391 which is known to be bad. Thus, that part of the rule was dropped as we now
3392 have anonymous access-to-constant types, making this much more likely.]}
3393 @begin{Example}
3394 @ChgRef{Version=[2],Kind=[AddedNormal]}
3395 @ChgAdded{Version=[2],Text=[@key{type} Cacc @key{is access constant} Integer;
3396 @key{procedure} Proc (Acc : @key{access} Integer) ...
3397 @key{procedure} Proc (Acc : Cacc) ...
3398 List : Cacc := ...;
3399 Proc (List); -- @RI[OK in Ada 95, ambiguous in Ada 2005.]]}
3400 @end{Example}
3401 @ChgRef{Version=[2],Kind=[AddedNormal]}
3402 @ChgAdded{Version=[2],Text=[If there is any code like this (such code should
3403 be rare), it will be ambiguous in Ada 2005.]}
3404 @end{Incompatible95}
3405
3406 @begin{Extend95}
3407 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00230-01],ARef=[AI95-00231-01],ARef=[AI95-00254-01]}
3408 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
3409 Generalized the anonymous access resolution rules to support the new
3410 capabilities of anonymous access types (that is, access-to-subprogram and
3411 access-to-constant).]}
3412
3413 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00382-01]}
3414 @ChgAdded{Version=[2],Type=[Leading],Text=[We now allow the creation of
3415 self-referencing types via anonymous access types. This is an extension
3416 in unusual cases involving task and protected types. For example:]}
3417 @begin{Example}
3418 @ChgRef{Version=[2],Kind=[AddedNormal]}
3419 @ChgAdded{Version=[2],Text=[@key{task type} T;]}
3420
3421 @ChgRef{Version=[2],Kind=[AddedNormal]}
3422 @ChgAdded{Version=[2],Text=[@key{task body} T @key{is}
3423 @key{procedure} P (X : @key{access} T) @key{is} -- @RI[Illegal in Ada 95, legal in Ada 2005]
3424 ...
3425 @key{end} P;
3426 @key{begin}
3427 ...
3428 @key{end} T;]}
3429 @end{Example}
3430 @end{Extend95}
3431
3432 @begin{DiffWord95}
3433 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00332-01]}
3434 @ChgAdded{Version=[2],Text=[Corrected the @lquotes@;single expected
3435 type@rquotes@; so that it works in contexts that don't have expected types
3436 (like object renames and qualified expressions). This fixes a hole in Ada 95
3437 that appears to prohibit using @nt{aggregate}s, 'Access, character literals,
3438 string literals, and @nt{allocator}s in qualified expressions.]}
3439 @end{DiffWord95}
3440