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 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Compilation Units - Library Units</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-10-1.html">Previous</A> <A HREF="AA-10-1-2.html">Next</A></P>
<HR>
<H1> 10.1.1 Compilation Units - Library Units</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [A <FONT FACE="Arial, Helvetica">library_item</FONT>
is a compilation unit that is the declaration, body, or renaming of a
library unit. Each library unit (except Standard) has a <I>parent unit</I>,
which is a library package or generic library package.] <A NAME="I3850"></A>A
library unit is a <I>child</I> of its parent unit. The <I>root</I> library
units are the children of the predefined library package Standard. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>1.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Standard
is a library unit. </FONT></DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">compilation<A NAME="I3851"></A>
::= </FONT>{<A NAME="I3852"></A><FONT FACE="Arial, Helvetica">compilation_unit</FONT>}</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">compilation_unit<A NAME="I3853"></A>
::= </FONT><BR>
<A NAME="I3854"></A><FONT FACE="Arial, Helvetica">context_clause</FONT> <A NAME="I3855"></A><FONT FACE="Arial, Helvetica">library_item</FONT><BR>
| <A NAME="I3856"></A><FONT FACE="Arial, Helvetica">context_clause</FONT> <A NAME="I3857"></A><FONT FACE="Arial, Helvetica">subunit</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">library_item<A NAME="I3858"></A>
::= </FONT>[<B>private</B>] <A NAME="I3859"></A><FONT FACE="Arial, Helvetica">library_unit_declaration</FONT><BR>
| <A NAME="I3860"></A><FONT FACE="Arial, Helvetica">library_unit_body</FONT><BR>
| [<B>private</B>] <A NAME="I3861"></A><FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">library_unit_declaration<A NAME="I3862"></A>
::= </FONT><BR>
<A NAME="I3863"></A><FONT FACE="Arial, Helvetica">subprogram_declaration</FONT> | <A NAME="I3864"></A><FONT FACE="Arial, Helvetica">package_declaration</FONT><BR>
| <A NAME="I3865"></A><FONT FACE="Arial, Helvetica">generic_declaration</FONT> | <A NAME="I3866"></A><FONT FACE="Arial, Helvetica">generic_instantiation</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">library_unit_renaming_declaration<A NAME="I3867"></A>
::= </FONT><BR>
<A NAME="I3868"></A><FONT FACE="Arial, Helvetica">package_renaming_declaration</FONT><BR>
| <A NAME="I3869"></A><FONT FACE="Arial, Helvetica">generic_renaming_declaration</FONT><BR>
| <A NAME="I3870"></A><FONT FACE="Arial, Helvetica">subprogram_renaming_declaration</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">library_unit_body<A NAME="I3871"></A>
::= </FONT><A NAME="I3872"></A><FONT FACE="Arial, Helvetica">subprogram_body</FONT> | <A NAME="I3873"></A><FONT FACE="Arial, Helvetica">package_body</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">parent_unit_name<A NAME="I3874"></A>
::= </FONT><A NAME="I3875"></A><FONT FACE="Arial, Helvetica">name</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3876"></A>A <I>library unit</I> is a
program unit that is declared by a <FONT FACE="Arial, Helvetica">library_item</FONT>.
When a program unit is a library unit, the prefix ``library'' is used
to refer to it (or ``generic library'' if generic), as well as to its
declaration and body, as in ``library procedure'', ``library <FONT FACE="Arial, Helvetica">package_body</FONT>'',
or ``generic library package''. <A NAME="I3877"></A>The term <I>compilation
unit</I> is used to refer to a <FONT FACE="Arial, Helvetica">compilation_unit</FONT>.
When the meaning is clear from context, the term is also used to refer
to the <FONT FACE="Arial, Helvetica">library_item</FONT> of a <FONT FACE="Arial, Helvetica">compilation_unit</FONT>
or to the <FONT FACE="Arial, Helvetica">proper_body</FONT> of a <FONT FACE="Arial, Helvetica">subunit</FONT>
[(that is, the <FONT FACE="Arial, Helvetica">compilation_unit</FONT>
without the <FONT FACE="Arial, Helvetica">context_clause</FONT> and the
<B>separate</B> (<FONT FACE="Arial, Helvetica">parent_unit_name</FONT>))].
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Discussion:
</B>In this example: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.b</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> Ada.Text_IO;<BR>
<B>package</B> P <B>is</B><BR>
...<BR>
<B>end</B> P;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>the term ``compilation unit''
can refer to this text: ``<B>with</B> Ada.Text_IO; <B>package</B> P <B>is</B>
... <B>end</B> P;'' or to this text: ``<B>package</B> P <B>is</B> ...
<B>end</B> P;''. We use this shorthand because it corresponds to common
usage.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We like to use the word ``unit''
for declaration-plus-body things, and ``item'' for declaration or body
separately (as in <FONT FACE="Arial, Helvetica">declarative_item</FONT>).
The terms ``<FONT FACE="Arial, Helvetica">compilation_unit</FONT>,''
``compilation unit,'' and ``<FONT FACE="Arial, Helvetica">subunit</FONT>''
are exceptions to this rule. We considered changing ``<FONT FACE="Arial, Helvetica">compilation_unit</FONT>,''
``compilation unit'' to ``<FONT FACE="Arial, Helvetica">compilation_item</FONT>,''
``compilation item,'' respectively, but we decided not to. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3878"></A><A NAME="I3879"></A>The <I>parent
declaration</I> of a <FONT FACE="Arial, Helvetica">library_item</FONT>
(and of the library unit) is the declaration denoted by the <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>,
if any, of the <FONT FACE="Arial, Helvetica">defining_program_unit_name</FONT>
of the <FONT FACE="Arial, Helvetica">library_item</FONT>. <A NAME="I3880"></A>If
there is no <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>, the
parent declaration is the declaration of Standard, the <FONT FACE="Arial, Helvetica">library_item</FONT>
is a <I>root</I> <FONT FACE="Arial, Helvetica">library_item</FONT>, and
the library unit (renaming) is a <I>root</I> library unit (renaming).
The declaration and body of Standard itself have no parent declaration.
<A NAME="I3881"></A>The <I>parent unit</I> of a <FONT FACE="Arial, Helvetica">library_item</FONT>
or library unit is the library unit declared by its parent declaration.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The declaration
and body of Standard are presumed to exist from the beginning of time,
as it were. There is no way to actually write them, since there is no
syntactic way to indicate lack of a parent. An attempt to compile a package
Standard would result in Standard.Standard. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Library units (other
than Standard) have ``parent declarations'' and ``parent units''. Subunits
have ``parent bodies''. We didn't bother to define the other possibilities:
parent body of a library unit, parent declaration of a subunit, parent
unit of a subunit. These are not needed, and might get in the way of
a correct definition of ``child.'' </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> [The children of a library unit occur immediately
within the declarative region of the declaration of the library unit.]
<A NAME="I3882"></A>The <I>ancestors</I> of a library unit are itself,
its parent, its parent's parent, and so on. [(Standard is an ancestor
of every library unit.)] <A NAME="I3883"></A>The <I>descendant</I> relation
is the inverse of the ancestor relation. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>These definitions
are worded carefully to avoid defining subunits as children. Only library
units can be children.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>We use the unadorned term ``ancestors''
here to concisely define both ``ancestor unit'' and ``ancestor declaration.''
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3884"></A><A NAME="I3885"></A><A NAME="I3886"></A><A NAME="I3887"></A>A
<FONT FACE="Arial, Helvetica">library_unit_declaration</FONT> or a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>
is <I>private</I> if the declaration is immediately preceded by the reserved
word <B>private</B>; it is otherwise <I>public</I>. A library unit is
private or public according to its declaration. <A NAME="I3888"></A>The
<I>public descendants</I> of a library unit are the library unit itself,
and the public descendants of its public children. <A NAME="I3889"></A>Its
other descendants are <I>private descendants</I>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The first concept
defined here is that a <FONT FACE="Arial, Helvetica">library_item</FONT>
is either public or private (not in relation to anything else -- it's
just a property of the library unit). The second concept is that a <FONT FACE="Arial, Helvetica">library_item</FONT>
is a public descendant or private descendant <I>of a given ancestor</I>.
A given <FONT FACE="Arial, Helvetica">library_item</FONT> can be a public
descendant of one of its ancestors, but a private descendant of some
other ancestor.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>A subprogram declared by a <FONT FACE="Arial, Helvetica">subprogram_body</FONT>
(as opposed to a <FONT FACE="Arial, Helvetica">subprogram_declaration</FONT>)
is always public, since the syntax rules disallow the reserved word <B>private</B>
on a body.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that a private library unit
is a <I>public</I> descendant of itself, but a <I>private</I> descendant
of its parent. This is because it is visible outside itself -- its privateness
means that it is not visible outside its parent.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Private children of Standard are
legal, and follow the normal rules. It is intended that implementations
might have some method for taking an existing environment, and treating
it as a package to be ``imported'' into another environment, treating
children of Standard in the imported environment as children of the imported
package. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.e</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Ramification:
</B>Suppose we have a public library unit A, a private library unit A.B,
and a public library unit A.B.C. A.B.C is a public descendant of itself
and of A.B, but a private descendant of A; since A.B is private to A,
we don't allow A.B.C to escape outside A either. This is similar to the
situation that would occur with physical nesting, like this: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.f</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>package</B> A <B>is</B><BR>
<B>private</B><BR>
<B>package</B> B <B>is</B><BR>
<B>package</B> C <B>is</B><BR>
<B>end</B> C;<BR>
<B>private</B><BR>
<B>end</B> B;<BR>
<B>end</B> A;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Here, A.B.C is visible outside
itself and outside A.B, but not outside A. (Note that this example is
intended to illustrate the visibility of program units from the outside;
the visibility within child units is not quite identical to that of physically
nested units, since child units are nested after their parent's declaration.)
</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal"> The parent unit of a <FONT FACE="Arial, Helvetica">library_item</FONT>
shall be a [library] package or generic [library] package.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal"> If a <FONT FACE="Arial, Helvetica">defining_program_unit_name</FONT>
of a given declaration or body has a <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>,
then the given declaration or body shall be a <FONT FACE="Arial, Helvetica">library_item</FONT>.
The body of a program unit shall be a <FONT FACE="Arial, Helvetica">library_item</FONT>
if and only if the declaration of the program unit is a <FONT FACE="Arial, Helvetica">library_item</FONT>.
In a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>,
the [(old)] <FONT FACE="Arial, Helvetica">name</FONT> shall denote a
<FONT FACE="Arial, Helvetica">library_item</FONT>. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>We could have
allowed nested program units to be children of other program units; their
semantics would make sense. We disallow them to keep things simpler and
because they wouldn't be particularly useful. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>
[(which can be used within a <FONT FACE="Arial, Helvetica">defining_program_unit_name</FONT>
of a <FONT FACE="Arial, Helvetica">library_item</FONT> and in the <B>separate</B>
clause of a <FONT FACE="Arial, Helvetica">subunit</FONT>)], and each
of its <FONT FACE="Arial, Helvetica">prefix</FONT>es, shall not denote
a <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>. [On the
other hand, a name that denotes a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>
is allowed in a <FONT FACE="Arial, Helvetica">with_clause</FONT> and
other places where the name of a library unit is allowed.]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Normal"> If a library package is an instance of a generic
package, then every child of the library package shall either be itself
an instance or be a renaming of a library unit. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>A child of
an instance of a given generic unit will often be an instance of a (generic)
child of the given generic unit. This is not required, however. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.b</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Reason:
</B>Instances are forbidden from having noninstance children for two
reasons: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16.c</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>1.<DD Class="SmallEnumerated">
We want all source code that can depend on information from the private
part of a library unit to be inside the "subsystem" rooted
at the library unit. If an instance of a generic unit were allowed to
have a noninstance as a child, the source code of that child might depend
on information from the private part of the generic unit, even though
it is outside the subsystem rooted at the generic unit.</FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>16.d</FONT></DIV>
<DL Class="SmallEnumerated"><FONT SIZE=-1><DT>2.<DD Class="SmallEnumerated">
Disallowing noninstance children simplifies the description of the semantics
of children of generic packages. </FONT></DL>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<DIV Class="Normal"> A child of a generic library package shall either
be itself a generic unit or be a renaming of some other child of the
same generic unit. The renaming of a child of a generic package shall
occur only within the declarative region of the generic package.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<DIV Class="Normal"> A child of a parent generic package shall be
instantiated or renamed only within the declarative region of the parent
generic.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Normal"> 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. [This
declaration is visible only within the scope of a <FONT FACE="Arial, Helvetica">with_clause</FONT>
that mentions the child generic unit.]</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Implementation Note: </B>Within
the child, like anything nested in a generic unit, one can make up-level
references to the current instance of its parent, and thereby gain access
to the formal parameters of the parent, to the types declared in the
parent, etc. This ``nesting'' model applies even within the <FONT FACE="Arial, Helvetica">generic_formal_part</FONT>
of the child, as it does for a generic child of a nongeneric unit. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>19.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Suppose P
is a generic library package, and P.C is a generic child of P. P.C can
be instantiated inside the declarative region of P. Outside P, P.C can
be mentioned only in a <FONT FACE="Arial, Helvetica">with_clause</FONT>.
Conceptually, an instance I of P is a package that has a nested generic
unit called I.C. Mentioning P.C in a <FONT FACE="Arial, Helvetica">with_clause</FONT>
allows I.C to be instantiated. I need not be a library unit, and the
instantiation of I.C need not be a library unit. If I is a library unit,
and an instance of I.C is a child of I, then this instance has to be
called something other than C.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Normal"> A library subprogram shall not override a primitive
subprogram. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>This prevents certain
obscure anomalies. For example, if a library subprogram were to override
a subprogram declared in its parent package, then in a compilation unit
that depends <I>in</I>directly on the library subprogram, the library
subprogram could hide the overridden operation from all visibility, but
the library subprogram itself would not be visible.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that even without this rule,
such subprograms would be illegal for tagged types, because of the freezing
rules. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Normal"> The defining name of a function that is a compilation
unit shall not be an <FONT FACE="Arial, Helvetica">operator_symbol</FONT>.
</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>Since overloading
is not permitted among compilation units, it seems unlikely that it would
be useful to define one as an operator. Note that a subunit could be
renamed within its parent to be an operator. </FONT></DIV>
<H4 ALIGN=CENTER>Static Semantics</H4>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">subprogram_renaming_declaration</FONT>
that is a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>
is a renaming-as-declaration, not a renaming-as-body.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> [There are two
kinds of dependences among compilation units:] </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>[The <I>semantic dependences</I> (see below) are the ones
needed to check the compile-time rules across compilation unit boundaries;
a compilation unit depends semantically on the other compilation units
needed to determine its legality. The visibility rules are based on the
semantic dependences.</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>25</FONT></DIV>
<UL Class="Bulleted"><LI TYPE=DISC>The <I>elaboration dependences</I> (see <A HREF="AA-10-2.html">10.2</A>)
determine the order of elaboration of <FONT FACE="Arial, Helvetica">library_item</FONT>s.]
</LI></UL>
<DIV Class="Paranum"><FONT SIZE=-2>25.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Don't confuse
these kinds of dependences with the run-time dependences among tasks
and masters defined in <A HREF="AA-9-3.html">9.3</A>, ``<A HREF="AA-9-3.html">Task
Dependence - Termination of Tasks</A>''. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3890"></A><A NAME="I3891"></A>A <FONT FACE="Arial, Helvetica">library_item</FONT>
depends semantically upon its parent declaration. A subunit depends semantically
upon its parent body. A <FONT FACE="Arial, Helvetica">library_unit_body</FONT>
depends semantically upon the corresponding <FONT FACE="Arial, Helvetica">library_unit_declaration</FONT>,
if any. A compilation unit depends semantically upon each <FONT FACE="Arial, Helvetica">library_item</FONT>
mentioned in a <FONT FACE="Arial, Helvetica">with_clause</FONT> of the
compilation unit. In addition, if a given compilation unit contains an
<FONT FACE="Arial, Helvetica">attribute_reference</FONT> of a type defined
in another compilation unit, then the given compilation unit depends
semantically upon the other compilation unit. The semantic dependence
relationship is transitive. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The ``if any''
in the third sentence is necessary because library subprograms are not
required to have a <FONT FACE="Arial, Helvetica">subprogram_declaration</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>If a given
compilation unit contains a <FONT FACE="Arial, Helvetica">choice_parameter_specification</FONT>,
then the given compilation unit depends semantically upon the declaration
of Ada.Exceptions.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>If a given compilation unit contains
a <FONT FACE="Arial, Helvetica">pragma</FONT> with an argument of a type
defined in another compilation unit, then the given compilation unit
depends semantically upon the other compilation unit. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.d</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>For example,
a compilation unit containing X'Address depends semantically upon the
declaration of package System.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.e</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>For the Address attribute, this
fixes a hole in Ada 83. Note that in almost all cases, the dependence
will need to exist due to <FONT FACE="Arial, Helvetica">with_clause</FONT>s,
even without this rule. Hence, the rule has very little effect on programmers.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.f</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that the semantic dependence
does not have the same effect as a <FONT FACE="Arial, Helvetica">with_clause</FONT>;
in order to denote a declaration in one of those packages, a <FONT FACE="Arial, Helvetica">with_clause</FONT>
will generally be needed.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>26.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that no special rule is needed
for an <FONT FACE="Arial, Helvetica">attribute_definition_clause</FONT>,
since an expression after <B>use</B> will require semantic dependence
upon the compilation unit containing the <FONT FACE="Arial, Helvetica">type_declaration</FONT>
of interest. </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>1 A simple program may consist
of a single compilation unit. A <FONT FACE="Arial, Helvetica">compilation</FONT>
need not have any compilation units; for example, its text can consist
of <FONT FACE="Arial, Helvetica">pragma</FONT>s. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Such <FONT FACE="Arial, Helvetica">pragma</FONT>s
cannot have any arguments that are <FONT FACE="Arial, Helvetica">name</FONT>s,
by a previous rule of this subclause. A <FONT FACE="Arial, Helvetica">compilation</FONT>
can even be entirely empty, which is probably not useful.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Some interesting properties of
the three kinds of dependence: The elaboration dependences also include
the semantic dependences, except that subunits are taken together with
their parents. The semantic dependences partly determine the order in
which the compilation units appear in the environment at compile time.
At run time, the order is partly determined by the elaboration dependences.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.c</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>The
model whereby a child is inside its parent's declarative region, after
the parent's declaration, as explained in <A HREF="AA-8-1.html">8.1</A>,
has the following ramifications: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.d</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>The restrictions on ``early'' use of a private type (RM83-7.4.1(4))
or a deferred constant (RM83-7.4.3(2)) do not apply to uses in child
units, because they follow the full declaration.</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>27.e</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>A library subprogram is never primitive, even if its profile
includes a type declared immediately within the parent's <FONT FACE="Arial, Helvetica">package_specification</FONT>,
because the child is not declared immediately within the same <FONT FACE="Arial, Helvetica">package_specification</FONT>
as the type (so it doesn't declare a new primitive subprogram), and because
the child is forbidden from overriding an old primitive subprogram. It
is immediately within the same declarative region, but not the same <FONT FACE="Arial, Helvetica">package_specification</FONT>.
Thus, for a tagged type, it is not possible to call a child subprogram
in a dispatching manner. (This is also forbidden by the freezing rules.)
Similarly, it is not possible for the user to declare primitive subprograms
of the types declared in the declaration of Standard, such as Integer
(even if the rules were changed to allow a library unit whose name is
an operator symbol).</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>27.f</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>When the parent unit is ``used'' the simple names of the
with'd child units are directly visible (see <A HREF="AA-8-4.html">8.4</A>,
``<A HREF="AA-8-4.html">Use Clauses</A>'').</LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>27.g</FONT></DIV>
<UL Class="SmallBulleted"><FONT SIZE=-1><LI TYPE=DISC>When a parent body with's its own child, the defining name
of the child is directly visible, and the parent body is not allowed
to include a declaration of a homograph of the child unit immediately
within the <FONT FACE="Arial, Helvetica">declarative_part</FONT> of the
body (RM83-8.3(17)). </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>27.h</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Note that ``declaration of a library
unit'' is different from ``<FONT FACE="Arial, Helvetica">library_unit_declaration</FONT>''
-- the former includes <FONT FACE="Arial, Helvetica">subprogram_body</FONT>.
Also, we sometimes really mean ``declaration of a view of a library unit'',
which includes <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>s.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.i</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The visibility rules generally
imply that the renamed view of a <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>
has to be mentioned in a <FONT FACE="Arial, Helvetica">with_clause</FONT>
of the <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.j</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>To be honest: </B>The real
rule is that the renamed library unit has to be visible in the <FONT FACE="Arial, Helvetica">library_unit_renaming_declaration</FONT>.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>27.k</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Reason: </B>In most cases,
``has to be visible'' means there has to be a <FONT FACE="Arial, Helvetica">with_clause</FONT>.
However, it is possible in obscure cases to avoid the need for a <FONT FACE="Arial, Helvetica">with_clause</FONT>;
in particular, a compilation unit such as ``<B>package</B> P.Q <B>renames</B>
P;'' is legal with no <FONT FACE="Arial, Helvetica">with_clause</FONT>s
(though not particularly interesting). ASCII is physically nested in
Standard, and so is not a library unit, and cannot be renamed as a library
unit. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>28</FONT></DIV>
<DIV Class="Notes"><FONT SIZE=-1>2 The <FONT FACE="Arial, Helvetica">designator</FONT>
of a library function cannot be an <FONT FACE="Arial, Helvetica">operator_symbol</FONT>,
but a nonlibrary <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>
is allowed to rename a library function as an operator. Within a partition,
two library subprograms are required to have distinct names and hence
cannot overload each other. However, <FONT FACE="Arial, Helvetica">renaming_declaration</FONT>s
are allowed to define overloaded names for such subprograms, and a locally
declared subprogram is allowed to overload a library subprogram. The
expanded name Standard.L can be used to denote a root library unit L
(unless the declaration of Standard is hidden) since root library unit
declarations occur immediately within the declarative region of package
Standard. </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>29</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> <I>Examples of
library units:</I> </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>30</FONT></DIV>
<DIV Class="Examples"><TT><B>package</B> Rational_Numbers.IO <B>is</B> <I>-- public child of Rational_Numbers, see <A HREF="AA-7-1.html">7.1</A></I><BR>
<B>procedure</B> Put(R : <B>in</B> Rational);<BR>
<B>procedure</B> Get(R : <B>out</B> Rational);<BR>
<B>end</B> Rational_Numbers.IO;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>31</FONT></DIV>
<DIV Class="Examples"><TT><B>private procedure</B> Rational_Numbers.Reduce(R : <B>in out</B> Rational);<BR>
<I>-- private child of Rational_Numbers</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>32</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Rational_Numbers.Reduce; <I>-- refer to a private child</I><BR>
<B>package body</B> Rational_Numbers <B>is</B><BR>
...<BR>
<B>end</B> Rational_Numbers;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>33</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Rational_Numbers.IO; <B>use</B> Rational_Numbers;<BR>
<B>with</B> Ada.Text_io; <I>-- see <A HREF="AA-A-10.html">A.10</A></I><BR>
<B>procedure</B> Main <B>is</B> <I>-- a root library procedure</I><BR>
R : Rational;<BR>
<B>begin</B><BR>
R := 5/3; <I>-- construct a rational number, see <A HREF="AA-7-1.html">7.1</A></I><BR>
Ada.Text_IO.Put("The answer is: ");<BR>
IO.Put(R);<BR>
Ada.Text_IO.New_Line;<BR>
<B>end</B> Main;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>34</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Rational_Numbers.IO;<BR>
<B>package</B> Rational_IO <B>renames</B> Rational_Numbers.IO;<BR>
<I>-- a library unit renaming declaration</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35</FONT></DIV>
<DIV Class="Normal"> Each of the above <FONT FACE="Arial, Helvetica">library_item</FONT>s
can be submitted to the compiler separately. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.a</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1><B>Discussion:
</B><I>Example of a generic package with children:</I></FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.b</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>generic</B><BR>
<B>type</B> Element <B>is</B> <B>private</B>;<BR>
<B>with</B> <B>function</B> Image(E : Element) <B>return</B> String;<BR>
<B>package</B> Generic_Bags <B>is</B><BR>
<B>type</B> Bag <B>is</B> <B>limited</B> <B>private</B>; --<I> A bag of Elements.</I><BR>
<B>procedure</B> Add(B : <B>in</B> <B>out</B> Bag; E : Element);<BR>
<B>function</B> Bag_Image(B : Bag) <B>return</B> String;<BR>
<B>private</B><BR>
<B>type</B> Bag <B>is</B> ...;<BR>
<B>end</B> Generic_Bags;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.c</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>generic</B><BR>
<B>package</B> Generic_Bags.Generic_Iterators <B>is</B><BR>
... --<I> various additional operations on Bags.</I></TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.d</FONT></DIV>
<DIV Class="SmallExamples"><TT> <B>generic</B><BR>
<B>with</B> <B>procedure</B> Use_Element(E : <B>in</B> Element);<BR>
--<I> Called once per bag element.</I><BR>
<B>procedure</B> Iterate(B : <B>in</B> Bag);<BR>
<B>end</B> Generic_Bags.Generic_Iterators;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.e</FONT></DIV>
<DIV Class="WideAnnotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>A
package that instantiates the above generic units: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.f</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> Generic_Bags;<BR>
<B>with</B> Generic_Bags.Generic_Iterators;<BR>
<B>package</B> My_Abstraction <B>is</B><BR>
<B>type</B> My_Type <B>is</B> ...;<BR>
<B>function</B> Image(X : My_Type) <B>return</B> String;<BR>
<B>package</B> Bags_Of_My_Type <B>is</B> <B>new</B> Generic_Bags(My_Type, Image);<BR>
<B>package</B> Iterators_Of_Bags_Of_My_Type <B>is</B> <B>new</B> Bags_Of_My_Type.Generic_Iterators;<BR>
<B>end</B> My_Abstraction;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.g</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>In the above example, Bags_Of_My_Type
has a nested generic unit called Generic_Iterators. The second <FONT FACE="Arial, Helvetica">with_clause</FONT>
makes that nested unit visible.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.h</FONT></DIV>
<DIV Class="Annotations" Style="margin-bottom: 0.4em"><FONT SIZE=-1>Here
we show how the generic body could depend on one of its own children:
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.i</FONT></DIV>
<DIV Class="SmallExamples"><TT><B>with</B> Generic_Bags.Generic_Iterators;<BR>
<B>package</B> <B>body</B> Generic_Bags <B>is</B><BR>
<B>procedure</B> Add(B : <B>in</B> <B>out</B> Bag; E : Element) <B>is</B> ... <B>end</B> Add;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.j</FONT></DIV>
<DIV Class="SmallExamples"><TT> <B>package</B> Iters <B>is</B> <B>new</B> Generic_Iterators;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.k</FONT></DIV>
<DIV Class="SmallExamples"><TT> <B>function</B> Bag_Image(B : Bag) <B>return</B> String <B>is</B><BR>
Buffer : String(1..10_000);<BR>
Last : Integer := 0;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.l</FONT></DIV>
<DIV Class="SmallExamples"><TT> <B>procedure</B> Append_Image(E : <B>in</B> Element) <B>is</B><BR>
Im : <B>constant</B> String := Image(E);<BR>
<B>begin</B><BR>
<B>if</B> Last /= 0 <B>then</B> --<I> Insert a comma.</I><BR>
Last := Last + 1;<BR>
Buffer(Last) := ',';<BR>
<B>end</B> <B>if</B>;<BR>
Buffer(Last+1 .. Last+Im'Length) := Im;<BR>
Last := Last + Im'Length;<BR>
<B>end</B> Append_Image;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.m</FONT></DIV>
<DIV Class="SmallExamples"><TT> <B>procedure</B> Append_All <B>is</B> <B>new</B> Iters.Iterate(Append_Image);<BR>
<B>begin</B><BR>
Append_All(B);<BR>
<B>return</B> Buffer(1..Last);<BR>
<B>end</B> Bag_Image;<BR>
<B>end</B> Generic_Bags;</TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>35.n</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I3892"></A>The syntax
rule for <FONT FACE="Arial, Helvetica">library_item</FONT> is modified
to allow the reserved word <B>private</B> before a <FONT FACE="Arial, Helvetica">library_unit_declaration</FONT>.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.o</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Children (other than children
of Standard) are new in Ada 95.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>35.p</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Library unit renaming is new in
Ada 95. </FONT></DIV>
<H4 ALIGN=CENTER>Wording Changes from Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>35.q</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>Standard is considered a library
unit in Ada 95. This simplifies the descriptions, since it implies that
the parent of each library unit is a library unit. (Standard itself has
no parent, of course.) As in Ada 83, the language does not define any
way to recompile Standard, since the name given in the declaration of
a library unit is always interpreted in relation to Standard. That is,
an attempt to compile a package Standard would result in Standard.Standard.
</FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-10-1.html">Previous</A> <A HREF="AA-10-1-2.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|