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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>AARM95 - Subunits of Compilation 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-2.html">Previous</A> <A HREF="AA-10-1-4.html">Next</A></P>
<HR>
<H1> 10.1.3 Subunits of Compilation Units</H1>
<DIV Class="Paranum"><FONT SIZE=-2>1</FONT></DIV>
<DIV Class="Normal"> [Subunits are like child units, with these (important)
differences: subunits support the separate compilation of bodies only
(not declarations); the parent contains a <FONT FACE="Arial, Helvetica">body_stub</FONT>
to indicate the existence and place of each of its subunits; declarations
appearing in the parent's body can be visible within the subunits.] </DIV>
<H4 ALIGN=CENTER>Syntax</H4>
<DIV Class="Paranum"><FONT SIZE=-2>2</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">body_stub<A NAME="I3906"></A>
::= </FONT><A NAME="I3907"></A><FONT FACE="Arial, Helvetica">subprogram_body_stub</FONT> | <A NAME="I3908"></A><FONT FACE="Arial, Helvetica">package_body_stub</FONT> | <A NAME="I3909"></A><FONT FACE="Arial, Helvetica">task_body_stub</FONT> | <A NAME="I3910"></A><FONT FACE="Arial, Helvetica">protected_body_stub</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">subprogram_body_stub<A NAME="I3911"></A>
::= </FONT><A NAME="I3912"></A><FONT FACE="Arial, Helvetica">subprogram_specification</FONT> <B>is</B> <B>separate</B>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>3.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>Although this
syntax allows a <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>,
that is disallowed by <A HREF="AA-10-1-1.html">10.1.1</A>, ``<A HREF="AA-10-1-1.html">Compilation
Units - Library Units</A>''. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>4</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">package_body_stub<A NAME="I3913"></A>
::= </FONT><B>package</B> <B>body</B> <A NAME="I3914"></A><FONT FACE="Arial, Helvetica">defining_identifier</FONT> <B>is</B> <B>separate</B>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>5</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">task_body_stub<A NAME="I3915"></A>
::= </FONT><B>task</B> <B>body</B> <A NAME="I3916"></A><FONT FACE="Arial, Helvetica">defining_identifier</FONT> <B>is</B> <B>separate</B>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>6</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">protected_body_stub<A NAME="I3917"></A>
::= </FONT><B>protected</B> <B>body</B> <A NAME="I3918"></A><FONT FACE="Arial, Helvetica">defining_identifier</FONT> <B>is</B> <B>separate</B>;</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>7</FONT></DIV>
<DIV Class="SyntaxIndented"><FONT FACE="Arial, Helvetica">subunit<A NAME="I3919"></A>
::= </FONT><B>separate</B> (<A NAME="I3920"></A><FONT FACE="Arial, Helvetica">parent_unit_name</FONT>) <A NAME="I3921"></A><FONT FACE="Arial, Helvetica">proper_body</FONT></DIV>
<H4 ALIGN=CENTER>Legality Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>8</FONT></DIV>
<DIV Class="Normal"> <A NAME="I3922"></A>The <I>parent body</I> of
a subunit is the body of the program unit denoted by its <FONT FACE="Arial, Helvetica">parent_unit_name</FONT>.
<A NAME="I3923"></A> The term <I>subunit</I> is used to refer to a <FONT FACE="Arial, Helvetica">subunit</FONT>
and also to the <FONT FACE="Arial, Helvetica">proper_body</FONT> of a
<FONT FACE="Arial, Helvetica">subunit</FONT>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9</FONT></DIV>
<DIV Class="Normal"> The parent body of a subunit shall be present
in the current environment, and shall contain a corresponding <FONT FACE="Arial, Helvetica">body_stub</FONT>
with the same <FONT FACE="Arial, Helvetica">defining_identifier</FONT>
as the subunit. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>9.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>This can't
be a Name Resolution Rule, because a <FONT FACE="Arial, Helvetica">subunit</FONT>
is not a complete context. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>10</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">package_body_stub</FONT>
shall be the completion of a <FONT FACE="Arial, Helvetica">package_declaration</FONT>
or <FONT FACE="Arial, Helvetica">generic_package_declaration</FONT>;
a <FONT FACE="Arial, Helvetica">task_body_stub</FONT> shall be the completion
of a <FONT FACE="Arial, Helvetica">task_declaration</FONT>; a <FONT FACE="Arial, Helvetica">protected_body_stub</FONT>
shall be the completion of a <FONT FACE="Arial, Helvetica">protected_declaration</FONT>.</DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11</FONT></DIV>
<DIV Class="Normal"> In contrast, a <FONT FACE="Arial, Helvetica">subprogram_body_stub</FONT>
need not be the completion of a previous declaration, [in which case
the <FONT FACE="Arial, Helvetica">_stub</FONT> declares the subprogram].
If the <FONT FACE="Arial, Helvetica">_stub</FONT> is a completion, it
shall be the completion of a <FONT FACE="Arial, Helvetica">subprogram_declaration</FONT>
or <FONT FACE="Arial, Helvetica">generic_subprogram_declaration</FONT>.
The profile of a <FONT FACE="Arial, Helvetica">subprogram_body_stub</FONT>
that completes a declaration shall conform fully to that of the declaration.
<A NAME="I3924"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>11.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B>The part about
<FONT FACE="Arial, Helvetica">subprogram_body_stub</FONT>s echoes the
corresponding rule for <FONT FACE="Arial, Helvetica">subprogram_bodies</FONT>
in <A HREF="AA-6-3.html">6.3</A>, ``<A HREF="AA-6-3.html">Subprogram
Bodies</A>''. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>12</FONT></DIV>
<DIV Class="Normal"> A subunit that corresponds to a <FONT FACE="Arial, Helvetica">body_stub</FONT>
shall be of the same kind (<FONT FACE="Arial, Helvetica">package_</FONT>,
<FONT FACE="Arial, Helvetica">subprogram_</FONT>, <FONT FACE="Arial, Helvetica">task_</FONT>,
or <FONT FACE="Arial, Helvetica">protected_</FONT>) as the <FONT FACE="Arial, Helvetica">body_stub</FONT>.
The profile of a <FONT FACE="Arial, Helvetica">subprogram_body</FONT>
subunit shall be fully conformant to that of the corresponding <FONT FACE="Arial, Helvetica">body_stub</FONT>.
<A NAME="I3925"></A></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13</FONT></DIV>
<DIV Class="Normal"> A <FONT FACE="Arial, Helvetica">body_stub</FONT>
shall appear immediately within the <FONT FACE="Arial, Helvetica">declarative_part</FONT>
of a compilation unit body. This rule does not apply within an instance
of a generic unit. </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>13.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Discussion: </B><A NAME="I3926"></A>This
is a methodological restriction; that is, it is not necessary for the
semantics of the language to make sense. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>14</FONT></DIV>
<DIV Class="Normal"> The <FONT FACE="Arial, Helvetica">defining_identifier</FONT>s
of all <FONT FACE="Arial, Helvetica">body_stub</FONT>s that appear immediately
within a particular <FONT FACE="Arial, Helvetica">declarative_part</FONT>
shall be distinct. </DIV>
<H4 ALIGN=CENTER>Post-Compilation Rules</H4>
<DIV Class="Paranum"><FONT SIZE=-2>15</FONT></DIV>
<DIV Class="Normal"> For each <FONT FACE="Arial, Helvetica">body_stub</FONT>,
there shall be a subunit containing the corresponding <FONT FACE="Arial, Helvetica">proper_body</FONT>.
</DIV>
<DIV Class="NotesHeader"><FONT SIZE=-1>NOTES</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>16</FONT></DIV>
<DIV Class="Notes" Style="margin-bottom: 0.4em"><FONT SIZE=-1>4 The
rules in <A HREF="AA-10-1-4.html">10.1.4</A>, ``<A HREF="AA-10-1-4.html">The
Compilation Process</A>'' say that a <FONT FACE="Arial, Helvetica">body_stub</FONT>
is equivalent to the corresponding <FONT FACE="Arial, Helvetica">proper_body</FONT>.
This implies: </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>17</FONT></DIV>
<UL Class="NotesBulleted"><FONT SIZE=-1><LI TYPE=DISC>Visibility within a subunit is the visibility that would
be obtained at the place of the corresponding <FONT FACE="Arial, Helvetica">body_stub</FONT>
(within the parent body) if the <FONT FACE="Arial, Helvetica">context_clause</FONT>
of the subunit were appended to that of the parent body. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>17.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>Recursively.
Note that this transformation might make the parent illegal; hence it
is not a true equivalence, but applies only to visibility within the
subunit. </FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18</FONT></DIV>
<UL Class="NotesBulleted"><FONT SIZE=-1><LI TYPE=DISC>The effect of the elaboration of a <FONT FACE="Arial, Helvetica">body_stub</FONT>
is to elaborate the subunit. </LI></FONT></UL>
<DIV Class="Paranum"><FONT SIZE=-2>18.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>The elaboration
of a subunit is part of its parent body's elaboration, whereas the elaboration
of a child unit is not part of its parent declaration's elaboration.
</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.b</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><B>Ramification: </B>A <FONT FACE="Arial, Helvetica">library_item</FONT>
that is mentioned in a <FONT FACE="Arial, Helvetica">with_clause</FONT>
of a subunit can be hidden (from direct visiblity) by a declaration (with
the same <FONT FACE="Arial, Helvetica">identifier</FONT>) given in the
subunit. Moreover, such a <FONT FACE="Arial, Helvetica">library_item</FONT>
can even be hidden by a declaration given within the parent body since
a library unit is declared in its parent's declarative region; this however
does not affect the interpretation of the <FONT FACE="Arial, Helvetica">with_clause</FONT>s
themselves, since only <FONT FACE="Arial, Helvetica">library_item</FONT>s
are visible or directly visible in <FONT FACE="Arial, Helvetica">with_clause</FONT>s.</FONT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>18.c</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1>The body of a protected operation
cannot be a subunit. This follows from the syntax rules. The body of
a protected unit can be a subunit. </FONT></DIV>
<H4 ALIGN=CENTER>Examples</H4>
<DIV Class="Paranum"><FONT SIZE=-2>19</FONT></DIV>
<DIV Class="Normal" Style="margin-bottom: 0.4em"> The package Parent
is first written without subunits: </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>20</FONT></DIV>
<DIV Class="Examples"><TT><B>package</B> Parent <B>is</B><BR>
<B>procedure</B> Inner;<BR>
<B>end</B> Parent;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>21</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Ada.Text_IO;<BR>
<B>package</B> <B>body</B> Parent <B>is</B><BR>
Variable : String := "Hello, there.";<BR>
<B>procedure</B> Inner <B>is</B><BR>
<B>begin</B><BR>
Ada.Text_IO.Put_Line(Variable);<BR>
<B>end</B> Inner;<BR>
<B>end</B> Parent;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>22</FONT></DIV>
<DIV Class="Wide" Style="margin-bottom: 0.4em"> The body of procedure
Inner may be turned into a subunit by rewriting the package body as follows
(with the declaration of Parent remaining the same): </DIV>
<DIV Class="Paranum"><FONT SIZE=-2>23</FONT></DIV>
<DIV Class="Examples"><TT><B>package</B> <B>body</B> Parent <B>is</B><BR>
Variable : String := "Hello, there.";<BR>
<B>procedure</B> Inner <B>is</B> <B>separate</B>;<BR>
<B>end</B> Parent;</TT></DIV>
<DIV Class="Paranum"><FONT SIZE=-2>24</FONT></DIV>
<DIV Class="Examples"><TT><B>with</B> Ada.Text_IO;<BR>
<B>separate</B>(Parent)<BR>
<B>procedure</B> Inner <B>is</B><BR>
<B>begin</B><BR>
Ada.Text_IO.Put_Line(Variable);<BR>
<B>end</B> Inner;</TT></DIV>
<H4 ALIGN=CENTER>Extensions to Ada 83</H4>
<DIV Class="Paranum"><FONT SIZE=-2>24.a</FONT></DIV>
<DIV Class="Annotations"><FONT SIZE=-1><A NAME="I3927"></A>Subunits of
the same ancestor library unit are no longer restricted to have distinct
identifiers. Instead, we require only that the full expanded names be
distinct. </FONT></DIV>
<HR>
<P><A HREF="AA-TOC.html">Contents</A> <A HREF="AA-0-29.html">Index</A> <A HREF="AA-10-1-2.html">Previous</A> <A HREF="AA-10-1-4.html">Next</A> <A HREF="AA-TTL.html">Legal</A></P>
</BODY>
</HTML>
|