1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Visibility</TITLE>
<META NAME="Author" CONTENT="JTC1/SC22/WG9/ARG, by Randall Brukardt, ARG Editor">
<META NAME="GENERATOR" CONTENT="Arm_Form.Exe, Ada Reference Manual generator">
<STYLE type="text/css">
DIV.paranum {position: absolute; font-family: Arial, Helvetica, sans-serif; left: 0.5 em; top: auto}
TT {font-family: "Courier New", monospace}
DT {display: compact}
DIV.Normal {font-family: "Times New Roman", Times, serif; margin-bottom: 0.6em}
DIV.Wide {font-family: "Times New Roman", Times, serif; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Annotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.WideAnnotations {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0.6em; margin-bottom: 0.6em}
DIV.Index {font-family: "Times New Roman", Times, serif}
DIV.SyntaxSummary {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Notes {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.NotesHeader {font-family: "Times New Roman", Times, serif; margin-left: 2.0em}
DIV.SyntaxIndented {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-bottom: 0.4em}
DIV.Indented {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-bottom: 0.6em}
DIV.CodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-bottom: 0.6em}
DIV.SmallIndented {font-family: "Times New Roman", Times, serif; margin-left: 10.0em; margin-bottom: 0.6em}
DIV.SmallCodeIndented {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.Examples {font-family: "Courier New", monospace; margin-left: 2.0em; margin-bottom: 0.6em}
DIV.SmallExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 7.5em; margin-bottom: 0.6em}
DIV.IndentedExamples {font-family: "Courier New", monospace; margin-left: 8.0em; margin-bottom: 0.6em}
DIV.SmallIndentedExamples {font-family: "Courier New", monospace; font-size: 80%; margin-left: 15.0em; margin-bottom: 0.6em}
UL.Bulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SmallNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.IndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.CodeIndentedNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-right: 8.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.SyntaxIndentedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesBulleted {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
UL.NotesNestedBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.Hanging {font-family: "Times New Roman", Times, serif; margin-top: 0em; margin-bottom: 0.6em}
DD.Hanging {margin-left: 6.0em}
DL.IndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.IndentedHanging {margin-left: 2.0em}
DL.HangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.HangingInBulleted {margin-left: 4.0em}
DL.SmallHanging {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallHanging {margin-left: 7.5em}
DL.SmallIndentedHanging {font-family: "Times New Roman", Times, serif; margin-left: 8.0em; margin-top: 0em; margin-bottom: 0.6em}
DD.SmallIndentedHanging {margin-left: 2.0em}
DL.SmallHangingInBulleted {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallHangingInBulleted {margin-left: 5.0em}
DL.Enumerated {font-family: "Times New Roman", Times, serif; margin-right: 0.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.Enumerated {margin-left: 2.0em}
DL.SmallEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 4.0em; margin-right: 4.0em; margin-top: 0em; margin-bottom: 0.5em}
DD.SmallEnumerated {margin-left: 2.5em}
DL.NestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 2.0em; margin-right: 2.0em; margin-top: 0em; margin-bottom: 0.5em}
DL.SmallNestedEnumerated {font-family: "Times New Roman", Times, serif; margin-left: 6.0em; margin-right: 6.0em; margin-top: 0em; margin-bottom: 0.5em}
</STYLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFF0" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-8-2.html">Previous</A> <A HREF="AA-8-4.html">Next</A></P>
<HR>
<H1> 8.3 Visibility</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [<A NAME="I3339"></A> The <I>visibility rules</I>,
given below, determine which declarations are visible and directly visible
at each place within a program. The visibility rules apply to both explicit
and implicit declarations.] </DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3340"></A><A NAME="I3341"></A><A NAME="I3342"></A>A
declaration is defined to be <I>directly visible</I> at places where
a <FONT FACE="Arial, Helvetica">name</FONT> consisting of only an <FONT FACE="Arial, Helvetica">identifier</FONT>
or <FONT FACE="Arial, Helvetica">operator_symbol</FONT> is sufficient
to denote the declaration; that is, no <FONT FACE="Arial, Helvetica">selected_component</FONT>
notation or special context (such as preceding => in a named association)
is necessary to denote the declaration. <A NAME="I3343"></A>A declaration
is defined to be <I>visible</I> wherever it is directly visible, as well
as at other places where some <FONT FACE="Arial, Helvetica">name</FONT>
(such as a <FONT FACE="Arial, Helvetica">selected_component</FONT>) can
denote the declaration.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="Normal"> The syntactic category <FONT FACE="Arial, Helvetica">direct_name</FONT>
is used to indicate contexts where direct visibility is required. The
syntactic category <FONT FACE="Arial, Helvetica">selector_name</FONT>
is used to indicate contexts where visibility, but not direct visibility,
is required.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3344"></A><A NAME="I3345"></A>There
are two kinds of direct visibility: <I>immediate visibility</I> and <I>use-visibility</I>.
<A NAME="I3346"></A>A declaration is immediately visible at a place if
it is directly visible because the place is within its immediate scope.
<A NAME="I3347"></A>A declaration is use-visible if it is directly visible
because of a <FONT FACE="Arial, Helvetica">use_clause</FONT> (see <A HREF="AA-8-4.html">8.4</A>).
Both conditions can apply.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3348"></A>A declaration can be <I>hidden</I>,
either from direct visibility, or from all visibility, within certain
parts of its scope. <A NAME="I3349"></A>Where <I>hidden from all visibility</I>,
it is not visible at all (neither using a <FONT FACE="Arial, Helvetica">direct_name</FONT>
nor a <FONT FACE="Arial, Helvetica">selector_name</FONT>). <A NAME="I3350"></A>Where
<I>hidden from direct visibility</I>, only direct visibility is lost;
visibility using a <FONT FACE="Arial, Helvetica">selector_name</FONT>
is still possible.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="Normal"> [<A NAME="I3351"></A> Two or more declarations
are <I>overloaded</I> if they all have the same defining name and there
is a place where they are all directly visible.] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Note that
a <FONT FACE="Arial, Helvetica">name</FONT> can have more than one possible
interpretation even if it denotes a non-overloadable entity. For example,
if there are two functions F that return records, both containing a component
called C, then the name F.C has two possible interpretations, even though
component declarations are not overloadable. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3352"></A>The declarations of callable
entities [(including enumeration literals)] are <I>overloadable</I>[,
meaning that overloading is allowed for them]. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A <FONT FACE="Arial, Helvetica">generic_declaration</FONT>
is not overloadable within its own <FONT FACE="Arial, Helvetica">generic_formal_part</FONT>.
This follows from the rules about when a <FONT FACE="Arial, Helvetica">name</FONT>
denotes a current instance. See AI83-00286. This implies that within
a <FONT FACE="Arial, Helvetica">generic_formal_part</FONT>, outer declarations
with the same defining name are hidden from direct visibility. It also
implies that if a generic formal parameter has the same defining name
as the generic itself, the formal parameter hides the generic from direct
visibility. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3353"></A>Two declarations are <I>homographs</I>
if they have the same defining name, and, if both are overloadable, their
profiles are type conformant. <A NAME="I3354"></A>[An inner declaration
hides any outer homograph from direct visibility.]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0025">8652/0025</A></I>}
[Two homographs are not generally allowed immediately within the same
declarative region unless one <I>overrides</I> the other (see Legality
Rules below).] <A NAME="I3355"></A><U>The only declarations that are
<A NAME="I3356"></A><I>overridable</I> are the implicit declarations
for predefined operators and inherited primitive subprograms.</U> A declaration
overrides another homograph that occurs immediately within the same declarative
region in the following cases: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10/1</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC>{<I><A HREF="defect1.html#8652/0025">8652/0025</A></I>}
<U>A declaration that is not overridable overrides one that is overridable</U><S>An
explicit declaration overrides an implicit declaration of a primitive
subprogram</S>, [regardless of which declaration occurs first]; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>10.a/1</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>{<I><A HREF="defect1.html#8652/0025">8652/0025</A></I>}
And regardless of whether the <U>non-overriddable</U><S>explicit</S>
declaration is overloadable or not. <U>For example, <FONT FACE="Arial, Helvetica">statement_identifier</FONT>s
are covered by this rule.</U></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The ``regardless of which declaration
occurs first'' is there because the explicit declaration could be a primitive
subprogram of a partial view, and then the full view might inherit a
homograph. We are saying that the explicit one wins (within its scope),
even though the implicit one comes later.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>If the overriding declaration
is also a subprogram, then it is a primitive subprogram.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>As explained in <A HREF="AA-7-3-1.html">7.3.1</A>,
``<A HREF="AA-7-3-1.html">Private Operations</A>'', some inherited primitive
subprograms are never declared. Such subprograms cannot be overridden,
although they can be reached by dispatching calls in the case of a tagged
type. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>The implicit declaration of an inherited operator overrides
that of a predefined operator; </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>In a previous
version of Ada 9X, we tried to avoid the notion of predefined operators,
and say that they were inherited from some magical root type. However,
this seemed like too much mechanism. Therefore, a type can have a predefined
"+" as well as an inherited "+". The above rule says
the inherited one wins.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The ``regardless of which declaration
occurs first'' applies here as well, in the case where <FONT FACE="Arial, Helvetica">derived_type_declaration</FONT>
in the visible part of a public library unit derives from a private type
declared in the parent unit, and the full view of the parent type has
additional predefined operators, as explained in <A HREF="AA-7-3-1.html">7.3.1</A>,
``<A HREF="AA-7-3-1.html">Private Operations</A>''. Those predefined
operators can be overridden by inherited subprograms implicitly declared
earlier. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>An implicit declaration of an inherited subprogram overrides
a previous implicit declaration of an inherited subprogram.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>[For an implicit declaration of a primitive subprogram
in a generic unit, there is a copy of this declaration in an instance.]
However, a whole new set of primitive subprograms is implicitly declared
for each type declared within the visible part of the instance. These
new declarations occur immediately after the type declaration, and override
the copied ones. [The copied ones can be called only from within the
instance; the new ones can be called only from outside the instance,
although for tagged types, the body of a new one can be executed by a
call to an old one.] </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>In addition,
this is also stated redundantly (again), and is repeated, in <A HREF="AA-12-3.html">12.3</A>,
``<A HREF="AA-12-3.html">Generic Instantiation</A>''. The rationale for
the rule is explained there. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I3357"></A><A NAME="I3358"></A>A
declaration is visible within its scope, except where hidden from all
visibility, as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I3359"></A>An overridden declaration is hidden
from all visibility within the scope of the overriding declaration. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>15.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>We have to
talk about the scope of the overriding declaration, not its visibility,
because it hides even when it is itself hidden.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the scope of an explicit
<FONT FACE="Arial, Helvetica">subprogram_declaration</FONT> does not
start until after its profile. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<UL Class="Bulleted" Style="margin-bottom: 0.3em"><LI TYPE=DISC><A NAME="I3360"></A>A declaration is hidden from all visibility
until the end of the declaration, except: </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>For a record type or record extension, the declaration
is hidden from all visibility only until the reserved word <B>record</B>;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<UL Class="NestedBulleted"><LI TYPE=DISC>For a <FONT FACE="Arial, Helvetica">package_declaration</FONT>,
task declaration, protected declaration, <FONT FACE="Arial, Helvetica">generic_package_declaration</FONT>,
or <FONT FACE="Arial, Helvetica">subprogram_body</FONT>, the declaration
is hidden from all visibility only until the reserved word <B>is</B>
of the declaration. </LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>We're talking
about the <B>is</B> of the construct itself, here, not some random <B>is</B>
that might appear in a <FONT FACE="Arial, Helvetica">generic_formal_part</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I3361"></A>If the completion of a declaration
is a declaration, then within the scope of the completion, the first
declaration is hidden from all visibility. Similarly, a <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
or <FONT FACE="Arial, Helvetica">parameter_specification</FONT> is hidden
within the scope of a corresponding <FONT FACE="Arial, Helvetica">discriminant_specification</FONT>
or <FONT FACE="Arial, Helvetica">parameter_specification</FONT> of a
corresponding completion, or of a corresponding <FONT FACE="Arial, Helvetica">accept_statement</FONT>.
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>19.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>This rule
means, for example, that within the scope of a <FONT FACE="Arial, Helvetica">full_type_declaration</FONT>
that completes a <FONT FACE="Arial, Helvetica">private_type_declaration</FONT>,
the name of the type will denote the <FONT FACE="Arial, Helvetica">full_type_declaration</FONT>,
and therefore the full view of the type. On the other hand, if the completion
is not a declaration, then it doesn't hide anything, and you can't denote
it. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I3362"></A>The declaration of a library unit (including
a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>)
is hidden from all visibility except at places that are within its declarative
region or within the scope of a <FONT FACE="Arial, Helvetica">with_clause</FONT>
that mentions it. [For each declaration or renaming of a generic unit
as a child of some parent generic package, there is a corresponding declaration
nested immediately within each instance of the parent.] Such a nested
declaration is hidden from all visibility except at places that are within
the scope of a <FONT FACE="Arial, Helvetica">with_clause</FONT> that
mentions the child.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>20.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This is the
rule that prevents <FONT FACE="Arial, Helvetica">with_clause</FONT>s
from being transitive; the [immediate] scope includes indirect semantic
dependents. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <A NAME="I3363"></A><A NAME="I3364"></A><A NAME="I3365"></A><A NAME="I3366"></A>A
declaration with a <FONT FACE="Arial, Helvetica">defining_identifier</FONT>
or <FONT FACE="Arial, Helvetica">defining_operator_symbol</FONT> is immediately
visible [(and hence directly visible)] within its immediate scope <A NAME="I3367"></A>
except where hidden from direct visibility, as follows: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I3368"></A>A declaration is hidden from direct
visibility within the immediate scope of a homograph of the declaration,
if the homograph occurs within an inner declarative region;</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC><A NAME="I3369"></A>A declaration is also hidden from direct
visibility where hidden from all visibility. </LI></UL>
<H4 ALIGN=CENTER>Name Resolution Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3370"></A>A <FONT FACE="Arial, Helvetica">direct_name</FONT>
shall resolve to denote a directly visible declaration whose defining
name is the same as the <FONT FACE="Arial, Helvetica">direct_name</FONT>.
<A NAME="I3371"></A>A <FONT FACE="Arial, Helvetica">selector_name</FONT>
shall resolve to denote a visible declaration whose defining name is
the same as the <FONT FACE="Arial, Helvetica">selector_name</FONT>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>"The same
as" has the obvious meaning here, so for +, the possible interpretations
are declarations whose defining name is "+" (an <FONT FACE="Arial, Helvetica">operator_symbol</FONT>).
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<DIV Class="Normal"> These rules on visibility and direct visibility
do not apply in a <FONT FACE="Arial, Helvetica">context_clause</FONT>,
a <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>, or a <FONT FACE="Arial, Helvetica">pragma</FONT>
that appears at the place of a <FONT FACE="Arial, Helvetica">compilation_unit</FONT>.
For those contexts, see the rules in <A HREF="AA-10-1-6.html">10.1.6</A>,
``<A HREF="AA-10-1-6.html">Environment-Level Visibility Rules</A>''.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>25.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Direct visibility
is irrelevant for <FONT FACE="Arial, Helvetica">character_literal</FONT>s.
In terms of overload resolution <FONT FACE="Arial, Helvetica">character_literal</FONT>s
are similar to other literals, like <B>null</B> -- see <A HREF="AA-4-2.html">4.2</A>.
For <FONT FACE="Arial, Helvetica">character_literal</FONT>s, there is
no need to worry about hiding, since there is no way to declare homographs.
</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>26/1</FONT></DIV>
<DIV Class="Normal"> {<I><A HREF="defect1.html#8652/0025">8652/0025</A></I>}
{<I><A HREF="defect1.html#8652/0026">8652/0026</A></I>} <U>A non-overridable</U><S>An
explicit</S> declaration is illegal if there is a homograph occurring
immediately within the same declarative region that is visible at the
place of the declaration, and is not hidden from all visibility by the
<U>non-overridable</U><S>explicit</S> declaration. <U>In addition, a
type extension is illegal if somewhere within its immediate scope it
has two visible components with the same name.</U> Similarly, the <FONT FACE="Arial, Helvetica">context_clause</FONT>
for a <FONT FACE="Arial, Helvetica">subunit</FONT> is illegal if it mentions
(in a <FONT FACE="Arial, Helvetica">with_clause</FONT>) some library
unit, and there is a homograph of the library unit that is visible at
the place of the corresponding stub, and the homograph and the mentioned
library unit are both declared immediately within the same declarative
region. <A NAME="I3372"></A>These rules also apply to dispatching operations
declared in the visible part of an instance of a generic unit. However,
they do not apply to other overloadable declarations in an instance[;
such declarations may have type conformant profiles in the instance,
so long as the corresponding declarations in the generic were not type
conformant]. <A NAME="I3373"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Discussion:
</B>Normally, these rules just mean you can't explicitly declare two
homographs immediately within the same declarative region. The wording
is designed to handle the following special cases: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.b</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>If the second declaration completes the first one, the
second declaration is legal.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.c</FONT></DIV>
<UL Class="SmallBulleted" Style="margin-bottom: 0.3em"><FONT SIZE=-1><LI TYPE=DISC>If the body of a library unit contains an explicit homograph
of a child of that same library unit, this is illegal only if the body
mentions the child in its <FONT FACE="Arial, Helvetica">context_clause</FONT>,
or if some subunit mentions the child. Here's an example: </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.d</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>package</B> P <B>is</B><BR>
<B>end</B> P;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.e</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>package</B> P.Q <B>is</B><BR>
<B>end</B> P.Q;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.f</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>package</B> <B>body</B> P <B>is</B><BR>
Q : Integer; --<I> OK; we cannot see package P.Q here.</I><BR>
<B>procedure</B> Sub <B>is</B> <B>separate</B>;<BR>
<B>end</B> P;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.g</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> P.Q;<BR>
<B>separate</B>(P)<BR>
<B>procedure</B> Sub <B>is</B> --<I> Illegal.</I><BR>
<B>begin</B><BR>
<B>null</B>;<BR>
<B>end</B> Sub;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.h</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1>If package body P said "<B>with</B>
P.Q;", then it would be illegal to declare the homograph Q: Integer.
But it does not, so the body of P is OK. However, the subunit would be
able to see both P.Q's, and is therefore illegal.</FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.i</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1>A previous version of Ada 9X
allowed the subunit, and said that references to P.Q would tend to be
ambiguous. However, that was a bad idea, because it requires overload
resolution to resolve references to directly visible non-overloadable
homographs, which is something compilers have never before been required
to do.</FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.1/1</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>{<I><A HREF="defect1.html#8652/0026">8652/0026</A></I>}
{<I><A HREF="defect2.html#8652/0102">8652/0102</A></I>} <U>If a <FONT FACE="Arial, Helvetica">type_extension</FONT>
contains a component with the same name as a component in an ancestor
type, there must be no place where both components are visible. For instance:</U>
</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.2/1</FONT></DIV>
<DIV Class="SmallExamples" Style="margin-bottom: 0.4em"><TT><U><B>package</B> A <B>is</B><BR>
<B>type</B> T <B>is tagged private</B>;<BR>
<B>package</B> B <B>is</B><BR>
<B>type</B> NT <B>is new</B> T <B>with record</B><BR>
I: Integer; -- <I>Illegal because T.I is visible in the body.</I><BR>
<B>end record</B>; -- <I>T.I is not visible here.</I><BR>
<B>end</B> B;<BR>
<B>private</B><BR>
<B>type</B> T <B>is tagged record</B><BR>
I: Integer; -- <I>Illegal because T.I is visible in the body.</I><BR>
<B>end record</B>;<BR>
<B>end</B> A;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.3/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>package</B> A <B>is</B><BR>
<B>package</B> <B>body</B> A <B>is</B><BR>
<B>package</B> <B>body</B> B <B>is</B><BR>
-- <I>T.I becomes visible here.</I><BR>
<B>end</B> B;<BR>
<B>end</B> A;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.4/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>package</B> A.C <B>is</B><BR>
<B>type</B> NT2 <B>is new</B> A.T <B>with record</B><BR>
I: Integer; -- <I>Illegal because T.I is visible in the private part.</I><BR>
<B>end record</B>; -- <I>T.I is not visible here.</I><BR>
<B>private</B><BR>
-- <I>T.I is visible here.</I><BR>
<B>end</B> A.C;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.5/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>with</B> A;<BR>
<B>package</B> D <B>is</B><BR>
<B>type</B> NT3 <B>is new</B> A.T <B>with record</B><BR>
I: Integer; -- <I>Legal because T.I is never visible in this package.</I><BR>
<B>end record</B>;<BR>
<B>end</B> D;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.6/1</FONT></DIV>
<DIV Class="SmallExamples"><TT><U><B>with</B> D;<BR>
<B>package</B> A.E <B>is</B><BR>
<B>type</B> NT4 <B>is new</B> D.NT3 <B>with null record</B>;<BR>
X : NT4;<BR>
I1 : Integer := X.I; -- <I>D.NT3.I</I><BR>
I2 : Integer := D.NT3(X).I; -- <I>D.NT3.I</I><BR>
I3 : Integer := A.T(X).I; -- <I>A.T.I</I><BR>
<B>end</B> A.E;</U></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.i.7/1</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>{<I><A HREF="defect2.html#8652/0102">8652/0102</A></I>}
<U>D.NT3 can have a component I because the component I of the parent
type is never visible. The parent component exists, of course, but is
never declared for the type D.NT3. In the child package A.E, the component
I of A.T is visible, but that does not change the fact that the A.T.I
component was never declared for type D.NT3. Thus, A.E.NT4 does not (visibly)
inherit the component I from A.T, while it does inherit the component
I from D.NT3. Of course, both components exist, and can be accessed by
a type conversion as shown above. This behavior stems from the fact that
every characteristic of a type (including components) must be declared
somewhere in the innermost declarative region containing the type - if
the characteristic is never visible in that declarative region, it is
never declared. Therefore, such characteristics do not suddenly become
available even if they are in fact visible in some other scope. See <A HREF="AA-7-3-1.html">7.3.1</A>
for more on the rules.</U> </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>26.j</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that we need to be careful
which things we make "hidden from all visibility" versus which
things we make simply illegal for names to denote. The distinction is
subtle. The rules that disallow names denoting components within a type
declaration (see <A HREF="AA-3-7.html">3.7</A>) do not make the components
invisible at those places, so that the above rule makes components with
the same name illegal. The same is true for the rule that disallows names
denoting formal parameters within a <FONT FACE="Arial, Helvetica">formal_part</FONT>
(see <A HREF="AA-6-1.html">6.1</A>). </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.k</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The part about
instances is from AI83-00012. The reason it says ``overloadable declarations''
is because we don't want it to apply to type extensions that appear in
an instance; components are not overloadable. </FONT></DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>5 Visibility for compilation
units follows from the definition of the environment in <A HREF="AA-10-1-4.html">10.1.4</A>,
except that it is necessary to apply a <FONT FACE="Arial, Helvetica">with_clause</FONT>
to obtain visibility to a <FONT FACE="Arial, Helvetica">library_unit_declaration</FONT>
or <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>6 In addition to the visibility
rules given above, the meaning of the occurrence of a <FONT FACE="Arial, Helvetica">direct_name</FONT>
or <FONT FACE="Arial, Helvetica">selector_name</FONT> at a given place
in the text can depend on the overloading rules (see <A HREF="AA-8-6.html">8.6</A>).</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>7 Not all contexts where
an <FONT FACE="Arial, Helvetica">identifier</FONT>, <FONT FACE="Arial, Helvetica">character_literal</FONT>,
or <FONT FACE="Arial, Helvetica">operator_symbol</FONT> are allowed require
visibility of a corresponding declaration. Contexts where visibility
is not required are identified by using one of these three syntactic
categories directly in a syntax rule, rather than using <FONT FACE="Arial, Helvetica">direct_name</FONT>
or <FONT FACE="Arial, Helvetica">selector_name</FONT>. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Ramification:
</B>An <FONT FACE="Arial, Helvetica">identifier</FONT>, <FONT FACE="Arial, Helvetica">character_literal</FONT>
or <FONT FACE="Arial, Helvetica">operator_symbol</FONT> that occurs in
one of the following contexts is not required to denote a visible or
directly visible declaration: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.b</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>1.<DD Class="SmallEnumerated">
A defining name.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.c</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>2.<DD Class="SmallEnumerated">
The <FONT FACE="Arial, Helvetica">identifier</FONT>s or <FONT FACE="Arial, Helvetica">operator_symbol</FONT>
that appear after the reserved word <B>end</B> in a <FONT FACE="Arial, Helvetica">proper_body</FONT>.
Similarly for ``<B>end loop</B>'', etc.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.d</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>3.<DD Class="SmallEnumerated">
An <FONT FACE="Arial, Helvetica">attribute_designator</FONT>.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.e</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>4.<DD Class="SmallEnumerated">
A <FONT FACE="Arial, Helvetica">pragma</FONT> <FONT FACE="Arial, Helvetica">identifier</FONT>.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.f</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>5.<DD Class="SmallEnumerated">
A <I>pragma_argument_</I><FONT FACE="Arial, Helvetica">identifier</FONT>.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.g</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>6.<DD Class="SmallEnumerated">
An <FONT FACE="Arial, Helvetica">identifier</FONT> specific to a pragma
used in a pragma argument. </FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>29.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The visibility rules have nothing
to do with the above cases; the meanings of such things are defined elsewhere.
Reserved words are not <FONT FACE="Arial, Helvetica">identifier</FONT>s;
the visibility rules don't apply to them either.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.i</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Because of the way we have defined
"declaration", it is possible for a usage name to denote a
<FONT FACE="Arial, Helvetica">subprogram_body</FONT>, either within that
body, or (for a non-library unit) after it (since the body hides the
corresponding declaration, if any). Other bodies do not work that way.
Completions of <FONT FACE="Arial, Helvetica">type_</FONT> and <FONT FACE="Arial, Helvetica">deferred_constant_declaration</FONT>s
do work that way. <FONT FACE="Arial, Helvetica">Accept_statements</FONT>
are never denoted, although the <FONT FACE="Arial, Helvetica">parameter_specification</FONT>s
in their profiles can be.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.j</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>The
scope of a subprogram does not start until after its profile. Thus, the
following is legal: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.k</FONT></DIV>
<DIV Class="SmallExamples"><TT>X : <B>constant</B> Integer := 17;<BR>
...<BR>
<B>package</B> P <B>is</B><BR>
<B>procedure</B> X(Y : <B>in</B> Integer := X);<BR>
<B>end</B> P;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.l</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The body of the subprogram will
probably be illegal, however, since the constant X will be hidden by
then.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.m</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>The
rule is different for generic subprograms, since they are not overloadable;
the following is illegal: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.n</FONT></DIV>
<DIV Class="SmallExamples"><TT>X : <B>constant</B> Integer := 17;<BR>
<B>package</B> P <B>is</B><BR>
<B>generic</B><BR>
Z : Integer := X; --<I> Illegal!</I><BR>
<B>procedure</B> X(Y : <B>in</B> Integer := X); --<I> Illegal!</I><BR>
<B>end</B> P;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.o</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The constant X is hidden from
direct visibility by the generic declaration. </FONT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>29.p</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I3374"></A>Declarations
with the same defining name as that of a subprogram or entry being defined
are nevertheless visible within the subprogram specification or entry
declaration. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>29.q</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The term ``visible by selection''
is no longer defined. We use the terms ``directly visible'' and ``visible''
(among other things). There are only two regions of text that are of
interest, here: the region in which a declaration is visible, and the
region in which it is directly visible.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>29.r</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Visibility is defined only for
declarations. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-8-2.html">Previous</A> <A HREF="AA-8-4.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|